//This function is for the sweepstakes --
function validatethisform() {  
  	var alertMessage = "Please enter your: \n";
	var isAlert = false;
	var phoneAlert = false;
	var sweeptakeAction = false;
	var mobileAction = false;
	
	if(!validateNotEmpty (document.hnb_sweep.optionalText1.value)  && !validateNotEmpty (document.hnb_sweep.phone.value) && !validateEmail(document.hnb_sweep.email.value) && !validateNotEmpty (document.hnb_sweep.firstName.value) && !validateNotEmpty (document.hnb_sweep.lastName.value) && 
		!validateNotEmpty (document.hnb_sweep.address1.value) && !validateNotEmpty (document.hnb_sweep.city.value) && !validateNotEmpty (document.hnb_sweep.state.value) && !validateNotEmpty (document.hnb_sweep.birthMonth.value) &&
		!validateNotEmpty (document.hnb_sweep.birthDay.value) && !validateNotEmpty (document.hnb_sweep.birthYear.value) ){
    	alertMessage += "Sweepstake information \n";
		isAlert = true;	
		phoneAlert = true;
	}
	else{
	
    // The following makes sure a field is NOT EMPTY  (validateNotEmpty) Repeat As necessary
	if(validateNotEmpty (document.hnb_sweep.phone.value) || validateEmail(document.hnb_sweep.email.value) || validateNotEmpty (document.hnb_sweep.firstName.value) || validateNotEmpty (document.hnb_sweep.lastName.value) || 
		validateNotEmpty (document.hnb_sweep.address1.value) || validateNotEmpty (document.hnb_sweep.city.value) || validateNotEmpty (document.hnb_sweep.state.value) || validateNotEmpty (document.hnb_sweep.birthMonth.value) ||
		validateNotEmpty (document.hnb_sweep.birthDay.value) || validateNotEmpty (document.hnb_sweep.birthYear.value) )
	{
	
   		if( !validateNotEmpty (document.hnb_sweep.firstName.value)){
    		alertMessage += "First Name \n";
    		document.hnb_sweep.firstName.style.background=errorcolor
    		isAlert = true;	
    	}
    
	
     	if(!validateNotEmpty (document.hnb_sweep.lastName.value)){
    		alertMessage += "Last Name \n";
    		document.hnb_sweep.lastName.style.background=errorcolor;
    		isAlert = true;	
    	}
	
		// Makes sure the Date of Birth Fields arent empty
	
		if(!validateNotEmpty (document.hnb_sweep.birthMonth.value)){
    		alertMessage += "Birth date: Month \n";
    		document.hnb_sweep.birthMonth.style.background=errorcolor;
    		isAlert = true;	
    	}
    	if(!validateNotEmpty (document.hnb_sweep.birthDay.value)){
    		alertMessage += "Birth date: Day \n";
    		document.hnb_sweep.birthDay.style.background=errorcolor;
    		isAlert = true;	
    	}
    	if(!validateNotEmpty (document.hnb_sweep.birthYear.value)){
    		alertMessage += "Birth date: Year \n";
    		document.hnb_sweep.birthYear.style.background=errorcolor;
    		isAlert = true;	
    	}
		if(validateNotEmpty (document.hnb_sweep.birthMonth.value) && validateNotEmpty (document.hnb_sweep.birthDay.value) && validateNotEmpty (document.hnb_sweep.birthYear.value))
		{
			document.hnb_sweep.dob.value = document.hnb_sweep.birthMonth.value+ "/" + document.hnb_sweep.birthDay.value +"/"+ document.hnb_sweep.birthYear.value;
		}
	
		
    	if(!validateNotEmpty (document.hnb_sweep.address1.value)){
    		alertMessage += "Address \n";
    		document.hnb_sweep.address1.style.background=errorcolor;
    		isAlert = true;	
    	}
	
		if(!validateNotEmpty (document.hnb_sweep.city.value)){
    		alertMessage += "City \n";
    		document.hnb_sweep.city.style.background=errorcolor;
    		isAlert = true;	
    	}
    
    	if(!validateNotEmpty (document.hnb_sweep.state.value)){
    		alertMessage += "State \n";
    		document.hnb_sweep.state.style.background=errorcolor;
    		isAlert = true;	
    	}
	 	if(!validateNotEmpty (document.hnb_sweep.zip.value)){
    		alertMessage += "Zip \n";
    		document.hnb_sweep.zip.style.background=errorcolor;
    		isAlert = true;	
    	}
	
	 	if(!validateNotEmpty (document.hnb_sweep.phone.value)){
    		alertMessage += "Phone \n";
    		document.hnb_sweep.phone.style.background=errorcolor;
    		isAlert = true;	
    	}
	
	
    	// The following Validates Emails are in correct Syntax
    	if(!validateEmail(document.hnb_sweep.email.value)){
    		alertMessage += "Email \n";
    		document.hnb_sweep.email.style.background=errorcolor;
    		isAlert = true;	
    	}		
		else{
			sweeptakeAction = true;
		}
	}

	
	// Validate Mobile Phone
	  if(validateNotEmpty (document.hnb_sweep.optionalText1.value) ){
		var temp_mobilphone = removeSpaces(document.hnb_sweep.optionalText1.value);
		var mobilphone = removeDashes(temp_mobilphone)
		
		if(validateNumeric (mobilphone) ){
    		var phone1 = mobilphone.substring(0,3);
			var phone2 = mobilphone.substring(3,6);
			var phone3 = mobilphone.substring(6);
			var mobile_phone="("+phone1+")"+phone2+"-"+phone3;
			if(!validateUSPhone(mobile_phone)){
			alertMessage += "a valid mobile phone number. \n";
    		document.hnb_sweep.optionalText1.style.background=errorcolor;
    		phoneAlert = true;	
    		}
			else{
			mobileAction = true 	
			}
			
		}
		else{
			alertMessage += "a valid mobile phone number. \n";
    		document.hnb_sweep.optionalText1.style.background=errorcolor;
    		phoneAlert = true;	
		}
		
	}
	if(mobileAction == true)
	{
		if(document.hnb_sweep.optionalText1.value != "" && document.hnb_sweep.optionalCheckbox1.checked != true)
		{
		//alert("Please check the box for getting text message updates."); 
		alertMessage += "Since you've entered your mobile number, please check the text alert sign up box below to complete your entry. \n";
    	document.hnb_sweep.optionalCheckbox1.style.background=errorcolor;
		isAlert = true;
		}
	}
	if(mobileAction == false && document.hnb_sweep.optionalCheckbox1.checked == true)
	{
		alertMessage += "mobile number to be able to receive text alert. \n";
    	document.hnb_sweep.optionalCheckbox1.style.background=errorcolor;
		isAlert = true;
	}
	
	
}
	
	
	
    if(isAlert || phoneAlert)
    {
        alert(alertMessage);
    }
    else
    { 
    	var url="http://open.4info.net:80/widget/alerts.jsp?openKeyword=HAUTE&phone1="+phone1+"&phone2="+phone2+"&phone3="+phone3;
		 var url2 =
 "http://contests.alloymarketing.com/entrycreate.do?contestId="+document.hnb_sweep.contestId.value+"&email="+document.hnb_sweep.email.value+"&birthYear="+document.hnb_sweep.birthYear.value+"&birthMonth="+document.hnb_sweep.birthMonth.value+"&birthDay="+document.hnb_sweep.birthDay.value;
		if(sweeptakeAction == true && mobileAction == true)
		{
			if(IsUnderage_sweeps(document.hnb_sweep)==true)
			{
				document.location.href="http://www.teen.com/shows/haute-and-bothered/sorry_sweep.vm";
			}
			else{
			//document.location.href=url2;
			//window.open(url,"mywindow","menubar=1,resizable=1,width=350,height=250");
			document.hnb_sweep.submit();
			//document.location.href=url2;
			//IsUnderage(document.hnb_sweep);
			}
			
			
			//document.location=url
			//window.open ("http://localhost:8080/teen-2/","mywindow","menubar=1,resizable=1,width=350,height=250"); 
			//window.open(url,"mywindow","menubar=1,resizable=1,width=350,height=250");
			//IsUnderage(document.contest)		
			
		}
		else{
			if(sweeptakeAction == true)
			{
			//IsUnderage(document.contest);
				if(!IsUnderage_sweeps(document.hnb_sweep))
				{
					document.hnb_sweep.submit();
				}
				else{
				//IsUnderage(document.contest);
					document.location.href="http://www.teen.com/shows/haute-and-bothered/sorry_sweep.vm";
				}
			}
			if(mobileAction == true)
			{
				//document.location=url;
				if(!IsUnderage_sweeps(document.hnb_sweep))
				
				{sure
				document.hnb_sweep.submit();
				
				}
				else{
				//document.location=url;
				document.location.href="http://www.teen.com/shows/haute-and-bothered/sorry_sweep.vm";
				}
			}
		}
    }
}