﻿// JavaScript Document
//本脚本程序是由杨懿制作，未经允许不得转载，如有转载请保留此注释 网址：www.coyer.cn

function WebControl(){
	var pid="";
	var stype="checkbox";
	var createById="false";
	var SizeW="0";
	var SizeH="0";
	var val="";
	var id="";
	var txt="";
	var state="false";

	var forecolor="#000000";
	var listval="";
	
	this.add=function(value,text){
		if(listval==""){
			listval=value + String.fromCharCode(0) + text;
		}else{
			listval+= String.fromCharCode(1) + value + String.fromCharCode(0) + text;
		}
	},
	
	this.clear=function(){
		listval="";
	},
	
	this.setColor=function(value){
		forecolor=value;
	},
	
	this.setState=function(value){	//对Radio有效
		state=value;
	},
	
	this.setText=function(value){	//对CheckBox、Radio、Select有效
		txt=value;
	},
	
	this.setValue=function(value){	//对所有控件有效、设置值
		val=value;
	},
	
	this.setId=function(value){		//对所有控件有效，设置 ID
		id=value;
	},
	
	this.setControlType=function(value){	//设置控件类型
		stype=value;
	},
	
	this.setParentId=function(value){		//设置父元素
		pid=value;
	},
	
	this.setWidth=function(value){			//对select、Upload 有效
		SizeW=value;
	},
	
	this.setHeight=function(value){			//对select、Upload 有效
		SizeH=value;
	},
	
	function getState(){
		return state;
	},
	
	function getCode(){
		var ret="";	
		
		switch(stype){
			case "checkbox":
				ret=getCheckBox();
				break;
			case "radiobox":
				ret=getRadioBox();
				break;
			case "select":
				ret=getDropList();
				break;
			case "upload":
				break;
			default:
				break;
		}
		
		return ret;
	},
	
	function getCheckBox(){
		var ret="<div style=\"cursor:hand; width:auto\" onmouseover=\"this.childNodes[0].childNodes[0].src=(this.childNodes[2].value==''?'images/check03.png':'images/check04.png');\" onmouseout=\"this.childNodes[0].childNodes[0].src=(this.childNodes[2].value==''?'images/check01.png':'images/check02.png');\" onclick=\"this.childNodes[0].childNodes[0].src=(this.childNodes[2].value==''?'images/check02.png':'images/check01.png');this.childNodes[2].value=((this.childNodes[0].childNodes[0].src.indexOf('check01.png')>=0 || this.childNodes[0].childNodes[0].src.indexOf('check03.png')>=0)?'':'"+ val +"');\"><div id=\"box\" style=\"float:left; width:13px; height:14px; text-align:center\"><img src=\""+ (getState()=="true"?"images/check02.png":"images/check01.png") +"\"></div><div id=\"text\" style=\"float:left; font-size:9pt; padding-left:3px; padding-top:1px\">"+  (txt!=""?"<a href=\"javascript:void(0)\" style=\"text-decoration:none;color:"+ forecolor +"; width:auto;height:auto\">"+ txt +"</a>":"") +"</div><input type=\"hidden\" name=\""+ id +"\" id=\""+ id +"\" value=\""+ (getState()=="true"?val:"") +"\" /></div>";
		
		return ret;
	},
	
	function getRadioBox(){
		var ret="<div onselectstart=\"return false\" style=\"cursor:hand; width:auto\" onmouseover=\"if(this.childNodes[2].value=='false'){this.childNodes[0].childNodes[0].src='images/radio03.png';}else{this.childNodes[0].childNodes[0].src='images/radio04.png';}\" onmouseout=\"if(this.childNodes[2].value=='false'){this.childNodes[0].childNodes[0].src='images/radio01.png';}else{this.childNodes[0].childNodes[0].src='images/radio02.png';}\" onclick=\"var bro=document.getElementsByName('"+ id +"');if(null!=bro && undefined!=bro){for(var i=0;i<bro.length;i++){bro[i].value='false';}} var img=document.getElementsByName('img"+ id +"');if(null!=img && undefined!=img){for(var i=0;i<img.length;i++){img[i].src='images/radio01.png';}} this.childNodes[0].childNodes[0].src=(this.childNodes[0].childNodes[0].src.indexOf('radio01.png')>=0?'images/radio02.png':'images/radio01.png');this.childNodes[2].value=(this.childNodes[2].value=='false'?'true':'false');\" onmousedown=\"if(this.childNodes[2].value=='false'){this.childNodes[0].childNodes[0].src='images/radio01.png';}else{this.childNodes[0].childNodes[0].src='images/radio02.png';}\"><div id=\"box\" style=\"float:left; width:13px; height:14px; padding-top:2px; font-size:10pt; text-align:center\"><img name=\"img"+ id +"\" src=\""+ (getState()=="true"?"images/radio02.png":"images/radio01.png") +"\"></div><div id=\"text\" style=\"float:left; font-size:9pt; padding-left:3px; padding-top:2px\"><a href=\"javascript:void(0)\" style=\"text-decoration:none; color:"+ forecolor +"\">"+ txt +"</a></div><input type=\"hidden\" name=\""+ id +"\" id=\""+ id +"\" value=\""+getState()+"\" /></div>";
		return ret;
	},
	
	function getDropList(){
		var lst=getList();
		var ret="<div style=\"height:18px; cursor:hand; background:#FFFFFF; z-index:1; width:"+ SizeW +"px; border:1px solid #979797; position:relative\" onmouseover=\"if(this.childNodes[3].style.display=='none'){this.childNodes[1].childNodes[0].src='images/select02.png'}\" onmousedown=\"this.childNodes[1].childNodes[0].src='images/select03.png'\" onmouseout=\"if(this.childNodes[3].style.display=='none'){this.childNodes[1].childNodes[0].src='images/select01.png'}\" onmouseup=\"if(this.childNodes[3].style.display==''){this.childNodes[1].childNodes[0].src='images/select02.png'}\" onclick=\"var drop=document.getElementsByTagName('div'); if(null!=drop && undefined!=drop){for(var i=0;i<drop.length;i++){if(drop[i].id=='selectdrop'){drop[i].style.display='none'}}} var bh=parseInt((document.documentElement.clientHeight == 0) ? document.body.clientHeight : document.documentElement.clientHeight);var sh=parseInt((document.documentElement.scrollTop == 0) ? document.body.scrollTop : document.documentElement.scrollTop);if((parseInt(this.offsetHeight)+parseInt(this.offsetTop))+120-sh>bh){this.childNodes[3].style.top=String(-122) + 'px';}else{this.childNodes[3].style.top=String(this.offsetHeight-2+document.body.scrollTop) + 'px'};this.childNodes[3].style.display=(this.childNodes[3].style.display==''?'none':'')\">    	<div id=\"box\" style=\"float:left; width:"+ String(parseInt(SizeW)-22) +"px; height:15px; padding-top:2px ; padding-left:3px; font-size:9pt; text-overflow: ellipsis; overflow: hidden;white-space: nowrap;\">"+ txt +"</div><div id=\"text\" style=\"float:left;border:1px #FFFFFF solid; width:17px; height:16px;padding-top:0px\"><img id=\"droparray\" src=\"images/select01.png\" /></div><input type=\"hidden\" name=\""+ id +"\" id=\""+ id +"\" value=\"" + val + "\" /><div style=\"position:absolute; background:white; width:"+ SizeW +"px; height:120px; border:1px solid #979797; overflow:scroll; overflow-x:hidden;overflow-y:auto; left:-1px; display:none;SCROLLBAR-FACE-COLOR: #f6f6f6; FONT-SIZE: 9pt; SCROLLBAR-HIGHLIGHT-COLOR: #ffffff; SCROLLBAR-SHADOW-COLOR: #cccccc; SCROLLBAR-3DLIGHT-COLOR: #cccccc; SCROLLBAR-ARROW-COLOR: #330000; SCROLLBAR-TRACK-COLOR: #f6f6f6; SCROLLBAR-DARKSHADOW-COLOR: #ffffff;\" id=\"selectdrop\">"+ lst +"</div></div>";
	
		return ret;
	},
	
	function getList(){
		var ret="";
		if(listval==""){
			return "";
		}
		
		var items=listval.split(String.fromCharCode(1));
		
		for(var i=0;i<items.length;i++){
			var ex=items[i].split(String.fromCharCode(0));
			
			ret += "<div style=\"font-size:9pt; position:relative; left:0px; padding-left:2px; padding-top:2px; border:1px solid #FFFFFF \" onmousedown=\"var root=this.parentNode.parentNode; root.childNodes[2].value='"+ ex[0] +"'; root.childNodes[0].innerHTML=this.innerHTML; this.parentNode.style.display='none'\" onmouseover=\"this.style.backgroundColor='#b2ddfa'; this.style.border='1px solid #64b3e8'\" onmouseout=\"this.style.backgroundColor=''; this.style.border='1px solid #ffffff'\">"+ ex[1] +"</div>"
		}
		
		return ret;
	},
	
	this.closeDrop=function(){
		var drop=document.getElementsByTagName('div'); 
		if(null!=drop && undefined!=drop){
			for(var i=0;i<drop.length;i++){
				if(drop[i].id=='selectdrop'){
					drop[i].style.display='none'
				}
			}
		}
		
		drop=document.getElementsByTagName('img'); 
		if(null!=drop && undefined!=drop){
			for(var i=0;i<drop.length;i++){
				if(drop[i].id=='droparray'){
					drop[i].src='images/select01.png'
				}
			}
		}
	},
	
	this.create=function(){
		var objParent=null;
		
		if(""!=this.pid){
			objParent=document.getElementById(pid);
			
			if(null==objParent || undefined==objParent){
				createById="false";
			}else{
				createById="true";
			}
		}else{
			createById="false";
		}
		
		if(createById=="false"){
			document.write(getCode());
		}else{
			objParent.innerHTML=getCode();
		}
	},
	
	this.getSource=function(){
		return getCode();
	}
}

