// Version de navigateur
var browser = navigator.appName;
var version = parseInt(navigator.appVersion);
var NS6=0,NS=0,MS=0;

// Javascript enable
var jvsenable = false;
var index_courant = "0";
if ( browser == "Microsoft Internet Explorer" && version > 3 ) MS = true;
if ( browser == "Netscape" && version > 3 && version < 5 ) NS = true;
if ( browser == "Netscape" && version > 5 ) NS6 = true;
jvsenable = MS||NS||NS6;

// ------------------------------------------------------------------------------------------------------------------------------

function clickPlusPanier(ID)
{
	document.cart_form.elements["PlusPanier"+ID].value=1;

	if (document.cart_form.URL_REDIRECT)
	{
	    var sep;
	    if (document.cart_form.action.indexOf('?', 1) > 0)
	       sep = '&';
	    else
	       sep = '?';

    	document.cart_form.URL_REDIRECT.value = document.cart_form.action
    	                                        + sep + 'PlusPanier' + ID + '=1&nbLigne='
    	                                        + document.cart_form.nbLigne.value
    	                                        + '&src=' + document.cart_form.src.value
    	                                        + '&RefArt' + ID + '=' + document.cart_form.elements['RefArt'+ID].value;
	}

	document.cart_form.submit();
}

// ------------------------------------------------------------------------------------------------------------------------------

function SwitchImg (im,sr)
{
	if (jvsenable)
		document[im].src = sr;
}

// ------------------------------------------------------------------------------------------------------------------------------

function ouvrirPreselection(refArticle)
{
    var url = "popupPreselections.php?refArticle="+refArticle;
    var mode = "menubar=no,location=no,directories=no,status=no,toolbar=no,scrollbars=yes,width=255,height=300";
    window.open(url,"popupPreselection",mode);
}

// ------------------------------------------------------------------------------------------------------------------------------

function ouvrirTarifPersonnalise(refArticle)
{
    var url = "popupTarifPersonnalise.php?refArticle="+refArticle;
    var mode = "menubar=no,location=no,directories=no,status=no,toolbar=no,scrollbars=yes,width=300,height=300";
    window.open(url,"popupTarifPersonnalise",mode);
}

// ------------------------------------------------------------------------------------------------------------------------------

function validerTarifPublic()
{
	document.prixPerso_form.action = document.prixPerso_form.actionValider.value;
}

// ------------------------------------------------------------------------------------------------------------------------------

function tousAuMemePrix()
{
	document.prixPerso_form.action = document.prixPerso_form.actionTousAuMemePrix.value;
}

// ------------------------------------------------------------------------------------------------------------------------------

function ouvrirImage(image)
{
    var url = "popupImage.php?image="+image;
    var mode = "menubar=no,location=no,directories=no,status=no,toolbar=no,scrollbars=no,width=200,height=200";
    window.open(url,"popupImage",mode);
}

// ------------------------------------------------------------------------------------------------------------------------------

function ouvrirMedia(type,media,width,height)
{
    var url = "popupMedia.php?type="+type+"&media="+media+"&width="+width+"&height="+height;
    var mode = "menubar=no,location=no,directories=no,status=no,toolbar=no,scrollbars=no,width="+width+",height="+height;
    window.open(url,"popupMedia"+type,mode);
}

// ------------------------------------------------------------------------------------------------------------------------------

function ouvrirCommentaire(refArticle,dimArticle)
{
    var url = "popupCommentaire.php?refArticle="+refArticle+"&dimArticle="+dimArticle;
    var mode = "menubar=no,location=no,directories=no,status=no,toolbar=no,scrollbars=yes,width=300,height=200";
    window.open(url,"popupCommentaire",mode);
}

// ------------------------------------------------------------------------------------------------------------------------------

function ouvrirCommentaireDyn(refArticle,dimArticle, commentaire)
{
    document.fCom.refArticle.value = refArticle;
    document.fCom.dimArticle.value = dimArticle;
    document.fCom.commentaire.value = commentaire;

    $('#popup_commentaire').fadeIn(500);
}

// ------------------------------------------------------------------------------------------------------------------------------

function ouvrirGravure(refArticle,dimArticle)
{
    var url = "popupGravure.php?refArticle="+refArticle+"&dimArticle="+dimArticle;
    var mode = "menubar=no,location=no,directories=no,status=no,toolbar=no,scrollbars=yes,width=300,height=200";
    window.open(url,"popupGravure",mode);
}

// ------------------------------------------------------------------------------------------------------------------------------

function ouvrirGravureDyn(refArticle,dimArticle, texte, police)
{
    document.fGrav.refArticle.value = refArticle;
    document.fGrav.dimArticle.value = dimArticle;
    document.fGrav.texte0.value = texte;
    document.fGrav.police0.value = police;

    $('#popup_gravure').fadeIn(500);
}

// ------------------------------------------------------------------------------------------------------------------------------

