
var loading = false;
var isIndexPage = true;
WGP.Reg = {

	loaded : '',
	
	canReg :  false,

	resetValidate : function(){
		this.canReg = false;
		
	},

	init : function(){
		
		var ids = ['uid','pwd','repwd','email'];
		for( var i=0; i<ids.length; i++ ){
			var id = ids[i];
			$(id).onfocus = function(){
				WGP.Reg.showInfo(this.id);
			}
			$(id).onblur = function(){
				WGP.Reg.check(this.id);
			}
		}

		this.loaded = 'init';
		
	},
	
	show : function(){
		if( this.loaded=='' ){
			this.init();
		}
		if(  $('Reg').style.display != 'block' ){
			WGP.Reg.Pop.show();
			WGP.Reg.resetValidate();
		} else {
			WGP.Reg.Pop.hide();
		}
	},

	submit : function(){
		this.canReg = true;

		if( loading ){
			return;
		}
		if(this.canReg){
			this.check('uid');
		}		
		if(this.canReg){
			this.check('pwd');
		}
		if(this.canReg){
			this.check('repwd');
		}
		if(this.canReg){
			this.check('email');
		}
		if(this.canReg){
			//this.check('vcode');
		}		
		if( this.canReg ){
			loading = true;
			$('formReg').submit();
		}
	},
	
	check : function(id){
		if(id=='uid'){
			this.checkUser();
		}
		else if(id=='email'){
			this.checkEmail();
		}
		else{
			this.checkOthers(id);
		}
	},
	
	checkUser : function(){
		var value = $("uid").value.trim();
		if(value==''){
			this.showError( 'uid','用户名不能为空' );
			return false;
		}
		else if( value.length<6 || value.length>16 ){
			this.showError( 'uid','使用数字和字母，长度为6-16个字符' );
			return false;
		}
		var cache = this.getCache(value);
		if( cache.value=='' ){
			this.validate( 1, value, 'WGP.Reg.callbackUser' );
		}
		else {
			if( cache.value!='true' ){
				this.showError('uid',cache.value);
			}
			else {
				this.showRight('uid','用户名可以使用');
			}
		}
	},

	callbackUser : function(res){
		var id = 'uid';
		var msg = '';
		switch(res){
			case -11 :
				msg = '使用数字和字母，长度为6-16个字符';
				break;
			case -12 :
				msg = '用户名已经被使用';
				break;
			case -13 :
				msg = '用户名不合法';
				break;
		}
		if(res<0){
			this.showError(id,msg);
			this.cache[this.cache.length-1].value = msg;
		}
		else {
			this.cache[this.cache.length-1].value = 'true';
			msg = '用户名可以使用';
			this.showRight(id,msg);
		}	
	},
	
	checkEmail : function(){
		var id = 'email';
		var value = $(id).value.trim();
		if(value==''){
			this.showError( id,'邮箱不能为空' );
			return false;
		}
		else if(value.indexOf('@')==-1){
			this.showError( id,'邮箱格式不正确' );
			return false;
		}

		var cache = this.getCache(value);
		if( cache.value=='' ){
			this.validate( 2, value, 'WGP.Reg.callbackEmail' );
		}
		else {
			if( cache.value!='true' ){
				this.showError(id,cache.value);
				return false;
			}
			else {
				this.showRight(id,'邮箱地址可以使用');
			}
		}
	},
	callbackEmail : function(res){
		var id = 'email';
		var msg = '';
		switch(res){
			case -21 :
				msg = '邮箱地址格式不正确';
				break;
			case -22 :
				msg = '邮箱地址已经被使用';
				break;
		}
		if(res<0){
			this.showError(id,msg);
			this.cache[this.cache.length-1].value = msg;
		}
		else {
			this.cache[this.cache.length-1].value = 'true';
			msg = '邮箱地址可以使用';
			this.showRight(id,msg);
		}	
	},

	checkOthers : function(id){
		var value = $(id).value.trim();
		if(id=='pwd'){
			if(value==''){
				this.showError( id, '密码不能为空' );
			}
			else if(value.length<4 || value.length>20){
				this.showError( id,'密码长度应为4-20个字符' );
			}
			else {
				this.showRight(id,'输入正确');
			}
		}
		if(id=='repwd'){
			var pwd = $('pwd').value.trim();
			if(value=='' || value!=pwd ){
				this.showError(id,'两次输入的密码不一致');
			}
			else {
				this.showRight(id,'输入正确');
			}
		}
		
		if(id=='vcode'){
			if(value==''){
				this.showError(id,'验证码不能为空' );
			}
			else if(value.length!=4){
				this.showError(id,'验证码不正确，请重新输入' );
			}
			else {
				this.showRight(id,'请输入图片中的字符，点击更换图片');
			}
		}
	},
	
	
	showInfo : function (id){
		var msg = '';
		$('uid_msg').style.fontWeight = 'normal';
		$('pwd_msg').style.fontWeight = 'normal';
		$('repwd_msg').style.fontWeight = 'normal';
		$('email_msg').style.fontWeight = 'normal';
		
		if( $(id+'_img') ){
			$(id+'_img').innerHTML = '';
		}
		switch(id){
			case 'email':
				msg = '请认真填写你的真实邮箱';
				break;
			case 'pwd':
				msg = '使用数字和字母，长度为4-20个字符';
				break;
			case 'uid':
				msg = '使用数字和字母，长度为6-16个字符';
				break;			
			case 'vcode':
				msg = '请输入图片中的字符，点击更换图片';
				break;			
		}	
		var obj = $(id+'_msg');
		obj.className = '';
		obj.innerHTML = msg;
	},


	showError : function(id,msg){
		$(id+'_msg').className = 'fontRed';
		$(id+'_msg').innerHTML = msg;
		//$(id+'_msg').style.fontWeight = 'normal';
		this.canReg = false;
	},
	showRight : function(id,msg){
		$(id+'_msg').className = '';
		$(id+'_msg').innerHTML = msg;
		this.canReg = true;
	},
	
	cache : [],

	getCache : function( key ){
		var value = null;
		for( var i=0; i<this.cache.length; i++ ){
			if( this.cache[i].name==key ){
				value = this.cache[i];
				break;
			}
		}
		if( value==null ){
			this.cache.push( {name:key,value:''} );
			value = this.cache[this.cache.length-1];
		}
		return value;
	},

	validate : function( type, value, callback ){
		var url = WGP.Config.passportAPI;
		url += '?action=VALIDATE&type='+type+'&value='+value+'&callback='+callback;
		var loader = new WGP.Common.Loader();
		loader.loadJS( url );
	}
}

