function showPic( imgName, imgCaption, imgWidth, imgHeight, textColor, bgColor ) {
	if(imgWidth<=100)imgWidth=100
	if(imgHeight<=100)imgHeight=100
	winHeight=imgHeight+60;
	var str = "";
	if (window.screen) {
		// Centers the window
	    var ah = screen.availHeight - 30;
    	var aw = screen.availWidth - 10;

    	var xc = (aw - imgWidth) / 2;
	    var yc = (ah - winHeight) / 2;
    	str += ",left=" + xc + ",screenX=" + xc;
    	str += ",top=" + yc + ",screenY=" + yc;
  	}

	w = window.open('','Demo','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width='+imgWidth+',height='+winHeight+str);
	w.document.write( "<html><head><title>"+imgCaption+"</title>" );
	w.document.write( "<STYLE TYPE='text/css'>" );
	w.document.write( "A {font-family: verdana; font-size: 10px; color: "+textColor+"; text-decoration : none;}" );
	w.document.write( "A:Visited {font-family: verdana;font-size: 10px; color: "+textColor+"; }" );
	w.document.write( "A:Active { font-family: verdana; font-size: 10px; color: "+textColor+"; }" );
	w.document.write( "A:Hover { font-family: verdana; font-size: 10px; color: "+textColor+"; }" );
	w.document.write( "IMG {border-color : "+textColor+";}" );
	w.document.write( "BODY { font-family: verdana; font-size : 10px; font-weight: normal; color : "+textColor+"; background-color : "+bgColor+"; }" );
	w.document.write( "</STYLE>" );
	w.document.write( "<script language='JavaScript'>\n");
	w.document.write( "IE5=NN4=NN6=false\n");
	w.document.write( "if(document.all)IE5=true;\n");
	w.document.write( "else if(document.getElementById)NN6=true\n");
	w.document.write( "else if(document.layers)NN4=true\n");
	w.document.write( "function autoSize() {\n");
	w.document.write( "	if(IE5) self.resizeTo(document.images[0].width+10,document.images[0].height+60)\n");
	w.document.write( "	else if(NN6) self.sizeToContent()\n");
	w.document.write( "	else top.window.resizeTo(document.images[0].width,document.images[0].height+60)\n");
	w.document.write( "	self.focus()\n");
	w.document.write( "}\n</scr");
	w.document.write( "ipt>\n");
	w.document.write( "</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad=" );
	w.document.write( "'javascript:autoSize();'>" );
	w.document.write( "<table cellpadding=0 cellspacing=0 border=0 align='center'><tr><td><a href='javascript:top.window.close();'><img src='"+imgName+"' border=0 alt='"+imgCaption+"'></a></td></tr>" );
	w.document.write( "</table></body></html>" );
	w.document.close();
};

function ltrim_catalogue(orig_string) {
	var modif_string;
	modif_string = orig_string;
	
	while ((modif_string.charAt(0) == ' ') ||
		   (modif_string.charAt(0) == '\t') ||
		   (modif_string.charAt(0) == '\n') ||
		   (modif_string.charAt(0) == '\r') ||
		   (modif_string.charAt(0) == '\0') ||
		   (modif_string.charAt(0) == '\x0B')) {
		modif_string = modif_string.substr(1);
	};
	return modif_string;
};

function rtrim_catalogue(orig_string) {
	var modif_string;
	modif_string = orig_string;
	
	while ((modif_string.charAt(modif_string.length-1) == ' ') ||
		   (modif_string.charAt(modif_string.length-1) == '\t') ||
		   (modif_string.charAt(modif_string.length-1) == '\n') ||
		   (modif_string.charAt(modif_string.length-1) == '\r') ||
		   (modif_string.charAt(modif_string.length-1) == '\0') ||
		   (modif_string.charAt(modif_string.length-1) == '\x0B')) {
		modif_string = modif_string.substr(0,modif_string.length-1);
	};
	return modif_string;
};

function trim_catalogue(orig_string) {
	var modif_string;
	modif_string = rtrim_catalogue(orig_string);
	modif_string = ltrim_catalogue(modif_string);
	return modif_string;
};

