// JavaScript Document
<!--
// Example: obj = findObj("image1");
function findObj(theObj, theDoc)

{

  var p, i, foundObj;

  

  if(!theDoc) theDoc = document;

  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)

  {

    theDoc = parent.frames[theObj.substring(p+1)].document;

    theObj = theObj.substring(0,p);

  }

  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];

  for (i=0; !foundObj && i < theDoc.forms.length; i++) 

    foundObj = theDoc.forms[i][theObj];

  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 

    foundObj = findObj(theObj,theDoc.layers[i].document);
	
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

// validate by expression
function testPattern(pattern,inputString){
  // return true if test results is true
  if(pattern.test(inputString)){
    return true;
   }else{
    return false;
   }
}
function matchValue(val1,val2){
	if(val1 != '' && val2 != ''){
		if(val1 != val2){
			return true;
		}else{ 
			return false;
		}
	}else{
		return true;
	}
}
// validate email address
function validateEmailAddress(email){
  var pattern = /^[_a-z0-9-]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})/;
  // if valid return false
  if(testPattern(pattern,email)){
    return false;
  }else{
    return true;
  }
}
// validate phone number
function validatePhoneNumber(number){
  if(number.length >= 7){
    // string pattern test for numerals only
     var searchForNumbers = /\D+\_+\W+\s+\S+/;
    // validate that the number is all numerals
    return testPattern(searchForNumbers,number);
  }else{
    return true;
  }
}
// validate form
function checkForm(){
  // error manager
  var error = false;
  // inti
  var theform = '';
  var noElements = 0;
  // get form object
  if(arguments.length>0){
    theform = checkForm.arguments[0];
	noElements = (checkForm.arguments.length) - 1; // get no of elements from function
  }else{
    // find default form
    theform =  document.forms[0];
	// find # of elements
	noElements = theform.elements.length; // get no of elements from form
  }
  // loop true elements to validate
  forLoop:
  for(var i=0; i<noElements;i++){
    // get element object
	if(arguments.length>0){
		var field = findObj(arguments[i+1]);
	}else{
    	var field = theform.elements[i];
	}
    // if the field is a required field
   if(field.type != 'submit' && field.type != 'hidden' && !field.disabled){
       if((field.className).search(/required/) >= 0){
        // check value
        if(error = checkValue(field)) break forLoop; // exit for loop
      }
    }
  }
  return error? false : true;
}
// check the values of the field name
function checkValue(f){
  if(f.value == ''){
    sendAlert('Error: '+f.title);
    return true;
  // validate phone number
  }else if((f.name).search(/phone/i) >= 0){
    if(validatePhoneNumber(f.value)){
      sendAlert('Please Enter a (7) or (10) digit format for this Field!');
      return true;
    }else{
      return false;
    }
  // check for valid email
  }else if((f.name).search(/email/i) >=0 ){
    if(validateEmailAddress(f.value)){
      sendAlert('Please Enter a Valid Email Address!');
      return true;
    }else{
      return false;
    }
  }else{
    return false;
  }
}
// alert user of error
function sendAlert(msg){
  window.alert(msg);
}
-->