WGP.Reg.Pop = {
	show : function(w,h){
		var clientWidth = document.documentElement.scrollWidth;
		var clientHeight = document.documentElement.scrollHeight;
		
		var mask = $('mask');
		mask.style.display = 'block';
		mask.style.height = clientHeight + "px"; 
		mask.style.width = clientWidth + "px"; 
	
		var reg = $('Reg');
		reg.style.display = 'block';
		reg.style.left = (clientWidth - reg.offsetWidth)/2 + 'px';
		reg.style.top = 100 + 'px';
		document.documentElement.scrollTop = 0;
		reg.onresize = function(){
			var frmBG = $('frmBG');
			frmBG.style.display = this.style.display;
			frmBG.style.left = this.style.left;
			frmBG.style.top = this.style.top;
			frmBG.style.width = this.style.width;
			frmBG.style.height = this.style.height;
		}
	},
	hide : function(){
		$('frmBG').style.display = 'none';
		$('mask').style.display = 'none';
		$('Reg').style.display = 'none';
	}
}

WGP.Passport = {
	post : function(data){
		var params = '?action=' + data.action;
		for( var key in data ){
			params += '&' + key + '=' + data[key];
		}
		var url = WGP.Config.passportAPI + params;
		var loader = new WGP.Common.Loader();
		loader.loadJS( url );
	}

}

WGP.Passport1 = {
	post : function(data){
		//var params = '?action=' + data.action;
		var params = '?';
		for( var key in data ){
			params += '&' + key + '=' + data[key];
		}
		var url = WGP.Config.login + params;
		var loader = new WGP.Common.Loader();
		loader.loadJS( url );
	}

}

