﻿var IE=(window.navigator.userAgent.indexOf('MSIE')>-1)?1:0;

function gestisci_caricafoto(x,y)
{
	if (document.getElementById(x).checked==true) {
		document.getElementById(y).disabled=true;
		document.getElementById(y).value="";
	} else {
		document.getElementById(y).disabled=false;
	}
}

function gestisci_combo_ricerca_destinazione(val,name)
{
  var e = document.getElementById(name);
  if (val== undefined || val=="--" || val=="")
  {
    e.disabled=true;
    //e.className = "pulsante1disabled";
  }
  else
  {
    e.disabled=false;
    //e.className = "pulsante1";
  }
}

function gestisci_combo_ricerca_tratta(val, combo2,name)
{
  var e = document.getElementById(name);
  var combo = document.getElementById(combo2);
  var val2 = combo.value;
  if (val== undefined || val=="--" ||  val=="" || val2==undefined || val2=="--" || val2=="")
  {
    e.disabled=true;
    //e.className = "pulsante1disabled";
  }
  else
  {
   e.disabled=false;
   //e.className = "pulsante1";
  }
}

function gestisci_combo_ricerca_compagnia(val,name)
{
  var e = document.getElementById(name);
  if (val== undefined || val=="--" || val=="")
  {
    e.disabled=true;
    //e.className = "pulsante1disabled";
  }
  else
  {
    e.disabled=false;
    //e.className = "pulsante1";
  }
}

function disabilita_check(val, name)
{
  var e = document.getElementById(name);
  if (val=='0') { e.checked=false; e.disabled=true; e.parentNode.disabled = true; }
  else { e.disabled=false; e.parentNode.disabled = false;}
}

function disabilita_submit(id,bool)
{
 var e = document.getElementById(id);
 e.disabled=bool;
 e.value="Attendere...";
 e.className = "pulsante1Disabled";
 document.body.style.cursor = "wait";
 e.onmouseover=null;
 e.onmouseout=null;
}

function visua_dettagli(io, cella)
{
   var e = document.getElementById(io);
   var x = document.getElementById(cella);
   
  if (x.style.display == 'table-cell' || x.style.display == 'block' || x.style.display == '')
  {
    x.style.display = 'none';
    e.innerHTML ='+ Vedi tutti i dettagli';
  }
  else
  {
    x.style.display = (IE)?'block':'table-cell';
    e.innerHTML ='- Nascondi tutti i dettagli';
  }
  return;
}

function visua_oggetto(oggetto)
{
   var x = document.getElementById(oggetto);
   
  if (x.style.display == 'table-cell' || x.style.display == 'block' || x.style.display == '')
  {
    x.style.display = 'none';
  }
  else
  {
    x.style.display = (IE)?'block':'table-cell';
  }
  return;
}

function apriPopup(finestra,larg,alt) {
	posX=(screen.width-larg)/2;
	posY=(screen.height-alt)/2;
	var mywin = window.open(finestra,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+larg+',height='+alt+',left='+posX+',top='+posY);
	void(0);
	if (mywin != null && typeof(mywin) == "object") { 
		mywin.focus();
	}
}

function compagniaCheckLinks(abil,disab)
{
   var e = document.getElementById(abil);
   var x = document.getElementById(disab);
   
   e.disabled=false;
   x.disabled=true;
}

function apriAzzurra(finestra,larg,alt,id) {
    var e = document.getElementById('azzurraMsg' + id);
    e.innerHTML = 'Attendere tre secondi<br\/> e permettere l\'apertura di pop-up.';
    setTimeout("document.getElementById('azzurraMsg" + id + "').innerHTML = '';",5000);
	posX=(screen.width-larg)/2;
	posY=(screen.height-alt)/2;
	win=window.open(finestra,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+larg+',height='+alt+',left='+posX+',top='+posY);
	void(0);
	win.opener.focus();
	setTimeout("win.close();",3000);
	setTimeout("document.formAzzurra" + id +".submit();",4000);
}

function apriAdriatica(finestra,larg,alt,id) {
    var e = document.getElementById('adriaticaMsg' + id);
    e.innerHTML = 'Attendere tre secondi<br\/> e permettere l\'apertura di pop-up.';
    setTimeout("document.getElementById('adriaticaMsg" + id + "').innerHTML = '';",5000);
	posX=(screen.width-larg)/2;
	posY=(screen.height-alt)/2;
	win=window.open(finestra,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+larg+',height='+alt+',left='+posX+',top='+posY);
	void(0);
	win.opener.focus();
	setTimeout("win.close();",3000);
	setTimeout("document.formAdriatica" + id +".submit();",4000);
}

function documentiPerTutti(clientId)
{
    var chkTutti = document.getElementById(clientId + "chkTutti"); 
    var agenzia = document.getElementById(clientId + "txtAgenzia");
    var agenziaId = document.getElementById(clientId + "txtAgenziaId");
    var rfvAgenzia = document.getElementById(clientId + "rfvTxtAgenzia");
    if (chkTutti.checked == false)
    {
        agenzia.disabled = false;
        agenzia.value = "";
        agenziaId.value = "";
        disabilita_check("***", clientId + "chkScaricato");
        ValidatorEnable(rfvAgenzia, true);
    }
    else
    {
        agenzia.disabled = true;
        agenzia.value = "";
        agenziaId.value = "0";
        disabilita_check("0", clientId + "chkScaricato");
        ValidatorEnable(rfvAgenzia, false);
    }
}

function completaCodDocumento(clientId)
{
    var doc = document.getElementById(clientId + "txtDoc");
    var chkPratica = document.getElementById(clientId + "chkPratica");
    if (doc.value.length > 0 && doc.value.length < 6)// && chkPratica.checked)
    {
        var num = 6 - doc.value.length;
        var chars = "";
        for (var i = 0; i < num; i++) chars += "0";
        doc.value = chars + doc.value;
    }
}

function ShowProgress() {
    api.load();
    return true;
}
