var SITE_URL = "http://"+location.host;
//show userbox
function showUserbox () {
	var un = document.getElementById("userbox");//.value;
	var url = SITE_URL+"/userbox.do";
	var res = doGet(url);
	un.innerHTML = res;
}




function IsUserLogin(){
	var request_url = SITE_URL +"/IsLogin.do?ran="+Math.random();
	//alert(request_url);
	var count  = doGet(request_url);
	return count;
}

function $(o){return document.getElementById(o);}


function loginAction(originalRequest){
		var count = IsUserLogin();

		if(count!=0){
			var strList  = count.split(',');       
			//alert(strList[0]);
			//$('uName').style.display="block";
			$('uName').innerHTML = strList[0]+"！" ;
			$('login_button').style.display="none";
			$('reg_button').style.display="none";
			$('nihao').style.display="";
			$('tuichu').style.display="";
			
			//$('uGid').innerHTML = strList[1];
			//$('log_sta1').style.display="";
			//$('log_sta').style.display="none";
		}else{
			$('uName').innerHTML="  ";
			$('login_button').style.display="";
			$('reg_button').style.display="";
			$('nihao').style.display="none";
			$('tuichu').style.display="none";
		}
}


function LoginIndex()
{
	var username = $('username').value;
	var password = $('password').value;
	var key = $('divs_putKey').value;
	//alert(username);alert(password);alert(key);
	
	if(username==null || username=="")
	{
		$('userLoginMessage').innerHTML = "<font color='#ff0000'>用户名为空！</font>";
		return "FALSE";
	}
	else if(password==null || password=="")
	{
		$('userLoginMessage').innerHTML = "<font color='#ff0000'>密码为空！</font！";
		return "FALSE";
	}
	else if(key==null || key=="")
	{
		$('userLoginMessage').innerHTML = "<font color='#ff0000'>验证码为空！</font>";
		
		return "FALSE";
	}
	else
	{
		var request_url = SITE_URL+"/LoginAjax.do?output=1&username="+encodeURI(username)+"&password="+password+"&divs_putKey="+key+"&divs_id="+$('divs_id').value+"&ran="+Math.random();
		var count  = doGet(request_url);
		
		return count;
	}
}




function refresh_key_index(){
	var request_url = SITE_URL+ "/RefreshKey.do?ran="+Math.random();
	var result  = doGet(request_url);	
	if(result!=null && result!=''){
		eval(result);
	}
	else{
		alert('服务器忙,请稍后再试');
	}
}


function getLoginUserInfo(){
	var logi = LoginIndex();	
	if(logi=="TRUE"){		
		var request_url = SITE_URL+"/userInfo.do?ran="+Math.random();
		var result  = doGet(request_url);	
		eval(result);
		if(typeof Account == 'undefined' || Account.gid <= 0){
			$('userLoginMessage').innerHtml='用户和密码不正确';
		}else{
			getData(Account.gid);
			if(document.getElementById('welcomInfo') != null && document.getElementById('welcomInfo') != 'undefined' ){
					document.getElementById('userLoginButton').style.display = "none";
					document.getElementById('userRetButton').style.display = "none";
					document.getElementById('welcomInfo').innerHTML =  Account.username+"，您好！</span><button onclick=\"window.open('http://my.checkoo.com/Logout.do');\">退出</button>";
			}
		}
	}else if(logi=="FALSE"){
		//$('password').value="";
		$('divs_putKey').value="";
		$('userLoginMessage').innerHTML = "<font color='#ff0000'>用户密码错误</font>";
		refresh_key_index();
		return;
	}else{
		alert(logi);
		refresh_key_index();
		return;
	} 
}

/*
	if(typeof(Account) == 'undefined' || Account.gid <=0){//not login
		document.getElementById("LoggedShoppingListInfo").style.display = 'none';
		document.getElementById("NotLoggedShoppingListInfo").style.display = '';
		document.getElementById("LoggedConsumePlanInfo").style.display = 'none';
		document.getElementById("NotLoggedConsumePlanInfo").style.display = '';
	}else{//logged in
		document.getElementById("LoggedShoppingListInfo").style.display = '';
		document.getElementById("NotLoggedShoppingListInfo").style.display = 'none';
		document.getElementById("LoggedConsumePlanInfo").style.display = '';
		document.getElementById("NotLoggedConsumePlanInfo").style.display = 'none';
	}
*/
function getUserInfo(){	
	$('userIndexJs').src = "/userInfo.do?ran="+Math.random();
	if(typeof Account == 'undefined' || Account.gid <= 0){
		$('userLoginMessage').innerHtml='用户和密码不正确';
	}else{
		//getData(Account.gid);
		getData();
	}
}

function getData(){
	var data = doGet("/getUserCountData.do?ran="+Math.random());
	//alert(data);
	eval(data); 
	//alert(destineInfo);
	//alert(collectionNum); 
	$('collect_index_num').innerHTML = collectionNum;
	$('today_coupon_index_num').innerHTML = destineInfo;
	$('login_index').style.display='none';
	$('useInfo_index').style.display='block';
	if($("planNum_index")!=null){
		$('planNum_index').innerHTML = planNum;
		$("LoggedConsumePlanInfo").style.display = '';
		$("NotLoggedConsumePlanInfo").style.display = 'none';
	}
	
	if($("billNum_index")!=null){
		$('billNum_index').innerHTML = billNum;
		$("LoggedShoppingListInfo").style.display = '';
		$("NotLoggedShoppingListInfo").style.display = 'none';
	}
	
	//$('user_index_plan').style.display='block';
}

/*
function getData(userId){
	
	UserInfoDwr.getUserDestineInfo2(userId, function (data){
		//alert(data);
		eval(data);
		//alert(destineInfo);
		//alert(collectionNum);
		$('collect_index_num').innerHTML = collectionNum;
		$('today_coupon_index_num').innerHTML = destineInfo;
		$('login_index').style.display='none';
		$('useInfo_index').style.display='block';
		if($("planNum_index")!=null)
		$('planNum_index').innerHTML = planNum;
		
		if($("billNum_index")!=null)
		$('billNum_index').innerHTML = billNum;
		//$('user_index_plan').style.display='block';
	});
}
*/

function printCityStyle(thisObj,Num){
	if(thisObj.className == "active")return;
	var tabObj = thisObj.parentNode.id;
	var tabList = document.getElementById(tabObj).getElementsByTagName("li");
	for(i=0; i <tabList.length; i++)
	{
		if (i == 0 && i == Num)
		{
		thisObj.className = "active";
		document.getElementById(tabObj+"_Content"+i).style.display = "block";
		continue;
		}else if(i == 0){
		tabList[i].className = "normal";
		document.getElementById(tabObj+"_Content"+i).style.display = "none";
		continue;
		}
		
		if (i == Num)
		{
		thisObj.className = "active";
		document.getElementById(tabObj+"_Content"+i).style.display = "block";
		}else{
		tabList[i].className = "normal";
		document.getElementById(tabObj+"_Content"+i).style.display = "none";
		}
	}
}

function v(){};
