// getElById restituisce il riferimento all'elemento corrispondente all'id cercato
function gEBID(id_elemento) {
	var elemento; // elemento da restituire
	
	if(document.getElementById) {
		elemento = document.getElementById(id_elemento); // IE > 5
	} else {
		elemento = document.all[id_elemento]; // IE < 5
	}
	
	return elemento;
}


function popUp(theURL) {
  window.open(theURL,'zoom','width=100,height=100,scrollbars=no,resizable=yes');
}

function MM_findObj(n, d) {
	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);
	if(!x && d.getElementById) x = d.getElementById(n);
	return x;
}

// Carte piccolo formato
cards = ["usomano", "opaca", "lucida", "gardapat13", "adesivaFedrigoni", "acquerBianco", "acquerAvorio", "tintoGesso", "tintoCrema", "marinaConPerga", "arjoWiggins", "fedriPearl", "fedriJade", "plike", "conDigiTexture", "c_pvc", "nonAdesivaAntispappolo", "patinataOpaca", "patinataLucida", "acquarelloStucco", "acquarelloGesso", "tintorettoStucco", "tintorettoGesso", "pergamena", "conquerorVergate", "conquerorMicroVergate", "conquerorIridescente", "ade_hqLucida", "ade_hqOpaca", "ade_pvc4Colori", "ade_pvc4ColoriBianco", "ade_pvcMetal4Colori", "ade_pvcMetal4ColoriBianco", "ade_pvcBianco", "ade_pvcTrasp", "ade_fedriLucida", "ade_fedriOpaca", "gardapat13", "metallics"]; // global

function hideAllCards() {
	for (n = 0; n < cards.length; n++) {
		if (gEBID(cards[n]) != null) { // old way
			if (gEBID(cards[n]).style.display != "none") {
				gEBID(cards[n]).style.display = "none";
			}
		}
		if (gEBID(allMaterials[n]) != null) {
			if (gEBID(allMaterials[n]).style.display != "none") {
				gEBID(allMaterials[n]).style.display = "none";
			}
		}
	}
}

function showCards(card) {
	hideAllCards();
	gEBID(card).style.display = 'none';
	gEBID(card).style.display = 'block';
}

function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function popUpSized(theURL, sizeX, sizeY) {
	if (sizeX < 100) { sizeX = 500; }
	if (sizeY < 100) {sizeY = 350; }
	var options = "width=" + sizeX + ",height=" + sizeY + ",scrollbars=no,resizable=yes";
  window.open(theURL,'zoom',options);
}

function swappa(itemID, newItem) {
	gEBID(itemID).src = newItem;
}

/*
function imgPreload() {
	var d=document;
	if(d.images){
		if(!d.SA_p) d.SA_p=new Array();
    	var i;
    	var j=d.SA_p.length;
    	var a=imgPreload.arguments;
    	for(i=0; i<a.length; i++) {
    		if (a[i].indexOf("#")!=0){
    			d.SA_p[j]=new Image;
    			d.SA_p[j++].src=a[i];
    		}
    	}
    }
}
 */

/*
function uploadWait(target, elToHide) {
	gEBID(elToHide).style.display = 'none';
	wait_html = '<p style="text-align: center;">';
	wait_html += '<img src="img/monitor_accesso.gif" alt="" border="0" /></p>';
	wait_html += '<p style="text-align: center;">Attendere...<br />Caricamento del file in corso...</p>';
	gEBID(target).innerHTML = wait_html;
}

function makeArray() { 
	this.length = makeArray.arguments.length 
	for (var i = 0; i < this.length; i++) {
		this[i] = makeArray.arguments[i];
	}
} 

function changePromo(htmlItem, src) {
	document.getElementById(htmlItem).src = src; // "home_promo/0.gif"
}

function swapHeadImages() {
	var images = new makeArray ("home_promo/0.gif", "home_promo/1.gif", "home_promo/2.gif", "home_promo/3.gif", "home_promo/4.gif", "home_promo/5.gif", "home_promo/6.gif", "home_promo/7.gif", "home_promo/8.gif"); // , "home_promo/9.gif"
	
// Image Preload
	img2load = "";
	for (n=0; n < images.length; n++) {
		img2load += "'" + images[n] + "'";
		if (n+1 < images.length) { img2load += ", "; }
	}
	imgPreload(img2load);
	
	var index = Math.floor(Math.random() * images.length); // valore casuale tra 0 e la lunghezza dell'array images - 1

	changePromo("home_box2", images[index]);
	setTimeout("swapHeadImages()", 3000); // Temporizzatore: 3 sec di attesa 
}

function waitOrderJob(hide, show) {
	gEBID(hide).style.visibility = 'visible';
	gEBID(hide).style.visibility = 'hidden';
	gEBID(show).style.visibility = 'hidden';
	gEBID(show).style.visibility = 'visible';
}

function homeBoxImgPreload() {
	
}
*/