var pageHeader = new function() {
	this.is_verify = false;
	this.obj = null;
	this.html = [];
	this.category_more = function(num,val) {
		var arr = kj.obj("#id_header_category .M_Drop");
		if(!arr || arr.length<num) return;
		for(var i = num;i<arr.length;i++) {
			arr[i].style.display=val;
		}

		if(val == 'none') {
			kj.set("#id_header_category .categorys_more i" , "className" , "arr_down");
		} else {
			kj.set("#id_header_category .categorys_more i" , "className" , "arr_up");
		}
	}
	this.showlogin = function() {
		kj.dialog.close("#winshowreg");
		var obj = kj.obj('#id_loginbox');
		if(obj) {
			this.login_html = obj.innerHTML;
			kj.remove(obj);
		}
		kj.dialog({'html':this.login_html,'id':'showlogin','type':'html','title':'会员登录','w':600,'showbtnmax':false,'showbtnhide':false});
	}
	this.show_verify = function() {
		var objpic = kj.obj("#id_verify_pic");
		if(objpic.src.indexOf("verifycode")<0) {
			objpic.src = kj.cfg('baseurl') + '/common.php?app=sys&app_act=verifycode';
			kj.handler(document.documentElement,"click",function(e){
				var arr = new Array('img' , 'input');
				var target = kj.event_target(e);
				if(target.name!='verifycode' && target.id!='id_verify_pic') {
					kj.hide('#id_verify_pic');
				}
			});
		}
		kj.show('#id_verify_pic');
	}
	this.on_login = function() {
		if(!document.frmlogin) return;
		if(this.is_verify === null) this.is_verify = kj.cfg("is_verify");
		if(kj.rule.form(document.frmlogin,1) == false) return false;
		kj.ajax.post(document.frmlogin , function(data) {
			var obj_data=kj.json(data);
			if(obj_data.isnull) {
				alert("系统繁忙，请稍后再来试试");
			} else {
				if(obj_data.code == 0) {
					if('jump_fromurl' in document.frmlogin && document.frmlogin.jump_fromurl.value!='') {
						window.open(document.frmlogin.jump_fromurl.value , "_self");
					} else {
						location.reload(true);
					}
				} else {
					if('msg' in obj_data && obj_data.msg) {
						alert(obj_data.msg);
					} else {
						alert("系统繁忙，请稍后再来试试");
					}
					if(this.is_verify) {
						jsheader.verify_refresh();
						document.frmlogin.verifycode.value='';
					}
					if('show_code' in obj_data && obj_data.show_code == '1') {
						this.is_verify = true;
						kj.show("#id_verify_code");
					}
					if(obj_data.code == '4') document.frmlogin.uname.focus();
					if(obj_data.code == '3') document.frmlogin.pwd.focus();
					if(obj_data.code == '11') document.frmlogin.verifycode.focus();
				}
			}
		});
		return false;
	}
	this.verify_refresh = function() {
		kj.obj("#id_verify_pic").src = kj.cfg('baseurl') + '/common.php?app=sys&app_act=verifycode&app_contenttype=img&app_rnd='+Math.random();
	}
	this.showreg = function() {
		kj.dialog.close("#winshowlogin");
		if("reg" in this.html) {
			kj.dialog({'html':this.html['reg'],'id':'showreg','type':'html','title':'注册会员','w':600,'showbtnmax':false,'showbtnhide':false});
		} else {
			kj.ajax.get(kj.cfg('baseurl') + "/index.php?app_act=reg" , function(data) {
				pageHeader.html['reg'] = data;
				kj.dialog({'html':data,'id':'showreg','type':'html','title':'注册会员','w':600,'showbtnmax':false,'showbtnhide':false});
				kj.loadjs(pageHeader.tempurl + "js/page.reg.js",function() {
					if(typeof(pageReg) == 'undefined') return;
					pageReg.reg_verify = pageHeader.reg_verify;
					pageReg.rule_uname = pageHeader.rule_uname;
				});
			});
		}
	}

}