/********************************************************************************
' **
' ** commun.js : Bibliothèque commune Javascript
' ** =========================
' **
' ** 
' ** RM-F-005
' **
' **
' ** 30/01/2008 - ebailly (SQLI) 
' **   
' **
' ********************************************************************************/


/**************************************/
/* Gestion des menus à onglets (Tabs) */
/**************************************/
function initOnglet(target) {
	$('onglet_'+target).className = 'onglet_on';
	
	categ = 'categ_'+target;
	node = $('cont_produits');
	el = node.getElementsByTagName("div");
	for (i = 0; i < el.length; i++) {
		if ($(el[i]).id.indexOf('categ') > -1 && $(el[i]).id != categ) {
			$(el[i]).style.display = "none";
			$(el[i]).setOpacity(0);
			$(el[i]).style.marginLeft = 0+"px";
		}
	}
	$(categ).style.display = "block";	
}

function initOngletTheque(target) {
	$('onglet_'+target).className = 'onglet_on_theque';
	
	categ = 'categ_'+target;
	node = $('cont_produits');
	el = node.getElementsByTagName("div");
	for (i = 0; i < el.length; i++) {
		if ($(el[i]).id.indexOf('categ') > -1 && $(el[i]).id != categ) {
			$(el[i]).style.display = "none";
			$(el[i]).setOpacity(0);
			$(el[i]).style.marginLeft = 0+"px";
		}
	}
	$(categ).style.display = "block";	
}

function initOngletConnaitre(target) {
	$('onglet_'+target).className = 'onglet_on_connaitre';
	
	categ = 'categ_'+target;
	node = $('cont_produits');
	el = node.getElementsByTagName("div");
	for (i = 0; i < el.length; i++) {
		if ($(el[i]).id.indexOf('categ') > -1 && $(el[i]).id != categ) {
			$(el[i]).style.display = "none";
			$(el[i]).setOpacity(0);
			$(el[i]).style.marginLeft = 0+"px";
		}
	}
	$(categ).style.display = "block";	
}

function showCateg(previous, target) {
	$(previous).style.display = "none";		
	$(previous).setOpacity(0);
	$(target).style.display = "block";	
	$(target).setOpacity(1);
}

function manageOnglet(onglet) {
	node = $('cont_onglet');
	el = node.getElementsByTagName("a");
	for (i = 0; i < el.length; i++) {	
		if ($(el[i]).className == 'onglet_on')
			$(el[i]).className = 'onglet_off';	
			
		if ($(el[i]).className == 'onglet_on ongletlong')
			$(el[i]).className = 'onglet_off ongletlong';
	}
	target = onglet.id.substr(7, onglet.id.length);	
	
	if ($('onglet_'+target).className.indexOf('ongletlong') > 0)
	{	   
	    $('onglet_'+target).className = 'onglet_on ongletlong';
	}
	else
	{	
	    $('onglet_'+target).className = 'onglet_on';
	}	
	
	node = $('cont_produits');
	el = node.getElementsByTagName("div");	
	for (i = 0; i < el.length; i++) {
		if ($(el[i]).id.indexOf('categ') > -1 && $(el[i]).style.display == "block") {
			currentCateg = $(el[i]).id;
		}
	}
	if (currentCateg != 'categ_'+target) {
		var fxOp = new Fx.Styles($(currentCateg), {duration:200, wait:false, transition: Fx.Transitions.linear, onComplete: function(){showCateg(currentCateg, 'categ_'+target)}});
		fxOp.start({ 'opacity':0 });
	}
}

function manageOngletTheque(onglet) {
	node = $('cont_onglet');
	el = node.getElementsByTagName("a");
	for (i = 0; i < el.length; i++) {
		if ($(el[i]).className == 'onglet_on_theque')
			$(el[i]).className = 'onglet_off_theque';
		if ($(el[i]).className == 'onglet_on_theque ongletlong')
			$(el[i]).className = 'onglet_off_theque ongletlong';
	}
	target = onglet.id.substr(7, onglet.id.length);		
	
	if ($('onglet_'+target).className.indexOf('ongletlong') > 0)
	{	   
	    $('onglet_'+target).className = 'onglet_on_theque ongletlong';
	}
	else
	{	
	    $('onglet_'+target).className = 'onglet_on_theque';
	}
	
	node = $('cont_produits');
	el = node.getElementsByTagName("div");	
	for (i = 0; i < el.length; i++) {
		if ($(el[i]).id.indexOf('categ') > -1 && $(el[i]).style.display == "block") {
			currentCateg = $(el[i]).id;
		}
	}
	if (currentCateg != 'categ_'+target) {
		var fxOp = new Fx.Styles($(currentCateg), {duration:200, wait:false, transition: Fx.Transitions.linear, onComplete: function(){showCateg(currentCateg, 'categ_'+target)}});
		fxOp.start({ 'opacity':0 });
	}
}

