function apriMappa(filtro,tipoFiltro, objLink)
{
    if (!objLink) {objLink=document.getElementById('linkApriMappaGruppo')};
    objLink.href='creaMappa.asp?filtro=' + filtro + '&tipofiltro=' + tipoFiltro;
    return hs.htmlExpand(objLink, { contentId: 'bloccoMappe', objectType: 'iframe', objectWidth: 700, objectHeight: 650} );
}


function AJAX(pagina, onComplete ) {
 var ajax_r
 // per l’oggetto nativo XMLHttpRequest
 if (window.XMLHttpRequest) {
  ajax_r = new XMLHttpRequest();
  ajax_r.onreadystatechange = function() {riceviAJAX(ajax_r,onComplete) };
  ajax_r.open("GET", pagina, true);
  ajax_r.send(null);
 // per IE
 } else if (window.ActiveXObject) {
  ajax_r = new ActiveXObject("Microsoft.XMLHTTP");
  if (ajax_r) {
  ajax_r.onreadystatechange = function() {riceviAJAX(ajax_r,onComplete) };
   ajax_r.open("GET", pagina, true);
   ajax_r.send();
  }
 }
}

function riceviAJAX(strm,onComplete) {
 var strRes;
 var arrValori;
 if (strm.readyState == 4) {
  strRes = strm.responseText;
  return onComplete(strRes);  
 }
}

// --------- filtro le combo via AJAX ---------------------
var timAjaxFiltra,fileCallAjaxCB,idTestoAjaxCB,idComboAjaxCB
function ajaxFiltraCombo(oDa,idCb,azione,valoreSelezionato,fileASP)
{
    clearTimeout(timAjaxFiltra);
    curComboAjax=document.getElementById(idCb);
    var pagina;
    fileCallAjaxCB='ajaxAzioni.asp';
    if (typeof(fileASP) !='undefined') {fileCallAjaxCB=fileASP;}
    if(fileCallAjaxCB.indexOf('?') < 0) {fileCallAjaxCB =fileCallAjaxCB + '?a=a'}
    fileCallAjaxCB=fileCallAjaxCB + '&azione=' + azione + '&default=' + valoreSelezionato;
    idTestoAjaxCB=oDa.id;
    idComboAjaxCB=idCb;
    timAjaxFiltra = setTimeout('eseguiAjaxFiltra()',800)
}
function eseguiAjaxFiltra()
{
    //alert(fileCallAjaxCB + '&filtro=' + document.getElementById(idTestoAjaxCB).value);
    if (curComboAjax) { AJAX(fileCallAjaxCB + '&filtro=' + document.getElementById(idTestoAjaxCB).value, riceviAjaxFiltra )     }
}
function riceviAjaxFiltra(aa)
{
    //alert(aa);
    updateComboOptions(document.getElementById(idComboAjaxCB),aa)
}
//----------------------------------------------------------------

function updateComboOptions(obj,sVal)
{
    //alert(sVal);
    // sVal deve essere del seguente formato: "Opzione1[1]|Opzione2[2]selected|Opzione3[3]"
    var mVal=sVal.split('|');
    var iJ,opt,idx,valu,selIndex;
    obj.options.length=0;
    selIndex=0;
    for (iJ=0; iJ<=mVal.length -1; iJ++)
     {
        if(mVal[iJ].length>2)
        {
            opt=document.createElement('option');
            if (mVal[iJ].indexOf('selected')>0) {selIndex=iJ;}
            idx=mVal[iJ].indexOf('[');
            opt.text=mVal[iJ].substr(0,idx) ;
            valu=mVal[iJ].substr(idx+1);
            valu=valu.substr(0,valu.indexOf(']') );
            opt.value=valu;
            try
                { obj.add(opt, null);}
            catch(ex)
                {obj.add(opt);} 
        }
      } 
     try {obj.selectedIndex=selIndex;} catch(ex) {}
}

