var JSConstant = {contextPath:'/huayangcms'};
//字符串前后去空格回车
String.prototype.trim = function(){
	return this.replace(/(^[\s\n\r]*)|([\s\n\r]*$)/g, '');
}
//下拉框工具函数
function SlctObj(slct, offset, interval){
	this.lastEvent = 0;
	this.lastKey = 0;
	this.slct = slct || null;
	this.mode = 0; //1：数字 2：文字
	this.interval = interval || 3000; //毫秒
	this.oldValue = '';
	this.offset = offset || 0;
	this.vm = {};
	
	this.kde = function(e){
		if(!StringUtils.keyIsNum(e.keyCode) && !StringUtils.keyIsCharacter(e.keyCode) && e.keyCode != 8) return; // 如果输入的字符不是有效字符直接返回
		var crtDate = new Date();
		if(this.lastEvent == 0){//初次
			this.init(e);
		}else{
			if(crtDate.getTime() - this.lastEvent < 0) return;
			if(crtDate.getTime()  - this.lastEvent > this.interval){//时间差大于间隔时间
				this.init(e);
			}else if(crtDate.getTime() - this.lastEvent <= this.interval){//时间间隔在指定的间隔内
				var crtv = this.oldValue + String.fromCharCode(e.keyCode);
				if(e.keyCode == 8){
					this.oldValue = this.oldValue.substr(0, this.oldValue.length - 1);
					crtv = this.oldValue;
				}
				this.slctByText(crtv);
			}
			this.lastEvent = crtDate.getTime();
		}
	}
	
	this.getMode = function(c){
		return StringUtils.keyIsNum(c) ? 1 : (StringUtils.keyIsCharacter(c) ? 2 : 0);
	}
	
	this.init = function(e){
		this.lastEvent = new Date().getTime();
		this.lastKey = e.keyCode;
		this.mode = this.getMode(e.keyCode);
		this.oldValue = String.fromCharCode(e.keyCode); //将ascii码转换为string
		this.slctByText(this.oldValue);
	}
	this.slctByText = function(text){
		if(text.length == 0){
			this.slct.selectedIndex = 0;
			return;
		}
		if(this.mode == 0) return;
		text = text.toUpperCase();
		var ofs = this.mode == 1 ? 0 : this.offset;
		for(var i = 0 ; i < this.slct.options.length ; i++){
			var tt = this.slct.options[i].innerHTML.toUpperCase();
			if(tt.indexOf(text) == ofs){
				this.slct.selectedIndex = i;
				this.oldValue = text;
				if(text.length == 1) this.vm[text] = this.slct.selectedIndex;
				return;
			}
		}
		if(text.length == 1) return;
		if(text.substr(text.length - 1) == this.oldValue){
			if(this.slct.options[this.slct.selectedIndex + 1].innerHTML.toUpperCase().indexOf(this.oldValue) == 0){
				this.slct.selectedIndex++;
			}else{
				this.slct.selectedIndex = this.vm[text.substr(text.length - 1)];
			}
		}
	}
}

//浏览器判断
var userAgent = navigator.userAgent.toLowerCase();
var browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
	safari: /webkit/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ),
	getBrowserType : function(){
		if(this.mozilla)
			return 'mozilla';
		else if(this.msie)
			return 'ie';
		else if(this.opera)
			return 'opera';
		else if(this.safari)
			return 'safari';
	}
};

