//This function checks if the name is entered. 
//If yes - it calls the function to check if the email is in a valid format
//If no - it returns false and asks the user to enter the name
function chkFields(form, email){
	if(form.MarketingName.value == ''){
		alert('Enter the name');
		form.MarketingName.focus()
		return false;
	}
	//for landing pages that have a state reqd.
	if(form.MarketingState != null) {
		if(form.MarketingState.value == 0){
			alert('Select a state');
			return false;
		}
			
	}	

	if(form.MarketingEmail.value == ''){
		alert('Enter the email');
		form.MarketingEmail.focus()
		return false;			
	}	
	
	if(form.MarketingPhone.value == ''){
		alert('Enter the phone');
		form.MarketingPhone.focus()
		return false;			
	}	
	

	else return isEmail(email);
}	
// ******************************************************************
// This function accepts a string variable and verifies if it is in
// the proper format for an e-mail address or not.

// The function returns true if the format is valid, false if not.
// ******************************************************************
function isEmail(email) {

    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

    // Check for null
    if (email == "") {
		return true;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            alert('Incorrect email format')
			return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        alert('Incorrect email format')
		return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        alert('Incorrect email format')
		return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            alert('Incorrect email format')
			return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        alert('Incorrect email format')
		return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
        alert('Incorrect email format')
		return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        alert('Incorrect email format')
		return false;
    }
    if (periodPos+3 > email.length) {
        alert('Incorrect email format')
		return false;
    }
    return true;
}

function openpopup(popurl){
	winpops=window.open(popurl,"","toolbar=no,width=520,height=520,directories=no,status=no,scrollbars=yes,resize=no,menubar=no")
}