/**************************************************
*                                                 *
* Author  : Windy_sk                              *
* Create  : 2003-05-03                            *
* Modified: 2004-1-9                              *
* Email   : windy_sk@126.com                      *
* HomePage: None (Maybe Soon)                     *
* Notice  : U Can Use & Modify it freely,         *
*           BUT PLEASE HOLD THIS ITEM.            *
*                                                 *
**************************************************/

//if(this.top.location.href.replace(/^(http:\/\/[^\/]+).*$/i,"$1")!=this.location.href.replace(/^(http:\/\/[^\/]+).*$/i,"$1")) top.location.href = location.href;

function reportError(msg, url, line) {
	var str = "You have found an error as below: \n\n";
	str += "Err: " + msg + "on line: " + line;
	//alert(str);
	return true;
}

window.onerror = reportError;

if(typeof(HTMLElement)!="undefined") {
	HTMLElement.prototype.__defineGetter__("innerText",function(){
		var textRange = this.ownerDocument.createRange();
		textRange.selectNodeContents(this);
		return textRange.toString();
	});

	HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
		var r=this.ownerDocument.createRange();
		r.setStartBefore(this);
		var df=r.createContextualFragment(sHTML);
		this.parentNode.replaceChild(df,this);
		return sHTML;
	});

	HTMLElement.prototype.__defineGetter__("outerHTML",function(){
		var attr;
		var attrs=this.attributes;
		var str="<"+this.tagName.toLowerCase();
		for(var i=0;i<attrs.length;i++){
			attr=attrs[i];
			if(attr.specified) str+=" "+attr.name+'="'+attr.value+'"';
		}
		if(!this.canHaveChildren) return str+">";
		return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
	});
		
 HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
		switch(this.tagName.toLowerCase()){
			case "area":
			case "base":
			case "basefont":
			case "col":
			case "frame":
			case "hr":
			case "img":
			case "br":
			case "input":
			case "isindex":
			case "link":
			case "meta":
			case "param":
			return false;
		}
		return true;
	});
}

String.prototype.Tlength = function() {
	var arr=this.match(/[^\x00-\xff]/ig);
	return this.length+(arr==null?0:arr.length);
}

Date.prototype.format = function(format){
/*
eg:format="YYYY-MM-dd hh:mm:ss";
*/
 	var o = {
		"M+" :  this.getMonth()+1,  //month
		"d+" :  this.getDate(),     //day
		"h+" :  this.getHours(),    //hour
		"m+" :  this.getMinutes(),  //minute
		"s+" :  this.getSeconds(), //second
		"q+" :  Math.floor((this.getMonth()+3)/3),  //quarter
		"S"  :  this.getMilliseconds() //millisecond
	}
	if(/(y+)/i.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}
	for(var k in o) {
		if(new RegExp("("+ k +")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
		}
	}
	return format;
}

Array.prototype.copy = function() {
	var copy = new Array();
	for (var i = 0; i < this.length; i++) {
		copy[i] = this[i];
	}
	return copy;
}

Array.prototype.concat = function (secondArray) {
	var firstArray = this.copy();
	if(typeof(secondArray.length)=="undefined" || secondArray.length==0) {
		firstArray[firstArray.length] = secondArray;
	} else {
		for (var i = 0; i < secondArray.length; i++) {
			firstArray[firstArray.length] = secondArray[i];
		}
	}
	return firstArray;
}

var load_function = new Array();
window.onload = function() {
	for(var i=0; i<load_function.length; i++) {
		if(typeof(load_function[i])=="function") load_function[i]();
	}
}

//load functions while page loaded as below
function loadTest() {
	//alert("Page Loaded!");
}
load_function = load_function.concat(loadTest);

function checkBrowser() {
	this.ver = navigator.appVersion;
	this.dom = document.getElementById ? true : false;
	this.ie7 = (this.ver.indexOf("MSIE 7")>-1 && this.dom) ? true : false;
	this.ie6 = (this.ver.indexOf("MSIE 6")>-1 && this.dom) ? true : false;
	this.ie5 = (this.ver.indexOf("MSIE 5")>-1 && this.dom) ? true : false;
	this.ie4 = (document.all && !this.dom) ? true : false;
	this.ns5 = (this.dom && parseInt(this.ver) >= 5 && navigator.appName=="Netscape")  ? true : false;
	this.ns4 = (document.layers && !this.dom) ? true : false;
	this.ff  =  (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1) ? true : false;
	this.saf = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1) ? true : false;
	this.ope = (navigator.userAgent.indexOf('Opera') != -1) ? true : false;
	this.mac = (this.ver.indexOf('Mac') != -1) ? true : false;
	this.ie = (this.ie7 || this.ie6 || this.ie5 || this.ie4);
	this.ns = (this.ns4 || this.ns5 || this.ff);
	this.bw = (this.ie || this.ns || this.mac || this.saf || this.ope);
	this.nbw = (!this.bw);
	this.Moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
	return this;
}

