<!--
/*******************************************************************************************

 * 注: MSIE7/FireFox3.0 下测试通过   
   
*********************************如果您使用本控件 请保留该信息 谢谢! *****************************   
 * http://2003zy.com
 * Email: wenq0917@sina.com 
 * QQ: 251490789 
 * Creation Date: 2009-05-29
 * Modification DAte: 2009-05-29 23:10
 * version: 1.0.0
*********************************************************************************************/

Number.prototype.NaN = function (val) {
    return isNaN(this) ? val : this;
};
Number.prototype.NaN0 = function () {
    return isNaN(this) ? 0 : this;
};
String.prototype.trim = function () {	
    return this.replace(/(^\s*)|(\s*$)/g, "");
};
String.prototype.lTrim = function () {	
    return this.replace(/(^\s*)/g, "");
};
String.prototype.rTrim = function () {	
    return this.replace(/(\s*$)/g, "");
};
Array.prototype.indexOf = function (search) {
	if (typeof search == "undefined") return -1;
	for (var i = 0; i < this.length; i++) {if (search.toString() == this[i].toString()) return i;}
    return -1;
};
Date.prototype.format = function (fs) {
	var month = (this.getMonth() < 9) ? ("0" + (this.getMonth() + 1)) : (this.getMonth() + 1);
	var date = (this.getDate() < 10) ? ("0" + this.getDate()) : this.getDate();
	if (fs.length == 1) {
		return this.getFullYear() + fs + (month) + fs + date; 
	}
	var hour = (this.getHours() < 10) ? ("0" + this.getHours()) : this.getHours();
	var minute = (this.getMinutes() < 10) ? ("0" + this.getMinutes()) : this.getMinutes();
	var second = (this.getSeconds() < 10) ? ("0" + this.getSeconds()) : this.getSeconds();
	
	fs = fs.replace("yyyy",this.getFullYear());
	fs = fs.replace("mm",(month));
	fs = fs.replace("dd",date);
	fs = fs.replace("hh",hour);
	fs = fs.replace("ii",minute);
	fs = fs.replace("ss",second);
	fs = fs.replace("SSS",this.getMilliseconds());
	return fs;
};

var WQ = {};

WQ.$ = function(id, doc){
    var doc = doc || document;
    return doc.getElementById(id);
};
WQ.$T = function(tag, doc){
	var doc = doc || document;
	return doc.getElementsByTagName(tag);
};
WQ.$N = function(name, doc){
	var doc = doc || document;
	return doc.getElementsByName(name);
};
WQ.$$ = function(name, doc){
    var doc = doc || document;
    return doc.createElement(name);
};

