// This function will validate a form
function validateForm(theform)
{
	pass = 1; //assume everything is ok
  	msg = "The following problems where found in trying to submit this form:\n\n";

  //validate the name
   	if (theform.name.value==null||theform.name.value=="")
  	{
    	msg = msg + "- The Name cannot be blank\n";
  	 	pass = 0;
  	}
  	else
  	{
 		var badChars = "~!@#$%^*()_-+={}[]:;\"'<,>.?/"; // illegal characters
		if (isIllegalChars(theform.name.value,badChars) == true)
		{
			msg = msg + "- The Name cannot have illegal characters (" + badChars + ") \n";
			pass = 0;
		}
	}	
 
  //validate the email address
   	if (theform.email.value==null||theform.email.value=="")
  	{
    	msg = msg + "- The Email Address cannot be blank\n";
  	 	pass = 0;
  	}
  	else
  	{
		if (isEmail(theform.email.value)==false)
		{
			msg = msg + "- The email address is not valid\n";
			pass = 0;
		}
  	}
  	
 //validate the phone number
   	if (theform.phone.value > "")
 	{
  		if (theform.phone.value.length < 12 || theform.phone.value.length > 12)
 		{
 			msg = msg + "- The Phone Number must be 12 characters\n";  		
 		}
 		
 		if (isFormatedPhoneNumber(theform.phone.value) == false)
  		{
  			msg = msg + "- The Phone Number is not formatted properly (### - ### - ####)\n";
  		}  	
  		
  		var badChars = " ~!@#$%^&*()_+={}[]:;\"'<,>.?/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // illegal characters
		if (isIllegalChars(theform.phone.value,badChars) != "")
		{
			msg = msg + "- The Phone Number cannot have illegal characters\n";
			msg = msg + "   (" + badChars.slice(0,42) + ")\n";			
			msg = msg + "   (" + badChars.slice(42) + ")\n";

			pass = 0;
		}
	}
  	
	if (pass == 1)
	{
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
}

// validators ------------------------------------------------------------------
	
function isEmpty (s) 
{
	var p = /\S+/;
	return !p.test(s);
}

function isEmail(string) 
{
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isAlphaNum(string) 
{
    if (string.search(/^[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function checknumber(string)
{
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(string)) 
		testresult=true 
	else 
		testresult=false
	return (testresult)
}

function isExecutable (s) 
{
	var p = /\.(bat|com|dll|exe|vbs)$/i;
	return p.test(s);
}

function isImage (s) 
{
	var p = /\.(gif|jpg)$/i;
	return p.test(s);
}

function isUrl (s) 
{
	var p = /^(http|https|ftp):\/\/\S+\.[^\.\s]{2,4}(\/\S*)?$/i;
	return p.test(s);
}

function isIllegalChars(s,illegalChars) 
{
    for (i = 0; i <= illegalChars.length - 1; i++)
    {
 		for (j = 0; j <= s.length - 1; j++)
 		{
 			if (s.charAt(j) == illegalChars.charAt(i))
 			{
 				return true
 			}
 		}
    }
    return false
}

function isFormatedPhoneNumber(s)
{
	if (s.charAt(3) != "-") return false
	if (s.charAt(7) != "-") return false
	else return true
}