//--------- funzioni di validazione dati ------------------------------------
function validaValoreCampo(obj,lMin,lMax,TipoDati,nomeCampo,bRequired)
{
	var strV,sErr;
	sErr='';
	strV=obj.value;
	if (TipoDati.toLowerCase() == 'sinoseleziona')
	{
		if (obj.selectedIndex==0) {sErr=sErr + 'Selezionare una voce per il campo ' + nomeCampo + '.\n';}
	}
	
	if (TipoDati.toLowerCase() == 'checkbox' && bRequired==true)
	{
		if (obj.checked==false) {sErr=sErr + 'E\' necessario selezionare la voce ' + nomeCampo + '.\n'; lMin=0;lMax=0;} 
	}
	
	if (lMin >0 && strV.length < lMin) {sErr='Inserire almeno ' + lMin + ' caratteri nel campo ' + nomeCampo + '.\n'; };
	if (lMax >0 && strV.length > lMax) {sErr=sErr + 'Inserire al massimo ' + lMax + ' caratteri nel campo ' + nomeCampo + '.\n';};
	if (TipoDati.toLowerCase() == 'numerico' || TipoDati.toLowerCase() == 'intero')
	{
		var espr= new RegExp("[. a-z.\/.\-]")
		if (espr.test(strV)) {sErr=sErr + 'Inserire solo valori numerici per il campo ' + nomeCampo + '.\n';}
	}
	
	if (sErr !='')
	{
		obj.style.color='red'
		obj.style.backgroundcolor='#FFFFFF';
		alert(sErr);
		obj.focus()
		return false;
	}
	return true;
}

// -------- funzioni per visualizzare tooltip ---------------------//
var x,y,timer2;
function mostratool(text,larghezza, tipo){
	if(text=="") return;
	
	var inizio, fine;
	inizio="<table width=\"" + larghezza + "\" class=\"TabellaTooltip\" border=\"0\" ><tr><td>";
	fine="</td></tr></table>";
	if (tipo=="immagine")
		{
			//........caricare l'immagine, ricavare le dimensioni e impostare il frame alle dimensioni volute..........
			inizio="<iframe scrolling=\"no\" id=\"iframeTooltip\" class=\"TabellaTooltip\" width=\"" + larghezza + "\" style=\"z-index:150;\" src=\"vuota.htm\">" ;
			fine="</iframe>";
			document.getElementById('BloccoTooltip').innerHTML=inizio + fine ;
			var s, frameTT,hImmagine;
			frameTT=document.getElementById('iframeTooltip')
			
			s="<html><head><style type=\"text/css\"> body { margin-left: 0px; 	margin-top: 0px; 	margin-right: 0px; 	margin-bottom: 0px;  background-color: #666666; } </style></head>" ;
			s=s + "<body>" ;
			s=s + "<img id=\"immagineTooltipPreview\" src=\"" + text +"\" border=\"0\" width=\"" + larghezza + "\">"
			s=s + "</body></html>"
			
			frameTT.contentWindow.document.write(s);
			hImmagine=frameTT.contentWindow.document.getElementById('immagineTooltipPreview').height;
			if (hImmagine=="" || hImmagine=='nothing' || hImmagine > 100) hImmagine=80;
			frameTT.style.height=hImmagine;

		} else {
			text=inizio + text + fine;
			document.getElementById('BloccoTooltip').innerHTML=text ;
		}

	 MostraToolTipOK(larghezza);
}

function MostraToolTipOK(larghezza) {
	if (x + larghezza + 10 > document.body.clientWidth) { x=x - larghezza -10 };
	document.getElementById('BloccoTooltip').style.visibility="visible";
	document.getElementById('BloccoTooltip').style.pixelLeft=x + 3;
	document.getElementById('BloccoTooltip').style.pixelTop=y + 6;
	document.getElementById('BloccoTooltip').style.left=x + 3;
	document.getElementById('BloccoTooltip').style.top=y + 6;	
	timer2=setTimeout("MostraToolTipOK(" + larghezza + ")",10);
}

function nasconditool(){
	document.getElementById('BloccoTooltip').style.visibility="hidden";
	clearTimeout(timer2);
}

function seleziona(o,posIniz)
{
    var lung,range;
    lung=o.value.length;
    if (lung>1 && posIniz <lung)
    {
        range=o.createTextRange();        
	    range.findText(o.value.substr(1));
	    range.select();
    }    
}
function testoSelect(obj)
{
    return obj.options[obj.selectedIndex].text;
}

function getMousePos(e){
	if (!e)
		var e = window.event||window.Event;
	if('undefined'!=typeof e.pageX){
		x = e.pageX;
		y = e.pageY;
	} else {
		x = e.clientX + document.body.scrollLeft;
		y = e.clientY + document.body.scrollTop;
	}
}

// You need to tell Mozilla to start listening:
if(window.Event && document.captureEvents)
 	document.captureEvents(Event.MOUSEMOVE);
// Then assign the mouse handler
document.onmousemove = getMousePos;

// -------- fine funzioni tooltip ---------------------//


