// JavaScript Document
function $(elementId){ 
	if (document.getElementById) {  
		return document.getElementById(elementId); 
	}else if(document.all) {  
		return document.all[elementId]; 
	}else if(document.layers) {  
		return document.layers[elementId]; 
	}
} 

function Refresh(url){
	 if(url!=undefined){
		parent.frames['My_Iframe'].window.location=url;	
	}else{ 
		parent.frames['My_Iframe'].window.location.reload();	
	}
}

function seekFolder(target0,target1){
	if (target1!=undefined||target1!=null){
		temp=$(target0).value
		var tmp="";
		astr=temp.split("\\");
		j=astr.length - 1;
		for(i=0;i<j+1;i++){
		 tmp=tmp+astr[i]+"\\";
		}
		$(target1).value=tmp.substring(0,tmp.length-1);
	}
}

function Go(url){
	switch(url){
		case "1-1-1":
			Refresh("CMS_Config.Asp");
			break;
		case "2-1-1":
			Refresh("CMS_CommPages.Asp?ID=1");
			break;
		case "2-1-2":
			Refresh("CMS_CommPages.Asp?ID=2");
			break;
		case "2-1-3":
			Refresh("CMS_CommPages.Asp?ID=3");
			break;
		case "2-1-4":
			Refresh("CMS_CommPages.Asp?ID=4");
			break;
		case "2-2-1":
			Refresh("CMS_ContentList.Asp?ID=1");
			break;
		case "2-2-2":
			Refresh("CMS_ContentEdit.Asp?Action=Add&ID=1");
			break;
		case "2-3-1":
			Refresh("CMS_ContentList.Asp?ID=2");
			break;
		case "2-3-2":
			Refresh("CMS_ContentEdit.Asp?Action=Add&ID=2");
			break;
		case "2-4-1":
			Refresh("CMS_LinksList.Asp");
			break;
		case "2-4-2":
			Refresh("CMS_LinksEdit.Asp?Action=Add");
			break;
		case "2-4-3":
			Refresh("CMS_CommPages.Asp?ID=5");
			break;
		case "3-1-1":
			Refresh("CMS_TestList.Asp");
			break;
		case "3-1-2":
			Refresh("CMS_TestEdit.Asp?Action=Add");
			break;
		case "3-1-3":
			Refresh("CMS_DelTestList.Asp");
			break;
	}
}

function getPosi(Id){
	Id="tempTbl";
	var width1=$(Id).style.width;
	getWidth=width1.substring(0,(width1.length-2)); 
	getPosi=(385-getWidth/2)+"px";
	return getPosi;
}
function init(){
	if($("tempDiv")!=undefined){
		$("tempDiv").style.left=getPosi();
		$("tempDiv").style.top=30+"px";
	}
}

function SetPage(n){
ajax.get("Functions/Kernel.Asp?Action=SetPage&JPagesize="+n,function(obj){Refresh();});
}

function getNewsById(id){ 
	ajax.get("CMS_News.Asp?Action=getNewsCate&ID="+id,function(obj){//$("getInfo").innerHTML=(obj.responseText);
		var tempArr=obj.responseText.split("|");
		if(tempArr[0]!="Error"){
				$("Cate_Text0").value=id;
				$("Cate_Text1").value=tempArr[1];
				$("Cate_Text2").value=tempArr[2];
				$("Cate_Text3").value=tempArr[3];
		}else{
				$("Cate_Text0").value=0;
				$("Cate_Text1").value="";
				$("Cate_Text2").value="";
				$("Cate_Text3").value="";
		}
		$("tempDiv").style.display="block";																  
	})	
}

