// JavaScript Document

// make the parameter visible
function show(object) {  
		var heightPx = 30;			
	
    if (document.layers && document.layers[object])
        document.layers[object].visibility = 'visible';
    else if (document.all) {
        document.all[object].style.visibility = 'visible';      
        document.all[object].style.height = heightPx;
		
		document.all[object].focus();
    }
}
// make the parameter hidden
function hide(object) {
   	var heightPx = 30;	
   if (document.layers && document.layers[object])
        document.layers[object].visibility = 'hidden';
    else if (document.all)
        document.all[object].style.visibility = 'hidden';
        document.all[object].style.height = heightPx;
}

function Trim(s) 
{
	  // Remove leading spaces and carriage returns		  
	  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	  {
	    s = s.substring(1,s.length);
	  }

	  // Remove trailing spaces and carriage returns
	  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	  {
	    s = s.substring(0,s.length-1);
	  }
	  return s;
}		

function checkCheckBox(cb){
 return cb.checked;
}

function checkFields() {

	var passValidation = true;

	//Validate Required
	if (
		(Trim(document.contactForm.input_firstNm.value).length == 0)  
		||
		(Trim(document.contactForm.input_lastNm.value).length == 0)  
		||
		(Trim(document.contactForm.input_email.value).length == 0)  
		||
		(Trim(document.contactForm.txtarea_comments.value).length == 0)  
		||
		(
		(Trim(document.contactForm.input_phone1.value).length == 0) ||
		(Trim(document.contactForm.input_phone2.value).length == 0) ||
		(Trim(document.contactForm.input_phone3.value).length == 0)  			 
		)				
		) {
		
		show('requiredField');		
		passValidation = false;		
		
	}else{		
		//Hide Required Filed Error Message from previous validation
		hide('requiredField');				
	}	
	
			
	//Validate Email address
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;	
	if (!filter.test(document.contactForm.input_email.value)) {		
		show('emailInvalid');		
		passValidation = false;
	}else{
		hide('emailInvalid');		
	}
	
	//Validate Phone Number
	var numericExpression = /^[0-9]+$/;
	if( !document.contactForm.input_phone1.value.match(numericExpression) ||
		!document.contactForm.input_phone2.value.match(numericExpression) ||
		!document.contactForm.input_phone3.value.match(numericExpression) ||
		Trim(document.contactForm.input_phone1.value).length != 3 ||
		Trim(document.contactForm.input_phone2.value).length != 3 ||
		Trim(document.contactForm.input_phone3.value).length != 4 
	) {			
		show('phoneInvalid');		
		passValidation = false;		
	}else{
		hide('phoneInvalid');		
	}
	
		
	
	if (passValidation){	
		return true;
	}else{		
		return false;
	}
	

	
}


