// JavaScript Document

  var intFormDataCnt=1
  var aryFormData = 
[ 
    ["q506", "Please enter your title.", "Title", "0"],
	["fname", "Please enter your first name.", "First Name", "0"],
    ["lname", "Please enter your last name.", "Last Name", "0"],
	["email", "Please enter your email address.", "0", "1"],
	["confirmemail", "Please confirm your email.", "0", "1"],
	["dob_month", "Please enter your MONTH of birth.", "0", "1"],	
	["dob_day", "Please enter your DAY of birth", "0", "1"],	
	["dob_year", "Please enter your YEAR of birth.", "0", "1"],	
	["address1", "Please enter your address.", "0", "1"],
	["city", "Please enter your city", "0", "1"],
	["state", "Please enter your state", "0", "1"],
	["postalcode", "Please enter your zip code.", "0", "1"],
	["empty_do_not_delete", "", "", "0"]
] 
// ["name_of_form_object", "Error message for missing info", "Name to Pass to User", "0"],

intFormDataCnt=aryFormData.length

function submitFunction ()
		{
			var formVar = document.regForm;

			if (!validateForm ())
				return false;
		}

  
function validateForm() {
  
  var formVar = document.regForm;
  var invalidList = "'!,;()$*%<>";
  
  	//Loops through form indices ========================
    for(var i = 0; i < formVar.elements.length; i++){

  		//Loops through form arry list ========================		
		 		for(var z = 0; z < intFormDataCnt; z++){
				
  				//Array list is matched with Form Indices ========================
						if (formVar.elements[i].name==aryFormData[z][0]) 
						{
	
						//Form Data Check - Start ========================
							if(formVar.elements[i].value.length == 0){
								alert(aryFormData[z][1]);
							    formVar.elements[i].focus();
								return false;
							} else 
							{
							//Form Invalid Character Check - Start ========================
							//	for (b = 0; b < formVar.elements[i].value.length; b++)
							//		{
							//			if (invalidList.indexOf (formVar.elements[i].value.charAt(b)) != -1){
							//					alert("Email doesn't look quite right.");													
							//					return false;
							//					}
							//		} 
							//Form Invalid Character Check - Start ========================							
							}
						//Form Data Check - End ========================					
								
						//Email Format Check - Start ========================
							if(formVar.elements[i].name == "email")
							{
									if (!validateEmail(formVar.elements[i].value))
									{
										alert ("Email address doesn't look quite right");
										formVar.elements[i].focus();
										return false;
									}
							}
						//Email Format Check - End	=========================
						
						
						//Email Format Confirm Email - Start ========================
							if(formVar.elements[i].name == "confirmemail")
							{
									if (formVar.email.value != formVar.confirmemail.value )
									{
										alert ("The email and confirmation email addresses do not match.");
										formVar.elements[i].focus();
										return false;
									}
							}
						//Email Format Confirm Email - End	=========================					
							
						

						//Zip Check - Start ========================
									if(formVar.elements[i].name == "postalcode")
									{
		
											if (!validatePostalCode ())
												return false;
									}							
						//Zip Check - End ========================
						
						

						
						
						
						
				
						
							
 						}


								//DOB Check - Start ========================
					var dob=new Date();
					var date=dob.getDate();
					var month=dob.getMonth();
					var year=dob.getYear();
					if(year<200){year+=1900};
					var cmbmonth=parseInt(document.forms[0].dob_month[document.forms[0].dob_month.selectedIndex].value);
					var cmbday=parseInt(document.forms[0].dob_day[document.forms[0].dob_day.selectedIndex].value);
					var cmbyear=parseInt(document.forms[0].dob_year[document.forms[0].dob_year.selectedIndex].value);
					
					var age=year-cmbyear;
					
					if((cmbmonth-1)>month){age--;}
					else{if((cmbmonth-1)==month && cmbday>date){age--;}}
								
						if(age<18) {
							alert('You must be at least 18 years old to enter this sweepstakes.');
							formVar.dob_year.focus();
							return false;
						} 
							
				//DOB Check - End  =========================

					
				 }
		}   
		
						
						
						
						//Question 1 - Start ========================

										if (formVar.q191.value.length == 0)
										{
											alert('Please answer brand of air care do you use most often.');
												formVar.q191.focus();
											return false;
										}
						
						//Question 1 - End ========================
						
						
						//Question 2 - Start ========================

										if (formVar.q857.value.length == 0)
										{
											alert('Please answer type of air care do you use most often.');
												formVar.q857.focus();
											return false;
										}
						
						//Question 2 - End ========================
						
						//Question 3 - Start ========================					
if (!formVar.q859[0].checked  && !formVar.q859[1].checked  && !formVar.q859[2].checked && !formVar.q859[3].checked && !formVar.q859[4].checked && !formVar.q859[5].checked && !formVar.q859[6].checked) {
									  alert("Please tell us how did you find out about AIR WICK Aromatherapy Scented Oil air care products.");	
									 formVar.q859[0].focus();
									  return false;
								}
						//Question 3 - End ========================		
						
						//Question 4 - Start ========================					
								var radio_choice = false;
								
								// Loop from zero to the one minus the number of radio button selections
								for (counter = 0;  counter < formVar.q860.length; counter++)
								{
									// If a radio button has been selected it will return true
									// (If not it will return false)
									if (formVar.q860[counter].checked)
									radio_choice = true; 
									}
									
									if (!radio_choice)
									{
									// If there were no selections made display an alert box 
									alert("Please Answer: Would you consider buying Aromatherapy Scented Oil air care products?")
									return (false);
								}
						//Question 4 - End ========================
						
						
						//Question 4 YES - Start ========================			
						
									if (formVar.q860[0].checked){
										
											//Question 5 - Start ========================					
													if (!formVar.q861[0].checked  && !formVar.q861[1].checked  && !formVar.q861[2].checked && !formVar.q861[3].checked) {
														  alert("Please tell us why would you consider buying Aromatherapy Scented Oil air care products.");	
														 formVar.q861[0].focus();
														  return false;
													}
											//Question 5 - End ========================				
											
											//Question 6 - Start ========================					
													if (!formVar.q863[0].checked  && !formVar.q863[1].checked  && !formVar.q863[2].checked && !formVar.q863[3].checked && !formVar.q863[4].checked && !formVar.q863[5].checked) {
														 alert("Please tell us where do you/would you use Aromatherapy Scented Oil air care products most often in your home.");	
														 formVar.q863[0].focus();
														  return false;
													}
											//Question 6 - End ========================		
															
									 
									}
									
									
									
						//Question 4 YES - End ========================									
									
									
						//Submission Check - Start ========================

										if (!formVar.q865.checked)
										{
											alert('Please check off that you agree to the rules of the game.');
												formVar.q865.focus();
											return false;
										}
					
						//Submission Check - End ========================
						
		
	//alert("TEST COMPLETE");
  return true;
  
  }
  
