// JavaScript Document

// Swaps Email Value
var emailIndex = 0;
var theEmails = new Array();
theEmails[0] = "development";
theEmails[1] = "managed";
theEmails[2] = "technical";
theEmails[3] = "accounts";
theEmails[4] = "jobs";

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;
	phone = document.getElementById('contact_phone').value;
    hideAllErrors();
	error = false;
 
 
 
 
  
  if (name == "") 
  {
	   document.getElementById("nameError").style.display = "inline";
		document.getElementById('contact_name').className = "form_input_error";		
  		error = true;		
  }
  
if (validate_email() == false)
{
		document.getElementById("emailError").style.display = "inline";
		document.getElementById('contact_email').className = "form_input_error";
	    error = true;
}
 	
if (phone != "" && isNaN(Number(phone)) == true)
	  {
		document.getElementById("phoneError").style.display = "inline";
		document.getElementById('contact_phone').className = "form_input_error";
		error = true;			
	  }

 
  	if (error == true)
	{	
	return false;
	}
	else
	{
	document.getElementById('contact_us').submit();
	}

  	
  }
 
 
  function hideAllErrors() //Hides all previous errors from view
  {
	document.getElementById("nameError").style.display = "none";
	document.getElementById("emailError").style.display = "none";
	document.getElementById("phoneError").style.display = "none";
	document.getElementById('contact_name').className = "form_input";
	document.getElementById('contact_email').className = "form_input";
	document.getElementById('contact_phone').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) 
  {
  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 {return true;}
}
}
