

function compileInfoDiv(id, val, j) {
	var div = document.createElement("div");
	div.setAttribute(className(), "printMainImg_DIV");

	var div1 = document.createElement("div");
	div1.style.cssFloat = "left";
	div1.style.styleFloat = "left";
	div1.style.width = "165px";
	div1.style.height = "145px";
	div1.style.paddingLeft = "5px";
	val = val.split(", ");
	var text = "";
	for (var i=0; i<val.length; i++) {
		if (val[i] != "") {
			var val2 = val[i].split("|");
			if (i == 2) {
				div1.setAttribute("id", "S_"+val2[1]);
			}
			text += "<br /><br />" + val2[0] + "<br /><strong>" + val2[1] + "</strong>";
		}
	}
	div1.innerHTML = text;
	div.appendChild(div1);
	var obj = document.getElementById(id);
	obj.appendChild(div);
}


function compileTitleImgDiv(id, val, j) {
	var div = document.createElement("div");
	div.setAttribute(className(), "printMainImg_DIV");

	var div1 = document.createElement("div");
	div1.style.cssFloat = "left";
	div1.style.styleFloat = "left";
	div1.style.width = "170px";
	div1.style.height = "150px";
	if (val != "") {
		div1.innerHTML = val;
	}
	div.appendChild(div1);

	var obj = document.getElementById(id);
	obj.appendChild(div);
}


function compileRecordImgDiv(id, val, j, m) {
	var val = val.split("|");
	var img = document.createElement("img");
	img.setAttribute("border", "0");
	img.setAttribute("align", "absmiddle");
	img.setAttribute("src", val[0]);
	img.setAttribute("vspace", "5");
	img.setAttribute("height", "125");
	img.setAttribute("width", "125");

	var a = document.createElement("a");
	a.setAttribute("id", "M_"+val[1]);
	a.setAttribute("target", "_top");
	a.setAttribute("title", "VAI ALLA SCHEDA MODELLO "+val[1]);
	a.setAttribute("href", "/model.asp?m="+m+"&p="+val[1]);
	a.appendChild(img);
	a.appendChild(document.createElement("br"));
	a.appendChild(document.createTextNode(val[1]));

	var div = document.createElement("div");
	div.style.marginRight = "2px";
	div.style.paddingLeft = "3px";
	div.style.cssFloat = "left";
	div.style.styleFloat = "left";
	div.style.width = "194px";
	div.style.height = "149px";
	div.style.textAlign = "left";
	div.style.borderTop = "1px solid #eeeeee";
	div.style.borderLeft = "1px solid #eeeeee";
	div.style.borderRight = "0px solid #eeeeee";
	div.style.borderBottom = "0px solid #eeeeee";

	div.appendChild(a);

	var obj = document.getElementById(id);
	obj.childNodes[j].appendChild(div);
}



function compileTitleDiv(id, val, j) {


	var obj = document.getElementById(id);
	var div = document.createElement("div");
	var div1 = document.createElement("div");
	div.setAttribute(className(), "printMain_DIV");
	if (val != "") {
		div1.setAttribute(className(), "printTitle_DIV");
		div1.appendChild(document.createTextNode(val));
		div1.innerHTML = val;
	} else {
		div1.style.cssFloat = "left";
		div1.style.styleFloat = "left";
		div1.style.width = "140px";
		div1.style.height = "100%";
		div1.style.overflow = "hidden";
	}
	div.appendChild(div1);
	obj.appendChild(div);
}