WGP.Pwd = {
	show : function(){
		var pop = new WGP.Pop('pop_pwd','找回密码');
		var html = WGP.Pwd.Tpl.form.join('');
		pop.html(html);
		pop.show();
		$('pop_pwd_img').src = WGP.Config.validateImg + '?r=' +  Math.random();
	},
	hide : function(){
		var pop = new WGP.Pop('pop_pwd');
		pop.hide();
	},
	
	submit : function(){
		if( $('pop_pwd_uid').value.trim()=='' ){
			alert( '用户名不能为空' );
			return;
		}
		if( $('pop_pwd_email').value.trim()=='' ){
			alert( '邮箱不能为空' );
			return;
		}
		if( $('pop_pwd_vcode').value.trim()=='' ){
			alert( '验证码不能为空' );
			return;
		}
		this.hide();

		var data = {
			action : 'RESET_PASSWORD',
			uid : $('pop_pwd_uid').value.trim(),
			email : $('pop_pwd_email').value.trim(),
			//vcode : $('pop_pwd_vcode').value.trim(),
			callback : 'WGP.Pwd.callback'
		}
		WGP.Passport.post(data);
	},

	info : function( content ){
		var pop = new WGP.Pop('pop_pwd_remind','操作提示',false);
		var data = {
			message  : content
		}
		var html = WGP.Pwd.Tpl.info.join('').process(data);
		pop.html(html);
		pop.show();
	},
	hideinfo : function(){
		var pop = new WGP.Pop('pop_pwd_remind');
		pop.hide();
	},
	callback : function(res){
		var msg = [];
		msg['-1'] = '验证码无效';
		msg['0'] = '通行证不存在或注册邮箱不正确';
		msg['1'] = '密码已经发送到你的邮箱，请查收';
		var content = msg[res];

		var pop = new WGP.Pop('pop_pwd_remind','操作提示');
		var data = {
			message  : content
		}
		var html = WGP.Pwd.Tpl.info.join('').process(data);
		pop.html(html);
		pop.show();
	}
}

WGP.Pwd.Tpl = {
	form : [	
	'<div class="main dialog_2">',
	'<h1><img src="images/r_title_3.jpg" /></h1>',
	'<p class="fontLabel">*<label>通行证用户名</label><input type="text" id="pop_pwd_uid"  class="iText iW165" /></p>',
	'<p class="fontLabel">*<label>注&nbsp;册&nbsp;邮&nbsp;箱</label>&nbsp;<input type="text" id="pop_pwd_email" class="iText iW65" /></p>',
	'<p class="fontLabel">*<label>验&nbsp;&nbsp;&nbsp;证&nbsp;&nbsp;&nbsp;码</label><input class="iText iW85"  type="text" id="pop_pwd_vcode" size="4" /><img id="pop_pwd_img" src="'+WGP.Config.validateImg+'"/></p>',
	'<div class="handle"><a href="javascript:WGP.Pwd.submit()" class="iBtn2 iB6"></a><a href="javascript:WGP.Pwd.hide()" class="iBtn2 iB4"></a></div>',
   '</div>'	
	],
	info_ : [
		'<div class="item">${message}</div>',
		'<div class="item button"><input id="remind_ok" onclick="WGP.Pwd.hideinfo()" type=button value="确 定" /><input id="remind_cancel" onclick="WGP.Pwd.hideinfo()" type=button value="取 消" /></div>'
	],
	info : [
		'<div class="main dialog_2">',
			'<p>',
			'<p>',
			'<p class="fontLabel">&nbsp;&nbsp;${message}<p>',
			'<div class="handle"><a href="javascript:WGP.Pwd.hideinfo();" class="iBtn2 iB6"></a><a href="javascript:WGP.Pwd.hideinfo();" class="iBtn2 iB4"></a></div>',
			'</div>'
	]
}



