tboks.utils={};
var isDEV=0;

//take care these strings are used at end in web_tboks reglogin to give name to check methods if adding here add there
tboks.utils.registrationElements=new Array();
tboks.utils.registrationElements[0]='name';
tboks.utils.registrationElements[1]='firstname';
tboks.utils.registrationElements[2]='account';
tboks.utils.registrationElements[3]='email';
tboks.utils.registrationElements[4]='password';
tboks.utils.registrationElements[5]='tel';
tboks.utils.registrationElements[6]='country';
tboks.utils.registrationElements[7]='location';
tboks.utils.registrationElements[8]='captcha';

tboks.utils.quickRegistration=false;
tboks.utils.quickRegistrationchecked=false;

tboks.utils.valuesdefault={};
tboks.utils.language='FR';

 	

tboks.utils.setVarValuesDefaut=function()
{
	if (tboks.utils.language!='FR')
	{
		alert ('problem language not set');
	}
	else
	{	tboks.utils.valuesdefault.name	 	='VotreNom';
		tboks.utils.valuesdefault.firstname	='VotrePrenom';
		tboks.utils.valuesdefault.account 	='';
		tboks.utils.valuesdefault.email 	='';
		tboks.utils.valuesdefault.password 	='q';	
		tboks.utils.valuesdefault.tel 		='';
		tboks.utils.valuesdefault.country 	=70;
		tboks.utils.valuesdefault.location	='75001';
		tboks.utils.valuesdefault.captcha 	='aaaa';
		tboks.utils.valuesdefault.zip='75001';
		tboks.utils.valuesdefault.city='YourCity';
	}            
	
};

tboks.utils.getCookie=function(c_name)
 {
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1){ c_end=document.cookie.length;}
			return unescape(document.cookie.substring(c_start,c_end));
		 }
	}
 return "";
 } ;

tboks.utils.argsExist=function(par)
{		
	 var args = new Object();  
	 args = GetUrlParms();			 
	 if(args[par])
		{  return true; }
	 else
		{ return false; }		
 };
	 
