
var base_name_navigation='';
var base_img_dir_navig = 'images/';

//var base_name_navigation='catalog/';
//var base_img_dir_navig = 'catalog/images/';

//window.document.oncontextmenu = copyRight;

function copyRight(myevent)
{
  myevent = myevent? myevent:window.event
  myObj =  myevent.srcElement ? myevent.srcElement : myevent.target

  //alert(myevent.button);
  
  if (myObj.tagName == 'IMG' && myevent.button > 1 &&
      myObj.width > 50 && myObj.height > 50)
  {
	 return false;
  }
}



function waitNavig( div ){
	$('#'+div).html('<br/><br/><center><img src="'+base_img_dir_navig+'ajax-loader.gif" border="0" align="center" /></center></br/><br/>');
}

function unwaitNavigNavig( div ){
	$('#'+div).html('');
}


 function ShowHide(id) {

  var elt = document.getElementById(id); if (!elt) return;

  if(elt.className == "div_hidden" )
	elt.className = "";
  else
	elt.className = "div_hidden";

 }
 
// function qui permet d'ajouter le site au favoris
function favoris() {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{ window.sidebar.addPanel("ClicAnimaux.com","http://www.clicanimaux.com",""); }
else { window.external.AddFavorite("http://www.clicanimaux.com","ClicAnimaux.com"); } }

function cart_delete( ligne, id ){
	if(confirm("Etes-vous sûr de vouloir supprimer cet article ? ")){
		$.ajax({
		   type: "POST",
		   url: base_name_navigation+"ajax.php",
		   data: "action=100&p_id="+id,
		   success: function(data){
			var response =  data.substring(1, data.length);
			switch(response){
				case 'redirect':
					window.location='shopping_cart.php';
				break;
				default:
					// Si on ne raffraichit pas la page, on update le panier
					$('#pro_lgn_'+ligne).fadeOut("slow");
					$('#pro_lgn_'+ligne).remove();
					update_panier_boxes();
					update_sub_total();
				break;

			}
			//alert("ok");
			//$('#pro_lgn_'+id).remove();
		   }
		 });
	}
}

function change_qte( id,  qte, prix, ligne ){ //alert(qte+" ->"+prix);
	if(qte == ""){
	
	}
	else if(isNaN(qte) ) {
		alert("Veuillez saisir une quantité correcte.");
		return false;
	} 
	else {
		var qte_dep = $('#qte_avant_modif_'+ligne).val();
		
		if(qte_dep != qte){
			if(qte<=0){
				cart_delete( ligne, id );				
			} else {
				qte = Math.ceil(qte);
				
				$.ajax({
				   type: "POST",
				   url: base_name_navigation+"ajax.php",
				   data: "action=103&p_prix="+prix+"&qte="+qte+"&p_id="+id+"&ligne="+ligne,
				   success: function(data){
					var response =  data.substring(1, data.length); 
						switch(response){
							case 'erreur stock':
								$('#labNameStockWarning'+ligne).html(" <span style=\"color:#cc0033; font-weight:bold;\">***</span>");
								$('#stockWarning').html("Les articles marqués*** ne sont pas en stock dans la quantité désirée.<br/>Veuillez ajuster la quantité des produits marqués (***), Merci");
								$('#qte_avant_modif_'+ligne).val(qte);
								$('#qte_modif_'+ligne).val(qte);
							break;
							default:
								$('#labNameStockWarning'+ligne).html("");
								$('#stockWarning').html("");
								$('#qte_avant_modif_'+ligne).val(qte)
								$('#qte_modif_'+ligne).val(qte)
								$('#final_price_lgn'+ligne).html( data );
								update_panier_boxes();
								update_sub_total();
							break;
						}
					}
				 });
			}
		}
	}
}