WGP.Pop = function( id, title, bg ){
	bg = bg==null ? true : false;

	this.id = id;
	
	if( $(id)==null ){
		var pop = document.createElement("div");
		//pop.className = "pop_remind";
		pop.id = this.id;
		var html = [
			//'<h2>'+title+'</h2>',
			'<div class="content" id="'+id+'_content"></div>',
			'<div class="bottom"></div>'
		];
		pop.innerHTML = html.join('');
		document.body.appendChild(pop);
	}

	this.html = function(html){
		$(id+'_content').innerHTML = html;
	}
	
	this.show = function(){
		var clientWidth = document.documentElement.scrollWidth;
		var clientHeight = document.documentElement.scrollHeight;
		
		if( bg ){
			var mask = $('mask');
			mask.style.display = 'block';
			mask.style.height = clientHeight + "px"; 
			mask.style.width = clientWidth + "px"; 
		}

		var div = $(this.id);
		div.style.zIndex = 1002;
		div.style.display = 'block';
		div.style.position = 'absolute';
		div.style.left = (clientWidth - div.offsetWidth)/2 + 'px';
		var y = (document.documentElement.clientHeight - div.offsetHeight)/2 + document.documentElement.scrollTop - 80;
		div.style.top = y + 'px';
		div.onresize = function(){
			var frmBG = $('frmBG');
			frmBG.style.display = this.style.display;
			frmBG.style.left = this.style.left;
			frmBG.style.top = this.style.top;
			frmBG.style.width = this.style.width;
			frmBG.style.height = this.style.height;
		}
	}

	this.hide = function(){
		
		$(id).style.display = 'none';
		if( bg &&  $('mask') ){
			$('mask').style.display = 'none';
		}
		$('frmBG').style.display = 'none';
	}
	
	
}

WGP.Pop.Info = {
	show : function(message){
		var pop = new WGP.Pop('pop_remind','操作提示');
		var data = {
			message  : message
		}
		var html = this.template.join('').process(data);
		pop.html(html);
		pop.show();
	},
	
	hide:function(){
		var pop = new WGP.Pop('pop_remind','操作提示');
		pop.hide();
		if( this.onclick!=null ){
			this.onclick();
		}
	},

	onclick : function(){},
	template : [
		'<div class="main dialog_2">',
			'<p>',
			'<p>',
			'<p class="fontLabel">&nbsp;&nbsp;${message}<p>',
			'<div class="handle"><a href="javascript:WGP.Pop.Info.hide();" class="iBtn2 iB6"></a><a href="javascript:WGP.Pop.Info.hide();" class="iBtn2 iB4"></a><div class="handle">',
			'</div>'
	]
}

WGP.Pop.Tpl = {
	info: [
			'<div class="main dialog_2">',
			'<p>',
			'<p>',
			'<p class="fontLabel">&nbsp;&nbsp;${message}<p>',
			'<div class="handle"><a href="javascript:WGP.Pwd.hideinfo();" class="iBtn2 iB6"></a><a href="javascript:WGP.Pwd.hideinfo();" class="iBtn2 iB4"></a></div>',
			'</div>'
	]
}


window.onload = function(){
	WGP.Swd.onload();
	var url = window.location.href;
	if(url.endsWith('?0') ){
		WGP.Pop.Info.onclick = function(){
			window.location.href = url.replace( /\?0$/g,'');
		}
		WGP.Pop.Info.show('<em style="color:red;">信息提交成功，请到注册邮箱收取帐号激活邮件，按提示激活您的帐号。</em>');
	}
	else if(url.endsWith('?100') ){
		WGP.Pop.Info.onclick = function(){
			window.location.href = url.replace( /\?100$/g,'');
		}
		WGP.Pop.Info.show('无效请求(数据不完整)');
	}
	else if(url.endsWith('?101') ){
		WGP.Pop.Info.onclick = function(){
			window.location.href = url.replace( /\?101$/g,'');
		}
		WGP.Pop.Info.show('验证码无效');
	}
	else if(url.endsWith('?102') ){
		WGP.Pop.Info.onclick = function(){
			window.location.href = url.replace( /\?102$/g,'');
		}
		WGP.Pop.Info.show('注册失败(未知错误)');
	}
	else if(url.endsWith('?200') ){
		WGP.Pop.Info.onclick = function(){
			window.location.href = url.replace( /\?200$/g,'');
		}
		WGP.Pop.Info.show('帐号未激活');
	}
	else if(url.endsWith('?201') ){
		WGP.Pop.Info.onclick = function(){
			window.location.href = url.replace( /\?201$/g,'');
		}
		WGP.Pop.Info.show('用户名或密码错误');
	}
	


}


