window.onerror=handleErr;

function handleErr(msg,url,l)
{
txt="There was an error on this page.\n\n"
txt+="Error: " + msg + "\n"
txt+="URL: " + url + "\n"
txt+="Line: " + l + "\n\n"
txt+="Click OK to continue.\n\n"
//alert(txt)
return true
}



function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters))
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImag eLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
}

function trim(Stringa) {
	return Stringa.replace(/^\s+|\s+$/g,"")
	}

function centra(){
	

		if(window.innerHeight>543){
			winH = window.innerHeight;
			}
		if(document.body.clientHeight>543){
			winH = document.body.clientHeight;
			}
		if(document.documentElement.clientHeight>543){
			winH = document.documentElement.clientHeight;
			}
			
		if(winH){
				temp=(winH-543)/2;
				
				_gb('Main').style.top=temp+"px";
			}		
		}
	
	

function centra_old(){
		//alert("entra");
		if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
		  winH = window.innerHeight;
		 }
		 else {
		  winH = document.body.clientHeight
		  
		 }
		}
		temp=(winH-543)/2;
		_gb('Main').style.top=temp+"px";
	}
	
	
function _gb(Id){
	return document.getElementById(Id);
	}

/* 
 * Cross-browser event handling, by Scott Andrew
 */
 
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {

		element.detachEvent('on' + eventType, lamdaFunction);
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

 


// JavaScript Document
function includeSwf(FlashVars,src,width,height,id)
{
	document.write(
    '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" align="middle">\n'+
      '<param name="FlashVars" value="'+FlashVars+'">\n'+
      '<param name="allowScriptAccess" value="always" />\n'+
      '<param name="movie" value="'+src+'" />\n'+
      '<param name="quality" value="high" />\n'+
      ' <param name="wmode" value="transparent" />\n'+
      '<embed src="'+src+'" wmode="transparent" quality="high" bgcolor="#000000" FlashVars="'+FlashVars+'" width="'+width+'" height="'+height+'" name="'+id+'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n'+
    '</object>');
}

function AddClickFoto(){
	ArrayATag=document.getElementsByTagName('a');
	for (i=0;i<ArrayATag.length;i++){
		if(ArrayATag[i].getAttribute("zoom")){
			addEvent(ArrayATag[i], 'click', ApriFoto, false)
		}
		}
	}

function ApriFoto(e){
	var target = window.event ? window.event.srcElement : e ? e.target : null;
	_gb('ZoomImg').src=target.getAttribute('zoom');
	_gb('ZoomImgTitolo').firstChild.nodeValue=target.getAttribute('titolo');
	_gb('ZoomImgDescrizione').firstChild.nodeValue=target.getAttribute('descrizione');
	_gb('ZoomBox').style.display="block";
	}
	
function ChiudiFoto(){
	_gb('ZoomBox').style.display="none";
	}

function CentraPaginazione(){
	BaseSpostamento=370;
	ModuloSpostamento=15;
	ArraySpan=_gb('GalleryPaginazione').getElementsByTagName('span');
	NumeroPagine=ArraySpan.length;
	SpostamentoTotale=BaseSpostamento-(ModuloSpostamento*NumeroPagine);
	_gb('GalleryPaginazione').style.paddingLeft= SpostamentoTotale+"px"
	}

function Ricerca(){
	FormRicerca_JS=_gb('FormRicerca');
	AccendiTab('TabRisultati')
	FormRicerca_JS.submit();
	}

function RipulisciRicerca(){
	FormRicerca_JS=_gb('FormRicerca');
	FormRicerca_JS.reset();
	}

var RicercaIsOpen=false;
var UtenteIsLogged=false;
var CarrelloIsPresent=false;
var TabUtente='none';
var TabRicerca='TabNews';
function Eve(){
	//funzione per annullare gli evevnti
	}

function ApriRicerca(){
	BoxRicerca_JS=_gb('RicercaBox');
	BoxRicercaAvanzata_JS=_gb('RicercaAvanzata');
	BoxTag_JS=_gb('TagBox');
	BoxUtente_JS=_gb('BoxUtente');
	InputRicerca_JS=_gb('ricerca_avanzata');
	
	//check sulle condizioni di partenza
	if(RicercaIsOpen==false){
		if(UtenteIsLogged==true || CarrelloIsPresent==true){
				Azione='RimpicciolisciUtente';
			}else{
				Azione='EliminaTag';
				}
			RicercaIsOpen=true;
			
			InputRicerca_JS.value=1;
		} 
	else if (RicercaIsOpen==true){
		if(UtenteIsLogged==true || CarrelloIsPresent==true){
			Azione='IngrandisciUtente';
		}else{
			Azione='VisualizzaTag';
			}
			RicercaIsOpen=false;
			InputRicerca_JS.value=0;

		}

	//azioni
	if(Azione=='RimpicciolisciUtente'){
		BoxRicerca_JS.className='BoxBase Avanzata';
		BoxUtente_JS.className='BoxBase Loggato Ridotto';
		
		}
	if(Azione=='EliminaTag'){
		BoxRicerca_JS.className='BoxBase Avanzata';
		BoxTag_JS.className='BoxBase NonVisibile';
		}
	if(Azione=='IngrandisciUtente'){
		BoxRicerca_JS.className='BoxBase';
		BoxTag_JS.className='BoxBase NonVisibile';
		BoxUtente_JS.className='BoxBase Loggato';
		}
	if(Azione=='VisualizzaTag'){
		BoxRicerca_JS.className='BoxBase';
		BoxTag_JS.className='BoxBase';
		}
	
	}

function RicercaDaTab(TipoTab){
	IframeRicerca_JS=_gb('IframeRicerca');
	if(TipoTab!='TabNews'){
		IframeRicerca_JS.src="ricerca.php?QS_speciale="+TipoTab;
	} else{
		IframeRicerca_JS.src="news.php";
		}
	ZoomChiudi()
	AccendiTab(TipoTab)
	}
	
function AccendiTab(TipoTab){
	var Tab=_gb(TipoTab);
	MenuGallery_JS=_gb('MenuGallery');
	TabRisultati_JS=_gb('TabRisultati')
	MenuGalleryArray=MenuGallery_JS.getElementsByTagName('a');
	TabRisultati_JS.style.display='none'
	
	for (var i=0;i<MenuGalleryArray.length;i++){
			MenuGalleryArray[i].className='Off'
		}
		
	Tab.className='On'
	Tab.style.display='block'
	TabRicerca=TipoTab;
	
	
	}
	

function VisualizzaComandi(NodoSorgente){
	NodoSorgente.className='On';
	}
function NascondiComandi(NodoSorgente){
	NodoSorgente.className='Off';
	}

function ZoomImg(NodoSorgente){
	
	
	GalleryCenter_JS=_gb('GalleryCenter');
	ZoomContainer_JS=_gb('ZoomContainer');
	ZoomDescrizione_JS=_gb('ZoomDescrizione');
	
	NuovoNodo=NodoSorgente.parentNode.cloneNode(NodoSorgente)
	UrlImgZoom=NuovoNodo.getAttribute('img_zoom');
	IdSql=NodoSorgente.parentNode.getAttribute('id_sql');
	
	ZoomContainer_JS.innerHTML='';
	ZoomContainer_JS.appendChild(NuovoNodo)
	
	//carico descrizione
	Descrizione=ZoomContainer_JS.getElementsByTagName('p')[0].innerHTML;
	ZoomDescrizione_JS.innerHTML=Descrizione;

	//carico immagine
	ZoomContainer_JS.getElementsByTagName('img')[1].src=UrlImgZoom;
	GalleryCenter_JS.className='ZoomAperto'
	
	//conteggio
	IframeRicerca_JS=_gb('IframeCounter');
	IframeRicerca_JS.src="ricerca.php?Azione=CounterFoto&id="+IdSql;

	}
	
function ZoomImgCom(NodoSorgente){
	NodoSorgente=NodoSorgente.parentNode;
	ZoomImg(NodoSorgente)
	}



function ZoomChiudi(){
	GalleryCenter_JS=_gb('GalleryCenter');
	GalleryCenter_JS.className=''
	}

function BoxUtente(Logged){
	var BoxUtente_JS=_gb('BoxUtente');
	var BoxUtenteLoggato_JS=_gb('BoxUtenteLoggato');
	var BoxUtenteNonLoggato_JS=_gb('BoxUtenteNonLoggato');
	var	BoxTag_JS=_gb('TagBox');

	if(BoxUtenteNonLoggato_JS.innerHTML==''){ 
	BoxUtenteNonLoggato_JS.innerHTML=BoxUtente_JS.innerHTML;}
	
	if(Logged==true && UtenteIsLogged==false){
		CarrelloIsPresent=true;	
		UtenteIsLogged=true;
		BoxUtente_JS.innerHTML=BoxUtenteLoggato_JS.innerHTML;
		BoxTag_JS.className='BoxBase NonVisibile';
		BoxUtente_JS.className='BoxBase Loggato';
		InitCart();
		ApriMenuUtente('MenuUtente_Carrello');
		}
	else if(Logged==false){
		CarrelloIsPresent=false;	
		UtenteIsLogged=false;
		BoxUtente_JS.innerHTML=BoxUtenteNonLoggato_JS.innerHTML;	
		BoxTag_JS.className='BoxBase';
		BoxUtente_JS.className='BoxBase';
		}
	else if(Logged=='SoloCarrello' &&UtenteIsLogged==false){
		CarrelloIsPresent=true;	
		UtenteIsLogged=false;		
		BoxUtente_JS.innerHTML=BoxUtenteLoggato_JS.innerHTML;
		_gb('MenuUtente').style.display='none';
		BoxTag_JS.className='BoxBase NonVisibile';
		BoxUtente_JS.className='BoxBase Loggato';
		ApriMenuUtente('MenuUtente_Carrello');
		
		}
	
	}
	

function ApriPagina(TipoPagina){
	//conteggio
	IframePagine_JS=_gb('IframePagine');
	
	if(TipoPagina=='Registrazione'){
		IframePagine_JS.src="utente.php?LoginAction=Registrazione";
		}
	if(TipoPagina=='ProfiloUtente'){
		IframePagine_JS.src="utente.php?LoginAction=ProfiloUtente";
		}
	_gb('PageContentBody').innerHTML="Loading Content ..."
	_gb('PageContentBox').style.display="block"
	

}

function InviaFormPagine(FormId){
	//conteggio
	IframePagine_JS=_gb('IframePagine');
	Form_JS=_gb(FormId);
	Form_JS.setAttribute('target',"IframePagine")
	Form_JS.target="IframePagine";
	Form_JS.submit();
	

}

function ChiudiPagina(){
	//conteggio
	_gb('PageContentBox').style.display="none"
	

}
function VisualizzaFormPreventivo(FormId){
	_gb('FormPreventivoEditoriale').style.display="none";
	_gb('FormPreventivoPubbliEditoriale').style.display="none";
	_gb('FormPreventivoPubblicitario').style.display="none";
	_gb(FormId).style.display="block";

	}
	
function ApriPaginaGenerica(IdPagina){
	
		IframePagine_JS=_gb('IframePagine');
		IframePagine_JS.src="interna.php?id="+IdPagina;
		_gb('PageContentBody').innerHTML="Loading ..."
		_gb('PageContentBox').style.display="block"

}
function Login(){
	LoginForm_JS=_gb('LoginForm');
	LoginForm_JS.submit()
	}

function AddCartZoom(NodoSorgente){
	
	var ZoomContainer_JS=_gb('ZoomContainer');
	var FotoElement=ZoomContainer_JS.getElementsByTagName('li')[0];
	
	var IdSql=FotoElement.getAttribute('id_sql');
	var ImgSrc=FotoElement.getElementsByTagName('img')[1].src;
	var ImgDescrizione=FotoElement.getElementsByTagName('p')[0].innerHTML;
	AddFotoToCart(IdSql,ImgSrc,ImgDescrizione);
	
	}

function AddFotoToCart(IdSql,ImgSrc,ImgDescrizione){
	
	if(!CarrelloIsPresent){
		alert("Problem, you are not logged in")
		//BoxUtente('SoloCarrello')
		return;
		}
	if(TabUtente!='MenuUtente_Carrello'){
		IframeUtente_JS=_gb('IframeUtente');
		IframeUtente_JS.src="includes/box_utente.php?LoginAction=AddCart&id="+IdSql;

		}
	else{
		var ListaFoto_JS=_gb('ListaElementi');
		var ZoomContainer_JS=_gb('ZoomContainer');
		var ArrayElementi=ListaFoto_JS.getElementsByTagName('li');
		//check
		var CheckPresenza=false;
		for (var i=0;i<ArrayElementi.length;i++){
			if(ArrayElementi[i].getAttribute('id_sql')==IdSql){CheckPresenza=true}
		}
		//aggiungo
		if(!CheckPresenza){
			ListaFoto_JS.innerHTML+="<li id_sql=\""+IdSql+"\"><img src=\""+ImgSrc+"\" /><span class=\"Nome\">"+ImgDescrizione+"</span><a class=\"EliminaFoto\" href=\"javascript:Eve()\" onclick=\"EliminaFoto(this,"+IdSql+")\"><img src=\"images/del.gif\" /></a><br class=\"ClearAll\" clear=\"all\" /></li>"
			IframeUtente_JS=_gb('IframeUtente');
			IframeUtente_JS.src="includes/box_utente.php?LoginAction=AddCart&id="+IdSql;
		} else{
			alert("Foto già presente nel carrello")
			}
	}

	}
	
function AddFotoToCartFromIframe(IdSql,ImgSrc,ImgDescrizione){
	
	if(!CarrelloIsPresent){BoxUtente('SoloCarrello')}
	if(TabUtente!='MenuUtente_Carrello'){ApriMenuUtente('MenuUtente_Carrello')}

	var ListaFoto_JS=_gb('ListaElementi');
	var ZoomContainer_JS=_gb('ZoomContainer');
	var ArrayElementi=ListaFoto_JS.getElementsByTagName('li');
	//check
	var CheckPresenza=false;
	for (var i=0;i<ArrayElementi.length;i++){
		if(ArrayElementi[i].getAttribute('id_sql')==IdSql){CheckPresenza=true}
	}
	//aggiungo
	if(!CheckPresenza){
		ListaFoto_JS.innerHTML+="<li id_sql=\""+IdSql+"\"><img src=\""+ImgSrc+"\" /><span class=\"Nome\">"+ImgDescrizione+"</span><a class=\"EliminaFoto\" href=\"javascript:Eve()\" onclick=\"EliminaFoto(this,"+IdSql+")\"><img src=\"images/del.gif\" /></a><br class=\"ClearAll\" clear=\"all\" /></li>"
	} 	

	}
	
function AddCart(NodoSorgente){

	FotoElement=NodoSorgente.parentNode.parentNode;
	var IdSql=FotoElement.getAttribute('id_sql');
	var ImgSrc=FotoElement.getElementsByTagName('img')[1].src;
	var ImgDescrizione=FotoElement.getElementsByTagName('p')[0].innerHTML;
	AddFotoToCart(IdSql,ImgSrc,ImgDescrizione);

}

function InitCart(){

	var ListaFoto_JS=_gb('ListaElementi');
	ListaFoto_JS.innerHTML='';
	IframeUtente_JS=_gb('IframeUtente');
	IframeUtente_JS.src="includes/box_utente.php?LoginAction=InitCart";
	

}		
function EliminaFoto(NodoSorgente){
	FotoElement=NodoSorgente.parentNode;
	var IdSql=FotoElement.getAttribute('id_sql');
	IframeUtente_JS=_gb('IframeUtente');
	IframeUtente_JS.src="includes/box_utente.php?LoginAction=RemCart&id="+IdSql;
	FotoElement.parentNode.removeChild(FotoElement)
	}

function EliminaMessaggio(NodoSorgente){
	FotoElement=NodoSorgente.parentNode;
	var IdSql=FotoElement.getAttribute('id_sql');
	IframeUtente_JS=_gb('IframeUtente');
	IframeUtente_JS.src="includes/box_utente.php?LoginAction=RemMessaggio&id="+IdSql;
	FotoElement.parentNode.removeChild(FotoElement)
	}

function _gTag(Tag,Div){
	return Div.getElementsByTagName(Tag);
	}
	
function LogOut(){
	IframeUtente_JS=_gb('IframeUtente');
	IframeUtente_JS.src="utente.php?LoginAction=Esci";
	UtenteIsLogged=false;
	}
	
function AggiornaSelectSottocategorie(Idcategoria){
	var ValoreSelectGallery='';
	var CheckOptionSelected=0;
	var SelectTotale=_gb('BoxRicercaSelectSottocategorieTotale');
	SelectTotale.style.display='none';
	SelectSottocategorie=_gb('BoxRicercaSelectSottocategorie');
	SelectSottocategorie.innerHTML='';
	OptionsTotale=_gTag('option',SelectTotale);
	
	for(i=0;i<OptionsTotale.length; i++){
		if(Idcategoria==OptionsTotale[i].getAttribute("id_categoria")){
			NodoClone=OptionsTotale[i].cloneNode(true);
			SelectSottocategorie.appendChild(NodoClone);
			if(CheckOptionSelected==0){
				CheckOptionSelected=1;
				ValoreSelectGallery=OptionsTotale[i].value;
				}
			}
	
		if(OptionsTotale[i].getAttribute("id_categoria")=="all"){
			NodoClone=OptionsTotale[i].cloneNode(true);
			SelectSottocategorie.appendChild(NodoClone);
			}
			
		}
	if(ValoreSelectGallery!=''){
		AggiornaSelectGallery(ValoreSelectGallery);
		}
}

function AggiornaSelectGallery(IdSottocategoria){
	var SelectTotale=_gb('BoxRicercaSelectGalleryTotale');
	SelectTotale.style.display='none';
	SelectGallery=_gb('BoxRicercaSelectGallery');
	SelectGallery.innerHTML='';
	OptionsTotale=_gTag('option',SelectTotale);
	for(i=0;i<OptionsTotale.length; i++){
		if(IdSottocategoria==OptionsTotale[i].getAttribute("id_sottocategoria") || OptionsTotale[i].getAttribute("id_sottocategoria")=="all" ){
			NodoClone=OptionsTotale[i].cloneNode(true);
			SelectGallery.appendChild(NodoClone);
			}
		}
}

function Preventivo(){
	_gb('PageContentBody').innerHTML="Loading Content ..."
	IframeUtente_JS=_gb('IframeUtente');
	IframeUtente_JS.src="includes/box_utente.php?LoginAction=PreventivoCart";
	_gb('PageContentBox').style.display="block"

	}
	
function ConfermaPreventivo(){
	IframeUtente_JS=_gb('IframeUtente');
	IframeUtente_JS.src="utente.php?LoginAction=PreventivoCartFinale";
	
}

function ApriMenuUtente(IdMenu){
	MenuUtente_JS=_gb('MenuUtente')
	
	TabTotale=_gTag('a',MenuUtente_JS);
	for(i=0;i<TabTotale.length; i++){
		TabTotale[i].className='';
		}

	_gb(IdMenu).className='Selezionato';
	_gb('MenuUtenteSelected').innerHTML=_gb(IdMenu).innerHTML
	
	IframeUtente_JS=_gb('IframeUtente');
	IframeUtente_JS.src="utente.php?LoginAction=DatiMenu&TipoMenu="+IdMenu;
	TabUtente=IdMenu;
	
	}

function ApriPreventivo(NodoSorgente,IdSql){

	IframePagine_JS=_gb('IframePagine');
	IframePagine_JS.src="utente.php?LoginAction=InfoPreventivo&id="+IdSql;
	_gb('PageContentBody').innerHTML="Loading ..."
	_gb('PageContentBox').style.display="block"
	
}

function ApriMessaggio(NodoSorgente,IdSql){

	IframePagine_JS=_gb('IframePagine');
	IframePagine_JS.src="utente.php?LoginAction=InfoMessaggio&id="+IdSql;
	_gb('PageContentBody').innerHTML="Loading ..."
	_gb('PageContentBox').style.display="block"
	
}

function CheckLogged(){
	if(UtenteIsLogged==true){
	ApriMenuUtente('MenuUtente_Carrello')
	var	BoxTag_JS=_gb('TagBox');
	BoxTag_JS.className='BoxBase NonVisibile';

	}
	
}

function CaricaNews(){
		IframePagine_JS=_gb('IframePagine');
		IframePagine_JS.src="news.php";
_gb('PageContentBody').innerHTML="Loading ..."

	
}
