/* NEEDED TO MAKE FORM RETURN FALSE WITH FIREFOX */
addEvent(window, "load", init);

function init()
{
	contactForm = document.getElementById("contactForm"); // initialize registration form and paste the line below into return false area of checkForm area
	//addEvent(registrationForm, "submit", correctSubmitHandler);
}

function correctSubmitHandler(e)
{
	if (e && e.preventDefault)
		e.preventDefault();
	return false;
}

function addEvent(obj, evType, fn)
{
	if (obj.addEventListener)
	{
   		obj.addEventListener(evType, fn, false);
   		return true;
	}
	else if (obj.attachEvent)
	{
   		var r = obj.attachEvent("on"+evType, fn);
   		return r;
 	}
 	else
 	{
   		return false;
 	}
}
/* NEEDED TO MAKE FORM RETURN FALSE WITH FIREFOX */

/* Contact Form */
function checkForm()
{
	var myForm = document.contactForm;
	var myMessage = document.contactForm.textmessage.value;
	if(myForm.name.value == "" || myForm.email.value == "" || myMessage == "")
	{
		if(myForm.name.value == "")
		{
			document.getElementById("nameWarning").style.display = "inline";
			myForm.name.focus();
		}
		else if(myForm.email.value == "" || !myForm.email.value.match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/))
		{
			document.getElementById("emailWarning").style.display = "inline";
			myForm.email.focus();
		}
		else if(myMessage == "")
		{
			document.getElementById("textmessageWarning").style.display = "inline";
			myForm.textmessage.focus();
		}
		return false;
	}
	else
	{
		return true;
	}
}

function checkName_onchange()
{
	var myForm = document.contactForm;
	if(myForm.name.value != "")
	{
		document.getElementById("nameWarning").style.display = "none";
	}
}

function checkEmail_onchange()
{
  var reEmail = new RegExp(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/);
	var emailValue = document.contactForm.email.value;
  if (!emailValue.match(reEmail))
	{
    document.getElementById("emailWarning").style.display = "inline";
		document.contactForm.email.focus();
  }
	if (emailValue.match(reEmail))
	{
    document.getElementById("emailWarning").style.display = "none";
  }
}

function checkTel_onchange()
{
  var rePhone = new RegExp(/\d{3}-\d{3}-\d{4}/);
	var phoneValue = document.contactForm.tel.value;
  if(!phoneValue.match(rePhone))
	{
		document.getElementById("phoneWarning").style.display = "inline";
		document.contactForm.tel.focus();
  }
	if(phoneValue.match(rePhone))
	{
		document.getElementById("phoneWarning").style.display = "none";
	}
}

function checkContact_onchange()
{
	var contact = document.contactForm.contact;
	if(contact.options[1].text || contact.options[2].text || contact.options[3].text)
	{
		document.getElementById("contactWarning").style.display = "none";
	}
}

