/*
 ** accueil.js
 **/
var boo_flash = true, prop_winSize;

jQuery(function($) {
    if (testBrowser())	initSWF(boo_flash);

	
	// on load
	$(window).load(function( ){
        recherche_init(1);
    });
    
	// circulaire
	// on resize
	$(window).resize(function() {
	   
        recherche_init(0);
    
		if ($("#circulaire_1").css("display") == "block") centerWinPop($("#circulaire_1"));
		if ($("#circulaire_2").css("display") == "block") centerWinPop($("#circulaire_2"));
	});

	// rollover btn circulaire
	$("div.circulaire img.prn_img_btn").hover(function(){
	    $(this).attr("src", $(this).attr("src").replace("_n.png", "_o.png") );    
	},function(){
	    $(this).attr("src", $(this).attr("src").replace("_o.png", "_n.png") );
	});
	$("div.circulaire img.tele_pdf_btn").hover(function(){
	    $(this).attr("src", $(this).attr("src").replace("_n.png", "_o.png") );    
	},function(){
	    $(this).attr("src", $(this).attr("src").replace("_o.png", "_n.png") );
	});



	
	// news letter form
	//
	if ((getCookie('coupon_acc') == 1)) 
	{
		$("div#form_nl").remove(); // byebye
		// return;
	} 
	else 
	{
		var set_position = $("#flash").position();
		set_position.top += 225;
		set_position.left += 464;
		$("#form_nl").css(set_position);
		$("#form_nl").show();

		// event
		//	
		$("td.fermer img").bind("click", function() {
			$("iframe[name='bentechsoftmail_rez']").eq(0).remove(); // byebye
				$("div#form_nl").fadeOut("slow");
        });

        // les return !
		$("input.submit").bind("click", function() {
			if (!val_non_vide("nom"))
				return;
			
			if (!val_non_vide("prenom"))
				return;

			var str_name = $("#prenom").attr("value");
			str_name += " ";
			str_name += $("#nom").attr("value");

			$("input[name='name']").attr("value", str_name);

			if (!val_non_vide("email_1"))
				return;
			if (!val_non_vide("email_2"))
				return;

			if (!val_egal("email_1", "email_2"))
				return;

			if (!val_courriel("email_1")) {
				$("#email_1").attr("value", " *** format erroné *** ");
				val_flash("email_1");
				// $("#email_2").attr("value","");
				return;
			}

			// si on rendu ici c'est q tt est bo ..
            //
            $("#form_nl form").submit();

            $("#benform").fadeOut("slow", function() {
                $("#confirmation").fadeIn("slow");
                setCookie('coupon_acc', 1);
            });

        });

        
        
		$("#deactiveCoupon span").bind("click", function() {
			$("iframe[name='bentechsoftmail_rez']").eq(0).remove(); // byebye
				$("div#form_nl").fadeOut("slow");
				createCookieForEver('coupon_acc', 1);
				// coupon de la page accueil ( ne plus afficher SVP = 1 )
			});

		$(window).resize(function(e){
			centerWinPop($("#circulaires"));
		});
 
	} // if not cookie
 
    
});


function centerWinPop(obj) {
	var prop_winpop = {
		"width" : obj.width(),
		"height" : obj.height()
	}
	var prop_winSize = {
		"width" : $(window).width(),
		"height" : $(window).height()
	}
	obj.css("top", Math.round(prop_winSize.height / 2 - prop_winpop.height / 2));
	obj.css("left", Math.round(prop_winSize.width / 2 - prop_winpop.width / 2));
}
function openPub(id) {
    
	centerWinPop($("#circulaire_"+id));
	$("#circulaire_"+id).show("fast");
}
function closePub(id) {
	$("#circulaire_"+id).hide("fast");
}
function openPdf(id) {
	var str_url = $( "#circulaire_" +id+ " div.pub img").attr("src");
    var str_base_name = str_url.substring(0,str_url.indexOf("."));
	window.open(  str_base_name+".pdf");
}


function ff() {

	$("#benform").hide();
}
function tt() {
	$("#confirmation").hide();
	$("#benform").show();
	rmCookie('coupon_acc');
	window.location = window.location; // relaod
}