//Mostra nascondi righe di tabella
function mostra_nascondi(id_riga){
	var IE=(window.navigator.userAgent.indexOf('MSIE')>-1)?1:0;
	document.getElementById(id_riga).style.display=(document.getElementById(id_riga).style.display=='none')?((IE)?'block':'table-row'):'none';
}

//ricerca
function mostra(sel){
if(sel=='3')
{
document.getElementById('search_prod').style.display = 'block';
document.getElementById('search_prod').style.visibility = 'visible';
}
else
{
document.getElementById('search_prod').style.visibility = 'hidden';
document.getElementById('search_prod').style.display = 'none';
}
}

//funzione per aprire i documenti  in una nuova finestra
function nuova_finestra(pagina) {
	window.open(pagina,'Document','scrollbars=yes,resizable=yes,status=no,width=780,height=560,location=no,toolbar=no');
	}

//funzione per aprire i siti esterni in una nuova finestra
function link_esterno(pagina) {
	window.open(pagina,'Site','scrollbars=yes,resizable=yes,status=yes,width=780,height=560,location=yes,toolbar=yes');
	}

//Funzione per popup
function popup(pagina,wdt,hgt,scr,loc,tool,menu) {
	var wdt = 800;
	var hgt = 600;
	window.open(pagina,'popup','scrollbars='+scr+',resizable=no,left='+parseInt((screen.availWidth-wdt)/2)+',top='+parseInt((screen.availHeight-hgt)/2)+',width='+wdt+',height='+hgt+',status=no,location='+loc+',toolbar='+tool+',menubar='+menu);
}

function refreshit() {
//		var frm = document.getElementById('form');
//		if(frm.id_categoria){
//			if(frm['id_categoria'].options[frm['id_categoria'].selectedIndex]){
//				var id_categoria = frm['categoria_id'].options[frm['categoria_id'].selectedIndex];
//			}
//		}
	document.form1.target="_self";
	document.form1.action="new_articolo.asp";
	document.form1.submit();
}

//funzione per l'ingrandimento delle immagini in una pop up 		
function apri(url_foto,des_foto){
	addr="/include/fullsize.htm?"+url_foto+"&"+escape(des_foto)
	alt=150
	lar=150
	rszb=(document.layers)?1:0;
	props='height='+alt+',width='+lar+',top='+parseInt((screen.availHeight-alt)/2)+',left='+parseInt((screen.availWidth-lar)/2)+',scrollbars=0,resizable='+rszb+',toolbar=0,menubar=0,location=0,status=0';
	window.open(addr,'_blank',props);
}

//funzione per selezionare tutti/nessuno gli elementi di una checkbox
var NumeroCheck=0;
function seleziona(selID) {
    for(i=1 ; i<=NumeroCheck; i++)
    {
    document.getElementById(selID+i).checked=true;
    }
}

function deseleziona(selID) {
    for(i=1 ; i<=NumeroCheck ; i++)
    {
    document.getElementById(selID+i).checked=false;
    }
}

function checkNumPartecipanti(){
    if(document.getElementById('eventopreno_numero').value == "") {
        alert("Attenzione!\nIndicare obbligatoriamente il numero dei partecipanti per i quali si effetta la richiesta");
        document.getElementById('eventopreno_numero').focus();
        return (false);
    }
}

//Abilita disabilita SELECT da OPTION
function disable(disableIt,e)
{
    if (disableIt) {
       document.getElementById("pos" + e).disabled=false;}
    else 
       {document.getElementById("pos" + e).disabled=true;}
}

function valori(){
    var stringa="";
	var sep="";
    for(i=1; i<=NumeroCheck; i++)
	    if (document.getElementById("del_corr"+i).checked==true){
	        stringa=stringa+sep+document.getElementById("del_corr"+i).value;
	        sep=", "
	    }
    if (stringa=="")
        alert('Attenzione!\nSelezionare almeno un articolo');
    else
        nuova_finestra('default.asp.asp?str_articolo_id='+stringa);
     //   document.location.href='stampa_cv_sel.asp?str_cv_id='+stringa;
}

