thisHREF = document.location.href;
var new_wy = "http://service.js.10086.cn"; 
if(thisHREF.indexOf(".js.chinamobile.com")!=-1){
	new_wy = "http://service.js.chinamobile.com";
}

var xmlHttp;
var tempIsLogin = "true";
var starttime;
var endtime;
var lastGetVerifyCodeTime;
var tempVerify = "false";
 
var jQuery = $;
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 1 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


var isLogin = null;
var userName = null;
var brandName = null;
var brandFeature = null;
var isVerify = null;
// 判断是否登录之后页面如何显示
function chooseDisplay() {
	var obSSOcookie = jQuery.cookie('ObSSOCookie');
	if(obSSOcookie != null && obSSOcookie!="" && obSSOcookie!="loggedout" && obSSOcookie!="loggedoutcontinue")
	{
		isLogin = true;
	}
	else
	{
		isLogin = false;
	}

	if (false == isLogin) {
		showPanle();
	} else {
		var url = "/loginhelp?callback=?";
		jQuery.getJSON(url, null, function call(result) {
			showChooseDiv(result);
		})
	}
}

//未登录状态，点击手机号码或服务密码时触发是否需要验证码
function chooseVerifyDisplay(){	
	if(tempVerify == "false"){
		var url = "/loginhelp?callback=?";
		jQuery.getJSON(url, null, function call(result) {
			showChooseVerify(result);
		})
	}
	tempVerify = "true";
}
//未登录状态，是否需要显示验证码
function showChooseVerify(result) {
	jQuery.each(result.data, function(i, verify) {
		isLogin = verify.isLogin;
		isVerify = verify.isVerify;
		showPanle();
	});
}
//登录状态
function showChooseDiv(result) {
	jQuery.each(result.data, function(i, user) {
		isLogin = user.isLogin;
		userName = user.userName;
		brandName = user.brandName;
		brandFeature = user.brandFeature;
		showPanle();
	});
}
function showPanle() {
	jQuery("#noLogin").ready(function(){
		var isLoginObj = document.getElementById("isLogin");
		var noLoginObj = document.getElementById("noLogin");
		var noLoginObj1 = document.getElementById("nologin1");
		var loginwaitingObj = document.getElementById("loginwaiting");
		var userNameObj = document.getElementById("userName");
		var brandNameObj = document.getElementById("brandName");
		var brandFeatureObj = document.getElementById("brandFeature");
		//已登录
		if (true == isLogin) {
		if(brandName.indexOf("神州行")!=-1){
		          	if(document.getElementById("operation").className=="selected") {
			          	document.getElementById("shKey").value="两城一家，实惠到家";
			          }
			          }
		else if(brandName.indexOf("动感地带")!=-1){
		          	if(document.getElementById("operation").className=="selected") {
			          	document.getElementById("shKey").value="假期回家不换卡，非常假期省话费";
			          }
			       }
	    else if(brandName.indexOf("全球通")!=-1){
		          	if(document.getElementById("operation").className=="selected") {
			          	document.getElementById("shKey").value="家庭帐户，一人付费全家共享";
			          }
			       }
			loginwaitingObj.style.display = "none";
			noLoginObj.style.display = "none";
			isLoginObj.style.display = "block";
			userNameObj.innerHTML = userName;
			brandNameObj.innerHTML = brandName;
			brandFeatureObj.innerHTML = brandFeature;
		}
		//未登录
		if (false == isLogin) {
			loginwaitingObj.style.display = "none";
			isLoginObj.style.display = "none";
			noLoginObj.style.display = "block";
			if (true == isVerify){
				noLoginObj1.className='nologin';
			}else{
				noLoginObj1.className='nologin1';
			}
			tempIsLogin = "false";
		}
	});
}

//等待信息
function handleStateChange() {
	var loadingInfoObj = document.getElementById("loadingInfo");
	loadingInfoObj.innerHTML = "正在检测登录状态，请稍候……";
}