function compileRecordDiv(id, val, j) {
	var obj = document.getElementById(id);
	var div = document.createElement("div");
	div.setAttribute(className(), "printSpec_DIV");
	if (val == "") {
		div.style.border = "0px solid transparent";
		div.style.height = "25px";
	} else if (val == "-") {
		div.style.textAlign = "center";
	}
	div.style.overflow = "hidden";
	div.innerHTML = val;
	obj.childNodes[j].appendChild(div);
	if (j > 0) {
		obj.childNodes[j].childNodes[0].style.height = String(parseInt(obj.childNodes[j].offsetHeight-2) + "px");
	}
}


	function addSeriesFilter(s, sForm, macrocategory) {
		var obj = document.getElementById("print_DIV");
		sFilter = s.split(",");
		for (var i=0; i<sFilter.length-1; i++) {
			var div = document.createElement("div");
			div.setAttribute("id", "seriesFilter_" + sFilter[i]);
			var input = document.createElement("input");
			input.setAttribute("type", "checkbox");
			input.setAttribute("value", sFilter[i]);
			input.setAttribute("name", "series");
			input.onclick = function() {
				this.parentNode.parentNode.action = "/pl.asp?m=" + macrocategory + "#S_" + this.getAttribute("value");
				this.parentNode.parentNode.submit();
			}
			div.appendChild(input);
			if ((sForm.indexOf(sFilter[i] + ",") > -1) || (sForm == ",")) {
				input.checked = true;
			}

			var infoA = document.createElement("a");
			infoA.setAttribute("href", "#S_" + sFilter[i]);
			infoA.setAttribute(className(), "aFilter");
			infoA.onclick = function() {showModels(this);}
			infoA.appendChild(document.createTextNode(" " + sFilter[i]))
			div.appendChild(infoA);

			if (i == 0) {
				var infoDiv = document.createElement("div");
				var infoDiv_title = document.createElement("strong");
				infoDiv_title.style.fontWeight = "bold";
				infoDiv_title.style.width = "120px";
				infoDiv_title.appendChild(document.createTextNode("Filtra i prodotti"));
				infoDiv.appendChild(document.createElement("p"));
				infoDiv.appendChild(infoDiv_title);
				infoDiv.appendChild(document.createElement("br"));
				obj.lastChild.appendChild(infoDiv);
			}
			obj.lastChild.appendChild(div);
			 if (i == sFilter.length-2) {
				var infoDiv = document.createElement("div");
				var infoA = document.createElement("a");
				infoA.setAttribute("target", "_top");
				infoA.setAttribute("href", "/pl.asp?m=" + macrocategory);
				infoA.style.fontWeight = "bold";
				infoA.appendChild(document.createTextNode("Annulla il filtro"));
				infoDiv.appendChild(document.createElement("p"));
				infoDiv.appendChild(infoA);
				obj.lastChild.appendChild(infoDiv);
			}
		}
	}

	function addModelFilter(m, mForm, macrocategory) {
		var mFilterArray = m.split(",");
		for (var i=0; i<mFilterArray.length-1; i++) {
			var filter = mFilterArray[i].split("|");
			var sFilter = filter[0];
			var mFilter = filter[1];
			var obj = document.getElementById("seriesFilter_" + sFilter);

			var div = document.createElement("div");
			div.setAttribute("id", "modelFilter_" + mFilter);
			div.style.paddingLeft = "5px";
			div.style.fontSize = "8px";
			div.style.color = "#666666";
			div.style.whiteSpace = "nowrap";
			div.style.paddingLeft = "5px";
			if (location.href.indexOf(sFilter) > -1) {
				div.style.display = "block";
			} else {
				div.style.display = "none";
			}
			var input = document.createElement("input");
			input.setAttribute("type", "checkbox");
			input.setAttribute("value", mFilter);
			input.setAttribute("name", "model");
			input.onclick = function() {
				this.parentNode.parentNode.parentNode.action = "/pl.asp?m=" + macrocategory + "#S_" + this.parentNode.parentNode.firstChild.getAttribute("value");
				this.parentNode.parentNode.parentNode.submit();
			}
			div.appendChild(input);
			if ((mForm.indexOf(mFilter + ",") > -1) || (mForm == ",")) {
				input.checked = true;
			}
			var infoA = document.createElement("a");
			infoA.setAttribute("href", "#M_" + mFilter);
			infoA.setAttribute(className(), "aFilter");
			infoA.style.fontSize = "8px";
			infoA.appendChild(document.createTextNode(" " + mFilter))
			div.appendChild(infoA);
			obj.appendChild(div);
		}
	}

		function showModels(obj) {
			var obj = obj.parentNode;
			for (var i=2; i<obj.childNodes.length; i++) {
				if (obj.childNodes[i].style.display == "none") {
					obj.childNodes[i].style.display = "block";
				} else {
					obj.childNodes[i].style.display = "none";
				}
			}

		}

	function plPrint(p) {
		var bodyClass = className();

		//document.getElementById("topSpaces_DIV").style.display = "none";

		document.body.setAttribute(bodyClass, "bodyInPrint");
		hideTag("A", "rel", "printPageLink", "");
		if (p == 0) {
			document.getElementById("print_DIV").style.display = "none";
			var conf = window.confirm("Sei sicuro di voler stampare il listino?");
			if (conf) {
				window.print();
				alert("Il documento è stato inviato alla stampa.");
			}
			document.getElementById("print_DIV").style.display = "block";
		} else {
			var page = String(p).split("_");
			page = page[1];
			var conf = window.confirm("Sei sicuro di voler stampare solo la pagina " + page + "?");
			if (conf) {
				hideTag("DIV", "class", "printPage_DIV", p);
				document.getElementById("print_DIV").style.display = "none";
				window.print();
				alert("La pagina " + page + " è stata inviata alla stampa.");
				document.getElementById("print_DIV").style.display = "block";
				hideTag("DIV", "class", "printPage_DIV", p);
			}
		}
		hideTag("A", "rel", "printPageLink", "");
		document.body.setAttribute(bodyClass, "body");
		//document.getElementById("topSpaces_DIV").style.display = "block";
	}

	function setPageNumber(p) {
		var obj = document.getElementsByTagName("span");
		for (var i=0; i<obj.length; i++) {
			if (obj[i].getAttribute("rel") == "pageNumber") {
				obj[i].appendChild(document.createTextNode(p));
			}
		}
	}



	function hideTag(tag, attr, value, p) {
		if (attr == "class") {
			attr = className();
		}
		var obj = document.getElementsByTagName(tag);
		for (var i=0; i<obj.length; i++) {
			if	((obj[i].getAttribute(attr) == value) && ((obj[i].getAttribute("id") != p) || (p == ""))) {
				if (obj[i].style.display != "none") {
					obj[i].style.display = "none";
				} else {
					obj[i].style.display = "block";
				}
			}
		}
	}