function setInformationsProduits(id, type_customize){
	if(type_customize == 1){
		var date_jj = $('#date_jj').val();
		var date_mm = $('#date_mm').val();
		var date_aaaa = $('#date_aaaa').val();
		var date_actu = new Date();
		var date_aaaa_actu = date_actu.getFullYear();
		
		if(date_jj == "" || isNaN(date_jj) || date_jj <= 0 || date_jj > 31){
			alert("La date du jour est incorrecte.");
			return false;
		}
		if(date_mm == "" || isNaN(date_mm) || date_mm <= 0 || date_mm > 12){
			alert("La date du mois est incorrecte.");
			return false;
		}
	  
	   
	   if(date_aaaa == "" || isNaN(date_aaaa) || date_aaaa < 1880 || date_aaaa > date_aaaa_actu){
		  alert("La date de l'année est incorrecte.");
		  return false;
	   }

		
		
		
		$.ajax({
		   type: "POST",
		   url: base_name_navigation+"ajax.php",
		   data: "action=701&products_id="+id+"&value_jj="+date_jj+"&value_mm="+date_mm+"&value_aaaa="+date_aaaa,
		   success: function(data){
			window.location.href='product_info.php?products_id='+id;
		   }
		});
		
	}
	else if(type_customize == 2){
	
		var products_options = $('#products_options').val();
		var re =/ /g;
		var tmp = products_options.replace(re,"");
		tmp.replace(' ','');
		if(tmp == ''){
		  alert("Veuillez saisir une chaine de caractères valide.");
		  return false;
		}
		if(products_options.length > 155){
		  alert("Les informations saisies ne doivent pas dépasser 155 caractères.");
		  return false;
		}
		
		$.ajax({
		   type: "POST",
		   url: base_name_navigation+"ajax.php",
		   data: "action=700&products_id="+id+"&value="+products_options,
		   success: function(data){
			window.location.href='product_info.php?products_id='+id;
		   }
		});
		
	}

}


function addPanier( id, qte, prix, ligne, attribute, comments, div_depart, type_customize){ 

	if(qte == ""){
	
	}
	else if(isNaN(qte) && qte != "add" ) {
		alert("La quantité n'est pas correcte.");
		return false;
	} 
	else {
		
			
			
			if(qte<=0){
				cart_delete( ligne, id );				
			} else {
			   
			   if(qte >1){
				   if(qte != "add")
						qte = Math.ceil(qte);
				}
				
				$.ajax({
				   type: "POST",
				   url: base_name_navigation+"ajax.php",
				   data: "action=103&p_prix="+prix+"&qte="+qte+"&p_id="+id+"&ligne="+ligne+"&attribute="+attribute,
				   success: function(data){
					var response =  data.substring(1, data.length); 
					//alert(data.substring(1, 14));
					if( data.substring(1, 15) == "erreur don min"){
						alert("Le don minimum pour cette association est de "+data.substring(17, data.length)+"€");
					}
					else {
						switch(response){
							case 'erreur stock':
								alert("Le stock pour ce produit est insuffisant, vous ne pouvez pas l'ajouter au panier");
							break;
							default:
								if(typeof(div_depart) == "undefined")
									effet_focus('btn_ajouter_panier', 'infoPanierContent');
								else
									effet_focus(div_depart, 'infoPanierContent');
									
								update_panier_boxes();
								if(typeof(comments) != "undefined" && comments != ''){
									$('#contener_comments_anonyme').html(qte);
									setTimeout("openbox('popup_comments')", 600);
									//openbox('popup_comments'); 
									$('#lig_comments_classic').remove();
								}
								else {
									setTimeout("openbox('popup_add_panier')", 600);
								}
								
									
							break;
						}
					}
					}
				 });
			}
		
	}
}


function affiche_boxes_visuel( ligne ){
	$('#boxes_img_visuel_'+ligne).fadeIn("fast");
}

function cache_boxes_visuel( ligne ){
	//$('#boxes_img_visuel_'+ligne).hide("fast");
	$('#boxes_img_visuel_'+ligne).css("display", "none");
}


function desactive_code_avantage(){
	$.ajax({
	   type: "POST",
	   url: base_name_navigation+"ajax.php",
	   data: "action=104",
	   success: function(data){
			window.location='shopping_cart.php';
		}
	 });
	 
}

function update_sub_total(){
	waitNavig('sub_title_total');
	$.ajax({
	   type: "POST",
	   url: base_name_navigation+"ajax.php",
	   data: "action=102",
	   success: function(data){
			//unwaitNavig('infoBoxContents');
			$('#sub_title_total').html( data );
		}
	 });

}

function update_panier_boxes(){
	waitNavig('infoPanierContent');
	$.ajax({
	   type: "POST",
	   url: base_name_navigation+"ajax.php",
	   data: "action=101",
	   success: function(data){
			//unwaitNavig('infoBoxContents');
			$('#panier_boxes').html( data );
		}
	 });
	

}

function affiche_suite_commentaire(p_id, p_type, debut, div){
	waitNavig(div);
	$.ajax({
	   type: "POST",
	   url: base_name_navigation+"ajax.php",
	   data: "action=201&p_id="+p_id+"&p_type="+p_type+"&debut="+debut,
	   success: function(data){
			$('#'+div).html( data );
			
		}
	 });
}


function preloader( img_src ) 
{

	var img = new Image; 

	img.src = img_src;
	return img;
}



