function open_win(what_link) {
  var the_url = "http://localhost";
  var the_x = 760;
  var the_y = 650;
  the_x -= 0;
  the_y -= 0;
  var how_wide = screen.availWidth;
  var how_high = screen.availHeight;
  if(what_link != "") {
    the_url = what_link;
  }
  var the_toolbar = "no";
  var the_addressbar = "no";
  var the_directories = "no";
  var the_statusbar = "no";
  var the_menubar = "no";
  var the_scrollbars = "yes";
  var the_do_resize =  "yes";
  var the_copy_history = "no";
  top_pos = (how_high / 2) - (the_y / 2);
  left_pos = (how_wide / 2) - (the_x / 2);
  if(window.outerWidth) {
    var option = "toolbar=" + the_toolbar + ", location=" + the_addressbar + ", directories=" + the_directories + ", status=" + the_statusbar + ", menubar=" + the_menubar + ", scrollbars=" + the_scrollbars + ", resizable=" + the_do_resize + ", outerWidth=" + the_x + ", outerHeight=" + the_y + ", copyhistory=" + the_copy_history + ", left=" + left_pos + ", top=" + top_pos;
    site = open(the_url, "DisplayWindow", option);
    var Opera = (navigator.userAgent.indexOf('Opera') != -1);
    if(Opera) {
      site.resizeTo(the_x, the_y);
      site.moveTo(0, 0);
    }
  } else {
    var option = "toolbar=" + the_toolbar + ", location=" + the_addressbar + ", directories=" + the_directories + ", status=" + the_statusbar + ", menubar=" + the_menubar + ", scrollbars=" + the_scrollbars + ", resizable=" + the_do_resize + ", Width=" + the_x + ", Height=" + the_y + ", copyhistory=" + the_copy_history + ", left=" + left_pos + ", top=" + top_pos;
    site=open('', "DisplayWindow", option);
    site.location = the_url;
    if(site.open) {
      site.focus();
      return false;
    }
    site.resizeTo(the_x, the_y);
  }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function focusFirstField() {
	myForm = document.forms[0];
        if(myForm){
            if (myForm.length > 0) {
                    myForm[0].focus();
                    myForm[0].select(0);
            }
        }
}

function focusFirstField_byForm(argFormId, argInputType) {
	myForm = document.getElementById(argFormId);
        if(myForm){
            var i = 0;
            for (i = 0; i<myForm.length; i++) {
                    myItem = myForm.elements[i];
                    if (myItem.type == argInputType) {
                            myItem.focus();
                            myItem.select(0);
                            return;
                    }
            }
        }
}

function VRK_show(areaName) {
	var vday, vweek, vmonth, vyear;
	if (areaName == 'D') vday = 'block'; else vday = 'none';
	if (areaName == 'W') vweek = 'block'; else vweek = 'none';
	if (areaName == 'M') vmonth = 'block'; else vmonth = 'none';
	if (areaName == 'Y') vyear = 'block'; else vyear = 'none';
	MM_changeProp('dayarea','','style.display',vday,'DIV');
	MM_changeProp('weekarea','','style.display',vweek,'DIV');
	MM_changeProp('montharea','','style.display',vmonth,'DIV');
	MM_changeProp('yeararea','','style.display',vyear,'DIV');
}

function VRK_show_v2(areaName) {
	var vday, vweek;
	if (areaName == 'D') vday = 'block'; else vday = 'none';
	if (areaName == 'W') vweek = 'block'; else vweek = 'none';
	MM_changeProp('viewD','','style.display',vday,'DIV');
	MM_changeProp('viewW','','style.display',vweek,'DIV');
}

function askConfirm(oA, sQuestion, sYes, sNo) {
    if (confirm(sQuestion)) {
        oA.href = sYes;
    } else {
        oA.href = sNo;
    }
}

function submitForm(argFormObj) {
	argFormObj.submit();
}


// Aggiunta di un'etichetta alla lista
function add_item_combotolist(argCombo, argList) {
	if (argCombo.value == '--') {
		alert('Selezionare prima un elemento dal menï¿½ a tendina');
	} else {
		// Controllo che l'elemento che sto copiando non sia giï¿½ presente negli elementi di destinaz.
		var found = false;
		var i;
		//alert(argList.length);
		for (i=0;i<argList.length;i++) {
			if (argList.options[i].value == argCombo.value) {
				found = true;
				break;
			}
		}
		// Se il controllo di esito positivo, mostro un messaggio, altrimenti faccio la copia
		if (found) {
			alert('L\'elemento "'+ argList.options[i].text +'" ï¿½ giï¿½ presente nella lista');
		} else {
			argList[argList.options.length] = new Option(argCombo.options[argCombo.selectedIndex].text, argCombo.value, true, true);
		}
	}
}

// Rimozione di un'etichetta dalla lista
function remove_item_fromlist(argList) {
	if (argList.selectedIndex == -1) {
		alert('Selezionare prima un elemento dalla lista');
	} else {
		argList.remove(argList.selectedIndex);
	}
}

/*
// Seleziona tutti gli elementi della lista
function select_every_item_inlist(argList) {
	var i;
	for (i=0;i<argList.length;i++) {
		argList.options[i].selected = true;
	}
}
*/

// Seleziona tutti gli elementi delle liste passate (vengono passati degli oggetti lista)
function select_every_item_inlist() {
	/*var i, j;
	for (j=0;j<arguments.length;j++) {
		for (i=0;i<arguments[j].length;i++) {
			arguments[j].options[i].selected = true;
		}
	}*/
}

// Copia il nome del file dal campo file al campo text
function copy_filename_filetotext(argFile, argText) {
	var path = argFile.value;
	var pos = path.lastIndexOf('\\');
	argText.value = path.substr(pos+1);
}

//Chiede conferma al navigatore col messaggio argMsg e naviga verso l'URL argURL
function ask_confirm_and_go_to(argMsg, argURL) {
	if (confirm(argMsg)) {
	 window.location = argURL;
	}
}

// Aggiunta di uno o piï¿½ item da una lista ad una lista
function add_item_listtolist(argListSrc, argListDest, argAlsoMove) {
	var somethingjumped = false;
	if (argListSrc.selectedIndex == -1) {
		alert('Selezionare prima un elemento dall\'elenco di origine');
	} else {
		// Ciclo gli elementi della lista di origine,
		// cominciando dal primo selezionato (selectedIndex ï¿½ il primo selezionato)
		for (j=argListSrc.length-1;j>=argListSrc.selectedIndex;j--) {
			// Copio solo gli elementi di argListSrc che sono selezionati
			if (argListSrc.options[j].selected) {
				// Controllo che l'elemento che sto copiando non sia giï¿½ presente negli elementi di destinaz.
				var found = false;
				var i;
				//alert(argList.length);
				for (i=0;i<argListDest.length;i++) {
					if (argListDest.options[i].value == argListSrc.options[j].value) {
						found = true;
						break;
					}
				}
				// Se il controllo di esito negativo, faccio la copia, altrimenti mi ricordo che ho saltato
				if (found) {
					somethingjumped = true;
				} else {
					argListDest[argListDest.options.length] = new Option(argListSrc.options[j].text, argListSrc.options[j].value, true, true);
					if (argAlsoMove) {
						argListSrc.options[j] = null;
					}
				}
			}
		}
		if (somethingjumped) alert('Alcuni elementi erano giï¿½ presenti nella lista di destinazione e, pertanto, non sono stati copiati');
	}
}

function googleSiteSearch(argText) {
	window.location="http://www.google.it/search?hl=it&q=" + argText +  "+site%3Aprogetto-sole.it&btnG=Cerca+con+Google&meta=";
}

function googleSiteSearchFiles(argText) {
	window.location="http://www.google.it/search?hl=it&q=" + argText +  "+site%3Aprogetto-sole.it%2Fscambiofile&btnG=Cerca+con+Google&meta=";
}

// Seleziona tutti i checkbox nel form argForm che hanno nome uguale ad argName
function checkallbyname(argForm, argName, argChecked) {
	for(i=0; i<argForm.elements.length; i++) {
		if (argForm.elements[i].type == 'checkbox') {
			if (argForm.elements[i].name == argName) {
				argForm.elements[i].checked=argChecked;
			}
		}
	}
}

function expandContainer(campo){
    var obj = document.getElementById(campo);
    if(campo == 'container'){
	obj.id = 'container_expanded';
    } else {
	obj.id = 'container';
    }
    obj = document.getElementById('column-sx');
    obj.style.display = (obj.style.display == '' || obj.style.display == 'block') ? 'none' : 'block';
    obj = document.getElementById('arrowlnk');
    obj.style.display = (obj.style.display == '' || obj.style.display == 'block') ? 'none' : 'block';
    if(getXMLHTTP()){
	url='/commonzf/index/menushower?elem=column-sx';
	callAsynch(url);
    }
}

// Visualizza/Nasconde un campo
// ATTENZIONE! Questa funzione è personalizzata per il menu...
// Ai menu di secondo livello bisogna cambiare anche la classe dell'elemento padre
function expandCollapse(campo)
{
    var obj = document.getElementById(campo);
    obj.style.display = (obj.style.display == '' || obj.style.display == 'block') ? 'none' : 'block';

    var field = campo.split( '_' );
    obj = document.getElementById(field[1]);

    switch (field[0])
    {

	case 'top':
        pathArray = obj.src.split( '/' );
	    obj.src = ( pathArray[pathArray.length-1] == 'arrow-int.gif' ) ? '/styles/img/arrow-out.gif' : '/styles/img/arrow-int.gif';
	    getXMLHTTP();
	    url='/commonzf/index/menushower?elem=' + field[1];
	    callAsynch(url);
	    break;
        /* start emiliano1*/
	case 'topalert':
        pathArray = obj.src.split( '/' );
	    obj.src = ( pathArray[pathArray.length-1] == 'arrow-in-a.gif' ) ? '/styles/img/arrow-out-a.gif' : '/styles/img/arrow-in-a.gif';
	    getXMLHTTP();
	    url='/commonzf/index/menushower?elem=' + field[1];
	    callAsynch(url);
	    break;
        /*  end emiliano1 */

	case 'sub':
        case 'subalert':
	default:
	    obj.className= (obj.className == 'menu_expanded' || obj.className == '') ? 'menu_collapsed' : 'menu_expanded';
	    break;

    }
}

// nasconde un div e ne mosta un altro
function setDisplay(campo,layercol,viscol)
{
	obj = document.getElementById(layercol + campo);
	obj.style.display = (obj.style.display == 'inline') ? 'none' : 'inline';

	obj = document.getElementById(viscol + campo);
	obj.style.display = (obj.style.display == 'inline') ? 'none' : 'inline';
}
/* start emiliano1 */
// Usato per visualizzare le esenzioni dal catalogo
function setDisplayEse(url, id, layercol, viscol)
{
        var ret = callSynch(url+"?id="+id+"&func=displayEse");
//        alert(ret);
	obj = document.getElementById(layercol + id);
	obj.style.display = (obj.style.display == 'inline') ? 'none' : 'inline';

        if(document.getElementById('layerese_text'+id) && document.getElementById(layercol + id).style.display=='inline'){
            document.getElementById('layerese_text'+id).innerHTML = ret;
        }

	obj = document.getElementById(viscol + id);
	obj.style.display = (obj.style.display == 'inline') ? 'none' : 'inline';
}
// Usato per visualizzare le esenzioni dal catalogo
function setDisplayEseCpa(url, id, layercol, viscol)
{
        var ret = callSynch(url+"?id="+id+"&func=displayEseCpa");
//        alert(ret);
	obj = document.getElementById(layercol + id);
	obj.style.display = (obj.style.display == 'inline') ? 'none' : 'inline';

        if(document.getElementById('layerese_text'+id) && document.getElementById(layercol + id).style.display=='inline'){
            document.getElementById('layerese_text'+id).innerHTML = ret;
        }

	obj = document.getElementById(viscol + id);
	obj.style.display = (obj.style.display == 'inline') ? 'none' : 'inline';
}
/* end emiliano1 */
//nasconde un div
function hideDisplay(campo)
{
	obj = document.getElementById(campo);
	obj.style.display ='none' ;
}
function activateDisplay(campo)
{
	obj = document.getElementById(campo);
	obj.style.display ='inline' ;
}
function checkInstallatore(from,to){
    if((from=='')||(to=='')){
        alert('Installatore non selezionato');
        return false;
    }
    if(from==to){
        alert('Installatore coincidenti');
        return false;
    }
    return true;
}

function checkAuto(installatoreFrom, installatoreTo, data){
    var autoFrom = document.getElementById('autoGiorno_' + installatoreFrom + '_' + data).innerHTML.replace(/^\s+|\s+$/g,"");
    var autoTo = document.getElementById('autoGiorno_' + installatoreTo + '_' + data).innerHTML.replace(/^\s+|\s+$/g,"");
    if(autoFrom.length==0){
        return;
    }
    if(autoTo.length==0){
        return;
    }
    if(autoFrom!=autoTo){
        if(confirm('Mantenere l\'associazione corrente delle automobili agli installatori?')){
            document.getElementsByName('autoA' + data)[0].value=autoTo;
            document.getElementsByName('autoB' + data)[0].value=autoFrom;
        }
    }
}

function checkInstallatoreSingolo(installatore){
    if(installatore==''){
        alert('Installatore non selezionato');
        return false;
    }
    return true;
}

function setInstallatoreVisibility(val,elem){
    for(i=0;i<elem.options.length;i++){
        if(elem.options[i].value==val){
            if(elem.options[i].value!=''){
                elem.options[i].style.display='none';
            }
        } else {
            elem.options[i].style.display='block';
        }
    }
}

function checkAutoCambiata(autoProposta,autoScelta){
    if(autoProposta==''){
        return true;
    }
    if(autoProposta==autoScelta){
        return true;
    }
    if(autoProposta!=autoScelta){
        if(confirm('Procedere con l\'assegnazione di questa auto a tutti gli appuntamenti delle giornata di questo installatore?')){
            document.getElementById('aggiornaAuto').value='S';
        }
    }
    return true;
}

function checkDataIntervento(data){
    if((!data)||(data=='')){
	alert("Data intervento obbligatoria");
        return false;
    }
    return true;
}


function showWithInfo(elemento, visualizza, nascondi){
	var obj = document.getElementById(elemento);
        var vis = document.getElementById(visualizza);
        var nas = document.getElementById(nascondi);

	if (obj.style.display == 'none') {
		obj.style.display = 'block';
                vis.style.display = 'none';
                nas.style.display = 'inline';
	} else {
		obj.style.display = 'none';
                vis.style.display = 'inline';
                nas.style.display = 'none';
	}
        return false;
}

function checkAssociazione(){
    if((document.getElementById('c_codice').value=='') && (document.getElementById('c_desc').value=='') && (document.getElementById('a_codice').value=='') && (document.getElementById('a_desc').value=='')){
	alert('Immettere almeno un codice o una descrizione da ricercare');
        return false;
    }
    return true;
}

function checkValues(){
    var elems = document.getElementsByTagName('select');
    for (var i = 0; i < elems.length; i++) {
	if (elems[i].name.match('^'+'c_val_')=='c_val_') {
	    if(elems[i].value==''){
		alert('Non tutte le prestazioni hanno un valore associato');
		return false;
	    }
	}
    }
    return true;
}

function modal(){
    var elem = document.getElementById("modal");
    if(elem){
	elem.style.visibility = (elem.style.visibility == "visible") ? "hidden" : "visible";
    }
}

/* FUNZIONI "TOGGLE" */
function togglediv(index) {
    if (document.getElementById('expanded'+index).style.display == 'block') {
        hidediv(index);
    } else {
        showdiv(index);
    }
}

function hidediv(index) {
    document.getElementById('expanded'+index).style.display = 'none';
    document.getElementById('expand'+index).className = 'expand closed';
}

function showdiv(index) {
    document.getElementById('expanded'+index).style.display = 'block';
    document.getElementById('expand'+index).className = 'expand open';
}

/* FINE FUNZIONI "TOGGLE" */

/* VISUALIZZAZIONE ALERT PER NOTIFICA E-MAIL */
function conferma(){
    var messaggio = 'Vuoi spedire la notifica e-mail al gruppo di questo documento?';
            var scelta = confirm(messaggio);
            if (scelta == true)  {
            var chkInvio = '&chkInvio=1';
    } else {
            var chkInvio = '&chkInvio=0';
    }
    return chkInvio;
}

/* FINE VISUALIZZAZIONE ALERT PER NOTIFICA E-MAIL */

/* START emiliano1: 25/03/11 funzioni per il back  */
function funcBack(stepReq, stepUrl){
    var ret = callSynch('/commonzf/index/back'+"?stepReq="+stepReq+"&stepUrl="+stepUrl);
    document.getElementById('divForBack').innerHTML = '';
//    alert(ret);
    if( document.getElementById('divForBack') && ret !='false'){
//        alert(ret);
        document.getElementById('divForBack').innerHTML = ret;
        form = document.getElementById('formBack');
        submitForm(form);
//        return true;
    }

    return false;


}
/* END back */
/*  START emiliano1 : 12/04/11 : Funzione che visualizza un tips da un oggetto "event" passato come parametro */
function nascondiTips(oEvent){
    if(document.getElementById('divForTips')){
        hideTip(oEvent);
    }
}
function mostraTips(oEvent, textHtml){
//    alert(textHtml)
    // Costruisce div :
    if( document.getElementById('divForTips')){

//        alert(textHtml)
        if(textHtml != ''){
           insertTipText('divForTips', textHtml)
            showTip(oEvent);
        }else{ 
            hideTip(oEvent);
        }
    }else{
        var backgroundColor = "#F2F2F2";
        var position = "absolute";//"fixed";
        var visibility = "hidden"; 
        var padding = "5px";
        var left = 0;   //oEvent.clientX + 5;
        var top = 0;    //oEvent.clientY + 25;
        var border = '1px solid #CECECE'
        createDiv('divForTips', textHtml, 0, 0, left, top, backgroundColor, position, visibility, padding, border );
        showTip(oEvent);
    }     
}
  function showTip(oEvent) { 
        var oDiv = document.getElementById("divForTips");
        oDiv.style.display = "inline";
        oDiv.style.left = oEvent.clientX + 5 + 'px';
        oDiv.style.top = oEvent.clientY + 40 + 'px';
//       alert(oEvent.clientY);
   }

    function hideTip(oEvent) {
        var oDiv = document.getElementById("divForTips"); 
        oDiv.style.display = "none";
    }

    function insertTipText(divId, textHtml){
         var oDiv = document.getElementById(divId);
         oDiv.innerHTML = '';
         if(textHtml != ''){
            oDiv.innerHTML = '<span>' + textHtml +'</span>';
         }
    }
    
// Creazione di un div personalizzato con dentro un testo
function createDiv(id, textHtml, width, height, left, top, backgroundColor, position, visibility, padding, border) {
//   alert(left + ' '+ top);
   var newdiv = document.createElement('div');
   newdiv.setAttribute('id', id);

   if (backgroundColor) {
       newdiv.style.backgroundColor = backgroundColor;
   }
   if (position) {
       newdiv.style.position = position;
   }
   if (visibility) {
//       newdiv.style.visibility = visibility;
        newdiv.style.display = 'none';
   }
   if (padding) {
       newdiv.style.padding = padding;
   }
   if (border) {
       newdiv.style.border = border;
   }
// alert(newdiv)
   if (textHtml) {
       newdiv.innerHTML = '<span>' + textHtml +'</span>';
   } else {
       newdiv.innerHTML = "nothing";
   }

   if (width) {
       newdiv.style.width = 300;
   }
   if (height) {
       newdiv.style.height = 300;
   }
   if ((left || top) || (left && top)) {
       newdiv.style.position = "absolute";

       if (left) {
           newdiv.style.left = left+'px';
       }

       if (top) {
           newdiv.style.top = top+'px';
       }
   }

   document.body.appendChild(newdiv);
}
/* END emiliano1 */
// 07/06/11 : Usato nella select del paginatore nuova versione
function change_num_rows(ele, link){
//    alert(link);
    var url = '';
    if(link != ''){
//        if (link.toString().indexOf("?")!=-1){
//            var pos = link.toString().indexOf("?");
//            var param = link.substring(pos+1, (link.length-pos) );
//            var param_ar = param.split('&')
//            for(var i=0; i < param_ar.length-1 ; i++){
//                alert(param_ar[i])
//            }
////            alert(param_ar);
//        }
        var intIndexOfMatch = link.indexOf( "page=" );

        if (intIndexOfMatch != -1){
            link = replaceQueryString(link, 'page', '1');
        }
        url = link;
    }else{
	url = window.location ;
    }
    
    var sep = '?';
    if (url.toString().indexOf("?")!=-1){
        sep = '&';
    }
	url=url+sep+'dimpage='+ ele; //document.getElementById('dimpage').value;
//	alert(url);
	window.location=url+'&change_num_rows=true';
}

function replaceQueryString(url,param,value) {
    var re = new RegExp("([?|&])" + param + "=.*?(&|$)","i");
    if (url.match(re))
        return url.replace(re,'$1' + param + "=" + value + '$2');
    else
        return url + '&' + param + "=" + value;
}
// Funzione per il GAG
function toggleEdificio(elem,ord){
    if((document.getElementById(elem).style.display=='none') || (document.getElementById(elem).style.display=='')){
        document.getElementById(elem).style.display='block';
    } else {
        document.getElementById(elem).style.display='none';
        document.getElementById('cercaEdificio'+ord).className='edificioRicerca';
    }
}
function toggle(elem){
    if((document.getElementById(elem).style.display=='none') || (document.getElementById(elem).style.display=='')){
        document.getElementById(elem).style.display='block';
    } else {
        document.getElementById(elem).style.display='none';
    }
}
function call(elem,ord,indirizzo, istat, codiceProvincia){
    getXMLHTTP();
    url='/gestioneallineamenti/mediciambulatori/edifici?EDI_INDIRIZZO=' + indirizzo + '&EDI_FK_COM_ISTAT=' + istat + '&COM_FK_PRV_ID=' + codiceProvincia + '&ord=' + ord;
    document.getElementById('cercaEdificio'+ord).className='edificioRicercaExp';
    loadScript(url,elem);
}
function setEdificio(istat, id, indirizzo, cap, citta, ord){
    document.getElementById('hiddenId' + ord).value = id;
    document.getElementById('edificio' + ord + 'Istat').innerHTML = istat;
    document.getElementById('allbox' + ord).className = 'allboxold';
    document.getElementById('message' + ord).style.display='block';
    document.getElementById('edificio' + ord + 'Indirizzo').innerHTML = indirizzo;
    document.getElementById('edificio' + ord + 'Cap').innerHTML = cap;
    document.getElementById('edificio' + ord + 'Citta').innerHTML = citta;
    toggle('cercaEdificio'+ord, ord);
}
function freccia(elem){
    var str= document.getElementById(elem).innerHTML;
    if(str.charCodeAt(0)==187){
        document.getElementById(elem).innerHTML=String.fromCharCode(171);
    } else {
        document.getElementById(elem).innerHTML=String.fromCharCode(187);
    }
}
<!-- funzione per selezionare tutti i checkbox presenti nella pagina -->
function SelezTT()
{
    var i = 0;
    var form_allineamenti_gem = document.form_allineamenti_gem.elements;
    for (i=0; i<form_allineamenti_gem.length; i++)
    {
        if(form_allineamenti_gem[i].type == "checkbox")
        {
            form_allineamenti_gem[i].checked = !(form_allineamenti_gem[i].checked);
        }
    }
}