tboks.utils.showAllInRegpopup=function()
 {
	$("#tr1").show();
	$("#tr2").show();	
	$("#tr3").show();
	$("#tr4").show();
	$("#tr5").show();
	$("#tr6").show();
	$("#tr7").show();
	if (GetParameter('country')=="70")
	{	$('#tr8').show();//zip
		$('#tr9').hide();//city
	}
	else
	{	$('#tr8').hide();//zip
		$('#tr9').show();//city
	}

	$("#divCaptcha").show(); 
 };
 tboks.utils.checkBeforePopup=function()
 {//alert ('problem shouldnt call checkbeforepopup SAY TO JOEL');
 if(!(typeof(tboks.webtboks.reg_login.setDisplay)=='undefined'))
	{return tboks.webtboks.reg_login.setDisplay();}
	else
	{return false;}
 };
 tboks.utils.oldcheckBeforePopup=function()
 {

	if( tboks.utils.argsExist("dsp"))		
	{	
/*		var display=GetParameter('dsp');	
		var showname 		= (display.substr(0,1)=="1");	
		var showfirstname 	= (display.substr(1,1)=="1");	
		var showaccount 	= (display.substr(2,1)=="1");	
		var showemail 		= (display.substr(3,1)=="1");	
		var showpassword 	= (display.substr(4,1)=="1");	
		var showtel 		= (display.substr(5,1)=="1");	
		var showcountry 	= (display.substr(6,1)=="1");	
		var showlocation	= (display.substr(7,1)=="1");	
		var showcaptcha 	= (display.substr(8,1)=="1");
*/	                                         
	
		 if( tboks.utils.argsExist("nom"))
		{	 if (isDEV==1){alert ("url has nom");}
			 var checkNom=tboks.webtboks.reg_login.checkNom();
			 if (checkNom && !showname)
				{$("#tr1").hide();} else {$("#tr1").show();}
		 }
		 else
		 { 
			if (!showname) {$("#tr1").hide();}
			$('#registerNom').attr('value','Votre Nom');  
		 }		 
		if( tboks.utils.argsExist("prenom"))
		{	 
			if (isDEV==1){alert ("url has prenom");}
			var checkPrenom=tboks.webtboks.reg_login.checkPrenom();
			if(checkPrenom && !showfirstname)
				{$("#tr2").hide();} else {$("#tr2").show();}
		}
		else
		{
			if (!showfirstname) {$("#tr2").hide();}
			$('#registerPrenom').attr('value','Votre Prenom');
		}
			
	
		 if( tboks.utils.argsExist("account"))
			{	 
				if (isDEV==1){alert ("url has account");}
				 var IsAccountOK=(tboks.webtboks.reg_login.checkAccount()==0);//-!-checkAccount() returns 0 if account is unique and well formatted
				 if(isAccountOK && !showaccount)
					{$("#tr3").hide();} 
				 else 
					{$("#tr3").show();}
			 }
		else
			{$("#tr3").show();}
			
		if( tboks.utils.argsExist("email"))
			{	 if (isDEV==1){alert ("url has email");}
				 var IsEmailOK=(tboks.webtboks.reg_login.checkEmail());//-!-checkEmail() returns 0 if email is unique and well formatted
				 alert("IsEmailOK"+IsEmailOK);//false??
				 alert("showemail"+showemail);
				 if(IsEmailOK  && !showemail)
					{alert ("bingjie test 1");$("#tr4").hide();} 
				 else 
					{alert ("bingjie test 2");$("#tr4").show();}
			 }
		else
			 {alert ("bingjie test 3");$("#tr4").show();}
			 
			 
			 
		/////////
		/* 	 if( tboks.utils.argsExist("email"))
		{	 alert ("url has email");
			 var checkEmail=tboks.webtboks.reg_login.checkEmail();
			 if(checkEmail){alert ("bingjie test 1");$("#tr4").hide();} else {alert ("bingjie test 2");$("#tr4").show();}
		 }else {alert ("bingjie test 3");$("#tr4").show();}
	 */	 //////////////////
		if( tboks.utils.argsExist("password"))
		{
			if (isDEV==1){alert ("url has password");}
			var checkPassword=tboks.webtboks.reg_login.checkPassword();
			if(checkPassword && !showpassword)
				{$("#tr5").hide();}
			else 
				{$("#tr5").show();}
		 }
		else 
			 {$("#tr5").show();}
					 
		 if( tboks.utils.argsExist("tel"))
			{	 if (isDEV==1){alert ("url has tel");}
				 var checkTel=tboks.webtboks.reg_login.checkTel();
				 if(checkTel && !showtel)
					{$("#tr6").hide();}
				else 
					{$("#tr6").show();}
			 }
		
				

		  if( tboks.utils.argsExist("country"))
			{	 if (isDEV==1)
					{alert ("url has country");	}	
			
				if (GetParameter('country')=="70" && !showcountry)
				{
					$('#tr7').hide();//country
					$('#tr8').show();//zip
					$('#tr9').hide();//city

					if (!showlocation)
					{
						if(tboks.utils.argsExist("zip"))
						{
							var checkZip=tboks.webtboks.reg_login.checkZip(); 
							if (checkZip)
							{
								$('#tr8').hide();//zip
							}
						}
					}
				}
				else//not france ned city not zip
				{
					$('#tr9').show();
					$('#tr8').hide();	
					$('#cityName').attr('value','Your city');		
				}
			}
/*			 }else if(showzip==0){				
					$('#tr8').hide();
					$('#registerZip').attr('value','75001');
					$('#cityName').attr('value','Your city');
					}		  
				else{
					$('#tr9').hide();
					$('#tr8').show();
					$('#registerZip').attr('value','75001');
					$('#cityName').attr('value','Your city');
					}
*/					
				
	 }
 };
 
 // load language js part
 
var isLoaded = false;				
 tboks.utils.wannaLoadThis=function()
{
	if (!isLoaded)
	{
		setTimeout('tboks.utils.wannaLoadThis()', 50);
		return;
	}
};

 tboks.utils.include=function(file)
 {
		if (window.document.getElementsByTagName)
				{
					script = window.document.createElement("script");
					script.type = "text/javascript";
					script.src = file;
					Body = window.document.getElementsByTagName("body");
					if (Body) 
					{
						Body[0].appendChild(script);
					}
				}
 };