function confirm_don_asso( p_asso ){
	var montant;

	if( typeof( $('#multi_montant_libre')) != "undefined" && $('#multi_montant_libre').val() != ""){
		
			montant = $('#multi_montant_libre').val();
			window.location='https://ssl7.ovh.net/~clicsoli/clicanimaux/catalog/don.php?asso_prelev='+p_asso+'&montant_libre='+montant;
		
	}
	else { 
		
		$('input[name=input_prelevement]').each( function(){ 
			if(this.checked == true){ 
				montant = this.value;
			}
		
		});
		
		window.location='https://ssl7.ovh.net/~clicsoli/clicanimaux/catalog/don.php?asso_prelev='+p_asso+'&montant='+montant;

	}
	
	
}


function confirm_don_asso_daily( p_asso, p_site_name ){
	var montant;

	if( typeof(p_site_name) == "undefined") p_site_name = "animaux";
	if( typeof( $('#multi_montant_libre_daily')) != "undefined" && $('#multi_montant_libre_daily').val() != ""){
		
			montant = $('#multi_montant_libre_daily').val();
			window.location='https://ssl7.ovh.net/~clicsoli/clicanimaux/catalog/don.php?asso_prelev='+p_asso+'&montant_libre='+montant+'&mode=day';
			//window.location= p_site_name+'/don.php?asso_prelev='+p_asso+'&montant_libre='+montant+'&mode=day';
		
	}
	else { 
		
		$('input[name=input_prelevement_daily]').each( function(){ 
			if(this.checked == true){ 
				montant = this.value;
			}
		
		});
		
		window.location='https://ssl7.ovh.net/~clicsoli/clicanimaux/catalog/don.php?asso_prelev='+p_asso+'&montant='+montant+'&mode=day';
		//window.location= p_site_name+'/don.php?asso_prelev='+p_asso+'&montant='+montant+'&mode=day';

	}
	
	
}


function calculeDeductionFiscale( amount, taux, div ) { 
	//alert(amount+" t:"+taux);
	if(typeof(div) == "undefined") 
		div = "result_deduction_input";
		
	if(!isNaN(amount) && !isNaN(taux) && amount != "" ){
		$('#'+div).val("");

		if(amount >0 && taux > 0){
			var reduction;
			var finalAmount;

			reduction = parseFloat((amount) * taux).toFixed(2);
			finalAmount = parseFloat((amount) * (1-taux)).toFixed(2);
			$('#'+div).html( "<b>soit "+finalAmount.replace('.', ',')+"€ après déduction fiscale</b>");
			//alert( div );
		}
		else {
			$('#'+div).html( "<b>Les dons à cette association<br/> ne donnent pas lieu à déduction fiscale.</b>");
		}
	}
	else {
		$('#'+div).html("");
	}
}


function afficheDatePrelev( ){

	var p_date = $('#prelev_date').val();
	var p_periodicite = $('#prelev_periodicite').val();
	var p_last_date = $('#prelev_last_date').val();
	
	if(p_periodicite >= 1){
		$('#div_date_prelev').css("display", "block");
		$('#label_date_prelev').css("display", "none");
		$('#label_date_prelev').css("display", "block");
		waitNavig('label_date_prelev');
		$.ajax({
		   type: "POST",
		   url: base_name_navigation+"ajax.php",
		   data: "action=300&p_date="+p_date+"&p_last_date="+p_last_date+"&p_periodicite="+p_periodicite,
		   success: function(data){
				$('#label_date_prelev').html( "<br/><br/><b>La date du prochain prélèvement <br/>aura lieu le : "+data+"<br/>" );
				
			}
		 });
		 
		
		
	}
	else if(p_periodicite==0.5){
		var data = '<input type="text" size="1" name="prelev_date" value="1,15" />Les prélèvements s\'effectuerons le 1er et le 15 du mois';
		$('#label_date_prelev').html( data );
		$('#label_date_prelev').css("display", "block");
		$('#div_date_prelev').css("display", "none");
	}
	else {
		$('#div_date_prelev').css("display", "none");
		$('#label_date_prelev').css("display", "none");
	}
}

function setRecommandation( p_id, p_type){
	$.ajax({
	   type: "POST",
	   url: base_name_navigation+"ajax.php",
	   data: "action=320&p_id="+p_id+"&p_type="+p_type,
	   success: function(data){
			$('#recommand_'+p_id).html( data );
			
		}
	 });

}

function replace_comments( div, id, type, template ){

		$.ajax({
		   type: "POST",
		   url: base_name_navigation+"ajax.php",
		   data: "action=330&id="+id+"&type="+type+"&template="+template,
		   success: function(data){
				$('#'+div).html( data );
				
			}
		 });

}


