/*========================================================================
JS Etesia
========================================================================*/

//Rollover Menu Lang
function initRollLang()
{
	if( $("#current_lang") )
	{
		$('#current_lang').hover(
		 function()
		 {
		 		if($(this).children(".lang"))
		 		{
		 			$(this).children(".lang").css('display', 'block');
		 		}
		 },
		 function()
		 {
		 		if($(this).children(".lang"))
		 		{
		 			$(this).children(".lang").css('display', 'none');
		 		}
		 }
		);
	}
}

//Rollover Pad Extranet
function initRollExtranet()
{
	if( $("#sm1005") )
	{
		$('#sm1005').hover(
		 function()
		 {
		 		if($(this).children(".menu-top"))
		 		{
		 			$(this).children(".menu-top").css('display', 'block');
		 		}
		 },
		 function()
		 {
		 		if($(this).children(".menu-top"))
		 		{
		 			$(this).children(".menu-top").css('display', 'none');
		 		}
		 }
		);
	}
}

//Rollover Pad eBoutique
function initRollBoutique()
{
	if( $("#sm6904") )
	{
		$('#sm6904').hover(
		 function()
		 {
		 		if($(this).children(".menu-top"))
		 		{
		 			$(this).children(".menu-top").css('display', 'block');
		 		}
		 },
		 function()
		 {
		 		if($(this).children(".menu-top"))
		 		{
		 			$(this).children(".menu-top").css('display', 'none');
		 		}
		 }
		);
	}
}


//Rollover Menu TOP
function initRollMenuTop()
{
	if( $(".li-menu-main") )
	{
		$('.li-menu-main').hover(
		 function()
		 {
		 		if($(this).children(".pad-ssmenu"))
		 		{
		 			$(this).children(".pad-ssmenu").css('display', 'block');
		 			if($(this).attr("class")=="li-menu-main")
		 			{
		 				$(this).addClass("li-menu-main-over");
		 			}
		 		}
		 },
		 function()
		 {
		 		if($(this).children(".pad-ssmenu"))
		 		{
		 			$(this).children(".pad-ssmenu").css('display', 'none');
		 			if($(this).attr("class")=="li-menu-main li-menu-main-over")
		 			{
		 				$(this).removeClass("li-menu-main-over");
		 			}
		 		}
		 }
		);
	}
}

//Rollover Menu CATALOGUE
function initRollMenuCatalog()
{
	if( $(".li-menuCata") )
	{
		$('.li-menuCata').hover(
		 function()
		 {
		 		var myImgBtn = $(this).find("img").attr("src");
		 		var myNewImgBtn = myImgBtn.replace("_off","_on");
		 		$(this).find("img").attr("src", myNewImgBtn);
		 },
		 function()
		 {
		 		var myImgBtn = $(this).find("img").attr("src");
		 		var myActiveBtn = $(this).find("img").attr("class");
		 		if(myActiveBtn!="active")
		 		{
		 			var myNewImgBtn = myImgBtn.replace("_on","_off");
		 			$(this).find("img").attr("src", myNewImgBtn);
		 		}
		 }
		);
	}
}

//Affiche/cache Pad
function showHidePad(idPad)
{
	if( document.getElementById(idPad).style.display == "block" )
	{
		document.getElementById(idPad).style.display = "none";
	}
	else
	{
		document.getElementById(idPad).style.display = "block";
	}
}

//Scroll Window
function scrollWindow(cible)
{
	var targetOffset = $("#"+cible).offset().top;
	$('html,body').animate({scrollTop: targetOffset}, 500);
}

// Cache les msg d'erreur
function hide_error () {
	div  = (document.layers) ? document.layers['errorPad'] : document.getElementById('errorPad');
	div2  = (document.layers) ? document.layers['erlogPad'] : document.getElementById('erlogPad');
	div.className = "error_hide";
	div2.className = "error_hide";
}

/*==== Focus sur les fields ====*/
function GetFocus(field) {
	if (field.value==field.title) {field.value=''}
}

/*==== Blur sur les fields ====*/
function GetBlur(field) {
	if (field.value=='') {
		field.value=field.title;
	} 
}

