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 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;
// 判断是否登录之后页面如何显示
function chooseDisplay() {
	var obSSOcookie = jQuery.cookie('ObSSOCookie');
	if(obSSOcookie != null && obSSOcookie!="" && obSSOcookie!="loggedout" && obSSOcookie!="loggedoutcontinue")
	{
		isLogin = true;
	}
	else
	{
		isLogin = false;
	}
//	if (null != jQuery.cookie('JSESSIONID') && "null" != jQuery.cookie('JSESSIONID')) {
//	if ("1" == jQuery.cookie(jQuery.cookie('JSESSIONID')) || 1 == jQuery.cookie(jQuery.cookie('JSESSIONID'))) {
//			isLogin = true;
//		} else {
//			isLogin = false;
//		}
//	} else {
//		isLogin = false;
//	}

	if (false == isLogin) {
		showPanle();
	} else {
		var url = "/loginhelp?callback=?";
		jQuery.getJSON(url, null, function call(result) {
	//		showChooseDiv(result);
			showChooseDiv(result);
		})
	}
}

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 loginwaitingObj = document.getElementById("loginwaiting");
		var userNameObj = document.getElementById("userName");
		var brandNameObj = document.getElementById("brandName");
		var brandFeatureObj = document.getElementById("brandFeature");
		//已登录
		if (true == isLogin) {
			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";
			tempIsLogin = "false";
		}
	});
}

//等待信息
function handleStateChange() {
	var loadingInfoObj = document.getElementById("loadingInfo");
	loadingInfoObj.innerHTML = "正在检测登录状态，请稍候……";
}
//判断用户是否已登录
//function showChooseDiv(result) {
//	var isLoginObj = document.getElementById("isLogin");
//	var noLoginObj = document.getElementById("noLogin");
//	var loginwaitingObj = document.getElementById("loginwaiting");
//	var userNameObj = document.getElementById("userName");
//	var isLogin = null;
//	var userName = null;
//	//获得json返回数据
//	jQuery.each(result.data, function(i, user) {
//		isLogin = user.isLogin;
//		userName = user.userName;
//	});
//	//已登录
//	if (true == isLogin) {
//		loginwaitingObj.style.display = "none";
//		noLoginObj.style.display = "none";
//		isLoginObj.style.display = "block";
//		userNameObj.innerHTML = userName;
//	}
//	//未登录
//	if (false == isLogin) {
//		loginwaitingObj.style.display = "none";
//		isLoginObj.style.display = "none";
//		noLoginObj.style.display = "block";
//		tempIsLogin = "false";
//	}
//}

//验证登陆信息
function checkPersonLogin() {
	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();
//		document.frmPersonLogin.imgValid.src = "/verifycodewy.do?r="+Math.random();
		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();
//		document.frmPersonLogin.imgValid.src = "/verifycodewy.do?r="+Math.random();
		changeVerifyCode();
		document.frmPersonLogin.password.focus();
		return false;
	}
	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();
//		document.frmPersonLogin.imgValid.src = "/verifycodewy.do?r="+Math.random();
		changeVerifyCode();
		document.frmPersonLogin.validCode.value = "";
		document.frmPersonLogin.validCode.focus();
		return false;
	}
	return true;
}

function checkPersonLoginCallBack(success, type, message) {
//	if(tempIsLogin=="true")　{
//		if (window.history.length > 1)　{
//			window.location.href="/index.html";
//			return;
//		}
//	}
	if(success)　{ 
		window.location.href = new_wy;
	}　else　{
		if (message.indexOf("手机号码或密码错误")!= -1)　{
			sAlert();
			return false;
		} else if (message.indexOf("割接错误")!= -1)　{
			alert("目前系统正在进行升级优化,暂时无法为您提供服务。给您带来不便，敬请谅解！");
			return false;
		}　else if (message.indexOf("半小时内输入密码错误次数超过5次")!=-1)　{
			alert("您输入密码累计超过3次错误，帐户将被锁定24小时");
			return false;
		}　else if (message.indexOf("请输入正确的验证码")!= -1)　{
			alert("请输入正确的验证码");
			var r_date = new Date();
			//document.frmPersonLogin.imgValid.src = "/verifycodewy.do?r="+Math.random();
			changeVerifyCode();
			document.frmPersonLogin.validCode.value = "";
			document.frmPersonLogin.validCode.focus();
			return false;
		}　else if (message.indexOf("认证服务器正忙，请稍后再试")!= -1)　{
			alert("密码校验失败，请重新登录！");
			window.location.href = new_wy;
		}　else　{
			window.location.href = new_wy;
		}
	}		
}

//用户退出
function toLogout() {
	try {
		var f = frames["_index_login_iframe"];
		f.location.href = "/login.do?action=logout&callback=toLogoutCallBack";
	//	window.location.href = "/index.html";
	//	window.location.refresh();
	} catch (e) {
	}
	//window.location.reload();
}

function toLogoutCallBack(success, type, message) {
	if(success) {
		window.location.href = "/index.html";
	//	window.location.reload();
	}　else {
	//	alert("退出时发生错误，请稍后再试");
		window.location.href = "/index.html";
	//	window.location.reload();
	}
}

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 = "";
		//document.frmPersonLogin.validCode.focus();
	}
}

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(){
//	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);
}
//点击验证码输入框显示图片验证码
function getVerifyCode(value){
 	var currentTime = new Date().getTime();
    if (lastGetVerifyCodeTime == null || currentTime - lastGetVerifyCodeTime > 1000 * 60 * 5) 
    {
		changeVerifyCode();
		$("#vcimg").show();
	}	
} 
//用户登录
function login() {
	if(checkPersonLogin())　{
		document.frmPersonLogin.submit();
	}
	return false;
}

function sAlert()　{ 
	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"; 
	 //   $("#id_passowrd_error").show();
	 msgObj.style.display="block"; 
	document.body.appendChild(msgObj);
	var tempFrame =  document.frames("activity");
	tempFrame.document.getElementById("city_yhzx").style.display="none";
} 

function closeDiv()　{
	document.body.removeChild(document.getElementById("bgDiv"));
	document.getElementById("errdiv").style.display="none";
	var tempFrame = document.frames("activity");
	tempFrame.document.getElementById("city_yhzx").style.display="block";
//	var loginFrame = document.frames("loginFrame");
//	document.getElementById("password").value="";
//	document.getElementById("password").focus();
	document.frmPersonLogin.password.value="";
	document.frmPersonLogin.password.focus();
	
	var r_date = new Date();
//	document.frmPersonLogin.imgValid.src = "/verifycodewy.do?r="+Math.random();
//	document.frmPersonLogin.imgValid.style.display ="inline";
	changeVerifyCode();
	document.frmPersonLogin.validCode.value = "";
}