function manageOngletConnaitre(onglet) {
	node = $('cont_onglet');
	el = node.getElementsByTagName("a");
	for (i = 0; i < el.length; i++) {
		if ($(el[i]).className == 'onglet_on_connaitre')
			$(el[i]).className = 'onglet_off_connaitre';
			
		if ($(el[i]).className == 'onglet_on_connaitre onglet_long')
			$(el[i]).className = 'onglet_off_connaitre onglet_long';
	}
	target = onglet.id.substr(7, onglet.id.length);		
	if ($('onglet_'+target).className.indexOf('ongletlong') > 0)
	{	   
	    $('onglet_'+target).className = 'onglet_on_connaitre ongletlong';
	}
	else
	{	
	    $('onglet_'+target).className = 'onglet_on_connaitre';
	}
	
	node = $('cont_produits');
	el = node.getElementsByTagName("div");	
	for (i = 0; i < el.length; i++) {
		if ($(el[i]).id.indexOf('categ') > -1 && $(el[i]).style.display == "block") {
			currentCateg = $(el[i]).id;
		}
	}
	if (currentCateg != 'categ_'+target) {
		var fxOp = new Fx.Styles($(currentCateg), {duration:200, wait:false, transition: Fx.Transitions.linear, onComplete: function(){showCateg(currentCateg, 'categ_'+target)}});
		fxOp.start({ 'opacity':0 });
	}
}

/**************************************/
/* Fonctions standards                */
/**************************************/
function rollBtn(target) {
	if ($(target).className.indexOf("_hover") > -1) {		
		$(target).className = "big_btn";
	} else {
		$(target).className = "big_btn_hover";
	}
}

function rollAlpha(target) { $(target).setOpacity(0.7); }

function resetAlpha(target) { $(target).setOpacity(1); }


function setInputValue(target, value) {
	if ($(target).value == "")
		$(target).value = value;
	else {
		if ($(target).value == value)
			$(target).value = "";
	}
}

function launchwin(winurl,winname,winfeatures)
{
	newwin = window.open(winurl,winname,winfeatures);
	setTimeout('newwin.focus();',250);
}

function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}



/***********************/
/* Accordéon - Accueil */
/***********************/
statutongletHome = 0;
resizeHomeinprogress = false;

function upHomeResize() {
	resizeHomeinprogress = false;
}


function initAccordeon() {
    statutongletHome = 0;
	$("sep_accordeon_1").className = null;
	$("sep_accordeon_2").className = null;

	$("content_theque").style.width = 0+"px";
	$("content_connaitre").style.width = 0+"px";
	
	$("band_theque").style.marginLeft = 6+"px";	
	$("band_connaitre").style.marginLeft = 6+"px";
}

function deplieAccordeon()
{
    // On déplie l'accordéon de l'accueil en fonction du paramètre de l'url
    if (document.location.href.substring(document.location.href.length-13)=="o=Apriltheque")
    {        
        resizeAccordeon('content_theque');
    }
    else if (document.location.href.substring(document.location.href.length-15)=="o=NousConnaitre")
    {        
        resizeAccordeon('content_connaitre');
    }    
}