var checker = checkBrowser();

function Get_Pos(the_obj){
	the_top = the_obj.offsetTop;
	the_left = the_obj.offsetLeft;
	while(the_obj=the_obj.offsetParent){
		the_top += the_obj.offsetTop;
		the_left += the_obj.offsetLeft;
	}
	this.top = the_top;
	this.left = the_left;
}

function Get_Obj_2(the_area, the_tag, att_name, att_value){
	var obj_list = new Array();
	var all_Obj = the_area.tags(the_tag);
	if(att_name!=undefined && att_value!=undefined){
		for(var i=0;i<all_Obj.length;i++){
			if(all_Obj[i][att_name].toLowerCase()==att_value.toLowerCase())
				obj_list[obj_list.length]=all_Obj[i];
		}
		return(obj_list);
	}else{
		return(all_Obj);
	}
}

function Get_Obj(the_area){
	var obj_list = new Array();
	var args = Get_Obj.arguments;
	for(var i=1; i<args.length; i++) {
		try {
			obj_list = obj_list.concat(the_area.getElementsByTagName(args[i]));
		} catch(e) {
			obj_list = obj_list.concat(Get_Obj_single(the_area, args[i]));
		}
	}
	return(obj_list);
}

function Get_Obj_single(the_area, tag_name){
	var obj_list = new Array();
	var obj_all = the_area.childNodes;
	for(var i=0; i<obj_all.length; i++) {
		if(typeof(obj_all[i].tagName)=="undefined") continue;
		if(obj_all[i].tagName.toLowerCase()==tag_name.toLowerCase()) {
			obj_list = obj_list.concat(obj_all[i]);
		}
	}
	return(obj_list);
}

function OpenDialog(url,width,height,mode) {
	var sOrnaments = "dialogWidth:"+width+"px;dialogHeight:"+height+"px;center:1;dialogLeft:200;dialogTop:100;dialogHide:0;edge:raised;help:0;resizable:0;scroll:0;status:0;unadorned:0;center:1;";
	var win = null;
	if(checker.ie) {
		if(mode){
			win = window.showModalDialog(url, window, sOrnaments);
		}else{
			win = window.showModelessDialog(url, window, sOrnaments);
		}
	} else {
		win = OpenWindow(url,width,height);
	}
	return win;
}

function OpenWindow(url,width,height) {
	var win = window.open(url, "showIt","height="+height+", width="+width+", top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no, modal=yes");
	return win;
}

function sleep(the_time) {
	var over_time = new Date(new Date().getTime() + the_time);
	while(over_time > new Date()) {}
}

function removeTextNode(xml_obj) {
	if(typeof(xml_obj.childNodes)!="undefined") {
		for(var i=0; i<xml_obj.childNodes.length; i++) {
			if(xml_obj.childNodes[i].nodeType==3) {
				xml_obj.removeChild(xml_obj.childNodes[i]);
				i--;
			}
		}
	}
	return xml_obj;
}

