function emailSubject(myForm)
{

var titleReg = document.title
var re = new RegExp("[-:]\\s*([\\w\\s()]+)[.,]"); 
var mySearch =/[\-\:]/

 
 
if (!(titleReg.search(mySearch) == -1))
{
    //var m = re.exec(docuement.title);
	//titleReg = m[0];
    document.myForm.email.value = "Form Submission: " + titleReg


}
else
{
      document.myForm.email.value = "Form Submission: " + titleReg
}
}
function submitIt(myForm) 
{
	//check that fields are filled out
	
	if (document.myForm.pname.value == "")
	{
		alert("Invalid name")
		document.myForm.pname.focus()
		document.myForm.pname.select()
		return false;
	}

	if(!stringFilter(document.myForm.phone.value))	
	{
		alert("Invalid phone number")
		document.myForm.phone.focus()
		document.myForm.phone.select()
		return false;
	}

	if (!validEmail(document.myForm.mailid.value)) 
	{
		alert("Invalid email address")
		document.myForm.mailid.focus()
		document.myForm.mailid.select()
		return false;
	}

	if(!checkText())	
	{
		alert("Invalid comments")
		document.myForm.comments.focus()
		document.myForm.comments.select()
		return false;
	}
	
	emailSubject(myForm);

}

function checkText()
{
	var regexpress=/<[a-zA-Z][a-zA-Z0-9]*>/  //regular expression defining an HTML tag

	// test
	if (document.myForm.comments.value == "")
		return false;
	if (document.myForm.comments.value.search(regexpress)==-1) // if match failed
		return true;
	else 
		return false;
}


function validEmail(mailid) 
{

	var invalidChars = " /:,;";
	var badChar;
	var atPos;
	var periodPos;

	if (mailid == "") 
	{
		return false;
	}

	for (i=0; i<invalidChars.length; i++) 
	{
		badChar = invalidChars.charAt(i)
		if (mailid.indexOf(badChar,0) > -1)
		{
			return false;
		}
	}

	atPos = mailid.indexOf("@",1)
	
	if (atPos == -1) 
	{
		return false;
	}

	if (mailid.indexOf("@",atPos+1) > -1) 
	{
		return false;
	}

	periodPos = mailid.indexOf(".",atPos)
	if (periodPos == -1) 
	{
		return false;
	}

	if (periodPos+3 > mailid.length)
	{
	return false;
	}
	
return true;

}


function stringFilter (phone)
{
	if (phone == "" || phone == null)
	{
		return false;
	}
	else
	{
		filteredValues = "()-+ "; // Characters stripped out
		var i;
		var returnString = "";
		for (i = 0; i < phone.length; i++)
		{ // Search through string and append to unfiltered values to returnString.
			var c = phone.charAt(i);
			if (filteredValues.indexOf(c) == -1) 
				returnString += c;
		}
	// After stripping out (), -, or + checking to see if any characters exist. If so then fail and alert user
		if(isNaN(returnString))
		{
			return false;
		}
		else
		{
	// Verifying that phone number is 10 digits or greater to be a valid phone number
			if(returnString.length >= 10)
			{
				//document.myForm.phone.value = returnString;
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}
