// JavaScript Document

function printconfig(id){
	if(exist(id)) $(id).printElement();
	else alert('Erreur d\'impression');
}

function police(size){
	var options = { path: '/', expires: 10 };
	if(size=='big') { 
		$("body").css("font-size","1em");
		$.cookie('police', 'big', options);
	} else {
		$("body").css("font-size","0.7em");	
		$.cookie('police', 'min', options);
	}
}

function slide_goto(uid){
	$("#slider").slider("value", uid); 
	ajust_img(uid);
	ajust_prx(uid+1);
	slide_setxt(uid);	
}

function slide_setxt(uid){
	if(uid>0) plur = "s"; else plur = "";
	$("#slider a").html("<span>"+(uid+1)+" part"+plur+"</span>");
}

function ajust_img(i) {
	$(".img_empty").each(function(){
		if($(this).attr("rel")<=i) $(this).attr("src","/images/slide2_20.png");
		else $(this).attr("src","/images/slide_20.png");
	});
}

function ajust_prx(pas){
	var borne;
	var liste = Array(21,22,23,24,25,26); // serveur on-deo : sous options

	for ( var i in liste)
	{
		id = liste[i];
		var qtt = dlg[id][3];
		pas2 = pas - qtt;
		if(pas2 >=0) borne = $("#slide_maxqtt").val();
		else borne =  $("#slide_minqtt").val();			
		modlg(id,borne,pas2);

	}	
}


$(function() {


	if(exist(".visuel_promo")) {
		$(".visuel_promo").click(function(){
			window.location.href="/page/offre_speciale/domaine_mail.php";
		});
	}


// TAILLE DE LA POLICE
	if($.cookie("police")!="null"){
		if($.cookie("police") == "big") $("body").css("font-size","1em");
		else $("body").css("font-size","0.7em");
	}

// CHECK ALL DOMAINE
	$('#checkall').click(function () {
		$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
		if(this.checked==true) $("#lab_checkall").text('Tout décocher');  else $("#lab_checkall").text('Tout cocher');
	});
	$('#checkall_hist').click(function () {
		$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
		if(this.checked==true) $("#lab_checkall_hist").text('Tout décocher');  else $("#lab_checkall_hist").text('Tout cocher');
	});
	$('.checkall_ext').click(function () {
		//checktout("#checkall_ext","#formbox","#lab_checkall_ext");
		$(this).parents('div:eq(0)').find(':checkbox').attr('checked', this.checked);
		if(this.checked==true) $("#lab_checkall_ext").text('Tout décocher');  else $("#lab_checkall_ext").text('Tout cocher');
	});
	
	$("#recherche_rap_ndd #nomdom").click(function (){ 
		$(this).val(''); 
	});
	
	$("#Formsrcdomaine #nomdom").click(function (){ 
		if($(this).val()=='nom_de_domaine...'){
          $(this).val('');   
        }
	});                                                  
	
	$("#message").click(function (){ 
		$(this).val(''); 
	});
	
///// TABS /////
	if(exist("#tabs"))	var $tabs = $("#tabs").tabs();
	if(exist(".tabis")) var $tabs = $(".tabis").tabs();
	
	$("#tabs").css("visibility","visible");	

	// GESTION TAB SUIVANT 
	$(".startconf").click(function(){
		var selected = 0;
		var idsel = Number($(this).attr('id')); 
		if(idsel>0)	selected = idsel;							 // ALLER A ... ID DU LIEN
		else		selected = $tabs.tabs('option', 'selected'); // TAB SUIVANT
		var sel = selected+1;
		$tabs.tabs('select',sel); 
		return false;
	});

	
//// TOOLTIP /////
	$('a.tooltip[href][title]').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		style: { 
		 width: 290,
		  padding: 3,
		  background: '#e4e4e4',
		  color: '#272727',
		  textAlign: 'left' ,
		  border: {
			 width: 1,
			 radius: 3,
			 color: '#272727'
		  },
		 tip: 'topMiddle'
	   },
		position: {
		   //target: 'mouse',
		   adjust: { screen: true }
		}
	});
	
	// imression panier
	var print_css2 = '<link rel="stylesheet" type="text/css" media="print" href="/css/print_panier.css" /><link rel="stylesheet" type="text/css" media="screen" href="/css/screen_panier.css" />';
	var cbox = false;
		if($(".print_kart").length!=0) {
			var print_css2 = '<link rel="stylesheet" type="text/css" media="print" href="/css/print_panier.css" /><link rel="stylesheet" type="text/css" media="screen" href="/css/screen_panier.css" />';
			$(".print_kart").click(function(){
			//	if(confirm("Souhaitez vous imprimer ce panier ?")){
					cbox = true;
					$("#content_css").prepend(print_css2);
					$("#content_kart").show();
					$(".legal2").show();
					$("img.display_screen").hide();
					//$.fn.colorbox({inline:true, href:"#contenu_kart", open:true, width:750, height:'90%'});
					//$().bind('cbox_complete', function(){
						var nbech = $("#echeancier2").length;
						if(nbech==0) {
							var echeancier = $(".echeancier h4").text();							   
							$("#contenu_kart").append('<div id="echeancier2">'+echeancier+'</div>');	
							if(cbox===true) $('#contenu_kart').printElement();
							cbox=false;
							//window.location.href="";
						}
					//});
					/*$().bind('cbox_closed', function(){
						$("#echeancier2").remove();	
						$("#content_kart").hide();						   
						$(".legal2").hide();
						$("img.display_screen").show();
						$("#content_css").html('');
					});*/
			//	}
			});
		}

	
//// EFFECT ////
	function callback(){
			setTimeout(function(){
				$("#effect").removeAttr('style').fadeOut();
			}, 1000);
		};	
		
///// HIGHTLIGHT /////
	if(exist("#effect")) {
		var options = {};
		$("#effect").effect("highlight",options,2000,callback);
	}
	
////// SLIDER ////////
	var largeur = $("#slider").width();
	var mini = $("#slide_minqtt").val();
	var maxi = $("#slide_maxqtt").val();
	var dif = maxi - mini+1;
	var img_width = 20;	var img_height = 20;
	var ecart = largeur/(dif-1);
	var pos = 0;
	for(var i=0;i<dif; i++) {
		pos = ecart*i;
		if(i==0) $("#step").append('<img src="/images/slide2_20.png" class="img_empty" rel="'+i+'" style="left:0;" onclick="slide_goto('+i+');" />');
		else $("#step").append('<img src="/images/slide_20.png" class="img_empty" rel="'+i+'" style="left:'+pos+'px;"  onclick="slide_goto('+i+');"/>');
	}

	$(".img_empty").each(function(){
		$(this).attr("width",img_width);
		$(this).attr("height",img_height);
	});

  	var paliermin = mini-1;
	var paliermax = maxi-1;
	var plur = "";
    $("#slider").slider({
							animate:true,
							min:paliermin,
							max:paliermax,
							slide: function(event, ui) {
								var pas;
								var interval;
								var postep;
								pas = ui.value;
								interval = 600/paliermax*pas;
								postep = interval-600;
								slide_setxt(pas);
								ajust_prx(pas+1);	
								ajust_img(pas);
							}
						});

});



