//-- Module d'affichage des info bulles + high light

function highlightWord(node,word) {

// Iterate into this nodes childNodes
if (node.hasChildNodes) {
var hi_cn;
for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++)
highlightWord(node.childNodes[hi_cn],word);
}
// And do this node itself

if (node.nodeType == 3) { // text node
tempNodeVal = node.nodeValue.toLowerCase();
tempWordVal = word.toLowerCase();
if (tempNodeVal.indexOf(tempWordVal) != -1) {
pn = node.parentNode;
if (pn.className != "searchword") {
// word has not already been highlighted!
nv = node.nodeValue;
ni = tempNodeVal.indexOf(tempWordVal);
// Create a load of replacement nodes

before = document.createTextNode(nv.substr(0,ni));
docWordVal = nv.substr(ni,word.length);
after = document.createTextNode(nv.substr(ni+word.length));
hiwordtext = document.createTextNode(docWordVal);
hiword = document.createElement("span");
hiword.className = "searchword";
hiword.appendChild(hiwordtext);
pn.insertBefore(before,node);
pn.insertBefore(hiword,node);
pn.insertBefore(after,node);
pn.removeChild(node);
}
}
}
}
function googleSearchHighlight() {

 if (!document.createElement) return;
 ref = document.referrer;
 if (ref.indexOf('?') == -1) return;

 qs = ref.substr(ref.indexOf('?')+1);

 qsa = qs.split('&');

 for (i=0;i<qsa.length;i++) {

 qsip = qsa[i].split('=');

 if (qsip.length == 1) continue;

 if (qsip[0] == 'q' || qsip[0] == 'p' || qsip[0]=='sp-q') { // q= for Google, p= for Yahoo, sp-q for Atomz

 words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);

 for (w=0;w<words.length;w++) 

 highlightWord(document.getElementsByTagName("body")[0],words[w]);

 }
 }
}

function setOptionQty (cid,product_id,quantity) {

var inputPid = document.getElementById('frmOptionPid')

var inputPCid = document.getElementById('frmOptionPCid')

var inputQty = document.getElementById('frmOptionQty')

arrayPid = inputPid.value.split(',')

arrayPCid = inputPCid.value.split(',')

arrayQty = inputQty.value.split(',')

//mise a jour de toutes les qtes

var totalPriceOptions = 0;

for (j=0;j<arrayPid.length;j++) {

tmpcid = arrayPCid[j]

tmpproduct_id = arrayPid[j]

if (document.getElementById('pm' + tmpcid + tmpproduct_id)) {

arrayQty[j] = document.getElementById('pm' + tmpcid + tmpproduct_id).value

totalPriceOptions += document.getElementById('priceOptions' + tmpcid + tmpproduct_id).value * arrayQty[j]

//mise a jour de l'affichage pour que les qtés correspondent a ce qui est affiché (pour firefox)

plusmoins(tmpcid,tmpproduct_id)

}

}

inputQty.value = arrayQty.join(',')

document.getElementById('totalOption2').innerHTML = document.getElementById('totalOption').innerHTML = totalPriceOptions.toFixed ? totalPriceOptions.toFixed(2) : parseInt(totalPriceOptions*100)/100 

}

function plusmoins(cid,product_id,type) {

var qte = document.getElementById('pm' + cid + product_id)

var plus1 = document.getElementById('plus1' + cid + product_id)

var plus2 = document.getElementById('plus2' + cid + product_id)

var fois1 = document.getElementById('fois1' + cid + product_id)

var fois2 = document.getElementById('fois2' + cid + product_id)

if (type==2) {

qte.value = parseInt(qte.value) + 1

}

if (type==1 && parseInt(qte.value)>0) {

qte.value = parseInt(qte.value) - 1

}

if (qte.value == 0) {

plus1.style.display = 'none'

plus2.style.display = 'none'

}

if (qte.value > 0) {

plus1.style.display = 'inline'

plus2.style.display = 'inline'

}

if (qte.value == 1) {

fois1.innerHTML = ''

fois2.innerHTML = ''

}

if (qte.value > 1) {

fois1.innerHTML = 'x ' + qte.value

fois2.innerHTML = 'x ' + qte.value

}

if (type == 1 || type == 2 ) setOptionQty(cid,product_id,qte.value)

}
function argItems (theArgName) {

sArgs = location.search.slice(1).split('&');

r = '';

for (var i = 0; i < sArgs.length; i++) {

if (sArgs[i].slice(0,sArgs[i].indexOf('=')) == theArgName) {

r = sArgs[i].slice(sArgs[i].indexOf('=')+1);

break;

}

}

return (r.length > 0 ? unescape(r).split('|') : '')

}

