/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Filename: philatelie50.js
 * Website: Philatelie 50
 * Author: CH1.fr
 * Description: javascript
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

jQuery(document).ready(function() {



/* Parser Url ____________________________________________________ */
jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();

/* Changement du titre pour la page conseiller a un ami ___________________________________________________ */
$("#recommend .formulaire form fieldset legend").text('Conseiller ce produit a un ami');
    $("#recommend .formulaire form fieldset label").eq(0).text('Votre Nom et prenom : ');

	
	
$(".titre_lien").each(function(){
var lien = $(this).children('h3').children('a').attr('href');
$(this).children('.short_product').children('.margintop').children('a').attr('href',lien);
});

var str = $(".bloc_liens .desc_cadeau").html();
$(".bloc_liens .desc_cadeau").remove();
$(".bloc_liens .bloc_cadeau .short_product .margintop a.LinkIn").attr('href','#');
$(".bloc_liens .bloc_cadeau .short_product").append(str);


$("#product a.LinkIn img, #").each(function(){
var alt = $(this).attr('alt');
$(this).parent('a').attr('title',alt);
});
$(".short_product .margintop a.LinkIn img").each(function(){
var alt = $(this).attr('alt');
$(this).parent('a').attr('title',alt);
});
$(".catalog .familly img").each(function(){
var alt = $(this).attr('alt');
$(this).attr('title',alt);
});

/* Avertissement frais de port ______________________________________________________ */

// tableau validation  _______________________________ 
if ($('#cart_detail .shipping td label').eq(0).text() == "France poste") {

	var montant_total = $('#cart_detail tr.amount td').eq(1).html();
	var fdp = $('#cart_detail table tr.shipping td').eq(1).children('span').html();
	var prix_limite = 75;   /* Limite de prix */
	var montant_achat = 0;
	var montant_restant = 0;
	montant_total = montant_total.replace(" €","").replace(",",".");
	montant_total = parseFloat(montant_total);
	fdp = fdp.replace("€","").replace(",",".");
	fdp = parseFloat(fdp);
	montant_achat = montant_total - fdp;
	montant_restant = prix_limite - montant_achat;
	montant_restant = Math.round(montant_restant*100) / 100;

	$('#cart_detail').prepend('<div class="avertissement_port"><strong>Attention, pour toute commande au dessus de ' + prix_limite +'&euro;,<br/> les frais de port pour la France sont gratuits ! </strong><br/>Il vous manque ' + montant_restant + ' &euro; d\'achats pour profiter de cette offre.</div>');
	
}

// tableau panier _______________________________ 


if ($('#formcart').length > 0) {
var montant_total = $('#selections_cart table tr.amount td').eq(1).html();
var prix_limite = 75;   /* Limite de prix */

montant_total = montant_total.replace("€", "").replace("&nbsp;", "").replace(",", ".");
montant_total = montant_total.replace(/ /g, '_');
montant_total = parseFloat(montant_total);

if (montant_total < prix_limite) {
	montant_restant = prix_limite - montant_total;
	montant_restant = Math.round(montant_restant*100) / 100;
	$('#selections_cart').prepend('<div class="avertissement_port"><strong>Attention, pour toute commande au dessus de ' + prix_limite +'&euro;,<br/> les frais de port pour la France sont gratuits ! </strong><br/>Il vous manque ' + montant_restant + ' &euro; d\'achats pour profiter de cette offre.</div>');
}

}

// Avertissement code postal ______________________________________________________ */

$("#cpid").parent('span').parent('.row').append('<div class="avertissement"></div>');
$('.avertissement').html('Attention le code postal que vous avez saisie est incorrect ou ne correspond pas &agrave; la France M&eacute;tropolitaine, v&eacute;rifiez bien votre saisie ou que le champ Pays ne soit pas France M&eacute;tropolitaine.');
$('.avertissement').hide();
var visible = false;
var codepostal = "^(([0-8][0-9])|(9[0-5]))[0-9]{3}$";



$("#cpid").blur(function() {
	var text = $(this).text();
	if($(this).val().match(codepostal)) {
		if(visible == true) {
			$(this).parent('span').next('.avertissement').fadeOut("slow");
			visible == false;
		}
	} else {
		$(this).parent('span').next('.avertissement').hide();
		if($('#pays').val() == "77")  {
		   $('.avertissement').fadeIn("slow");
		   visible = true;
   }
}
});

 $("#pays").change(function()  {
	if($('#pays').val() == "77")  {
		if($("#cpid").val().match(codepostal)) {
			$('.avertissement').fadeOut("slow");
			visible == false;
		} else {
			$('.avertissement').fadeIn("slow");
			visible = true;
	   }
   } else {
		if(visible == true) {
			$('.avertissement').fadeOut("slow");
			visible == false;
		}
   
   }
   

});



/* fin Jquery */
});


/* Swap moteur de recherche ________________________________________________ */
 
function swap( F, R )
{
var vD = F.defaultValue;
if ( F.value == ( R ? '' : vD ) ) F.value = ( R ? vD : '' );
}



