var $=function(id){if(typeof(id)=="string"){return document.getElementById(id)||document.getElementsByName(id)[0];}else{return id;}};
var issecondlife=(navigator.userAgent.indexOf("Second Life")>-1?true:false);
function DIVDialog(width,height,url,wtop){
      var bordercolor;

      titleheight=18; //
      bordercolor="red";//
      titlecolor="#99CCFF";//
      wtop = wtop || 300;
      var sHeight;
      sHeight=(document.body.scrollHeight>document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight);
      var bgObj=document.createElement("div");
      bgObj.setAttribute('id','bgDiv');
      bgObj.style.position="absolute";
      bgObj.style.top="0";
      bgObj.style.background="#777";
      bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=10,finishOpacity=50)";
      bgObj.style.opacity="0.2";
      bgObj.style.left="0";
      bgObj.style.width="100%";
      bgObj.style.height=sHeight + "px";
      bgObj.style.zIndex = "10000";
      ResolveIe6Problem(bgObj);
      var msgObj=document.createElement("div");
      msgObj.setAttribute("id","msgDiv");
      msgObj.setAttribute("align","center");
      msgObj.style.background="white";
      msgObj.style.border="1px solid " + bordercolor;
      msgObj.style.position = "absolute";
      msgObj.style.left = "50%";
      msgObj.style.top = document.body.scrollTop+wtop+"px";
      msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
      msgObj.style.marginLeft = "-" + (width/2) + "px";
      msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
      msgObj.style.width = width + "px";
      msgObj.style.height =height + "px";
      msgObj.style.zIndex = "10001";
      msgObj.innerHTML='<iframe id="iDialog" frameborder="0" src="'+ url +'" style="width:100%;height:100%;"></iframe>';
      
      document.body.appendChild(bgObj);
      document.body.appendChild(msgObj);
      window.onscroll=function(){
        $("msgDiv").style.top = document.body.scrollTop+wtop+"px";
      }
}
DIVDialog.Ext = function()
{
    $('iDialog').src = 'about:blank';
    document.body.removeChild($('bgDiv'));
    document.body.removeChild($('msgDiv'));
}
function DIVAlert(Title,Msg,FunString,Height){
      var msgw,msgh,bordercolor;
      msgw=400;//
      msgh=Height||100;//

      titleheight=18; //
      bordercolor="red";//
      titlecolor="#99CCFF";//
   
      var sWidth,sHeight;
      sHeight=(document.body.scrollHeight>document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight);
      var bgObj=document.createElement("div");
      bgObj.setAttribute('id','bgDiv');
      bgObj.style.position="absolute";
      bgObj.style.top="0";
      bgObj.style.background="#777";
      bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=10,finishOpacity=50)";
      bgObj.style.opacity="0.2";
      bgObj.style.left="0";
      bgObj.style.width="100%";
      bgObj.style.height=sHeight + "px";
      bgObj.style.zIndex = "10000";
      ResolveIe6Problem(bgObj);
      
      document.body.appendChild(bgObj);
   
      var msgObj=document.createElement("div");
      msgObj.setAttribute("id","msgDiv");
      msgObj.setAttribute("align","center");
      msgObj.style.background="white";
      msgObj.style.border="1px solid " + bordercolor;
         msgObj.style.position = "absolute";
               msgObj.style.left = "50%";
               msgObj.style.top = document.body.scrollTop+300+"px";
               msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
               msgObj.style.marginLeft = "-225px" ;
               msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
               msgObj.style.width = msgw + "px";
               msgObj.style.height =msgh + "px";
               msgObj.style.textAlign = "center";
               msgObj.style.lineHeight ="25px";
               msgObj.style.zIndex = "10001";
   
        var title=document.createElement("h4");
        title.setAttribute("id","msgTitle");
        title.style.textAlign="left";
        
        title.style.margin="0";
        title.style.padding="3px";
        title.style.background=bordercolor;
        title.style.border="1px solid " + bordercolor;
        title.style.height=titleheight+"px";
        title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
        title.style.color="white";
        title.style.cursor="pointer";
        title.innerHTML=(Title==null?"Alert:":Title+":");
        var txt=document.createElement("p");
        txt.style.margin="1em 0"
        txt.setAttribute("id","msgTxt");
        txt.innerHTML=Msg;
        
        var btnOK=document.createElement("button");
        btnOK.id="btn_ok";
        btnOK.style.backgroundColor="#ffffff";
        btnOK.innerHTML="OK";
        if(!document.all)
        {
        	btnOK.style.marginLeft="175";
        }
        btnOK.style.display="block";
        btnOK.style.width="50px";
        btnOK.style.height="20px";
        btnOK.style.textAlign="center";
        btnOK.style.color=bordercolor;
        btnOK.style.border="1px solid " + bordercolor;
        btnOK.style.cursor="pointer";
        btnOK.style.lineHeight="18px";
        btnOK.onclick=function(){
             document.body.removeChild(bgObj);
             window.onscroll=null;
             document.onkeydown=null;
             document.body.removeChild(msgObj);
        	if(FunString!=null)
        	{
        		eval("try{"+FunString+"}catch(e){}");
        	}
        }
        document.body.appendChild(msgObj);
        msgObj.appendChild(title);
        msgObj.appendChild(txt);
        msgObj.appendChild(btnOK);
        btnOK.focus();
              
        window.onscroll=function(){
        $("msgDiv").style.top = document.body.scrollTop+300+"px";
        }
        if(issecondlife)
        {
        	document.onkeydown=keydown;
        }
}
function DIVConfirm(Title,Msg,T_FunString,F_FunString,Height){
      var msgw,msgh,bordercolor;
      msgw=400;//
      msgh=Height||110;//

      titleheight=18; //
      bordercolor="red";//
      titlecolor="#99CCFF";//
   
      var sWidth,sHeight;
      sHeight=(document.body.scrollHeight>document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight);
      var bgObj=document.createElement("div");
      bgObj.setAttribute('id','bgDiv');
      bgObj.style.position="absolute";
      bgObj.style.top="0";
      bgObj.style.background="#777";
      bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=10,finishOpacity=50)";
      bgObj.style.opacity="0.2";
      bgObj.style.left="0";
      bgObj.style.width="100%";
      bgObj.style.height=sHeight + "px";
      bgObj.style.zIndex = "10000";
      
      ResolveIe6Problem(bgObj);
      document.body.appendChild(bgObj);
      var msgObj=document.createElement("div")
      msgObj.setAttribute("id","msgDiv");
      msgObj.setAttribute("align","center");
      msgObj.style.background="white";
      msgObj.style.border="1px solid " + bordercolor;
      msgObj.style.position = "absolute";
      msgObj.style.left = "50%";
      msgObj.style.top = document.body.scrollTop+300+"px";
      msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
      msgObj.style.marginLeft = "-225px" ;
      msgObj.style.width = msgw + "px";
      msgObj.style.height =msgh + "px";
      msgObj.style.textAlign = "center";
      msgObj.style.lineHeight ="25px";
      msgObj.style.zIndex = "10001";
        var title=document.createElement("h4");
        title.setAttribute("id","msgTitle");
        title.setAttribute("align","left");
        title.style.margin="0";
        title.style.padding="3px";
        title.style.background=bordercolor;
        title.style.border="1px solid " + bordercolor;
        title.style.height=titleheight+"px";
        title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
        title.style.color="white";
        title.style.cursor="pointer";
        title.innerHTML=(Title==null?"Confirm:":Title+":");
        var txt=document.createElement("p");
        txt.style.margin="1em 0"
        txt.setAttribute("id","msgTxt");
        txt.innerHTML=Msg;
        
      	var BtnBlock=document.createElement("table")
      	BtnBlock.setAttribute("border","0px");
      	BtnBlock.setAttribute("cellPadding","0px");
      	BtnBlock.setAttribute("cellSpacing","0px");
      	BtnBlock.style.width="100%";
      	BtnBlock.style.height="20px";
		BtnBlock.style.marginTop="0px";
		
        var btnOK=document.createElement("button");
        btnOK.id="btn_ok";
        btnOK.innerHTML="Ok";
        btnOK.style.backgroundColor="#ffffff";
        btnOK.style.height="20px";
        btnOK.style.textAlign="center";
        btnOK.style.display="block";
        btnOK.style.width="60px";
        btnOK.style.color=bordercolor;
        btnOK.style.border="1px solid " + bordercolor;
        btnOK.style.cursor="pointer";
        btnOK.style.lineHeight="18px";
        btnOK.onclick=function(){
             document.body.removeChild(bgObj);
             window.onscroll=null;
             document.body.removeChild(msgObj);
        	if(T_FunString!=null)
        	{
        		eval("try{"+T_FunString+"}catch(e){}");
        	}
        }
        var btnCancel=document.createElement("button");
        btnCancel.innerHTML="Cancel";
        btnCancel.style.backgroundColor="#ffffff";
        btnCancel.style.height="20px";
        btnCancel.style.textAlign="center";
        btnCancel.style.display="block";
        btnCancel.style.width="60px";
        btnCancel.style.color=bordercolor;
        btnCancel.style.border="1px solid " + bordercolor;
        btnCancel.style.cursor="pointer";
        btnCancel.style.lineHeight="18px";
        btnCancel.onclick=function(){
             document.body.removeChild(bgObj);
             window.onscroll=null;
             document.body.removeChild(msgObj);
        	if(F_FunString!=null)
        	{
        		eval("try{"+F_FunString+"}catch(e){}");
        	}
        	document.onkeydown=null;
        }
        btnOK.style.marginLeft="85";
        btnCancel.style.marginLeft="65";
        var tr = document.createElement("tr");
        var td1 = document.createElement("td");
        var td2 = document.createElement("td");
        td1.style.width="50%";
        td2.style.width="50%";
        
        td1.appendChild(btnOK);
        td2.appendChild(btnCancel);
        tr.appendChild(td1);
        tr.appendChild(td2);
        var tbody=document.createElement("tbody");
        tbody.appendChild(tr);
        BtnBlock.appendChild(tbody);

        msgObj.appendChild(title);
        msgObj.appendChild(txt);
        msgObj.appendChild(BtnBlock);
		document.body.appendChild(msgObj);
        btnOK.focus();
        
        window.onscroll=function(){
        $("msgDiv").style.top = document.body.scrollTop+300+"px";
        }
        if(issecondlife)
        {
        	document.onkeydown=keydown;
        }
}
function ResolveIe6Problem(backObject)
{
    index = navigator.userAgent.indexOf("MSIE");
    var ie6 = false;
    if(index != -1)
    {
        if(navigator.userAgent.substring(index+5,index+8)<"7.0")
        {
            ie6= true;
        }
    }
    
    if(backObject != null)
    {
        if(ie6)
        {
            backObject.innerHTML='<iframe frameborder="0" style="width:100%;height:100%;"></iframe>';
        }
    }
    else
    {
        return ie6;
    }
}
function keydown(e){
	e = e || event;
	if(e.keyCode.toString()==13)
	{
		try{
			$("btn_ok").click();
		}catch(e){}
		return false;
	}
}
/*
 * Name:ConfirmTimer
 * Description:show a div confirm dialog with a time counter
 * 
 * Return:
 */
