// JavaScript Document
function validate_form(thisform)
{
	with(thisform)
	{/* No any Validation */
		if(validate_required(vName,"Name ") == false)
		{
			vName.focus();
			return false;
		}		
		if(validate_required(vPhone,"Phone ") == false)
		{
			vPhone.focus();
			return false;
		}
		if(validate_required(vEmail,"Email ") == false)
		{
			vEmail.focus();
			return false;
		}
		if(validate_email(vEmail,"Email ") == false)
		{
			vEmail.focus();
			return false;
		}
		if(validate_required(vEnquiry,"Enquiry ") == false)
		{
			vEnquiry.focus();
			return false;
		}				
	}	
}


// this function is used to find keycode of input - Nilesh Patel
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}
// only no. can be entered using this function - Nilesh Patel
function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);
  
  if (cCode < 48 || cCode > 57 ) 
  {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
	alert("Value must be Numeric Value!");
	return false
  }
  else {return true}
}
// CHECK FOR INPUT REQUIRMENT
function validate_required(field,thename)
{
	with (field)
	{
		if (value==null||value=="")
		{
			alert("Please Enter "+thename+" !");
			return false
		}
		else {return true}
	}
}
//e-mail validation
function validate_email(field)
{
		with (field)
		{
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")

		if(apos == -1 || dotpos == -1 || dotpos <= apos + 1 || dotpos == 0 || dotpos == value.length - 1)
	  /*{alert(field.name+" is not valid e-mail!");return false}*/
	  {alert("Please Enter Valid E-mail Address!");return false}

	  user_name = value.substr(0, apos);
	  domain_name = value.substr(apos + 1, value.length);                  

	  if(Validate_String(user_name) === false || 
    	Validate_String(domain_name) === false)
	   {alert(msgtxt); return(false);}
	else {return true}
		}
}
//function used by e-mail validation validation
function Validate_String(string, return_invalid_chars) 
{
  valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  invalid_chars = '';
  if(string == null || string == '')
   return(true);
  //For every character on the string.   
  for(index = 0; index < string.length; index++) {
    char = string.substr(index, 1);                        

    //Is it a valid character?
    if(valid_chars.indexOf(char) == -1) {
      //If not, is it already on the list of invalid characters?
      if(invalid_chars.indexOf(char) == -1) {
        //If it's not, add it.
        if(invalid_chars == '')
          invalid_chars += char;
        else
          invalid_chars += ', ' + char;
      }
    }
  }
  //If the string does not contain invalid characters, the function will return true.
  //If it does, it will either return false or a list of the invalid characters used
  //in the string, depending on the value of the second parameter.
  if(return_invalid_chars == true && invalid_chars != '') {
    last_comma = invalid_chars.lastIndexOf(',');
    if(last_comma != -1)
      invalid_chars = invalid_chars.substr(0, $last_comma) + 
      ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
    return(invalid_chars);
    }
  else
    return(invalid_chars == ''); 
}
// number validation


function isDigit(num)
{	with (num)
	{
		if (validate_required(num)==false)
				{return false}
		var string="1234567890";
		for(var i=0;i<value.length;i++)
		{		
				if (string.indexOf(value.charAt(i))!=-1)
				{	return true;	}
				else
		{		alert(num.name+" must be numeric");
				num.value='';
				return false;
		}
		}
	}
}
