function $$(id){
	return typeof(id) == "string"?document.getElementById(id):id;
}
String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
};
var validEmail =/^[0-9a-zA-Z]+[_+\.0-9a-zA-Z-]*@([0-9a-zA-Z]([-]*[_0-9a-zA-Z])*\.){1,}([_0-9a-zA-Z]([_0-9a-zA-Z-])+)$/;
function getCookie(varName)
{
    var srcCookie=window.document.cookie;
    if(srcCookie=="")
    {
        return "";
    }
    var nPos=srcCookie.lastIndexOf(varName+"=");
    if(nPos>0)
    {   
        if(nPos>=2)
        {
            nPos=srcCookie.indexOf("; "+varName+"=",nPos-2);
        }
        else
        {
            nPos=srcCookie.indexOf("; "+varName+"=");
        }
    }
    if(nPos>=0)
    {   
        nPos=srcCookie.indexOf('=',nPos)+1;
        var nTailPos=srcCookie.indexOf("; ",nPos);
        if(nTailPos>0)
        {
            return srcCookie.substring(nPos,nTailPos);
        }
        else
        {
            return srcCookie.substr(nPos);
        }
    }
    return "";
}
/**
 * 设置cookie
 * 
 * @param key 键值
 * @param value value
 * @param isEscape 是否需要编码
 * @param isRootPath 是否根目录
 * @param cookieDomain 是否指定cookie所属域
 */
function setCookie(key, value, isEscape, cookiePath, cookieDomain, isSessionScope){
    var date = new Date();
    date.setTime(new Date().getTime() + 63072000000); //二年
    if(isEscape){
    	value = escape(value);
    }
    var rootPath = "";
    if(cookiePath && cookiePath.length > 0){
    	rootPath = "; path=" + cookiePath;
    }
    var cookieShareDomain = "";
    if(cookieDomain && cookieDomain.length > 0){
    	cookieShareDomain = "; domain=." + cookieDomain;
    }
    
    var expireTime = "";
    if(!isSessionScope){ //cookie expire scope not by session, a final value
    	expireTime = "; expires=" + date.toGMTString();
    }
    
    document.cookie = key+"=" + value + rootPath + cookieShareDomain + expireTime;
}

