
function popup(adr,nompop,larg,haut,res){window.open(adr,nompop,'width='+larg+',height='+haut+',scrollbars=1,toolbar=0,location=0,status=0,menubar=0,resizable='+res);}
function imgPopup(nomPop,img,fond,txt,css){
   imgPop = window.open("",nomPop,"scrollbars=yes,width=700,height=550");
   imgPop.document.write("<html>\n\n");
   imgPop.document.write("<head><title>Apercu d'image</title></head>\n\n");
   imgPop.document.write("<body bgcolor=\""+fond+"\">\n");
   imgPop.document.write("  <table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"100%\">\n");
   imgPop.document.write("    <tr><td align=\"center\"><img src=\"ressources/"+img+"\"></td></tr>\n");
   imgPop.document.write("    <tr><td align=\"center\">\n");
   imgPop.document.write("      <table border=\"0\" cellpadding=\"0\" cellspacing=\"2\">\n");
   imgPop.document.write("        <tr><td><span style=\""+css+"\">"+txt+"</span></td></tr>\n");
   imgPop.document.write("      </table>\n");
   imgPop.document.write("    </td></tr>\n");
   imgPop.document.write("  </table>\n");
   imgPop.document.write("</body>\n\n");
   imgPop.document.write("</html>");
}
function Makepop(url,my_l,my_h,my_s,my_status,my_resize,my_name){
	/* Version 1.0 */
	/* Creation Marc alias DMC */
	addPop=window.open(url,my_name,"width="+my_l+",height="+my_h+",scrollbars="+my_s+",toolbar=0,location=0,status="+my_status+",menubar=no,resizable="+my_resize);addPop.focus();
}
function affichePop(objlien){
	//Makepop(objlien.href,500,500,1,1,0,"infotext");
	return false;
}

/* ////////////////////////////////////////////// */
/*	Test un ensemble de caract šres                */
/*	@return true ou false                         */
/* ////////////////////////////////////////////// */
function defendu(string) {
if (!string){return false;}

   var iChars = "abcdefghijklmnopqrstuvwxyz@-_.~0123456789";
   for (var i = 0; i < string.length; i++) {
		if (iChars.indexOf(string.charAt(i).toLowerCase()) == -1){
			return false;
		}
   }
   return true;
} 
/* ////////////////////////////////////////////// */
/*	Test l'email                                  */
/*	@return false ou String                       */
/* ////////////////////////////////////////////// */
function is_Email(emails){
	var Regex = new RegExp("^[A-Za-z0-9]+([_\.\-][A-Za-z0-9]*)*@[A-Za-z0-9]+([_\.\-][A-Za-z0-9]{1,})*\.([A-Za-z]{2,}){1}$");
	return Regex.test(emails);
}



function testchamp(objformulaire,nom){
 if(objformulaire[nom].value!=""){
 	return true;
 }else{
 	return false;
 }
}

/* Utilisé par l'animation "Flash sur addonline" */
function setFlash(url,height,width,version,id){
	var resultat ="";
	resultat +='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+',0,0,0"  width="'+width+'" height="'+height+'" hspace="0" vspace="0" align="">';
	resultat +='<param name=movie value="'+url+'"/><param name=quality value=autohigh/>';
	resultat +='<param name=bgcolor value=#cccccc/>';
	resultat +='<param name="wmode" value="transparent"/>';
	resultat +='<embed src="'+url+'" wmode="transparent" width="'+width+'" height="'+height+'" hspace="0" vspace="0" align="" quality="autohigh" bgcolor="#cccccc"  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
	resultat +='</objet>';
	var monFlash = document.getElementById(id);
	if(monFlash != null){
		monFlash.innerHTML = resultat;
	}
}



function validerFormInscriptionNewsletter(formObject) {
	var form = $(this);
	var Regex = new RegExp("^[A-Za-z0-9]+([_\.\-][A-Za-z0-9]*)*@[A-Za-z0-9]+([_\.\-][A-Za-z0-9]{1,})*\.([A-Za-z]{2,}){1}$");

	if(Regex.test($F("dolist_form_Email"))) {
		return true;
	} else {
		alert("Veuillez entrer une adresse e-mail valide");
		return false;
	}
}

/*
 * DOM loaded
 * Toutes les actions nécessitants le chargement complet du DOM
 * devraient se trouver ici
 */
