/* CONFIG */
menuClassName = "menuNavigazione";
menuOn        = "subMenu-on";
menuOff       = "subMenu-off";
var link_foto = "";	
var conta = 1;
var conta2 = 1;
var valore = 10;

var opa = 0;
var opa2 = 0;

var id_sfumatura;


function ruota_immagini(){
 
 elemento1  = prendiElementoDaId("titolo");
 
 if (conta == 1) { elemento1.style.background='url(documenti/lavoro/immagini/barcode.gif) no-repeat center'; }
 if (conta == 2) { elemento1.style.background='url(documenti/lavoro/immagini/wifi.gif) no-repeat center'; }
 if (conta == 3) { elemento1.style.background='url(documenti/lavoro/immagini/web.gif) no-repeat center'; }
 if (conta == 4) { elemento1.style.background='url(documenti/lavoro/immagini/software.gif) no-repeat center'; }
 if (conta == 5) { elemento1.style.background='url(documenti/lavoro/immagini/riparazioni.gif) no-repeat center'; }
 if (conta == 6) { elemento1.style.background='url(documenti/lavoro/immagini/pc.gif) no-repeat center'; }
 if (conta == 7) { elemento1.style.background='url(documenti/lavoro/immagini/rfid.gif) no-repeat center'; }
 if (conta == 8) { elemento1.style.background='url(documenti/lavoro/immagini/digitalizzazione.gif) no-repeat center'; }

 if (conta == 1) { img_sx.src = "documenti/lavoro/immagini/barcode_small.jpg"; }
 if (conta == 2) { img_sx.src = "documenti/lavoro/immagini/wifi_small.jpg"; }
 if (conta == 3) { img_sx.src = "documenti/lavoro/immagini/web_small.jpg"; }
 if (conta == 4) { img_sx.src = "documenti/lavoro/immagini/software_small.jpg"; }
 if (conta == 5) { img_sx.src = "documenti/lavoro/immagini/riparazioni_small.jpg"; }
 if (conta == 6) { img_sx.src = "documenti/lavoro/immagini/pc_small.jpg"; }
 if (conta == 7) { img_sx.src = "documenti/lavoro/immagini/rfid_small.jpg"; }
 if (conta == 8) { img_sx.src = "documenti/lavoro/immagini/digitalizzazione_small.jpg"; }

 if (conta < 8) { conta++; }
 else           { conta = 1; } 

 setTimeout("ruota_immagini()", 2000); 
}


function ruota_immagini_2(){
 
 if (conta2 == 1) { img_radio.src = "jpg/radio0.gif"; }
 if (conta2 == 2) { img_radio.src = "jpg/radio1.gif"; }
 if (conta2 == 3) { img_radio.src = "jpg/radio2.gif"; }
 if (conta2 == 4) { img_radio.src = "jpg/radio3.gif"; }
 if (conta2 == 5) { img_radio.src = "jpg/radio2.gif"; }
 if (conta2 == 6) { img_radio.src = "jpg/radio1.gif"; }

 if (conta2 < 6) { conta2++; }
 else            { conta2 = 1; } 
 	
 setTimeout("ruota_immagini_2()", 200); 
}

function sfuma_immagini(){

 if ( (opa == 0) || (opa == 100) ) 
 {
  opa = 0;
  opa2 = 0;
 
  effetto_sfumatura();
 } 
}


function effetto_sfumatura(){
 
 var img1 = document.images["img_radio"];
 var img2 = document.images["img_testata"];
 var img3 = document.images["img_servizi"];
 
 opa++;
 opa2 = opa2 + 0.01;
 
 if (opa < 100)
 {
 	if (document.all)
  {	
   img1.filters.alpha.opacity = opa;
   img2.filters.alpha.opacity = opa;
   img3.filters.alpha.opacity = opa;   
  }
  else
  {	
   img1.style.MozOpacity = opa2;
   img2.style.MozOpacity = opa2;
   img3.style.MozOpacity = opa2;
  }
  id_sfumatura = setTimeout("effetto_sfumatura()", 30); 
 }
 else
 {	
 	clearInterval(id_sfumatura);
 }	
}


/* SCRIPT */
function closeSub(menu) {
	for (var i=0; i<menu.childNodes.length; i++)
		if (menu.childNodes[i].nodeName.toLowerCase()=="li") {
			li = menu.childNodes[i];
			li.onmouseover = li.onactivate = li.onfocus = function() { if (this.subMenu) 
			{
			    if (this.subMenu.className == menuClassName + " " + menuOff) {this.subMenu.className = this.subMenu.className + " " + menuOn;}
                else {this.subMenu.className = menuOn;}
			}}			
			li.onmouseout = li.ondeactivate = li.onblur = function() { if (this.subMenu) {closeSub(this.subMenu);} };
			for (j=0; j<li.childNodes.length; j++)
				if (li.childNodes[j].nodeName.toLowerCase()=="ul" || li.childNodes[j].nodeName.toLowerCase()=="ol") closeSub(li.subMenu = li.childNodes[j])
		}
    if (menu.className == menuClassName) {menu.className = menu.className + " " + menuOff;}
    else {menu.className = menuOff;}
}

/* ON LOAD */
window.onload = function() {
}