function gotoAnchor(theAnchor) {
	var the_url = location.href;
	if(theAnchor==null) {
		location.href = the_url + "#";
	} else {
		theAnchor = "#" + theAnchor;
		location.href = the_url.replace(/#+\w*$/, "") + theAnchor;
	}
	return false;
}

function copyStr(txt, msg) {
	try {
		window.clipboardData.setData("text",txt);
		alert(msg);
	} catch(e) {
		alert("浏览器不支持此功能!");
	}
	return;
}

function loginCheck() {
	//ajax code for mark
	myAjax.init("TEXT", loginCheckDone, loadingStart, loadingEnd);
	myAjax.get(web_url+"/ajax.php?job=login_check", "");
}

function loginCheckDone(content) {
	if(content.length>50) document.getElementById("user_info").innerHTML = content;
}

function layerShow(obj) {
	obj.style.display = "";
	if(checker.ie) {
		obj.style.top = ((document.documentElement.offsetHeight - obj.offsetHeight)/2 + document.documentElement.scrollTop) + "px";
		obj.style.left = ((document.documentElement.offsetWidth - obj.offsetWidth)/2 + document.documentElement.scrollLeft) + "px";
	} else {
		obj.style.top = ((window.innerHeight - obj.offsetHeight)/2 + document.documentElement.scrollTop) + "px";
		obj.style.left = ((window.innerWidth - obj.offsetWidth)/2 + document.documentElement.scrollLeft) + "px";
	}
}

function login() {
	var theForm = document.getElementById("form_login");
	if(theForm.user_name.value=="") {
		alert("请输入用户名称！");
		theForm.user_name.focus();
	} else if(theForm.user_psw.value=="") {
		alert("请输入用户密码！");
		theForm.user_psw.focus();
	} else if(theForm.check_code.value=="") {
		alert("请输入验证码，如不清楚，请点击图片更换！");
		theForm.check_code.focus();
	} else {
		theForm.return_url.value = location.href;
		//ajax code for mark
		myAjax.init("TEXT", loginDone, loadingStart, loadingEnd);
		myAjax.post_form(web_url+"/ajax.php?job=login", theForm);
	}
	return false;
}

function loginDone(errCode) {
	var theForm = document.getElementById("form_login");
	errCode = parseInt(errCode);
	switch(errCode) {
		case 1:
			alert("登录错误，错误的用户名或密码！");
			theForm.user_name.value = "";
			theForm.user_psw.value = "";
			theForm.check_code.value = "";
			theForm.user_name.focus();
			document.getElementById('vcode').src=web_url+'/vcode.php?'+Math.random();
			break;
		case 2:
			alert("校验码不正确，请重新输入！");
			theForm.check_code.value = "";
			theForm.check_code.focus();
			document.getElementById('vcode').src=web_url+'/vcode.php?'+Math.random();
			break;
		default:
			alert("登录成功！");
			theForm.user_name.value = "";
			theForm.user_psw.value = "";
			theForm.check_code.value = "";
			document.getElementById('login').style.display="none";
			loginCheck();
	}
}

/*--Functions 4 Cookie Start--*/
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie (name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : 365;
	var exp = new Date();
	exp.setTime(exp.getTime() + (expires*24*60*60*1000));
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	var CookieStr = name + "=" + escape (value);
	CookieStr += "; expires=" + exp.toGMTString() ;
	CookieStr += ((path == null) ? "" : ("; path=" + path));
	CookieStr += ((domain == null) ? "" : ("; domain=" + domain));
	CookieStr += ((secure == true) ? "; secure" : "");
	document.cookie = CookieStr;
}

function deleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = getCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
/*--Functions 4 Cookie End--*/

/*--Functions 4 Ajax Start--*/
function Ajax() {
	ajax_requester = false;
	ajax_returnType = "TEXT";
	ajax_curState = "";
	ajax_onData = null;
	ajax_onStart = null
	ajax_onOver = null;
	ajax_header = "";
	ajax_result = "";
	ajax_charset = "";

	this.init = function(the_type, ajax_onData, ajax_onStart, ajax_onOver, ajax_charset) {
		if(typeof(the_type)=="undefined") {
			self.ajax_returnType = "TEXT";
		} else {
			self.ajax_returnType = the_type;
		}
		if(typeof(ajax_charset)=="undefined") {
			self.ajax_charset = "GBK";
		} else {
			self.ajax_charset = ajax_charset;
		}
		if(typeof(ajax_onData)!="function") {
			self.ajax_onData = this.getValue;
		} else {
			self.ajax_onData = ajax_onData;
		}
		if(typeof(ajax_onStart)!="function") {
			self.ajax_onStart = this.Dummy;
		} else {
			self.ajax_onStart = ajax_onStart;
		}
		if(typeof(ajax_onOver)!="function") {
			self.ajax_onOver = this.Dummy;
		} else {
			self.ajax_onOver = ajax_onOver;
		}
		self.ajax_requester = this.getRequester();
		self.ajax_requester.onreadystatechange = self.handleResult;
		return;
	}

	this.getRequester = function() {
		var xmlhttp_request = false;
		try {
			if(window.ActiveXObject) {
				var versions = ['Microsoft.XMLHTTP', 'MSXML6.XMLHTTP', 'MSXML5.XMLHTTP', 'MSXML4.XMLHTTP', 'MSXML3.XMLHTTP', 'MSXML2.XMLHTTP', 'MSXML.XMLHTTP'];
				for(var i=0; i<versions.length; i++) {
					try{
						xmlhttp_request = new ActiveXObject(versions[i]);
						try{
							xmlhttp_request.setRequestHeader("Content-Type", "text/xml; " + self.ajax_charset);
							//xmlhttp_request.setRequestHeader("Content-Type",  self.ajax_charset);
						} catch(e) {}
						break;
					} catch(e) {
						xmlhttp_request = false;
					}
				}
			} else if(window.XMLHttpRequest) {
				xmlhttp_request = new XMLHttpRequest();
				try{
					xmlhttp_request.overrideMimeType('text/xml');
				} catch(e) {}
			}
		}catch(e){
			xmlhttp_request = false;
		}
		return xmlhttp_request;
	}

	handleResult = function() {
		var State_lst = ["尝试连接", "正在装载", "装载完毕", "文档处理", "处理完成"];
		self.ajax_curState = State_lst[self.ajax_requester.readyState];
		if(self.ajax_requester.readyState==4) {
			if(self.ajax_requester.status==0 || self.ajax_requester.status==200) {
				try {
					if(self.ajax_returnType.toUpperCase()=="XML") {
						self.ajax_result = self.ajax_onData(self.ajax_requester.responseXML.documentElement);
					} else {
						self.ajax_result = self.ajax_onData(self.ajax_requester.responseText);
					}
					try {
						self.ajax_header = self.ajax_requester.getAllResponseHeaders();
					} catch(e) {}
				} catch(e) {
					self.ajax_curState = "Error - " + (typeof(e.description)=="undefined" ? e.message : e.description);
				}
			} else {
				self.ajax_curState = "Error - " + self.ajax_requester.status + " - 连接远程数据失败!";
			}
			self.ajax_onOver();
		}
		return;
	}

	send = function(the_method, the_url, the_para) {
		self.ajax_onStart();
		if(typeof(self.ajax_requester)!="object") return;
		try{
			if(typeof(the_para)=="undefined") the_para = "";
			if(the_method.toUpperCase()=="POST") {
				self.ajax_requester.open("POST", the_url, true);
				self.ajax_requester.setRequestHeader("Content-Length", the_para.length);
				self.ajax_requester.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + self.ajax_charset);
				self.ajax_requester.send(the_para);
			} else {
				self.ajax_requester.open("GET", the_url, true);
				self.ajax_requester.send(null);
			}
		}catch(e){
			self.ajax_curState = "Error - 在获取数据时出错：" + (typeof(e.description)=="undefined" ? e.message : e.description);
			self.ajax_onOver();
		}
		return;
	}

	this.post_form = function(the_url, the_form) {
		var para_lst = new Array();
		var the_para = "";
		for(var i=0; i<the_form.elements.length; i++) {
			if(the_form.elements[i].name.length==0) continue;
			if(the_form.elements[i].type=="radio" || the_form.elements[i].type=="checkbox") {
				if(the_form.elements[i].checked) {
					the_para = encodeURIComponent(the_form.elements[i].name) + "=" + encodeURIComponent(the_form.elements[i].value);
				} else {
					continue;
				}
			} else if(the_form.elements[i].type=="select-multiple") {
					for(n=0; n<the_form.elements[i].options.length; n++) {
						if(the_form.elements[i].options[n].selected) {
							the_para += "&" + encodeURIComponent(the_form.elements[i].name) + "=" + encodeURIComponent(the_form.elements[i].options[n].value);
						}
					}
					if(the_para.length>1) the_para = the_para.substr(1);
			} else {
				the_para = encodeURIComponent(the_form.elements[i].name) + "=" + encodeURIComponent(the_form.elements[i].value);
			}
			para_lst.push(the_para);
		}
		self.send("POST", the_url, para_lst.join("&"));
		return;
	}

	this.post = function(the_url, the_para) {
		if(the_para==null) the_para = ""
		self.send("POST", the_url, the_para);
		return;
	}

	this.get = function(the_url, the_para) {
		if(the_para==null) the_para = "";
		if(the_url.indexOf("?")>-1) {
			the_url += "&" + the_para;
		} else {
			the_url += "?" + the_para;
		}
		self.send("GET", the_url, "");
		return;
	}

	this.GetState = function() {
		return self.ajax_curState;
	}

	this.GetHeader = function() {
		return self.ajax_header;
	}

	this.GetResult = function() {
		return self.ajax_result;
	}

	this.removeTextNode = function(xml_obj) {
		if(typeof(xml_obj.childNodes)!="undefined") {
			for(var i=0; i<xml_obj.childNodes.length; i++) {
				if(xml_obj.childNodes[i].nodeType==3) {
					xml_obj.removeChild(xml_obj.childNodes[i]);
					i--;
				}
			}
		}
		return xml_obj;
	}

	this.getValue = function(the_value) {
		return the_value;
	}

	this.Dummy = function() {
		return;
	}
}

