

function checkemail(obj) {
var obj = eval(obj);
if (obj.email != null) {
	var tmpaddress = obj.email.value;
}
var tvar;
	if ((tmpaddress.indexOf('@') < 0) || ((tmpaddress.charAt(tmpaddress.length-4) != '.') && (tmpaddress.charAt(tmpaddress.length-3) != '.'))) {
		tvar = "\n     -  Correct email address";
	} else {
        tvar = "";
	}
	return tvar;
}

function checknewsletteremail(obj) {
var obj = eval(obj);
if (obj.ea != null) {
	var tmpaddress = obj.ea.value;
}
var tvar;
	if ((tmpaddress.indexOf('@') < 0) || ((tmpaddress.charAt(tmpaddress.length-4) != '.') && (tmpaddress.charAt(tmpaddress.length-3) != '.'))) {
		tvar = "\n     -  Valid email address";
	} else {
        tvar = "";
	}
	return tvar;
}



// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-. ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function checkphone(obj) {
var obj = eval(obj);
var tmpphone = obj.phone.value;
var error = "";
	if (checkInternationalPhone(tmpphone)==false){
		error = "\n     -  Please enter a valid phone number";
	}
return error;
}

function WithoutContent(ss) {
if(ss.length > 0) { return false; }
return true;
}

function NoneWithContent(ss) {
for(var i = 0; i < ss.length; i++) {
	if(ss[i].value.length > 0) { return false; }
	}
return true;
}

function NoneWithCheck(ss) {
for(var i = 0; i < ss.length; i++) {
	if(ss[i].checked) { return false; }
	}
return true;
}

function WithoutCheck(ss) {
if(ss.checked) { return false; }
return true;
}

function WithoutSelectionValue(ss) {
for(var i = 0; i < ss.length; i++) {
	if(ss[i].selected) {
		if(ss[i].value.length) { 
			return false; 
		}
	}
}
return true;
}

function checkRequiredFields(obj) {
var obj = eval(obj);
var missinginfo = "";
	if (obj.fullname != null) {
		if(WithoutContent(obj.fullname.value)) { 
			missinginfo += "\n     -  Name";
		} 
	}
	if (obj.email != null) {
		if(WithoutContent(obj.email.value)) { 
			missinginfo += "\n     -  Email";
		}
		if(!WithoutContent(obj.email.value)) { 
			missinginfo += checkemail(obj);
		} 
	}
	
	if (obj.phone != null) {
		if(WithoutContent(obj.phone.value)) { 
			missinginfo += "\n     -  Phone number";
		}
		if(!WithoutContent(obj.phone.value)) { 
			missinginfo += checkphone(obj);
		}
	}
	if (obj.question != null) {
		if(WithoutContent(obj.question.value)) { 
			missinginfo += "\n     -  Who's profile is seen on the penny (last name only)";
		}
		if(!WithoutContent(obj.question.value)) { 
			if(obj.question.value != "lincoln" && obj.question.value != "Lincoln") {
				missinginfo += "\n     -  Who's profile is seen on the penny (last name only)";
			}
		}
	}
// Put field checks above this point.
	if(missinginfo.length > 2) {
		missinginfo ="_____________________________\n" +
			"Please fill in the following information:\n" +
			missinginfo + "\n_____________________________" +
			"\nPlease re-enter and submit again.";
			//return false;
			alert(missinginfo);
			//obj.action =="";
	} else {
		obj.submit();
		//alert("form ok");
	}
} // end of function CheckRequiredFields()


function checkRequiredFields2(obj) {
var obj = eval(obj);
var missinginfo = "";
	if (obj.fullname != null) {
		if(WithoutContent(obj.fullname.value)) { 
			missinginfo += "\n     -  Name";
		} 
	}
	if (obj.title != null) {
		if(WithoutContent(obj.title.value)) { 
			missinginfo += "\n     -  Title";
		} 
	}
	if (obj.email != null) {
		if(WithoutContent(obj.email.value)) { 
			missinginfo += "\n     -  Email";
		}
		if(!WithoutContent(obj.email.value)) { 
			missinginfo += checkemail(obj);
		} 
	}
	if (obj.question != null) {
		if(WithoutContent(obj.question.value)) { 
			missinginfo += "\n     -  Who's profile is seen on the penny (last name only)";
		}
		if(!WithoutContent(obj.question.value)) { 
			if(obj.question.value != "lincoln" && obj.question.value != "Lincoln") {
				missinginfo += "\n     -  Who's profile is seen on the penny (last name only)";
			}
		}
	}
// Put field checks above this point.
	if(missinginfo.length > 2) {
		missinginfo ="_____________________________\n" +
			"Please fill in the following information:\n" +
			missinginfo + "\n_____________________________" +
			"\nPlease re-enter and submit again.";
			//return false;
			alert(missinginfo);
			//obj.action =="";
	} else {
		obj.submit();
		//alert("form ok");
	}
} // end of function CheckRequiredFields()

function checkRequiredNewsletterFields(obj) {
var obj = eval(obj);
var missinginfo = "";
	if (obj.ea != null) {
		if(WithoutContent(obj.ea.value)) { 
			missinginfo += "\n     -  Valid email address";
		}
		if(!WithoutContent(obj.ea.value)) { 
			missinginfo += checknewsletteremail(obj);
		} 
	}
// Put field checks above this point.
	if(missinginfo.length > 2) {
		missinginfo ="_____________________________\n" +
			"Please fill in the following information:\n" +
			missinginfo + "\n_____________________________" +
			"\nPlease re-enter and submit again.";
			//return false;
			alert(missinginfo);
			//obj.action =="";
	} else {
		obj.submit();
		//alert("form ok");
	}
} // end of function CheckRequiredFields()