//日期工具类
var DateUtils = {
	format : function(d,f){
		var date = new Date();
		try{
			f = f || 'DD.MM.YYYY';
			f = f.toUpperCase();
			if(f.indexOf('YYYY') != -1)
				date.setYear(parseInt(d.substr(f.indexOf('YYYY'), 4), 10));
			if(f.indexOf('MM') != -1)
				date.setMonth(parseInt(d.substr(f.indexOf('MM'), 2), 10) - 1);
			if(f.indexOf('DD') != -1)
				date.setDate(parseInt(d.substr(f.indexOf('DD'), 2), 10));
		}catch(e){
			alert('DateUtils#format(d,f) invoke error, args: ' + d.toString() + ', ' + f.toString());
		}
		return date;
	},
	getString : function(d, f){
		d = d || new Date();
		f = f || 'DD.MM.YYYY';
		f = f.toUpperCase();
		f = f.replace(/YYYY/, this.getYear(d));
		f = f.replace(/MM/, this.getMonth(d));
		f = f.replace(/DD/, this.getDate(d));
		return f;
	},
	getYear : function(d){
		if(d == null) d = new Date();
		var year;
		switch(browser.getBrowserType()){
			case 'ie':year = d.getYear() + '';break;
			case 'mozilla':year = (1900 + d.getYear()) + '';break;
		}
		return year;
	},
	getMonth : function(d){
		if(d == null) d = new Date();
		var month = (d.getMonth() + 1) + '';
		return month.length == 1 ? '0' + month : month;
	},
	getDate : function(d){
		if(d == null) d = new Date();
		var day = d.getDate() + '';
		return day.length == 1 ? '0' + day : day;
	},
	getCurrentDate : function(){
		return new Date();
	},
	getCurrentDateStr : function(format){
		return this.getString(format);
	}
}
//字符串工具类
var StringUtils = {
	badChars : function(s){
		var i;
 		for(i = 0; i < s.length; i++)
  		if(s.charCodeAt(i) > 127) 
  			return i;
 		return -1;
	},
	repBadChrs : function(s){
		var i;
 		while((i = this.badChars(s)) != -1){
  			s = this.strReplace(s,s.substr(i,1),'');
 		}
 		return s;
	},
	keyIsNum : function(n){
		return n >= 48 && n <= 57;
	},
	keyIsCharacter : function(n){
		return n == 32 || (n >= 65 && n <= 90) || (n >= 97 && n <= 122);
	},
	strReplace : function(conversionString, inChar, outChar){
		if(!conversionString) return '';
		if(conversionString < 0) return 'invalid value';
		var convertedString = conversionString.split(inChar);
		convertedString = convertedString.join(outChar);
		return convertedString;
	},
	replaceParams : function(str, rpcs, params){
		for(var i = 0 ; i < rpcs.length ; i++){
			str = this.strReplace(str, rpcs[i], params[i]);
		}
		return str;
	}
}
function isNull(){
	return typeof(obj) == 'undefined' || obj == null;
}
//处理http节点工具类
var HttpUtils = {
	getNodes : function(path, doc){
		if(isNull(path)) return ;
		doc = doc || document;
		var parentNode = null;
		var tnodes = [];
		var nodes = path.split('#');
		for(var i = 0 ; i < nodes.length ; i++){
			//var nodestr = nodes[i].split(':');
			var cmatch = nodes[i].match(/^\[.*\]$/);
			if(cmatch != null){//多id或name
				var cnodes = cmatch[0].substr(1, cmatch[0].length - 2);
				if(cnodes == '') 
					cnodes = [];
				else
					cnodes = cnodes.split(',');
				for(var n = 0 ; n < cnodes.length ; n++){
					var ccmatch = cnodes[n].match(/\[[0-9]*\]$/);
					if(ccmatch != null){//name
						var cname = cnodes[n].substr(0, cnodes[n].length - ccmatch[0].length);
						eval('var indexary = ' + ccmatch[0]);
						var tmpary = parentNode ? this.findNodes(parentNode, cname) : doc.getElementsByName(cname);
						if(tmpary == null || tmpary.length == 0) return;
						if(indexary.length == 0){
							tnodes.concat(tmpary);
						}else if(indexary.length == 1){
							if(tmpary[indexary[0]]){
								tnodes.push(tmpary[indexary[0]]);
							}
						}else if(indexary.length > 1){
							for(var j = 0 ; j < indexary.length ; j++){
								if(tmpary[indexary[j]]){
									tnodes.push(tmpary[indexary[j]]);
								}
							}
						}
					}else{// id
						var tmp = parentNode ? this.findNode(parentNode, cnodes[n]) : doc.getElementById(cnodes[n]);
						if(tmp != null)
							tnodes.push(tmp);
					}
				}
			}else{//单id或name
				var ccmatch = nodes[i].match(/\[[0-9]*\]$/);
				if(ccmatch != null){//name
					var cname = nodes[i].substr(0, nodes[i].length - ccmatch[0].length);
					eval('var indexary = ' + ccmatch[0]);
					var tmpary = parentNode ? this.findNodes(parentNode, cname) : doc.getElementsByName(cname);
					if(tmpary == null || tmpary.length == 0) return;
					if(indexary.length == 0){
						if(i+1 < nodes.length){
							parentNode = tmpary[0];
						}else{
							tnodes = tnodes.concat(tmpary);
						}
					}else if(indexary.length == 1){
						if(tmpary[indexary[0]]){
							if(i+1 < nodes.length){
								parentNode = tmpary[indexary[0]];
							}else{
								tnodes = tnodes.concat(tmpary[indexary[0]]);
							}
						}
					}else if(indexary.length > 1){
						for(var j = 0 ; j < indexary.length ; j++){
							if(tmpary[indexary[j]]){
								tnodes.push(tmpary[indexary[j]]);
							}
						}
					}
				}else{// id
					var tmp = parentNode ? this.findNode(parentNode, nodes[i]) : doc.getElementById(nodes[i]);
					if(i+1 < nodes.length && tmp == null) 
						return;
					if(tmp != null)
						if(i+1 < nodes.length){
							parentNode = tmp
						}else{
							tnodes = tnodes.concat(tmp);
						}
				}
			}
		}
		return tnodes;
	},	
	setValue : function(path, value, doc){//HttpUtils.setValue('inspActTableTd#[chk_26[0],chk_27[0],chk_40[0],chk_50[0],chk_55[0],chk_70[0],chk_85[0]]', {disabled:false});
		if(isNull(value)) return;
		var tnodes = this.getNodes(path, doc);
		for(var i = 0 ; i < tnodes.length ; i++){
			for(var name in value){
				if(typeof(tnodes[i][name]) == 'function'){
					if(typeof(value[name]) == 'function'){
						tnodes[i][name] = value[name];
					}else{
						tnodes[i][name].call(tnodes[i], null);
					}
				}else{
					this.copyAttribute(value, tnodes[i]);
				}
			}
		}
	},
	setValues : function(paths, values, doc){
		if(paths != null){
			if(paths instanceof Array){
				for(var i = 0 ; i < paths.length ; i++){
					this.setValue(paths[i], values[i], doc);
				}
			}else{
				this.setValue(paths, values, doc);
			}
		}
	},
	findNode : function(pnode, id){
		if(isNull(pnode)) return null;
		var nodes = pnode.childNodes;
		if(nodes.length > 0){
			for(var i = 0 ; i < nodes.length ; i++){
				if(nodes[i].id == id){
					return nodes[i];
				}else{
					var tmp = this.findNode(nodes[i], id);
					if(tmp != null)
						return tmp;
				}
			}
		}
		return null;
	},
	findNodes : function(pnode, name){
		if(isNull(pnode)) return null;
		var nodes = pnode.childNodes;
		var rst = [];
		if(nodes.length > 0){
			for(var i = 0 ; i < nodes.length ; i++){
				if(!isNull(nodes[i].name) && nodes[i].name == name){
					rst.push(nodes[i]);
				}
				var tmp = this.findNodes(nodes[i], name);
				if(tmp != null && tmp.length > 0){
					rst = rst.concat(tmp);
				}
			}
		}
		return rst;
	},
	findNodesByTagName : function(pnode, tagName){
		if(isNull(pnode)) return null;
		var nodes = pnode.childNodes;
		var rst = [];
		if(nodes.length > 0){
			for(var i = 0 ; i < nodes.length ; i++){
				if(!isNull(nodes[i].tagName) && nodes[i].tagName == tagName){
					rst.push(nodes[i]);
				}
				var tmp = this.findNodesByTagName(nodes[i], tagName);
				if(tmp != null && tmp.length > 0){
					rst = rst.concat(tmp);
				}
			}
		}
		return rst;
	},
	//复制属性，如果待复制的对象不是object则直接赋值
	copyAttribute : function(from, to){
		if(typeof(from) == 'object' && !(from instanceof Array) && from != null){			
			if(typeof(to) != 'object' || to == null)
				to = {};
			for(var att in from){
				if(typeof(from[att]) == 'object' && !(from[att] instanceof Array) && from[att] != null){
					if(typeof(to[att]) != 'object' || to[att] == null)
						to[att] = {};
					this.copyAttribute(from[att], to[att]);
				}else if(to[att] && typeof(to[att]) == 'function'){
					continue;
				}else
					to[att] = from[att];
			}
		}else{			
			to = from;
		}
	},
	submitForm : function(formInfo, doc, formNode){
		doc = doc || document;
		var form = null;
		if(typeof formNode == 'undefined'){
			form = doc.createElement("form");
			form.method = 'post';
			form.id = 'tmpForm';
			doc.body.appendChild(form);
		}else
			form = formNode;
		form.action = formInfo.uri;
		if(formInfo.target)
			form.target = formInfo.target;
		var nodes = [];
		if(formInfo.param){
			for(var name in formInfo.param){
				var els = HttpUtils.findNodes(form, name);
				if(els && els.length > 0){
					els[0].value = formInfo.param[name];
				}else{
					var el = doc.createElement("input");
					el.type = 'hidden';
					el.name = name;
					el.value = formInfo.param[name];
					form.appendChild(el);
					nodes.push(el);
				}
			}
		}
		form.submit();
		for(var i = 0; i < nodes.length ; i++){
			form.removeChild(nodes[i]);
		}
		if(!formNode)
			doc.body.removeChild(form);
	},
	getUrlInfo : function(win){
		win = win || window;
		var loc = win.location;
		var urlInfo = {};
		//urlInfo.webname = loc.pathname.split('/')[1];
		if(JSConstant.contextPath.charAt(0) == '/'){
			urlInfo.webname = JSConstant.contextPath.substr(1, JSConstant.contextPath.length - 1);
		}else{
			urlInfo.webname = JSConstant.contextPath;
		}
		urlInfo.uri = loc.pathname;
		urlInfo.queryStr = loc.search;
		urlInfo.host = loc.host;
		return urlInfo;		
	},
	back : function(win){
		win = win || window;
		var url = win.preUrl;
		if(url && url != ''){
			if(url.length > 2 && url.substr(0,1) == '{' && url.substr(url.length - 1, 1) == '}'){
				eval('url=' + url);
				this.submitForm(url, win.document);
			}else{
				win.location.href = url;
			}
		}else{
			history.back();
		}
	},
	insertHTML : function(node, html, doc){
		doc = doc || document;
		if(!node)
			return null;
		var span = node.appendChild(doc.createElement("<span>"));
		span.innerHTML = html;
		var nodes = span.childNodes;
		var rst = [];
		if(nodes){
			var len = nodes.length;
			for(var i = 0 ; i < len ; i++){
				rst.push(node.appendChild(nodes[0]));
			}
		}
		node.removeChild(span);
		return rst.length == 1 ? rst[0] : rst;
	},
	loadCss : function(doc, el){
		doc = doc || document;
		var link = doc.createElement('link');
		if(typeof el == 'object')
			ObjectUtils.extend(link, el);
		var head = document.getElementsByTagName('head')[0];
		return head.appendChild(link);
	},
	loadJs : function(doc, el){
		doc = doc || document;
		var script = document.createElement('script');
		if(typeof el == 'object')
			ObjectUtils.extend(script, el);
		var head = document.getElementsByTagName('head')[0];
		head.appendChild(script);
		return script;
	},
	getPosition : function(el){
		return {x:el.offsetLeft, y:el.offsetTop, h:el.offsetHeight, w:el.offsetWidth};
	},
	//加入收藏夹
	addFavorite : function(title, url, descrition){
		try{
			window.external.addFavorite(url, title);
		}catch(e){
			window.sidebar.addPanel(title, url, descrition);
		}
	},
	//设置首页
	setHomePage : function(url){
		if(browser.msie){
			document.body.style.behavior = 'url(#default#homepage)';
			document.body.setHomePage(url);
		}else if(window.netscape){
			try{
				window.netscape.security.privilegeManager.enablePrivilege('UniversalXPConnect');
				var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
				prefs.setCharPref('browser.startup.homepage',url);
			}catch(e){
				alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );
			}
		}
	},
	getHostPath : function(win){
		win = win || window;
		var loc = win.location;
		return loc.protocol + '//' + loc.host;
	},
	getBasePath : function(win){
		return HttpUtils.getHostPath(win) + JSConstant.contextPath;
	}
}
var ArrayUtils = {
	concat : function(){
		var ary = [];
		for(var i = 0 ; i < arguments.length ; i++){
			var tmp = arguments[i];
			if(tmp instanceof Array){
				for(var j = 0 ; j < tmp.length ; j++){
					this.concat(ary, tmp[j]);
				}
			}else{
				ary.push(tmp);
			}
		}
		return ary;
	}
}