WGP.Passport.Active = {
	show : function(w,h){
		var clientWidth = document.documentElement.scrollWidth;
		var clientHeight = document.documentElement.scrollHeight;
		//显示遮罩
		var mask = $('mask');
		mask.style.display = 'block';
		mask.style.height = clientHeight + "px"; 
		mask.style.width = clientWidth + "px"; 
		//
		var reg = $('Active');
		reg.style.display = 'block';
		reg.style.left = (clientWidth - reg.offsetWidth)/2 + 'px';
		reg.style.top = 100 + 'px';
		document.documentElement.scrollTop = 0;
		reg.onresize = function(){
			var frmBG = $('frmBG');
			frmBG.style.display = this.style.display;
			frmBG.style.left = this.style.left;
			frmBG.style.top = this.style.top;
			frmBG.style.width = this.style.width;
			frmBG.style.height = this.style.height;
		}
	},
	hide : function(){
		$('frmBG').style.display = 'none';
		$('mask').style.display = 'none';
		$('Active').style.display = 'none';
	},
	send : function(){

		var uid = $('active_uid').value.strip();
		var mail = $('active_mail').value.strip();

		if( uid=='' ){
			alert( '请输入注册帐号' );
			$('active_uid').focus();
			return;
		}
		if( mail=='' ){
			alert( '请输入注册邮箱' );
			$('active_mail').focus();
			return;
		}
		var url = WGP.Config.passportAPI + '?action=RESEND_ACTIVE_MAIL&uid='+uid+'&email='+mail+'&callback=WGP.Passport.Active.sendBack';
		var loader = new WGP.Common.Loader();
		loader.loadJS( url );

	},
	sendBack : function(res){
		if( res==-1 ){
			WGP.Pop.Info.show('帐号无效');
		} else if( res==-2 ){
			WGP.Pop.Info.show('帐号或邮箱不正确');
		} else if( res==-3 ){
			WGP.Pop.Info.show('两次重发激活邮件操作的时间过短，请30秒稍后再试!');
		} else if( res==1 ) {
			WGP.Pop.Info.show( '您好，激活邮件已发送到'+$('active_mail').value.strip()+'，请登录邮箱收取邮件，按提示激活您的帐号。' );
			WGP.Passport.Active.hide();
		}
	}
}



WGP.Passport.Mail = {
	show : function(w,h){
		$('pmail_uid').value = $('active_uid').value;
		if( $('Active') ){
			$('Active').style.display = 'none';
		}
		var clientWidth = document.documentElement.scrollWidth;
		var clientHeight = document.documentElement.scrollHeight;
		//显示遮罩
		var mask = $('mask');
		mask.style.display = 'block';
		mask.style.height = clientHeight + "px"; 
		mask.style.width = clientWidth + "px";
		//
		var reg = $('PMail');
		reg.style.display = 'block';
		reg.style.left = (clientWidth - reg.offsetWidth)/2 + 'px';
		reg.style.top = 100 + 'px';
		reg.style.position = 'absolute';
		reg.style.zIndex = 10000;
		document.documentElement.scrollTop = 0;
		
		reg.onresize = function(){
			var frmBG = $('frmBG');
			frmBG.style.display = this.style.display;
			frmBG.style.left = this.style.left;
			frmBG.style.top = this.style.top;
			frmBG.style.width = this.style.width;
			frmBG.style.height = this.style.height;
		}
	},
	hide : function(){
		$('frmBG').style.display = 'none';
		$('mask').style.display = 'none';
		$('PMail').style.display = 'none';
	},
	send : function(){
		var uid = $('pmail_uid').value.strip();
		var mail = $('pmail_mail').value.strip();
		var pwd = $('pmail_pwd').value.strip();
		if( uid=='' ){
			alert( '请输入注册帐号' );
			$('pmail_uid').focus();
			return;
		}
		if( pwd=='' ){
			alert( '请输入密码' );
			$('pmail_pwd').focus();
			return;
		}
		if( mail=='' ){
			alert( '请输入注册邮箱' );
			$('pmail_mail').focus();
			return;
		}
		var url = WGP.Config.passportAPI + '?action=MODIFY_MAIL&uid='+uid+'&email='+mail+'&password='+pwd+'&callback=WGP.Passport.Mail.sendBack';
		var loader = new WGP.Common.Loader();
		loader.loadJS( url );
	},
	sendBack : function(res){
		if( res==-1 ){
			WGP.Pop.Info.show('帐号或密码不正确');
			WGP.Passport.Mail.hide();
		} else if( res==-2 ){
			WGP.Pop.Info.show('邮箱无效或已被使用');
			WGP.Passport.Mail.hide();
		} else if( res==1 ) {
			WGP.Pop.Info.show( '您好，您的注册邮箱已改为'+$('pmail_mail').value.strip()+'，如果您的帐户还没激活，激活邮件已发送到'+$('pmail_mail').value.strip()+'，请登录邮箱收取邮件，按提示激活您的帐号。' );
			WGP.Passport.Mail.hide();
		}
	}
}

