
// Customise those settings

// var seconds = 5;
// var url = "boo.php";

////////////////////////////////
//
// Refreshing the DIV
//
////////////////////////////////
var divMenuIdContent;
var divMenuId = "bandeauHaut";

function refreshdiv(url, divContenuId, menuId, strParam)
{
	// The XMLHttpRequest object
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
		}
	catch (e)
		{
			try	{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
				}
			catch (e)
				{
				try	{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
				catch (e)	
					{
					alert("Votre navigateur ne supporte pas AJAX.");
					return false;
					}
				}
		}


	// Timestamp for preventing IE caching the GET request
	fetch_unix_timestamp = function()
		{
			return parseInt(new Date().getTime().toString().substring(0, 10))
		}

	var timestamp = fetch_unix_timestamp();
	var nocacheurl = url+"?t="+timestamp+strParam;

	// The code...

	xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				document.getElementById(divContenuId).innerHTML=xmlHttp.responseText;
				if (menuId!=null) updateMenu(menuId);
			}
		}
	xmlHttp.open("GET",nocacheurl,true);
	xmlHttp.send(null);
}

function swap(oldNode, newNode){
    var parentNode = oldNode.parentNode;
    parentNode.insertBefore(newNode, oldNode);
    parentNode.removeChild(oldNode);
};


function updateMenu(menuId)
{	var oldElement;
	var newElement;
	document.getElementById(divMenuId).innerHTML = divMenuIdContent;
	oldElement = document.getElementById(menuId);
	newElement = document.createElement("label");
	newElement.setAttribute("class","ActiveMenu");
	newElement.innerHTML=oldElement.innerHTML;
	swap(oldElement,newElement);
}

/* SUBMIT FORM */
function getFormValues() {
	var poststr = 
				"&nom=" + encodeURI(document.getElementById("nom").value ) +
				"&prenom=" + encodeURI(document.getElementById("prenom").value ) +
				"&ville=" + encodeURI(document.getElementById("ville").value ) +
				"&courriel=" + encodeURI(document.getElementById("courriel").value ) +
				"&message=" + encodeURI(document.getElementById("message").value );
	return poststr; 
}

function envoyerMessage()
{
	try
	{
		var ErrorFound = "";
		var myForm = document.getElementById("myForm");
		var labels = myForm.getElementsByTagName( "label" );
		var myColor = labels[0].style.color; 
		for ( var i = 0; ( label = labels[i] ); i++ )
			{
				label.style.color=myColor;
				if (label.htmlFor!="")
					{
						if (document.getElementById(label.htmlFor).value=="")
							{
								label.style.color="red";
								ErrorFound = "yes";
							}
					}
			}
		
			if (ErrorFound=="yes")
			{
				alert("Veuillez saisir toutes les informations obligatoires !");
				return false; 
			}	
	
		ErrorFound="";
	
		document.getElementById("courriel").style.color="black";
		if (emailAddressValidate(document.getElementById("courriel").value)==false)
			{
				document.getElementById("courriel").style.color="red";
				ErrorFound +="Adresse Courriel invalide !\n";
			}
	
			if (ErrorFound!="")
			{ 
				alert(ErrorFound);
				return false;
			}
	
		document.getElementById("lblEnvoyer").innerHTML="Envoi en cours...";
		var myUrl ="contenu/ecrire.php"
		var str = getFormValues(); 
		refreshdiv(myUrl,"contenu",null,str);
		return true;
	}
	catch(myError)
	{
		alert("error");
	}
}