function switch_language(lang){
	var url = window.location.href;
	var new_url = "";
	var posi = url.indexOf("?");
	if (posi == -1){
		new_url = url +"?locate="+lang;

	}else{
		var pathPart = url.substring(0,posi);
		var paramPart = url.substring(posi+1,url.length);		
		new_url = pathPart+"?locale="+lang;
		var pairs = paramPart.split('&');
		for(var i=0;i<pairs.length;i++){
			if (pairs[i].indexOf("locale=")!=0 && pairs[i].indexOf("code=")!=0){
				new_url+="&"+pairs[i];
			}
		}
	}
	window.location.href=new_url;
}
function inputIsBlank(obj){
	if ( obj != null && obj.value!=null && obj.value!=""){
		return false;
	}else{
		return true;
	}
}
function refresh_validcode(img_id){
	var validcode_src = $("#"+img_id).attr("src");
	var pindex = validcode_src.indexOf("?");
	if (pindex==-1){
		validcode_src = validcode_src+"?r="+new Date().getTime();
	}else{
		validcode_src = validcode_src.substring(0,pindex)+"?r="+new Date().getTime();
	}
	$("#"+img_id).attr("src",validcode_src);
}
function add_hold(hold_input_id, cascadeHandler){
	$('#'+hold_input_id).focus(function() {
		$('#'+hold_input_id+'_box_id').addClass('logtxtbox_on');
		if(cascadeHandler != null && cascadeHandler != undefined){
			cascadeHandler();
		}
	}).blur(function(){
		$('#'+hold_input_id+'_box_id').removeClass('logtxtbox_on');
		if(cascadeHandler != null && cascadeHandler != undefined){
			cascadeHandler();
		}
	}).keydown(function(event){
		if(event.keyCode!=9){
			$('#'+hold_input_id+'_hold').hide();
		} else {
			if(cascadeHandler != null && cascadeHandler != undefined){
				cascadeHandler();
			}
		}
	}).keyup(function(event){
		change_hold_show(hold_input_id,$(this).val());
		if(cascadeHandler != null && cascadeHandler != undefined){
			cascadeHandler();
		}
	}).change(function(event){
		change_hold_show(hold_input_id,$(this).val());
		if(cascadeHandler != null && cascadeHandler != undefined){
			cascadeHandler();
		}
	});
	$('#'+hold_input_id+'_hold').click(function() {
		$('#'+hold_input_id).focus();
	});
}
function change_hold_show(hold_input_id,input_val){
	if(input_val==""){
		$('#'+hold_input_id+'_hold').show();
	}else{
		$('#'+hold_input_id+'_hold').hide();
	}
}
function choose_mail_version(type){
	
	if (type == "lite"){		
		$('#span_curr_ver').attr("mail_version",'lite');
		//$('#span_curr_ver').text(mailver_lite);
		//$('#dt_curr_ver').attr("class", ver_style+" ver_img1");
		$('#ver_topspeed').attr("class","current");
		$('#ver_lagship').attr("class","");
		$('#ver_lagship').attr("title", mailver_lite_alt);
		$('#ver_topspeed').attr("title","");
		
		$('#allWayHttpsContainer').hide();
		//$("#service").val('http://'+window.location.hostname+'/lite/');
		$('#targetService').val('');
	}else{
		$('#span_curr_ver').attr("mail_version",'mail');
		//$('#span_curr_ver').text(mailver_full);
		//$('#dt_curr_ver').attr("class",ver_style);
		$('#ver_lagship').attr("class","current");
		$('#ver_topspeed').attr("class","");
		$('#ver_lagship').attr("title", "");
		$('#ver_topspeed').attr("title",mailver_full_alt);
		//$("#service").val('http://'+window.location.hostname+'/Sofia.jsp');
		var port = window.location.port;
		if (port == "" || port == "80") {
			processAllwayHttpStatus();
			$('#allWayHttpsContainer').show();
		} else {
			$('#allWayHttpsContainer').hide();
		}
	}
	//$('#mail_version_list').hide();
}

function sms_send_code(){
	var geturl = "clientdownloadsms?smsnumber="+$("#smsnumber").val()+"&smssystem="+$("#smssystem").val()+"&phoneverify="+$("#phoneverify").val()+"&locale="+locale;
	$.getJSON(geturl, function(data) {
		$("#smstip").html(data.code);
		$("#phoneverify").val('');
		refresh_validcode('phone_verify_img');
	});
}

function show_send_sms_login() {
	$("#sms_code_div").show();
}

function send_login_sms_code(contextUrl, user) {
	var phone = "";
	if ($$("loginType").value == 3) {
		if (!checkPhone()) {
			return;
		}
		phone = $$("phone").value;
	}
	$("#loginSmsCodeAnchor").hide();
	$("#firstSendTip").hide();
	$("#subSendTip").show();
	$("#smsSendFeedback").hide();
	var startPoint = 60;
	var timer;
	$.ajax({
		type: "GET",
		dataType: "jsonp",
		jsonpCallback: "jsonCallback",
		url: contextUrl + "/loginSmsCode",
		data: "username="+user+"&loginPhone="+phone+"&action=send&smssystem=mail&locale="+locale,
		crossDomain: true,
		xhrFields: {withCredentials: true},
		success: function(data) {
			$("#smsSendFeedback").show();
			$("#smsSendFeedback").text(data.code);
			if ("0" == data.result) { //fail to send sms
				$("#loginSmsCodeAnchor").show();
			} else { //sms sent
				$("#loginSmsCodeAnchor").hide();
				$("#fail").text("");
				$("#loginSmsCountdownInfo").show();
				timer = setInterval(function() {
					startPoint--;
					$("#loginSmsCountdown").text(startPoint);
					if (startPoint <= 0) {
						$("#loginSmsCountdownInfo").hide();
						$("#loginSmsCountdown").text(60);
						$("#loginSmsCodeAnchor").show();
						clearInterval(timer);
					}
				}, 1000);
			}
		}
	});
}

