function xId(id) {
	return document.getElementById(id);
}

function preloadImages() {
	var d = document;
	if (d.images) {
		d.tmp = new Array();
		for (i=0; i<arguments.length; i++) {
			d.tmp[i] = new Image;
			d.tmp[i].src = "imagess/"+arguments[i];
		}
	}
}

function imgOver(obj){
	img=obj.src;
	ext=img.substring(img.lastIndexOf(".") + 1, img.length);
	imgOn=img.replace("."+ext, "_on."+ext);
	obj.src=imgOn;
}
function imgOut(obj){
	img=obj.src;
	ext=img.substring(img.lastIndexOf(".") + 1, img.length);
	imgOff=img.replace("_on."+ext, "."+ext);
	obj.src=imgOff;
}

function openPopup(file, w, h){
	try{if(newWin.closed==false) newWin.close();}catch(e){}
	var left = Math.floor((screen.width-w)/2);
	var top = Math.floor((screen.height-h)/2);
	var setting="location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no,width="+w+",height="+h+",top="+top+",left="+left;
	newWin=window.open(file, 'popUp', setting);
	newWin.focus();
}

function openDiv(id,s){
	qs = "id="+id+"&s="+s;
	//Ajax.SetDebug(true);
	Ajax.Call(qs, "POST", setXml);
	xId("contentLogosChild").innerHTML = "";

	w = parseInt(xId("contentLogosChild").style.width);
	h = parseInt(xId("contentLogosChild").style.height);

	var left = Math.floor((document.body.clientWidth-w)/2);
	var top = Math.floor((document.body.clientHeight-h)/2);
	xId("contentLogosChild").style.top = top + "px";
	xId("contentLogosChild").style.left = left + "px";
	xId("contentLogosChild").style.display = "block";
}

function closeDiv(){
	xId("contentLogosChild").style.display = "none";
}

function debugObj(obj){
	v="";
	for (x in obj) {
		v += (x + " - " + obj[x] + "\n")
	}
	alert(v)
}

