// JavaScript Document

function echeck(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID");
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID");
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID");
		    return false;
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID");
		    return false;
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID");
		    return false;
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID");
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID");
		    return false;
		 }
}
function IsNumeric(strString){
     //check for valid numeric strings; 
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
 } 

function valid_contactform()
{
	if( document.frmContact.txtusername.value == ''){
		alert(' Enter Username.');
		document.frmContact.txtusername.focus();
		return false;
	}
	if ( document.frmContact.txtemail.value == '' ) {
		alert(' Enter Email-ID.');
		document.frmContact.txtemail.focus();
		return false;
	}
	if(document.frmContact.txtemail.value != '')
	{		
		if (echeck(document.frmContact.txtemail.value) == false)
		{
			alert(' Enter valid Email-ID.');
			document.frmContact.txtemail.focus();
			return false;
		}
	}
	if(document.frmContact.txtphone.value != ''){
	if(IsNumeric(document.frmContact.txtphone.value) == false){
		alert(' Phone no. should be integer.');
		document.frmContact.txtphone.focus();
		return false;
		}
	}
	if( document.frmContact.txtcomment.value == ''){
		alert(' Enter Message.');
		document.frmContact.txtcomment.focus();
		return false;
	}
	return true;
}