function acquistaContenuto(objForm)
{
	if (confirm('Aggiungere il prodotto al carrello ordini?'))
		{
			
			objForm.azione.value="addcontenutocarrello";
			objForm.submit();
		}
}
function carrelloContenuto(objForm)
{
	objForm.azione.value="mostracontenutocarrello";
	objForm.submit();
}

function zoomImg(img)
{
	nw=window.open('zoomimage.asp?img=' + img,'mwin','titlebar=0,toolbar=no,status=0,menubar=no,scrollbars=no,width=20,height=20,resizable=yes,left=' + screen.width/2 + ',top=' + screen.height/2 );
	nw.focus();
}


// JavaScript Document
/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var menuwidth='165px' //default menu width
var menubgcolor='lightblue'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6) dropmenuobj.style.left=dropmenuobj.style.top="-500px"
	if (menuwidth!=""){
	dropmenuobj.widthobj=dropmenuobj.style
	dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover") obj.visibility=visible
	else if (e.type=="click") obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
mostraNascondiCombo(false);
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
mostraNascondiCombo(true);
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function mostraNascondiCombo(stato)
{
	var vis, Combo;
	vis='hidden';
	if(stato) {vis='visible'};
	try
	{
		Combo=document.body.getElementsByTagName('select');
		for(i=0;i<Combo.length;i++)
		{
			try
			{ Combo[i].style.visibility=vis; }
			catch(ex)
			{		}
		}
	}
	catch(ex)
	{ }
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu


function TestoDaHtml(s)
{
    var v;
    v=s;
    if (s.indexOf('<') > 0) v=s.substring(0,s.indexOf('<'));
    if (s.indexOf('>') > 0) v=v + s.substring(s.indexOf('>')+1);
    if (v.indexOf('<') > 0) v=TestoDaHtml(v) ;
    return v;
}



//**********************************                  ***********/////
function MostraRigaSottomenu(oggetto,idSottomenu,idPlace)
{
    var blocco,aa;
    for(i=0;i<20;i++)
       {
         try
            {
                aa='';
                aa=document.getElementById('TDMenuTop' + i).className;
                if(aa.toLowerCase().indexOf("selezionato")>0) {aa=aa.toLowerCase().replace("selezionato","")}
                document.getElementById('TDMenuTop' + i).className=aa;
                document.getElementById('PlaceHolderSottomenu' + i).style.display='none';                                
            }
            
            catch(e)
            {  
            }
        }
    blocco=document.getElementById(idSottomenu).innerHTML;
    document.getElementById(idPlace).innerHTML=blocco;
    document.getElementById(idPlace).className='PlaceHolderSottomenuAttivo';
    aa=document.getElementById('TDMenuTop' + oggetto).className;
    if(aa.toLowerCase().indexOf("selezionato")<=0) {aa=aa + 'Selezionato'}
    document.getElementById('TDMenuTop' + oggetto).className=aa;
    document.getElementById(idPlace).style.display='block';
}


function displayPopup(str)
{
    var d;
    d=document.getElementById('CMS_BodyPopup');
    if (!d) {
		d=document.createElement('div')
		d.id='CMS_BodyPopup';
		d.style.display='none';
		d.style.border='1px solid #000000';
		d.style.backgroundColor='#FCFCFC';
		document.body.insertBefore(d,document.body.childNodes[0])			
	}
	d.cssClass='divPopupFisso';
    d.innerHTML=str;
    
    hs.align = 'center';
	
	var objL;
    objL=document.getElementById('linkPopupFisso');
    objL.onclick=function() {return hs.htmlExpand(this, { contentId: 'highslide-html' } )}
	return objL.onclick();
	
}

function espandiHS(objLink,Larghez,Altez,Titolo,NomeDiv)
{
	if (NomeDiv=='' | !NomeDiv) {NomeDiv='highslideIframePrincipale';}
	var obj;
	obj=document.getElementById(NomeDiv);
	if(obj) {
		obj.style.width=Larghez;
		obj.style.height=Altez;
	}
	//if (NomeDiv=='highslideIframePrincipale') {document.getElementById('titoloPopupIframeComune').innerHTML=Titolo;}	
	
	return hs.htmlExpand(objLink, {contentId: NomeDiv, objectType: 'iframe', objectWidth: Larghez, objectHeight: Altez, objectLoadTime: 'before',allowHeightReduction:true,allowWidthReduction:true,cacheAjax:false,preserveContent:false} )
}