function validateFields() 
{
    var posName = document.getElementById('posNameGestion');
    var posTel = document.getElementById('posTelGestion');
    var whiteSpace = /^[\s]+$/;
	
    if ( posName.value == '' || whiteSpace.test(posName.value) || posTel.value == '' || whiteSpace.test(posTel.value)  ) 
    {
		alert("Merci de fournir au moins votre nom et votre numero de telephone");
	}
    else 
    {
		sendPosEmail();
	}
}
function sendPosEmail () {
	var frmEl = document.getElementById('cFormGestion');
    var posName = document.getElementById('posNameGestion');
    var posEmail = document.getElementById('posEmailGestion');
    var posLoc = document.getElementById('posLocGestion');
    var localisation = document.getElementById('localisation');
    var tel = document.getElementById('posTelGestion');
    var civil = document.getElementsByName('civilGestion');
    var prenom = document.getElementById('prenomGestion');
    var adresse = document.getElementById('adresseGestion');
    var codepostal = document.getElementById('codepostalGestion');
    var ville = document.getElementById('villeGestion');
    
    
    var success = document.getElementById('emailSuccessGestion');
    
	var page = "scripts/xmlHttpRequest_gestion.php?contact_gestion=true&xml=true";
	
	showContactTimer(); // quickly begin the load bar
	success.style.display = 'none'; // hide the success bar (incase this is a multi-email
	
	
	// convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.
	var str1 = posName.value;
	str1 = str1.replace(/&/g,"**am**");
	str1 = str1.replace(/=/g,"**eq**");
	str1 = str1.replace(/\+/g,"**pl**");
	var str2 = posEmail.value;
	str2 = str2.replace(/&/g,"**am**");
	str2 = str2.replace(/=/g,"**eq**");
	str2 = str2.replace(/\+/g,"**pl**");
    
    
    var str3; 
    if(civil.item(0).checked)
        str3 = civil.item(0).value;
    if(civil.item(1).checked)
        str3 = civil.item(1).value;
    if(civil.item(2).checked)
        str3 = civil.item(2).value;
	str3 = str3.replace(/&/g,"**am**");
	str3 = str3.replace(/=/g,"**eq**");
	str3 = str3.replace(/\+/g,"**pl**");
    
	var str4 = posLoc.value;
	str4 = str4.replace(/&/g,"**am**");
	str4 = str4.replace(/=/g,"**eq**");
	str4 = str4.replace(/\+/g,"**pl**");
    var str5 = localisation.value;
	str5 = str5.replace(/&/g,"**am**");
	str5 = str5.replace(/=/g,"**eq**");
	str5 = str5.replace(/\+/g,"**pl**");
    var str6 = prenom.value;
	str6 = str6.replace(/&/g,"**am**");
	str6 = str6.replace(/=/g,"**eq**");
	str6 = str6.replace(/\+/g,"**pl**");
    var str7 = adresse.value;
	str7 = str7.replace(/&/g,"**am**");
	str7 = str7.replace(/=/g,"**eq**");
	str7 = str7.replace(/\+/g,"**pl**");
    var str8 = codepostal.value;
	str8 = str8.replace(/&/g,"**am**");
	str8 = str8.replace(/=/g,"**eq**");
	str8 = str8.replace(/\+/g,"**pl**");
    var str9 = ville.value;
	str9 = str9.replace(/&/g,"**am**");
	str9 = str9.replace(/=/g,"**eq**");
	str9 = str9.replace(/\+/g,"**pl**");
    var str10 = tel.value;
	str10 = str10.replace(/&/g,"**am**");
	str10 = str10.replace(/=/g,"**eq**");
	str10 = str10.replace(/\+/g,"**pl**");
    
	
	var stuff = "&posName="+str1+"&posEmail="+str2+"&civil="+str3+"&posLocGestion="+str4+"&localisation="+str5+"&prenom="+str6+"&adresse="+str7+
            "&codepostal="+str8+"&ville="+str9+"&tel="+str10;
	loadXMLPosDoc(page,stuff);
}
function showContactTimer () {
	var loader = document.getElementById('loadBarGestion');
	var frmEl = document.getElementById('cFormGestion');
	//frmEl.style.display = "none";
	$("#cFormGestion").fadeOut(200);
	//loader.style.display = 'block';
	$("#loadBarGestion").fadeIn(200);
	sentTimer = setTimeout("hideContactTimer()",3000);
}



function hideContactTimer () {
	var loader = document.getElementById('loadBarGestion');
	var success = document.getElementById('emailSuccessGestion');
	var fieldArea = document.getElementById('contactFormAreaGestion');
	var inputs = fieldArea.getElementsByTagName('input');
	var inputsLen = inputs.length;
	var tAreas = fieldArea.getElementsByTagName('textarea');
	var tAreasLen = tAreas.length;
    var frmEl = document.getElementById('cFormGestion');
	// Hide the load bar alas! Done Loading
	//loader.style.display = "none";
	$("#loadBarGestion").fadeOut(200);
	//success.style.display = "block";
	$("#emailSuccessGestion").fadeIn(200);
    //frmEl.reset();

	success.innerHTML = '<strong style="color:green;">'+grabPosXML("confirmation")+'</strong>';
	// Now Hijack the form elements
	for ( i=0;i<inputsLen;i++ ) {
		if ( inputs[i].getAttribute('type') == 'text' ) {
			inputs[i].value = '';
		}
	}
	for ( j=0;j<tAreasLen;j++ ) {
		tAreas[j].value = '';
	}
}

function ajaxContact() {
var frmEl = document.getElementById('cFormGestion');
addEvent(frmEl, 'submit', validateFields, false);
frmEl.onsubmit = function() { return false; }
}
addEvent(window, 'load',ajaxContact, false);