/*==== shareSocial ====*/
function OpenShare(src,nom)
{
	var largeur = 620;
	var hauteur = 460;
	var leftx = 10;
	var topx = 10;
	popUp = window.open(src,nom,'width=' + largeur + ',' + 'height=' + hauteur  + ' ,left=' + leftx + ',top= '+ topx +',scrollbars=yes,toolbars=no,menubars=no,location=no,resizable=yes');
}
function showSocialLinks(el, idPad)
{
	var myImgBtn = el.src;
	var longueurChaine = myImgBtn.length;
	longueurChaine = (longueurChaine-4);
	
	var etat = myImgBtn.substring( longueurChaine-4, longueurChaine );
	
	if(etat=="plus")
	{
		var myNewImgBtn = myImgBtn.replace("_plus","_moins");
		var btnDisplay = "inline";
		
	}
	else
	{
		var myNewImgBtn = myImgBtn.replace("_moins","_plus");
		var btnDisplay = "none";
	}
	
	el.src = myNewImgBtn;
	
	var allLinks = document.getElementById("social_links_"+idPad).getElementsByTagName("a");
	
	for(var i=2; i<(allLinks.length-1); i++)
	{
		allLinks[i].style.display = btnDisplay;
	}
}

/*==== Geolocalisation de l'utilisateur ====*/
var daClientLocation;

// ---> Geolocalisation de la MAP
	function getUserLocation(command) 
	{
		daClientLocation	=	google.loader.ClientLocation;
		
		var centerLat			=	35;
		var centerLong			=	0;
		var centerZoom			=	2;
		
		if (daClientLocation != undefined)
		{
			var centerLat	= 	daClientLocation.latitude;
			var centerLong	=	daClientLocation.longitude;
			var daCity 		=	daClientLocation.address.city;
			var centerZoom	=	8;
			
			if ( $('.form-revendeur').length > 0 )
			{
				//$('.form-revendeur').html( 'Vous cherchez un revendeur Etesia ? pr�s de chez vous '+ daCity +' alors <a href="'+ urlRevendeur +'?lat='+centerLat+'&amp;long='+centerLong+'">Cliquez ici !</a>');
			}
		}
		
		if (command =='retour')
		{
			return daClientLocation;
		}
	}
function upd_shopping_cart(current_sel, pid, base_url)
{
    var new_qty = current_sel.value;
    document.location.href=base_url+'&upd_pid='+pid+'&upd_cart='+new_qty;
}

function show_shipping_form(is_same)
{
    if(is_same == "1")
    {
        document.getElementById('shipping_form').style.display = 'none';
    }
    else
    {
       document.getElementById('shipping_form').style.display = 'block';    
    }
}

function popup_shop_cgv()
{
    var largeur = 800;
    var hauteur = 600;
    var leftx = 10;
    var topx = 10;
    popUp = window.open("shop_cgv.php","CGV",'width=' + largeur + ',' + 'height=' + hauteur  + ' ,left=' + leftx + ',top= '+ topx +',scrollbars=yes,toolbars=no,menubars=no,location=no,resizable=yes');
}
function shop_alerte_msg(msg)
{
    if(document.frm_confirmation.cgv.checked)
    {
        document.frm_confirmation.submit();
    }
    else
    {
        alert(msg);    
        return false;
    }
}


//eBoutique images
function initRollPhotoEboutique(urlImgZoom)
{
	if( $(".eboutique-thumb") )
	{
		$('.eboutique-thumb').click(
		 function()
		 {
		 		$('.eboutique-thumb').removeClass("active");
				$('.eboutique-thumb-video').removeClass("active");
		 		document.getElementById('eboutiqueZoom').innerHTML = '<img alt="" src="" class="eboutique-zoom" />';
		 		var myNewSrc = $(this).attr("rel");
		 		$(".eboutique-zoom").attr("src", urlImgZoom+myNewSrc);
		 		$(this).addClass("active");
		 }
		);
	}
}

function loadShopVideo(id_video)
{
	var target= document.getElementById('eboutiqueZoom');
	$('.eboutique-thumb').removeClass("active");
	$('.eboutique-thumb-video').addClass("active");
	target.innerHTML='<object width="425" height="240"><param name="movie" value="http://www.youtube.com/v/'+id_video+'?fs=1&amp;hl=fr_FR&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+id_video+'?fs=1&amp;hl=fr_FR&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="240"></embed></object>';
}
