var garantie_panel="";
var minisite_panel="";
var contact_dialog="";
var tooltip_envoi_ok="";
var attributes = {
   width: { from: 100, to: 520, unit: "px",by:40 },
   height: { from: 250, to: 250, unit: "px",by:1 }
};
function GetXmlHttpObject() {
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
function add_class_pas_vu() {
les_textes=document.getElementsByTagName("div");
for(var i=0;i<les_textes.length;i++)
	{
		if ( les_textes[i].id.substr(0,6) == "texte_" )
			{
				YAHOO.util.Dom.addClass(les_textes[i].id,"pas_vu");
			}
	}
}

function init() {
add_class_pas_vu();
YAHOO.util.Dom.removeClass("texte_accueil","pas_vu");
var anim = new YAHOO.util.Anim("texte_accueil", attributes);
anim.animate();
cree_panel_garantie();
cree_panel_minisite();
cree_contact_dialog();
cree_tooltip_envoi_ok();
date_mise_a_jour();
}

function lien_accueil(e) {
YAHOO.util.Event.preventDefault(e); 
add_class_pas_vu();
YAHOO.util.Dom.removeClass("texte_accueil","pas_vu");

var anim = new YAHOO.util.Anim("texte_accueil", attributes);
anim.animate();
}
function lien_prestations(e) {
YAHOO.util.Event.preventDefault(e); 
add_class_pas_vu();
YAHOO.util.Dom.removeClass("texte_prestations","pas_vu");
var anim = new YAHOO.util.Anim("texte_prestations", attributes);
anim.animate();
}
function lien_realisations(e) {
YAHOO.util.Event.preventDefault(e); 
add_class_pas_vu();
YAHOO.util.Dom.removeClass("texte_realisations","pas_vu");
var anim = new YAHOO.util.Anim("texte_realisations", attributes);
anim.animate();
}
function lien_outils(e) {
YAHOO.util.Event.preventDefault(e); 
add_class_pas_vu();
YAHOO.util.Dom.removeClass("texte_outils","pas_vu");
var anim = new YAHOO.util.Anim("texte_outils", attributes);
anim.animate();
}
function lien_contact(e) {
YAHOO.util.Event.preventDefault(e); 
contact_dialog.show();
}
function voir_garanties(e) {
garantie_panel.show();
}
function voir_minisites(e) {
minisite_panel.show();
}
function cree_panel_garantie(){
var width_img="220";
var le_panel=document.getElementById("panel");
garantie_panel = new YAHOO.widget.Panel(
		"panel_garantie",
		{ fixedcenter:true,
		visible:false
		} 
	);
garantie_panel.setHeader("<div class='tl'></div><span>Gestion des garanties</span><div class='tr'></div>");
garantie_panel.setBody("\
<div style=\"overflow:auto\">\
<table id=\"table_img\">\
	<thead>\
		<tr>\
			<td>Login</td>\
			<td>Recherche</td>\
			<td>S&eacute;lection</td>\
			<td>Saisie</td>\
		</tr>\
	</thead>\
	<tbody>\
		<tr>\
			<td><img onclick=\"aff_img(this.src)\" width=\""+width_img+"\" class=\"img_panel\" src=\"images/garanties/1_login.png\" alt=\"Login\" Title=\"Login\"/></td>\
			<td><img onclick=\"aff_img(this.src)\" width=\""+width_img+"\" class=\"img_panel\" src=\"images/garanties/2_recherche.png\" alt=\"Recherche\" Title=\"Recherche\"/></td>\
			<td><img onclick=\"aff_img(this.src)\" width=\""+width_img+"\" class=\"img_panel\" src=\"images/garanties/3_selection.png\" alt=\"S&eacute;lection\" Title=\"S&eacute;lection\"/></td>\
			<td><img onclick=\"aff_img(this.src)\" width=\""+width_img+"\" class=\"img_panel\" src=\"images/garanties/4_saisie.png\" alt=\"Saisie\" Title=\"Saisie\"/></td>\
		</tr>\
	</tbody>\
</table>\
</div>\
");
garantie_panel.setFooter("\
	<div class=\"footer_panel\">\
		Cliquez sur une image pour l\'ouvrir dans une nouvelle fen&ecirc;tre\
	</div>\
");
garantie_panel.render(le_panel.id);
}
function cree_panel_minisite(){
var width_img="220";
var le_panel=document.getElementById("panel");
minisite_panel = new YAHOO.widget.Panel(
		"panel_minisite",
		{ fixedcenter:true,
		visible:false
		} 
	);
minisite_panel.setHeader("<div class='tl'></div><span>Gestion des minisites</span><div class='tr'></div>");
minisite_panel.setBody("\
<div style=\"overflow:auto\">\
<table id=\"table_img\">\
	<thead>\
		<tr>\
			<td>Cr&eacute;ation</td>\
			<td>Administration</td>\
			<td>R&eacute;sultat</td>\
		</tr>\
	</thead>\
	<tbody>\
		<tr>\
			<td><img onclick=\"aff_img(this.src)\" width=\""+width_img+"\" class=\"img_panel\" src=\"images/minisites/1_creation.png\" alt=\"Login\" Title=\"Login\"/></td>\
			<td><img onclick=\"aff_img(this.src)\" width=\""+width_img+"\" class=\"img_panel\" src=\"images/minisites/2_admin.png\" alt=\"Recherche\" Title=\"Recherche\"/></td>\
			<td><img onclick=\"aff_img(this.src)\" width=\""+width_img+"\" class=\"img_panel\" src=\"images/minisites/3_resultat.png\" alt=\"S&eacute;lection\" Title=\"S&eacute;lection\"/></td>\
		</tr>\
	</tbody>\
</table>\
</div>\
");
minisite_panel.setFooter("\
	<div class=\"footer_panel\">\
		Cliquez sur une image pour l\'ouvrir dans une nouvelle fen&ecirc;tre\
	</div>\
");
minisite_panel.render(le_panel.id);
}
function cree_contact_dialog() {
var handleSubmit=function() {
var data = this.getData();
var maforme=this.form;
var el="";
var erreur=false;
for(var i=0;i<maforme.elements.length;i++)
	{
		el=maforme.elements[i];
		YAHOO.util.Dom.removeClass(el,"erreur_saisie");
		switch(el.name)
			{
				case "societe":
					if ( el.value == "" )
						{
							YAHOO.util.Dom.addClass(el,"erreur_saisie");
							erreur=true;	
						}
				case "nom":
					if ( el.value == "" )
						{
							YAHOO.util.Dom.addClass(el,"erreur_saisie");
							erreur=true;	
						}
				case "email":
					if ( el.value == "" )
						{
							YAHOO.util.Dom.addClass(el,"erreur_saisie");
							erreur=true;	
						}
				case "telephone":
					if ( el.value == "" )
						{
							YAHOO.util.Dom.addClass(el,"erreur_saisie");
							erreur=true;	
						}
			}
	}
if ( erreur )
	{
		return;
	}
//this.submit();
var message="Société :"+data.societe+"\n"
	+"Adresse :"+data.adresse+"\n"
	+"C.P. :"+data.cp+"\n"
	+"Ville :"+data.ville+"\n"
	+"Nom :"+data.nom+"\n"
	+"Prénom :"+data.prenom+"\n"
	+"E-mail :"+data.email+"\n"
	+"Téléphone :"+data.telephone+"\n"
	+"Sujet :"+data.sujet+"\n"
var xmlHttp_mail=new GetXmlHttpObject();
var bug_IE=parseInt(Math.random()*99999999); // pour envoyer une requete différente à chaque fois
var url="envoi_mel.php?bug_IE="+bug_IE
	+"&message="+escape(message);
xmlHttp_mail.open("POST",url,false);
xmlHttp_mail.send(null);
if (xmlHttp_mail.readyState==4 || xmlHttp_mail.readyState=="complete")
	{ 
	if ( xmlHttp_mail.responseText != "ok" )
		{
			alert("L'envoi à échoué.\n"+xmlHttp_mail.responseText);
		}else
		{
			contact_dialog.hide();
			tooltip_envoi_ok.show();
			window.setTimeout("tooltip_envoi_ok.hide()",2000);
		}
	}
}
var handleCancel=function() {
contact_dialog.hide();
}
var handleSuccess=function(o) {
lister(o);
alert('OK');
contact_dialog.hide();
}
var handleFailure=function(o) {
lister(o);
	alert('L\'envoi a échoué : '+o.status);
}
contact_dialog = new YAHOO.widget.Dialog("contact_dialog", 
{ width : "300px",
  fixedcenter : true,
  visible : false, 
  constraintoviewport : true,
  buttons : [ 
		{ text:"Envoyer", handler:handleSubmit, isDefault:true },
		{ text:"Annuler", handler:handleCancel } ]
} );
contact_dialog.callback={success: handleSuccess,failure: handleFailure};
contact_dialog.render();
}
function cree_tooltip_envoi_ok() {
tooltip_envoi_ok = new YAHOO.widget.Tooltip("tooltip_envoi_ok",
	{ xy:[400,300], // positionnement
		width:"200px",
		zIndex:2000,
		text:"<div style=\"text-align:center;\">Votre mail a &eacute;t&eacute; transmis.<br>Merci</div>",
		effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5},
		{effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5}]
	} 
);
tooltip_envoi_ok.render();

}
function aff_img(img) {
window.open(img,"","menubar=no, status=no, scrollbars=no, menubar=no");
}
function date_mise_a_jour() {
var today=new Date();
var date_maj="01/"+(today.getMonth()+1)+"/"+today.getFullYear();
document.getElementById("date_mise_a_jour").innerHTML="Date de derni&egrave;re mise &agrave; jour : "+date_maj;
}
YAHOO.util.Event.addListener("lien_accueil", "click", lien_accueil);
YAHOO.util.Event.addListener("lien_prestations", "click", lien_prestations);
YAHOO.util.Event.addListener("lien_realisations", "click", lien_realisations);
YAHOO.util.Event.addListener("lien_outils", "click", lien_outils);
YAHOO.util.Event.addListener("lien_contact", "click", lien_contact);
YAHOO.util.Event.addListener("voir_garanties", "click", voir_garanties);
YAHOO.util.Event.addListener("voir_minisites", "click", voir_minisites);

YAHOO.util.Event.onDOMReady(init); 

