
function selCombo(id_combo1,id_combo2,tipo) {
 
  id = $("select[id='" + id_combo1 + "']").val();
  
  $.get("/decode64.php", {tipo: tipo, requestItems: 'tipo'},
  function(dataProvince){
    $("select[id='"+ id_combo2 + "']").empty();
    var options = '<option value="">-- seleziona --</option>';
    
    var arr = eval('(' + dataProvince + ')');
    $.each(arr, function (i, elem) {
    id_reg = elem.split("_");
    if(id_reg[1]==id)
    options += '<option value="' + i + '">' + id_reg[0].toUpperCase() + '</option>';
    });
    $("select[id='"+ id_combo2 + "']").html(options);
  });

}

function selOrgano(id_combo2,tipo) {

  id = codprov;

  $.get("/decode64_p.php", {tipo: tipo, requestItems: 'tipo'},
  function(tipo_organo){
    $("select[id='"+ id_combo2 + "']").empty();
    var options = '<option value="">-- seleziona --</option>';

    var arr = eval('(' + tipo_organo + ')');
    $.each(arr, function (i, elem) {
    id_reg = elem.split("_");
    if(id_reg[1]==id)
    options += '<option value="' + i + '">' + id_reg[0].toUpperCase() + '</option>';
    });
    $("select[id='"+ id_combo2 + "']").html(options);
  });

}

function InsertIntoControl (ControlTo,value) {

    parent.document.getElementById(ControlTo).value = value;
     //$("#"+ControlTo).val(value);
     //TopUp.close("");
    parent.TopUp.close("");
     
}

function openControl (href) {

    parent.document.location.href = href;
     //$("#"+ControlTo).val(value);
     //TopUp.close("");
    parent.TopUp.close("");

}

function confDelete(utente) {

   return confirm("Vuoi davvero cancellare : " + utente + "?");

}

function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function Count(entrada,salida,texto,caracteres) {

  var salidaObj=getObject(salida);
  //var pr = entrada.getValue(true);
  var longitud=caracteres - entrada.value.length;
 
  if(longitud <= 0) {
    longitud=0;
    texto='<span class="disable"> '+texto+' </span>';
        entrada.value = entrada.value.substr(0,caracteres);//setValue(entrada.getValue(true).substr(0,caracteres));


  }
  salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}

jQuery.jPrintArea=function(el)
{
var iframe=document.createElement('IFRAME');
var doc=null;
$(iframe).attr('style','position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc=iframe.contentWindow.document;
var links=window.document.getElementsByTagName('link');
doc.write('<html xmlns="http://www.w3.org/1999/xhtml">');
doc.write('<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
doc.write('<link href="/css/print_template.css" media="screen" rel="stylesheet" type="text/css" />');

for(var i=0;i<links.length;i++)
if(links[i].rel.toLowerCase()=='stylesheet')
doc.write('<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>');
doc.write('</head><body>');
doc.write('<div class="'+$(el).attr("class")+'">'+$(el).html()+'</div>');
doc.write('</body></html>');
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();

document.body.removeChild(iframe);
}