function resizeAccordeon(el)
{
	largeurElemAccordeonLarge = 533;
	largeurElemAccordeonSmall = 0;
	duree = 800;
	trans = Fx.Transitions.Expo.easeOut;			
	tabElems = Array("content_offre", "content_theque", "content_connaitre");	
	
	if (!resizeHomeinprogress)
	{		
		if (el == tabElems[0]) {			
			if ($(el).offsetWidth >= largeurElemAccordeonLarge) {}
			else {
			    resizeHomeinprogress = true;			    
				
				var fx4 = new Fx.Styles($(tabElems[0]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
				fx4.start({
					'width':largeurElemAccordeonLarge
				});	
				var fx5 = new Fx.Styles($(tabElems[1]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
				fx5.start({
					'width':largeurElemAccordeonSmall
				});
				if ($(tabElems[2]).offsetWidth >= largeurElemAccordeonLarge) {
					var fx6 = new Fx.Styles($(tabElems[2]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
					fx6.start({
						'width':largeurElemAccordeonSmall
					});
				}				
				statutongletHome = 0;
			}
		}

		if (el == tabElems[1]) {
			if ($(el).offsetWidth >= largeurElemAccordeonLarge) {}
			else {
			    resizeHomeinprogress = true;	
			    			
				var fx10 = new Fx.Styles($(tabElems[0]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
				fx10.start({
					'width':largeurElemAccordeonSmall
				});	
				var fx11 = new Fx.Styles($(tabElems[1]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
				fx11.start({
					'width':largeurElemAccordeonLarge
				});
				if ($(tabElems[2]).offsetWidth >= largeurElemAccordeonLarge) {
					var fx12 = new Fx.Styles($(tabElems[2]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
					fx12.start({
						'width':largeurElemAccordeonSmall
					});
				}				
				statutongletHome = 1;
			}
		}

		if (el == tabElems[2]) {
			if ($(el).offsetWidth >= largeurElemAccordeonLarge) {}
			else {
				resizeHomeinprogress = true;
				var fx16 = new Fx.Styles($(tabElems[0]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
				fx16.start({
					'width':largeurElemAccordeonSmall
				});	
				var fx17 = new Fx.Styles($(tabElems[1]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
				fx17.start({
					'width':largeurElemAccordeonSmall
				});
				var fx18 = new Fx.Styles($(tabElems[2]), {duration:duree, wait:false, transition: trans, onComplete: function(){upHomeResize()}});
				fx18.start({
					'width':largeurElemAccordeonLarge
				});				
				statutongletHome = 2;			
			}
		}	  
	}	
}


/***********************************/
/* Accordéon - Page Intérieure (PI)*/
/***********************************/

statutongletPI = 0;
resizePIinprogress = false;

function upPIResize() {
	resizePIinprogress = false;
}

function initAccordeonPI() {
    statutongletPI = 0;
	$("sep_accordeon_1").className = null;
	$("sep_accordeon_2").className = null;
	
	$("content_theque_PI").style.width = 0+"px";
	$("content_connaitre_PI").style.width = 0+"px";
	
	$("mini_band_theque").style.marginLeft = 6+"px";	
	$("mini_band_connaitre").style.marginLeft = 6+"px";
}

function initAccordeonPITheque() {
    statutongletPI = 1;
	$("sep_accordeon_1").className = null;
	$("sep_accordeon_2").className = null;
	
	$("content_offre_PI").style.width = 0+"px";	
	$("content_theque_PI").style.width = 530+"px";
	$("content_connaitre_PI").style.width = 0+"px";
	
	$("mini_band_offre").style.marginLeft = 6+"px";	
	$("mini_band_connaitre").style.marginLeft = 6+"px";	
}

function initAccordeonPIConnaitre() {
    statutongletPI = 2;
	$("sep_accordeon_1").className = null;
	$("sep_accordeon_2").className = null;
	
	$("content_offre_PI").style.width = 0+"px";
	$("content_theque_PI").style.width = 0+"px";	
	$("content_connaitre_PI").style.width = 533+"px";
	
	$("mini_band_offre").style.marginLeft = 6+"px";
	$("mini_band_theque").style.marginLeft = 6+"px";			
}


function resizeAccordeonPI(el)
{  	
	largeurElemAccordeonLarge = 530;
	largeurElemAccordeonSmall = 0;
	duree = 1000;
	trans = Fx.Transitions.Expo.easeOut;				
	tabElems = Array("content_offre_PI", "content_theque_PI", "content_connaitre_PI");				

    if (!resizePIinprogress)
    {
	    if (el == tabElems[0]) {		
		    if ($(el).offsetWidth >= largeurElemAccordeonLarge) {	}
		    else {
		        resizePIinprogress = true;	        
    			
			    var fx4 = new Fx.Styles($(tabElems[0]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
			    fx4.start({
				    'width':largeurElemAccordeonLarge
			    });	
			    var fx5 = new Fx.Styles($(tabElems[1]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
			    fx5.start({
				    'width':largeurElemAccordeonSmall
			    });
				    var fx6 = new Fx.Styles($(tabElems[2]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
				    fx6.start({
					    'width':largeurElemAccordeonSmall
				    });		
			    statutongletPI = 0;		
		    }
	    }

	    if (el == tabElems[1]) {
		    if ($(el).offsetWidth >= largeurElemAccordeonLarge) { }
		    else {		
		        resizePIinprogress = true;	        
    			
			    var fx10 = new Fx.Styles($(tabElems[0]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
			    fx10.start({
				    'width':largeurElemAccordeonSmall
			    });	
			    var fx11 = new Fx.Styles($(tabElems[1]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
			    fx11.start({
				    'width':largeurElemAccordeonLarge
			    });
			    if ($(tabElems[2]).offsetWidth >= largeurElemAccordeonLarge) {
				    var fx12 = new Fx.Styles($(tabElems[2]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
				    fx12.start({
					    'width':largeurElemAccordeonSmall
				    });
			    }
			    statutongletPI = 1;
		    }
	    }

	    if (el == tabElems[2]) {
		    if ($(el).offsetWidth >= largeurElemAccordeonLarge) { }
		    else {		    
		        resizePIinprogress = true;
		            			
			    var fx16 = new Fx.Styles($(tabElems[0]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
			    fx16.start({
				    'width':largeurElemAccordeonSmall
			    });	
			    var fx17 = new Fx.Styles($(tabElems[1]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
			    fx17.start({
				    'width':largeurElemAccordeonSmall
			    });
			    var fx18 = new Fx.Styles($(tabElems[2]), {duration:duree, wait:false, transition: trans, onComplete: function(){upPIResize()}});
			    fx18.start({
				    'width':largeurElemAccordeonLarge
			    });
			    statutongletPI = 2;
		    }
	    }
	}		
}

	
function validerRecherchePointDeVente(idAdresse,idVille,idCodePostal) {
	var ok = true;
	objadresse = document.getElementById(idAdresse);
	objville = document.getElementById(idVille);
	objcp = document.getElementById(idCodePostal);
	
	if ((objadresse.value=="")  && (objville.value == "") && (objcp.value == "")) {
		alert("Veuillez saisir des informations pour trouver votre point de vente");
		return false;
	    }
		
	if ((objadresse.value!="")  && ((objville.value == "") && (objcp.value == ""))) {
		alert("Saisissez un code postal ou une ville");
		return false;
		}

	return true;
}