function valideOption(formulaire) {
	returnval = true;
	//Valide que les quantités sont des nombres
	for (i=0; i<formulaire.elements.length; i++) {
		if (formulaire.elements[i].name.indexOf("_choisi")>=0&&formulaire.elements[i].name.indexOf("_choisi_radio")<=0) {
			if (formulaire.elements[i].options[formulaire.elements[i].selectedIndex].value == "") {
				returnval = false;
			};
		};
	};
	//Affiche un message d'erreur
	if (returnval == false) {
		alert("Veuillez compléter les champs reliés au produit pour l'ajouter au panier.");
	};
	return returnval;
};

function ajax_getxmlcategories(base_catalogue, path_categories, fct_readyStateChanged) {
	//Function qui va chercher en AJAX les catégories en XML
	//Retourne false si le AJAX n'est pas supporté ou true si OK
	//La variable xmlHTTP doit être déclaré dans la page
	
	var page = base_catalogue;
	xmlHTTP = null;
	
	try {
		//Firefox, Opera 8.0+, Safari
		xmlHTTP = new XMLHttpRequest();
	} catch (e) {
		//Internet Explorer
		try {
			xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				return false;
			}
		}
	}
	
	xmlHTTP.onreadystatechange = fct_readyStateChanged;
	
	if (path_categories == "/") {
		//Catégories principales
		page += "categoriesprincipales.xml"; 
	} else {
		//Enlève le / au début s'il est là
		if (path_categories.charAt(0) == "/") {
			path_categories = path_categories.substring(1);
		};
		//Rajoute le / à la fin s'il n'est pas là
		if (path_categories.charAt(path_categories.length - 1) != "/") {
			path_categories += "/";
		}
		
		//Sous-catégories
		page += path_categories+ "souscategories.xml";
	}
	
	xmlHTTP.open("GET", page, true);
	xmlHTTP.send(null);
	return true;
	
};

function parse_xml_categories(xml) {
	//Fonction qui parse les catégories en format XML
	//Retourne un array qui contient pour chaque categorie 
	//0 => Nom de la catégorie
	//1 => URL Relatif
	//La page doit inclure les Javascript suivant 
	//<script language="JavaScript" src="/catalogue_files/includes/fonctions/javascript/xml/tinyxmlw3cdom.js"></script>
	//<script language="JavaScript" src="/catalogue_files/includes/fonctions/javascript/xml/tinyxmlsax.js"></script>


	//instantiate the W3C DOM Parser
	var parser = new DOMImplementation();
	//load the XML into the parser and get the DOMDocument
	var domDoc = parser.loadXML(xml);
	
	//get the root node (<categories>)
	var docRoot = domDoc.getDocumentElement();
	
	//Parcoure les catégories
	var categorie_array = new Array();
	for (i = 0; i < docRoot.getElementsByTagName("category").getLength(); i++) {
		categorie = docRoot.getElementsByTagName("category").item(i);
		categorie_array[i] = new Array(	categorie.getElementsByTagName("name").item(0).getFirstChild().getNodeValue(),
										categorie.getElementsByTagName("relative_category_url").item(0).getFirstChild().getNodeValue()
									);
	};
	return categorie_array;
};

function updateSelect(champs,valeur) {
	formulaire = document.produit;
	if (formulaire!=null) {
		for (i=0; i<formulaire.elements[champs].options.length; i++) {
			if (formulaire.elements[champs].options[i].value == valeur) {
				formulaire.elements[champs].options[i].selected = true;
			};
		};
	};
};

function updateRadio(champs,valeur) {
	formulaire = document.produit;
	if (formulaire!=null) {
		if (valeur=="") {
			for (i=0; i<formulaire.elements[champs].length; i++) {
				formulaire.elements[champs][i].checked = false;
			};
		} else {
			for (i=0; i<formulaire.elements[champs].length; i++) {
				if (formulaire.elements[champs][i].value == valeur) {
					formulaire.elements[champs][i].checked = true;
				};
			};
		};
	};
};

