/*---------------------------------------------------------------
Description   :- function to validate an email id
Programmer    :- SBI
Last Modified :- 22/Aug/2008
-------------------------------------------------------------------*/ 
  function validate_email(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }
   return true;
}
/*------------------------------------------------------------------
Description   :- function to show tool tips for user egistration
Programmer    :- SBI
Last Modified :- 22/Aug/2008
-------------------------------------------------------------------*/
function tool_tip_js(field,imgid,boxid,requiredflag){
	var closeid=imgid+'_close';
	var trueid=imgid+'_true';
	if(field=='firstname' || field=='lastname' || field=='address' || field=='city'  || field=='postcode' || field=='phone' || field=='age'  || field=='dateofbirth'    || field=='fname'   || field=='lname'   || field=='zip'  || field=='siteName' ){
		var text =document.getElementById(field).value;
		text = text.replace(/ /g,""); 
		if(text==''){  
			document.getElementById(closeid).style.display = 'block';
			document.getElementById(trueid).style.display = 'none';
			document.getElementById(boxid).style.display = 'block';	
		}else{ 
			document.getElementById(closeid).style.display = 'none';
			document.getElementById(trueid).style.display = 'block';
			document.getElementById(boxid).style.display = 'none';	
		}
	}
	if(field=='email' || field=='confirmemail'){	 
		var mailid=document.getElementById(field).value;
		var EmailId=document.getElementById('email').value;
		mailid = mailid.replace(/ /g,"");
		 
 			if(mailid!=''){ 
				var email_status=validate_email(mailid);	
				if(email_status){ 
					if( field=='confirmemail' && EmailId!=mailid){	
						document.getElementById(closeid).style.display = 'block';
						document.getElementById(trueid).style.display = 'none';
						document.getElementById(boxid).style.display = 'block';
					}else{
						document.getElementById(trueid).style.display = 'block';
						document.getElementById(closeid).style.display = 'none';
						document.getElementById(boxid).style.display = 'none';
					}
				}else{ 
					document.getElementById(closeid).style.display = 'block';
					document.getElementById(trueid).style.display = 'none';
					document.getElementById(boxid).style.display = 'block';
				}
			}else {
				
					document.getElementById(closeid).style.display = 'block';
					document.getElementById(trueid).style.display = 'none';
					document.getElementById(boxid).style.display = 'block';
				
			}
		 
	} 
	if(field=='img_verification'){	
		var rand_img=document.getElementById('rand_img').value;
		var img_verification=document.getElementById('img_verification').value;
		img_verification = img_verification.replace(/ /g,"");
 			if(img_verification==''){ 
				document.getElementById(closeid).style.display = 'block';
				document.getElementById(trueid).style.display = 'none';
				document.getElementById(boxid).style.display = 'block';
			}else if(img_verification !=rand_img  ){
				document.getElementById(closeid).style.display = 'block';
				document.getElementById(trueid).style.display = 'none';
				document.getElementById(boxid).style.display = 'block';
			}else{
				document.getElementById(closeid).style.display = 'none';
				document.getElementById(trueid).style.display = 'block';
				document.getElementById(boxid).style.display = 'none';	
			}
			
		}
	 
	if(field=='password'){
		var pwd=document.getElementById('password').value; //alert("kk"+trueid);
		pwd = pwd.replace(/ /g,"");
		var len=pwd.length;
		if(pwd=='' || len<6){    
			document.getElementById(closeid).style.display = 'block';
			document.getElementById(trueid).style.display = 'none';
			document.getElementById(boxid).style.display = 'block';	
		}else{  
			document.getElementById(closeid).style.display = 'none';
			document.getElementById(trueid).style.display = 'block';
			document.getElementById(boxid).style.display = 'none';
			
		}
	}
	if(field=='confirmPassword'){
		var pwd=document.getElementById('password').value;
		var confirmPassword=document.getElementById('confirmPassword').value;
		pwd = pwd.replace(/ /g,"");
		confirmPassword = confirmPassword.replace(/ /g,"");
 		if(confirmPassword==''){  
			document.getElementById(closeid).style.display = 'block';
			document.getElementById(trueid).style.display = 'none';
			document.getElementById(boxid).style.display = 'block';	
		}else if(confirmPassword != pwd){
			document.getElementById(closeid).style.display = 'block';
			document.getElementById(trueid).style.display = 'none';
			document.getElementById(boxid).style.display = 'block';	
		}
		else{
			document.getElementById(closeid).style.display = 'none';
			document.getElementById(trueid).style.display = 'block';
			document.getElementById(boxid).style.display = 'none';
			
		}
	}
	
	if(field=='country'){
		var country=document.getElementById('country').value;  
 		if(country==''){  
			document.getElementById(closeid).style.display = 'block';
			document.getElementById(trueid).style.display = 'none';
			document.getElementById(boxid).style.display = 'block';	
			
		}else{ 
			document.getElementById(closeid).style.display = 'none';
			document.getElementById(trueid).style.display = 'block';
			document.getElementById(boxid).style.display = 'none';	
			
		}
	}
	
	if(field=='state'){
		var text =document.getElementById(field).value;
		text = text.replace(/ /g,""); 
		var countryid = document.getElementById('country').value;   //alert("inner"+countryid +"fgfgf"+requiredflag ); 
		//if(countryid=='223' || requiredflag =='1' ){
		if(countryid=='223' && requiredflag =='1' ){
			if(text==''){
				document.getElementById(closeid).style.display = 'block';
				document.getElementById(trueid).style.display = 'none';
				document.getElementById(boxid).style.display = 'block';	
			}else{
				document.getElementById(closeid).style.display = 'none';
				document.getElementById(trueid).style.display = 'block';
				document.getElementById(boxid).style.display = 'none';	
			}
		}else{
				document.getElementById(closeid).style.display = 'none';
				document.getElementById(trueid).style.display = 'none';
				document.getElementById(boxid).style.display = 'none';	
			}
	}
	if(field=='dateofbirth'){
		var dateofbirth =document.getElementById(field).value;
		if(dateofbirth =='0000-00-00' || dateofbirth ==''){
				document.getElementById(closeid).style.display = 'block';
				document.getElementById(trueid).style.display = 'none';
				document.getElementById(boxid).style.display = 'block';	
		}else{
				document.getElementById(closeid).style.display = 'none';
				document.getElementById(trueid).style.display = 'none';
				document.getElementById(boxid).style.display = 'none';	
		}
	}
	
	if(  field=='siteURL' ){
		
		var url = document.getElementById('siteURL').value;
		var newvalue = url.substr(7);
		newvalue = newvalue.replace(/ /g,""); 
		if(newvalue==''){
				document.getElementById(closeid).style.display = 'block';
				document.getElementById(trueid).style.display = 'none';
				document.getElementById(boxid).style.display = 'block';	
		}else{
 				document.getElementById(closeid).style.display = 'none';
				document.getElementById(trueid).style.display = 'none';
				document.getElementById(boxid).style.display = 'none';	
 		}
		
	}
	
  	
	
 }