WGP.Pwd.Modify = {
	show : function(){
		var pop = new WGP.Pop('pop_pwd_modify','修改密码');
		var html = this.template.form.join('');
		pop.html(html);
		pop.show();
	},
	hide : function(){
		var pop = new WGP.Pop('pop_pwd_modify');
		pop.hide();
	},
	
	submit : function(){
		if( $('pop_pwd_modify_uid').value.trim()=='' ){
			alert( '用户名不能为空' );
			return;
		}
		if( $('pop_pwd_modify_pwd').value.trim()=='' ){
			alert( '原密码不能为空' );
			return;
		}
		if( $('pop_pwd_modify_newpwd').value.trim()=='' ){
			alert( '新密码不能为空' );
			return;
		}
		if( $('pop_pwd_modify_renewpwd').value.trim()!=$('pop_pwd_modify_newpwd').value.trim() ){
			alert( '新密码与确认密码不同' );
			return;
		}

		var data = {
			action : 'PASSWORD',
			uid : $('pop_pwd_modify_uid').value.trim(),
			pwd : $('pop_pwd_modify_pwd').value.trim(),
			newpwd : $('pop_pwd_modify_newpwd').value.trim(),
			callback : 'WGP.Pwd.Modify.callback'
		}
		WGP.Passport.post(data);
	},

	info : function( content ){
		var pop = new WGP.Pop('pop_pwd_modify_remind','操作提示',false);
		var data = {
			message  : content
		}
		var html = WGP.Pwd.Tpl.info.join('').process(data);
		pop.html(html);
		pop.show();
	},
	hideinfo : function(){
		var pop = new WGP.Pop('pop_pwd_modify_remind');
		pop.hide();
	},
	callback : function(res){

		if( res==1 ){
			this.hide();
		}

		var msg = [];
		msg['-1'] = '通行证不存在或密码不正确';
		msg['-2'] = '密码无效，长度必须为4-20个字符';
		msg['1'] = '密码更改成功';
		var content = msg[res];

		var pop = new WGP.Pop('pop_pwd_modify_remind','操作提示');
		var data = {
			message  : content
		}
		var html = this.template.info.join('').process(data);
		pop.html(html);
		pop.show();
	},

	template : {
       form : [
            '<div class="main dialog_2">',
			'<p>',
	        '<p class="fontLabel">*<label>通行证用户名</label><input type="text" id="pop_pwd_modify_uid"  class="iText iW165" /></p>',
	        '<p class="fontLabel">*<label>原&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;码</label><input type="password" id="pop_pwd_modify_pwd"  class="iText iW165" /></p>',
	        ' <p class="fontLabel">*<label>新&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;码</label><input type="password" id="pop_pwd_modify_newpwd" class="iText iW165" /></p>',
	        ' <p class="fontLabel">*<label>确&nbsp;认&nbsp;密&nbsp;码&nbsp;</label><input type="password" id="pop_pwd_modify_renewpwd"  class="iText iW165" /></p>',
	     '<div class="handle"><a href="javascript:WGP.Pwd.Modify.submit();" class="iBtn2 iB6"></a><a href="javascript:WGP.Pwd.Modify.hide();" class="iBtn2 iB4"></a></div></div>'
		 ],	
		info : [
		    '<div class="main dialog_2">',
			'<p>',
			'<p>',
			'<p class="fontLabel">&nbsp;&nbsp;${message}<p>',
			'<div class="handle"><a href="javascript:WGP.Pwd.Modify.hideinfo();" class="iBtn2 iB6"></a><a href="javascript:WGP.Pwd.Modify.hideinfo();" class="iBtn2 iB4"></a></div>',
			'</div>'
		]
	}
}