//Addtional functions==============================
//=================================================
function validateEmail(object_value)
	{

		object_value = trim(object_value);
			
		//alert (object_value);					
		
		var atindex, nextdotindex, lastdotindex, i, firstnonspace, lastnonspace;
		var invalidList = "'!,;()$*%<> ";
		var dontexit = true;
		
		// If the object_value is null assume it's valid (we're not checking whether its required or not)
	
		if (object_value == null)
			return true;
			
		// Two consecutive '.' are not allowed
		
		if (object_value.indexOf ("..") != -1)
			return false;
		
		// Determine whether they have an '@' and a '.' The last '.' should be after the '@'. The '@' can't be
		// at the beginning and there must be a character between the '@' and the '.'
			
		atindex = object_value.indexOf ('@');
		nextdotindex = object_value.indexOf ('.',atindex);
		lastdotindex = object_value.lastIndexOf ('.');
					
		if (atindex == -1 || lastdotindex == -1 || atindex >= lastdotindex || atindex == 0 || (nextdotindex <= atindex + 1))
			return false;
	
		// Any characters between the first blank and the last blank should not be invalid
						
		for (i = 0; i < object_value.length; i++)
		{
			if (invalidList.indexOf (object_value.charAt (i)) != -1)
				return false;
		} 
		
		return true;

	}


function trim(str) { 
		str.replace(/^\s*/, '').replace(/\s*$/, ''); 
	
	   return str;
	} 
	
	
//Check Zip Code	
function validatePostalCode ()
		{
			var formVar = document.regForm;
			var postalCode = null;
			
			if (formVar != null)
			{
				postalCode = formVar.postalcode;
				
				if (postalCode != null)
				{
					if (!checkpostalcode (postalCode.value))
					{
						alert ("The Zip code does not look quite right");
						postalCode.focus();
						return false;
					}
				}
			}
			
			return true;
		}
		
    function checkpostalcode(object_value)
    {
		//if (object_value == null || object_value.length == 0)
        	//return true;
		
	    if (object_value.length != 5 && object_value.length != 10)
	        return false;

		if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+")
    	    return false;

		// make sure first 5 digits are a valid integer
		if (!checkinteger(object_value.substring(0,5)))
			return false;

		if (object_value.length == 5)
			return true;
	
		// check if separator is either a'-' or ' '
		if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
        	return false;

		// check if last 4 digits are a valid integer
		if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+")
    	    return false;

		return (checkinteger(object_value.substring(6,10)));
    }
	
	
	