/*--------------------------------------------------------------------------
Description   :- function to check Password Strength
Programmer    :- SBI
Last Modified :- 22/Aug/2008
--------------------------------------------------------------------------*/

function passwordStrength(password)
{

	var desc = new Array();
	desc[0] = "Very Weak";
	desc[1] = "Weak";
	desc[2] = "Better";
	desc[3] = "Medium";
	desc[4] = "Strong";
	desc[5] = "Strongest";

	var score   = 0;
	
	//if password bigger than 6 give 1 point
	if (password.length > 6) score++;
	//if password has both lower and uppercase characters give 1 point      
	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;
	
	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;
	
	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;
	
	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;
	//document.getElementById("passwordDescription").innerHTML = desc[score];
	document.getElementById("passwordStrength").innerHTML = desc[score];
	document.getElementById("passwordStrength").className = "strength" + score;
}

/*----------------------------------------------------------------
Description   :- Function to Validate a number
Programmer    :- SBI
Last Modified :- 18/Aug/2008
-------------------------------------------------------------------*/
function ValidateNumber(e)
{
	var key;
	var keychar;

	if (window.event)
	key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();

	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
	else if ((("0123456789.").indexOf(keychar) > -1))
		return true;
	else
		return false;
	
}
/*----------------------------------------------------------------
Description   :- Function to Login Submit Form
Programmer    :- SBI
Last Modified :- 26/Aug/2008
-------------------------------------------------------------------*/
function SubmitLoginform(){   
 	document.FormLogin.action="home-login.html";
	document.FormLogin.submit();
/* window.location="home-login.html"; */	
	
}//end function



/*--------------------------------------------------------------------------
Description   :- function to agree the terms of use and Privacy Policies
Programmer    :- SBI
Last Modified :- 29/Aug/2008
--------------------------------------------------------------------------*/
function  IagreeConditions(id){  
	if(id){
		window.location="content-user-agree-"+id+".html";
	}else return false;
}

/*--------------------------------------------------------------------------
Description   :- function to agree the terms of use and Privacy Policies
Programmer    :- SBI
Last Modified :- 29/Aug/2008
--------------------------------------------------------------------------*/
function  CancelContents(id){
	if(id){
		window.location="content-user-cancelContent-"+id+".html";
	}else return false;
}
/*----------------------------------------------------------------
Description   :- function to show preview of the announcement
Programmer    :- SBI
Last Modified :- 01/sep/2008
-------------------------------------------------------------------*/
function OpenaNewWindow(url,flag){ 
window.location='announcement-dismiss.html';
}//end fucntion