function effet_focus(id_depart, id_arrive){
	var temps = 300; // temps de l'annim en milisecondes
	var intervalle_globale = 20; 
	var x_temp = temps/intervalle_globale;
	
		
	var pos_x1 = $('#'+id_depart).position().left;
	var pos_x2 = $('#'+id_arrive).position().left;
	
	var pos_y1 = $('#'+id_depart).position().top;
	var pos_y2 = $('#'+id_arrive).position().top;
	
	if($('#'+id_arrive).width() > $('#'+id_depart).width())
		var ecart_width = $('#'+id_arrive).width() - $('#'+id_depart).width(); 
	else
		var ecart_width = $('#'+id_depart).width() - $('#'+id_arrive).width(); 
	
	//alert(ecart_width+" = w arrivé :"+$('#'+id_arrive).width()+ " & w depart = "+$('#'+id_depart).width());
	
	if($('#'+id_arrive).height() > $('#'+id_depart).height())
		var ecart_height = $('#'+id_arrive).height() - $('#'+id_depart).height();
	else
		var ecart_height = $('#'+id_depart).height() - $('#'+id_arrive).height();
		
		
	var intervalle_width = ecart_width / x_temp;
	var intervalle_height = ecart_height / x_temp;
	
	// on fixe la position de depart
	$('#effet_focus').css('left', pos_x1);
	$('#effet_focus').css('top', pos_y1);
	$('#effet_focus').css('width', "30px");
	$('#effet_focus').css('height', "30px");
	$('#effet_focus').show();
	
	// on va vers la droite
	if(pos_x2 >= pos_x1){
		var min_x = pos_x1;
		var max_x = pos_x2;
		var intervale_x = (pos_x2 - pos_x1)/x_temp;
	}
	// on va vers la gauche
	else{
		var min_x = pos_x2;
		var max_x = pos_x1;
		var intervale_x = -1*((pos_x1 - pos_x2)/x_temp);
	}
	
	//alert(pos_y1+" -> "+pos_y2);
	
	// on va vers le bas
	if(pos_y1 <= pos_y2){
		var intervale_y = (pos_y2 - pos_y1)/x_temp;
	}
	// on va vers le haut
	else {
		var intervale_y = -1*((pos_y1 - pos_y2)/x_temp);
	}
	
	var left = $('#effet_focus').position().left; 
	var top = $('#effet_focus').position().top;
	var width = $('#effet_focus').width();
	var height = $('#effet_focus').height();
	
	
	for(var time = 0; time < temps; time = time+intervalle_globale){
		left = left+intervale_x;
		top = top+intervale_y;
		width = width+intervalle_width;
		height = height+intervalle_height;
		
		$('#effet_focus').delay( intervalle_globale/2 ).animate({ left: parseInt(left)+"px", top: parseInt(top)+"px", width: parseInt(width)+"px", height: parseInt(height)+"px" }, intervalle_globale/2 );

	}
	
	$('#effet_focus').delay( temps-intervalle_globale ).fadeOut('fast');
}


function affiche_suite_action( width, limit, type, debut, div){
	waitNavig(div);
	$.ajax({
	   type: "POST",
	   url: base_name_navigation+"ajax.php",
	   data: "action=400&width="+width+"&limit="+limit+"&type="+type+"&debut="+debut,
	   success: function(data){
			$('#'+div).html( data );
			
		}
	 });

}

function affiche_options(div, mod){
	if($('#'+div).css('display') == "none"){
		$('#'+div).slideDown();
		$('#btn_options_'+mod).removeAttr("class");
		$('#btn_options_'+mod).attr("class", "btn_filtrer_on");
	}
	else {
		$('#'+div).css('display', 'none');
		$('#btn_options_'+mod).removeAttr("class");
		$('#btn_options_'+mod).attr("class", "btn_filtrer");
	}
	
}
					
function update_filtre( value, div, mod, width ) {


		$('#btn_options_'+mod).val('Trié par '+value.toLowerCase() );
		waitNavig(div);
		$.ajax({
		   type: "POST",
		   url: base_name_navigation+"ajax.php",
		   data: "action=500&value="+value+"&mod="+mod+"&width="+width,
		   success: function(data){
				$('#'+div).html( data );
				
			}
		 });
	


}

function refresh_captcha( captcha ){
	
	$('.'+captcha).html('<center><img src="'+base_img_dir_navig+'ajax-loader.gif" border="0" align="center" /></center>');

	$.ajax({
	   type: "POST",
	   url: base_name_navigation+"ajax.php",
	   data: "action=600",
	   success: function(data){
			$('.'+captcha).html( data );	
		}
	 });

}