function closeDiv(){
	if($("tempDiv")!=undefined){
	$("tempDiv").style.display='none';	
	}
}

  
function myMenu(N){
	if($("ChildNode"+N).style.display=='none'){
		$("ChildIcon"+N).className='liIcon';
		$("ChildNode"+N).style.display='block';
	}else{
		$("ChildIcon"+N).className='liIcon_';
		$("ChildNode"+N).style.display='none';
	}
}
function LetsGo(M){
	for (var i=1;i<10;i++){
		if($("Navi"+i)!=undefined){
			if(i==M){
				$("Navi"+i).className="Navi_li1"; 
			}else{
				$("Navi"+i).className="Navi_li2";
			}
		}
	}
	for (var i=1;i<10;i++){
		if($("LeftMenu"+i)!=undefined){
			if(i==M){
				$("LeftMenu"+i).style.display="block"; 
			}else{
				$("LeftMenu"+i).style.display="none";
			}
		}
	}
}
function AJAXRequest() {
	var xmlPool=new Array,AJAX=this,ac=arguments.length,av=arguments;
	var xmlVersion = ["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
	var nullfun=function(){return;};
	var av=ac>0?typeof(av[0])=="object"?av[0]:{}:{};
	var encode=av.charset?av.charset.toUpperCase()=="UTF-8"?encodeURIComponent:escape:encodeURIComponent;
	this.url=av.url?av.url:"";
	this.oncomplete=av.oncomplete?av.oncomplete:nullfun;
	this.content=av.content?av.content:"";
	this.method=av.method?av.method:"POST";
	this.async=av.async?async:true;
	this.onexception=av.onexception?av.exception:nullfun;
	this.ontimeout=av.ontimeout?av.ontimeout:nullfun;
	this.timeout=av.timeout?av.timeout:3600000;
	if(!getObj()) return false;
	function getObj() {
		var i,tmpObj;
		for(i=0;i<xmlPool.length;i++) if(xmlPool[i].readyState==0||xmlPool[i].readyState==4) return xmlPool[i];
		try { tmpObj=new XMLHttpRequest; }
		catch(e) {
			for(i=0;i<xmlVersion.length;i++) {
				try { tmpObj=new ActiveXObject(xmlVersion[i]); } catch(e2) { continue; }
				break;
			}
		}
		if(!tmpObj) return false;
		else { xmlPool[xmlPool.length]=tmpObj; return xmlPool[xmlPool.length-1]; }
	}
	function $(id) { return document.getElementById(id); }
	function varobj(val) {
		if(typeof(val)=="string") {
			if(val=$(val)) return val;
			else return false;
		}
		else return val;
	}
	this.setcharset=function(cs) {
		if(cs.toUpperCase()=="UTF-8") encode=encodeURIComponent;
		else encode=escape;
	}
	this.send=function() {
		var purl,pc,pcbf,pm,pa,ct,ctf=false,xmlObj=getObj(),ac=arguments.length,av=arguments;
		if(!xmlObj) return false;
		purl=ac>0?av[0]:this.url;
		pc=ac>1?av[1]:this.content;
		pcbf=ac>2?av[2]:this.oncomplete;
		pm=ac>3?av[3].toUpperCase():this.method;
		pa=ac>4?av[4]:this.async;
		if(!pm||!purl||!pa) return false;
		var ev={url:purl, content:pc, method:pm};
		purl+=(purl.indexOf("?")>-1?"&":"?")+Math.random();
		xmlObj.open(pm,purl,pa);
		if(pm=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ct=setTimeout(function(){ctf=true;xmlObj.abort();},AJAX.timeout);
		xmlObj.onreadystatechange=function() {
			if(ctf) AJAX.ontimeout(ev);
			else if(xmlObj.readyState==4) {
				ev.status=xmlObj.status;
				try{ clearTimeout(ct); } catch(e) {};
				try{
					if(xmlObj.status==200) pcbf(xmlObj);
					else AJAX.onexception(ev);
				}
				catch(e) { AJAX.onexception(ev); }
			}
		}
		if(pm=="POST") xmlObj.send(pc); else xmlObj.send("");
	}
	this.get=function() {
		var purl,pcbf,ac=arguments.length,av=arguments;
		purl=ac>0?av[0]:this.url;
		pcbf=ac>1?av[1]:this.oncomplete;
		if(!purl&&!pcbf) return false;
		this.send(purl,"",pcbf,"GET",true);
	}
	this.update=function() {
		var purl,puo,pinv,pcnt,rinv,ucb,ac=arguments.length,av=arguments;
		puo=ac>0?av[0]:null;
		purl=ac>1?av[1]:this.url;
		pinv=ac>2?(isNaN(parseInt(av[2]))?1000:parseInt(av[2])):null;
		pcnt=ac>3?(isNaN(parseInt(av[3]))?null:parseInt(av[3])):null;
		if(puo=varobj(puo)) {
			ucb=function(obj) {
				var nn=puo.nodeName.toUpperCase();
				if(nn=="INPUT"||nn=="TEXTAREA") puo.value=obj.responseText;
				else try{puo.innerHTML=obj.responseText;} catch(e){};
			}
		}
		else ucb=nullfun;
		if(pinv) {
			AJAX.send(purl,"",ucb,"GET",true);
			if(pcnt&&--pcnt) {
				var cf=function(cc) {
					AJAX.send(purl,"",ucb,"GET",true);
					if(cc<1) return; else cc--;
					setTimeout(function(){cf(cc);},pinv);
				}
				setTimeout(function(){cf(--pcnt);},pinv);
			}
			else return(setInterval(function(){AJAX.send(purl,"",ucb,"GET",true);},pinv));
		}
		else this.send(purl,"",ucb,"GET",true);
	}
	this.post=function() {
		var purl,pcbf,pc,ac=arguments.length,av=arguments;
		purl=ac>0?av[0]:this.url;
		pc=ac>1?av[1]:"";
		pcbf=ac>2?av[2]:this.oncomplete;
		if(!purl&&!pcbf) return false;
		this.send(purl,pc,pcbf,"POST",true);
	}
	this.postf=function() {
		var fo,pcbf,purl,pc,pm,ac=arguments.length,av=arguments;
		if(!(fo=ac>0?av[0]:null)) return false;
		if(fo=varobj(fo)) {
			if(fo.nodeName!="FORM") return false;
		}
		else return false;
		pcbf=ac>1?av[1]:this.oncomplete;
		purl=ac>2?av[2]:(fo.action?fo.action:this.url);
		pm=ac>3?av[3]:(fo.method?fo.method.toUpperCase():"POST");
		if(!pcbf&&!purl) return false;
		pc=this.formToStr(fo);
		if(!pc) return false;
		if(pm) {
			if(pm=="POST") this.send(purl,pc,pcbf,"POST",true);
			else if(purl.indexOf("?")>0) this.send(purl+"&"+pc,"",pcbf,"GET",true);
				else this.send(purl+"?"+pc,"",pcbf,"GET",true);
		}
		else this.send(purl,pc,pcbf,"POST",true);
	} 
	this.formToStr=function(fc) {
		var i,qs="",and="",ev="";
		for(i=0;i<fc.length;i++) {
			e=fc[i];
			if (e.name!='') {
				if (e.type=='select-one'&&e.selectedIndex>-1) ev=e.options[e.selectedIndex].value;
				else if (e.type=='checkbox' || e.type=='radio') {
					if (e.checked==false) continue;
					ev=e.value;
				}
				else ev=e.value;
				ev=encode(ev);
				qs+=and+e.name+'='+ev;
				and="&";
			}
		}
		return qs;
	}
}

function DivDrag()
{
    this.Move=function(Id,Evt,T)
    {
        if(Id=="") return;
        var o = $(Id);
        if(!o) return;
        evt = Evt ? Evt : window.event;
        o.style.position = "absolute";
        o.style.zIndex = 200;
        var obj = evt.srcElement ? evt.srcElement : evt.target;
        var w = o.offsetWidth;
        var h = o.offsetHeight;
        var l = o.offsetLeft;
        var t = o.offsetTop;
        var div = document.createElement("DIV");
        document.body.appendChild(div);
        div.style.cssText = "filter:alpha(Opacity=10,style=0);opacity:0.2;width:"+w+"px;height:"+h+"px;top:"+(t)+"px;left:"+(l)+"px;position:absolute;background:#000";
        div.setAttribute("id", Id +"temp");
        
        if(T)
        {
            this.Move_OnlyMove(Id,evt);
        }
        else
        {
            
        }
    }
	
    this.Move_OnlyMove = function(Id,Evt)
    {
        var o = $(Id+"temp");
        if(!o) return;
        evt = Evt?Evt:window.event;
        var relLeft = evt.clientX - o.offsetLeft;
        var relTop = evt.clientY - o.offsetTop;

        if (!window.captureEvents)
        {
            o.setCapture(); 
        
        }
        else
        {
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
        }
        
        document.onmousemove = function(e)
        {
            if (!o) return;
            e = e ? e : window.event;
            if (e.clientX - relLeft <= 0)
                o.style.left = 0 +"px";
            else if (e.clientX - relLeft >= document.documentElement.clientWidth - o.offsetWidth - 2)
                o.style.left = (document.documentElement.clientWidth - o.offsetWidth - 2) +"px";
            else
                o.style.left = e.clientX - relLeft +"px";
            if (e.clientY - relTop <= 1)
                o.style.top = 1 +"px";
            else if (e.clientY - relTop >= document.documentElement.clientHeight - o.offsetHeight - 30)
                o.style.top = (document.documentElement.clientHeight - o.offsetHeight - 30) +"px";
            else
                o.style.top = e.clientY - relTop +"px";
        }
        
        document.onmouseup = function()
        {
            if (!o) return;
            if (!window.captureEvents)
                o.releaseCapture();
            else
                window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
            var o1 = $(Id);
            if (!o1) return;
            var l0 = o.offsetLeft;
            var t0 = o.offsetTop;
            var l = o1.offsetLeft;
            var t = o1.offsetTop;    
            MyMove.Move_e(Id, l0 , t0, l, t);
            document.body.removeChild(o);
            o = null;
        }    
    }
    
    this.Move_e = function(Id, l0 , t0, l, t)
    {
        if (typeof(window["ct"+ Id]) != "undefined") clearTimeout(window["ct"+ Id]);
        var o = $(Id);
        if (!o) return;
        var sl = st = 8;
        var s_l = Math.abs(l0 - l);
        var s_t = Math.abs(t0 - t);
        if (s_l - s_t > 0)
            if (s_t)
                sl = Math.round(s_l / s_t) > 8 ? 8 : Math.round(s_l / s_t) * 6;
            else
                sl = 0;
        else
            if (s_l)
                st = Math.round(s_t / s_l) > 8 ? 8 : Math.round(s_t / s_l) * 6;
            else
                st = 0;
        if (l0 - l < 0) sl *= -1;
        if (t0 - t < 0) st *= -1;
        if (Math.abs(l + sl - l0) < 52 && sl) sl = sl > 0 ? 2 : -2;
        if (Math.abs(t + st - t0) < 52 && st) st = st > 0 ? 2 : -2;
        if (Math.abs(l + sl - l0) < 16 && sl) sl = sl > 0 ? 1 : -1;
        if (Math.abs(t + st - t0) < 16 && st) st = st > 0 ? 1 : -1;
        if (s_l == 0 && s_t == 0) return;
        if (Math.abs(l + sl - l0) < 2)
            o.style.left = l0 +"px";
        else
            o.style.left = l + sl +"px";
        if (Math.abs(t + st - t0) < 2) 
            o.style.top = t0 +"px";
        else
            o.style.top = t + st +"px";
        window["ct"+ Id] = window.setTimeout("MyMove.Move_e('"+ Id +"', "+ l0 +" , "+ t0 +", "+ (l + sl) +", "+ (t + st) +")", 1);
    }
}
 
var ajax=new AJAXRequest();
var MyMove = new DivDrag();


//¼ì²é¹ÜÀíÔ±µÇÂ¼------------------------------------------------------------------------------
function CheckAdminLogin()
{
   if ($("LoginName").value=="")
   {
	  alert("User Name is not empty.");
      $("LoginName").focus();
	  return false;
   }    
   if ($("LoginPassword").value=="")
   {
	  alert("User Password is not empty.");
	  $("LoginPassword").focus();
	  return false;
   }
   if ($("VerifyCode").value=="")
   {
      alert("Verify Code is not empty.");
      $("VerifyCode").focus();
	  return false;
   }
   return true;
}