/*------------------------------------------------------------------
Description   :- Display State 
Programmer    :- SBI
Last Modified :- 02/sep/2008
-------------------------------------------------------------------*/
function Selectcountry(reqstate,flag){  
	var countryId  = document.getElementById('country').value;
	if(flag){
		var url ="ajax_common.php?countryId="+countryId+"&reqstate="+reqstate+"&action=state";  
	}else{
	 var url ="ajax_state.php?countryId="+countryId+"&reqstate="+reqstate;  
	}
	ajaxpage(url,'DivState');
}

/*------------------------------------------------------------------
Description   :- This function is used to show renewal mode if the user has selected 1 Year Payment
Programmer    :- SBI
Last Modified :- 06/Oct/2008
-------------------------------------------------------------------*/
function ShowRenewalType(value){   
  if(value=='1 Year'){
	  document.getElementById('RenewalMode').style.display='block';
  }else{
	  document.getElementById('RenewalMode').style.display='none';
  }
	 
}
/*-------------------------------------------------------------------
Description   :- Show the rate window
Programmer    :- AKL
Last Modified :- 25/Oct/2008
-------------------------------------------------------------------*/
function Showsysmsgwindow(sysid,sysimgid,Isread){ 
	if(sysid   ){
		var imageId= 'sysimgid_'+sysid;
		var containerId = 'Container_'+sysid; 
 		if(Isread=='no') {  
			document.getElementById(imageId).style.display='none';
		}
		var url = "ajax_page.php?subaction=updateSysmsgstatus&sysmsgId="+sysid;// alert(url);
		ajaxpage(url,containerId);
		
	}
	
}
/*-------------------------------------------------------------------
Description   :- Show popup window
Programmer    :- SBI
Last Modified :- 28/Nov/2008
-------------------------------------------------------------------*/
 function ShowPopWindow(url){
   document.getElementById('ShowPopUp').style.display='block';
  }

/*----------------------------------------------------------------
Description   :- Function to Affiliate Login Submit Form
Programmer    :- SBI
Last Modified :- 01/Dec/2008
-------------------------------------------------------------------*/
function SubmitAffiliateLoginform(){   
 	document.FormLogin.action="login-Submit.html";
	document.FormLogin.submit();
	
}//end function

/*----------------------------------------------------------------
Description   :- Function is used to show the payment info 
Programmer    :- SBI
Last Modified :- 20/Dec/2008
-------------------------------------------------------------------*/
	function showPaymentInfo(){
		var Gateway = document.getElementById('Paymentgateway').value;
		if(Gateway==''){
			alert("Please select payment method");
		}else{
			var url= "ajax_common.php?action=Paymentinfo&gateway="+Gateway;
			ajaxpage(url,'Paymentdetails');
		}//end if
		
	}//end function
	
/*----------------------------------------------------------------
Description   :- Function is used to show the payment info 
Programmer    :- SBI
Last Modified :- 01/JAN/2008
-------------------------------------------------------------------*/
 function showdisabledPaymentText(Text){ // alert(Text);
 	if(Text =='membership'){
		var disabledtextmsg = document.getElementById('Membershiptext').value;
	}else{
		var disabledtextmsg = document.getElementById('PaymentText').value;
	}
		
	document.getElementById('ShowDisablePaymentText').style.display='block';
	document.getElementById('DisabledText').innerHTML=disabledtextmsg;
 }
 
/*----------------------------------------------------------------
Description   :- Function is used to show affiliate stats
Programmer    :- SBI
Last Modified :- 29/April/2009
-------------------------------------------------------------------*/
 function Showaffiliatestats(){
	 var fromdate = document.getElementById('from_date').value;
	 var todate = document.getElementById('to_date').value;
	 var url = "Sales-Stats~"+fromdate+"~"+todate+"_1.html";
 	 document.allstats.action=url;
	 document.allstats.submit();
 }
 
	
	/*----------------------------------------------------------------
	Description   :- list all records
	Programmer    :- AKL
	Last Modified :- 04/MAY/2009
	-------------------------------------------------------------------*/
	function listallrecords(url){  //alert("inner");
		value = document.getElementById('Sel_rec').value;
		url = "setrecordsperpage.php?&Sel_rec="+value+"&url="+url;
 		window.location=url;
	  }
 
/*----------------------------------------------------------------
Description   :- list all records
Programmer    :- AKL
Last Modified :- 04/MAY/2009
-------------------------------------------------------------------*/
	function show_popup(url)
	{
		var newwindow;
		newwindow=window.open(url,'name','height=700,width=950,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,status=no,directories=no');
		if (window.focus) {
			newwindow.focus();
			window.parent.close();
		}
	}
	
 