
function check_str(value,msg_error){
	if(value == ""){
		alert(msg_error);
		return 1;
	}
	return 0;
}
function Check(e) {
	e.checked = true;
}
function Clear(e) {
	e.checked = false;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


/******* CAttribut *******/
function CAttItem (code_ean, option_id){
	this.Datas = new Array;
	this.EAN = code_ean;
	this.OptID = option_id;
}
CAttItem.prototype.AddProperty = function (attribut_id, attribut_detail_id, majoration_prix, qte_stock){
	newID = this.Datas.length;
	this.Datas[newID] = new Array;
	this.Datas[newID]["AttDetailID"] = attribut_detail_id;
	this.Datas[newID]["AttID"] = attribut_id;
	this.Datas[newID]["MajPrix"] = majoration_prix;
	this.Datas[newID]["Stock"] = qte_stock;
}


function CAttribut (ObjectName, pagesURL){
	this.ObjectName = ObjectName;
	
	this.DelaiLivTag = "DelaiLivTag";
	this.StockTag = "StockTag";
	this.MajorationTag = "MajorationTag";
	this.AttSelectID = "sel_attrib_id";
	this.AttSelectName = "sel_attrib";
	this.DefaultValue = "----------";
	this.HiddenOptID = "option_id";
	this.HiddenEAN = "code_ean";

	this.PrixBase = 0;
	this.Devise = "EUR";
	this.Majoration = 0;
	this.pagesURL = pagesURL;
	this.SelectOK = false;
	
	this.s_DelaiLiv = 0;
	this.DelaiLiv = new Array;
	this.DelaiLiv[0] = new Array;
	this.DelaiLiv[1] = new Array;
	this.DelaiLiv[2] = new Array;
	this.DelaiLiv[3] = new Array;
	this.DelaiLiv[4] = new Array;
	this.DelaiLiv[5] = new Array;
	this.DelaiLiv[6] = new Array;
	this.DelaiLiv[0][0] = 1;
	this.DelaiLiv[1][0] = 2;
	this.DelaiLiv[2][0] = 3;
	this.DelaiLiv[3][0] = 4;
	this.DelaiLiv[4][0] = 5;
	this.DelaiLiv[5][0] = 6;
	this.DelaiLiv[6][0] = 7;
	
	this.EANList = new Array;
	this.AttArbo = new Array;
	this.AttArboDef = new Array;
	
	/* fabrication arbo */
	this.PrevEAN = "";
	this.cItem = 0;
	this.levelCount = 0;
	
	this.SelectedList = new Array;
}

CAttribut.prototype.SetEANHiddenInput = function (InputName){
	this.HiddenEAN = InputName
}
CAttribut.prototype.SetOptionIDHiddenInput = function (InputName){
	this.HiddenOptID = InputName
}
CAttribut.prototype.SetAttSelectName = function (InputName){
	this.AttSelectName = InputName
}
CAttribut.prototype.SetMajorationTag = function (InputName){
	this.MajorationTag = InputName
}
CAttribut.prototype.SetDefaultOption = function (Libelle){
	this.DefaultValue = Libelle
}

CAttribut.prototype.SetDelaiLivText = function (DelaiID, DelaiText){
	for(i=0; i<this.DelaiLiv.length; i++){
		if(this.DelaiLiv[i][0] == DelaiID)
			this.DelaiLiv[i][1] = DelaiText;
	}
}

CAttribut.prototype.Add = function (libelle, attribut_id, libelle_opt, attribut_detail_id, majoration_prix, qte_stock, code_ean, tri, option_id){
	
	if(this.PrevEAN != code_ean){
		this.cItem = this.EANList.length;
		this.EANList[this.cItem] = new CAttItem(code_ean, option_id);
		this.PrevEAN = code_ean;
	}
	this.EANList[this.cItem].AddProperty(attribut_id, attribut_detail_id, majoration_prix, qte_stock);
	
	ItemDatasCount = this.EANList[this.cItem].Datas.length-1;
	this.NewArboEntry(this.AttArbo, 0, ItemDatasCount, libelle_opt, attribut_detail_id, code_ean, libelle, attribut_id);
}

CAttribut.prototype.NewArboEntry = function (Arbo, cLevel, ToLevel, eText, eID, EAN, eDef, eDefID){
	if(cLevel < ToLevel){
		this.NewArboEntry(Arbo[this.EANList[this.cItem].Datas[cLevel]["AttDetailID"]][0], cLevel+1, ToLevel, eText, eID, EAN, eDef, eDefID);
		return;
	}else{
		if(cLevel > this.levelCount) this.levelCount = cLevel;
	
		found = false;
		for(var i in Arbo){
			if(i == eID){
				found = true;
				break;
			}
		}
		
		if(found){
			Arbo[eID][2][Arbo[eID][2].length] = EAN;
		}else{
			Arbo[eID] = new Array;
			Arbo[eID][0] = new Array;
			Arbo[eID][1] = eText;
			Arbo[eID][2] = new Array;
			Arbo[eID][2][0] = EAN;
			
			if(cLevel+1 > this.AttArboDef.length){
				this.AttArboDef[cLevel] = new Array;
				this.AttArboDef[cLevel][0] = eDefID;
				this.AttArboDef[cLevel][1] = eDef;
			}
		}
	}
}

CAttribut.prototype.RefreshCombo = function (Level, Value){
	//if(Value == 0) return true;
	

	var ArboNode = new Array;
	ArboNode[0] = this.AttArbo;

	if(Level == this.levelCount){

		for(i=0; i<this.SelectedList.length; i++){
			ArboNode = ArboNode[0][this.SelectedList[i]];
		}
		for(i=0; i<this.EANList.length; i++){
			if(this.EANList[i].EAN == ArboNode[2][0]){
				var divMajor = document.getElementById(this.MajorationTag);
				divMajor.innerHTML = this.EANList[i].Datas[Level]["MajPrix"] + " " + this.Devise;
				eval("document.forms['basketform'].elements['"+this.HiddenOptID+"'].value = '" + this.EANList[i].OptID + "'");
				eval("document.forms['basketform'].elements['"+this.HiddenEAN+"'].value = '" + this.EANList[i].EAN + "'");
				this.SelectOK = true;
				break;
			}
		}
		return true;
	}else{
		eval("document.forms['basketform'].elements['"+this.HiddenEAN+"'].value = ''");
		eval("document.forms['basketform'].elements['"+this.HiddenOptID+"'].value = 0");
		var divMajor = document.getElementById(this.MajorationTag);
		divMajor.innerHTML = "NC";
	}
	this.SelectOK = false;
	
	if(this.SelectedList.length > Level)
		while(this.SelectedList.length > Level){
			document.getElementById(this.AttSelectID + (this.SelectedList.length)).options.length = 1;
			this.SelectedList.pop();
		}
	this.SelectedList.push(Value);
	
	
	var ISelect = document.getElementById(this.AttSelectID + (Level+1));
	ISelect.options.length = 1;
	if(Value == 0) return true;

	for(i=0; i<this.SelectedList.length; i++){
		ArboNode = ArboNode[0][this.SelectedList[i]];
	}
	
	//ISelect.options[ISelect.options.length] = new Option(this.DefaultValue, 0);
	for(var i in ArboNode[0]){
		ISelect.options[ISelect.options.length] = new Option(ArboNode[0][i][1], i);
	}
	
	//auto select des prochains combo, si plus qu'un choix dispo
	if(ArboNode[2].length == 1){
		var NextAttID = 0;
		for(NextAttID in ArboNode[0]){}
		ISelect.selectedIndex = 1;
		this.RefreshCombo(Level+1, NextAttID);
	}

	return true;
}

CAttribut.prototype.DisplayCombo = function (AttributID) {
	var Opts = ""
	
	for(i=0; i<this.AttArboDef.length; i++){
		if(AttributID == this.AttArboDef[i][0]){

			document.write("<select id='"+this.AttSelectID+""+i+"' name='"+this.AttSelectName+this.AttArboDef[i][0]+"' onchange='"+this.ObjectName+".RefreshCombo("+i+", this.value)'>");
			document.write("<option value='0'>"+this.DefaultValue+"</option>");
			if(i == 0)
				for(var z in this.AttArbo){
					document.write("<option value='"+z+"'>"+this.AttArbo[z][1]+"</option>");
				}
			document.write("</select>");
		}
	}
}

/* debug function */
function DumpArbo(Arbo, level){
	var s_level = "---";
	for(i=0; i<level; i++) s_level += "---";
	for(var i in Arbo){
		document.write(s_level + " " + Arbo[i][1] + " ("+ i +")<br/>");
		//for(var j in Arbo[i][2])
			//document.write(s_level + " > " + Arbo[i][2][j] + "<br>");
		if(Arbo[i][0].length) DumpArbo(Arbo[i][0], level+1);
	}
}
//DumpArbo(C.AttArbo, 0)


function EcrireCookie(nom, valeur)
{
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : "/";
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}
function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
			return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0)
			break;
	}
	return null;
}
function EffaceCookie(nom)
{
	date=new Date;
	date.setFullYear(date.getFullYear()-1);
	EcrireCookie(nom,null,date);
}

