var map_zoom=1;

// JavaScript Document
// Serve a passare da una pagina all'altra dell'elenco degli utenti
function jump(n) {			  
 document.formfiltri.limit.value = n;
 document.formfiltri.submit();
}
function ordina (cosa) {
document.formfiltri.filt_orderby.value = cosa;
document.formfiltri.submit();
}

function Trim(stringa) {
return stringa.replace(/\s+$|^\s+/g,"");
}

function verifica_data (gg,mm,aa) {
   var strdata = gg+"/"+mm+"/"+aa;
   data = new Date(aa,mm-1,gg);
   daa=data.getFullYear().toString();
   dmm=(data.getMonth()+1).toString();
      dmm=dmm.length==1?"0"+dmm:dmm
   dgg=data.getDate().toString();
      dgg=dgg.length==1?"0"+dgg:dgg
   dddata=dgg+"/"+dmm+"/"+daa
   if (dddata!=strdata) return false;
	else return true;
}

function checkEmail(email)
{
  var goodEmail = email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.biz)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
  if (goodEmail) good = true;
  else good = false;
  
  if (Trim(email) == "") good = true;
  return good;
}

function noHtml(txt) {
    a = txt.indexOf('<');
    b = txt.indexOf('>');
    len = txt.length;
    c = txt.substring(0, a);
    if(b == -1) {
       b = a;
    }
    d = txt.substring((b + 1), len);
    txt = c + d;
    cont = txt.indexOf('<');
    if (cont != -1) {
      txt = noHtml(txt);
    }
    return txt;
}
function remove_badchar (str) {
 if (Trim(str) != "") {
 // per prima cosa elimino i tag html
 res = noHtml(str);
 res = res.replace ('\"', '&quot;');
 // trasformo le & in un codice riconoscibile: "*:and:*"
 res = res.replace ('&', '*:and:*');
 } else res=str;
return res;	
}
function waiting_msg() {
 return '<div class="waiting"><p><img src="images/ajax-loader_small.gif" alt="please wait" /></p><p>Loading, please wait...</p></div>';
}
function genera_news(tipo) {
 var mydiv = document.getElementById("div_news_content");
 mydiv.innerHTML = waiting_msg();
 agent.call('','genera_news','genera_news_ret', tipo);
}
function genera_news_ret(ret) {
 var mydiv = document.getElementById("div_news_content");
 mydiv.innerHTML = ret;
}

function zoom_map(s_zoom) {
	map_zoom = map_zoom+s_zoom;
	if (map_zoom==0) map_zoom = 3;
	else if (map_zoom != 1 && map_zoom != 2 && map_zoom != 3) map_zoom = 1;
	var myimg = document.getElementById("mappa_alba");
	myimg.src = 'images/Contattaci/dove'+map_zoom+'.gif';
}

function codiceFISCALE(cfins)
   {
   var cf = cfins.toUpperCase();
   var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
   if (!cfReg.test(cf))
      return false;
   var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
   var s = 0;
   for( i = 1; i <= 13; i += 2 )
      s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   for( i = 0; i <= 14; i += 2 )
      s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   if ( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
      return false;
   return true;
}


// Verifica Partita Iva
function controllaPIVA(pi)
{
	 if( pi == '' )  return false;
	 if( pi.length != 11 )
			 return false;
	 var validi = "0123456789";
	 for( i = 0; i < 11; i++ ){
			 if( validi.indexOf( pi.charAt(i) ) == -1 )
					 return false
		  }
	 s = 0;
	 for( i = 0; i <= 9; i += 2 )
			 s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	 for( i = 1; i <= 9; i += 2 ){
			 c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
			 if( c > 9 )  c = c - 9;
			 s += c;
	 }
	 if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
			 return false

return true;

}

function check_ute_mod_adm () {

 var oggi = parseInt(document.form_ute_mod_adm.oggi.value);

 var err="";
 var SERIAL = document.form_ute_mod_adm.SERIAL.value;
 var DATSCACON = document.form_ute_mod_adm.DATSCACON.value;
 var codfis = document.form_ute_mod_adm.codfis.value;
 var pariva = document.form_ute_mod_adm.pariva.value;
 var FLWEBBLOC = document.form_ute_mod_adm.FLWEBBLOC.value;
 if (codfis!="" && !codiceFISCALE(codfis) && !controllaPIVA(codfis)) err+= "Codice fiscale non corretto\n";
 if (pariva!="" && !controllaPIVA(pariva)) err+= "Partita IVA non corretta\n";
 var arr_DATSCACON = DATSCACON.split("/");
 if(SERIAL.length>0 && SERIAL.length!=27) err+="Il codice Seriale deve essere di 27 caratteri\n";
  if (arr_DATSCACON!="" && !verifica_data(arr_DATSCACON[0], arr_DATSCACON[1], arr_DATSCACON[2])) err+="Data scadenza contratto: formato non corretto\n";
  
 //se la data del contratto è valida e FLWEBBLOC!="" rendo un errore
 var datscacon_int = parseInt(arr_DATSCACON[2]+arr_DATSCACON[1]+arr_DATSCACON[0]);
 if (FLWEBBLOC!="" && !isNaN(datscacon_int) && datscacon_int>oggi) err = "Attenzione! Non puoi impostare un Blocco al Supporto Tecnico se la data del contratto è valida";
 
 if (err!="") {
	 alert(err);
	 return false;
 } else return true;
 
}


function check_ute_prof () {
 var err="";
 var codfis = document.form_mod_prof.codfis.value;
 var pariva = document.form_mod_prof.pariva.value;
 if (codfis!="" && !codiceFISCALE(codfis) && !controllaPIVA(codfis)) err+= "Codice fiscale non corretto\n";
 if (pariva!="" && !controllaPIVA(pariva)) err+= "Partita IVA non corretta\n";
 
 if (err!="") {
	 alert(err);
	 return false;
 } else return true;
}