function mouseover(tagid){
	for(var i=1; i<4; i++){
		if( i == tagid){
			var tagObj = $$("tag_"+i);
			if(tagObj){				
				tagObj.className = "tagcur";
			}
			var phoneObj = $$("phonecon_"+i);
			if(phoneObj){				
				phoneObj.className = "tagcon show clearfix";
			}
		}else{
			var tagObj = $$("tag_"+i);
			if(tagObj){	
				tagObj.className = "";
			}
			var phoneObj = $$("phonecon_"+i);
			if(phoneObj){
				phoneObj.className = "tagcon hide clearfix";
			}
		}	
	}
}

//绑定窗口缩放事件
function bindWindowResizeEvent(){
	window.onresize = function(){
		setBrowserTipTop();
	};
	window.onscroll = function(){
		setBrowserTipTop();
	};
}

function setBrowserTipTop(){
	var bodyHeight = document.documentElement.clientHeight;
	var scrollTop = document.documentElement.scrollTop;
	var bodyWidth = document.body.scrollWidth;
	var divHeight = $("#eisp2_tip").outerHeight();
	var divTop = bodyHeight + scrollTop - divHeight;
	$$("eisp2_tip").style.top = divTop + "px";
	$$("eisp2_tip").style.width = bodyWidth + "px";
}

