/*Validate Form*/   
function validate_required(field,alerttxt)
{
with (field)
{
  if (value==null||value=="")
  {
  alert(alerttxt);return false;
  }
  else
  {
  return true;
  }
}
}

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false;}
else {return true;}
}
}


/*Validate Form UPDATE AND REFER*/
function validate_form(thisform)
{
with (thisform)
{
	
 if (validate_required(firstname,"First Name must be filled out")==false)
  {firstname.focus();return false;}
  
  if (validate_required(lastname,"Last Name must be filled out")==false)
  {lastname.focus();return false;} 
  
 
  
  	if(thisform.name == "TheForm2")
	{ 
		   if ( Gender.selectedIndex == 0 )
		    {
		        alert ("Slecet a Title from the drop down list.");
		        return false;
		    }
	}

 if (validate_required(email,"E-mail address must be filled out!")==false)
  {email.focus();return false;}
  
  if (validate_email(email,"Not a valid e-mail address!")==false)
  {email.focus();return false;} 
 return true;

 	
	 
}
}


function validate_formEmail(thisform)
{
with (thisform)
{
	
  if (validate_required(email,"E-mail address must be filled out!")==false)
  {email.focus();return false;}
  
  if (validate_email(email,"Not a valid e-mail address!")==false)
  {email.focus();return false;}  
	
	winCloseRefer();
	 return true;
}
}



/*Validate SURVEY*/

/*SURVEY*/
function validate_formSurvey(thisform)
{
with (thisform)
{
					if ((q1[0].checked == false ) && ( q1[1].checked == false) && ( q1[2].checked == false) && ( q1[3].checked == false))
				    {
				        alert ( "Please choose your answer from Question 1" );
				       return false;
				    }	
				    
				   	var chks = document.getElementsByName('q2[]');
				   	var hasChecked = false;			
						 				
						for (var i = 0; i < chks.length; i++)
						{
							  if(chks[i].type == "checkbox")
							   {
							    	if (chks[i].checked)
										{
										hasChecked = true;
										break;
										}
							    }else{
							 	
							 		if (chks[i].value!=null||chks[i].value!="")
									  {
									  hasChecked = true; break;
									  }		
							    }
									  
						}
						if (!hasChecked )
						{
							alert("Please select at least one from Question 2.");
							chks[0].focus();
							return false;
						}  
						
				
					var chks3 = document.getElementsByName('q3[]');
				   	var hasChecked = false;			
					 				
					for (var i = 0; i < chks3.length; i++)
					{
						  if(chks3[i].type == "checkbox")
						   {
						    	if (chks3[i].checked)
									{
									hasChecked = true;
									break;
									}
						    }else{
						 	
						 		if (chks3[i].value!=null||chks3[i].value!="")
								  {
								  hasChecked = true; break;
								  }		
						    }
								  
					}
					if (!hasChecked )
					{
						alert("Please select at least one from Question 3.");
						chks3[0].focus();
						return false;
					} 
							
				 		var chks4 = document.getElementsByName('q4[]');
				   	var hasChecked = false;			
					 				
					for (var i = 0; i < chks4.length; i++)
					{
						  if(chks4[i].type == "checkbox")
						   {
						    	if (chks4[i].checked)
									{
									hasChecked = true;
									break;
									}
						    }else{
						 	
						 		if (chks4[i].value!=null||chks4[i].value!="")
								  {
								  hasChecked = true; break;
								  }		
						    }
								  
					}
					if (!hasChecked )
					{
						alert("Please select at least one from Question 4.");
						chks4[0].focus();
						return false;
					} 
					
					var chks5 = document.getElementsByName('q5[]');
				   	var hasChecked = false;			
					 				
					for (var i = 0; i < chks5.length; i++)
					{
						  if(chks5[i].type == "checkbox")
						   {
						    	if (chks5[i].checked)
									{
									hasChecked = true;
									break;
									}
						    }else{
						 	
						 		if (chks5[i].value!=null||chks5[i].value!="")
								  {
								  hasChecked = true; break;
								  }		
						    }
								  
					}
					if (!hasChecked )
					{
						alert("Please select at least one from Question 5.");
						chks5[0].focus();
						return false;
					} 
					
										
						if ( ThirdParty.checked == true)
						{
							if (validate_required(ThirdPartyEmail,"E-mail address must be filled out!")==false)
						  {email.focus();return false;}
						  
						  if (validate_email(ThirdPartyEmail,"Not a valid e-mail address!")==false)
						  {email.focus();return false;}  
						}		  
				  
					
					if(thisform.name == "Survey")
						{
						  window.open('ThankYouSurvey.php',thisform.target,'location=0,status=0,height=465,width=468');
						 return true;
						}
	
}
}