var XMLHTTP;
function MostraComuni(PID,CID)
{
    if (parseInt(PID) > 0)
    {
    var url = "/include/ajax_comuni.asp?pid=" + PID + "&cid=" + CID;
    XMLHTTP = RicavaBrowser(CambioProvincia);
    XMLHTTP.open("GET", url, true);
    XMLHTTP.send(null);
    }
    else
    {
    document.getElementById("show_comuni").innerHTML = "";
    } 
}
function MostraProvince(ID)
{
    if (parseInt(ID) > 0)
    {
    var url = "/include/ajax_dx_province.asp?id=" + ID;
    XMLHTTP = RicavaBrowser(CambioRegione);
    XMLHTTP.open("GET", url, true);
    XMLHTTP.send(null);
    }
    else
    {
    document.getElementById("show_province").innerHTML = "";
    } 
}
function MostraProvince2(RID,PID)
{
    if (parseInt(RID) > 0)
    {
    var url = "/include/ajax_province.asp?rid=" + RID + "&pid=" + PID;
    XMLHTTP = RicavaBrowser(CambioRegione2);
    XMLHTTP.open("GET", url, true);
    XMLHTTP.send(null);
    }
    else
    {
    document.getElementById("show_province2").innerHTML = "";
    } 
}
function MostraProvince3(RID,PID)
{
    if (parseInt(RID) > 0)
    {
    var url = "/include/ajax_province_cerca_ut.asp?rid=" + RID + "&pid=" + PID;
    XMLHTTP = RicavaBrowser(CambioRegione3);
    XMLHTTP.open("GET", url, true);
    XMLHTTP.send(null);
    }
    else
    {
    document.getElementById("show_province3").innerHTML = "";
    } 
}

function CambioProvincia()
{
    if (XMLHTTP.readyState == 4)
    {
    var R = document.getElementById("show_comuni");
    R.innerHTML = XMLHTTP.responseText;
    }
}
function CambioRegione()
{
    if (XMLHTTP.readyState == 4)
    {
    var R = document.getElementById("show_province");
    R.innerHTML = XMLHTTP.responseText;
    }
}
function CambioRegione2()
{
    if (XMLHTTP.readyState == 4)
    {
    var R2 = document.getElementById("show_province2");
    R2.innerHTML = XMLHTTP.responseText;
    }
}
function CambioRegione3()
{
    if (XMLHTTP.readyState == 4)
    {
    var R3 = document.getElementById("show_province3");
    R3.innerHTML = XMLHTTP.responseText;
    }
}

function RicavaBrowser(QualeBrowser)
{
    if (navigator.userAgent.indexOf("MSIE") != (-1))
    {
    var Classe = "Msxml2.XMLHTTP";
    if (navigator.appVersion.indexOf("MSIE 5.5") != (-1));
    {
    Classe = "Microsoft.XMLHTTP";
    } 
    try
    {
    OggettoXMLHTTP = new ActiveXObject(Classe);
    OggettoXMLHTTP.onreadystatechange = QualeBrowser;
    return OggettoXMLHTTP;
    }
    catch(e)
    {
    alert("Errore: l'ActiveX non verrą eseguito!");
    }
    }
    else if (navigator.userAgent.indexOf("Mozilla") != (-1))
    {
    OggettoXMLHTTP = new XMLHttpRequest();
    OggettoXMLHTTP.onload = QualeBrowser;
    OggettoXMLHTTP.onerror = QualeBrowser;
    return OggettoXMLHTTP;
    }
    else
    {
    alert("L'esempio non funziona con altri browser!");
    }
}

/* FUNZIONI PER LIMITARE CARATTERI DIGITATI IN TEXTAREA
/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/
var ns6=document.getElementById&&!document.all
function restrictinput(maxlength,e,placeholder){
    if (window.event&&event.srcElement.value.length>=maxlength)
    return false
    else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
    //var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
    var pressedkey=/[a-zA-Z0-9\s\.\,\/]/ //detect alphanumeric keys
    if (pressedkey.test(String.fromCharCode(e.which)))
    e.stopPropagation()
    }
}

function countlimit(maxlength,e,placeholder){
    var theform=eval(placeholder)
    var lengthleft=maxlength-theform.value.length
    var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
    if (window.event||e.target&&e.target==eval(placeholder)){
    if (lengthleft<0)
    theform.value=theform.value.substring(0,maxlength)
    placeholderobj.innerHTML=lengthleft
    }
}

function displaylimit(thename, theid, thelimit){
    var theform=theid!=""? document.getElementById(theid) : thename
    var limit_text='Puoi inserire ancora <span id="'+theform.toString()+'">'+thelimit+'</span> caratteri'
    if (document.all||ns6)
    document.write(limit_text)
    if (document.all){
    eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
    eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
    }
    else if (ns6){
    document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
    document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
    }
}