WQ.util = {
	getScriptPath : function (pattern) {
		//if (!pattern) pattern = /WQ[\w\-\.]*\.js/;
		if (typeof pattern != "object") {
			if (pattern) {
				pattern += "\.js";
			} else {
				pattern = "WQ\.js";
			}
			pattern = new RegExp(pattern,"");
		}
	    var elements = document.getElementsByTagName('script');
	    for (var i = 0; i < elements.length; i++) {
	        if (elements[i].src && elements[i].src.match(pattern) != null) {
	            return elements[i].src.substring(0, elements[i].src.lastIndexOf('/') + 1);
	        }
	    }
	    return null;
	},
	getHtmlPath : function() {
	    return location.href.substring(0, location.href.lastIndexOf('/') + 1);
	},	
	loadStyle : function (path) {
	    var link = WQ.$$('link');
	    link.setAttribute('type', 'text/css');
	    link.setAttribute('rel', 'stylesheet');
	    link.setAttribute('href', path);
	    WQ.$T("head")[0].appendChild(link);
	},
	loadJS : function (path,charset) {
		if (!path) return;
		var fileName = WQ.file.getFileName(path);
		if (this.getScriptPath(fileName)) {
			//alert("JS '"+path+"' had already loaded.");
			return;
		}
		
		var script = WQ.$$('script');
		if (charset) script.setAttribute("charset", charset);
		//script.setAttribute('type', 'text/javascript');
		//script.setAttribute('language', 'javascript');
		//script.setAttribute('src', path);
		script.type = "text/javascript";
		script.language = "javascript";
		script.defer = true;
		script.src = path;
		WQ.$T("head").item(0).appendChild(script);
	},
	ajaxLoadJS : function (path,charset) {
		if (!path) return;
		var fileName = WQ.file.getFileName(path);
		if (this.getScriptPath(fileName)) {
			//alert("JS '"+path+"' had already loaded.");
			return;
		}
		
		var script = WQ.$$('script');
		if (charset) script.setAttribute("charset", charset);
		script.type = "text/javascript";
		script.language = "javascript";
		script.defer = true;
		
		var ajax = new WQ.Ajax();
		ajax.send({url:path,asynchronous:false});
		//alert(path+"\n"+ajax.responseText);
		script.text = ajax.responseText;
		//this.execScript(ajax.responseText,"javascript");
		WQ.$T("head").item(0).appendChild(script);
	},
    eval : function (str) {
    	if (str) eval(str);
    },
	execScript : function (scriptText,language) {
		if (!scriptText) return;
		if (language) {
			if (window.execScript) { 
				window.execScript(scriptText,language); 
			} else { 
				window.eval(scriptText,language); 
			}
		} else {
			if (window.execScript) { 
				window.execScript(scriptText); 
			} else { 
				window.eval(scriptText); 
			}	
		}
	},
    /**
	 * 获取目标的绝对位置
	 * $Date 2009-05-29 23:10
	 */
	getPosition : function (e) {
		var left = 0;
		var top  = 0;
		while (e.offsetParent) {
			left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
			top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
			e     = e.offsetParent;
		}
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
	
		return {x:left, y:top};
	},
	/**
	 *	获取HTML页面参数 flag 为1 获取详细参数
	 */
	getHTMLParams : function (flag) {
		var parastr = window.location.search;
		if (flag) {
			var parm = Array();
			if (parastr.indexOf("&") > 0) {
				var tempstr = "";
				var para = parastr.split("&");
				for (var i = 0; i < para.length; i++) {
					tempstr = para[i];
						 
					var pos = tempstr.indexOf("=");
					parm[i] = [tempstr.substring(0,pos), tempstr.substring(pos+1)];
				}
			 }
			 return parm;
		}
		 return parastr;
	},
	getPageScroll : function () {
		var xScroll,yScroll;

		if (self.pageYOffset) {
			xScroll = self.pageXOffset;
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			xScroll = document.documentElement.scrollLeft;
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			xScroll = document.body.scrollLeft;
			yScroll = document.body.scrollTop;
		}

		return new Array(xScroll,yScroll);
	},
	/**
	 * getPageSizeInfo()
	 * @return array with page width, height and window width, height
	 */
	getPageSizeInfo : function () {		
		var xScroll, yScroll;		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		var pageHeight, pageWidth;
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}

		return new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	}
};
var ToolUtil = WQ.util;
var Utils = WQ.util;
WQ.request = {
	_values: null,
	urlEncodeIfNecessary: function (s) {
		var regex = /[\\\"<>\.;]/;
		var hasBadChars = regex.exec(s) != null;
		return hasBadChars && typeof encodeURIComponent != UNDEF ? encodeURIComponent(s) : s;
	},
	_getValues: function () {
		if (this._values) return;
		var q = document.location.search || document.location.hash;
		if (q) {
			if (/\?/.test(q)) { q = q.split("?")[1]; } // strip question mark
			
			var pairs = q.split("&");
			for (var i = 0; i < pairs.length; i++) {
				if (!this._values) this._values = {};
				var key = pairs[i].substring(0, pairs[i].indexOf("="));
				var value = urlEncodeIfNecessary(pairs[i].substring((pairs[i].indexOf("=") + 1)));
				if (this._values[key]) {
					if (WQ.type.isArray(this._values[key])) {
						this._values[key].push(value);
					} else {
						this._values[key] = [this._values[key],value];
					}
				} else {
					this._values[key] = value;
				}
			}
		}
	},
	getValues: function (key,defaultValue) {
		if (!key) return null;
		_getValues();
		if (!this._values || !this._values[key]) return defaultValue;
		if (WQ.type.isArray(this._values[key])) {
			return this._values[key];
		} else {
			return [this._values[key]];
		}
	},
	getString: function (key,defaultValue) {
		if (!key) return null;
		_getValues();
		if (!this._values || !this._values[key]) return defaultValue;
		if (WQ.type.isArray(this._values[key])) {
			var _val = "";
			for (var i = 0; i < this._values[key].length; i++) {
				if (_val.length > 0) _val += ",";
				_val += this._values[key][i];
			}
			return "["+_val+"]";
		} else {
			return this._values[key];
		}
	},
	getInt: function (key,defaultValue) {
		if (!key) return null;
		return parseInt(this.getString(key,defaultValue)).NaN(defaultValue);
	}	
}
var Request = WQ.request;

WQ.type = {
	isArray : function (obj) {
	   return obj && (obj.constructor.toString().indexOf("Array") != -1);
	},
	isFunction : function (obj) {
	   return obj && (obj.constructor.toString().indexOf("Function") != -1);
	},
	isObject : function (obj) {
	   return obj && ((obj.constructor) ? (obj.constructor.toString().indexOf("Object") != -1) : (typeof obj == 'object'));
	},
	isString : function (obj) {
	   return obj != null && (obj.constructor.toString().indexOf("String") != -1);
	},
	isNumber : function (obj) {
	   return obj && (obj.constructor.toString().indexOf("Number") != -1);
	},
	isBoolean : function (obj) {
	   return obj && (obj.constructor.toString().indexOf("Boolean") != -1);
	}
};

WQ.validation = {
	isNumber : function (oNum) {	
		if (!oNum) return false;
		var strP=/^\d+(\.\d+)?$/;
		if (!strP.test(oNum)) return false;	
		try {		
			if (parseFloat(oNum) != oNum) return false;
		} catch (ex) {		
			return false;
		}
		return true;
	},
	isInt : function (src) {	
		if (!src) return false;	
		var strP=/^\d+$/;	
		return strP.test(src);	
	}
};

WQ.cookie = {
	set : function (cookieName,cookieValue,expires) {
		document.cookie = escape(cookieName) + '=' + escape(cookieValue)
			+ (expires ? '; expires=' + expires.toGMTString() : '');
	},
	get : function (cookieName) {
		var cookieValue = '';
		var posName = document.cookie.indexOf(escape(cookieName) + '=');
		if (posName != -1) {
			var posValue = posName + (escape(cookieName) + '=').length;
			var endPos = document.cookie.indexOf(';', posValue);
			if (endPos != -1) 
				cookieValue = unescape(document.cookie.substring(posValue, endPos));
			else 
				cookieValue = unescape(document.cookie.substring(posValue));
		}
		return (cookieValue);
	},
	del : function (cookieName) {
		if (!cookieName) return false;
		var now = new Date();
		var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);

		this.set(cookieName, 'cookieValue', yesterday);
	}
};
var CookieObj = WQ.cookie;
/**
 * 监听事件
 * $param el 对象; 如：window/document/document.body
 * $param event 事件; 如：keydown/click/load/unload
 * $param listener 回调函数
 */
