function LoginAlert(){
	window.pwShow("/Common/cmLoginPopWnd.do",300,320,1,null);
}

function loginExpandSwitch(strType){
	function responseProcess(strResponseHtml){	
		$("login_Extend_div").innerHTML=strResponseHtml;
	}
	strReqForm="action=GetExpandHtml&type="+strType;
	genXMLHttpReq(1,"/Common/cmLoginMisc.do",strReqForm,responseProcess);
}

function loginTextOnKeyDown(e,strParam){
	e = e || event ;
	if( e.keyCode ==13)	{
		return loginAction(strParam);
	}
}

function loginReload(nParentType){
	if( nParentType==0){
		window.top.pwHide();
		window.top.location.reload();
	}else{
		location.reload();
	}
}

function loginAction(strParam){
	var arrParam=strParam.split(",");
	var nActionType=parseFloat(arrParam[0]);
	var nParentType=0;
	if( arrParam.length>=1){
		nParentType=parseInt(arrParam[1]);
	}

	var strHtmlIDPrefix="login";
	var strReqForm="";
	strReqForm=genTextCheckNotNull(strHtmlIDPrefix+"_Inner_form","");
	if( strReqForm==false) return;
	var strType="";
	var emPostBtn=$(strHtmlIDPrefix+"_Act"+nActionType+"_button");
	var strPostBtnTitle="";
	switch(parseInt(nActionType)){
	case 0: 
		if( genIsValidUserName($(strHtmlIDPrefix+"_Nick_text").value)==false){
			return;
		}
		if( genIsValidEmail($(strHtmlIDPrefix+"_Email_text").value)==false){
			return;
		}
		strType="reg";
		var emPwd=$(strHtmlIDPrefix+"_pwd");
		var emRePwd=$(strHtmlIDPrefix+"_Re_pwd");
		if(emPwd.value!=emRePwd.value){
			alert(cmLang.AlertPwdNotIdentical);
			return;
		}		
		strReqForm=strReqForm+cfRegReqParam();
		break;
	case 1:
		strType="login";
		var emSavePassCheck=$(strHtmlIDPrefix+"_SavePwd_check");
		if( emSavePassCheck!=null && emSavePassCheck.checked){
			strReqForm+="&keep=1";
		}
		break;
	case 2:
		var emCode=$(strHtmlIDPrefix+"_Code_text");
		if( emCode==null || genTxtIsNull(emCode.value)==true){
			alert(cmLang.AlertInputActiveCode);
			return;
		}
		strType="active";
		break;
	case 3:
		strType="postACode";
		break;		
	case 4:
		strType="getPwd";
		break;
	case 5:
		strType="changeEmail";
		break;
	}
	
	if( emPostBtn!=null){
		emPostBtn.disabled="disabled";
		strPostBtnTitle=emPostBtn.value;
		emPostBtn.value=cmLang.Sending;
	}

	strReqForm="action="+strType+strReqForm;
	function responseProcess(strResponseHtml){
		if( emPostBtn!=null){
			emPostBtn.disabled="";
			emPostBtn.value=strPostBtnTitle;
		}
		switch(parseInt(nActionType)){
		case 0:
			cmRefreshVerifyCodeImg(strHtmlIDPrefix+"_VerifyCode_span");
			if( cfRegRespProcess(strResponseHtml)==true){
				var arrResp=strResponseHtml.split(c_strToken_Level0);
				if( arrResp.length>0){
					strResponseHtml=arrResp[0];
				}
				alert(strResponseHtml);
				genRetPrompt(strResponseHtml,strHtmlIDPrefix+"_RetInfo_div");
				if( arrResp.length>0 && arrResp[1]=="1"){
					loginReload(nParentType);
				}
				return;
			}			
			break;	
		case 1:
			if( strResponseHtml=="1"){
				loginReload(nParentType);
				strResponseHtml="";
			}else if( strResponseHtml=="-1" || strResponseHtml=="-2"){
				$(strHtmlIDPrefix+"_pwd").value="";
				if( strResponseHtml=="-1"){
					strResponseHtml=cmLang.AlertNickNotExist;
				}else{
					strResponseHtml=cmLang.AlertPwdIncorrect;
				}
			}else{
				var arrRet=strResponseHtml.split(c_strToken_Level0);
				if( arrRet[0]=="0"){
					$(strHtmlIDPrefix+"_Extend_div").innerHTML=arrRet[1];
					strResponseHtml=cmLang.AlerttFirstSignin;				
					alert(strResponseHtml);
				}
			}
			break;
		case 2:
			if(strResponseHtml=="1"){
				strResponseHtml=cmLang.AlertActiveSuccess;
				alert(strResponseHtml);
				loginReload(nParentType);
			}
			break;
		case 3:
			alert(strResponseHtml);
			break;		
		case 5:
			break;
		default:
			break;		
		}
		if(strResponseHtml!=""){
			genRetPrompt(strResponseHtml,strHtmlIDPrefix+"_RetInfo_div");
		}
	}
	genXMLHttpReq(1,"/Common/cmLoginMisc.do",strReqForm,responseProcess);
}﻿

function logout(){
	function responseProcess(strResponseHtml){	
		location.reload();
	}
	strReqForm="action=logout";
	genXMLHttpReq(1,"/Common/cmLoginMisc.do",strReqForm,responseProcess);
}

function loginRedirect(strUrl){
	location.href=strUrl;
}

function regEnable(emCheck){
	$("login_Act0_button").disabled=!emCheck.checked;	
}

