// JavaScript Document
var urlSito=location.host;
//-- funzione rollover
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];}
}
//-->


var urlSito=location.host;
// MOSTRA - NASCONDI (Split)
function Attiva(Menu) {
objMenu=document.getElementById(Menu);

if (objMenu.style.display == "none") 
{
	objMenu.style.display = "block";
	
}
else 
{
	objMenu.style.display = "none";
	
}
} 


function Adv(adv,mode) {
objMenu=document.getElementById(adv);

if (mode==1) 
{
	objMenu.style.display = "block";
	
}
else 
{
	objMenu.style.display = "none";
	
}
} 


// setta il colore sulle righe * ie 6
function color(val)
{
function sfHover() {
	if(!document.getElementById(val))
    {
        return;
    }
	var sfEls = document.getElementById(val).getElementsByTagName("a");
	for (var i=0; i<sfEls.length; i++) { 
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

browsername=navigator.appName;

if (browsername.indexOf("Microsoft")!=-1) {

if (navigator.appVersion.indexOf("6.0")!=-1)
	{
			sfHover(val);
			
	}
}

}

//stampa
function stampa()
{
window.open('stampa.php','Stampa','scrollbars=1,resizable=0,width=575,height=400');
}


//-- funzioni per ajax
// funzione per assegnare un oggetto XMLHttpRequest
		function assegnaXMLHttpRequest() {
			var
				XHR = null,
				browserUtente = navigator.userAgent.toUpperCase();
			if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
				XHR = new XMLHttpRequest();
			else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
				if(browserUtente.indexOf("MSIE 5") < 0)
					XHR = new ActiveXObject("Msxml2.XMLHTTP");
				else
					XHR = new ActiveXObject("Microsoft.XMLHTTP");
			}
			return XHR;
		};

 
var http_request = false;
function makeRequest(val,page,id) {
		
        var postvar=val;//mainSelection.options[mainSelection.selectedIndex].value

	 if(id!="1")
		{
		document.getElementById("col_cent").innerHTML ='<div align="center"><img src="immagini/loader.gif" vspace="30"  ></div>';
		}
			else
			     {
				   document.getElementById("box_link_art").innerHTML ='<div align="center"><img src="immagini/loader.gif" vspace="30"  ></div>';
				 }
				 
		http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                //http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function(){
		scrivi(postvar,id);
	 
	}
    
	var pg=page+".php";
	
	 
	http_request.open("POST", ""+pg, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(postvar);

    }

//-- stampa risultato
function scrivi(postvar,id)
{
	     
	
	switch(id)
	 {
	   case 1 :  div="col_cent";
	   break;
	   case 2 : div="box_link_art";
	   break;
	   case 3 :   div="dispense";
	   break;
	   default :   div="col_cent";
	 }
	
			if (http_request.readyState == 4) 
			{
           
						if (http_request.status == 200) 
						{
							
							document.getElementById(''+div).innerHTML = http_request.responseText; 
						
						}
						
						else {
							document.getElementById(''+div).innerHTML ='<div align="center"><br>Problemi di connessione riprovare grazie.</b></div>';
					
						}
         
		 	
			}


    }

//-- Buddy post
function getpost(post,page)
{
var mail_ut=document.getElementById('mail_ut').value;
var mail_to=document.getElementById('mail_to').value;
var mex=document.getElementById('mex').value;
var autore=document.getElementById('autore').value;
var new_post=post+"&mail_to="+mail_to+"&mail_ut="+mail_ut+"&autore="+autore+"&mex="+mex+"&ok=ok"
//alert(new_post);
makeRequest(new_post,page,'');
}

//-- iscrizione newsletter
function nlett()
{
var mail_ut=document.getElementById('mail_ut').value;
var cognome=document.getElementById('cognome').value;
var nome=document.getElementById('nome').value;
var new_pos="&mail_ut="+mail_ut+"&cognome="+cognome+"&nome="+nome+"&ok=ok";
makeRequest(new_pos,"nlett_add",'');
}

function scriviDirettore()
{
var mail_ut=encodeURIComponent(document.getElementById('mail_ut').value);
var cognome=encodeURIComponent(document.getElementById('cognome').value);
var nome=encodeURIComponent(document.getElementById('nome').value);
var oggetto=encodeURIComponent(document.getElementById('oggetto').value);
var mex=encodeURIComponent(document.getElementById('mex').value);
var new_pos="&mex="+mex+"&oggetto="+oggetto+"&mail_ut="+mail_ut+"&cognome="+cognome+"&nome="+nome+"&ok=ok";

makeRequest(new_pos,"scrivi",'');
}

//-- stampa 
function leggi()
{
var cont=opener.document.getElementById("stamp").innerHTML;
document.getElementById("box_first").innerHTML = cont;

var cont=opener.document.getElementById("cn_int").innerHTML;
document.getElementById("cn_int").innerHTML = cont;
}

function homepage() { 
if(document.all)
	{
	document.body.style.behavior='url(#default#homepage)';
	document.body.setHomePage('http://mondoprofessionisti.comingonweb.it');
	}
} 

function setaddhp()
{
	if(document.all)
	{
		document.write('&nbsp;<a href="javascript:void(\'0\')" ><img src="immagini/aggiungi_preferiti.gif" alt="fai di mondoprofessionisti la tua homepage" border="0" onclick="homepage();" /></a>');
	}
}

//-- funzioni per aggiornamento select.
function azzera(val)
{
var subSelection=document.getElementById(val)
for (var i = subSelection.length - 1; i >= 0; i--) 
subSelection.remove(i); 

var NewOpt = document.createElement('option'); 
	NewOpt.value = ""; 
	NewOpt.text = "-"; 
	try{ 
	subSelection.add(NewOpt, null); //Metodo Standard, non funziona con IE 
	}catch(e){ 
	subSelection.add(NewOpt); // Funziona solo con IE 
	} 
}

function updateSubSelection(XMLResult,select2){
if (http_request.readyState == 4) 
			{
              
						if (http_request.status == 200) 
						{
							
							//Gestisco il documento XML ricevuto e popolo la seconda SELECT 
								var sub_categoria = http_request.responseXML.getElementsByTagName(select2); 
								//Recupero la seconda SELECT 
								var subSelection = document.getElementById(select2); 
								//Scorro gli elementi  
								//alert(http_request.responseText.getElementsByTagName(select2))
								for (var i = 1; i < sub_categoria.length; i++){ 
								//Recupero i vari elementi singoli 
								var item = sub_categoria[i]; 
								//Creo il nuovo elemento OPTION da aggiungere nella seconda SELECT 
								var NewOpt = document.createElement('option'); 
								NewOpt.value = item.getAttribute("value"); 
								NewOpt.text = item.firstChild.nodeValue; 
								//Popolo la seconda SELECT 
								try{ 
								subSelection.add(NewOpt, null); //Metodo Standard, non funziona con IE 
								}catch(e){ 
								subSelection.add(NewOpt); // Funziona solo con IE 
								} 
								} 
						
						}
						
						else {
							alert('Problemi di connessione riprovare grazie.');
					
						}
         
		 	
			}	


}


//-- CREO LA SELECT 
function populateSubSelection(select1,select2,val)
{
        //var postvar=val;//mainSelection.options[mainSelection.selectedIndex].value
		var mainSelection = document.getElementById(select1); 
		var postvar="choice="+mainSelection.options[mainSelection.selectedIndex].value+"&op="+val;
		//Recupero la seconda SELECT 
		var subSelection = document.getElementById(select2); 
		//Svuoto la secondo SELECT 
		for (var i = subSelection.length - 1; i >= 0; i--) 
		subSelection.remove(i); 
		//document.getElementById("col_cent").innerHTML ='<div align="center"><img src="immagini/loader.gif" vspace="30"  ></div>';
		
		http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                //http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function(){
		updateSubSelection(postvar,select2);
	 
	}
    
	var pg="http://mondoprofessionisti.comingonweb.it/includes/comune_ajax_fh.php";
	
	http_request.open("POST", ""+pg, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(postvar);

    }
/* DISPENSE */
//compra dispensa
function buydisp(id)
{
window.open('buy.php?id='+ id ,'Stampa','scrollbars=1,resizable=0,width=780,height=470');
}
//-- privato - azienda
function PrAz()
{
	var tipo=  document.getElementById("tipo_ut1").checked ;
	
	if(tipo == true)
	{
	  val=2;
	}
	 else 
	     {
		   val=1;
		 }

if(val == "1") // azienda

   {

	document.getElementById("cf").disabled=true;
	document.getElementById("cf").value="";
		  document.getElementById("denominazione").disabled=false;
		  document.getElementById("iva").disabled=false; 
		  document.getElementById("iva").style.background="#FFFFFF";
		     document.getElementById("denominazione").style.background="#FFFFFF";
			   document.getElementById("cf").style.background="#CCCCCC";
		  
		 
   }
     else 
	 		{
			   document.getElementById("cf").disabled=false;
			  document.getElementById("denominazione").disabled=true;
		 	 document.getElementById("iva").disabled=true;
		   document.getElementById("denominazione").value="";
		 	 document.getElementById("iva").value="";
			 
		   document.getElementById("iva").style.background="#CCCCCC";
		    document.getElementById("denominazione").style.background="#CCCCCC";
			   document.getElementById("cf").style.background="#FFFFFF";
			 
			
			}
}

function ckNum(campo)
{
var data = document.getElementById(campo).value;

if(data !="")
   {
			if (isNaN(data)) {
						   alert("Sono ammessi solo numeri");
						   document.getElementById(campo).select(); 
						   };
   }
}

/*NASCONDI FLASH */
function swf_hide()
{
var flashObjects = document.getElementsByTagName('object'); 
for (i = 0; i != flashObjects.length; i++) { flashObjects[i].style.visibility = 'hidden'; } 
var flashEmbeds = document.getElementsByTagName('embeds'); 
for (i = 0; i != flashEmbeds.length; i++) { flashEmbeds[i].style.visibility = 'hidden'; } 
}

function swf_disp()
{
var flashObjects = document.getElementsByTagName('object'); 
for (i = 0; i != flashObjects.length; i++) { flashObjects[i].style.visibility = 'visible'; } 
var flashEmbeds = document.getElementsByTagName('embeds'); 
for (i = 0; i != flashEmbeds.length; i++) { flashEmbeds[i].style.visibility = 'visible'; } 
}

/* LISTA DISPENSE */
function disp(post)
{
var alfabeto=new Array('a','b','c','d','e','f','g','h','i','l','m','n','o','p','q','r','s','t','u','v','z')
 for(var i='0'; i<='20'; i++)
	{
     var lettera=alfabeto[i];
	 objMenu=document.getElementById(lettera);
	 if(post==alfabeto[i])
        {
			if(objMenu) 
			objMenu.style.display="block";
		}
			else
				 {
					    
						if(objMenu) 
								{
									objMenu.style.display="none";
								}
				  }
	}
}