function checkinteger(object_value)
{
   	//Returns true if value is a number or is NULL
	//otherwise returns false	

    if (object_value.length == 0)
   	    return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
   	if (check_char < 1)
		return checknumber(object_value);
   	else
		return false;
}

function checknumber(object_value)
{
	//Returns true if value is a number or is NULL
	//otherwise returns false	

	if (object_value == null || object_value.length == 0)
		return true;

	//Returns true if value is a number defined as
	//   having an optional leading + or -.
	//   having at most 1 decimal point.
	//   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	//The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0));
	
	//Was it a decimal?
	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;

	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
			// ignore leading blanks
		}
		else if (trailing_blank)
			return false;
		else
			digits = true;
	}
						
	//All tests passed, so...
	return true
}





//====================

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? parseInt((screen.width-w)/2) : 0;
	TopPosition = (screen.height) ? parseInt((screen.height-h)/2) : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',screenX='+TopPosition+',screenY='+LeftPosition+',scrollbars='+scroll;
	win = window.open(mypage,myname,settings);
	if(win.window.focus){win.window.focus();}
}




function gotoWebsite(urlnum){



	if(urlnum=="1") {
	
		urlSend = window.open("http://offers.e-centives.com/contest/?id=6bd35c32-4715-4250-b075-519d5956bd21&wsid=1&b=5576","");
	
	} 
				
	if(urlnum=="2") {
	
	this.location.href="http://www.airwick.us/products_electricals.shtml";
	}
	
	if(urlnum=="3") {
	
	this.location.href="http://www.airwick.us/products_liquids.shtml";
	}
	
	
	if(urlnum=="4") {
	
	this.location.href="http://stf.os-0.com/we?scid=16995&dcid=16995&emailfrom=" + stafemail;
	}
	
	if(urlnum=="5") {
	
			urlSend = window.open("http://offers.e-centives.com/siflo/?id=938dfc0b-4c35-4d30-96e0-a57f927d9aca&b=5553","");
	}
	
		if(urlnum=="6") {
	
	this.location.href="http://www.airwick.us/products_electricals.shtml";
		}


	
		if(urlnum=="7") {
			urlSend = window.open("http://offers.e-centives.com/contest/?id=6bd35c32-4715-4250-b075-519d5956bd21&wsid=1&b=5576","");
	
	
		}
	
	
		if(urlnum=="8") {
	
	this.location.href="http://www.airwick.us/holidaygame/rules.html";
		}
	
		if(urlnum=="9") {
	
			urlSend = window.open("http://www.airwick.us","");
		}


	
	} 

//================================


function questionOther1(otherqshow)
	{
		
		
		
		if(otherqshow=="1") {
			if (document.regForm.q191[5].selected) {
					//alert("test");
					document.getElementById('otherbrand').style.display = '';

			} else {
					document.getElementById('otherbrand').style.display = 'none';

			}
			
		}
		
		
		if(otherqshow=="2") {
			if (document.regForm.q857[6].selected) {
					//alert("test");
					document.getElementById('otherbrand2').style.display = '';

			} else {
					document.getElementById('otherbrand2').style.display = 'none';

			}
			
		}
		
		if(otherqshow=="3") {

					document.getElementById('otherbrand3').style.display = '';



		}
		
		
		if(otherqshow=="4") {

					document.getElementById('otherbrand4').style.display = '';



		}
		if(otherqshow=="5") {

					document.getElementById('why').style.display = '';
					document.getElementById('consideryes').style.display = 'none';		
					
					
					if((navigator.appVersion.indexOf("Mac")!= -1)){

						document.getElementById('reentry').style.top = '-1350px';
					}
					else{
						
						
						
						if(navigator.userAgent.indexOf("Firefox")!=-1){
							document.getElementById('reentry').style.top = '-1450px';
						} else {
							document.getElementById('reentry').style.top = '-1550px';
						}
						

						
						
					}
					



		}
		
		if(otherqshow=="6") {

					document.getElementById('why').style.display = 'none';
					document.getElementById('consideryes').style.display = '';
					
					if((navigator.appVersion.indexOf("Mac")!= -1)){

						document.getElementById('reentry').style.top = '-1588px';
					}
					else{
						
						
						
						
						
						if(navigator.userAgent.indexOf("Firefox")!=-1){
							document.getElementById('reentry').style.top = '-1701px';
						} else {
							document.getElementById('reentry').style.top = '-1843px';
						}
						


						
						
					}
					



					

		}
			
			
	}
