$(document).ready(function() {
  
   pTimer=setTimeout("initialiser()",1000);
      
});


function initialiser ()
{
	$("#news_sep").hide();
	$("#news_placement").show();
  generer_les_ombres(nbOmbres)
	clearTimeout(pTimer);
}

function EcrireCookie(nom, valeur)
{

var argv=EcrireCookie.arguments;
var argc=EcrireCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=nom+"="+escape(valeur)+
((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");

}

function getCookieVal(offset)
{

var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1) endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr)); 
}
function LireCookie(nom)
{

var arg=nom+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen)
{

var j=i+alen;
if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;


}
return null; 
}

function enregistrer_compte()
{
date=new Date;
date.setMonth(date.getMonth()+12);

identifiant = document.forms[0].identifiant.value;
motdepasse = document.forms[0].motdepasse.value


EcrireCookie("identifiant", identifiant, date);
EcrireCookie("motdepasse", motdepasse, date);

document.forms[0].submit()
}

function charger_compte()
{
	identifiant=LireCookie("identifiant");
	motdepasse=LireCookie("motdepasse");
	
	if(identifiant) document.forms[0].identifiant.value=identifiant;
	if(motdepasse) document.forms[0].motdepasse.value=motdepasse;
}

function generer_les_ombres(nb)
{
	for(idx=1; idx <= nb; idx++)
		generer_ombre(idx);	
}

function generer_ombre(num)
{
	
	var imgWidth=$("#labelImage_"+num).width()+(10*2);
	var imgHeight=$("#labelImage_"+num).height();		

	$("#zoneOmbre_"+num).width(imgWidth);
}

function loadAccessMap()
{
	
	displayAccessMap = document.getElementById('agencies').value;
	
	if(displayAccessMap != 0)
	{				
		chaineHTML = '<iframe class="labelImage" id="labelImage_1" width="740" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+googleMapDatas[displayAccessMap]+'"></iframe>';
		document.getElementById('zoneOmbre_1').innerHTML = chaineHTML;	
		document.getElementById('zoneOmbre_1').style.display = "block"; 
	}
}

function displayContact(id)
{
	$(".contactInsert").css("display", "none");	
	calqueToDisplay = "#calqueContact_"+id
	$(calqueToDisplay).css("display", "block");
}

function hideContact()
{
	$(".contactInsert").css("display", "none");		
}

var effet = 200;

function contactEffect(idDiv)
{		
	effet = effet - 15;	
	if (effet > 0)
	{
		objTimer = setTimeout("contactEffect("+idDiv+")", effet);
		if(effet%2) displayContact(idDiv)
		else hideContact();
	}
	else
	{
		effet = 200;
		displayContact(idDiv);
		clearTimeout(objTimer);				
	}
}

function envoyer_courriel()
{
	
	if( ($("#societe").val() == '') || ($("#nom_prenom").val() == '') || ($("#courriel").val() == '') || ($("#telephone").val() == '') || ($("#message").val() == '') )
		alert("Merci de remplir tous les champs");
	else
	{
		$.ajax({
			type: "POST",
			url: "../send_email.ajax.php",
			data: ({societe : $("#societe").val(), nom_prenom : $("#nom_prenom").val(), courriel : $("#courriel").val(), telephone : $("#telephone").val(), message : $("#message").val() }),
			success: function(ajaxReturn){
				if (ajaxReturn == 1)
				{
					 $("#societe").val('');
					 $("#societe").attr("disabled", true);
					 
					 $("#nom_prenom").val('');
					 $("#nom_prenom").attr("disabled", true);				 
					 
					 $("#courriel").val('');
					 $("#courriel").attr("disabled", true);
					 
					 $("#telephone").val('');
					 $("#telephone").attr("disabled", true);
					 
					 $("#message").val('');
					 $("#message").attr("disabled", true);
					 
					alert("Votre courriel a été envoyé à la société ALMA");
				}
				else alert("Erreur lors de l'envoi de votre courriel: "+ajaxReturn);
  		}
 		});
	}
}