var errorLabelList = '';
var errorIDList = '';
var errorDisplayList = '';

var today = new Date();
var currMonth = today.getMonth();
var currYear = today.getFullYear();

function validateUtilSearch() {
  if (document.getElementById('searchArgQuick').value == '') {
    alert('Please include a search term.');
    document.getElementById('searchArgQuick').focus();	
    return false;
  }	  
  return true;	
}	

function isBlank(inputObj) { 
 for(var x = 0; x < inputObj.value.length; x++) {
  if(inputObj.value.charCodeAt(x) != 32) {
   return false;
  }  
 }
 return true;
}

function isValidEmail(inputObj) {
 if(inputObj.value.indexOf('@') == -1 || inputObj.value.indexOf('.') == -1 || inputObj.value.length < 7) {
  return false;
 }
 return true;
}

function isNumeric(inputObj) {
 if(isNaN(inputObj.value)) {
  return false;
 }
 else {
  return true;
 }
}

function isRadioSelected(inputObj) { 
 for(x = 0; x < inputObj.length; x++) {
  if(inputObj[x].checked) {	    
   return inputObj[x].value;
  }
 }	  
 return false;
}

function isValidZip(inputObj) {
 if(isNumeric(inputObj) && inputObj.value.length == 5) { 
  return true;
 }
 else {
  return false;
 }
}

function isValidFullZip(inputObj) {}

function isValidPhone(format,inputObj) {
 // format - 0 = (xxx) xxx-xxxx
 // format - 1 = xxx xxx-xxxx
 // format - 2 = xxx.xxx.xxxx
 // format - 3 = xxx-xxxx
 switch(format) {
  case 0: {
   if(inputObj.value.indexOf('(') == -1 || inputObj.value.indexOf(')') == -1 || inputObj.value.indexOf('-') == -1 || inputObj.value.length !=14) {
    return false;
   }
   else {
    return true;
   }
  }
 }
}




function validateRequest() {
   var errArray;

	 // Clear Errors
   if (errorLabelList != '') {
   	  errArray = errorLabelList.split(',');
   	   for (i=0; i < errArray.length; i++) {
   	 	 document.getElementById(errArray[i]).style.border = '0px none';
   	   }   	
   	   document.getElementById('errorMessages').innerHTML = '';
   	   document.getElementById('errorMessages').style.display = 'none';
   	 
       errorIDList = '';
       errorLabelList = '';
   	   errorDisplayList = '';
   }	
   
   if (isBlank(document.getElementById('name'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'name';
   	   errorLabelList = errorLabelList + 'nameLabel';
   	   errorDisplayList = errorDisplayList + 'Name is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('email'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'email';
   	   errorLabelList = errorLabelList + 'emailLabel';
   	   errorDisplayList = errorDisplayList + 'Email is a required field.';   	 	
   }  

   else if (!isValidEmail(document.getElementById('email'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'email';
   	   errorLabelList = errorLabelList + 'emailLabel';
   	   errorDisplayList = errorDisplayList + 'E-mail must be in the proper format.'; 
   }
   
   if (errorIDList != '') {
   	var errDisplay = '<strong>The following errors have occurred:</strong><ul>';
   	
   	errIDArray = errorIDList.split(',');
   	errLabelArray = errorLabelList.split(',');
   	errDisplayArray = errorDisplayList.split(',');

   	for (i=0; i < errLabelArray.length; i++) {   		
   		document.getElementById(errLabelArray[i]).style.border='1px solid #FF0000';	 
   		errDisplay = errDisplay + '<li>' + errDisplayArray[i] + '</li>';
   	}   	
   	errDisplay = errDisplay + '</ul>';
   	
   	document.getElementById('errorMessages').innerHTML = errDisplay;
   	document.getElementById('errorMessages').style.display = 'block';
   	document.getElementById(errIDArray[0]).focus();
   	return;
   }
   else  {
     document.getElementById('how_contact').submit();   	    
   }

}

function validateJob() {
   var errArray;

	 // Clear Errors
   if (errorLabelList != '') {
   	  errArray = errorLabelList.split(',');
   	   for (i=0; i < errArray.length; i++) {
   	 	 document.getElementById(errArray[i]).style.border = '0px none';
   	   }   	
   	   document.getElementById('errorMessagesResume').innerHTML = '';
   	   document.getElementById('errorMessagesResume').style.display = 'none';
   	 
       errorIDList = '';
       errorLabelList = '';
   	   errorDisplayList = '';
   }	
   
   if (isBlank(document.getElementById('name'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'name';
   	   errorLabelList = errorLabelList + 'name';
   	   errorDisplayList = errorDisplayList + 'Name is a required field.';   	 	
   }  
   
   if (isBlank(document.getElementById('email'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'email';
   	   errorLabelList = errorLabelList + 'email';
   	   errorDisplayList = errorDisplayList + 'Email is a required field.';   	 	
   }  

   else if (!isValidEmail(document.getElementById('email'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'email';
   	   errorLabelList = errorLabelList + 'email';
   	   errorDisplayList = errorDisplayList + 'E-mail must be in the proper format.'; 
   }
   
   if (isBlank(document.getElementById('resume'))) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'resume';
   	   errorLabelList = errorLabelList + 'resume';
   	   errorDisplayList = errorDisplayList + 'You must specify a resume location.';   	 	
   }
   
   else if ( document.getElementById('resume').value.substring(document.getElementById('resume').value.length-4) != '.doc' ) {
   	   if (errorIDList != '') {
   	   	errorIDList = errorIDList + ',';
   	   	errorLabelList = errorLabelList + ',';
   	   	errorDisplayList = errorDisplayList + ',';
   	   }
   	   errorIDList = errorIDList + 'resume';
   	   errorLabelList = errorLabelList + 'resume';
   	   errorDisplayList = errorDisplayList + 'You may only upload a \'.doc\' type file.';   	 	
   }  
   
   if (errorIDList != '') {
   	var errDisplay = '<strong>The following errors have occurred:</strong><ul>';
   	
   	errIDArray = errorIDList.split(',');
   	errLabelArray = errorLabelList.split(',');
   	errDisplayArray = errorDisplayList.split(',');

   	for (i=0; i < errLabelArray.length; i++) {   		
   		document.getElementById(errLabelArray[i]).style.border='1px solid #FF0000';	 
   		errDisplay = errDisplay + '<li>' + errDisplayArray[i] + '</li>';
   	}   	
   	errDisplay = errDisplay + '</ul>';
   	
   	document.getElementById('errorMessagesResume').innerHTML = errDisplay;
   	document.getElementById('errorMessagesResume').style.display = 'block';
   	document.getElementById(errIDArray[0]).focus();
   	return;
   }
   else  {
     document.getElementById('jobSubmit').submit();   	    
   }

}