var validations = new Array();

// Define which validations to perform. Each array item

// holds the form field to validate, and the validation

// to be applied. This is the only part you need to

// customize in order to use the script in a new page!



validations[0]=["document.myform.name", "notblank"];
validations[1]=["document.myform.email", "validemail"];
validations[2]=["document.myform.company", "notblank"];
validations[3]=["document.myform.contact", "isnumber"];
validations[4]=["document.myform.vercode", "notblank"];
validations[5]=["document.myform.services", "notblank"];



// Customize above array when used with a new page.

function isEmpty(s) 

{
   //var s = field.value;
  if (s == null || s.length == 0)

    return true;



  // The test returns true if there is at least one non-

  // whitespace, meaning the string is not empty. If the

  // test returns true, the string is empty.

  return !/\S/.test(s);

}
function looksLikeEmail(field)

{

  var s = field.value;



  if (isEmpty(s))

   {
     alert("Email may not be empty");

     field.focus();

     return false;

   }

  if (/[^@]+@\w+\.+/.test(s))

       return true;

  alert("E-mail not in valid form.");

  field.focus();

  return false;

}

function isNumberInput(field, event) 

{

  var key, keyChar;



  if (window.event)

    key = window.event.keyCode;

  else if (event)

    key = event.which;

  else

    return true;

  // Check for special characters like backspace

  if (key == null || key == 0 || key == 8 || key == 13 || key == 27)

    return true;

  // Check to see if it's a number

  keyChar =  String.fromCharCode(key);

  if (/\d/.test(keyChar)) 

    {

     window.status = "";

     return true;

    } 

  else 

   {

    window.status = "Field accepts numbers only.";

    return false;

   }

}


function isInteger(field)

{

  var s = field.value;

  if (isEmpty(s))

   {

     alert("Field cannot be empty");

     field.focus();

     return false;

   }

  if (!(/^-?\d+$/.test(s)))

   {

     alert("Field must contain only digits");

     field.focus();

     return false;

   }

 return true;

}
function isChar(field)

{

  var s = field.value;

  if (isEmpty(s))

   {

     alert("Field cannot be empty");

     field.focus();

     return false;

   }



  if (!(/[^@]+\w+$/.test(s)))

   {

     alert("Field must contain only digits");

     field.focus();

     return false;

   }

 return true;

}



function validate()

{

  var i;

  var checkToMake;

  var field;


  for (i = 0; i < validations.length; i++)

   {

     field = eval(validations[i][0]);

     checkToMake = validations[i][1];

     switch (checkToMake)     

      {

       case 'notblank': if (isEmpty(field.value))

                          {

                           alert("Field may not be empty");

                           field.focus();

                           return false;

                          }

                        break;

       case 'validemail':  if (!looksLikeEmail(field))

                               return false;

                           break;

       case 'isnumber':  if (!isInteger(field))

                            return false;
                             
							break;
	  case 'ischar':  if (!isChar(field))
	                     
						 return false;
       
	                      break;
	
	 case 'iskeymask':  if(!isNumberInput(field))
	                       
						   return false;
						   
	  }

   }

  return true;
}