WGP.Swd = {
	doxmlhttp : function(url,msg){
		//alert(msg);
		if(msg=='1'){
			WGP.Swd.xmlhttp.sendRequest(url);
		}else if(msg=='201'){
			//alert('dfdfd');
			$("login_uid").value='';
			$("login_pwd").value='';
			$("login_uid").focus();
			WGP.Pop.Info.show('用户名或密码错误！');
			$('Login_loading').hide();
			//window.location.reload();
		}else{//200 帐号未激活
			$("login_uid").value='';
			$("login_pwd").value='';
			$("login_uid").focus();
			WGP.Pop.Info.show('帐号未激活！');
			$('Login_loading').hide();
		}
	},
	hide : function(){
		var pop = new WGP.Pop('pop_pwd');
		pop.hide();
	},
	
	submit : function(){
		var uid = $("login_uid").value.trim();
		if( uid=='' ){
			alert('帐号不能为空');
			$("login_uid").focus();
			return;
		}
		var pwd = $("login_pwd").value.trim();
		if( pwd=='' ){
			alert('密码不能为空');
			$("login_pwd").focus();
			return;
		}
		var data = {
			action : 'LOGIN',
			login_uid : uid,
			login_pwd : pwd,
			callback : 'WGP.Swd.doxmlhttp'
		}
		WGP.Swd.showLoading('Login');
		WGP.Passport1.post(data);
	},
	
	onload : function(){
		WGP.Swd.xmlhttp.sendRequest(WGP.Config.wgpassport);
	},

	showLoading : function(eid,index)
		{
		    isIndexPage = index;
			var pe = $(eid);
			if(pe)
			{
				var cid = eid+"_loading";
				var ce= $(cid);
				if(ce==null)
				{
					var dw = pe.offsetWidth?pe.offsetWidth:pe.width;
	        var dh = pe.offsetHeight?pe.offsetHeight:pe.height;
					ce = document.createElement('div');
		
					ce.id = cid;
					ce.className = 'loading';
		
					ce.style.width = dw+'px';
	
					ce.style.height = dh+'px';
	        ce.innerHTML= "<div style=\"position:absolute;left:"+(dw/2-16)+"px;top:"+(dh/2-16)+"px;opacity:1;\"><img src=\"images/loading.gif\" border=\"0\" /><br/></div>";
	
	        pe.style.position = "relative";
					pe.appendChild(ce);
				}else{
					ce.show();
				}
			}
			
		},


	info : function( content ){
		var pop = new WGP.Pop('pop_pwd_remind','操作提示',false);
		var data = {
			message  : content
		}
		var html = WGP.Pwd.Tpl.info.join('').process(data);
		pop.html(html);
		pop.show();
	},
	hideinfo : function(){
		var pop = new WGP.Pop('pop_pwd_remind');
		pop.hide();
	}
}