WQ.event = {
    add : function (el, event, listener) {
        if (el.addEventListener){
            el.addEventListener(event, listener, false);
        } else if (el.attachEvent){
            el.attachEvent('on' + event, listener);
        }
    },
    remove : function (el, event, listener) {
        if (el.removeEventListener){
            el.removeEventListener(event, listener, false);
        } else if (el.detachEvent){
            el.detachEvent('on' + event, listener);
        }
    },
    /**
     * 监听键盘被按下回车时的事件
     * $param handler 回调函数
     */
    enter : function (handler,doc) {
    	WQ.event.add((doc ? doc : document), "keydown", function (e) {
    		var e = e || window.event;
    		if (13 == e.keyCode) {
    			if (typeof(handler) == "function") {
    				try	{ 
    					(handler).apply(this);
    				} catch (e) {}
    			} else {
    				WQ.util.eval(handler);
    			}
    		}
    	});
    },
    onLoad : function (handler) {
    	WQ.event.add(window,"load",handler);
    }
};
var EventObj = WQ.event;
WQ.file = {
	/**
	 * 获取文件名
	 */
	getFileName : function (filePath,includeExt) {
		if (!filePath) return "";
		filePath = filePath.replace(/\\/g,"/");
		var index = filePath.lastIndexOf("/");
		if (index >= 0 && filePath.length > 1) {
			filePath = filePath.substring(index+1);
		}
		if (!includeExt) {
			index = filePath.lastIndexOf(".");
			filePath = filePath.substring(0,index);
		}
		return filePath;
	},
	
	/**
	 * 获取文件的扩展名
	 */
	getFileExtension : function (fileName) {
		if (!fileName) return "";
		var index = fileName.lastIndexOf(".");
		if (index > 0) {
			return fileName.substring(index+1);
		} else {
			return "";
		}
	}
};
var FileObj = WQ.file;
var getFileName = WQ.file.getFileName;
var getFileExtension = WQ.file.getFileExtension;
WQ.date = {
	format : function (fs, date) {
		if (!date) date = new Date();
		return date.format(fs);
	}
};

