// fonctions AJAX

function AfficherDetailCarton(tag, codeCarton, visible) {
	// affichage du détail du carton
	var strId = new String();
	var strTagId = new String();
	var strPrefix = new String();
	strTagId = tag.id;
	intPos = strTagId.lastIndexOf('_');
	strPrefix = strTagId.substr(0, intPos+1);
	strDivId = strPrefix + "div" + strTagId.substr(intPos+1, strTagId.length - (intPos+1));
	
	var divTag = document.getElementById(strDivId);
	divTag.style.width = '20px';
	divTag.innerHtml = "...";
	if (visible) {
		divTag.style.visibility = 'visible';	
	}
	else divTag.style.visibility = 'hidden';			

	// requête Ajax pour récupérer le détail du carton
	if (visible) {
	    var url = '../ajax/produit.aspx';
	    var pars = 'code='+codeCarton;
	    var target = strDivId;
	    var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
	}

	divTag.style.width = '300px';

}

function Authentifier(chemin)
{
    var divErreur = document.getElementById('divErreur');
    var txtLogin = document.getElementById('Header1_txtLogin');
    var txtPassword = document.getElementById('Header1_txtPassword');
    
    // requête Ajax pour l'identification
	var url = chemin+'/ajax/login.aspx';
	var pars = 'login='+txtLogin.value+'&password='+txtPassword.value;
	var myAjax = new Ajax.Updater('divErreur', url, {method:'get', parameters:pars, evalScripts:true,
	    onComplete: function(request) {
            if (divErreur.innerHTML=='') {
        	    divErreur.style.visibility = 'hidden';
    	        location.href = chemin+'/mon-compte/accueil.aspx';
    	    }
    	    else {
                divErreur.style.width = '197px'
                divErreur.style.visibility = 'visible';
            }
    	    
	    }
	});
    
}

function ChangerQuantite(blnAugmenter, intQuantiteCommandable, intMultipleDeVente, tagID)
{
    var inputText = document.getElementById(tagID);
    var intQte = parseInt(inputText.value, 10);
    
    if (blnAugmenter) {
        if (intQte < intQuantiteCommandable) {
            var quantite;
            if (intMultipleDeVente==1)
                quantite = intQte + intMultipleDeVente;
            else
                quantite = (intQte==1) ? intMultipleDeVente : intQte + intMultipleDeVente;
            if (quantite>intQuantiteCommandable) quantite = intQuantiteCommandable;
            var strQuantite = String(quantite);
            inputText.value = strQuantite;
        }
    }
    else {
        if (intQte > intQuantiteCommandable) {
            var quantite2 = intQte - intMultipleDeVente;
            if (quantite2<=0) quantite2 = 1;
            var strQuantite2 = String(quantite2);
            inputText.value = strQuantite2;
        }       		
    }     
}
     
 

//simule un clic(~clic humain) ss ff
function simulateClick(cb) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
cb.dispatchEvent(evt);
}

// fonctions d'affichage des DIV

function AfficherBulle(tag, visible) {
	var strId = new String();
	var strTagId = new String();
	var strPrefix = new String();
	strTagId = tag.id;
	intPos = strTagId.lastIndexOf('_');
	strPrefix = strTagId.substr(0, intPos+1);
	strDivId = strPrefix + "div" + strTagId.substr(intPos+1, strTagId.length - (intPos+1));
	
	var divTag = document.getElementById(strDivId);
	divTag.style.width = '150px';
	if (visible) {
		divTag.style.visibility = 'visible';	
	}
	else divTag.style.visibility = 'hidden';			
}

function AfficherEtiquette(tag, visible) {
	var strId = new String();
	var strTagId = new String();
	var strPrefix = new String();
	strTagId = tag.id;
	intPos = strTagId.lastIndexOf('_');
	strPrefix = strTagId.substr(0, intPos+1);
	strDivId = strPrefix + "div" + strTagId.substr(intPos+1, strTagId.length - (intPos+1));
	
	var divTag = document.getElementById(strDivId);
	divTag.style.width = '150px';
	divTag.style.zindex = 1000;
	if (visible) {
		divTag.style.position = 'absolute';
		divTag.style.top = tag.style.top + 100;
		divTag.style.left = tag.style.left - 50;
		divTag.style.marginLeft = -100;
		divTag.style.visibility = 'visible';	
	}
	else divTag.style.visibility = 'hidden';			
}

