//Function to check numeric values only
function IsNumeric(strString)
{
	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 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){
     document.getElementById(h_id).style.display='';
	document.getElementById(h_id).innerHTML="Invalid E-mail ID";
	id.focus();
     return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	document.getElementById(h_id).style.display='';
	document.getElementById(h_id).innerHTML="Invalid E-mail ID";
	id.focus();
     return false;
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    document.getElementById(h_id).style.display='';
	document.getElementById(h_id).innerHTML="Invalid E-mail ID";
	id.focus();

      return false;
  }
   if (str.indexOf(at,(lat+1))!=-1){
      	document.getElementById(h_id).style.display='';
		document.getElementById(h_id).innerHTML="Invalid E-mail ID";
		id.focus();

      return false
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      	document.getElementById(h_id).style.display='';
		document.getElementById(h_id).innerHTML="Invalid E-mail ID";
		id.focus();

      return false
   }
   if (str.indexOf(dot,(lat+2))==-1){
    	document.getElementById(h_id).style.display='';
		document.getElementById(h_id).innerHTML="Invalid E-mail ID";
		id.focus();

      return false
   }
   if (str.indexOf(" ")!=-1){
      	document.getElementById(h_id).style.display='';
		document.getElementById(h_id).innerHTML="Invalid E-mail ID";
		id.focus();

      return false
   }
   return true          
}

function validation(tem)
{
	id=document.getElementById('name');
	 h_id='hid_'+'name'; 
	 document.getElementById(h_id).style.display='none';
	 document.getElementById(h_id).innerHTML='';
	 if(id.value=='')
	 {
		  document.getElementById(h_id).style.display='';
		  document.getElementById(h_id).innerHTML='Enter Full Name';
		  id.focus();
		  return false;
 	}
	
	id=document.getElementById('email');
	 h_id='hid_'+'email'; 
	 document.getElementById(h_id).style.display='none';
	 document.getElementById(h_id).innerHTML='';
	 if(id.value=='')
	 {
		  document.getElementById(h_id).style.display='';
		  document.getElementById(h_id).innerHTML='Enter E-Mail Address';
		  id.focus();
		  return false;
 	}
	
	if (echeck(id.value)==false){
		 document.getElementById(h_id).style.display='';
		  document.getElementById(h_id).innerHTML='Invalid E-Mail Address';
		id.focus();
		return false;
	 }
	 
	 id=document.getElementById('phone');
	 h_id='hid_'+'phone'; 
	 document.getElementById(h_id).style.display='none';
	 document.getElementById(h_id).innerHTML='';
	 if(id.value=='')
	 {
		  document.getElementById(h_id).style.display='';
		  document.getElementById(h_id).innerHTML='Enter Phone Number';
		  id.focus();
		  return false;
 	}
	if(IsNumeric(id.value)==false)
	{
		document.getElementById(h_id).style.display='';
		document.getElementById(h_id).innerHTML='Enter Numeric Value';
		id.focus();
		return false;
	} else { document.getElementById(h_id).style.display='none'; }

	if(tem!='')
	{
		send_mail();
	} else {
		return true;
	}
	
}