function setXml(xmlObj){
	root = xmlObj.getElementsByTagName("items").item(0);
	nodes = root.getElementsByTagName("item");
	parent_node = root.getElementsByTagName("item_parent");

	div = document.createElement("DIV")
	div.style.padding = "8px";
	div.style.textAlign = "center";
	div.style.backgroundColor = "#EDEDED";
	div.innerHTML = '<a href="javascript:closeDiv();" style="font-weight:bold;">CHIUDI</a>'
	xId("contentLogosChild").appendChild(div)

	tab = document.createElement("TABLE");
	tab.className = "logos";
	tab.border = "0";
	var lastRow = tab.rows.length;
	var iteration = lastRow;
	var row = tab.insertRow(lastRow);
	var cell = row.insertCell(0);
	cell.setAttribute("colspan", 3);
	cell.innerHTML = '&nbsp;'

	if (parent_node.length > 0) {
		var lastRow = tab.rows.length;
		var iteration = lastRow;
		var row = tab.insertRow(lastRow);
		var cell = row.insertCell(0);
		cell.setAttribute("colSpan", 3);
		cell.setAttribute("height", 24);
		cell.setAttribute("align", "center");
		cell.innerHTML = '<a href="javascript:closeDiv();" style="font-weight:bold;">CHIUDI</a>'

		node = parent_node.item(0);
		img = node.getAttribute("img");
		title = node.getAttribute("title");
		pdf = node.getAttribute("pdf");
		target = node.getAttribute("target");
		url = node.getAttribute("url");
		
		if (img != "") {
			if (url != "") {
				img = '<a href="' + url +'" target="_blank"><img src="files/'+img+'" width="116" height="70" alt="" border="0" /></a>';
			} else {
				img = '<img src="files/'+img+'" width="116" height="70" alt="" border="0" />';
			}
		} else {
			img = '<img src="images/empty.gif" alt="" width="116" height="70" border="0" >';
		}
		if (pdf != "") {
			pdf = '<a href="' + pdf + '" target="' + target + '"><img src="images/pdf.gif" alt="Scarica PDF" width="16" height="16" border="0" style="border-bottom:none; padding-top:4px; margin-left:0px; margin-right:10px;" />scarica pdf</a>';
		} else {
			pdf = '<img src="images/empty.gif" alt="" width="16" height="16" border="0" style="border-bottom:none; padding-top:4px; margin-left:0px;" />';
		}

		if (url != "") {
			title = '<a href="' + url +'" target="_blank">' + title + '</a>';
		}
		code = img + '<div>' + title + '<br />' + pdf + '</div>';
		cell.innerHTML = code;

	}

	if (nodes.length > 0) {
		indexCell = -1;
		for (i=0; i<nodes.length; i++) {
			if (i % 3 == 0) {
				var lastRow = tab.rows.length;
				var iteration = lastRow;
				var row = tab.insertRow(lastRow);
				indexCell = -1;
			}
			indexCell++;
			var cell = row.insertCell(indexCell);

			node = nodes.item(i);
			img = node.getAttribute("img");
			title = node.getAttribute("title");
			pdf = node.getAttribute("pdf");
			target = node.getAttribute("target");
			url = node.getAttribute("url");
			
			if (img != "") {
				if (url != "") {
					img = '<a href="' + url +'" target="_blank"><img src="files/'+img+'" width="116" height="70" alt="" border="0" /></a>';
				} else {
					img = '<img src="files/'+img+'" width="116" height="70" alt="" border="0" />';
				}
			} else {
				img = '<img src="images/empty.gif" alt="" width="116" height="70" border="0" >';
			}
			if (pdf != "") {
				pdf = '<a href="' + pdf + '" target="' + target + '"><img src="images/pdf.gif" alt="Scarica PDF" width="16" height="16" border="0" style="border-bottom:none; padding-top:4px; margin-left:0px; margin-right:10px;" />scarica pdf</a>';
			} else {
				pdf = '<img src="images/empty.gif" alt="" width="16" height="16" border="0" style="border-bottom:none; padding-top:4px; margin-left:0px;" />';
			}

			if (url != "") {
				title = '<a href="' + url +'" target="_blank">' + title + '</a>';
			}
	
			code = img + '<div>' + title + '<br />' + pdf + '</div>';
			cell.innerHTML = code;
		}
	} else {
		var lastRow = tab.rows.length;
		var iteration = lastRow;
		var row = tab.insertRow(lastRow);
		var cell = row.insertCell(0);
		cell.setAttribute("height", 24);
		cell.setAttribute("align", "center");
		cell.setAttribute("bgColor", "#EDEDED");
		cell.innerHTML = '<a href="javascript:closeDiv();" style="font-weight:bold;">CHIUDI</a>'

		var lastRow = tab.rows.length;
		var iteration = lastRow;
		var row = tab.insertRow(lastRow);
		var cell = row.insertCell(0);
		cell.innerHTML = '&nbsp;'

		var lastRow = tab.rows.length;
		var iteration = lastRow;
		var row = tab.insertRow(lastRow);
		var cell = row.insertCell(0);
		cell.innerHTML = '<b>Nessun record trovato</b>'
	}
	xId("contentLogosChild").appendChild(tab);

	var lastRow = tab.rows.length;
	var iteration = lastRow;
	var row = tab.insertRow(lastRow);
	var cell = row.insertCell(0);
	cell.setAttribute("colspan", 3);
	cell.innerHTML = '&nbsp;'

	div = document.createElement("DIV")
	div.style.padding = "8px";
	div.style.textAlign = "center";
	div.style.backgroundColor = "#EDEDED";
	div.innerHTML = '<a href="javascript:closeDiv();" style="font-weight:bold;">CHIUDI</a>'
	xId("contentLogosChild").appendChild(div)
}


