severtime=new Date();
function setServerTime(){
        var xmlHttp = false;
        //获取服务器时间
        try {
          xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e2) {
            xmlHttp = false;
          }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
          xmlHttp = new XMLHttpRequest();
        }
        xmlHttp.open("GET", "null.txt", false);
        xmlHttp.setRequestHeader("Range", "bytes=-1");
        xmlHttp.send(null);
        severtime = new Date(xmlHttp.getResponseHeader("Date"));
}
setServerTime();
function openLiveChat(){
	var url = "https://server.iad.liveperson.net/hc/9055748/?cmd=file&file=visitorWantsToChat&site=9055748&imageUrl=https://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/Secure/1a&";
	window.open(url,'msn','height=500,width=600, toolbar=no, menubar=no, scrollbars=yes, resizable=yes');
}
function openRules(){
	window.open('http://www.stsbet.com/branduser/sbk5/client/'+$("chooseLanguage").value+'.html','subWin','top=200, left=200,height=400,width=640, toolbar=no, menubar=no, scrollbars=yes,location=no,resizable=no');
}
function hideLeftFrameset(){
	parent.window.location.href="mainpage.html";
}
function openOddsTable(paras){
	var pf=$("pf").value;
	var curr=$("currid").value;
	var mainfra=parent.document.getElementById('mainFrame');
	var sidefra=parent.document.getElementById('sideFrame');
	if(mainfra){
		sidefra.src='homeside.jsp?PF='+(pf?pf:"0")+'&currId='+(curr?curr:"NO")+'&'+paras;
		parent.document.getElementById("contentframeset").cols="222,820,*";
	}
}
function changeOddsType(t){
	var oType = t.value;
	document.cookie = "oType="+oType;
	var paras=self.parent.window.location.search.replace("?","");
	var p = "oddsType="+t.value;
	var pf=$("pf").value;
	var curr=$("currid").value;
	var mainfra=parent.document.getElementById('mainFrame');
	var mainframe=window.parent.frames["mainFrame"];
	var spType = '';
	if(mainframe)	spType = '&markId='+mainframe.markId+'&sportId='+mainframe.sportId+'&showLeagueType='+mainframe.showMarketType;
	mainfra.src='page/PageInfo.jsp?PF='+(pf?pf:"0")+'&currId='+(curr?curr:"NO")+'&'+p+spType+'&'+paras;
}
function openSettings(){
	window.open("../client/008.jsp",'settings','height=500,width=800, toolbar=no, menubar=no, scrollbars=yes, resizable=yes');
}

/*function CloseBet(){
	var h = parseInt(time.split(":")[0]);
	var j = parseInt(time.split(":")[1].replace(/^[0]?/, ''));
	j--;
	var b = "";
	if(j < 0){
		h--;
		j=59;
	}
	if(h < 1 && j < 31){
		 b = "<b>";
	}
	if(j<10){
		j="0"+j;
	}
	if( h < 0 ){
		$("autoExit").hide();
		hideLeftFrameset();
		watchExit();
	}else{
		time = h+":"+j;
		document.getElementById("autoExit").innerHTML = b + sbkForm.register +" "+ time + (b == "" ? "" : "</b>" );//onclick
		clearTimeout(setTimeoutTest);
		setTimeoutTest = setTimeout("CloseBet()", 1000);
	} 
	
	$("autoExit").onclick=function openTime(){
							time = tt;clearTimeout(setTimeoutTest);
							setTimeoutTest = setTimeout("CloseBet()", 1000);
						 } 
}

var watchExitTest=null;
function watchExit(){
	if(watchExitTest) clearTimeout(watchExitTest);
	watchExitTest=setTimeout(watchExit,1000);	
	if( (time == "0:00") && (parent.document.getElementById('mainFrame').src.indexOf("mainpage.html")<0 ) ) {
		time=tt;CloseBet();$("autoExit").show();
		if(watchExitTest) clearTimeout(watchExitTest);
	}
}*/