WGP.Swd.xmlhttp = {
		createXMLHttpRequest : function () 
		{      
			if(window.XMLHttpRequest) { 
			 	XMLHttpReq = new XMLHttpRequest(); 
			}else if (window.ActiveXObject) {
			  try {    
			  	XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			  }catch(e){
			      try{     
			         	XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			      }catch(e){
			      
			      }
			  }
		    } 
		},
		
 
		sendRequest : function (url) {     
			WGP.Swd.xmlhttp.createXMLHttpRequest();  
			
			if(url.indexOf('?')>0)
				url += '&t='+Math.random();
			else
				url += '?t='+Math.random();   
				
			XMLHttpReq.open("GET", url, true);      
			XMLHttpReq.onreadystatechange = WGP.Swd.xmlhttp.processResponse;
			XMLHttpReq.send(null);  
		},
		
       
		processResponse : function (){        
			if(XMLHttpReq.readyState == 4){          
				if(XMLHttpReq.status == 200){ 
					var data = XMLHttpReq.responseText;
					
					var jsonData = XMLHttpReq.responseText.evalJSON();
					//alert(jsonData.flag);
					if(jsonData.flag==0){
                        if(isIndexPage == true)		{			
						  var outHtml = WGP.Swd.xmlhttp.getContent(WGP.Swd.xmlhttp.sucessInfo,jsonData);
						  document.getElementById("Login").className="cols_login";
						}else{
						  var outHtml = WGP.Swd.xmlhttp.getContent(WGP.Swd.xmlhttp.sucessInfo_otherPage,jsonData);
						  document.getElementById("Login").className="cols_login";
						}
					}else if(jsonData.flag==1){
					if(isIndexPage == true)	{
						var outHtml = WGP.Swd.xmlhttp.getContent(WGP.Swd.xmlhttp.loginInfo,jsonData);
					}else{
					    var outHtml = WGP.Swd.xmlhttp.getContent(WGP.Swd.xmlhttp.loginInfo_otherPage,jsonData);
					}
					}
					document.getElementById("Login").innerHTML = outHtml;                     
				}else{            
 					window.alert("您所请求的页面有异常！");               
				}
			}
 		},
 		

		getContent: function(template,data) {
			var tpl = template.join('').replace(/&lt;/g, "<").replace(/&gt;/g, ">");
			return tpl.process(data);
		},
		
		sucessInfo : [
					'<div class="s1">&nbsp;</div>',
					'<div >',
					'<b>&nbsp;&nbsp;&nbsp;江山欢迎您: ${userID}',
					'</b></div>',
					'<div class="loginbtnpanel">',
							'<a class="loginbtn" href="javascript:window.location=\'${WGP.Config.game}\';" HIDEFOCUS>进入游戏</a>',
							'<a class="loginbtn" style="right:5px;" href="http://u.dpecn.com" target="_blank" HIDEFOCUS>推广联盟</a>',
							'<a class="loginbtn" style="top:25px;" href="javascript:WGP.Pwd.Modify.show();" HIDEFOCUS>修改密码</a>',
							'<a class="loginbtn" style="top:25px;right:5px;" href="javascript:window.location=\'${WGP.Config.logout}\';" HIDEFOCUS>注销退出</a>',
					'</div>',
					'<div class="s3"></div>'
		],
		
		loginInfo: [
		            '<div class="s1"><a href="reg.html" target="_blank">注册</a><a href="javascript:WGP.Pwd.show();">忘记密码</a></div>',
					'<div class="s2">',
					'	<a href="javascript:WGP.Swd.submit();" class="iBtn loginBtn"></a>',
					'	<input name="login_uid" id="login_uid" class="iText" value="" type="text"/>',
					'	<input name="login_pwd" id="login_pwd" class="iText" value="" onkeypress="keyPress(event)" type="password" />',
					'</div>',
					'<div class="s3"><a href="javascript:WGP.Passport.Active.show();"">没收到激活邮件?</a></div>'
		],
		
		sucessInfo_otherPage: [
				'<div class="s1">&nbsp;</div>',
					'<div >',
					'<b>&nbsp;&nbsp;&nbsp;江山欢迎您: ${userID}',
					'</b></div>',
					'<div class="loginbtnpanel">',
							'<a class="loginbtn" href="javascript:window.location=\'${WGP.Config.game}\';" HIDEFOCUS>进入游戏</a>',
							'<a class="loginbtn" style="right:5px;" href="http://u.dpecn.com" target="_blank" HIDEFOCUS>推广联盟</a>',
							'<a class="loginbtn" style="top:25px;" href="javascript:WGP.Pwd.Modify.show();" HIDEFOCUS>修改密码</a>',
							'<a class="loginbtn" style="top:25px;right:5px;" href="javascript:window.location=\'${WGP.Config.logout}\';" HIDEFOCUS>注销退出</a>',
					'</div>',
					'<div class="s3"></div>'
		],
		
		loginInfo_otherPage: [
		            '<div class="s1">&nbsp;&nbsp;</div>',
					'<div class="s2">',
					'	<a href="javascript:WGP.Swd.submit();" class="iBtn loginBtn"></a>',
					'	<input name="login_uid" id="login_uid" class="iText" value="" type="text"/>',
					'	<input name="login_pwd" id="login_pwd" class="iText" value="" onkeypress="keyPress(event)" type="password" />',
					'</div>',
					'<div class="s3"></div>'
		]
 }
