// Function to open browser windows
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Disable POSTING of form data if information is missing (Contact Form)
function validateContactForm(){
  if(document.contactForm.your_name.value == ''){
    return false;
  }
  if(document.contactForm.your_tel.value == ''){
    return false;
  }
  return true;
}

// Function to validate format of email address
function isValidEmail(str) {
   if((str.indexOf(".") > 2) && (str.indexOf("@") > 0)){
    return true;
   } else{
    return false;
   }
}

// Validates fields on form
function validateFormAlpha(mainField,fieldName){
  var disableCheck = false;
  var valid = false;
  var mainField;

  if(mainField == 'id_number'){
    if(document.getElementById(mainField).value.length != 13){
      document.getElementById(fieldName).innerHTML = '&nbsp;<img src="images/error_icon.gif"> ID Number must be 13 numbers';
      disableCheck = true;
    }else{
      disableCheck = false;
    }
  }

  if(mainField == 'your_email'){
  	if(isValidEmail(document.getElementById(mainField).value) == false){
      document.getElementById(fieldName).innerHTML = '&nbsp;<img src="images/error_icon.gif"> Invalid e-mail address';
      disableCheck = true;
    }
    if(isValidEmail(mainField) == true){
      disableCheck = false;
    }    
  }

  if(disableCheck == false){
    
    if(document.getElementById(mainField).value == ''){
      valid = false;
    }else{
      valid = true;
    }
    
    if(valid == false){
      document.getElementById(fieldName).innerHTML = '&nbsp;<img src="images/error_icon.gif"> Required field';
    }  
    
    if(valid == true){
      document.getElementById(fieldName).innerHTML = '&nbsp;<img src="images/ok_icon.gif">';
    } 
    
  }

}