window.onload=function() {
	isAllLoad = true;
	
	bindChangeValueTimer();
	add_hold("user", bindChangeValueTimer);
	add_hold("password");
	add_hold("validcode");
	add_hold("phone");
	add_hold("smscode");
	//add_hold("domain_input");
	var userInput = $$("user");	
	var last = getCookie('lastuser');
	
	if (last!=null && last!='' && $("#user").val()==""){
		$("#user").val(last);
	}
	if ($("#user").val()==""){
		userInput.focus();
		$("#user_hold").show();
	}else{
		$("#user_hold").hide();
		$("#password").focus();
	}
		
	if(isFullDomainLogin && isProxy){
		var lagshipObj = $('#ver_lagship');
		if(lagshipObj){
			lagshipObj.hide();
		}
		var topspeedObj = $('#ver_topspeed');
		if(topspeedObj){
			topspeedObj.hide();
		}
		var httpsObj = $('#allWayHttpsContainer');
		if(httpsObj){
			httpsObj.hide();
		}
		var adminLogin = $('#adminLoginHref');
		if(adminLogin){
			adminLogin.hide();
		}
	} else {
		if (tosystem !=undefined){
	      if('lite' == tosystem){//如果浏览器直接lite就选lite
	    	  choose_mail_version('lite');
	      }else if ('mail' == tosystem){
	    	var lastver = getCookie('mailver');
	    	if(lastver){
	    		choose_mail_version(lastver);
	    	}
	      }
	    }
		
		if(!$('#span_curr_ver').attr("mail_version")){
	    	choose_mail_version('mail');
	    }
		
		if(tosystem != undefined && 'mail' == tosystem){
	    	processAllwayHttpStatus();
	    }
	}
    
	$("#password").keydown(function(event){
		if (event.which ==13){
			$('#submitBtn').click();
		}
	});	
	if($("#validcode")){
		$("#validcode").keydown(function(event){
			if (event.which ==13){
				$('#submitBtn').click();
			}
		});
	}
	if($("#smscode")){
		$("#smscode").keydown(function(event){
			if (event.which ==13){
				$('#submitBtn').click();
			}
		});
	}
	
    try {
    	var ie6 = navigator.userAgent.toUpperCase().indexOf("MSIE 6.0") > -1 ? true : false;
    	var ie7 = navigator.userAgent.toUpperCase().indexOf("MSIE 7.0") > -1 ? true : false;
    	var knowBrowserTip = getCookie('konwBrowserTip');
    	if('1' != knowBrowserTip){
    		if(ie6){
    			$("#browserVersionTip")[0].innerHTML = "IE6.0";
        		setBrowserTipTop();
        		bindWindowResizeEvent();
        	}
    		
            if ( ie6 || ie7 ) {
                $$("eisp2_tip").style.display = "";
                $$("oldBrowser").value="1";
            } else {
            	$$("oldBrowser").value="0";
            }
    	}
    } catch (e){	
    }
  
    
	$(".enter_btn").hover(function(){
		$(this).toggleClass("enter_btn_hover");
	}).mousedown(function(){
		$(this).addClass("enter_btn_down");
	}).mouseup(function(){
		$(this).removeClass("enter_btn_down");
	});
	$(".btn").hover(function(){
			$(this).toggleClass("enter_btn_hover");
		}).mousedown(function(){
			$(this).addClass("enter_btn_down");
		}).mouseup(function(){
			$(this).removeClass("enter_btn_down");
		});   
	
	$("#hilite_mail").hover(function(){
		$("#downld_box_mail").show();		
	});
	$("#link_2dcode_mail").hover(function(){
		$("#ppbox_2dcode").toggle();		
	});
	$("#link_2dcode_mail_phone").hover(function(){
		$("#ppbox_2dcode_phone").toggle();		
	});
	$("#link_shortmsg_mail").click(function(event){
		if(!$("#ppbox_shortmsg").is(":visible")){
			$("#phone_verify_img").attr("src","verifycodetel?t="+(new Date()).getTime());
			$("#smsnumber").val('');
			$("#phoneverify").val('');
			event.stopPropagation();
			$(document).bind("click",{id:'ppbox_shortmsg'},hideMsgPop);
		}else{
			$(document).unbind("click",hideMsgPop);
		}		
		$("#ppbox_shortmsg").toggle();
	});
	
	$("#link_2dcode_oa").hover(function(){
		$("#ppbox_2dcode_oa").toggle();		
	});
	$("#link_shortmsg_oa").click(function(){
		if(!$("#ppbox_shortmsg_oa").is(":visible")){
			$("#phone_verify_img").attr("src","verifycodetel?t="+(new Date()).getTime());
			$("#smsnumber").val('');
			$("#phoneverify").val('');			
		}	
		$("#ppbox_shortmsg_oa").toggle();		
	});
	
	$("#link_2dcode_emeeting").hover(function(){
		$("#ppbox_2dcode_emeeting").toggle();		
	});
	$("#link_shortmsg_emeeting").click(function(event){
		if(!$("#ppbox_shortmsg_emeeting").is(":visible")){
			$("#phone_verify_img").attr("src","verifycodetel?t="+(new Date()).getTime());
			$("#smsnumber").val('');
			$("#phoneverify").val('');
			event.stopPropagation();
			$(document).bind("click",{id:'ppbox_shortmsg_emeeting'},hideMsgPop);
		}else{
			$(document).unbind("click",hideMsgPop);
		}		
		$("#ppbox_shortmsg_emeeting").toggle();
	});	
	
	$("#link_2dcode_nosys").hover(function(){
		$("#ppbox_2dcode_nosys").toggle();		
	});
	$("#link_shortmsg_nosys").click(function(event){
		if(!$("#ppbox_shortmsg_nosys").is(":visible")){
			$("#phone_verify_img").attr("src","verifycodetel?t="+(new Date()).getTime());
			$("#smsnumber").val('');
			$("#phoneverify").val('');
			event.stopPropagation();
			$(document).bind("click",{id:'ppbox_shortmsg_nosys'},hideMsgPop);
		}else{
			$(document).unbind("click",hideMsgPop);
		}		
		$("#ppbox_shortmsg_nosys").toggle();
	});	
	
};
//隐藏短信下载的弹窗层
function hideMsgPop(event)
{
	var elementid = event.data.id;
	if($("#"+elementid).is(":visible")){
		var e = event || window.event;
		var elem = e.srcElement||e.target;		
		while(elem)
		{ 
			if(elem.id == elementid)
				return;
			elem = elem.parentNode;		
		}
		$("#"+elementid).hide();	
		$(document).unbind("click",hideMsgPop);
	}
}

function changeAllWayHttpsLoginStatus(obj)
{
	if(obj.checked){
		setCookie('isAllwayHttps','1', false, '/', $("#domain").val(), false);
		$("#targetService").val(mailAllwayHttpsUrl);
	} else {
		setCookie('isAllwayHttps','0', false, '/', $("#domain").val(), false);
		$("#targetService").val(serviceUrl.replace('https://','http://'));
	}
}

