// JavaScript Document

// Swaps Email Value
var emailIndex = 0;
var theEmails = new Array();
theEmails[0] = "manager";
theEmails[1] = "ops";
theEmails[2] = "support";

function switcher(method) {
   if(method == "next") {
      emailIndex++;
	  if(emailIndex>=theEmails.length) 
	  {
		  emailIndex = 0;
	  }	 
   }
   if(method == "prev") {
      emailIndex--;
	   if(emailIndex < 0) 
	   {
		   emailIndex = theEmails.length - 1;
	   }
   }   		
   document.getElementById('contact_sendto').value = theEmails[emailIndex]; 
}

//checks form to make sure all data i8s correct.
function checkForm() {
	name = document.getElementById('contact_name').value;
    email = document.getElementById('contact_email').value;
	
 
 
  if (name == "" && email == "") 
  {
  		hideAllErrors();
		document.getElementById("nameError").style.display = "inline";
		document.getElementById("emailError").style.display = "inline";
		document.getElementById('contact_name').className = "form_input_error"
		document.getElementById('contact_email').className = "form_input_error"
		document.getElementById("contact_name").select();
		document.getElementById("contact_name").focus();
  		return false;
  }
  else if (name == "" && email != "") 
  {
		hideAllErrors();
		document.getElementById("nameError").style.display = "inline";
		document.getElementById('contact_name').className = "form_input_error"
		document.getElementById("contact_name").select();
		document.getElementById("contact_name").focus();
		
		if (validate_email() == false)
		{
			document.getElementById("emailError").style.display = "inline";
			document.getElementById('contact_email').className = "form_input_error"
			return false;
		}
		else
		{
			return false;
		}
  }
  else if (email == "") 
  {
		hideAllErrors();
		document.getElementById("emailError").style.display = "inline";
		document.getElementById('contact_email').className = "form_input_error"
		document.getElementById("contact_email").select();
		document.getElementById("contact_email").focus();
		return false;
  } 
  else 
  { 
  	if (validate_email() == false)
	{
	return false;
	}
  } 
  return true;
  }
 
  function hideAllErrors() //Hides all previous errors from view
  {
	document.getElementById("nameError").style.display = "none"
	document.getElementById("emailError").style.display = "none"
	document.getElementById('contact_name').className = "form_input"
	document.getElementById('contact_email').className = "form_input"
  }
  
  function validate_email() //Checks to validate the e-mail. Must contain @ and .
{
with (document.getElementById("contact_email"))
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {
  hideAllErrors()
  document.getElementById("emailError").style.display = "inline";
  document.getElementById('contact_email').className = "form_input_error"
document.getElementById("contact_email").select();
document.getElementById("contact_email").focus();
  return false;}
else {document.getElementById('contact_us').submit();}
}
}