var url=location.href.toLowerCase();
var tempSrvId="";

if(url.indexOf("company.php")!=-1)
{
    //显示客户端DIV
	var tempKhId="";
    function setLink()
    {
        var khid=$("khid").value;
        if(khid!=tempKhId)
        {
        	
	        if(khid.length>0 && khid!="-1")
	        {
                var Sys = {};
                var ua = navigator.userAgent.toLowerCase();
                if (window.ActiveXObject)
                { Sys.ie = ua.match(/msie ([\d.]+)/)[1]; }
                if(Sys.ie=="7.0")
                {
                    var popuped = false;
                    var popAd = function() {
                        if (popuped) return;
                        popuped = true;

                        window.showModalDialog(basekfturl + "weblogin/test.aspx?ie7=1&khid="+khid,"","dialogHeight:10px;dialogWidth:10px;");
                        document.body.detachEvent("onclick", popAd);
                    }
                    try {
                        popAd();
                    } catch (e) {
                        popuped = false;
                        document.body.attachEvent("onclick", popAd)
                    }                    
		            tempKhId=khid;	           
	        	}
	        	else
	        	{
	        	    var ajax=request("ajaxRequest",basekfturl + "weblogin/test.aspx?khid="+khid);      
	        	    tempKhId=khid;	        	    
	        	}
	        }
        }
    }
    window.setInterval(setLink,1000);
}
else
{
    //显示服务端DIV
    $("Layer1").style.display="inline";
    $("Layer2").style.display="inline";
    
    //更改服务端窗口大小
	if(!(document.body.clientWidth>780))
	{
	    window.resizeBy(190,160);
	}
	
    function getInfo()
    {
        var re = /\d{9}/ig;
        var ks=$("l-ts-wd").innerText.match(re);

        if(ks!=null)
        {          
        	khid=ks[0];
            if(khid!=tempSrvId)
            {
                //alert(khid+" kk "+tempSrvId+"abc");
		        var ajax=request("ajaxRequest",basekfturl + "weblogin/test1.aspx?khid="+khid);      
		        tempSrvId=khid;
            }
        }
        else
        {
            $("showUserDiv").innerHTML="";
            $("showMergeDiv").innerHTML="";          
        }
    }
    window.setInterval(getInfo,1000);
}

function request(id,url){ 
    oScript = $(id); 
    var head = document.getElementsByTagName("head").item(0); 
    if (oScript) { 
        head.removeChild(oScript); 
    } 
    oScript = document.createElement("script"); 
    oScript.setAttribute("src", url); 
    oScript.setAttribute("id",id); 
    oScript.setAttribute("type","text/javascript"); 
    oScript.setAttribute("language","javascript"); 
    head.appendChild(oScript); 
    return oScript; 
} 

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }

  return elements;
}

function reGet()
{
    var ajax=request("ajaxRequest",basekfturl + "weblogin/test1.aspx?khid="+tempSrvId);   
}

function createLink()
{
    var link=window.prompt("请输入链接地址","http://");
    var ba=window.prompt("请输入工号","");
    var url=link+"?ba="+ba;
    window.clipboardData.setData("Text",url+ba);
}