function processAllwayHttpStatus()
{
	var port = window.location.port;
	if (port != "" && port != "80") {
		return;
	}
	
	var isAllwayHttps = getCookie('isAllwayHttps');
	if(allWayHttpsChoose != undefined){
		if(allWayHttpsChoose=='1'||allWayHttpsChoose=='2'){
			isAllwayHttps='1';
			setCookie('isAllwayHttps','1', false, '/', $("#domain").val(), false);
		}
	}
	
	if(isAllwayHttps && '1' == isAllwayHttps && $$("service").value.indexOf("Sofia.jsp") > -1){
		$('#allWayHttps').attr("checked", true);
		if(allWayHttpsChoose && allWayHttpsChoose=='2'){
			$('#allWayHttps').attr("disabled", true);	
		}
		$("#targetService").val(mailAllwayHttpsUrl);
	} else {
		$('#allWayHttps').attr("checked", false);
		$("#targetService").val('');
	}
}

function closeBrowerTip()
{
	$('#eisp2_tip').fadeOut();
	setCookie('konwBrowserTip', '1');
}

function ie8Click(){
	var ie8Href = "http://windows.microsoft.com/zh-CN/windows/upgrade-your-browser/";
	if('zh_HK' == locale || 'zh_TW' == locale){
		ie8Href = "http://windows.microsoft.com/zh-tw/windows/upgrade-your-browser/";
	} else if ('en' == locale){
		ie8Href = "http://windows.microsoft.com/en-us/windows/upgrade-your-browser/ ";
	}
	window.open(ie8Href);
}

/**
 * 绑定密码框值修改定时器
 * 
 */
function bindChangeValueTimer()
{
	setTimeout(function(){
		var passwordInput = $("#password").val();
		if(passwordInput != ""){
			$("#password_hold").hide();
		} else {
			$("#password_hold").show();
		}
	}, 5);
}

function loginSubmit(){
	if ($$("loginType").value == 3) {
		phoneLoginVerifyCode();
		return false;
	}
	
	var domainInput = $$("domain") ;
    var userInput = $$("user") ;
    var usernameInput = $$("username") ;
    var validcodeInput= $$("validcode") ;
    var smscodeInput = $$("smscode");
    usernameInput.value = userInput.value;
    if(usernameInput.value != null){ //可输入大小写，不过最后全部转为小写
	    usernameInput.value = usernameInput.value.trim().toLowerCase();
    }
    
    if(!isFullDomainLogin){
        if(!inputIsBlank(usernameInput) && !inputIsBlank(domainInput)){
            usernameInput.value = usernameInput.value +"@"+domainInput.value.trim().toLowerCase();
        }
    }
    
       //valid email formater
    if(!validEmail.test(usernameInput.value)){
        $$("fail").innerHTML =invalidUser;
  	    userInput.focus();	   
  	    return false;
    }
    
    if ($$("password").value.trim() == '') {
    	$$("password").focus();
		return false;
    }
    
   if(validcodeInput!=null){
	   if(validcodeInput.value==null || validcodeInput.value.length!=4){
		   $$("fail").innerHTML =invalidcode;
		   return false;
	   }
   }
   if (smscodeInput != null && $(smscodeInput).is(":visible")) {
	   if (smscodeInput.value == null || smscodeInput.value.length != 6) {
		   $$("fail").innerHTML =invalidsmscode;
		   return false;
	   }
   }
   
   setCookie('lastuser',userInput.value);
   setFormValue();
   
   if ($$("password").value != '') {
	   var pwd = $$("password").value;
	   $$("password").value='';
	   
	   pwd = Base64.encode("MTIzx" + Base64.encode("NDU2c" + pwd));
	   $$("pwd").value=pwd;
   }
   
   return true;
}

