 /**
 * SameDayMarriage.com JavaScript Application Handler
 * Updated: January 20, 2007 
 * @author Skitsanos.com
 * @version 1.0
 */

	var containerContactForm;
	var backFromAction = "<br />Thank you, your message has been sent.&nbsp;<a href='javascript: recoverForm()'>Return back to form</a><hr />"
	
	/**
	 * Handles form submit
	 */
	function submitForm()
	{

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.getElementById("email").value;
   if(reg.test(address) == false) {
      alert('Invalid Email Address');
      return false;
   
}

		containerContactForm = document.getElementById("ResponseForm").innerHTML;
				
		var postData = "";
		
		var foundObjects = $("ContactForm").getElementsByTagName("input");
		
		for (i = 0; i < foundObjects.length; i++)
		{
			postData += foundObjects[i].id + "=" + foundObjects[i].value
			if (i < foundObjects.length-1)
			{
				postData += "&";
			}		
		}
		
		if (postData != "")
		{
			postData += "&";
		}
		
		foundObjects = document.getElementById("ContactForm").getElementsByTagName("textarea");
		
		for (i = 0; i < foundObjects.length; i++)
		{
			postData += foundObjects[i].id + "=" + foundObjects[i].value;
			if (i < foundObjects.length-1)
			{
				postData += "&";
			}			
		}
					
		Waml.Http.open("POST", "sendmail.php?" + (Math.random() * 2048), true, function(req){
			document.getElementById("ResponseForm").innerHTML = req.responseText + backFromAction;
		}, function(req){
			document.getElementById("ResponseForm").innerHTML = req.responseText  + backFromAction + containerContactForm;
		}, postData)
	}
	
	function recoverForm()
	{
		document.getElementById("ResponseForm").innerHTML = containerContactForm;
	}
