/*
######################################
Fonction de vérification du browser
made in Bratta, http://www.bratta.com
merci à lui pour son talent technique
######################################
*/

function lib_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

// This popup is opened by MultiMedia.renderListenAndSeeLink
function openMediaPopup(adresse)
{
refMultimediaPopup=window.open(adresse,'MultimediaPopUp','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=560,height=460');
refMultimediaPopup.focus();
}

// This popup is opened in order to render a pictureGallery
function openPictGalleryPopup(adresse)
{
refMultimediaPopup=window.open(adresse,'MultimediaPopUp','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=720,height=550');
refMultimediaPopup.focus();
}

// This popup is opened by Image.renderListenAndSeeLink 
function openImagePopup(adresse)
{
refImagePopup=window.open(adresse,'ImagePopUp','toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=560,height=460');
refImagePopup.focus();
}

// This popup is opened by Shop_Product.renderBigFormatPopup
function openBigFormatPopup(adresse)
{
refImagePopup=window.open(adresse,'ImagePopUp','toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0,width=320,height=500');
refImagePopup.focus();
}


function winOpen(adresse)
{
window.open(adresse,'PopUp','toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=700,height=450');
}

function winOpenImp(adresse)
{
window.open(adresse,'PopUp','toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=700,height=450');
}

function winOpen2(adresse)
{
window.open(adresse,'PopUp','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=560,height=460');
}


//var NS = (navigator.appName == "Netscape");
function printit(){
 self.print();
}

function chercheAncre(ancre) {	
	myY=chercheY(ancre)
	mainDiv4.scrollBy(-10000000)
	mainDiv4.scrollBy(myY)
}

function chercheY(MyImg) {
	if(document.all)
	{
		return document.images[MyImg].offsetTop+document.images[MyImg].offsetParent.offsetTop+document.images[MyImg].offsetParent.offsetParent.offsetTop+document.images[MyImg].offsetParent.offsetParent.offsetParent.offsetTop
	}
	if(document.layers)
	{
		return document.mainContentDiv4.document.images[MyImg].y
	}
	return document.images[MyImg].y
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset)
			// set index of end of cookie value
			if (end == -1)
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value)
	+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
	+";path=/"
}

function setCookieMaxExpire(name,value) {
    var today = new Date();
	var expires = new Date();
    expires.setTime(today.getTime() + 1000*60*60*24*30) ;
    setCookie(name,value,expires);
}

/*
function certify(somme)
{

testleftm = parseInt(somme); // on m?morise la partie enti?re de la valeur
testright = somme - testleftm; // on soustrait la valeur par la partie enti?re
fixright = (Math.round(testright*100))/100; // on arrondit ? 2 chiffres la partie d?cimale
if (fixright) // si on a une valeur apr?s la virgule
    {
    if (fixright*100 % 10) // si c'est un modulo de 10
      {
      return Math.round((eval(testleftm)+eval(fixright))*100)/100;
      }
    else // si ce n'est pas un modulo de 10
      {
      return (eval(testleftm)+eval(fixright) + '0');
      }
    }
else // si la valeur pass?e est un entier
    {
  return (eval(testleftm)+eval(fixright));
    }

    return somme.toFixed(2);
}
*/

function certify(x) {
  var k = (Math.round(x * 100) / 100).toString();
  k += (k.indexOf('.') == -1)? '.00' : '00';
  return k.substring(0, k.indexOf('.') + 3);
}


function addItem(productId, priceToAdd, countToAdd, webosite, webozone, webopage) {
	if ((countToAdd != null) && (countToAdd != 0) && (countToAdd != ''))
		var sumToAdd = parseFloat(priceToAdd) * parseFloat(countToAdd);
	else
		var sumToAdd = parseFloat(priceToAdd);
		var currentCookie = getCookie("sc_curArray");
		if (null != currentCookie) {
			var indexProduct = currentCookie.indexOf(productId+"/",0);
			if ( indexProduct != -1) {
			var indexBegin = currentCookie.indexOf("/",indexProduct) + 1;
			var indexEnd = currentCookie.indexOf("*",indexBegin);
			var productNumber = parseInt(currentCookie.substring(indexBegin,indexEnd)) + 1;
			var newCookie=currentCookie.substring(0,indexProduct)+currentCookie.substring(indexEnd+1,currentCookie.length)+productId+'/'+productNumber+'*';
			setCookieMaxExpire("sc_curArray", newCookie);
		} else {
			setCookieMaxExpire("sc_curArray", currentCookie + productId + '/' + countToAdd + '*');
		}
	}
	else {
		setCookieMaxExpire("sc_curArray", productId + '/' + countToAdd + '*');
	}

	currentPrice = getCookie("sc_curTotalPrice");
	if ((null != currentPrice) && (0 != currentPrice)) {
		setCookieMaxExpire("sc_curTotalPrice", certify(parseFloat(currentPrice) + parseFloat(sumToAdd)));
	}
	else {
		setCookieMaxExpire("sc_curTotalPrice", certify(parseFloat(sumToAdd)));
	}

	currentNbArticles = getCookie("sc_curProdNum");  
	if ((null != currentNbArticles) && (0 != currentNbArticles)) {
		setCookieMaxExpire("sc_curProdNum", parseInt(currentNbArticles) + parseInt(countToAdd));
	}
	else {
		setCookieMaxExpire("sc_curProdNum", parseInt(countToAdd));
	}
	// call weborama stat 
	//webo_zpi(webozone,webopage,webosite);
	// reload page in order to update basket content section on the left
	history.go(0);

    // call Xiti
    return xt_click(this, 'F', 5, 'in_warenkorb_legen::id_'+productId);
}

var delay=1000;
//pour ns4 le script affiche directement la string1
function togglePrice(ID,string1,string2,indice){
	if(document.layers)
		document.write(string1);
	else{
		indice=(indice==null)?1:indice;
		document.getElementById(ID).innerHTML=eval('string'+indice);
		indice=(indice==1)?2:1;
		setTimeout('togglePrice(\''+ID+'\',\''+string1+'\',\''+string2+'\','+indice+')',delay);
	}
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function startPrintArte(){
  var bw=new lib_bwcheck();
  if(!bw.mac){
    print();
    setTimeout("close()", 1);
  }
}

function setfocus() {
    try {
        if (document.getElementById("defsubmitcmd")) document.getElementById("defsubmitcmd").focus();
        if (document.getElementById("ordercmd")) document.getElementById("ordercmd").focus();
    } catch (Exception) {}
}