function retaillerFenetre()
{
    window.focus();
    window.resizeTo(document.images[0].width+10,document.images[0].height+29);
}

// ------------------------------------------------------------------------------------------------------------------------------

function nouvelleFenetre(url,width,height)
{
	var mode = "menubar=no,location=no,directories=no,status=no,toolbar=no,scrollbars=yes,width="+width+",height="+height;
    window.open(url,"nouvelleFenetre",mode);
}

// ------------------------------------------------------------------------------------------------------------------------------

function transfertPanier()
{
	document.cart_form.action = document.cart_form.actiontransfert.value;
}

// ------------------------------------------------------------------------------------------------------------------------------

function validationPanier()
{
	document.cart_form.action = document.cart_form.actionvalidation.value;
}

// ------------------------------------------------------------------------------------------------------------------------------

function viderPanier(texte)
{
    if (confirm(texte))
    {
        document.cart_form.action = document.cart_form.actionvider.value;
    }
}

// ------------------------------------------------------------------------------------------------------------------------------

function confirmationAjoutPanier(texte)
{
	alert(texte);
}

// ------------------------------------------------------------------------------------------------------------------------------

function validerCommande(texte)
{
	if (document.valid_form.ignorerCGV.value == "N" && !document.valid_form.okCGV.checked)
		{
		alert (texte);
		return (false);
		}
	document.valid_form.Action.value = document.valid_form.ActionValider.value;
	document.valid_form.CGV.value=""; // On ne remonte pas les CGV au serveur
	return (true);
}

// ------------------------------------------------------------------------------------------------------------------------------

function changerAdresse()
{
	document.valid_form.CGV.value=""; // On ne remonte pas les CGV au serveur
	document.valid_form.submit();
}

// ------------------------------------------------------------------------------------------------------------------------------

function actionCT(url)
{
	document.cart_form.action = url;

	if (document.cart_form.URL_REDIRECT)
	{
	   document.cart_form.URL_REDIRECT.value = url + '&nbLigne='
	                                           + document.cart_form.nbLigne.value
	                                           + '&src=' + document.cart_form.src.value;
	}

	document.cart_form.submit();
}

// ------------------------------------------------------------------------------------------------------------------------------

function show_props_win(obj)
{
var result = "<B>Eléments de l'objet :</B><BR><BR><PRE>\n";
    for (var i in obj)
        {
        result += "\t." + i + " = " + obj[i] + "<BR>"
        }
    w = window.open();
    w.document.write(result);
}

// ------------------------------------------------------------------------------------------------------------------------------

function popupPreselectionCatalogue(ref, champ, valeur, art_hac2)
{
    $('#popup_preselection').fadeOut(500,
        function ()
        {
            document.fPresel.ref_article.value = ref;
            document.fPresel.champ.value = champ;
            document.fPresel.valeur.value = valeur;
            document.fPresel.art_hac2.value = art_hac2;
            document.fPresel.URL_REDIRECT.value = 'index.php?Action=catalogue&Etape=liste_menu&champ=' + champ + '&valeur='
                                                  + valeur + '&art_hac2=' + art_hac2 + '&page=' + document.fPresel.page.value;

            document.fPreselAjout.ref_article.value = document.fPresel.ref_article.value;
            document.fPreselAjout.champ.value = document.fPresel.champ.value;
            document.fPreselAjout.valeur.value = document.fPresel.valeur.value;
            document.fPreselAjout.art_hac2.value = document.fPresel.art_hac2.value;
            document.fPreselAjout.URL_REDIRECT.value = document.fPresel.URL_REDIRECT.value;

            document.getElementById('popup_preselection').style.top = document.documentElement.scrollTop + 150 + 'px';
            document.getElementById('popup_preselection').style.left = (window.document.body.clientWidth - 970)/2 + 'px';

            $('#popup_preselection').fadeIn(500, function() {

                if (($.browser.msie) && ($.browser.version.substr(0,1) < 7))
                {
                    // Sous IE6, on met un iframe vide derrière le popup
                    // pour masquer les SELECT
                    var pt = $('#table_presel').position();
                    var left_table = pt.left;
                    var top_table = pt.top;

                    $('#table_presel').css('position', 'absolute');
                    $('#table_presel').css('left', left_table);
                    $('#table_presel').css('top', top_table);

                    $('#ifr_presel').css('left', left_table + 10 + 'px');
                    $('#ifr_presel').css('top', top_table + 10 + 'px');
                    $('#ifr_presel').width($('#table_presel').width() - 20);
                    $('#ifr_presel').height($('#table_presel').height() - 20);

                    $('#ifr_presel').show();
                }
            });
        } );
}

// ------------------------------------------------------------------------------------------------------------------------------

function chr(ascii)
{
    return String.fromCharCode(ascii);
}

// ------------------------------------------------------------------------------------------------------------------------------