//验证登陆信息
function checkPersonLogin() {
   //add 插码 点击BUTTION
   if (typeof(_tag)!="undefined"){_tag.dcsMultiTrack('DCS.dcsuri','/nopv.gif', 'WT.campaign','portals website','WT.event','logon','WT.log_rt','btClick');}
   //end
   	var noLogVerifyObj = document.getElementById("nologin1");
	if (!trimAll(document.frmPersonLogin.mobile.value)) {
		alert("请填写您的手机号码");
		document.frmPersonLogin.mobile.focus();
		return false;
	}
	if (document.frmPersonLogin.mobile.value.length != 11) {
		alert("您输入的手机号码长度不对,请重新输入");
		var r_date = new Date();
		if(noLogVerifyObj.className == "nologin"){
			changeVerifyCode();
		}
		document.frmPersonLogin.mobile.focus();
		return false;
	}
	if (!trimAll(document.frmPersonLogin.password.value)) {
		alert("请填写您的密码");
		document.frmPersonLogin.password.focus();
		return false;
	}
	if (document.frmPersonLogin.password.value.length != 6) {
		alert("您输入密码长度不对,请重新输入");
		var r_date = new Date();
		if(noLogVerifyObj.className == "nologin"){
			changeVerifyCode();
		}
		document.frmPersonLogin.password.focus();
		return false;
	}
	
	if(noLogVerifyObj.className == "nologin"){
		if (!trimAll(document.frmPersonLogin.validCode.value)) {
		alert("请填写验证码");
		document.frmPersonLogin.validCode.focus();
		return false;
		}
		if (document.frmPersonLogin.validCode.value.length != 4) {
			alert("您输入的验证码长度不对,请重新输入");
			var r_date = new Date();
			changeVerifyCode();
			return false;
		}
	}
	return true;
}

function checkPersonLoginCallBack(success, type, message) {
	if(success)　{ 
		//插码start,采集用户登录成功
		if (typeof(_tag)!="undefined"){_tag.dcsMultiTrack('DCS.dcsuri','/nopv.gif', 'WT.campaign','portals website','WT.event','logon','WT.log_rt','suc');}
		//插码end
		window.location.href = new_wy;
	}　else　{
		//插码start,采集用户登录失败原因
		if (typeof(_tag)!="undefined"){_tag.dcsMultiTrack('DCS.dcsuri','/nopv.gif', 'WT.campaign','portals website','WT.event','logonFail','WT.log_rt',message);}
		//插码end
		if (message.indexOf("手机号码或密码错误")!= -1)　{
			if(type=="泰州"){
				sAlert("tz");
			} else {
				sAlert();
			}
			return false;
		} else if (message.indexOf("割接错误")!= -1)　{
			alert("目前系统正在进行升级优化,暂时无法为您提供服务。给您带来不便，敬请谅解！");
			return false;
		} else if (message.indexOf("-2232")!= -1)　{
			if(type=="泰州"){
				sAlert("tz");
			} else {
				sAlert();
			}
			return false;
		} else if (message.indexOf("-99")!= -1)　{
			alert("目前系统正在进行升级优化,暂时无法为您提供服务。给您带来不便，敬请谅解！");
			return false;
		}　else if (message.indexOf("-2303")!=-1)　{
			alert("尊敬的客户，由于您已经连续3次输入错误的服务密码，当天办理业务受限，请24小时后再来办理，或携带有效证件至营业厅办理。不便之处，敬请谅解！");
			return false;
		}　else if (message.indexOf("请输入正确的验证码")!= -1)　{
			alert("请输入正确的验证码");
			var r_date = new Date();
			var noLogVerifyObj = document.getElementById("nologin1");
			if(noLogVerifyObj.className == "nologin"){
				changeVerifyCode();
			}
			document.frmPersonLogin.validCode.value = "";
			document.frmPersonLogin.validCode.focus();
			return false;
		}　else if (message.indexOf("请输入验证码")!= -1)　{
			alert("请输入验证码");
			var r_date = new Date();
			var noLogVerifyObj = document.getElementById("nologin1");
			if(noLogVerifyObj.className == "nologin"){
				changeVerifyCode();
			}
			document.frmPersonLogin.validCode.value = "";
			document.frmPersonLogin.validCode.focus();
			return false;
		}  else if(message.indexOf("登录用户较多，请稍候再试")!= -1)
		{
		 	alert(message);
		 	return false;
		}  else if (message.indexOf("系统繁忙，请稍候再试")!= -1)　{
			alert(message);
		 	return false;
		}　else　{
			window.location.href = new_wy;
		}
	}		
}

//用户退出
function toLogout() {
	try {
		var f = frames["_index_login_iframe"];
		f.location.href = "/login.do?action=logout&callback=toLogoutCallBack";
	} catch (e) {
	}
}

