﻿

//功能：同alert方法
//message:提示消息
//参数isServer:是否是在．CS中调用，传入值为Yes或No
//time:窗口多少毫秒后自动关闭
//url:点确定后所要跳转的URL
//isIframe:在内页中调用
//script:js代码
function MessageInfo(message,isServer,time,url,isIframe,script)
{   
    if(url==null)url="";
    if(script==null)script="";
    var str="<div><div id='divBg'></div>"
    str=str+"<div id='divAlert'>";
    str=str+"<div class='alertHead' onmousedown='oMove(event);' title='按住鼠标左键可进行拖动' style='cursor:move;'>百惠提示</div>";
    str=str+"<div id='alertContent' class='alertContent'>";
    str=str+"<span class='edge'></span>";
    str=str+"<span class='container'>"+message+"</span>";
    str=str+"</div>";
    str=str+"<div class='alertfoot'><input id='btnAlert'　class='btnAlert' type='button'  value='确定' onclick='Remove()' /></div>";
    str=str+"</div></div>";
    if(isServer=="Yes")
    {
        document.write(str); //服务器端JS调用
    }
    else
    {         
        $("body").append(str);    //客户端JS调用 
    }
    var bgHeight=window.screen.height>document.body.scrollHeight?window.screen.height:document.body.scrollHeight;
    $("#divBg").css("height",bgHeight); 
    $("#divBg").css("width",window.screen.availWidth); 
    var divAlertTop=window.screen.height>document.body.scrollHeight?document.body.scrollHeight:window.screen.height;
    if(isServer=="Yes")    
    {
        if(isIframe=="Yes")
        {
            $("#divAlert").css("bottom",divAlertTop/2);
            $("#divAlert").css("marginBottom","-75px"); 
        }
        else
        {
            $("#divAlert").css("top",divAlertTop/2);
            $("#divAlert").css("marginTop","-75px"); 
        }
    }
    else
    {         
         $("#divAlert").css("top",document.documentElement.scrollTop+window.screen.availHeight/2); 
         $("#divAlert").css("marginTop","-150px"); 
    }   
    $("#divAlert").css("right","50%");    
    $("#divAlert").css("marginRight","-150px");
    //屏蔽所有selelct
    $("select").css("display","none");
    $("#divBg").css("display","block");
    $("#divAlert").css("display","block");  
    
    //锁定浏览器屏幕  
//    $("html").css("overflow","hidden");
    $("#btnAlert").focus(); 
    if(time!=""&&time!=0&&time!=null)
    {
        setTimeout("Remove()",time);
    } 
    this.Remove=function()
    {
        $("#divBg").css("display","none");
        $("#divAlert").css("display","none");
        $("select").css("display","");
        $("html").css("overflow","auto"); 
           
         var parentdiv=document.getElementById("divAlert");
         if(parentdiv)
         {
            parentdiv.parentNode.removeChild(parentdiv); 
         }
        if(script!=null && script!=""&&script!=undefined)
        {
            eval(script); 
        }   
        if(url!=""&&url!=null&&url!=undefined)
        {
            window.location.href=url;
        }
    }
     
}

//浏览器类型及版本检测
function getOs() 
{    
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        return "MSIE";
    }
    if (navigator.userAgent.indexOf("Chrome") > 0) {
        return "Chrome";
    }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
        return "Firefox"; 
   } 
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
        return "Safari"; 
   }  
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
        return "Camino"; 
   } 
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
        return "Gecko";
    }
       
} 