function TreeView(){
	var m_source="";
	var m_loadmode="0";
	var m_checkbox="false";
	var m_line="true";
	var m_rootcaption="";
	var m_explandAll="true";
	var doc=null;
	var seq=0;
	var formitem=new WebControl();
	var listtype="none";
	var m_width="100%";
	var m_formname ="treeviewcheckbox";
	
	this.checkName=function(value){
		m_formname=value;
	},
	
	//formitem.setState("false");
	this.width=function(value){
		m_width=value;
	},
	
	this.source=function(value){
		m_source=value;
	},
	
	this.checkMode=function(value){
		listtype=value;
	},
	
	this.mode=function(value){
		m_loadmode=value;
	},
	
	this.load=function(){
		try{
			doc = new ActiveXObject("Msxml2.DOMDocument.3.0"); 
			if(m_loadmode=="1"){
				doc.async=false;
				doc.loadXML(m_source);
			}else{
				doc.load(m_source);
			}
			
			return true;
		}catch(e){
			//alert(e.message);
			return false;
		}
	},
	
	this.create=function(){
		var html="";
		
		formitem.setControlType(listtype);
		formitem.setId(m_formname);
	
		try{
			var n=doc.getElementsByTagName("root")[0];
			
			//m_checkbox = n.getAttribute("checkbox");
			//m_line = n.getAttribute("line");
			m_rootcaption=n.getAttribute("text");
			
			html="<div id=\"root\">";
			html+="<div id=\"caption\">"+ m_rootcaption +"</div>";
			html+=enumSub(n);
			html+="</div>";
			
			document.write(html);
		}catch(e){
			
		}
	},
	
	this.getSource=function(){
		var html="";
		
		formitem.setControlType(listtype);
		formitem.setId(m_formname);
	
		try{
			var n=doc.getElementsByTagName("root")[0];
			
			//m_checkbox = n.getAttribute("checkbox");
			//m_line = n.getAttribute("line");
			m_rootcaption=n.getAttribute("text");
			
			html="<div id=\"root\">";
			html+="<div id=\"treecaption\"><a>"+ m_rootcaption +"</a></div>";
			html+=enumSub(n);
			html+="</div>";
			
			return html;
		}catch(e){
			return "";
		}
	},
	
	function enumSub(obj){
		var ret="";
		var n=obj.childNodes;
		
		for(var i=0;i<n.length;i++){
			var nx=n[i].childNodes;
			seq++;
			
			formitem.setText("");
			formitem.setValue(n[i].getAttribute("value"));
			formitem.setState(n[i].getAttribute("checked"));
			
			ret+="<div id=\"item"+ String(seq) +"\" style=\"width:"+ m_width +"\"><div id=\"line\" style=\"float:left; width:40px; background:url(images/icon"+ (i<n.length-1?(nx.length<=0?"25":(m_explandAll=="true"?"25b":"25a")):(nx.length<=0?"26":(m_explandAll=="true"?"26b":"26a"))) +".gif) no-repeat 20px top; height:21px\"></div><div id=\"treetext\" style=\"float:left; height:20px\"><nobr>"+ (n[i].getAttribute("style")=="checkbox"?formitem.getSource():"<img src=\""+ n[i].getAttribute("src") +"\" style=\"float:left\">") +"<a " + (n[i].getAttribute("style")!="checkbox"?"style=\"padding-top:2px; float:left;width:auto; height:15px; padding-left:1px\" href=\"javascript:void(0)\"":"style=\"float:left\"")+ " onclick=\"var pnd=document.getElementById('subitem"+ String(seq) +"');if(null!=pnd && undefined!=pnd){pnd.style.display=(pnd.style.display==''?'none':'');var fChild=this.parentNode.parentNode.parentNode.childNodes[0];fChild.style.background='url(images/icon' + (pnd.style.display==''?'"+ (i<n.length-1?"25b":"26b") +"':'"+ (i<n.length-1?"25a":"26a") +"') + '.gif) no-repeat 20px top'}\">" + n[i].getAttribute("text") +"</a></nobr></div></div>";
			
			if(nx.length>0){
				if(i<n.length-1){
					ret +="<div id=\"subitem"+ String(seq) +"\" style=\"width:100%; height:auto;background:url(images/icon27.gif) repeat-y 24px top; padding-left:40px;"+ (m_explandAll=="true"?"":"display:none") +"\">";
				}else{
					ret +="<div id=\"subitem"+ String(seq) +"\" style=\"width:100%; height:auto; padding-left:40px;"+ (m_explandAll=="true"?"":"display:none") +"\">";
				}
				ret += enumSub(n[i]);
				ret +="</div>";
			}
		}
		
		return ret;
	}
}