function prevnext(type) {

var pn = ''

var pl = argItems('pl')

var pid = argItems('product_id')

if (!pid) {

sPaths = location.pathname.slice(1).split('/')

var pid = sPaths[sPaths.length -1].substr(0,sPaths[sPaths.length -1].indexOf('-'))

}

if (pl != '' && pl.length > 1) {

for(var i=0;i<pl.length;i++) {

if (pl[i] == pid) {

if (type=='p' && i>0) pn = pl[i-1]

if (type=='n' && i<pl.length-1) pn = pl[i+1]

}

}

}

return pn

}

function purchase(cidoption,pid){document.forms['purchase' + cidoption + pid].submit()}

function poppurchase() {document.forms['purchase'].submit()}

function caddie() {opener.location.href="/info/basket/t_caddie.cfm";opener.focus();self.close();}
function Check_garanties(){

if ("undefined" == typeof(document.forms['garanties_1'])) {return true;}

else

{

if(document.forms['garanties_1'].ext.checked == true)

{

document.forms['garanties_1'].submit();

return false;

}

if(document.forms['garanties_2'].ext.checked == true)

{

document.forms['garanties_2'].submit();

return false;

}

return true;

}

}
function Checkboxes(id){

if (id == 1){

if(document.forms['garanties_1'].ext.checked == true){document.forms['garanties_2'].ext.checked = false;}

}

if (id == 2){

if(document.forms['garanties_2'].ext.checked == true){document.forms['garanties_1'].ext.checked = false;}

}

}
function popupXL(source){

xlimage = document.getElementById('xl');

xlimage.style.display='block';

}
function popupXL2(of) {

var xlContStyle = document.getElementById('xlCont').style

xlContStyle.display='block';

if (of && document.getElementById('xlImg').height > 400) {

with (xlContStyle) {

height='400px';

width=(parseInt(document.getElementById('xlImg').width) + 20) + 'px';

overflow='auto'

}

}

}

function showpopDesc(idpopdesc,e) {

var posx = 0;

var posy = 0;

if (!e) var e = window.event;

if (e.pageX || e.pageY){

posx = e.pageX;

posy = e.pageY;

}

else if (e.clientX || e.clientY) {

posx = e.clientX + document.body.scrollLeft;

posy = e.clientY + document.body.scrollTop;

}
with (document.getElementById(idpopdesc).style) {

display='block';

left = posx;

top = parseInt(posy);

}

}
function hidepopDesc(idpopdesc) {

document.getElementById(idpopdesc).style.display='none';

}
function showpopSort(e,memo) {

var posx = 0;

var posy = 0;

if (!e) var e = window.event;

if (e.pageX || e.pageY){

posx = e.pageX;

posy = e.pageY;

}

else if (e.clientX || e.clientY) {

posx = e.clientX + document.body.scrollLeft;

posy = e.clientY + document.body.scrollTop;

}

with (document.getElementById(memo).style) {

display='block';

//left = parseInt(posx)+10 - ((senes == 'g') ? 320 : 0);;

//top = parseInt(posy) - 25;

}

}
function hidepopSort(memo) {

with (document.getElementById(memo).style) {
display='none';

}

}
function opt(monde,pid,t){
window.open('/'+monde+'/showdetl.cfm?product_id='+pid+'&option='+t+((t==3) ?'&cs=1' :'') + '&pid=374053&pcid=4', 'Option', 'height=450,width=400,top=20,left=20,resizable=yes,scrollbars=yes')

}
window.onload = googleSearchHighlight;