function validateZipCode(zipCode) {
   // Check for correct zip code
   reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
   if (!reZip.test(zipCode)) {
	return false;
   } else {
   	return true;
   }
} 

function isblank(s){
	for(var i=0; i < s.length; i++){
		var c = s.charAt(i);
		if((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}


function resetWarningField() {
	document.getElementById("firstNameWarn").style.display="none";												
	document.getElementById("lastNameWarn").style.display="none";												
	document.getElementById("addressWarn").style.display="none";												
	document.getElementById("cityWarn").style.display="none";								
	document.getElementById("stateWarn").style.display="none";								
	document.getElementById("zipCodeWarn").style.display="none";								
	document.getElementById("phoneNumberWarn").style.display="none";								
	document.getElementById("emailAddressWarn").style.display="none";												
	document.getElementById("confirmEmailAddressWarn").style.display="none";	

}

function validateEntryForm(formObj) { 
	var msg;
	var empty_fields = "";
	var errors = "";
	var success = true;
//	formObj.address2.optional = true;
	resetWarningField();

	for(var i=0; i < document.forms[formObj].length; i++){
//		var e = formObj.elements[i];
		
		var e = document.forms[formObj].elements[i];
		
		if((e.type == "text" || e.type == "hidden" || e.type == "select-one") && !e.optional){
			//first check if the field is empty
			
			if((e.value == null) || (e.type == "") || isblank(e.value)){
				if (e.name.indexOf("firstName") > -1) {
					document.getElementById("firstNameWarn").style.display="block";												
					success = false;					
				} else if (e.name.indexOf("lastName") > -1) {
					document.getElementById("lastNameWarn").style.display="block";
					success = false;					
				} else if (e.name.indexOf("address1") > -1) {
					document.getElementById("addressWarn").style.display="block";
					success = false;					
				} else if (e.name.indexOf("city") > -1) {
					document.getElementById("cityWarn").style.display="block";
					success = false;					
				} else if (e.name.indexOf("state") > -1) {
					document.getElementById("stateWarn").style.display="block";	
					success = false;					
				} else if (e.name.indexOf("zipCode") > -1) {
					document.getElementById("zipCodeWarn").style.display="block";
					success = false;					
				} else if (e.name.indexOf("phone") > -1) {
					document.getElementById("phoneNumberWarn").style.display="block";
					success = false;					
				} else if (e.name.indexOf("email") > -1) {
					document.getElementById("emailAddressWarn").style.display="block";
					success = false;					
				} else if (e.name.indexOf("confirmEmail") > -1) {
					document.getElementById("confirmEmailAddressWarn").style.display="block";
					success = false;					
				} else {
				//	empty_fields += "\n        " + e.name;
				}
				continue;
			}

		}
	}
	
	if ( !(validateZipCode(document.forms[formObj].zipCode.value)) ) {
		document.getElementById("zipCodeWarn").style.display="block";	
		success = false;		
	} 
	if (document.forms[formObj].email.value.indexOf('@') <= -1) {
		document.getElementById("emailAddressWarn").style.display="block";		
		success = false;		
	} 
	if (document.forms[formObj].email.value != document.forms[formObj].confirmEmail.value) {
		document.getElementById("confirmEmailAddressWarn").style.display="block";	
		success = false;		
	} 
	
	
	if (success == false) {
		window.location.hash = "sweepstakesHome";	
	} else {
		document.forms[formObj].submit();
	} 
	
}

function mailLYNMBpage()
{
//	document.domain = window.location.host;
//	document.domain = "localhost";

//	For DEV environment
//	document.domain = "dev.parenting.com";

//  For TEST environment
//	document.domain = "test.parenting.com";		

//  For PRODUCTION environment
//	document.domain = "www.parenting.com";

	var url = window.location.href;
	mail_str = "mailto:?subject=Join me for the Love Your New-Mom Body program!";
	mail_str += "&body=Babytalk.com just launched their Love Your New-Mom Body program, and I wanted to invite you to join me";
	mail_str += "! %0A%0AYou'll get 12 weeks of great advice on feeling great, looking great, and appreciating those new-mom curves.  Best of all, it's specifically designed for busy moms who don't have all the time in the world to hang out at the gym";
	mail_str += ". %0A%0APlus, you can enter to win a week at a luxury spa in Mexico";
	mail_str += "! %0A%0ACheck it out here: " + escape('http://www.babytalk.com/lynmb'); 
	location.href = mail_str;
}

function mailpage()
{
	var title = document.title.replace(/&/, "and");;

//	document.domain = window.location.host;
//	document.domain = "localhost";

//	For DEV environment
//	document.domain = "dev.parenting.com";

//  For TEST environment
//	document.domain = "test.parenting.com";		

//  For PRODUCTION environment
//	document.domain = "www.parenting.com";

	var url = window.location.href;
	mail_str = "mailto:?subject=Thought you might like to join the " + title;
	mail_str += "&body=I thought you might be interested in joining the " + title;
	mail_str += ". %0A%0AYou can view it at " + escape(url); 
	location.href = mail_str;
}