function validate_formNewsletter(thisform)
{
with (thisform)
{
	
 if (validate_required(firstname,"First Name must be filled out")==false)
  {firstname.focus();return false;}
  
  if (validate_required(lastname,"Last Name must be filled out")==false)
  {lastname.focus();return false;} 
  
  if (validate_required(email,"E-mail address must be filled out!")==false)
  {email.focus();return false;}
  
  if (validate_email(email,"Not a valid e-mail address!")==false)
  {email.focus();return false;} 

	var chksNews = document.getElementsByName('CharismaOnline[]');
	var hasChecked = false;			
	var countSizeN =chksNews.length;

	for (var i = 0; i < countSizeN; i++)
	{
	if (chksNews[i].checked)
	{
	hasChecked = true;
	break;
	}
	}
	if (!hasChecked  )
	{
	alert("Please select at least one Charisma Online Magazine you would like to receive");
	chksNews[0].focus();
	return false;
	}  

	if(thisform.name == "Newsletter")
	{
	
	window.open('ThankYouNewsletter.php',thisform.target,'location=0,status=0,height=485,width=468');
	 return true;
	}
	 	
	 
}
}




function validate_formSubscribe(thisform)
{
with (thisform)
{
		if ((PaymentOption[0].checked == false ) && ( PaymentOption[1].checked == false))
	    {
	        alert ( "Please SELECT YOUR PAYMENT OPTION" );
	       return false;
	    }	
				   return true;  
}
}





/*REGISTRATION*/
/*Checkout with CC*/

function  validate_formCheckout(thisform)
{
with (thisform)
{
			
			if ( CCType.selectedIndex == 0 )
		    {
		        alert ( "You must enter your Credit Card Type before proceeding" );
		        return false;
		    }  	
		  	
		  	if (validate_required(CCNum,"You must enter your Credit Card Number before proceeding")==false)
		  	{CCNum.focus();return false;}
		  	
		  	  	if ( CCExpMonth.selectedIndex == 0 )
		    {
		        alert ("You must enter your Credit Card Expiration Month before proceeding");
		        return false;
		    }
		    
		    if ( CCExpYear.selectedIndex == 0 )
		    {
		        alert ( "You must enter your Credit Card Expiration Year before proceeding");
		        return false;
		    }
			
			if (validate_required(CCName,"Credit Card Name is a required field and cannot be left blank")==false)
		  	{CCName.focus();return false;}   	
		
		    
		  if (validate_required(secCode,"You must enter your Credit Card Security Code before proceeding")==false)
		  	{secCode.focus();return false;}
	
	
		 if (validate_required(BillingFirstname,"Billing First Name is a required field and cannot be left blank")==false)
		  {BillingFirstname.focus();return false;}
		  
		  if (validate_required(BillingLastname,"Billing Last Name is a required field and cannot be left blank")==false)
		  {BillingLastname.focus();return false;}
		  
		  // if (validate_required(COMPANY_NAME,"Company Name is a required field and cannot be left blank")==false)
		  //{COMPANY_NAME.focus();return false;}
		  
		
		  if (validate_required(BillingAddress,"Billing Address 1 is a required field and cannot be left blank")==false)
		  {BillingAddress.focus();return false;}
		  
		  if ( Country.selectedIndex == 0 )
		    {
		        alert ("Slecet a Country from the drop down list.");
		        return false;
		    }
		  
  
		  if (validate_required(BillingCity,"Billing City is a required field and cannot be left blank")==false)
		  {BillingCity.focus();return false;}
		  
		  
		  if ( BillingState.selectedIndex == 0 )
		    {
		        alert ("Slecet a State from the drop down list.");
		        return false;
		    }
		
		   
		  
		  if (validate_required(BillingZip,"Billing Zip is a required field and cannot be left blank")==false)
		  {BillingZip.focus();return false;}
		  
		   
		    
			if (BillingZip.length < 5) {
			alert("Please enter only 5 digit or 4 digit  zip code.");
			BillingZip.focus();return false;
			}
			
		
		 if (validate_required(BillingPhone,"Phone Number is a required field and cannot be left blank")==false)
		  {BillingPhone.focus();return false;}
		   
		    
		 if (validate_required(BillingEmail,"E-mail address is a required field and cannot be left blank")==false)
		  {BillingEmail.focus();return false;}
		  
		  if (validate_email(BillingEmail,"Not a valid e-mail address!")==false)
		  {BillingEmail.focus();return false;} 
		    
    
  
  
  var chks = document.getElementsByName('UseBilling');
	var hasChecked = false;
	
	if (chks[0].checked)
	{
		return true;
	}else{
	
			if (validate_required(ShippingFirstname,"Shipping First Name is a required field and cannot be left blank")==false)
		  {ShippingFirstname.focus();return false;}
		  
		  if (validate_required(ShippingLastname,"Shipping Last Name is a required field and cannot be left blank")==false)
		  {ShippingLastname.focus();return false;}
		  
		
		  if (validate_required(ShippingAddress,"Shipping Address 1 is a required field and cannot be left blank")==false)
		  {ShippingAddress.focus();return false;}
		  
		  if (validate_required(ShippingCity,"Shipping City is a required field and cannot be left blank")==false)
		  {ShippingCity.focus();return false;}
		  
		  
		  if ( ShippingState.selectedIndex == 0 )
		    {
		        alert ("Slecet a Shipping State from the drop down list.");
		        return false;
		    }   
		  
		  if (validate_required(ShippingZip,"Shipping Zip is a required field and cannot be left blank")==false)
		  {ShippingZip.focus();return false;}	 
		  
		  
		  
	
	} 
 
  if (validate_required(BillingSignature,"Billing Signature is a required field and cannot be left blank")==false)
  {BillingSignature.focus();return false;}
   return true;
 	 
}
}