function getScroll(doc){
	var doc = doc || document;
	var t, l, w, h; 
	if(doc.documentElement && doc.documentElement.scrollTop){
		t = doc.documentElement.scrollTop;
		l = doc.documentElement.scrollLeft;
		w = doc.documentElement.scrollWidth;
		h = doc.documentElement.scrollHeight;
	}else{
		t = doc.body.scrollTop;
		l = doc.body.scrollLeft;
		w = doc.body.scrollWidth;
		h = doc.body.scrollHeight;
	}
	return {scrollTop:t, scrollLeft:l, scrollWidth:w, scrollHeight:h};
}
function setScroll(position, doc){
	var doc = doc || document;
	var scroll = null;
	if(doc.documentElement && doc.documentElement.scrollTop){
		scroll = doc.documentElement;
	}else{
		scroll = doc.body;
	}
	scroll.scrollTop = position.scrollTop ? position.scrollTop : scroll.scrollTop;
	scroll.scrollLeft = position.scrollLeft ? position.scrollLeft : scroll.scrollLeft;
}

var ObjectUtils = {
	size : function(obj){
		var size = 0;
		for(var name in obj){
			if(typeof(obj[name]) != 'function'){
				size++;
			}
		}
		return size;
	},
	toJson : function(obj){
		if(typeof(obj) == 'object'){
			var str = '';
			if(obj == null){
				str = null;
			}else if(obj instanceof Array){
				str += '[';
				for(var i = 0 ; i < obj.length ; i++){
					str += this.toJson(obj[i]) + ',';
				}
				if(str.charAt(str.length - 1) == ','){
					str = str.substr(0, str.length - 1);
				}
				str += ']';
			}else{
				str += '{';
				for(var name in obj){
					str += '\"' + name + '\":' + this.toJson(obj[name]) + ',';
				}
				if(str.charAt(str.length - 1) == ','){
					str = str.substr(0, str.length - 1);
				}
				str += '}';
			}
			return str;
		}else if(typeof(obj) == 'number'){
			return obj;
		}else if(typeof(obj) == 'string'){
			var tmp = obj.replace(/(\')/g, '\\\'');
			tmp = tmp.replace(/(\")/g, '\\\"');
			return '\"' + tmp + '\"';
		}else if(typeof(obj) == 'function' || typeof(obj) == 'undefined'){
			return null;
		}
	},
	clone : function(obj){
		return eval('(' + this.toJson(obj) + ')');
	},
	extend : function(obj){
		if(!(obj instanceof Object)) return;
		if(arguments.length > 1){
			for(var i = 1 ; i < arguments.length ; i++){
				var ex = arguments[i];
				if(typeof ex == 'function')
					ex.call(obj, null);
				else if(typeof ex == 'object')
					for(var key in ex)
						obj[key] = ex[key];
			}
		}
	}
};
var SelectUtils = {
	add:function(slc, data){
		var ops = slc.options;
		for(var i = 0 ; i < ops.length ; i++){
			if(ops[i].value == data.value)
				return;
		}
		if(browser.msie)
			slc.add(new Option(data.text, data.value));
		else
			slc.add(new Option(data.text, data.value), null);
	},	
	remove:function(slc, value){
		var ops = slc.options;
		for(var i = 0 ; i < ops.length ; i++){
			if(ops[i].value == value){
				slc.remove(ops[i].index);
				return;
			}
		}
	},
	changeHtml : function(el, text){
		if(browser.msie){//IE浏览器
			el.innerHTML = '#$separator$#';
			var str = el.parentNode.innerHTML;
			el.parentNode.innerHTML = str.split('#$separator$#').join(text);
		}else{//其他浏览器
			el.innerHTML = text;
		}
	},
	keyDownEvent : function(event, el, offset, second){
		offset = offset || 6;
		second = second || 3;
		if(typeof(el.slctObj) == 'undefined') 
			el.slctObj = new SlctObj(el, offset, second * 1000);
		el.slctObj.kde(event);
	}
};
function XHR(method, url) {
    this.method = method.toUpperCase();
    this.url = url || ('/' + HttpUtils.getUrlInfo().webname + '/ajax/AjaxServlet');
}
XHR.prototype.newRequest = function() {
    var request = this.request;
    if (request) {
        request.onreadystatechange = function() {};
        if (request.readyState != 4)
            request.abort();
        delete request;
    }
    request = this.getXmlHttpRequest();
    this.request = request;
    this.sent = false;
    this.params = new Array();
    this.headers = new Array();
    return request;
}

XHR.prototype.getXmlHttpRequest = function(){
	var xmlHTTP;
	try {
		xmlHTTP = new XMLHttpRequest();
	}catch(e) {
		try {
			xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e) {
			try {
				xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHTTP;
}

XHR.prototype.checkRequest = function() {
    if (!this.request)
        throw "Request not created";
    if (this.sent)
        throw "Request already sent";
    return true;
}

XHR.prototype.addParam = function(pname, pvalue) {
    this.checkRequest();
    this.params[this.params.length] = { name: pname, value: pvalue };
}

XHR.prototype.addHeader = function(hname, hvalue) {
    this.checkRequest();
    this.headers[this.headers.length] = { name: hname, value: hvalue };
}

XHR.prototype.sendRequest = function(callback) {
    this.checkRequest();
    var query = "";
    for (var i = 0; i < this.params.length; i++) {
        if (query.length > 0)
            query += "&";
        query += encodeURIComponent(this.params[i].name) + "="
            + encodeURIComponent(this.params[i].value);
    }
    var url = this.url;
    if (this.method == "GET" && query.length > 0) {
        if (url.indexOf("?") == -1)
            url += "?";
        else
            url += "&";
        url += query;
    }
    this.request.open(this.method, url, true);
    for (var i = 0; i < this.headers.length; i++)
        this.request.setRequestHeader(this.headers[i].name, this.headers[i].value);
    var tmpReq = this.request;
    this.request.onreadystatechange = function(){
    	try{
    		var req = tmpReq;
	    	if(req.readyState == 4){
	    		if(req.status == 200){
	    			if(url.indexOf('ajax/AjaxServlet') != -1){
	    				var txt = req.responseText.trim().replace(/[\n\r]/g,'\t');
	    				eval('var tmp = ' + txt);
	    				if(typeof tmp == 'string' && tmp.indexOf('[AjaxError]') == 0)
	    					throw tmp.substr('[AjaxError]'.length);
	    				callback(tmp);
	    			}else{
	    				callback(req.responseText,req.responseXML);
	    			}
	    		}
	    		else 
	    			throw 'ajax request fault.';
	    	}
    	}catch(e){
    		var msg = 'ajax callback error: \n' + e.toString() + '\n';
    		if(e.description)
    			msg += 'errorDescription: ' + e.description;
    		alert(msg);
    			
    	}
    };
    var body = null;
    if (this.method == "POST") {
        body = query;
        this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    }
    this.sent = true;
    this.request.send(body);
}

XHR.prototype.isCompleted = function() {
    if (this.request && this.sent)
        if (this.request.readyState == 4)
            if (this.request.status == 200)
                return true;
            else
                this.showRequestInfo();
    return false;
}
var Ajax = {
	call : function(classname, methodname, argument, callback){
		if(argument === undefined || argument == null)
			argument = [];
		else if(argument instanceof Array)
			argument = argument
		else{
			argument = [argument];
		}
		
		var  xhr = new XHR('POST');
		xhr.newRequest();
		xhr.addParam('classname', classname);
		xhr.addParam('methodname', methodname);
		xhr.addParam('argument', ObjectUtils.toJson(argument));
		xhr.sendRequest(callback);
	},
	req : function(url, params, callback, method){
		var xhr = new XHR(method ? method:'POST', url);
		xhr.newRequest();
		if(params){
			for(var name in params){
				xhr.addParam(name, params[name]);
			}
		}
		xhr.sendRequest(callback);
		return xhr;
	},
	form : function(form, callback, method){
		var xhr = new XHR(method ? method:'POST', form.action);
		xhr.newRequest();
		for(var i = 0 ; i < form.elements.length ; i++){
			var el = form.elements[i];
			xhr.addParam(el.name, el.value);
		}
		xhr.sendRequest(callback);
	},
	htmlEncode : function(value){
		return value ? value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;") : "";
	}
};
var JF = function(){
	if(typeof window.variable == 'undefined')
		window.variable = {};
	if(typeof window.variable.JF == 'undefined') 
		window.variable.JF = JF.prototype;
	window.variable.JF._args = arguments;
	var self = window.variable.JF;
	if(typeof arguments[0] == 'string'){
		var strMatch = arguments[0].match(/^([@#$%:]?)(\S*)/);
		switch(strMatch[1]){
			case '@' :
				self = self.findByClass(strMatch[2]);break;
			case '#' :
				self = self.findById(strMatch[2]);break;
			case '$' :
				self = self.findByName(strMatch[2]);break;
			case '%' :
				self = self.findByTag(strMatch[2]);break;
			case ':' :
				self.ele = self.findByAttribute(strMatch[2]);break;
		}
	}
	return self;
};
JF.prototype.forEach = function(funcName, func){
	if(!this._args[0]) return;
	var obj = this._args[0];
	for(var key in obj){
		var tmp = this.getArgs(arguments, 2);
		tmp.push(key);
		if(obj[key] && obj[key][funcName])
			obj[key][funcName].apply(obj[key], tmp);
		else{
			func.apply(obj[key], tmp);
		}
	}
}
JF.prototype.getArgs = function(args, offset, size){
	size = size || args.length;
	offset = offset || 0;
	if(offset >= size) return;
	var r = [];
	for(var i = offset ; i < size ; i++){
		r.push(args[i]);
	}
	return r;
}
JF.prototype.addCss = function(css){
	try{
	var obj = this._args[0].style;
	if(typeof css == 'string'){
		var strs = css.split(';');
		if(strs.length > 0){
			for(var i = 0 ; i < strs.length ; i++){
				var kv = strs[i].split(':');
				if(kv.length == 2){
					var key = kv[0].trim();
					var value = kv[1].trim();
					var offset = 0;
					while((offset = key.indexOf('-')) > 0){
						key = key.substr(0, offset) + key.charAt(offset + 1).toUpperCase() + key.substr(offset + 2);
					}
					if(typeof obj[key] != 'undefined'){
						obj[key] = value;
					}
				}
			}
		}
	}else if(typeof css == 'object'){
		for(var key in css)
			if(obj[key])
				obj[key] = css[key];
	}
	}catch(e){
		alert(e.message + e);		
	}
	return this;
}
JF.prototype.addClass = function(cls){
	var el = this._args[0];
	if(typeof cls == 'string'){
		el.className += ' ' + cls;
	}
}
JF.prototype.removeClass = function(cls){
	var el = this._args[0];
	if(!el.className) return;
	if(typeof cls == 'string'){
		var tmp = '';
		var sp = el.className.split(cls);
		for(var i = 0 ; i < sp.length ; i++){
			tmp += sp[i];
		}
		el.className = tmp;
	}
}
JF.prototype.show = function(p){
	var obj = this._args[0];
	p = p || '';
	if(obj.length)
		for(var i = 0 ; i < obj.length ; i++)
			obj[i].style.display = p;
	else
		obj.style.display = p;
}
JF.prototype.hide = function(){
	var obj = this._args[0];
	if(obj.length)
		for(var i = 0 ; i < obj.length ; i++)
			obj[i].style.display = 'none';
	else
		obj.style.display = 'none';
}
JF.prototype.addHead = function(text){
	var obj = this._args[0];
	var head = obj.getElementsByTagName('HEAD')[0];
	if(typeof text == 'string'){
		HttpUtils.insertHTML(head, text, obj);
	}
}
JF.prototype.center = function(){
	var obj = this._args[0];
	var scroll = getScroll(obj.ownerDocument);
	var height = 0 , width = 0;
	if(obj.style.display == 'none'){
		height = this.pxToNum(obj.style.height);
		width = this.pxToNum(obj.style.width);
	}else{
		height = obj.clientHeight;
		width = obj.clientWidth;
	}
	obj.style.left = (scroll.scrollLeft + (obj.ownerDocument.body.clientWidth - width) / 2) + 'px';
	obj.style.top = (scroll.scrollTop + (obj.ownerDocument.body.clientHeight - height) / 2) + 'px';
}
JF.prototype.insertHTML = function(text){
	var el = this._args[0];
	return HttpUtils.insertHTML(el, text, el.ownerDocument);
}
JF.prototype.insertNode = function(node){
	var pnode = this._args[0];
	if(node.parentNode)
		return pnode.appendChild(node);
	else{
		var doc = pnode.ownerDocument;
		if(!doc) return null;
		var tmp = document.createElement(node.nodeType);
		delete node.nodeType;
		this.copyAtt(tmp, node);
		return pnode.appendChild(tmp);
	}
		
}
JF.prototype.copyAtt = function(obj1, obj2){
	if(!obj1 || !obj2) return obj1;
	for(var key in obj2){
		try{obj1[key] = obj2[key];}catch(e){}
	}
	return obj1;	
}
JF.prototype.findById = function(id){
	var context = this._args[1] || document;
	if(!context.nodeName) return null;
	if(context.nodeName == '#document')
		return context.getElementById(id);
	else
		return HttpUtils.findNode(context, id);
}
JF.prototype.findByName = function(name){
	var context = this._args[1] || document;
	if(!context.nodeName) return null;
	if(context.nodeName == '#document')
		return context.getElementsByName(name);
	else
		return HttpUtils.findNodes(context, name);
	
}
JF.prototype.findByAttribute = function(str){
	var strs = str.split(':');
	if(strs.length != 2) return;
	var pnode = this._args[1] || arguments[1];
	var ren = [];
	if(pnode){
		if(pnode.childNodes.length){
			for(var i = 0 ; i < pnode.childNodes.length ; i++){
				var node = pnode.childNodes[i];
				if(typeof node[strs[0]] == 'string' && node[strs[0]].indexOf(strs[1]) != -1){
					ren.push(node);
				}
				if(node.childNodes.length){
					var ary = this.findByAttribute(str, node);
					if(ary.length)
						ren = ren.concat(ary);
				}
			}
		}
	}
	return ren;
}
JF.prototype.setCss = function(key, value){
	var el = this._args[0];
	if(key == 'height'){
		if((typeof value == 'string' && value.indexOf('px') == -1) || typeof value == 'number')
			value += 'px';
		el.style.height = value;
		var tmp = el.offsetHeight - parseFloat(el.style.height.substr(0, el.style.height.length - 2));
		el.style.height = (parseFloat(value.substr(0, value.length - 2)) - (tmp < 0 ? 0:tmp)) + 'px';
	}else{
		el.style[key] = value;
	}
	return this;
}
JF.prototype.extend = function(obj){
	var bean = this._args[0];
	if(typeof obj == 'object' && typeof bean == 'object')
		for(var key in obj)
			bean[key] = obj[key];
	return this;
}
JF.prototype.getPointer = function(event){
	if(!event) return {x:0, y:0};
	var x = event.pageX || (event.clientX + getScroll(document).scrollLeft) || 0;
	var y = event.pageY || (event.clientY + getScroll(document).scrollTop) || 0;
	return {x:x, y:y}; 
}
JF.prototype.pxToNum = function(pxStr){
	if(typeof pxStr == 'string' && (pxStr = pxStr.toUpperCase()).indexOf('PX') != -1)
		return parseFloat(pxStr.substr(0, pxStr.indexOf('PX')).trim());
	else
		return 0;
}
JF.prototype.loadCss = function(path, doc){
	if(typeof path == 'string'){
		var cssPath = '';
		if(path.indexOf('/' + HttpUtils.getUrlInfo().webname) != 0)
			cssPath = '/' + HttpUtils.getUrlInfo().webname + '/' + path;
		doc = this._args[0] || doc || document;
		var head = this.getHead(doc);
		if(this.findByAttribute('src:' + path, head).length == 0){
			JF(head).insertHTML('<link rel="stylesheet" type="text/css" href="' + cssPath + '" />');
		}
//        var link = doc.createElement('link');
//        link.setAttribute('type', 'text/css');
//        link.setAttribute('rel', 'stylesheet');
//        link.setAttribute('href', path);
//        document.getElementsByTagName("head")[0].appendChild(link);
	}
}
JF.prototype.getHead = function(){
	var doc = this._args[0] || arguments[0] || document;
	return doc.getElementsByTagName('head')[0];
}
JF.prototype.addTask = function(exeFunc, taskName, timeout, finishFunc){
	window.tmpFunc = function(){
		try{
			exeFunc.call(this);
			finishFunc.call(this);
		}catch(e){
//			alt(e);
		}
	}
	window.task = window.task || {};
	window.task[taskName] = window.setInterval('tmpFunc()', timeout);
}
JF.prototype.clearTask = function(taskName){
	if(window.task){
		window.clearInterval(window.task[taskName]);
		delete window.task[taskName];
		delete window.tmpFunc;
	}
}
var alt = function(el, param){
	var str = [];
	param = param || {};
	if(typeof el == 'undefined' || el == null || typeof el == 'number' || typeof el == 'string') {
		alert(el);
		return
	}
	var size = param.size || 999;
	for(var name in el){
		try{
		if(typeof el[name] == 'function' && param.func === false){
			continue;
		}
		if(typeof param.notNull != 'undefined'){
			if(el[name] != null)
				str.push(name + ' : ' + el[name]);
		}else{
			str.push(name + ' : ' + el[name]);
		}
		if(str.length >= size){
			alert(str.join('\n'));
			str = null;
			str = [];
		}
		}catch(e){
			alert(e.messaage + e);
		}
	}
	alert(str.join('\n'));
}
var JFPopup = function(args){
	args = args || {};
	this.win = args.win || window;
	this.doc = this.win.document;
	this.generatorId = function(){
		var id = Math.round(new Date().getTime());
		while(this.doc.getElementById(id)){
			id = Math.round(new Date().getTime());
		}
		return id;
	}
	this.id = args.id || this.generatorId();
	this.title = args.title || 'Dialog';
	this.width = args.width;
	this.height = args.height;
	this.auto = args.auto || false;
	this.footerHtml = args.footer || '<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"></div';
	this.css = args.css || 'css/jquery-ui-1.7.2.custom.css';
	
	this.createFrame = function(){
		try{
			this.frame = JF(this.doc.body).insertHTML('<iframe frameborder="0" scrolling="no" id="'+this.id+'" name="'+this.id+'" src="about:blank"></iframe>');
			JF(this.frame).addCss('overflow: hidden; display: block; background-color: #cccccc; position: absolute; z-index: 1002; outline-color: -moz-use-text-color; outline-style: none; outline-width: 0px;');
			this.height && JF(this.frame).addCss('height:' + this.height + 'px');
			this.width && JF(this.frame).addCss('width:' + this.width + 'px');
			this.frameDoc = this.frame.contentWindow.document;
			this.frameDoc.clear();
			this.frameDoc.write('<html><head><title>JFPopup</title><link rel="stylesheet" type="text/css" href="/' + HttpUtils.getUrlInfo().webname + '/' + this.css + '" /></head><body style="margin: 0px; padding: 0px"></body></html>');
			this.frameDoc.close();
			this.frame.main =  JF(this.frameDoc.body).insertHTML('<div id="popupMain" style="width: auto; height: auto; font-size:12px; display: block; z-index: 1002; outline-color: -moz-use-text-color; outline-style: none; outline-width: 0px;" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-dialog"></div>');
			this.frame.header = JF(this.frame.main).insertHTML('<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" unselectable="on" style="-moz-user-select: none;"><span class="ui-dialog-title" id="ui-dialog-title-dialog" unselectable="on" style="-moz-user-select: none;">'+this.title+'</span><a href="javascript:void(0);" id="popupClose" class="ui-dialog-titlebar-close ui-corner-all" role="button" unselectable="on" style="-moz-user-select: none;"><span class="ui-icon ui-icon-closethick" unselectable="on" style="-moz-user-select: none;">close</span></a></div>'); 
			this.frame.content = JF(this.frame.main).insertHTML('<div id="popupContent" class="ui-dialog-content ui-widget-content" style="min-height: 74px; min-width: 100px; padding-left: 2px; padding-right: 2px;">Hellow.</div>');
			this.frame.closeBtn = JF('#popupClose', this.frameDoc);
			this.frame.closeBtn.popup = this;
			this.frame.closeBtn.onmouseover = function(){JF(this).addClass('ui-state-hover');};
			this.frame.closeBtn.onmouseout = function(){JF(this).removeClass('ui-state-hover');};
			this.frame.closeBtn.onclick = function(){this.onmouseout.apply(this,[]);this.popup.hide()};
			var h = this.height || this.frame.clientHeight || JF().pxToNum(this.frame.style.height);
			this.frame.content.style.height = h - 6 - 31 - 12;
		}catch(e){
			alt(e);
		}
	}
	this.show = function(param){
		param = param || {};
		if(param.content)
			this.frame.content.innerHTML = param.content;
		if(param.url)
			this.frame.content.innerHTML = '<iframe frameborder="0" style="width:100%; height:100%" src="'+param.url+'"></iframe>'
		if(param.height){
			this.frame.style.height = param.height + 'px';
			this.frame.content.style.height = JF().pxToNum(this.frame.style.height) - 6 - 31 - 12;
		}
		if(param.width){
			this.frame.style.width = param.width;
		}
		JF(this.frame).center();
	}
	this.hide = function(){
		JF(this.frame).hide();
	}
	this.drag = function(st){
		if(!st) return;
		var popup = this; 
		popup.minDistance = 1;
		popup.lastPointer = {};
		this.frame.header.onmousedown = function(){
			popup.dragStatus = 'start';
		};
		this.doc.onmouseup = this.frameDoc.onmouseup = function(){
			popup.dragStatus = 'end';
		};
		this.doc.onmousemove = this.frameDoc.onmousemove = function(event){
			if(popup.dragStatus === undefined || popup.dragStatus == 'end') 
				return;
			var crtPointer = null, distance = 0;
			event = event || {};
			if(popup.win.event){//IE 触发事件来源父窗口
				crtPointer = JF().getPointer(popup.win.event);
			}else if(popup.frame.contentWindow.event){//IE 触发事件来源子窗口
				crtPointer = JF().getPointer(popup.frame.contentWindow.event);
				crtPointer.x += JF().pxToNum(popup.frame.style.left);
				crtPointer.y += JF().pxToNum(popup.frame.style.top);
			}else if(event.view){//FF
				crtPointer = JF().getPointer(event);
				if(event.view == popup.frame.contentWindow){//FF 触发事件来源父窗口
					crtPointer.x += JF().pxToNum(popup.frame.style.left);
					crtPointer.y += JF().pxToNum(popup.frame.style.top);
				}
			}
			if(popup.dragStatus == 'start'){
				popup.lastPointer.x = crtPointer.x || 0;
				popup.lastPointer.y = crtPointer.y || 0;
				popup.dragStatus = 'move';
			}
			distance = Math.sqrt(Math.pow(popup.lastPointer.x - crtPointer.x, 2) + Math.pow(popup.lastPointer.y - crtPointer.y, 2));
			if(distance > popup.minDistance){
				var diff = {};
				diff.x = crtPointer.x - popup.lastPointer.x;
				diff.y = crtPointer.y - popup.lastPointer.y;
				popup.frame.style.left = (JF().pxToNum(popup.frame.style.left) + diff.x) + 'px';
				popup.frame.style.top = (JF().pxToNum(popup.frame.style.top) + diff.y) + 'px';
				popup.lastPointer = crtPointer;
			}
			crtPointer = null;
		};
	}
	
	this.createFrame();
	this.drag(args.move)
	return this;
}

function zIndex(id) {
	var subNav = document.getElementById(id);
	if(subNav){
		var subNavLi = subNav.getElementsByTagName("li");
		if(subNavLi){
			var subNavLiLen = subNavLi.length;
			for (var i=0;i<subNavLiLen;i++){
				subNavLi[i].style.zIndex = subNavLiLen*100 -  (i+1)*100;
			}
		}
	}
}


//百叶窗切换
function showInfo(n,count,name,f)
{
	zIndex("subNav");
	for (var i=1;i<=count;i++)
    {
		var titlename = name+'Title_'+i;
		var infoname = name+'Info_'+i;
		if (i==n) {
			var e = $("#" + titlename);
			e.attr('className', e.attr('className').replace('Out', 'On')).css({zIndex:1000});
			$("#" + infoname).css({display:''});
		}else{
			var e = $("#" + titlename);
			e.attr('className', e.attr('className').replace('On', 'Out'));
			$("#" + infoname).css({display:'none'});
		}
    }
	saveCrtTab({currentzBookmark:n});
}

function tabChange(id){
	zIndex("subNav");
	var link = $("li", $("#subNav"));
	if(id == 1){
		var tmp = link[0];
		if(tmp){
			id = tmp.id.substr(11);
		}
	}
	link.each(function(){
		var e = $(this);
		if(this.id == ("classTitle_" + id)){
			e.attr('className', e.attr('className').replace('Out', 'On')).css({zIndex:1000});
		}else{
			e.attr('className', e.attr('className').replace('On', 'Out'));
		}
	});
	$(".threeNav").each(function(){
		if(this.id == ("secNav_" + id)){
			$(this).css({display:''});
		}else{
			$(this).css({display:'none'});
		}
	});
	link = $("a", $("#secNav_" + id));
	if(link.size() > 0){
		var cid = link[0].id.substr(9);
		subTabChange(cid, id);
	}else{
		$(".tabDiv").each(function(){
			if(this.id == ("classInfo_" + id)){
				$(this).css({display:''});
			}else{
				$(this).css({display:'none'});
			}
		});
	}
	saveCrtTab({currentzBookmark:id});
}

function subTabChange(id, pid){
	$("a", $("#secNav_" + pid)).each(function(){
		if(this.id == ("secNavLi_" + id)){
			$(this).attr({className:'aHover'});
		}else{
			$(this).attr({className:''});
		}
	});
	$(".tabDiv").each(function(){
		if(this.id == ("classInfo_" + id)){
			$(this).css({display:''});
		}else{
			$(this).css({display:'none'});
		}
	});
}

function saveCrtTab(params){
	var url = $.url.init(document.location.href);
	if(params){
		for(var key in params)
			url.setParam(key, params[key]);
	}
	var crtUrl = url.getUrl();
	var paramMap = {action:"saveCrtTab", url:crtUrl, encode:'false'};
//	if(document.location.pathname == '' || document.location.pathname == '/'){
//		paramMap.url = 'http://' + document.location.host + 
//			((document.location.port == '' || document.location.port == '80') ? '' : ':'+document.location.port) +
//			'/cr/' + params['currentzBookmark'];
//	}
	$.post('page',paramMap,function(data){});
}


var PicUtil = {
	_timer : null,
	play : function(ele, pagename){
		var imgs = $("img", ele);
		//初始化计算器
		var crt = {
			_crt : 1,
			_count : 1,
			init : function(i,n){
				_crt = i;
				_count = n;
			},
			current : function(){
				return _crt;
			},
			last : function(){
				_crt = _crt > 1 ? (_crt - 1) : _count;
				return _crt;
			},
			next : function(){
				_crt = _crt < _count ? (_crt + 1) : 1;
				return _crt;
			}
		};
		crt.init(1,imgs.length);
		//初始化图片样式
		this.init(imgs);
		//切换图片目录
		imgs.each(function(i){
			var pos = this.src.lastIndexOf("/");
			var str = this.src.substring(0, pos);
			this.src = str.substring(0, str.lastIndexOf("/")) + "/" + pagename + this.src.substring(pos, this.src.length);
		});
		
		this._timer = setInterval(function(){
			//随机图片
			var newidx = (Math.floor(Math.random() * imgs.length * 2) % (imgs.length - 1)) + 1;
			if(newidx != (crt.current()-1)){
				var crtimg = imgs.get(crt.current() == imgs.length ? 1 : crt.current());
				var newimg = imgs.get(newidx);
				var tmp = crtimg.src;
				crtimg.src = newimg.src;
				newimg.src = tmp;
			}
			//轮换显示
			$(imgs.get(crt.current()-1)).animate({opacity:0}, 1000, null, function(){
				$(imgs.get(crt.current()-1)).css({display:"none"});
				$(imgs.get(crt.next()-1)).css({display:"block"}).animate({opacity:1}, 1000);
			});
		},8000);
	},
	
	init : function(imgs){
		imgs.each(function(i){
			if(i == 0)
				$(this).css({display:"block", opacity:1});
			else
				$(this).css({display:"none", opacity:0});
		});
		if(this._timer != null){
			window.clearInterval(this._timer);
			this._timer = null;
		}
	}
}
