// holds the ajax object
var adv_contact_ajax;
	
function sendMail()
{
	// show ajax loader
	formObj = document.getElementById("adv_contact_form");
	ajaxLoaderObj = document.getElementById("adv_contact_loader");
	formObj.style.display="none";
	ajaxLoaderObj.style.display="block";

	// init ajax object
	adv_contact_ajax = new sack();
	adv_contact_ajax.method="POST";
	adv_contact_ajax.onCompletion=_emailSent;
	adv_contact_ajax.requestFile = "/adv_contact.php";
	
	// get details
	adv_email = document.getElementById('adv_email').value;
	adv_bizName = document.getElementById('adv_bizName').value;
	adv_contact = document.getElementById('adv_contact').value;
	adv_phone = document.getElementById('adv_phone').value;
	
	// update mail parameters
	adv_contact_ajax.setVar('submit',"true");
	adv_contact_ajax.setVar('company_name',adv_bizName);
	adv_contact_ajax.setVar('contact_name',adv_contact);
	adv_contact_ajax.setVar('domain',"");
	adv_contact_ajax.setVar('phone',adv_phone);
	adv_contact_ajax.setVar('category',"");
	adv_contact_ajax.setVar('email',adv_email);
	
	// sent the mail
	adv_contact_ajax.runAJAX();
}
function _emailSent()
{
	// get response
	response = adv_contact_ajax.response;
	
	// show message and hide animation
	ajaxLoaderAnimation = document.getElementById("adv_contact_loader_animation");	
	ajaxLoaderMsg = document.getElementById("adv_contact_loader_msg");
	ajaxLoaderAnimation.style.display="none";
	ajaxLoaderMsg.style.display="block";
	
	if(response!="")
	{
		ajaxLoaderMsg.innerHTML=adv_contact_ajax.response;
		
	}else{
		
		ajaxLoaderError = document.getElementById("adv_contact_loader_error");
		ajaxLoaderError.style.display="none";
		ajaxLoaderMsg.innerHTML="<span class='success'>ההודעה נשלחה בהצלחה</span>";
		setTimeout("hideLoader(true)",5000);
	}
}
function hideLoader(initFields)
{
	// clear all fields
	if(initFields)
	{
		document.getElementById('adv_email').value="";
		document.getElementById('adv_bizName').value="";
		document.getElementById('adv_contact').value="";
		document.getElementById('adv_phone').value="";
	}
	
	// hide ajax loader
	formObj = document.getElementById("adv_contact_form");
	ajaxLoaderObj = document.getElementById("adv_contact_loader");
	ajaxLoaderObj.style.display="none";
	formObj.style.display="block";
	
	// hide message and show loader again
	ajaxLoaderAnimation = document.getElementById("adv_contact_loader_animation");	
	ajaxLoaderMsg = document.getElementById("adv_contact_loader_msg");
	ajaxLoaderError = document.getElementById("adv_contact_loader_error");
	
	ajaxLoaderMsg.style.display="none";
	ajaxLoaderAnimation.style.display="block";
	ajaxLoaderError.style.display="block";
}