function pageSkip(id, url, pageId){
	if(id != 'rules' && id != 'pass_word' && id != 'tab_mainpage'){
		if(parent.window.location.href.indexOf('mainpage.html') > -1){
			parent.window.location.href = 'index.html?pageId='+pageId;				
		}
	}
	if(url){
		parent.document.getElementById('mainFrame').src=url;
		parent.document.getElementById('contentframeset').cols='222,820,*';			
	}
	$('tab_mainpage').style.color = '#000'
	$('tab_index').style.color = '#000'
	var a = document.getElementsByTagName("a");
	for(var i = 0; i < a.length; i++){
		if(a[i].id){
			if(a[i].id == id){
				$(id).style.color = '#000000';
				Element.stopObserving(a[i],"mouseout",null);
				Element.observe(a[i],"mouseout",function(){this.style.color='#000000'});
			}else{
				$(a[i].id).style.color = '#FF6E01';
				Element.stopObserving(a[i],"mouseout",null);
				Element.observe(a[i],"mouseout",function(){this.style.color='#FF6E01'});
			}
		}
	}
}

function UserLogOut(){
	var param = { loginOut:'loginOut' };
	new Ajax.Request(
		'http://www.stsbet.com/branduser/services/getUserState.jsp' + '?vv='+ Math.random()   ,
	   {method: 'POST',parameters: param,onComplete:UserLogOut$Complete ,asynchronous : true});
}
function UserLogOut$Complete( response ){
	parent.window.location.href="mainpage.html";
}	
function quick_login(){
	var evt=window.event||arguments.callee.caller.arguments[0];
	var key = evt.keyCode?evt.keyCode:evt.which;
	if(key == 13){
		isDelayLogin();
	}
}

function isDelayLogin(){
	if( !waitFlag ){
		waitFlag = true;
		setTimeout(function(){  waitFlag = false; },3000);
		CheckUserLogin( $('ipUN').value , $('ipPW').value ,$('validation').value );
	}
}

function CheckUserLogin(  loginId , password ,IPVAL  ){

	var loginId = loginId.replace(/(^\s*)|(\s*$)/g, "");
	var password = password.replace(/(^\s*)|(\s*$)/g, "");
	var IPVAL = IPVAL.replace(/(^\s*)|(\s*$)/g, "");

	if(loginId ==null ||  loginId == "" ){
		alert( menuText2Show.sbkForm.IDCanNotBeEmpty );
		$('ipUN').focus();
		return;
	}
	if(password ==null || password == "" ){
		alert( menuText2Show.sbkForm.PasswordCanNotBeEmpty );
		$('ipPW').focus();
		return;
	}
	if( password.length < 6 ){
		alert( menuText2Show.sbkForm.PasswordMustBeAtLeast );
		$('ipPW').focus();
		return;
	}
	if( IPVAL == null || IPVAL == "" ){
		alert( menuText2Show.sbkForm.VerificationCodeCanNotBeEmpty );
		$('validation').focus();
		return;
	}
	if( IPVAL.length != 4 || isNaN(IPVAL) ){
		alert( menuText2Show.sbkForm.InvalidVerificationCode );
		$('validation').focus();
		return;
	}
	/*if(! $('agree').checked ){
		alert(sbkForm.argeeAlert);
		return;
	}*/
	var pi = "";
	$('userName').value = BaseNumRefEncode(loginId,pi);
	$('password').value = BaseNumRefEncode(password,pi);
	$('IPVAL').value = IPVAL;
	$('checkLogin').value = 'checkLogin';
	var param = {
		 userName: BaseNumRefEncode(loginId,pi) ,
		 password: BaseNumRefEncode(password,pi) ,
		 IPVAL:IPVAL ,
		 checkLogin:'checkLogin' };
	document.forms[1].action = 'http://www.stsbet.com/branduser/services/getUserState.jsp' + '?vv='+ Math.random();
	document.forms[1].submit();
	//window.open('/branduser/sbk5/main/mention.jsp','_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=750,height=400,left=230,top=161');
	 /* new Ajax.Request(
		'/branduser/services/getUserState.jsp' + '?vv='+ Math.random(),
	   {method: 'POST',parameters: param,onComplete:CheckUserLogin$Complete.bind(null,loginId,password) ,asynchronous : true});*/
}

