var IE = ( navigator.appName == 'Microsoft Internet Explorer' ? 1 : 0 ); function lowest_price() { var lowest = -1; for( var i = 0; i < T.length; i++ ) if ( lowest == -1 || T[i][1] < lowest ) lowest = T[i][1]; return lowest; } /*function rabais() { var i = 0; var TA = 0; var IM = -1; for( i=0; i < T.length; i++ ) { TA += parseInt( T[i][3] ); if ( IM == -1 || T[i][1] < T[IM][1] && T[i][3] ) IM = i; } if ( IM != LID && LID != -1 || TA >= 2 ) { document.getElementById('qte_'+T[IM][0]).innerHTML = '
(' + Math.floor( TA / 2 ) + ' gratuit)'; document.getElementById('prix_'+T[IM][0]).innerHTML=arrondi2Str((T[IM][1]*(T[IM][3]-1))); T[IM][4] = 1; LID = IM; RA = 1; }else if ( RA ) { document.getElementById('qte_'+T[IM][0]).innerHTML = ''; document.getElementById('prix_'+T[IM][0]).innerHTML=arrondi2Str(T[IM][1]*(T[IM][3])); T[IM][4] = 0; RA = 0; } }*/ PG = 0; UID = PG; function strDataToArr( data ) { var arrItems = data.split( "\n" ); var arrData = Array(); for( var i = 0; i < arrItems.length - 1; i++ ) { arrData[i] = arrItems[i].split( "|" ); } return arrData; } function getStartPosFree() { var articles = document.getElementById('articles'); for( var posDebut = 1; ; posDebut++ ) if ( articles.rows[ posDebut ].id.substr(0,3) != 'TR_' ) break; return posDebut; } function updateTableArticlesGratuit( qte ) { if ( qte == PG ) return; var articles = document.getElementById('articles'); var posDebut = getStartPosFree(); if ( qte > PG ) { var txt = Array(); txt[ 0 ] = ''; txt[ 1 ] = '

'; txt[ 2 ] = listeProduit; txt[ 4 ] = "Offert par Nua Cosmétique"; for( var i = 0; PG + i < qte; i++ ) { var tr = articles.insertRow( posDebut + PG ); tr.id = "TG_0_" + UID++; for( var td, ii = 0; ii < 5; ii++ ) { td = tr.insertCell( ii ); if ( !txt[ ii ] || typeof( txt[ ii ] ) == "string" || typeof( txt[ ii ] ) == "undefined" ) td.innerHTML = ( txt[ ii ] ? txt[ ii ] : ' ' ); else { var select = txt[ ii ].cloneNode(true); select.options[ select.options.length - 1 ].setAttribute( 'selected', 'selected' ); td.appendChild( select ); // IE if ( IE ) { document.getElementById( tr.id ).getElementsByTagName('select')[0].selectedIndex = select.options.length - 1; document.getElementById( tr.id ).getElementsByTagName('select')[0].onchange = function () { editFreeProduct(this.parentNode.parentNode,this.value); } } } } } } else { qteEffacer = 0; for( var i = posDebut + PG - 1; i >= posDebut && qteEffacer < PG - qte; i-- ) { if ( nameToID( articles.rows[ i ].id ) == 0 ) { articles.deleteRow( i ); qteEffacer++; } } for( var i = posDebut + PG - 1 - qteEffacer; i >= qte + posDebut; i-- ) { var tr = articles.deleteRow( i ); } } PG = qte; } var listeProduit = 0; function editInfoProduit(newID, msg) { var infoProduit = strDataToArr( msg ); var produit = document.getElementById( newID ); var articles = document.getElementById('articles'); var posBase = getStartPosFree(); for( var i = 0; i < PG; i++, posBase++ ) { if ( articles.rows[ posBase ].id == newID ) break; } if ( i == PG ) return; articles.rows[ posBase ].cells[ 0 ].getElementsByTagName( 'img' )[0].src = '/files/boutique/' + infoProduit[0][ 0 ]; articles.rows[ posBase ].cells[ 1 ].getElementsByTagName( 'h1' )[0].innerHTML = infoProduit[0][ 1 ]; } function askInfoProduct( html, id ) { $.ajax({url: "/ajax.php?ajax=info_produit&id="+id, success: function(msg) { editInfoProduit(html.id,msg); } }); } function editFreeProduct( html, newID ) { var oldID = nameToID( html.id ); $.ajax({async: false, url: "/ajax.php?ajax=add_panier_free&id_article="+newID+"&id_ancien_article="+oldID}); html.id = 'TG_' + newID + '_' + nameToUID( html.id ); askInfoProduct( html, newID ); return true; } function askRefreshFreeProductList() { $.ajax({async: false, url: "/ajax.php?ajax=liste_produits_gratuit", success:function(msg){ updateFreeProductList( msg ); }}); return true; } function nameToID( name ) { return name.match( /^T._(-?[0-9]+)(_[0-9]+)?$/i )[1]; } function nameToUID( name ) { return name.match( /^T._-?[0-9]+_([0-9]+)$/i )[1]; } function updateFreeProductList( data ) { // Création var posFree = getStartPosFree(); var articles = document.getElementById('articles'); for( var i = 0; i < PG; i++ ) { var tmpListeProduit = listeProduit.cloneNode(true); var val = document.createAttribute( 'value' ); var pos = posFree + i; val.nodeValue = ( articles.rows[ pos ].cells[ 2 ].select && articles.rows[ pos ].cells[ 2 ].select.value ? articles.rows[ pos ].cells[ 2 ].select.value : nameToID( articles.rows[ pos ].id ) ); tmpListeProduit.setAttributeNode( val ); for( var ii = 0; ii < tmpListeProduit.options.length; ii++ ) { if ( ii == tmpListeProduit.options.length - 1 ) val.nodeValue = 0; if ( tmpListeProduit.options[ ii ].value == val.nodeValue ) { val = document.createAttribute( "selected" ); val.nodeValue = "selected"; tmpListeProduit.options[ ii ].setAttributeNode( val ); break; } } articles.rows[ pos ].cells[ 2 ].innerHTML = ''; articles.rows[ pos ].cells[ 2 ].appendChild( tmpListeProduit.cloneNode(true) ); if ( IE ) { articles.rows[ pos ].cells[ 2 ].getElementsByTagName('select')[0].selectedIndex = ii; articles.rows[ pos ].cells[ 2 ].getElementsByTagName('select')[0].onchange = function () { editFreeProduct(this.parentNode.parentNode,this.value); } } } } function _update_panier( produits, produitsGratuit ) { var NP = lowest_price(); if ( NP != LP ) { askRefreshFreeProductList(); LP = NP; } updateTableArticlesGratuit( produitsGratuit ); } LP = -1; RA = 0; LID = -1; T = new Array(); R = new Array(); function rabais_global( prix ) { return arrondi( prix * 0 ); } function calcul_prix(id,prix,poids,num) { if ( typeof(R[id]) == 'undefined' ) { T.push(new Array(id,prix,poids,num,0)); R[id] = T.length-1; } else { T[R[id]]=new Array(id,prix,poids,num,0); } document.getElementById('prix_'+id).innerHTML=(taxe(prix,1)*num); return true; } function arrondi(val) { return Math.round(val*100)/100; } function taxe(val,t) { return arrondi(val * (0.196 + ( t ))); } function arrondi2Str(val) { var N = arrondi( val ); var A = new String( N ).split( new RegExp( '\\.' ) ); if ( A.length < 2 ) A[1] = '00'; if ( !A.length ) A[0] = '0'; if ( A[1].length != 2 ) for ( var i = 2 - A[1].length; i > 0; i-- ) A[1] += '0'; return A.join('.'); } function calcul_total() { //rabais(); c=0; tva=0; p=0; rabais=0; for(i=0;i