function LoginWindow(){
    var obj1=undefined;
    var obj2=undefined;
    
    this.showLogin=function(){
        var html="<iframe src=\"loginwindow.aspx\" width=\"409\" frameborder=\"0\" height=\"360\" border=\"0\" id=\"popupframe\"></iframe>";
        this.MYalertOk();
	    var pl=parseInt((document.documentElement.clientWidth == 0) ? document.body.clientWidth : document.documentElement.clientWidth);
        var pt=parseInt((document.documentElement.clientHeight == 0) ? document.body.clientHeight : document.documentElement.clientHeight);
        var st=parseInt((document.documentElement.scrollTop ==0) ? document.body.scrollTop : document.documentElement.scrollTop);
        
	    obj1=document.createElement('<div id="a"   style="position:absolute;filter:alpha(opacity=50);background-color:#FFFFFF;top:0px;left:0px;width:'+String(pl)+'px;height:'+String(pt + st)+'px;z-index:10000" onselectstart="return false" oncontextmenu="return false"></div>');   
	    var str='<div   align="center" id="floatwindow" style="filter:alpha(opacity=100);position:absolute;z-index:10001;top:'+String(parseInt((pt-360 )/2 + st))+'px;left:'+String(parseInt((pl-409)/2))+'px;width:409px;height:360px;font-size:9pt;line-height:30px"></div>';  
	    obj2=document.createElement(str);
    	
	    obj2.innerHTML=html;
    	
	    document.body.appendChild(obj1);   
	    document.body.appendChild(obj2);
	    
	    var oFrame=document.getElementById("popupframe");
	    
	    if(undefined != oFrame){
	        eval("window.popupframe.document.location.reload();");
	    }
    },
    
    this.MYalertOk=function(){ 
	    if(obj1!=undefined){
		    document.body.removeChild(obj1);   
	    }
	    
	    if(obj2!=undefined){
		    document.body.removeChild(obj2);
	    }
    	
	    obj1=undefined;
	    obj2=undefined;
    },
    
    this.checkForm=function(obj){
        if(obj.username.value==""){
            alert("请输入登录帐号！");
            obj.username.focus();
            return false;
        }
        
        if(obj.password.value.length<6 || obj.password.value.length>18){
            alert("请输入登录密码！");
            obj.username.select();
            obj.username.focus();
            
            return false;
        }
        
        if(obj.keycode.value==""){
            alert("请输入验证码！");
            obj.keycode.focus();
            return false;
        }
        
        var ret=this.postData("process.aspx","act=login&username=" + obj.username.value + "&password=" + obj.password.value + "&keycode=" + obj.keycode.value);
        
        if(ret=="0"){
            parent.document.location.reload();
        }else{
            alert(ret);
            
            return false;
        }
    },
    
    this.postData=function(url,args){    
        var xmlObj=new ActiveXObject("MSXML2.XMLHttp");
    	
        xmlObj.open("post",url,false);
        xmlObj.setRequestHeader("Content-Length",args.length);
        xmlObj.setRequestHeader("Cache-Control","no-cache");
        xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlObj.send(encodeURI(args));
    	
        return xmlObj.responseText;
    }
}

function TextEffect(){
    var mObj=new Array();
    var TWND=0;
    var nColor = "#FF0000";
    var oColor = new Array();
    var bChange = false;
    
    this.load=function(obj){
        if(undefined == obj){
            return false;
        }
        
        mObj=obj;
        
        for(var i=0; i<mObj.length; i++){
            var oDiv=document.getElementById(mObj[i]);
            
            if(oDiv != undefined){
                oColor[i]=oDiv.style.color==""?"#000000":oDiv.style.color;   
            }
        }
        
        return true;
    },
    
    this.blink=function(){
        if(undefined == mObj ){
            return;
        }
        
        if(mObj.length<=0){
            return;
        }
        
        TWND=setInterval("changeColor()",3000);
    },
    
    this.stop=function(){
        clearInterval(TWND);
    },
    
    this.changeColor=function(){
        for(var i=0; i<mObj.length; i++){
            var oDiv=document.getElementById(mObj[i]);
            
            if(oDiv != undefined){
                if(!bChange){
                    oDiv.style.color = nColor;
                }else{
                    oDiv.style.color = oColor[i];
                }
            }
        }
        
        bChange=!bChange;
    },
    
    this.setColor=function(value){
        nColor = value;
    }
}