function ConfirmTimer(Title,Msg,ConfirmHandle,CancelHandle){
	  var msgw,msgh,bordercolor;
	  msgw=400;//
	  msgh=110;//
	
	  titleheight=18; //
	  bordercolor="red";//
	  titlecolor="#99CCFF";//
	   
	  var sWidth,sHeight;
	  sWidth=document.body.clientWidth;
	  sHeight=(document.body.scrollHeight>document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight);
	  var bgObj=document.createElement("div");
	  bgObj.setAttribute('id','bgDiv');
	  bgObj.style.position="absolute";
	  bgObj.style.top="0";
	  bgObj.style.background="#777";
	
	  bgObj.style.opacity="0.2";
	  bgObj.style.left="0";
	  bgObj.style.width=sWidth + "px";
	  bgObj.style.height=sHeight + "px";
	  bgObj.style.zIndex = "10000";
	  
	  if(navigator.userAgent.indexOf("MSIE")!=-1)
	  {
	  	  index=navigator.userAgent.indexOf("MSIE");
	  if(navigator.userAgent.substring(index+4,index+3)<"7.0")
	  {
		 bgObj.innerHTML='<iframe frameborder="0" style="width:100%;height:100%;"></iframe>';
		  }
	  }
	      
	  document.body.appendChild(bgObj);
	   
	  var msgObj=document.createElement("div")
	  msgObj.setAttribute("id","msgDiv");
	  msgObj.setAttribute("align","center");
	  msgObj.style.background="white";
	  msgObj.style.border="1px solid " + bordercolor;
	  msgObj.style.position = "absolute";
	  msgObj.style.left = "50%";
	  msgObj.style.top = document.body.scrollTop+300+"px";
	  msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
	  msgObj.style.marginLeft = "-225px" ;
	  msgObj.style.width = msgw + "px";
	  msgObj.style.height =msgh + "px";
	  msgObj.style.textAlign = "center";
	  msgObj.style.lineHeight ="25px";
	  msgObj.style.zIndex = "10001";
	  var title=document.createElement("h4");
	  title.setAttribute("id","msgTitle");
	  title.setAttribute("align","left");
	  title.style.margin="0";
	  title.style.padding="3px";
	  title.style.background=bordercolor;
	  title.style.border="1px solid " + bordercolor;
	  title.style.height=titleheight+"px";
	  title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
	  title.style.color="white";
	  title.style.cursor="pointer";
	  title.innerHTML=(Title==null?"Confirm:":Title+":");
	 
	  var txt=document.createElement("p");
	  txt.style.margin="1em 0"
	  txt.setAttribute("id","msgTxt");
	  
	  iCounter = 0;
	  txt.innerHTML=iCounter;
	  StopWatchStart();
	  
	
	var BtnBlock=document.createElement("table")
	BtnBlock.setAttribute("border","0px");
	BtnBlock.setAttribute("cellPadding","0px");
	BtnBlock.setAttribute("cellSpacing","0px");
	BtnBlock.style.width="100%";
	BtnBlock.style.height="20px";
	BtnBlock.style.marginTop="0px";
	
	var btnOK=document.createElement("button");
	btnOK.innerHTML="Ok";
	btnOK.style.backgroundColor="#ffffff";
	btnOK.style.height="20px";
	btnOK.style.textAlign="center";
	btnOK.style.display="block";
	btnOK.style.width="60px";
	btnOK.style.color=bordercolor;
	btnOK.style.border="1px solid " + bordercolor;
	btnOK.style.cursor="pointer";
	btnOK.style.lineHeight="18px";
	btnOK.onclick=function(){
	     document.body.removeChild(bgObj);
	     window.onscroll=null;
	     document.body.removeChild(msgObj);
	     StopWatchStop();
		if( ConfirmHandle!= null ||ConfirmHandle!= undefined )
		{
			eval("try{"+ConfirmHandle+"}catch(e){}");
		}
	}
	var btnCancel=document.createElement("button");
	btnCancel.innerHTML="Cancel";
	btnCancel.style.backgroundColor="#ffffff";
	btnCancel.style.height="20px";
	btnCancel.style.textAlign="center";
	btnCancel.style.display="block";
	btnCancel.style.width="60px";
	btnCancel.style.color=bordercolor;
	btnCancel.style.border="1px solid " + bordercolor;
	btnCancel.style.cursor="pointer";
	btnCancel.style.lineHeight="18px";
	btnCancel.onclick=function(){
						     document.body.removeChild(bgObj);
						     window.onscroll=null;
						     document.body.removeChild(msgObj);
						     StopWatchStop();
							if( CancelHandle != null || CancelHandle != undefined )
							{
									eval("try{"+CancelHandle+"}catch(e){}");
							}
					}
	btnOK.style.marginLeft="85";
	btnCancel.style.marginLeft="65";
	var tr = document.createElement("tr");
	var td1 = document.createElement("td");
	var td2 = document.createElement("td");
	td1.style.width="50%";
	td2.style.width="50%";
	
	td1.appendChild(btnOK);
	td2.appendChild(btnCancel);
	tr.appendChild(td1);
	tr.appendChild(td2);
	var tbody=document.createElement("tbody");
	tbody.appendChild(tr);
	BtnBlock.appendChild(tbody);
	
	msgObj.appendChild(title);
	msgObj.appendChild(txt);
	msgObj.appendChild(BtnBlock);
	document.body.appendChild(msgObj);
	btnOK.focus();

}