//PopUnder Power
//Credit notice must stay intact for use.
//Paste this entire javascript between the
//<head> & </head> tags of your page, 
//Visit http://www.mikenew.net for more scripts. 
//by Mike New, with special thanks to Jeff Phillips 
//of classadrivers.com
//Downloaded from Java-scripts.net
//More scripts at http://www.java-scripts.net 

//Begin. Specify URLs to randomly select from
//and pop-under. Edit & add freely.
var popunder=new Array();
popunder[0]="http://ns60165.ovh.net/~brandtqu/";

//Specify the width and height of new popunder window (in pixels).
var width = '1024'; 
var height = '768';

//these are obvious variables. set "yes" or "no".
var p = 'scrollbars=yes, resizable=yes, toolbar=yes,' + 'menubar=yes, status=yes, location=yes, left=85, top=20, height=' + height + ',width=' + width;

// Load new PopUnder only once per browser session? (0=no, 1=yes)
// Putting 0 will cause the Popunder to load every time page is loaded
// Specifying 1 will cause it to load only once per session
var one_time=1;

// That's it! Don't edit the code below unless you're really good. :-P //

function get_cookie(Name) {
  var search = Name + "=";
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1) { // if the cookie exists
      offset += search.length;
      //set the index of beginning value
      end = document.cookie.indexOf(";", offset);
      
    if (end == -1) // set the index of the end of cookie value
         end = document.cookie.length;
         returnvalue = unescape(document.cookie.substring(offset, end));
      }
   }
  return returnvalue;
}

function loadornot(){
if (get_cookie('popunder')==''){
load_pop_power();
document.cookie="popunder=yes";
}
}

function load_pop_power(){
win2 = window.open(popunder[Math.floor(Math.random()*(popunder.length))], "bw", p);
win2.blur();
window.focus();
}