// JavaScript Document

function validateTheInfo()
{
//Zip code validation START
	zipcode = document.form1.zipcode.value;
 if (zipcode.length == 5)
{
for (i=0; i < 5; i++)
{
if (zipcode.charAt(i) > '9' || zipcode.charAt(i) < '0')
{
alert('Invalid Zipcode');
return false;
}
}
}
else
{
alert('Invalid Zipcode');
return false;
}
//  Zip code validation END
//  Email validation code START
email = document.form1.email.value;
if(email.indexOf('@',1) == -1)
{
alert('Invalid Email address');
return false;
}
if(email.indexOf('.',3) == -1)
{
alert('Invalid Email address');
return false;
}
if(email.length < 8)
{
alert('Invalid Email address');
return false
}
//  Email validation code END
//  Names/city validation code START
if(document.form1.first_name.value.length < 2)
{
alert('Invalid first Name');
return false;
}
if(document.form1.last_name.value.length < 3)
{
alert('Invalid Last Name');
return false;
}
if(document.form1.city.value.length < 3)
{
alert('Invalid City');
return false;
}
//  Names/city validation code END
if(document.form1.address_line_1.value == '' || document.form1.address_line_1.value.indexOf(' ') == -1)
{
alert('Invalid Address');
return false;
}if(document.form1.phone1.value.length < 10)
{
alert('Invalid Phone Number');
return false;
}

//age validation
var dob = new Date();
var date=dob.getDate();
var month=dob.getMonth() + 1;
var year=dob.getFullYear();
var cmbmonth=parseInt(document.getElementById('cmbmonth').options[document.getElementById('cmbmonth').selectedIndex].value);
var cmbday=parseInt(document.getElementById('cmbday').options[document.getElementById('cmbday').selectedIndex].value);
var cmbyear=parseInt(document.getElementById('cmbyear').options[document.getElementById('cmbyear').selectedIndex].value);

age=year-cmbyear;

if(cmbmonth>month){age--;}
else{if(cmbmonth==month && cmbday>=date){age--;}}
if(cmbmonth==0){alert('You must enter the month you were born in.');return false;}
else if(cmbday==0){alert('You must enter the day you were born on.');return false;}
else if(cmbyear==0){alert('You must enter the year you were born in.');return false;}
else if(age<18){alert("We're sorry but you must meet the age restrictions contained in the official rules to participate in this sweepstakes.");return false;}

return 1;
}
