// JavaScript Document
// This was written for the Visuale website by James Parenti
window.onload = initForm;

function initForm() {
	getForm();
}

/* -------------------GRAB theForm.html --------------------*/

function getForm() {
		var url = "theForm.html";
		new Ajax.Request(url,
		{
			method:'get',
			onSuccess:function(transport) {
				var destinationId = document.getElementById("formBox");
				destinationId.innerHTML = transport.responseText;
			}
		});
}


/* -----------------Process Submission --------------------*/
 // This processes the form action itself.
   function doForm(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
           if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
		 if(obj.childNodes[i].tagName == "TEXTAREA") {
		    getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		 }
         
      }
		var urlObject = "thankyou.php" + getstr;
		new Ajax.Request(urlObject,
		{
			method:'get',
			onSuccess:function(transport) {
				var destinationId = document.getElementById("formBox");
				destinationId.innerHTML = "<div class=\"quickThankYou\">Thank You.</div>";
				setTimeout("getForm()",2000);
			}
        }); 

}	

