function prendiElementoDaId(id_elemento) {
	var elemento;
	if(document.getElementById)
		elemento = document.getElementById(id_elemento);
	else
		elemento = document.all[id_elemento];
	return elemento;
}

function stampaImmobile(){
	if(window.print){
		window.print();
	} else {
		alert("Il browser non supporta il metodo STAMPA. Seleziona Stampa dal menu File.");
	}
}

// invia un form generico di modifica e cancelazzione
// theAction = a = cancella; theAction = b = modifica; 
// i checkbox di cancellazione si chiamano 'cancella'
function inviaForm(theAction, theForm, toActionFile, cb) { //azione, nome del form, file action a cui inviare il form, checkbox da controllare
	switch(theAction) {
		case 'a': //cancella
			var IsChecked=false;
			c=document.forms[theForm].elements[cb];
			if (c.length) {
				for (var i=0; i<c.length; i++)
					IsChecked |=c[i].checked;
			} else {
				IsChecked=c.checked;
			}
			if (!IsChecked){
				alert("Seleziona almeno un articolo da mettere nel carrello!");
				return false;
			} else {
				document.formdati.action=toActionFile;
			}
			break;
		
		case 'RichiestaPreventivo':
			var IsChecked=false;
			c=document.forms[theForm].elements[cb];
			if (c.length) {
				for (var i=0; i<c.length; i++)
					IsChecked |=c[i].checked;
			} else {
				IsChecked=c.checked;
			}
			if (!IsChecked){
				alert("Seleziona almeno un articolo per cui richiedere il preventivo!");
				return false;
			} else {
				document.formdati.action=toActionFile;
			}
			break;
		
		case 'ModificaListino':
			var IsChecked=false;
			c=document.forms[theForm].elements[cb];
			if (c.length) {
				for (var i=0; i<c.length; i++)
					IsChecked |=c[i].checked;
			} else {
				IsChecked=c.checked;
			}
			if (!IsChecked){
				alert("Seleziona almeno un articolo per cui impostare i prezzi!");
				return false;
			} else {
				document.formdati.action=toActionFile;
			}
			break;
		
		case 'AddArticleToVetrina':
			var IsChecked=false;
			c=document.forms[theForm].elements[cb];
			if (c.length) {
				for (var i=0; i<c.length; i++)
					IsChecked |=c[i].checked;
			} else {
				IsChecked=c.checked;
			}
			if (!IsChecked){
				alert("Seleziona almeno un articolo da inserire nella vetrina!");
				return false;
			} else {
				document.formdati.action=toActionFile;
			}
			break;
			
		case 'b': //modifica
			document.formdati.action=toActionFile;
			break;
	}
}
/*
function inviaFormRichiestaInformazioniArticolo(){
	if(theForm.richiesta.value=='')  {
        alert('Inserire il testo della richiesta!');
        return false;
	} else {
		return true;
	}
}*/
// seleziona/deseleziona tutti i checkbox con lo stesso nome
function selAll(sender, toCheck) { // pulsante inviante, checkbox da selezionare/deselezionare
	var a = document.forms[sender.form.name];
	var p = a[toCheck];
	if (document.getElementById(sender.id).checked == true) {
		v = true;
	} else {
		v = false;
	}
	for (var i = 0; i < p.length; i++) {
			p[i].checked = v;
	}
}

// seleziona/deseleziona tutti i checkbox che iniziano (chunk) con lo stesso nome
function selAllChunk(sender, chunk) { // pulsante inviante, chunk del campo input da selezionare/deselezionare
	if (document.getElementById(sender.id).checked == true) {
		v = true;
	} else {
		v = false;
	}
	with (document.forms[sender.form.name]) {
		for (var i = 0; i < elements.length; i++) {
			if (elements[i].type=="checkbox"&&elements[i].name.substr(0,2)==chunk) {
				elements[i].checked = v; 
			}
		}
	}
}

function hideEle(ele) { // elemento da mostrare
	document.getElementById(ele).style.visibility = "hidden";
	document.getElementById(ele).style.display = "none";
}

function showEle(ele) { // elemento da nascondere
	document.getElementById(ele).style.visibility = "visible";
	document.getElementById(ele).style.display = "block";
}


/*******************/
function valid(form) {
	if (!form.ricerca.value) {
		window.alert("Inserisci una parola per la ricerca");
		return false
	}
}

function vai(){
	p=document.menu.rapido.selectedIndex;
	lk=document.menu.rapido.options[p].value;
	if(lk!="0") document.location=(lk);
}

popup = null;

function winxy(content,x,y) {
str = content;
opt = "scrollbars=yes,resizable=yes,width="+x+",height="+y+",status=no,location=no,toolbar=no";
if(popup != null) popup.close();
popup = window.open(str,'misure',opt);
}

function changeVis(id){
	stato=(id.style.display=="none")?"block":"none";
	id.style.display=stato;
}

function bookmark(){
	var url = window.document.location;
	var title = window.document.title;
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		window.external.AddFavorite(url,title);
	} else if (navigator.appName == "Netscape") {
		window.sidebar.addPanel(title,url,"");
	} else {
		alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
	}
}

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) { //v4.01
  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;
}

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];}
}

/* Photo gallery*/
function ViewPhoto(ObjImgDest, UrlBig, UrlZoom){
	ObjImgDest.src=UrlBig
	if (UrlZoom!=''){
		prendiElementoDaId("StilcasaZoomContainer").style.display="block";
		prendiElementoDaId("StilcasaZoomLink").href=UrlZoom;
	} else {
		prendiElementoDaId("StilcasaZoomContainer").style.display="none";
		prendiElementoDaId("StilcasaZoomLink").href="";		
	}
}