/*Checkout NO CC*/
function  validate_formCheckoutShort(thisform)
{
with (thisform)
{
				
	
 if (validate_required(BillingFirstname,"Billing First Name is a required field and cannot be left blank")==false)
  {BillingFirstname.focus();return false;}
  
  if (validate_required(BillingLastname,"Billing Last Name is a required field and cannot be left blank")==false)
  {BillingLastname.focus();return false;}
   //if (validate_required(COMPANY_NAME,"Company Name is a required field and cannot be left blank")==false)
	//	  {COMPANY_NAME.focus();return false;}

  if (validate_required(BillingAddress,"Billing Address 1 is a required field and cannot be left blank")==false)
  {BillingAddress.focus();return false;}
  
  
   if ( Country.selectedIndex == 0 )
		    {
		        alert ("Slecet a Country from the drop down list.");
		        return false;
		    }
		  
  
  if (validate_required(BillingCity,"Billing City is a required field and cannot be left blank")==false)
  {BillingCity.focus();return false;}
  
  
  if ( BillingState.selectedIndex == 0 )
    {
        alert ("Slecet a State from the drop down list.");
        return false;
    }

   
  
  if (validate_required(BillingZip,"Billing Zip is a required field and cannot be left blank")==false)
  {BillingZip.focus();return false;}
  
  
  	if (BillingZip.length < 5) {
	alert("Please enter only 5 digit or 4 digit  zip code.");
	BillingZip.focus();return false;
	}
	

 if (validate_required(BillingPhone,"Phone Number is a required field and cannot be left blank")==false)
  {BillingPhone.focus();return false;}
  

    
 if (validate_required(BillingEmail,"E-mail address is a required field and cannot be left blank")==false)
  {BillingEmail.focus();return false;}
  
  if (validate_email(BillingEmail,"Not a valid e-mail address!")==false)
  {BillingEmail.focus();return false;} 
    
    
  
  
  var chks = document.getElementsByName('UseBilling');
	var hasChecked = false;
	
	if (chks[0].checked)
	{
		
	}else{
	
			if (validate_required(ShippingFirstname,"Shipping First Name is a required field and cannot be left blank")==false)
		  {ShippingFirstname.focus();return false;}
		  
		  if (validate_required(ShippingLastname,"Shipping Last Name is a required field and cannot be left blank")==false)
		  {ShippingLastname.focus();return false;}
		
		  if (validate_required(ShippingAddress,"Shipping Address 1 is a required field and cannot be left blank")==false)
		  {ShippingAddress.focus();return false;}
		  
		  if (validate_required(ShippingCity,"Shipping City is a required field and cannot be left blank")==false)
		  {ShippingCity.focus();return false;}
		  
		  
		  if ( ShippingState.selectedIndex == 0 )
		    {
		        alert ("Slecet a Shipping State from the drop down list.");
		        return false;
		    }   
		  
		  if (validate_required(ShippingZip,"Shipping Zip is a required field and cannot be left blank")==false)
		  {ShippingZip.focus();return false;}
		 
	
	} 
 
  if (validate_required(BillingSignature,"Billing Signature is a required field and cannot be left blank")==false)
  {BillingSignature.focus();return false;}
   return true;
 	 
}
}