jQuery(function($) {
	
	// Lightbox
	$('a[rel*=lightbox]').lightBox();
	
	// Déplacement du 1er scrollable de la page d'accueil
	if(currentPageNum == 1) {
		$(".scrollable").eq(0).appendTo("#scrollable");
		if(!$.browser.msie) {
			$("#scrollable .next, #scrollable .prev").css({opacity: 0});
		} else {
			$("#scrollable .next, #scrollable .prev").hide();
		}
		$("#scrollable").hover(function() {
			if(!$.browser.msie) {
				$(this).find(".next, .prev").stop().dequeue().animate({opacity: 1, top: '165px'});
			} else {
				$(this).find(".next, .prev").show();
			}
		}, function() {
			if(!$.browser.msie) {
				$(this).find(".next, .prev").stop().dequeue().animate({opacity: 0, top: '175px'});
			} else {
				$(this).find(".next, .prev").hide();
			}
		});
	}
	
	// Scrollable
	$(".scrollable").scrollable({circular: true}).autoscroll().navigator({indexed: true});
	
	// Menu déroulant
	$("#menu_h > ul").prepend("<li><a href=\"./\"><span class=\"left\"><span class=\"home\"><span class=\"right\">Accueil</span></span></span></a></li>");
	$("#menu_h > ul > li").each(function(index, element) {
		if($(element).find("ul").size() > 0) {
			$(element).find("> a").addClass("hasChildren");
		}
	});
	$("#menu_h .niveau2 li:last-child").addClass("last");
	$("#menu_h a[href*='--" + currentPageNum + ".']").addClass("selected");
	$("#menu_h a[href*='--" + currentPageNum + ".']").parents("ul").prev().addClass("selected");
	if(currentPageNum == 1) {
		$("#menu_h > ul > li:first-child a").addClass("selected");
	}
	
	// Initialisation des champs de formulaire
	$("input[type='text']").fields();
	
	// Validation du formulaire de recherche
	$("#rechercheForm").submit(function() {
		if($("#txt_keywords").val() != "" && $("#txt_keywords").val() != $("#txt_keywords").data("defaultValue")) {
			return true;
		} else {
			alert("Veuillez préciser votre recherche.");
		}
		return false;
	});
	
	// Validation du formulaire d'inscription à la newsletter
	$("#AbonnementDOLIST").submit(function() {
		if($("#dolist_form_Email").val() != "" && $("#dolist_form_Email").val() != $("#dolist_form_Email").data("defaultValue") && is_Email($("#dolist_form_Email").val())) {
			return true;
		} else {
			alert("Veuillez préciser une adresse e-mail valide.");
		}
		return false;
	});
	
	// Validation du conseiller qui rappelle (étape 1)
	$("#contactRapideFooter .btnValider, #contactRapide .bttok2").click(function() {
		etape1($(this).parents("form"));
	});
	
	// Validation du conseiller qui rappelle (étape 2)
	$("#contactRapideFooter, #contactRapide").submit(function() {
		var captcha = $(this).find("input[name='captchaValue']");
		if(captcha.val()!== "" && captcha.val() != captcha.data("defaultValue")) {
			return true;
		} else {
			alert("Veuillez saisir les carractères de l'image dans le champ avant de valider");
		}
		return false;
	});
	
	function etape1(oForm) {
		var form = oForm;
		var nom = form.find("input[name='nom']");
		var prenom = form.find("input[name='prenom']");
		var mail = form.find("input[name='email']");
		var tel = form.find("input[name='tel']");
		var message = "";
		
		if(nom.val() == "" || nom.val() == nom.data("defaultValue")) {
			message += "- nom\n";
		}
		
		if(prenom.val() == "" || prenom.val() == prenom.data("defaultValue")) {
			message += "- prénom\n";
		}
		
		if(tel.val() == "" || tel.val() == tel.data("defaultValue")) {
			message += "- téléphone\n";
		}
		
		if(mail.val() == "" || mail.val() == mail.data("defaultValue") || !is_Email(mail.val())) {
			message += "- e-mail\n";
		}
		
		if(message == "") {
			form.find(".etape1").hide().end().find(".etape2").show();
		} else {
			alert("Veuillez corriger les informations suivantes :\n" + message);
		}
	}
	
	// Animation du retour haut de page
	$(".lien_h_page").click(function(event) {
		event.preventDefault();
		$("body, html").animate({scrollTop:0}, 200); 
	});
	
	// Références client
	$(".referenceClient a:first-child").lightBox();
	$(".referenceClient .legend").each(function(index, element) {
		$(this).prev().attr("title", $(this).text());
		$(this).html("<span>" + $(this).prev().find("img").attr("alt") + "</span>" + $(this).text());
		$(this).after("<div /><span />").nextAll().click(function() {
			$(this).parent().find("a:first-child").click();
		});
	});
	
	$(".referenceClient").hover(function() {
		$(this).find(".legend").stop().dequeue().animate({ bottom: 0, opacity: 0.6 }, 300);
		$(this).find("div").stop().dequeue().animate({ opacity: 1, filter: "" }, 300);
		$(this).find("span").stop().dequeue().animate({ top: 0, opacity: 0.75, filter: "" }, 300);
	}, function() {
		$(this).find(".legend").stop().dequeue().animate({ bottom: "-50px", opacity: 0 }, 300);
		$(this).find("div").stop().dequeue().animate({ opacity: 0 }, 300);
		$(this).find("span").stop().dequeue().animate({ top: "-50px", opacity: 0, filter: "" }, 300);
	});
	
})

/*
 * Plugin jQuery d'initilisation des valeurs par défaut sur les champs texte
 * Au clic, si le champ contient la valeur par défaut, celui-ci est vidé.
 * Quand on quitte le champ, si celui-ci est vide, on remet la valeur par défaut.
 */
jQuery.fn.fields = function() {
	this.each(function(index, element) {
		$(element).data("defaultValue", $(element).val());
		$(element).click(function() {
			if($(this).val() == $(this).data("defaultValue")) {
				$(this).val("");
			}
		}).blur(function() {
			if($(this).val() == "") {
				$(this).val($(this).data("defaultValue"));
			}
		});
	});
};