function setFormValue() {
	$$("fromUrl").value=window.location.href;
	   
	   //process mail vs lite
	   if (tosystem !=undefined){
		   if ('mail' == tosystem && 'lite'==$('#span_curr_ver').attr("mail_version")){
	    	   $("#system").val('lite');
	    	   $("#service").val('http://'+window.location.hostname+'/lite/');
	    	   var port = window.location.port;
	    	   if (port != "") {
	    		   $("#service").val('http://'+window.location.hostname+':'+window.location.port+'/lite/');
	    	   }
		   }else if ('lite' == tosystem && 'mail'==$('#span_curr_ver').attr("mail_version")){
	    	   $("#system").val('mail');
	    	   $("#service").val('http://'+window.location.hostname+'/Sofia.jsp');
	    	   var port = window.location.port;
	    	   if (port != "") {
	    		   $("#service").val('http://'+window.location.hostname+':'+window.location.port+'/Sofia.jsp');
	    	   }
		   }
		   if ('mail' == tosystem || 'lite'==tosystem){
			   if($('#span_curr_ver') && $('#span_curr_ver').attr("mail_version")){
				   setCookie('mailver',$('#span_curr_ver').attr("mail_version"), false, '/', $("#domain").val(), false);
			   }
			  var openit= $("#openit").attr("checked");
			   if(openit){
				   $("#service").val('http://'+window.location.hostname+'/ec/PersonalCenter.jsp?module=ipLogin');
			   }
		   } else {
			   setCookie('mailver', 'mail', false, '/', $("#domain").val(), false);
		   }
	   } else {
		   setCookie('mailver', 'mail', false, '/', $("#domain").val(), false);
	   }
	   
	   //record isAllwayHttps cookie
	   if(tosystem != undefined && 'mail' == tosystem){
		   if(isFullDomainLogin && isProxy){ //
			   $("#targetService").val(mailAllwayHttpsUrl);
		   } else {
	    	   var httpsChecked = $("#allWayHttps").attr("checked");
	    	   if(httpsChecked){
	    		   setCookie('isAllwayHttps','1', false, '/', $("#domain").val(), false);
	    		   setCookie('httpsUrl', mailAllwayHttpsUrl, true, '/', $("#domain").val(), false);
	    	   } else {
	    		   setCookie('isAllwayHttps','0', false, '/', $("#domain").val(), false);
	    	   }
		   }
	   }
}
 
function checkUser() {
	var domainInput = $$("domain") ;
    var userInput = $$("user") ;
    var usernameInput = $$("username") ;
    usernameInput.value = userInput.value;
    if(usernameInput.value != null){ //可输入大小写，不过最后全部转为小写
	    usernameInput.value = usernameInput.value.trim().toLowerCase();
    }
    
    if(!isFullDomainLogin){
        if(!inputIsBlank(usernameInput) && !inputIsBlank(domainInput)){
            usernameInput.value = usernameInput.value +"@"+domainInput.value.trim().toLowerCase();
        }
    }
    
    var tipDiv = $$("fail");
    if (tipDiv != null){
    	//valid email formater
    	if(!inputIsBlank(usernameInput) && !validEmail.test(usernameInput.value)){
     	    tipDiv.innerHTML =invalidUser;
        } else {
        	tipDiv.innerHTML = "";
        }
    }
}

function showWX() {
	
}

function showPhone() {
	$$("fail").innerHTML = "";
	$$("loginType").value = 3;
	
	$("#user_div").hide();
	$("#pwd_div").hide();
	if ($("#validcode_div")) {
		$("#validcode_div").hide();
	}
	$("#domainA").hide();
	$("#pwdLoginA").show();
	$("#quick_div").hide();
	
	$$("phone").value = "";
	$$("smscode").value = "";
	$('#phone_hold').show();
	$('#smscode_hold').show();
	$("#phone_div").show();
	$("#sms_code_div").show();
}

function showUserPwd() {
	$$("fail").innerHTML = "";
	$$("loginType").value = 1;
	
	$("#loginDiv").show();
	$("#emailsDiv").hide();
	
	$("#domainA").show();
	$("#pwdLoginA").hide();
	$("#quick_div").show();
	
	$("#user_div").show();
	$("#pwd_div").show();
	if ($("#validcode_div")) {
		$("#validcode_div").hide();
	}
	$("#phone_div").hide();
	$("#sms_code_div").hide();
}

function checkPhone() {
	$$("fail").innerHTML = "";
	var phoneValue = $$("phone").value.trim();
	if (phoneValue == '') {
		return false;
	}
	if (!/^[0-9]+$/.test(phoneValue)) {
		$$("fail").innerHTML = invalidPhone;
		return false;
	}
	return true;
}