//element:显示提示信息的容器
//warningTitle;错误标题,字体加粗
//warningMessage:错误信息
//提示框宽度,默认300
function MessageHint(element,warningTitle,warningMessage,width)
{  
    if(width!=null)
    {
        $("#"+element).css("width",width);
    }
    else
    {
        $("#"+element).css("width","300px");
    }
     var strHint="<div class='warningInfo'>";
    strHint=strHint+"<div class='MessageHint'> " ;
    strHint=strHint+"<span class='ui-icon ui-icon-info'></span><span style='float:left;'><strong>"+warningTitle+"</strong>"+warningMessage+"</span><div style='clear:both'></div></div></div>";
    $("#"+element).html(strHint); 
    return false;
}
//element:显示提示信息的容器
//warningTitle;错误标题,字体加粗
//warningMessage:错误信息
//提示框宽度,默认300
function MessageWarning(element,warningTitle,warningMessage,width)
{
    if(width!=null)
    {
        $("#"+element).css("width",width);
    }
    else
    {
        $("#"+element).css("width","300px");
    }
    var strWarning="<div class='warningInfo'>";
    strWarning=strWarning+"<div class='MessageWarning'> " ;
    strWarning=strWarning+"<span class='ui-icon ui-icon-info'></span><span style='float:left;'><strong>"+warningTitle+"</strong>"+warningMessage+"</span><div style='clear:both'></div></div></div>";
    $("#"+element).html(strWarning); 
    return false;
}

/*功能：相似于confirm方法，但只作用于客户端控件
message:提示消息
isServer:是否是在．CS中调用，传入值为Yes或No
callback:点击确定之后的回调函数
示例：点确定后跳转到WWW．baidu.com
    MessageConfirm("去 www.baidu.com?","Yes",GoBaidu)
    function GoBaidu()
    {
          window.location.href="http://www.baidu.com";
    }*/
//isIframe:在内页中调用
function MessageConfirm(message,isServer,callback,isIframe)
{
     var str1="<div><div id='divBg'></div>"
     str1=str1+"<div id='divconfirm'>";
     str1=str1+"<div class='confirmHead' onmousedown='oMove(event);' title='按住鼠标左键可进行拖动' style='cursor:move;'>百惠提示</div>";
     str1=str1+"<div id='confirmContent' class='confirmContent'>";
     str1=str1+"<span class='edge'></span>";
     str1=str1+"<span class='container'>"+message+"</span>";
     str1=str1+"</div>";
     str1=str1+"<div class='confirmfoot'><input id='btnYes'　class='btnconfirm' type='button'  value='确定'/>&nbsp;<input id='btnNo'　class='btnconfirm' type='button'  value='取消' /></div>";
     str1=str1+"</div></div>";
     if(isServer=="Yes")
    {
        document.write(str1); //服务器端JS调用
    }
    else
    {         
        $("body").append(str1);    //客户端JS调用 
    }
    var bgHeight=window.screen.height>document.body.scrollHeight?window.screen.height:document.body.scrollHeight;
    $("#divBg").css("height",bgHeight); 
    $("#divBg").css("width",window.screen.availWidth);
    var divConfirmTop=window.screen.height>document.body.scrollHeight?document.body.scrollHeight:window.screen.height;
    if(isServer=="Yes")
    {
         if(isIframe=="Yes")
        {
            $("#divconfirm").css("bottom",divConfirmTop/2);
            $("#divconfirm").css("marginBottom","-75px"); 
        }
        else
        {
            $("#divconfirm").css("top",divConfirmTop/2);
            $("#divconfirm").css("marginTop","-75px"); 
        }        
    }
    else
    {         
         $("#divconfirm").css("top",document.documentElement.scrollTop+window.screen.availHeight/2);
         $("#divconfirm").css("marginTop","-150px");  
    } 
    $("#divconfirm").css("right","50%");    
    $("#divconfirm").css("marginRight","-150px");    
   //屏蔽所有selelct
    $("select").css("display","none");
    $("#divBg").css("display","block");
    $("#divconfirm").css("display","block");    

    //锁定浏览器屏幕     
//    $("html").css("overflow","hidden");
    $("#btnYes").focus();  
    
    //取消
    $("#btnNo").click(function(){
    $("#divBg").css("display","none");
	$("#divconfirm").css("display","none");
	$("select").css("display","none");	
	$("html").css("overflow","auto");
	 var parentdiv=document.getElementById("divconfirm");
     if(parentdiv)
     {
        parentdiv.parentNode.removeChild(parentdiv); 
     }
	});
	
	//确定
	$("#btnYes").click(function(){
	$("#divBg").css("display","none");
	$("#divconfirm").css("display","none");
	$("select").css("display","none");
	$("html").css("overflow","auto");
	 var parentdiv=document.getElementById("divconfirm");
     if(parentdiv)
     {
        parentdiv.parentNode.removeChild(parentdiv); 
     }
	if(callback!=null)
	callback();
	});
    return false;
}