function carica_menu()
{
	if(tags_ = document.getElementsByTagName("ul"))
		for(i=0; i<tags_.length; i++) 
			if (tags_[i].className==menuClassName) closeSub(tags_[i]);
	if(tags_ = document.getElementsByTagName("ol"))
		for(i=0; i<tags_.length; i++) 
			if (tags_[i].className==menuClassName) closeSub(tags_[i]);
			
}


function prendiElementoDaId(id_elemento) 
{
	var elemento;
	if(document.getElementById)
		elemento = document.getElementById(id_elemento);
	else
		elemento = document.all[id_elemento];
	return elemento;
}

function setActiveStyleSheet(titolo)
{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{	
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
		{
			a.disabled = true;
			if(a.getAttribute("title") == titolo) a.disabled = false;
		}
	}
}


function Mostra() {
        if (document.getElementById) {
                document.getElementById("s1").style.visibility="visible";
                document.getElementById("s2").style.visibility="visible";
                document.getElementById("s3").style.visibility="visible";                                
        } else if (document.all) {
                document.all.s1.style.visibility="visible";
                document.all.s2.style.visibility="visible";
                document.all.s3.style.visibility="visible";                                
        }
}

function Nascondi() {
	
        if (document.getElementById) {
                document.getElementById("s1").style.visibility="hidden";
                document.getElementById("s2").style.visibility="hidden";
                document.getElementById("s3").style.visibility="hidden";                                
        } else if (document.all) {
                document.all.s1.style.visibility="hidden";
                document.all.s2.style.visibility="hidden";
                document.all.s3.style.visibility="hidden";                                
        }
}


function sf(oggetto)
{	
	oggetto.focus();
}

function svuota()
{	
	contratto.prodotto.value = '';
}

function dimensiona_div() 
{
	alert("OK");
			    elemento1  = prendiElementoDaId("corpo");
			    elemento2  = prendiElementoDaId("centro");               
			    elemento3  = prendiElementoDaId("sx");               
                a=elemento1.clientHeight;
                b=(a)+"px";
				elemento3.style.height=b;
}






// inizio htmlEntities -> http://www.dieterraber.net/jsStringFuncs.htm
String.prototype.htmlEntities = function()
{
  var chars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
                         'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
                         'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
                         'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
                         'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
                         'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<',
                         '>','¢','£','¤','¥','¦','§','¨','©','ª','«',
                         '¬','­','®','¯','°','±','²','³','´','µ','¶',
                         '·','¸','¹','º','»','¼','½','¾');

  var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
                            'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
                            'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
                            'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
                            'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
                            'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
                            'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
                            'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
                            'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig',
                            'lt','gt','cent','pound','curren','yen','brvbar','sect','uml',
                            'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
                            'sup2','sup3','acute','micro','para','middot','cedil','sup1',
                            'ordm','raquo','frac14','frac12','frac34');

  newString = this;
  for (var i = 0; i < chars.length; i++)
  {
    myRegExp = new RegExp();
    myRegExp.compile(chars[i],'g')
    newString = newString.replace (myRegExp, '&' + entities[i] + ';');
  }
  return newString;
}
// fine htmlEntities -> http://www.dieterraber.net/jsStringFuncs.htm


function showpreview(){
	contenuto_testo=document.getElementById("testo").value;
	// trasformo caratteri in htmlEntities
	// se si vuol mantenere inserimento HTML commentare la riga
	contenuto_testo=contenuto_testo.htmlEntities();
	// trasformo a capo in <br/>
	contenuto_testo=contenuto_testo.replace(/\n/g,"<br/>");
	document.getElementById("preview").innerHTML=contenuto_testo;
}









function carica_menu_sx(m1)
{
 elemento = prendiElementoDaId("sx");               
 elemento.style.height="auto";			

 var percorso="carica_menu_sx.php?m1="+m1;	
 nome_div2 = "sx_menu";
 xmlHttp2=GetXmlHttpObject2();
 if (xmlHttp2==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
 xmlHttp2.onreadystatechange=stateChanged2;
 xmlHttp2.open("GET",percorso,true);
 xmlHttp2.send(null);	
}


function carica_contenuto(m1,m2)
{
 

 elemento = prendiElementoDaId("centro");               
 elemento2 = prendiElementoDaId("corpo");               
 elemento.style.height="auto";			

 elemento2.style.cursor = 'wait';
 
// alert(document.body.style.cursor);
 
 var percorso="carica_contenuto.php?m1="+m1+"&m2="+m2;	
 nome_div = "centro";
 xmlHttp=GetXmlHttpObject();
 

 
 if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.open("POST",percorso,true);
  xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );

  xmlHttp.send(null);

 elemento2.style.cursor = 'default';
}



function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function GetXmlHttpObject2()
{
var xmlHttp2=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp2=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp2;
}


function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	//alert(xmlHttp.responseXML);

//   	alert(xmlHttp.responseText);

 	//alert("OK");
//alert(xmlhttp.getAllResponseHeaders);

str = xmlHttp.responseText;

//str = xmlHttp.responseXML;
//alert(str);
str = str.replace(/#/g,"");

 document.getElementById(nome_div).innerHTML=str;
 } 
}

function stateChanged2() 
{ 
if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
 { 
 document.getElementById(nome_div2).innerHTML=xmlHttp2.responseText;
 } 
}



