var contact_manager = {};
var sendContactUrl = "contact_insert.php";

function AJAX_ContactMgr() {
	//logEvent("companyMgr", "info");
}
AJAX_ContactMgr.prototype.setTimeOut = function() {
	logEvent("Contact setTimeOut", "time");
	/* use a closure so eventSend() executes in the correct scope */
	var thisC = this;
	//thisC.//logEvent("time out");
	/* Look for changes in the form data every one second. */
	this.timeout = setTimeout(function() {
		thisC.contactSend();
	}, 10);
};

AJAX_ContactMgr.prototype.contactSend = function() {
  /* Update the data stored in YAHOO.util.Connect._sFormData
     to be the current from data*/
	var Dom = YAHOO.util.Dom; 
	this.form = Dom.get('contact_form');
	var the_saved = YAHOO.util.Dom.get("contact_save_status");
	the_saved.innerHTML = "<em>Sending...</em>";
	logEvent("contactSend - contact_send.js", "time");
	var first_name = Dom.get("first_name");
	if (first_name.value=="") {
		alert("Your first name is required");
		the_saved.innerHTML = "<em>Your first name is required</em>";
		return;
	}
	var last_name = Dom.get("last_name");
	if (last_name.value=="") {
		alert("Your last name is required");
		the_saved.innerHTML = "<em>Your last name is required</em>";
		return;
	}
	var company = Dom.get("company");
	if (company.value=="") {
		alert("Your Company name is required");
		the_saved.innerHTML = "<em>Your Company name is required</em>";
		return;
	}
	var email = Dom.get("email");
	if (email.value=="") {
		alert("Your email address is required");
		the_saved.innerHTML = "<em>Your email address is required</em>";
		return;
	}
	var inquiry = Dom.get("inquiry");
	
	this.sentData = "first_name=" + first_name.value;
	this.sentData += "&last_name=" + last_name.value;
	this.sentData += "&company=" + company.value;
	this.sentData += "&email=" + email.value;
	this.sentData += "&inquiry=" + inquiry.value;
  	/* make the initial cache of the form data */
	
	//YAHOO.util.Connect.setForm(this.form);
	
	//this.sentData = YAHOO.util.Connect._sFormData;
	
	if (this.sentData!='') {	
		logEvent(sendContactUrl + '?' + this.sentData);
		
		var the_button = Dom.get("contact_save_button");
		the_button.disabled = true;
		var request = YAHOO.util.Connect.asyncRequest('POST', sendContactUrl,
		   {success: function(o){
				this.cache = this.sentData;
				response = o.responseText;
				//mark it saved
				var the_saved = YAHOO.util.Dom.get("contact_save_status");
				the_saved.innerHTML = response + " :: Thank you for sending us a comment";
				var the_button = Dom.get("contact_save_button");
				the_button.disabled = false;
				setTimeout("hideContactPage()", 4000);
			},
		   after: function(){
			   //
			},
		   scope: this}, this.sentData);
		
	}
};