function validate_UnsubscribeEmail(thisform)
{
with (thisform)
{
	
 if (validate_required(firstname,"First Name must be filled out")==false)
  {firstname.focus();return false;}
  
  if (validate_required(lastname,"Last Name must be filled out")==false)
  {lastname.focus();return false;} 
  
  if (validate_required(email,"E-mail address must be filled out!")==false)
  {email.focus();return false;}
  
  if (validate_email(email,"Not a valid e-mail address!")==false)
  {email.focus();return false;} 

 	return true;
 	
	 
}
}




/*Unsubscribe*/

 function validate_form_unsubscribe(thisform)
{
with (thisform)
{
    var chksUn = document.getElementsByName('TakeMeOff');
	var hasCheckedUn = false;
	for (var i = 0; i < chksUn.length; i++)
	{
	if (chksUn[i].checked)
	{
	hasCheckedUn = true;
	break;
	}
	}
	if (!hasCheckedUn)
	{
	alert("Please select check Box or Select Cancel button");
	chksUn[0].focus();
	return false;
	}  
		        
   
 	return true;
}
}



/*Registration DISPLAY LAYER POP UP*/
function ShowPop(nr)
{
	
	if (document.layers)
	{
		current = (document.layers[nr].display == 'block') ? 'none' : 'block';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'block') ? 'none' : 'block';
		document.all[nr].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'block') ? 'none' : 'block';
		document.getElementById(nr).style.display = vista;
	}	
}


/*PP*/
var win = null;
function newWindow(mypage,pageName,w,h,features) {  
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += features;
  win = window.open(mypage,pageName,settings);
  win.window.focus();
}
/*CLOSE*/

function winClose(){
window.opener.location.href="Home.php";
self.close();
}

function winCloseCheckout(){
window.opener.location.href="Checkout.php";
self.close();
}
function winCloseSubscribe(){
window.opener.location.href="Subscribe.php";
self.close();
}

function winCloseIndex(){
window.opener.location.href="index.php";
self.close();
}
function winCloseRefer(){
window.opener.location.href="ShareFriend.php";
self.close();
}
/*WINDOW POPS*/
function abreventana(donde,quien,como)
{ 
infoventana=window.open(donde,quien,como);
if (navigator.appName.substring(0,8) == "Netscape")	
{
window.infoventana.focus()
}
}
function enlaza_vf(donde)
{
window.open(donde,'','toolbar=yes,status=yes,scrollbars=yes,resizable=yes,width=700,height=450,top=16,left=50');
}
function enlaza(donde)
{
document.location=donde;
}
function enlaza_memoria(donde)
{
window.open(donde,'','toolbar=yes,status=yes,scrollbars=yes,resizable=yes,width=700,height=465,top=16,left=50');
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
function enlazapromo(donde)
{
window.open(donde,'','height=244,width=778,menubar=no,resizable=no,status=no,scrollbars=no,toolbar=no,location=no,hotkeys=0,top=16,left=16');
}
function abreventanatiendas(donde,quien,como)
{ 
top.document.location='/tiendas/';
infoventana=window.open(donde,quien,como);
if (navigator.appName.substring(0,8) == "Netscape")	
{
window.infoventana.focus()
}
}