WQ.form = {
	//得到复选框被选中的个数
	getCheckedCount : function (fieldName) {
		if (!fieldName) fieldName = "key";
		var all = document.getElementsByName(fieldName);
		var num = 0;
		for (i = 0; i < all.length; i++) {
			if (all[i].checked) {
				num = num + 1;
			}
		}
		return num;
	},
	autoCheckedRadio : function (radioName, value, ignoreDisabled) {	
		if (!ignoreDisabled) ignoreDisabled = false;
		var all = document.getElementsByName(radioName);
		for(var i = 0; i < all.length; i++){		
			if(all[i].type == 'radio' && all[i].value == value){
				if (!ignoreDisabled && all[i].disabled == true) {
					continue;
				}
				all[i].checked = true;			
			}
		}
	},
	// valueStr = value1,value2,value3,...
	autoCheckedCheckbox : function (checkboxName,valueStr,delimiter) {	
		if (!delimiter) delimiter = ",";
		valueStr = delimiter + valueStr + delimiter;
		var all = document.getElementsByName(checkboxName);
		for(var i = 0; i < all.length; i++){		
			if (all[i].type == 'checkbox' && all[i].disabled != true) {			
				var tmpValue = delimiter + all[i].value + delimiter;
				if (valueStr.indexOf(tmpValue) >= 0) {			
					all[i].checked = true;
				} else {
					all[i].checked = false;	
				}			
			}
		}
	},
	getRadioValue : function (radioName) {		
		var all = document.getElementsByName(radioName);
		for(var i = 0; i < all.length; i++){		
			if(all[i].type == 'radio' && all[i].disabled != true && all[i].checked){				
				return all[i].value;
			}
		}
		return "";
	},	
	getCheckboxValues :function (checkboxName,delimiter) {	
		var all = document.getElementsByName(checkboxName);
		var valueArr = new Array();
		var returnVal = "";
		for(var i = 0; i < all.length; i++){		
			if(all[i].type == 'checkbox' && all[i].disabled != true && all[i].checked){
				if (delimiter) {
					returnVal += all[i].value+delimiter;
				} else {				
					valueArr[valueArr.length] = all[i].value;
				}
			}
		}
		if (delimiter) {
			if (returnVal.length > 0) {
				return returnVal.substring(0, returnVal.length-1);		
			} else {
				return returnVal;
			}		
		} else {				
			return valueArr;
		}	
	},
	/**
	 * 选中下拉选择框中指定的值
	 * @param selectObj 选择框对象; 如果有多个选择框的名称相同时, 必须传入名称
	 * @param value 值
	 * @param type value(default)|text
	 */ 
	searchSelectItem : function (selectObj, value, type) {		
		this.select.searchItem(selectObj, value, type);
	},
	
	selectAll : function (idCheckboxName, selectAllObj) {		
		var all = document.getElementsByName(idCheckboxName);
		for (i = 0; i < all.length; i++) {			
			if (all[i].type == 'checkbox' && all[i].name == idCheckboxName && all[i].disabled != true) {				
				all[i].checked = selectAllObj.checked;			
			}
		}
	},
	
	unSelectAll : function (obj) {	    
	    if(obj.checked){			
			obj.checked = obj.checked & 0;
	    } 	
	},

	enabledInput : function (inputName) {
		try {
			if (!inputName) return false; 
			var elements = document.getElementsByName(inputName);
			for (var i = 0; i < elements.length; i++) {				
				elements[i].disabled = false;		
			}		
		} catch (e) {
			alert(e.message + " in enabledInput().");	
		}
	},

	disabledInput : function (inputName) {
		try {
			if (!inputName) return false; 
			var elements = document.getElementsByName(inputName);
			for (var i = 0; i < elements.length; i++) {				
				elements[i].disabled = true;		
			}		
		} catch (e) {
			alert(e.message + " in disabledInput().");	
		}
	},

	displayElementsByName : function (name,isDispaly) {
		try {
			if (!name) return false;
			if (isDispaly == undefined) isDispaly = true;
			var elements = document.getElementsByName(name);
			for (var i = 0; i < elements.length; i++) {				
				if (isDispaly) {
					elements[i].style.display = "";	
				} else {
					elements[i].style.display = "none";	
				}					
			}		
		} catch (e) {
			alert("In function displayElementsByName: "+e.message);	
		}
	}
};
var FormObj = WQ.form;
WQ.form.select = {
	/**
	 * @param selectSource selObj.options
	 * @param selectTarget selObj.options
	 */
	copyItem : function (selectSource, selectTarget) {
		for (var i = 0; i < selectSource.length; i++) {
			if (selectSource[i].selected) {
				selectTarget.add( new Option(selectSource[i].text,selectSource[i].value));
			}
		}
	},
	/**
	 * @param selectSource selObj.options
	 * @param selectTarget selObj.options
	 */
	copyAllItem : function (selectSource, selectTarget) {
		for (var i = 0; i < selectSource.length; i++) {
			selectTarget.add( new Option(selectSource[i].text,selectSource[i].value));
		}
	},
	/**
	 * @param selectSource selObj.options
	 * @param selectTarget selObj.options
	 */
	moveItem : function (selectSource, selectTarget) {
		this.copyItem(selectSource, selectTarget);
		for (var i = 0; i < selectTarget.length; i++) {
			for (var j = 0; j < selectSource.length; j++) {
				if (selectSource[j].text == selectTarget[i].text)
					selectSource[j] = null;
			}
		}
	},
	/**
	 * @param selectSource selObj.options
	 * @param selectTarget selObj.options
	 */
	moveAllItem : function (selectSource, selectTarget) {
		this.copyAllItem(selectSource, selectTarget);
		selectSource.length = 0;
	},	
	/**
	 * 列表中选中项上移
	 * @param selObj 列表框对象
	 */
	upItem : function (selObj) { 
		if (!selObj) return false;
		var value = ""; 
		var text = ""; 
		var ops = selObj.options;
		for (var i = 0; i < (ops.length-1); i++) {		
			if (!ops[i].selected && ops[i+1].selected) { 
				value = ops[i].value; 
				text = ops[i].text; 
				ops[i] = new Option(ops[i+1].text, ops[i+1].value); 
				ops[i].selected = true; 
				ops[i+1] = new Option(text, value); 
			} 
		} 
	},
	/**
	 * 列表中选中项下移
	 * @param selObj 列表框对象
	 */
	downItem : function (selObj) { 
		if (!selObj) return false;
		var value = ""; 
		var text = ""; 
		var ops = selObj.options;
		for (var i = (ops.length-1); i > 0; i--) {		
			if (!ops[i].selected && ops[i-1].selected) { 
				value = ops[i].value; 
				text = ops[i].text; 
				ops[i] = new Option(ops[i-1].text, ops[i-1].value); 
				ops[i].selected = true; 
				ops[i-1] = new Option(text, value); 
			} 
		} 
	},
	/**
	 * 选中下拉选择框中指定的值
	 * @param selectObj 选择框对象; 如果有多个选择框的名称相同时, 必须传入名称
	 * @param value 值
	 * @param type value(default)|text
	 */ 
	searchItem : function (selectObj, value, type) {		
		if (!type) type = "value";
		if (typeof(selectObj) == "string") {
			selectObj = document.getElementsByName(selectObj);
			for (var i = 0; i < selectObj.length; i++) {
				var tmpObj = selectObj[i];
				this.searchItem(tmpObj,value);
			}			
			return true;
		}
		var obj = selectObj.options;
		for (var i = 0; i < obj.length; i++) {
			if ((type == "value" && obj[i].value == value) || (type == "text" && obj[i].text == value)) {
				obj[i].selected = true;
				break;
			}
		}
	},	
	getValue : function (selObj) {		
		var opts = selObj.options;
		for (var i = 0; i < opts.length; i++) {
			if (opts[i].selected) {
				return opts[i].value;
			}
		}
	},
	getText : function (selObj) {		
		var opts = selObj.options;
		for (var i = 0; i < opts.length; i++) {
			if (opts[i].selected) {
				return opts[i].text;
			}
		}
	},
	getValues : function (selObj,delimiter) {		
		var opts = selObj.options;
		var valueArr = new Array();
		var value = "";
		for (var i = 0; i < opts.length; i++) {
			if (opts[i].selected) {
				if (delimiter) {
					value += opts[i].value + delimiter;
				} else {				
					valueArr[valueArr.length] = opts[i].value;
				}
			}
		}
		if (delimiter) {
			if (value.length > 0) {
				return value.substring(0, value.length-1);		
			} else {
				return value;
			}		
		} else {				
			return valueArr;
		}
	},
	getTexts : function (selObj,delimiter) {		
		var opts = selObj.options;
		var valueArr = new Array();
		var value = "";
		for (var i = 0; i < opts.length; i++) {
			if (opts[i].selected) {
				if (delimiter) {
					value += opts[i].text + delimiter;
				} else {				
					valueArr[valueArr.length] = opts[i].text;
				}
			}
		}
		if (delimiter) {
			if (value.length > 0) {
				return value.substring(0, value.length-1);		
			} else {
				return value;
			}		
		} else {				
			return valueArr;
		}
	}
};
var SelectObj = WQ.form.select;
var searchSelectItem = WQ.form.select.searchItem;
WQ.window = {
	location : function (url,target) {
		if (!url) return false;
		if (target) {
			target.location.href = url;
		} else {
			self.window.location.href = url;
		}
	},

	back : function (n) {		
		if (n == "") n = -1;
		window.history.back(n);
	}
};
var WindowObj = WQ.window;
//-->