function StopWatchStart(){
	handle = setInterval("Counter()",1000);
}

function StopWatchStop(){
	clearInterval(handle);
}

function Counter(){
	iCounter += 1;
	document.all.msgTxt.innerHTML = ""+iCounter+"";
}

function httprequest(url,requesthandle)
{
	var element = document.createElement("script");
    element.src = url;
    element.type = "text/javascript";
    element.language = "javascript";
	if(document.all)
	{
        element.onreadystatechange = function()
        {
             var state = element.readyState;
             if (state == "loaded" || state == "interactive" || state == "complete")
             {
                 requesthandle();
                 document.body.removeChild(element);
             }
        }
	}
	else 
	{
        element.onload = function()
        {
           requesthandle();
           document.body.removeChild(element);
        }
    }
   document.body.appendChild(element);
}
function checklength(obj,length)
{
	if(obj.value.length>length)
	{
		obj.value=obj.value.substring(0,length);
	}
}
function getPos(obj)
{
    var offset = {top:0,left:0};
    offset.top = obj.offsetTop;
    offset.left = obj.offsetLeft;
    if(obj.offsetParent != null) 
    {
       offset.left += getPos(obj.offsetParent).left;
       offset.top += getPos(obj.offsetParent).top;
    }
    return offset;
}
function getUrlPara(url, name) 
{     
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");       
    if (reg.test(url)) 
    {
        return unescape(RegExp.$2.replace(/\+/g, " ")); 
    }
    else
    {
        return ""; 
    }
}
function checkString(source, allowAllSpace, maxLength)
{
    if(source == null)
    {
        return false;
    }
    if(allowAllSpace == null)
    {
        allowAllSpace = true;
    }
    var sourceString;
    if(typeof(source) == "object")
    {
        source.value = source.value.replace(/(^\s*)|(\s*$)/g, ""); 
        sourceString = source.value;
    }
    if(maxLength != null)
    {
        sourceString = sourceString.substring(0, maxLength - 1);
        source.value = sourceString;
    }
    if(!allowAllSpace && sourceString.length == 0)
    {
        return false;
    }
    return /^(?:[\u4e00-\u9fa5]*\w*\s*)+$/.test(sourceString);
}
function checkNumber(sourceString, nemberMax)
{
    try
    {
        var num = parseFloat(sourceString);
        if(nemberMax != null)
        {
            return num <= nemberMax;
        }
        return num >= 0;
    }
    catch(e)
    {
        //e.message
        return false;
    }
}