function controle_date_expiration( annee, mois, annee_du_jour, mois_du_jour){
	var msg_error = "La date d'expiration de votre carte de crédit est incorrecte.";
	//annee = 2011;
	//mois = 01;
	//alert('annee:'+annee+' -mois:'+mois+' -annee_du_jour:'+annee_du_jour+' -mois_du_jour:'+mois_du_jour);
	if(typeof(annee) != "undefined" && typeof(mois) != "undefined" && typeof(annee_du_jour) != "undefined" && typeof(annee) != "undefined"){
		if( annee < annee_du_jour){
			alert( msg_error );
			return false;
		}
		else {
			if(annee == annee_du_jour && mois < mois_du_jour){
				alert( msg_error );		
				return false;
			}	
		}
	}
	else {
		alert( msg_error );
		return false;
	}
	
	return true;
}




function calcul_nb_caracteres(){
	var chaine = $('#products_options').val();
	
	if(chaine.length > 155){
		$('#products_options').val( chaine.substring(0, 155) );
		$('#affiche_nb_caracteres').html("155 caractères / 155 autorisés");
	}
	else {
		if(chaine.length==1)
			$('#affiche_nb_caracteres').html( chaine.length +" caractère / 155 autorisés");
		else
			$('#affiche_nb_caracteres').html( chaine.length +" caractères / 155 autorisés");
	}
	
}

function ShowMenu(id){
	$('#'+id).css('display', 'block');
}
function HideMenu(id){
	$('#'+id).css('display', 'none');
}

function get_montant_remboursement(value){
	$('#montant_remboursement').html('<b>Votre remboursement sera de : '+value+" €</b>");
}
function get_montant_remboursement_day(value){
	var montant = value*30;
	$('#montant_remboursement').html('<b>Votre remboursement sera de : '+montant+" €</b>");
}

function expandGestionPrelevBloc(  ){
	var btn = $('#btnExpandGestionPrelev');
	if(typeof(btn) != "undefined"){ 
		if($(btn).attr("class") == "btnExpandPlus"){
			$(btn).attr("class", "btnExpandMoins");
			$('#gestion_prelev_bloc').css('display', 'block');
			$('#gestion_prelev_bloc').stop(true, true).slideDown('slow');
		}
		else {
			$(btn).attr("class", "btnExpandPlus");
			$('#gestion_prelev_bloc').stop(true, true).slideUp('fast');
			$('#gestion_prelev_bloc').css('display', 'none');
		}
	}
}


function expandGestionDonsBloc(  ){
	var btn = $('#btnExpandGestionDons');
	if(typeof(btn) != "undefined"){ 
		if($(btn).attr("class") == "btnExpandPlus"){
			$(btn).attr("class", "btnExpandMoins");
			$('#gestion_dons_bloc').css('display', 'block');
			$('#gestion_dons_bloc').stop(true, true).slideDown('slow');
		}
		else {
			$(btn).attr("class", "btnExpandPlus");
			$('#gestion_dons_bloc').stop(true, true).slideUp('fast');
			$('#gestion_dons_bloc').css('display', 'none');
		}
	}
}


function expandGestionCBBloc(  ){
	var btn = $('#btnExpandGestionCB');
	if(typeof(btn) != "undefined"){ 
		if($(btn).attr("class") == "btnExpandPlus"){
			$(btn).attr("class", "btnExpandMoins");
			$('#gestion_CB_bloc').css('display', 'block');
			$('#gestion_CB_bloc').stop(true, true).slideDown('slow');
		}
		else {
			$(btn).attr("class", "btnExpandPlus");
			$('#gestion_CB_bloc').stop(true, true).slideUp('fast');
			$('#gestion_CB_bloc').css('display', 'none');
		}
	}
}


function expandGestionDonneesBloc(  ){
	var btn = $('#btnExpandGestionDonnees');
	if(typeof(btn) != "undefined"){ 
		if($(btn).attr("class") == "btnExpandPlus"){
			$(btn).attr("class", "btnExpandMoins");
			$('#gestion_Donnees_bloc').css('display', 'block');
			$('#gestion_Donnees_bloc').stop(true, true).slideDown('slow');
		}
		else {
			$(btn).attr("class", "btnExpandPlus");
			$('#gestion_Donnees_bloc').stop(true, true).slideUp('fast');
			$('#gestion_Donnees_bloc').css('display', 'none');
		}
	}
}


function get_this_year( year, div, oscid){
	$.ajax({
	   type: "POST",
	   url: base_name_navigation+"ajax.php",
	   data: "action=702&year="+year+"&oscid="+oscid,
	   success: function(data){
			$('#'+div).html( data );
		}
	});
}


