//Checks if the supplied fields are empty and highlights field in red if so
function ContactFormValidation (sFieldIDs) {
	var i;
	var arrFields = sFieldIDs.split(":");
	var currField;
	var borderstyle = "1px solid #000000";
	var bgcolorstyle = "#bb7272";
	var bSubmitForm = true;
	var email= /^[\w-\.]+\@[\w\.-]+\.[a-zA-Z]{2,4}$/;
		
	for (i = 0; i < arrFields.length; i++) {
		// Get form field reference
		currField = document.getElementById(arrFields[i]);
		
		// Check for null in the case of a non existing html element
		if (currField != null) {
			// Set fields style to default
			SetBorderStyle(currField, "default");
			
			// If field is empty then set the style to red background and border
			if (currField.value == "") {
				SetBorderStyle(currField, "error");
				bSubmitForm = false;
			}
		}
	}
	return bSubmitForm;
}
function SetBorderStyle(fldFormField, fDefaultOrError){
	if (fDefaultOrError.toLowerCase() == "error") {
		borderstyle = "1px solid #000000";
		bgcolorstyle = "#bb7272";
	}
	else if (fDefaultOrError.toLowerCase() == "default") {
		borderstyle = "1px solid #969696";
		bgcolorstyle = "#FFFFFF";
	}
	
	fldFormField.style.border = borderstyle;
	fldFormField.style.background = bgcolorstyle;
}
// Used on textboxes used for storing dates takes from a calendar popup
function wc_stopchar(e,charlist){
	//charlist=='';
	if (window.event){
		var key = window.event.keyCode;
	}
	else if (e){
		var key = e.which;
	}
	else{
		return true;
	}

	var keychar = String.fromCharCode(key);
	if((charlist).indexOf(keychar) > -1 || key==8 || key==0){
		/*
		if (key==8) {
			e.target.value = "";
		}
		*/
		return true;
	}else{
		return false;
	}
}

// http://www.redips.net/javascript/date-validation/
function isDate(txtDate){  
  var objDate;  // date object initialized from the txtDate string  
  var mSeconds; // milliseconds from txtDate  
  
  // date length should be 10 characters - no more, no less  
  if (txtDate.length != 10) {
  	return false;  
  }
  
  // extract day, month and year from the txtDate string  
  // expected format is mm/dd/yyyy  
  // subtraction will cast variables to integer implicitly  
  var day   = txtDate.substring(0,2)  - 0;
  var month = txtDate.substring(3,5)  - 1; // because months in JS start with 0  
  var year  = txtDate.substring(6,10) - 0;  
  
  // third and sixth character should be /  
  if (txtDate.substring(2,3) != '/') {
  	return false;  
  }
  if (txtDate.substring(5,6) != '/') {
  	return false;  
  }
  
  // test year range  
  if (year < 999 || year > 3000) {
  	return false;  
  }
  
  // convert txtDate to the milliseconds  
  mSeconds = (new Date(year, month, day)).getTime();  
  
  // set the date object from milliseconds  
  objDate = new Date();  
  objDate.setTime(mSeconds);  
  
  // if there exists difference then date isn't valid  
  if (objDate.getFullYear() != year)  {
  	return false;  
  }
  if (objDate.getMonth() != month) {
  	return false;  
  }
  if (objDate.getDate() != day) {
  	return false;  
  }
  
  // otherwise return true  
  return true;  
}

function validatePhoneFax(sPhoneFax) {
	if(sPhoneFax==''){
		return false;
	}else{
		return true;
	}
}
function validateEmail(sEmail) {
	if(sEmail==''){
		return false;
	}else{
		return true;
	}
}

function validatePostalCode(sPostalCode) {
	var rePostalode = /^[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d$/;
	return (rePostalode.test(rePostalode) ? true : false);
}



function selectEvent(url){
	window.open('includes/surveys/event_search_form.php','Events','width=950,height=300,left=100,top=100,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
}

function selectSurvey(url){
	window.open('includes/surveys/survey_search_form.php','Events','width=950,height=300,left=100,top=100,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
}