var ajax_running = false;
var ajax_queue = Array();

function loadingStart() {
	var loading = document.getElementById("bar_loading");
	//loading.style.display = "";
	if(checker.ie) {
		loading.style.top = ((document.documentElement.offsetHeight - loading.offsetHeight)/2 + document.documentElement.scrollTop) + "px";
		loading.style.left = ((document.documentElement.offsetWidth - loading.offsetWidth)/2 + document.documentElement.scrollLeft) + "px";
	} else {
		loading.style.top = ((window.innerHeight - loading.offsetHeight)/2 + document.documentElement.scrollTop) + "px";
		loading.style.left = ((window.innerWidth - loading.offsetWidth)/2 + document.documentElement.scrollLeft) + "px";
		loading.style.MozOpacity = 0.90;
	}
	ajax_running = true;
	return;
}

function loadingEnd() {
	var result = "";
	var loading = document.getElementById("bar_loading");
	if(typeof(myAjax)!="undefined") result = myAjax.GetState();
	if(result.match(/Error/i)) alert(result);
	loading.style.display = "none";
	ajax_running = false;
	try {
		var new_job = ajax_queue.shift();
		if(typeof(new_job)!="undefined") {
			setTimeout(new_job, 50);
		}
	} catch(e) {alert(e.description)}
	return;
}

function loadingJudge(func) {
	if(ajax_running) {
		if(typeof(func)!="undefined") {
			ajax_queue.push(func);
		} else {
			alert("进程处理中，请稍候！");
		}
	}
	return ajax_running;
}

var myAjax = new Ajax();
/*--Functions 4 Ajax End--*/