function toLogoutCallBack(success, type, message) {
	if(success) {
		window.location.href = "/index.html";
	}　else {
		window.location.href = "/index.html";
	}
}

function refreshEvent()　{
	if (document.frmPersonLogin.imgValid.style.display=="none")　{
		var r_date = new Date();
		document.frmPersonLogin.imgValid.src = "/verifycodewy.do?r="+Math.random();
		document.frmPersonLogin.imgValid.style.display ="inline";
		document.frmPersonLogin.validCode.value = "";
	}
}

function refreshEventByCusor()　{
	var r_date = new Date();
	document.frmPersonLogin.imgValid.src = "/verifycodewy.do?r="+Math.random();
	document.frmPersonLogin.imgValid.style.display ="inline";
	document.frmPersonLogin.validCode.value = "";
}
//更换图片验证码
function changeVerifyCode(objName)
{
    if(objName == null || objName == '')
    	objName = "vcimg";
    lastGetVerifyCodeTime = new Date().getTime();
    vcimgUrl = "/verifycodewy.do?r=" + Math.random();
    $("#"+objName).show();
    $("#"+objName).attr("src", vcimgUrl);
    document.frmPersonLogin.validCode.value = "";
	document.frmPersonLogin.validCode.focus();
}
//点击验证码输入框显示图片验证码
function getVerifyCode(value){
 	var currentTime = new Date().getTime();
    if (lastGetVerifyCodeTime == null || currentTime - lastGetVerifyCodeTime > 1000 * 60 * 5) 
    {
		changeVerifyCode();
		$("#vcimg").show();
	}	
} 
//用户登录
function login() {
	//插码start,采集用户点击登陆按钮
	if (typeof(_tag)!="undefined"){_tag.dcsMultiTrack('DCS.dcsuri','/nopv.gif', 'WT.campaign','portals website','WT.event','logon','WT.log_rt','bef');}
//插码end
	if(checkPersonLogin())　{
		document.frmPersonLogin.submit();
	}
	return false;
}

function sAlert(gsd)　{ 
	showTipMsg = true; 
	var msgw,msgh,bordercolor; 
	msgw=400; 
	msgh=100; 
	titleheight=25 //提示窗口标题高度 
	bordercolor="#336699";//提示窗口的边框颜色 
	titlecolor="#99CCFF";//提示窗口的标题颜色 
	     
	var sWidth,sHeight; 
	sWidth=document.body.offsetWidth; 
	sHeight=screen.height; 
	var bgObj=document.createElement("div"); 
	bgObj.setAttribute('id','bgDiv'); 
	bgObj.style.position="absolute"; 
	bgObj.style.top="0"; 
	bgObj.style.background="white"; 
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
	bgObj.style.opacity="0.6"; 
	bgObj.style.left="0"; 
	bgObj.style.width=sWidth + "px"; 
	bgObj.style.height=sHeight + "px"; 
	bgObj.style.zIndex = "10000"; 
	document.body.appendChild(bgObj); 
	   
	var msgObj=document.getElementById("errdiv"); 
	msgObj.setAttribute("align","center"); 
	msgObj.style.background="white"; 
	msgObj.style.border="1px solid " + bordercolor; 
	msgObj.style.position = "absolute"; 
	msgObj.style.left = "50%"; 
	msgObj.style.top = "50%";
	msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 
	msgObj.style.marginLeft = "-225px" ; 
	msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px"; 
	msgObj.style.textAlign = "center"; 
	msgObj.style.lineHeight ="25px"; 
	msgObj.style.zIndex = "100000"; 
	msgObj.style.display="block"; 
	if(gsd=="tz")
	{
		var jsObj=document.getElementById("jserr");
		var tzObj=document.getElementById("tzerr");
		jsObj.style.display="none";
		tzObj.style.display="block";
	} 
	document.body.appendChild(msgObj);
} 

function closeDiv()　{
	document.body.removeChild(document.getElementById("bgDiv"));
	document.getElementById("errdiv").style.display="none";
	document.frmPersonLogin.password.value="";
	document.frmPersonLogin.password.focus();
	
	var r_date = new Date();
	var noLogVerifyObj = document.getElementById("nologin1");
	if(noLogVerifyObj.className == "nologin"){
		changeVerifyCode();
	}
	document.frmPersonLogin.validCode.value = "";
}