//弹出登录窗口\
//参数webRoot:网站所在根目录
//参数callbackURL:关闭该窗口后的目的页面URL
//参数isServer:是否是在．CS中调用，传入值为Yes或No
 function CreateLogin(webRoot,callbackURL,isServer)
    {        
        var strDiv="<div id='divBg'></div>";
        strDiv=strDiv+"<a name='lnklogin'><div id='divLogin' style='display:none;position:absolute;'><iframe id='frameLogin' src='"+webRoot+"UserControls/Logon.aspx?callbackurl="+escape(callbackURL)+"' width='303px' height='169px' scrolling='no' frameborder='0' /></div></a>";
        if(isServer=="Yes")
        {
            document.write(strDiv); //服务器端JS调用
        }
        else
        {         
            $("body").append(strDiv);    //客户端JS调用 
        }   
        var bgHeight=window.screen.height>document.body.scrollHeight?window.screen.height:document.body.scrollHeight;     
        if(getOs()=="MSIE")
        {      
            $("#divBg").css("height",bgHeight); 
        }
        else
        {
           $("#divBg").css("height",bgHeight);       
        } 
        
        $("#divBg").css("z-index","1000");  
        $("#divLogin").css("z-index","1001");  
        $("#divLogin").css("left","50%");
        $("#divLogin").css("top","50%"); 
        $("#divLogin").css("marginLeft","-150px");
        $("#divLogin").css("marginTop","-100px");    
        $("#divBg").css("display","block");
        $("#divLogin").css("display","block");
        window.scrollTo(0,$("#divLogin").css("top"));
        
        //锁定浏览器屏幕  
        $("html").css("overflow","hidden");         
    }
    
    //让iframe自适应大小
    function SetWinHeight(obj)
    {
        var win=obj;
        if (document.getElementById)
        {
            if (win && !window.opera)
            {
                if (win.contentDocument && win.contentDocument.body.offsetHeight)
                    win.height = win.contentDocument.body.offsetHeight;
                else if(win.Document && win.Document.body.scrollHeight)
                    win.height = win.Document.body.scrollHeight;
            }
        }
    }
    
    function CreateWindow(url,title,width,height)
    {
        var strDiv = "<div id='divBg'></div>";
        
        var divWidth=width==null?"300":width;
        var divHeight=height==null?"300":height;
        var newDiv=document.createElement("DIV");
        newDiv.id = "divContent";
        newDiv.style.position = "absolute";
        if(divHeight>500)
        {
            newDiv.style.top="10px";
        }
        else
        {
            newDiv.style.top=document.documentElement.scrollTop+(window.screen.availHeight-200-divHeight)/2+"px"; 
        }        
        newDiv.style.left=(document.body.scrollWidth-divWidth)/2;
        newDiv.style.width=divWidth+"px";
        if(getOs()=="MSIE")
        {      
            newDiv.style.height=divHeight+"px";
        }
        else
        {
            newDiv.style.height=(divHeight+45)+"px";
        }
        newDiv.style.border="outset 2px #ECECEC";
        newDiv.style.zIndex="1000";
        newDiv.style.display="none";
        newDiv.style.background="white";  
        newDiv.style.textAlign="center";
        newDiv.style.lineHeight="";
        
        
        //顶部条
        var topDiv=document.createElement("DIV");
        topDiv.style.height="20px";
        var spanTitle=document.createElement("SPAN");
        spanTitle.innerHTML=title;
        spanTitle.setAttribute("class","BoxTop");
//        spanTitle.style.fontSize="14px";
//        spanTitle.style.fontWeight="bold";
//        spanTitle.style.color="#918c7e";
//        spanTitle.style.styleFloat ="left";
//        spanTitle.style.cssFloat ="left";
        topDiv.appendChild(spanTitle);
        var closeX=GetCssImg("X","15px","#ff6600");
        closeX.style.styleFloat ="right"; 
        closeX.style.cssFloat ="right";                
        topDiv.appendChild(closeX);
        
        //中间内容区
        var contentDiv =document.createElement("DIV");
        contentDiv.style.left = "0";
        contentDiv.innerHTML = "<iframe src='" + url + "' onload='Javascript:SetWinHeight(this)' width='100%' scrolling='no' frameborder='0' />";
        
        newDiv.appendChild(topDiv);
        newDiv.appendChild(contentDiv);
        //alert(newDiv.outerHTML);
        
        $("body").append(strDiv);
        $("body").append(newDiv);
        
        var bgHeight=window.screen.height>document.body.scrollHeight?window.screen.height:document.body.scrollHeight;     
        if(getOs()=="MSIE")
        {      
            $("#divBg").css("height",bgHeight); 
        }
        else
        {
           $("#divBg").css("height",bgHeight);       
        }
        
        $("#divBg").css("z-index","1000");
        $("#divBg").css("display","block");
        $("#divContent").css("z-index","1001");  
        $("#divContent").css("left","50%");
        $("#divContent").css("top","30%"); 
        $("#divContent").css("marginLeft","-200px");
        $("#divContent").css("marginTop","-150px");    
        $("#divContent").css("display","block");
        window.scrollTo(0,$("#divContent").css("top"));
        
        //锁定浏览器屏幕  
        //$("html").css("overflow","hidden");
    }
    
    //功能，从页面弹出一个DIV
    //参数strHtml:div显示的内容
    //参数title:标题，显示在左上角
    //参数width:宽（如：500）
    //参数height:高（如：500,Div内容部分显示高度为：500-底部高(默认20)-标题栏高(默认20)）
    //参数backgroundcolor:背景色
    //参数showBottom:是否显示底部条
    //参数modeWindow:是否显示为模式窗口
    //参数top:定位top值
    //参数left:定位left值
    function CreateDiv(strHtml,title,width,height,backgroundcolor,titleClassName,showBottom,modeWindow,top,left)
    {          
        var showBg=modeWindow==null?false:modeWindow;    
        var divWidth=width==null?"300":width;
        var divHeight=height==null?"300":height;
        var newDiv=document.createElement("DIV");
        newDiv.id="divNew";        
        newDiv.style.position = "absolute";
        if(top!=null)
        {
            newDiv.style.top=top+"px";
        }
        else
        {
            if(divHeight>500)
            {
                newDiv.style.top="10px";
            }
            else
            {
                newDiv.style.top=document.documentElement.scrollTop+(window.screen.availHeight-200-divHeight)/2+"px"; 
            } 
        }       
        newDiv.style.left=(left==null?(document.body.scrollWidth-divWidth)/2:left)+"px";
        newDiv.style.width=divWidth+"px";
        newDiv.style.height=divHeight+"px";        
        newDiv.style.border="outset 2px #ECECEC";
        newDiv.style.zIndex="1000";
        newDiv.style.background=backgroundcolor==null?"white":backgroundcolor;  
        newDiv.style.textAlign="center";
        newDiv.style.lineHeight="";  
        
        //顶部条
        var topDiv=document.createElement("DIV");
        if(titleClassName!=null)
        {
            topDiv.className=titleClassName;
            topDiv.style.height="26px";
        }
        else
        {
            topDiv.style.height="20px";
        }
        var spanTitle=document.createElement("SPAN");
        spanTitle.innerHTML=title;
        spanTitle.style.fontSize="15px";
        spanTitle.style.styleFloat ="left";
        spanTitle.style.cssFloat ="left";
        topDiv.appendChild(spanTitle);
        var closeX=GetCssImg("X","15px","#ff6600");
        closeX.style.styleFloat ="right"; 
        closeX.style.cssFloat ="right";                
        topDiv.appendChild(closeX);
        
        var isShowBottom=showBottom==null?true:showBottom;
         
        //中间内容区
        var contentDiv =document.createElement("DIV");
        if(isShowBottom)
        {
            contentDiv.style.height=divHeight-46+"px";
        }
        else
        {
            contentDiv.style.height=divHeight-20+"px"; 
        }      
        if(!document.all)
        {                
            contentDiv.style.display="table-cell";
        }       
        contentDiv.style.width=divWidth+"px";         
        contentDiv.style.verticalAlign="middle";
        contentDiv.style.textAlign="center";	
        var edgeSpan=document.createElement("span");
        edgeSpan.style.width="0";
        edgeSpan.style.height="100%";
        edgeSpan.style.display="inline-block";
        edgeSpan.style.verticalAlign="middle";
        var contentSpan=document.createElement("span");
        contentSpan.style.display="inline-block";
        contentSpan.style.verticalAlign="middle";
        contentSpan.style.height="100%"; 
        contentSpan.style.overflow="hidden";          
        contentSpan.innerHTML=strHtml;
        contentDiv.style.overflow="auto";
        contentDiv.appendChild(edgeSpan);
        contentDiv.appendChild(contentSpan);
        
        newDiv.appendChild(topDiv);
        newDiv.appendChild(contentDiv); 
        
        //底部条       
        if(isShowBottom) 
        { 
            var bottomDiv=document.createElement("DIV");
            bottomDiv.style.height="20px";
            bottomDiv.style.textAlign="center";
//            var close=GetCssImg("关闭","15px","#ff6600");    
            var close=GetCloseButton("关闭");     
            bottomDiv.appendChild(close);
            newDiv.appendChild(bottomDiv); 
        } 
        if(showBg)
        {            
            var divBg=document.createElement("DIV");
            divBg.id="divBg";
            var bgHeight=window.screen.height>document.body.scrollHeight?window.screen.height:document.body.scrollHeight;
            divBg.style.height=bgHeight+"px";
            divBg.style.width=window.screen.availWidth+"px";            
            divBg.style.display="block"; 
            divBg.style.zIndex="1000";
            newDiv.style.zIndex="1001";  
            document.body.appendChild(divBg);            
        }       
        document.body.appendChild(newDiv);       
    }    
    
    function GetCloseButton(text)
    {
        var newButton=document.createElement("input");       
        newButton.type="button";
        newButton.className="but02";
        newButton.value=text;
        newButton.onclick=function()
        {
            this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
            var divBg=document.getElementById("divBg");
            if(divBg)
            {
                divBg.parentNode.removeChild(divBg);
            } 
        }   
        return newButton;    
    }

    //获取Css小图标
    //参数str:图标文字
    //参数fontSize:图标文字大小
    //参数overBackgroundColor:鼠标移到图标上图标显示的颜色
    function GetCssImg(str,fontSize,overBackgroundColor)
    {          
        var newImg=document.createElement("SPAN");
        newImg.id="btnCssClose";        
        newImg.innerHTML=str;       
        newImg.title="关闭";
        newImg.style.cursor = "hand";
        newImg.style.padding="0 3px";
        newImg.style.fontWeight="bold";
        newImg.style.fontSize=fontSize;
        newImg.style.fontFamily="Arial,Verdana,Sans-Serif";
        newImg.style.color="#CCC";
        newImg.style.textDecoration="none";
        newImg.onmouseout=function()
        {
            newImg.style.padding="0 3px";
            newImg.style.fontWeight="bold";
            newImg.style.fontSize=fontSize;
            newImg.style.fontFamily="Arial,Verdana,Sans-Serif";
            newImg.style.color="#C0C0C0";
            newImg.style.textDecoration="none";
            newImg.style.border="none";
            newImg.style.background="none";
        }
        newImg.onmouseover=function()
        {
            newImg.style.padding="0 3px";
            newImg.style.fontWeight="bold";
            newImg.style.fontSize=fontSize;
            newImg.style.fontFamily="Arial,Verdana,Sans-Serif";
            newImg.style.color="#FFFFFF";
            newImg.style.textDecoration="none";
            newImg.style.background=overBackgroundColor;
            newImg.style.borderTop="1px solid #ffcc99";
            newImg.style.borderRight="1px solid #663300";            
            newImg.style.borderBottom="1px solid #000000";
            newImg.style.borderLeft="1px solid #ff9966";
        }
        newImg.onclick=function()
        {
            this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
            var divBg=document.getElementById("divBg");
            if(divBg)
            {
                divBg.parentNode.removeChild(divBg);
            }            
        }
        return newImg;
     }
     
     function CloseWindow()
     {
        document.getElementById("divContent").parentNode.removeChild(document.getElementById("divContent"));
        $("#divBg").css("display","none");
     }
    
    var nie=document.getElementById&&!document.all; 
    var otop,oleft;
    var obj;
    var isdrag=false; 

    function oMove(e){        

    obj = nie?e.target : event.srcElement; 
    var topElement = "HTML";      
     while (obj.tagName != topElement && obj.id != "divAlert" && obj.id != "divconfirm") { 
     obj = nie ? obj.parentNode : obj.parentElement; 
     } 
     if (obj.id=="divAlert"||obj.id=="divconfirm") { 
     isdrag = true; 
    
     otop = nie ? e.clientY- obj.offsetTop:event.y - obj.offsetTop;
	 oleft = nie ? e.clientX- obj.offsetLeft:event.x - obj.offsetLeft;
	 //设置捕获范围
      if(obj.setCapture){
          obj.setCapture();
      }else if(window.captureEvents){
          window.captureEvents(Event.MOUSEMOVE);
      }
   
	 obj.onmousemove = moveMouse;
obj.onmouseup = function()
	{
		obj.onmousemove = null;
		obj.style.filter = null;
		 //取消捕获范围
           if(obj.releaseCapture){
              obj.releaseCapture();
           }else if(window.captureEvents){
              window.captureEvents(Event.MOUSEMOVE);
           }
          
          //清除事件
          obj.onmouseup=null;
	}

	 return false; 
	 }

}
function moveMouse(e)
{
 if (isdrag) { 
 var top =  nie ?   e.clientY - otop :   event.clientY - otop;
 var left = nie ?  e.clientX - oleft :  event.clientX - oleft;
     top = top>0?top:0;
     left = left>0?left:0;
     
//     top = top>document.body.scrollHeight?document.body.scrollHeight:top;
     left = left>document.body.scrollWidth-2-parseInt(obj.style.width)?document.body.scrollWidth-2-parseInt(obj.style.width):left;
     
	 obj.style.top  = top+"px"; 
     obj.style.left  =  left+"px"; 
   }
   return false;

}
document.onmouseup = new Function("isdrag=false");