function CheckUserLogin$Complete( str ){
	  var rt = eval(str);
	  if(rt){
		  if ( rt.response.user.loginId ){
			document.getElementById("pf").value = rt.response.user.profileLevel;
			document.getElementById("currid").value = rt.response.user.currId;
			if(parent.window.location.href.lastIndexOf("index.html") == -1)
				window.parent.location.href="index.html";
		  }else {
			if ( rt.numVal == "E"){
				alert( menuText2Show.sbkForm.InvalidVerificationCode );
			}else if(rt.response.isLocked){
				alert(sbkForm.UserNameLocked);
			}else if(rt.response.region!="null"){
				alert(sbkForm.InvalidArea.replace("{0}"," "+rt.response.region+" "));
			}else{
				alert(sbkForm.InvalidUsernameOrPassword);
			}
			$('ipUN').value = "";
			$('ipPW').value = "";
			$('validation').value = "";
			$('ipUN').focus();
			//getImage();
			//window.location.href="/branduser/sbk5/main/hometop.jsp";
		}
	  }
}

function DoStartUserRefresh(){
	new Ajax.Request(
		'http://www.stsbet.com/branduser/services/getUserState.jsp'  + '?vv='+ Math.random(),
			{method: 'GET', onSuccess:RefreshEnd ,  onFailure:RefreshError, asynchronous : true});
}
RefreshError.Count = 0 ;
function RefreshError( response ){
	RefreshError.Count ++;
	var rt = String(response.responseText).evalJSON();
	clearTimeout( RefreshHandle );
	RefreshHandle = setTimeout( DoStartUserRefresh , 10*1000 );

}

function RefreshEnd( response ){
	try{
		RefreshError.Count = 0
		var rt = String(response.responseText).evalJSON();
		LoginUserData = rt.response.user;
		if ( LoginUserData.loginId ){
		   document.getElementById("pf").value = rt.response.user.profileLevel;
		   document.getElementById("currid").value = rt.response.user.currId;

		   RefreshEnd.loged = true;
		   Element.show( 'infoMsg') ;
		   SetAllowAmountB.bind( null , LoginUserData.currId + ":" +  LoginUserData.allowAmountB ).delay( 1 );
		   clearTimeout( RefreshHandle );
		   RefreshHandle = setTimeout( DoStartUserRefresh , 1*60*1000 );
		   if ( !GetINFO ){
			   GetINFO = true;
			   GetInfo();
		   }
		}else{
			document.getElementById("pf").value = "";
			document.getElementById("currid").value = "";
			clearTimeout(setTimeoutTest);
			//setTimeoutTest = setTimeout("CloseBet()", 1000);//如果没有登录 5分钟返回主页面
			Element.hide( 'infoMsg') ;
			if (  RefreshEnd.loged ){
			   // $('login_bt').onclick = function(){location.reload();}
			}
			$('ipPW').value = '';
			setTimeout( getImage  , 100  );
			SetAllowAmountB( '' );
			if ( RefreshEnd.loged ){
			 MainContextFrame.SetURL( '' );
			 RefreshEnd.loged = false;
			 window.parent.location.href="index.html";
		   }

		}
		return ;
	}
	catch( e ){
		clearTimeout( RefreshHandle );
		RefreshHandle = setTimeout( DoStartUserRefresh , 10*1000 );
	}
}

function GetInfo(){
	 var url="getInfoList.jsp?locale="+getLocale();
	 new Ajax.Request(
	 url,
	 {
		 method: 'get',
		 onComplete:GetInfo$Complete,
		 asynchronous:true
	 });
 }
function GetInfo$Complete( response ){
	try{
		var data =  String(response.responseText).evalJSON();
			var messages=data.message;
		var divObj=document.getElementById("infoMsg");
		var divStr="";
		var divHtml = "";
		if(messages.length>0){
		   for(var i=0; i<messages.length; i++){
			   divStr += messages[i] + "\r\n";
			   if ( i < 3 ){
				  divHtml += messages[i]+"&nbsp;&nbsp;";
			   }
		  }
		}
		if ( divObj.tempV != divStr ){
			divStr = divStr.replace(/(<\/font>)/g, "")
			divStr = divStr.replace(/<font [^>]*>/g, "")
			divObj.title =divStr;
			divObj.innerHTML=divHtml;
			divObj.tempV = divStr;
		}
	}catch(e){
		   // alert("HomeTop:\n"+e.message );
	}finally{
	   setTimeout( GetInfo , 30*1000 );
	}
}
function ShowInfo(){
	window.open( 'http://www.stsbet.com/branduser/sbk5/main/page/info.jsp', 'info','width=800, toolbar=no, menubar=no, scrollbars=yes, resizable=yes' );
}