function AfficherMenu(menu, visible)
{
	strAId = "header1_aOnglet"+menu;
	var aTag = document.getElementById(strAId);

	strDivId = "header1_menu"+menu;
	var divTag = document.getElementById(strDivId);
	
	strIframeId = "header1_menu"+menu+"I";
	var iFrameTag = document.getElementById(strIframeId);	

	if (visible) {
		divTag.style.visibility = 'visible';	
		divTag.style.top = aTag.style.top+149;
		divTag.style.marginLeft = -100;
		iFrameTag.style.visibility = 'visible';	
		iFrameTag.style.top = aTag.style.top+149;
		iFrameTag.style.marginLeft = -100;
	}
	else {
		divTag.style.visibility = 'hidden';			
		iFrameTag.style.visibility = 'hidden';			
	}
	
}

function AfficherImage(tag, visible) {
	var strId = new String();
	var strTagId = new String();
	var strPrefix = new String();
	strTagId = tag.id;
	intPos = strTagId.lastIndexOf('_');
	strPrefix = strTagId.substr(0, intPos+1);
	strDivId = strPrefix + "div" + strTagId.substr(intPos+1, strTagId.length - (intPos+1));
	
	var divTag = document.getElementById(strDivId);
	divTag.style.width = '150px';
	if (visible) {
		divTag.style.marginTop = -150;
		divTag.style.visibility = 'visible';	
	}
	else divTag.style.visibility = 'hidden';			
}

function OuvrirPopup(page, largeur, hauteur)
{
	var maFenetre = window.open(page,'zoom','toolbar=no,directories=no,menubar=no,scrollbars=no,width='+largeur+',height='+hauteur);
}

function RetrouverMotPasse(chemin)
{
	var maFenetre = window.open(chemin+'/email/MotPasseOublie.aspx','_blank','width=400,height=200');	
}

function JouerFlash()
{
	var fond = document.getElementById("Header1_imgFond");
	fond.style.visibility = 'hidden';
	fond.style.position = 'absolute';
	//var movie = document.getElementById("mast");
	var movie = window.document.mast;
	movie.style.visibility = 'visible';
	movie.style.position = 'relative';
	movie.LoadMovie(0, "/images/flash/mast.swf");
}

//Cette fonction appelle le click d'un bouton particulier lorsqu'on est dans un textbox et qu'on clique "enter"
function clickOnEnter(event,clickHandler)
{ 	

    NS4 = (document.layers) ? true : false;

	var code = 0;	

	if (NS4)

		code = event.which;

	else

		code = event.keyCode;
		
    
	if (code==13) //touche "enter"

	{
		clickObj = document.getElementById(clickHandler);
 
		if (clickObj)
		{	
		  clickObj.focus();
	      clickObj.click(); 
        }

		return(false);
	}

}
//Cette fonction appelle le click d'un bouton particulier lorsqu'on est dans un textbox et qu'on clique "enter"
function clickOnEnterAutoComplete(event,clickHandler)
{ 	

    NS4 = (document.layers) ? true : false;

	var code = 0;	

	if (NS4)

		code = event.which;

	else

		code = event.keyCode;
		
    
	if (code==13) //touche "enter"

	{
		clickObj = document.getElementById(clickHandler);
 
		if (clickObj)
		{	
		  clickObj.focus();
		  
		    var browser=navigator.appName;
            var b_version=navigator.appVersion;
            
            if(browser == "Microsoft Internet Explorer")
            {
                clickObj.click(); 
            }
		    else //pour FireFox. Le click ne marche pas lorsqu'on a un autocomplete extender 
		    {
		        simulateClick(clickObj);
                event.stopPropagation();
                event.preventDefault();
            }
		 }

		return(false);
	}

}
//Cette fonction appelle le focus d'un bouton particulier lorsqu'on est dans un textbox et qu'on clique "enter"
function focusOnEnter(event,clickHandler)
{ 
		clickObj = document.getElementById(clickHandler);

		if (clickObj){   clickObj.focus();}

		return(false);
}

// Efface le text au Focus
function clearText(obj)
{ 
	obj.value = "";		
}

// Efface le texte au Focus si le texte est celui par défaut. 
function clearDefautText(obj, texteParDefaut)
{ 
    if(obj.value == texteParDefaut)
    {
	    obj.value = "";	
	}	
}