function getElementPos(element) {
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
    var el = element;
    if (el.parentNode === null || el.style.display == 'none') {
        return false;
    }
    var parent = null;
    var pos = [];
    var box;
    if (el.getBoundingClientRect)    //IE
    {
        box = el.getBoundingClientRect();
        var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
        return { x: box.left + scrollLeft, y: box.top + scrollTop };
    } else if (document.getBoxObjectFor)    // gecko    
    {
        box = document.getBoxObjectFor(el);
        var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0;
        var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0;
        pos = [box.x - borderLeft, box.y - borderTop];
    } else    // safari & opera    
    {
        pos = [el.offsetLeft, el.offsetTop];
        parent = el.offsetParent;
        if (parent != el) {
            while (parent) {
                pos[0] += parent.offsetLeft;
                pos[1] += parent.offsetTop;
                parent = parent.offsetParent;
            }
        }
        if (ua.indexOf('opera') != -1 || (ua.indexOf('safari') != -1 && el.style.position == 'absolute')) {
            pos[0] -= document.body.offsetLeft;
            pos[1] -= document.body.offsetTop;
        }
    }
    if (el.parentNode) {
        parent = el.parentNode;
    } else {
        parent = null;
    }
    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors
        pos[0] -= parent.scrollLeft;
        pos[1] -= parent.scrollTop;
        if (parent.parentNode) {
            parent = parent.parentNode;
        } else {
            parent = null;
        }
    }
    return { x: pos[0], y: pos[1] };
}

