function mytrim(val)
{
		val1 = "";
		val2="";
		ctrr = 0;
		lngth = val.length;
		for (i=0; i<lngth; i++)
		{
		if (val.charCodeAt(i) != 32)
		{
		for(j=i;j<lngth;j++)
		{
		if (val.charCodeAt(j) != 13 && val.charCodeAt(j) != 10 )
			{
			val1 += val.charAt(j);
			}
		}
		break;
		}
		}
		if (val1 != "")
		{
		lngth = val1.length
		ctrr=lngth;
		for (k=0; k<lngth; k++)
		{
		ctrr=ctrr-1;
		if (val1.charCodeAt(ctrr) != 32)
		{
		for(l=0;l<lngth-k;l++)
		{
		val2 += val1.charAt(l);
		}
		val1=val2;
		break;
		}
		}
		}
		return val1;
}
 function IsNumeric(sText)
 {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

 }
 
 function isValidPhoneNumber(numval,message) {
 var valid = "0123456789-";
 var hyphencount = 0;
 var ret_val=true; 
 if (numval.length!=12)
 {
  ret_val =  false;
 }
 if (ret_val)
 {
 for (i=0;i<numval.length;i++)
 {
  if(valid.indexOf(numval.charAt(i))==-1)
   ret_val=false;
  else if ( (i != 3 && i != 7) && !(parseInt(numval.charAt(i)) >= 0 && parseInt(numval.charAt(i)) <=9) )
	ret_val=false;
  }
 if (ret_val && (numval.charAt(3) != "-" || numval.charAt(7) != "-" ))
 {
 ret_val=false;
 }
 }
 if (!ret_val)
 {
 alert(message+"\n The format is 999-999-9999");
 }
 return ret_val;
}

function checkform4()
{
		if (mytrim(document.frmintern.firstname.value)=="")
		{
			alert("Please enter First Name");
			document.frmintern.firstname.focus();
			return false;
		}
		if (mytrim(document.frmintern.lastname.value)=="")
		{
			alert("Please enter Last Name");
			document.frmintern.lastname.focus();
			return false;
		}
		if (!mytrim(document.frmintern.zip.value)=="")
		{
			if (!IsNumeric(document.frmintern.zip.value))
			{
				alert("Please enter valid Zip");
				document.frmintern.zip.focus();
				return false;
			}
			if (document.frmintern.zip.value.length<5)
			{
				alert("Please enter valid Zip");
				document.frmintern.zip.focus();
				return false;
			}
		}
		if (!mytrim(document.frmintern.phone.value)=="")
		{
			if (!isValidPhoneNumber(document.frmintern.phone.value,"Please enter valid cell number"))
			{
				document.frmintern.phone.focus();
				return false;
			}
			
		}
		var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		if (!(chkFilter.test(document.frmintern.email.value))) {
			  alert("Please enter a valid email address");
			  document.frmintern.email.focus();
			  return false;
		}
		if(!mytrim(document.frmintern.comments.value)=="")
		{
		  if(document.frmintern.comments.value.length>5000)
		  {
			  alert("Please enter comments less than 5000 words");
			  document.frmintern.comments.focus();
			  return false;
		  }
		}
				
}