
$(document).ready(function(){
	$("#questionEnvoyer").click(function() {
		questionSend();
		return false;
	});
	$("#questionResetbut").click(function() {
		document.getElementById("questionForm").reset();
		return true;
	});

});

function questionSend(){
		
	var nom = document.getElementById("nom").value;
	var courriel = document.getElementById("courriel").value;
	var ville = document.getElementById("ville").value;
	var question = document.getElementById("question").value;
		
	if (nom && courriel && question){
			
		$body = 'Nom:         ' + nom + '\n'; 
		$body += 'Courriel:    ' + courriel + '\n'; 
		$body += 'Ville:       ' + ville + '\n';
		$body += '\n';
		$body += 'Question:\n' + question; 

		var myrequest= ajaxRequest();
		myrequest.onreadystatechange=function(){
			if (myrequest.readyState==4){
				if (myrequest.status==200 || window.location.href.indexOf("http")==-1){
					alert(myrequest.responseText);
				}
				else{
					alert("Une erreur s'est produite, veuillez reessayer.");
				}
			}
		}
		$body = encodeURIComponent($body);
		myrequest.open("POST", getTemplate() + "/sendmail.php", true);
		myrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		myrequest.send("text=" + $body);
		
	}else{
		alert("Vous devez entrer des informations valides dans les champs.");
	}
};

function ajaxRequest() {
   var AJAX = null;                                 // Initialize the AJAX variable.
   
   if (window.XMLHttpRequest) {                     // Does this browser have an XMLHttpRequest object?
      AJAX=new XMLHttpRequest();                    // Yes -- initialize it.
   } else {                                         // No, try to initialize it IE style
      AJAX=new ActiveXObject("Microsoft.XMLHTTP");  // Wheee, ActiveX, how do we format c: again?
   }      // End setup Ajax.
   
   if (AJAX==null) {                                // If we couldn't initialize Ajax...
      alert("Your browser doesn't support AJAX.");  // Sorry msg.                                               
      return false;                                 // Return false, couldn't set up ajax
   }
   return AJAX;
}

