/*
VALIDATE: validates email entry, checking format correctness and passing values to email submission.
User must within the entry form of content posting enter "Hidden" input tags to indicate identifier type of email to be generated.
eg. <INPUT type=hidden name=emailID value=default>
*/


function validate() {

	var strComments, strName, strEmail, strTitle, strOrg, strAddress, strPhone, strEmailDisplay, strEmailID;
	strComments = document.getElementsByName("comment");
	strName=document.getElementsByName("name");
	strEmail=document.getElementsByName("email");
	strOrg=document.getElementsByName("org");
	strTitle=document.getElementsByName("title");
	strAddress=document.getElementsByName("address");
	strPhone=document.getElementsByName("phone");
	
	if (document.org)
	{
		strOrg=document.getElementsByName("org")[0].value;
		//alert("org ="+strOrg);
	}
	
	if (document.title)
	{
		strTitle=document.getElementsByName("title")[0].value;
		//alert("title ="+strTitle);
	}
	else
	{
		strTitle="";
	}
	
	if (document.address)
	{
		strAddress=document.getElementsByName("address")[0].value;
		//alert("add ="+strAddress);
	}
	else
	{
		strAddress="";
	}

	if (document.phone)
	{
		strPhone=document.getElementsByName("phone")[0].value;
	}	
	else
	{
		strPhone="";
	}
	
	if (document.emailID != "")
		strEmailID=document.getElementsByName("emailID")[0].value;
	else //default email ID
		strEmailID = "default";
	
	if ( strComments[0].value == "" ) {
		alert("Please enter your comments.");
		//return false;
		strComments.focus();
	}	

	if ( strName[0].value == "" ) {
		alert("Please enter your name.");
		strName.focus();
	}	

	if ( ( strEmail[0].value == "" ) || ( checkEmail(strEmail[0].value) ) ) {
		alert("Please enter a valid email address.");
		strEmail.focus();
	}
	
	
	//location.href("/nidcdinternet/tools/nsrp_email.aspx?Email=" + strEmail[0].value + "&Name=" + strName[0].value + "&Comments=" + strComments[0].value + "&Title=" + strTitle[0].value + "&Address=" + strAddress[0].value + "&Organization=" + strOrg[0].value + "&Phone=" + StrPhone[0].value + "&Body=" + strBody[0].value);
	location.href= "/nidcdinternet/tools/nsrp_email.aspx?Email=" + strEmail[0].value + "&Name=" + strName[0].value + "&Comments=" + strComments[0].value + "&Title=" + strTitle + "&Address=" + strAddress + "&Organization=" + strOrg + "&Phone=" + strPhone+ "&EmailID=" + strEmailID;
	
}

function checkEmail(myString) {
	var newString = myString.match(/\b\S+@.+\.\D{2,4}\b/gi);

	if (!newString) {
		return true;
	}
	
	else {
		return false;
	}
}