function phoneLoginVerifyCode() {
	var phone = $$("phone").value.trim();
	var smscode = $$("smscode").value.trim();
	var system = $$("system").value.trim();
	if (!checkPhone()) {
		$$("phone").focus();
		return;
	}

	if (smscode == '') {
    	$$("smscode").focus();
		return;
    }
	
	if (smscode.length != 6) {
		$$("fail").innerHTML = invalidsmscode;
		return;
	}
	
	$.ajax({
		type: "GET",
		dataType: "jsonp",
		jsonpCallback: "jsonCallback",
		url: "loginSmsCode",
		data: "loginPhone="+encodeURI(phone)+"&smscode="+encodeURI(smscode).replace("+", "%2b")+"&action=phoneLoginVerifyCode&system="+system+"&locale="+locale,
		crossDomain: true,
		xhrFields: {withCredentials: true},
		success: function(data) {
			if ("0" == data.result) { //fail to verify sms
				$("#fail").text(data.code);
			} else {
				var emails = data.emails;
				if (emails == '') {
					window.location.href = "bindMail?locale=zh_CN&action=phoneLogin&loginPhone="+encodeURI(phone)+"&system="+system;
				} else {
					var emailArray = emails.split(",");
					var html = "";
					for(var b=0;b<emailArray.length;b++) {
						var email = emailArray[b];
						var divClass = "mrdl";
						var statusHtml = "<img src=\"images/xz.png\" class=\"img1\">";
						var styleHtml = "cursor:pointer";
						if (email.indexOf("#0") < 0) {
							divClass = "mrdl_1";
							var status = "";
							if (email.indexOf("#1") > -1) {
								status = accountStatus1;
							} else if (email.indexOf("#2") > -1) {
								status = accountStatus2;
							} else if (email.indexOf("#3") > -1) {
								status = accountStatus3;
							} else if (email.indexOf("#4") > -1) {
								status = accountStatus4;
							} else if (email.indexOf("#5") > -1) {
								status = accountStatus5;
							} else if (email.indexOf("#6") > -1) {
								status = accountStatus6;
							} else if (email.indexOf("#7") > -1) {
								status = accountStatus7;
							} else if (email.indexOf("#8") > -1) {
								status = accountStatus8;
							}
							statusHtml = "<p>"+status+"</p>";
							styleHtml = "";
						} else if (email.indexOf("$0") < 0) {
							divClass = "mrdl mrdl_1";
							var status = "";
							if (email.indexOf("$1") > -1) {
								status = serviceStatus1;
							} else if (email.indexOf("$2") > -1) {
								status = serviceStatus2;
							} else if (email.indexOf("$3") > -1) {
								status = serviceStatus3;
							} else if (email.indexOf("$4") > -1) {
								status = serviceStatus4;
							} else if (email.indexOf("$5") > -1) {
								status = serviceStatus5;
							} else if (email.indexOf("$6") > -1) {
								status = serviceStatus6;
							} else if (email.indexOf("$7") > -1) {
								status = serviceStatus7;
							} else if (email.indexOf("$8") > -1) {
								status = serviceStatus8;
							}
							statusHtml = "<p>"+status+"</p>";
							styleHtml = "";
						}
						
						email = email.substring(0, email.length - 4);
						var onclickHtml = "";
						if (styleHtml.length > 0) {
							onclickHtml = "onclick=\"userLogin('"+phone+"','"+email+"', 'phoneLogin')\"";
							if (emailArray.length == 1) {
								userLogin(phone, email, 'phoneLogin');
								return;
							}
						}
						html = html + "<div class=\""+divClass+"\" style=\""+styleHtml+"\" "+onclickHtml+"><div class=\"c2\">"+email+"</div>"+statusHtml+"</div>";
					}
					
					$("#loginDiv").hide();
					$("#emailsDiv").show();
					$$("emailsDiv2").innerHTML = html;
				}
			}
		}
	});
}

function userLogin(phone, email, loginType) {
	$$("loginPhone").value = phone;
	$$("loginUser").value = email;
	$$("loginType").value = loginType;
	setFormValue();
	$$('loginform').action = $$('loginform').action.replace("verifylogin", "loginSmsCode");
	$('#loginform').submit();
}