tboks.utils.argsInUrl=function(argname)
{	switch (argname) 
	{ 	case "name": 
		return tboks.utils.argsExist("prenom");
		break; 

		case "firstname": 
		return tboks.utils.argsExist("prenom");
		break;
		
		case "account": 
		return tboks.utils.argsExist("account");
		break;
		
		case "email": 
		return tboks.utils.argsExist("email");
		break;

		case "password":
		return tboks.utils.argsExist("password");
		break;

		case "tel": 
		return tboks.utils.argsExist("tel");
		break;

		case "country": 
		return tboks.utils.argsExist("country");
		break;

		case "zip": 
		return tboks.utils.argsExist("zip");
		break;

		case "city": 
		return tboks.utils.argsExist("cityName");
		break;

		case "": 
		return tboks.utils.argsExist("");
		break;

		
		default: 
		return false ;
		break; 
	}
};

 //end load language js part
 
		// display.defaut.showname 		=0;
		// display.defaut.showfirstname	=0;
		// display.defaut.showaccount 		=1;
		// display.defaut.showemail 		=1;
		// display.defaut.showpassword		=0;
		// display.defaut.showtel 	   		=0;
		// display.defaut.showcountry 		=0;
		// display.defaut.showlocation		=0;
		// display.defaut.showcaptcha 		=0;
		
		// display.required.showname 		=0;
		// display.required.showfirstname	=0;
		// display.required.showaccount 	=1;
		// display.required.showemail 		=0;
		// display.required.showpassword	=0;
		// display.required.showtel 	   	=0;
		// display.required.showcountry 	=0;
		// display.required.showlocation	=0;
		// display.required.showcaptcha 	=0;
		
		// valuesdefault.name 		=tboks.utils.getdefaultName();
		// valuesdefault.firstname =tboks.utils.getdefaultFirstName();
		// valuesdefault.tel 	   	='0000000000';
		// valuesdefault.country 	=tboks.utils.getdefaultCountryID();
		// valuesdefault.location	=0;
				
		// display.urlshowname 	= (urldsp.substr(0,1)=="1");	
		// display.urlshowfirstname= (urldsp.substr(1,1)=="1");	
		// display.urlshowaccount 	= (urldsp.substr(2,1)=="1");	
		// display.urlshowemail 	= (urldsp.substr(3,1)=="1");	
		// display.urlshowpassword = (urldsp.substr(4,1)=="1");	
		// display.urlshowtel 		= (urldsp.substr(5,1)=="1");	
		// display.urlshowcountry 	= (urldsp.substr(6,1)=="1");	
		// display.urlshowlocation	= (urldsp.substr(7,1)=="1");	
		// display.urlshowcaptcha 	= (urldsp.substr(8,1)=="1");
		
		// display.urlexistshowname 		= (urldsp.substr(0,1)=="1");	
		// display.urlexistshowfirstname 	= (urldsp.substr(1,1)=="1");	
		// display.urlexistshowaccount 	= (urldsp.substr(2,1)=="1");	
		// display.urlexistshowemail 		= (urldsp.substr(3,1)=="1");	
		// display.urlexistshowpassword 	= (urldsp.substr(4,1)=="1");	
		// display.urlexistshowtel 		= (urldsp.substr(5,1)=="1");	
		// display.urlexistshowcountry 	= (urldsp.substr(6,1)=="1");	
		// display.urlexistshowlocation	= (urldsp.substr(7,1)=="1");	
		// display.urlexistshowcaptcha 	= (urldsp.substr(8,1)=="1");
				// $test==1 ? $do = true : $do = false;
	    // TUD.showname 		=display.urlexistshowname 		?(display.required.showname 	||display.urlshowname 		):(display.required.showname 		||display.defaut.showname 		);	
		// TUD.showfirstname   =display.urlexistshowfirstname	?(display.required.showfirstname||display.urlshowfirstname	):(display.required.showfirstname	||display.defaut.showfirstname	);	
		// TUD.showaccount 	=display.urlexistshowaccount 	?(display.required.showaccount 	||display.urlshowaccount 	):(display.required.showaccount 	||display.defaut.showaccount 	);
		// TUD.showemail 	    =display.urlexistshowemail 		?(display.required.showemail 	||display.urlshowemail 		):(display.required.showemail 		||display.defaut.showemail 		);	 
		// TUD.showpassword	=display.urlexistshowpassword 	?(display.required.showpassword	||display.urlshowpassword 	):(display.required.showpassword	||display.defaut.showpassword	);
		// TUD.showtel 	   	=display.urlexistshowtel 		?(display.required.showtel 	   	||display.urlshowtel 		):(display.required.showtel 	   	||display.defaut.showtel 	   	);
		// TUD.showcountry 	=display.urlexistshowcountry 	?(display.required.showcountry 	||display.urlshowcountry 	):(display.required.showcountry 	||display.defaut.showcountry 	);
		// TUD.showlocation	=display.urlexistshowlocation	?(display.required.showlocation	||display.urlshowlocation	):(display.required.showlocation	||display.defaut.showlocation	);
		// TUD.showcaptcha 	=display.urlexistshowcaptcha 	?(display.required.showcaptcha 	||display.urlshowcaptcha 	):(display.required.showcaptcha 	||display.defaut.showcaptcha 	);		
 
