// this regular expression validates the format for the zip code
var uszip=/(^\d{5}$)|(^\d{5}-\d{4}$)/;

// this function validates US zip code entered by the user
function checkZip(myZip)
{
	if (myZip.value!="")
	{
		var validzip=uszip.exec(myZip.value);
		if (validzip)
		{
			return true;
		}
		else
		{	
			alert(myZip.value+" is not a valid zip code");
			myZip.focus();
			myZip.select();
			return false;
		}
	}
	return false;
} 

// this reqular expression resembles valid format of the e-mail
var remail=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

// this function validates e-mail entered by the user
 function checkEmail(myemail)
{
	if (myemail.value!="")
	{
		if (remail.test(myemail.value))
		{
			return true;
		}
		else
		{
			alert ("Invalid email address");
			myemail.focus();
			myemail.select();
			return false;
		}
	}
	return false;
}

// this function makes sure that all required fields are filled in when the form is submitted
function emptyFields()
{
	if (document.eBook.firstName.value=="" || document.eBook.lastName.value=="" 
		|| document.eBook.zip.value=="" || document.eBook.phoneArea.value=="" 
		|| document.eBook.email.value=="")
	{
		alert("You must enter data in required fields! Fields marked with asterisk.");
        return false;
	}
	return true;
}

// this regular exspression resembles valid format of the phone number
var re=/^\(?(\d{3})\)?[\.\-\/]?(\d{3})[\.\-\/]?(\d{4})$/;
// this function validates and formates phone number entered by the user
function checkPhone(myPhone)
{
if (myPhone.value!="")
{
	var validPhone=re.exec(myPhone.value);
	if (validPhone)
	{
		myPhone.value="("+validPhone[1]+")-"+validPhone[2]+"-"+validPhone[3];
	}
	else
	{
		alert(myPhone.value+" is not a valid phone number");
		myPhone.focus();
		myPhone.select();
	}
	return false;
}
}

// this regular exspression resembles valid format of the phone number
var re=/^\(?(\d{3})\)?[\.\-\/]?(\d{3})[\.\-\/]?(\d{4})$/;
// this function validates and formates phone number entered by the user
function checkFax(myFax)
{
if (myFax.value!="")
{
	var validFax=re.exec(myFax.value);
	if (validFax)
	{
		myFax.value="("+validFax[1]+")-"+validFax[2]+"-"+validFax[3];
	}
	else
	{
		alert(myFax.value+" is not a valid fax number");
		myFax.focus();
		myFax.select();
	}
	return false;
}
}

function showDate()
{
   dt = new Date();   //Gets today's date right now (to the millisecond).
   month = dt.getMonth()+1;
   day = dt.getDate();
   year = dt.getFullYear();
   alert(month + '/' + day + '/' + year);
}

// this function checks if two emails are the same
function confirmEmail()
{
	if (document.newsletterReq.email.value!= document.newsletterReq.emailConfirm.value)
	{
		alert(document.newsletterReq.emailConfirm.value+" is not the same as first email you specified!");
			document.newsletterReq.emailConfirm.focus();
			return false;
	}
	return true;
	
}

function confirmEmailDemo()
{
	if (document.getPass.email.value!= document.getPass.emailConfirm.value)
	{
		alert(document.getPass.emailConfirm.value+" is not the same as first email you specified!");
			document.getPass.emailConfirm.focus();
			return false;
	}
	return true;
	
}

function emptyFieldsDemo()
{
	if (document.getPass.first_name.value=="" || document.getPass.last_name.value=="" 
		|| document.getPass.email.value=="" || document.getPass.emailConfirm.value=="" 
		|| document.getPass.position.value=="Select Position")
	{
		alert("All fields are required!");
        return false;
	}
	return true;
}

function emptyFieldsDemoInfo()
{
	if (document.getInfo.first_name.value=="" || document.getInfo.last_name.value=="" 
		|| document.getInfo.email.value=="" || document.getInfo.emailConfirm.value=="" 
		|| document.getInfo.position.value=="Select Position" || document.getInfo.schoolName.value==""
		|| document.getInfo.address.value=="" || document.getInfo.city.value==""
		|| document.getInfo.state.value=="" || document.getInfo.phone.value=="")
	{
		alert("All fields are required! You  most likely didn't select a position.");
        return false;
	}
	return true;
}


function emptyFieldsCareers()
{
	if (document.applicationOnline.firstName.value=="" || document.applicationOnline.lastName.value=="" 
		|| document.applicationOnline.address1.value=="" || document.applicationOnline.country.value=="" 
		|| document.applicationOnline.position.value=="Select Position" || document.applicationOnline.email.value==""
		|| document.applicationOnline.phone.value=="" || document.applicationOnline.city.value==""
		|| document.applicationOnline.eduLevel.value=="chooseOpt" || document.applicationOnline.resume1.value==""
		|| document.applicationOnline.salaryExpec.value=="")
	{
		alert("All fields are required!");
        return false;
	}
	return true;
}