//date creator
function  Year_Month(){  
	var  now  =  new  Date();  
	var  yy  =  now.getYear();  
	var  mm  =  now.getMonth();  
	var  mmm=new  Array();
	var locale = getLocale();
	if(locale=='zh_CN' || locale=='zh_TW'){
		mmm[0]="1月";
		mmm[1]="2月";
		mmm[2]="3月";
		mmm[3]="4月";
		mmm[4]="5月";
		mmm[5]="6月";
		mmm[6]="7月";
		mmm[7]="8月";
		mmm[8]="9月";
		mmm[9]="10月";
		mmm[10]="11月";
		mmm[11]="12月";
		mm=mmm[mm];
		return(mm);  
	}else{
		mmm[0]="Jan";
		mmm[1]="Feb";
		mmm[2]="Mar";
		mmm[3]="Apr";
		mmm[4]="May";
		mmm[5]="Jun";
		mmm[6]="Jul";
		mmm[7]="Aug";
		mmm[8]="Sep";
		mmm[9]="Oct";
		mmm[10]="Nov";
		mmm[11]="Dec";
		mm=mmm[mm];
		return(mm);  
	}  
}
function CurentTime(){  
	var  hh  =  severtime.getHours();
	var  mm  =  severtime.getMinutes();
	hh = parseInt(hh);
	var  ampm = hh<12?"am":"pm";
	var  clock  =  hh<=12?hh:(hh-12);
	if  (mm  <  10)  mm = '0' + mm;
	     clock = clock + ':'+ mm + ' ';
		//clock  +=  mm+' ';
	return(clock+" "+ampm);
}  
function refreshDateTime(){
	setServerTime();
	var today=severtime.getDate();
	var fullyear=severtime.getFullYear();
	//var ss = now.getSeconds();
	if(getLocale()=='zh_CN' || getLocale()=='zh_TW'){
		$("date_md").innerHTML=fullyear+"年 "+Year_Month()+" "+today+"日";
	}else
		$("date_md").innerHTML=Year_Month()+" "+today+", "+fullyear;
	$("date_hm").innerHTML=CurentTime();
}
window.setInterval(refreshDateTime,60*1000);
function BindLanguageSelect( id ){
	 var cookie = new Cookie();
	 var locale = cookie.getProperty(cookie._LOCALE);
	 if(locale && locale != 'undefined' && locale != 'null'){
		 
	 }else{
		 cookie.setProperty(cookie._LOCALE, 'en_US' ,null,"/");
	 }
	var obj = document.getElementById( id );
	Form.Element.Methods.setValue(id, getLocale());
	obj.onchange = function(evt){	
		var evt = evt ? evt : (window.event ? window.event : null);

		var src = evt.srcElement || evt.target;
		var o = src;
		var cookie = new Cookie();
		cookie.delProperty(cookie._LOCALE);
	cookie.setProperty(cookie._LOCALE, o.value ,null,"/");
		var p = parent;
		while( p.parent != p ){
			 p = p.parent;
		}
		window.setTimeout( function(){
			  try{            
				p.location.reload();
			  }
			  catch( e ){
				  window.location.reload();
			  }
		   } , 200 );  
		
		/*var mainframe=window.parent.frames["mainFrame"];
		if(mainframe)	{
			var spType = 'sportId='+mainframe.sportId+'&showLeagueType='+mainframe.showMarketType;
			parent.document.getElementById('mainFrame').src='page/PageInfo.jsp?'+spType;
		}*/
	}
	obj = null;
}

function getImage(){
	if($("pwImg")){
		$("pwImg").src= '';
		$("pwImg").src='http://www.stsbet.com/branduser/p.gjsp?vv='+Math.random();
	}
}

function doNav(){
	var paras=self.parent.window.location.search.replace("?","");
	openOddsTable(paras);
}
