// JavaScript Document

function checkAz()
{ var descrizione = document.getElementById("descrizione").value;
  if (descrizione!="") document.form1.submit();
  else alert("Attenzione, è necessario specificare il nome dell'azienda");
}


function checkCampagna()
{ var titolo = document.getElementById("titolo").value;
 /* var creditidisp = document.getElementById("creditidisp").value;
  var crediti = document.getElementById("crediti").value;
  var diff = creditidisp-crediti;
  if (diff<0) alert("Attenzione, i crediti stanziati per questa campagna sono superiori ai crediti disponibili");
  else
   {
	if (crediti<1)
	alert("Attenzione, è necessario specificare più crediti");
	else
	 {
      if ((titolo!="") && (crediti!="")) document.formCamp.submit();
      else alert("Attenzione, è necessario specificare tutti i campi");
	 }
   } */
   
   if (titolo=="") alert("Attenzione, è necessario specificare il titolo.");
   else document.formCamp.submit();
}

function checkCreaCampagna()
{
  var rag_soc = document.getElementById("rag_soc").value;
  var piva = document.getElementById("piva").value;
  var nreg = document.getElementById("nreg").value;
  var cap = document.getElementById("cap").value;
  if ((rag_soc!="") || (piva!="") || (nreg!="") || (cap!="")) document.formCrea.submit();
  else alert("Attenzione, è necessario specificare almeno un campo");
}

function checkClub()
{ var lettera = document.getElementById("lettera").value;
  var immagine = document.getElementById("immagine").value;
  var flash = document.getElementById("flash").value;
  var controllo = document.getElementById("controllo").value;
  if (controllo == "0")
   {
	if (lettera!="") document.formClub.submit();
    else alert("Attenzione, è necessario specificare tutti i campi");
   }
  else
   {
	if ((lettera!="") && (immagine!="") && (flash!="")) document.formClub.submit();
    else alert("Attenzione, è necessario specificare tutti i campi");
   }
}

function checkProdotto()
{ var descrizione = document.getElementById("descrizione").value;
  var crediti = document.getElementById("crediti").value;
  var dettagli = document.getElementById("dettagli").value;
  var immagine = document.getElementById("immagine").value;
  if ((descrizione!="") && (crediti!="") && (dettagli!="") && (immagine!="")) document.formP.submit();
  else alert("Attenzione, è necessario specificare tutti i campi");
}

function checkCrediti()
{
  var crediti = document.getElementById("crediti").value;
  if (crediti!="") document.formC.submit();
  else alert("Attenzione, è necessario specificare il numero di crediti");
}

function checkValutazione()
{
 var contenuti1 = document.getElementById("contenuti10").checked;
 var contenuti2 = document.getElementById("contenuti20").checked;
 var contenuti3 = document.getElementById("contenuti30").checked;
 var docenti1 = document.getElementById("docenti10").checked;
 var docenti2 = document.getElementById("docenti20").checked;
 var docenti3 = document.getElementById("docenti30").checked;
 var globale = document.getElementById("globale0").checked;
 var tecno1 = document.getElementById("tecno10").checked;
 var tecno2 = document.getElementById("tecno20").checked;
 var tecno3 = document.getElementById("tecno30").checked;
 var tecno4 = document.getElementById("tecno40").checked;
 if (!(contenuti1) && !(contenuti2) && !(contenuti3) && !(globale) && !(docenti1) && !(docenti2) && !(docenti3) && !(tecno1) && !(tecno2) && !(tecno3) && !(tecno4)) document.formval.submit();
 else alert("Attenzione, è necessario specificare tutti i campi!");
}

function checkNews()
{ var descrizione = document.getElementById("descrizione").value;
  var titolo = document.getElementById("titolo").value;
  if (titolo!="") document.form1.submit();
  else alert("Attenzione, è necessario specificare tutti i campi");
}

function confirmDeleteAz(id)
{ if (confirm("Si conferma l'eliminazione di questa azienda?")) 
	location.replace('?page=aziende&action=delete&id='+id);
}

function confirmDeleteNews(id)
{ if (confirm("Si conferma l'eliminazione di questa news?")) 
	location.replace('?page=news&action=delete&id='+id);
}

function checkCoop()
{ var descrizione = document.getElementById("descrizione").value;
  if (descrizione!="") document.form1.submit();
  else alert("Attenzione, è necessario specificare il nome della cooperativa");
}

function confirmDeleteCoop(id)
{ if (confirm("Si conferma l'eliminazione di questa cooperativa?")) 
	location.replace('?page=coop&action=delete&id='+id);
}

function checkVideo()
{ var titolo = document.getElementById("titolo").value;
  if (document.getElementById("tipo")!=null)
   var tipo = document.getElementById("tipo").value;
  else tipo=1; 
  var tipoUpload = document.getElementById("tipoUpload").value;
  var controllo = document.getElementById("controllo").value;

  if (tipo == '1')
   var nomefile = document.getElementById("fileInd").value;
  else
   nomefile = document.getElementById("fileRemoto").value;
   
  var nomefileImm = document.getElementById("loadImmagine").value;
  var oldimm = document.getElementById("old_imm").value;
  if (((titolo!="") && (nomefile!="") && ((nomefileImm!="") || oldimm!="")) || (controllo=="true")) document.form1.submit();
  else alert("Attenzione, è necessario specificare tutti i campi");
}
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function checkRmt()
{ var vid = document.getElementById("rmt").value;
  if (vid=="") alert("Attenzione, è necessario specificare il nome del file caricato sul FTP esterno!");
  else document.form1.submit();
}

function checkOpen(id)
{ 
  if (id==1) document.getElementById("rowOpen").style.display='none';
  if (id==2) document.getElementById("rowOpen").style.display='';
}


function confirmDeleteVideo(id)
{ if (confirm("Si conferma l'eliminazione di questo video?")) 
	location.replace('?page=video&action=delete&id='+id);
}

function confirmDeleteRmt(id)
{ if (confirm("Si conferma l'eliminazione di questo video?")) 
	location.replace('?page=video&action=deletermt&id='+id);
}

function confirmDeleteVideoEcm(id)
{ if (confirm("Si conferma l'eliminazione di questo video?")) 
	location.replace('?page=ecm&action=deletevideo&id='+id);
}

function checkCat()
{ var descrizione = document.getElementById("descrizione").value;
  if (descrizione!="") document.form1.submit();
  else alert("Attenzione, è necessario specificare il nome della sottocategoria");
}

function confirmDeleteCat(id)
{ if (confirm("Si conferma l'eliminazione di questa categoria?")) 
	location.replace('?page=cat&action=delete&id='+id);
}

function controllo_data(stringa){
	var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if (!espressione.test(stringa))
	{
	    return false;
	}else{
		anno = parseInt(stringa.substr(6),10);
		mese = parseInt(stringa.substr(3, 2),10);
		giorno = parseInt(stringa.substr(0, 2),10);
		
		var data=new Date(anno, mese-1, giorno);
		if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno){
			return true;
		}else{
			return false;
		}
	}
}

function confronta_data(data1, data2){
	data1str = data1.substr(6)+data1.substr(3, 2)+data1.substr(0, 2);
	data2str = data2.substr(6)+data2.substr(3, 2)+data2.substr(0, 2);
	if (data2str-data1str<0) {
		return false;
	}else{
		return true;
	}
}

function giorni_differenza(data1,data2){
	if(!controllo_data(data1) && !controllo_data(data1)){
		alert('Inserire le date nel formato gg/mm/aaaa');
		exit;
	}

	if(!confronta_data(data1,data2)){
		alert('La data di inizio deve essere precedente quella di fine');
		exit;
	}

	anno1 = parseInt(data1.substr(6),10);
	mese1 = parseInt(data1.substr(3, 2),10);
	giorno1 = parseInt(data1.substr(0, 2),10);
     
	anno2 = parseInt(data2.substr(6),10);
	mese2 = parseInt(data2.substr(3, 2),10);
	giorno2 = parseInt(data2.substr(0, 2),10);

    var dataok1=new Date(anno1, mese1-1, giorno1);
	var dataok2=new Date(anno2, mese2-1, giorno2);
	
	differenza = dataok2-dataok1;    
	giorni_differenza = new String(differenza/86400000);
	
	//alert(giorni_differenza+' giorni di differenza');
	return giorni_differenza;
}

function checkCorso()
{ var titolo = document.getElementById("titolo").value;
  var data1  = document.getElementById("sel3").value;
  var data2  = document.getElementById("sel4").value;  
  var data3  = document.getElementById("sel5").value;    
  var err = 0;
  var msg = "Attenzione, non è possibile continare l'inserimento poichè:\n";
  if (giorni_differenza(data1,data2)<1) {msg+" - La data di fine corso è antecedente alla data di inizio corso\n"; err++;}
  if (titolo=="") { msg+" - Il titolo è obbligatorio\n"; err++}
  if (data1=="")  { msg+" - La data di inizio è obbligatoria\n"; err++}
  if (data2=="")  { msg+" - La data di fine è obbligatoria\n"; err++}  
  //if (data3=="")  { msg+" - La data da cui è possibile scaricare l'attestato è obbligatoria\n"; err++}    
  if (err>0) alert(msg);
  else document.formData.submit();
}

function showNews(id)
{ 
  if (prev!=0)
    { document.getElementById("tit"+prev).style.display='';
 	  document.getElementById("descr"+prev).style.display='none';
	  document.getElementById("news"+prev).style.display='none';
	}
  document.getElementById("news"+id).style.display='';
  document.getElementById("descr"+id).style.display='';
  document.getElementById("tit"+id).style.display='none';
  prev    = id;
}

function hideNews(prev)
{ document.getElementById("tit"+prev).style.display='';
  document.getElementById("descr"+prev).style.display='none';
  document.getElementById("news"+prev).style.display='none';
  prev = 0; 
}
  

function addQuestionario(idCorso)
{ location.replace("?page=ecm&action=addQuestionario&idCorso="+idCorso); }

//function saveQuestionario()
//{ var 

function chTipo(id)
{ if (id==0) {
               document.getElementById("rowIndicizzato").style.display='none';
			   document.getElementById("rigaUploadVideo").style.display='none';
			   document.getElementById("rowNormale").style.display='';
               document.getElementById("rowLink").style.display='none';
			   chUpload('1');
		     }
  else
  if (id==1) {
               document.getElementById("rowIndicizzato").style.display='';
			   document.getElementById("rigaUploadVideo").style.display='none';
			   document.getElementById("rowNormale").style.display='none';
               document.getElementById("rowLink").style.display='none';
			    chUpload('2');
		     }

}

function chUpload(id)
{
  if (id==0) { document.getElementById("rowNormale").style.display='';
               document.getElementById("rowLink").style.display='none';
		     }
  else
  if (id==1) { document.getElementById("rowNormale").style.display='none';
               document.getElementById("rowLink").style.display='';
		     }
}

function checkDomanda()
{ 
  var o1 = document.getElementById("opzione1").value;
  var o2 = document.getElementById("opzione2").value;
  var o3 = document.getElementById("opzione3").value;
  var o4 = document.getElementById("opzione4").value;
  var o5 = document.getElementById("opzione5").value;
  var r1 = document.getElementById("r1").checked;
  var r2 = document.getElementById("r2").checked;
  var r3 = document.getElementById("r3").checked;
  var r4 = document.getElementById("r4").checked;
  var r5 = document.getElementById("r5").checked;  
  var domanda = document.getElementById("domanda").value;


  if (domanda=="") { alert ("Attenzione, non è stato indicato il testo della domanda!"); return; }
  if ((r1==true && o1=="") || (r2==true && o2=="") || 
	  (r3==true && o3=="") || (r4==true && o4=="") || (r5==true && o5==""))
          alert("Attenzione, è stata selezionata come risposta corretta un'opzione vuota!");
  else document.form1.submit();
  
}

function expandDomanda(id)
{ var riga = "row"+id;
  if (document.getElementById(riga).style.display=='') document.getElementById(riga).style.display='none';
  else document.getElementById(riga).style.display='';
}

function confirmDelete(id)
{ if (confirm("Attenzione, si conferma l'eliminazione di questa domanda dal questionario?"))
  location.replace("?page=ecm&action=deleteDomanda&idDomanda="+id);
}

function confirmDeleteQuestionario(id)
{ if (confirm("Attenzione, si conferma l'eliminazione di questo questionario e di tutte le domande riferite ad esso?"))
   location.replace("?page=ecm&action=deleteQuestionario&idQuestionario="+id);
}

function confirmDeteleCorso(id)
{ if (confirm("Attenzione, si conferma l'eliminazione di questo corso, di tutti i questionari e di tutte le domande riferite ad esso?"))
   location.replace("?page=ecm&action=deleteCorso&idCorso="+id);
}

function confirmDeleteFAQ(id)
{ if (confirm("Attenzione, si conferma l'eliminazione di questa FAQ?"))
   location.replace("?page=faq&action=delete&idFaq="+id);
}
function confirmDeleteFAQ(id)
{ if (confirm("Attenzione, si conferma l'eliminazione di questa FAQ?"))
   location.replace("?page=faq&action=delete&idFaq="+id);
}
function checkFAQ()
{ var domanda = document.getElementById("domanda").value;
  var risposta= document.getElementById("risposta").value;
  if (domanda=="" || risposta=="") alert("Attenzione per procedere sia i campi DOMANDA che RISPOSTA devono essere compilati");
  else document.form1.submit();
}

function chCat(idCat,idCategoria){
document.getElementById("rowSubCat").style.display='';
var idCat = document.getElementById("classe").value;
var idCategoria = document.getElementById("idOld").value;
var myAjax = new Ajax.Updater( "divSubcat", "pages/subcat.php?idCat="+idCat+"&idCategoria="+idCategoria, { method: 'get'});
}

function makeDomanda(idQuest,domanda)
{
 var myAjax = new Ajax.Updater( "divDomanda", "pages/domande.php?idQuest="+idQuest+"&domanda="+domanda, { method: 'get'});
}

function checkRisposta(idDomanda)
{ var ch = 0;
 for (var i=1;i<6;i++)
  { var tmp = "r"+i; 
   if (document.getElementById(tmp)!=null) {
    if (document.getElementById(tmp).checked) ch=i; } }
	
 if (ch==0) alert ("Attenzione, selezionare una risposta");
 else addRisposta(ch,idDomanda);
}

function addRisposta(ch,idDomanda)
{
  var myAjax = new Ajax.Updater( "divDomanda", "pages/verifica.php?idDomanda="+idDomanda+"&risposta="+ch, { method: 'get'});	
}
 
function TextScroll(scrollname, div_name, up_name, down_name)
{
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 0;
    this.speed = 5;
    this.timeoutID = 0;
    this.div_obj = null;
    this.up_name = up_name;
    this.dn_name = down_name;

{
        if (document.getElementById) {
            div_obj = document.getElementById(this.div_name);
            if (div_obj) {
                this.div_obj = div_obj;
                this.div_obj.style.overflow = 'hidden';
            }
            div_up_obj = document.getElementById(this.up_name);
            div_dn_obj = document.getElementById(this.dn_name);
            if (div_up_obj && div_dn_obj) {
                div_up_obj.setAttribute("onmouseover", scrollname + ".scrollUp();")
                div_up_obj.setAttribute("onmouseout", scrollname + ".stopScroll();")

div_dn_obj.setAttribute("onmouseover", scrollname + ".scrollDown();")
                div_dn_obj.setAttribute("onmouseout", scrollname + ".stopScroll();")
            }
        }
    }

this.stopScroll = function() {
        clearTimeout(this.timeoutID);
    }

this.scrollUp = function() {
        if (this.div_obj) {
            this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
        }
    }

this.scrollDown = function() {
        if (this.div_obj) {
            this.scrollCursor += this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
        }
    }

this.resetScroll = function() {
        if (this.div_obj) {
            this.div_obj.scrollTop = 0;
            this.scrollCursor = 0;
        }
    }
}

function checkMail(email)
{
 var r = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  if( r.test( email ) )
    return(true);
  else
    return(false);
}

function check_cont_reg()
{
var user      = document.getElementById("user").value;
var pass      = document.getElementById("pass").value;
var pass2     = document.getElementById("pass2").value;
var rag_soc   = document.getElementById("rag_soc").value;
var indirizzo = document.getElementById("indirizzo").value;
var citta     = document.getElementById("citta").value;
var cap       = document.getElementById("cap").value;
var email     = document.getElementById("email").value;
var email2    = document.getElementById("email2").value;
var piva      = document.getElementById("piva").value;
var nome      = document.getElementById("nome").value;
var cognome   = document.getElementById("cognome").value;
var privacy   = document.getElementById("privacy").checked;
var reg       = document.getElementById("reg").value;
var dn		  = document.getElementById("dn").value;
var tel		  = document.getElementById("tel").value;


var codfis    = document.getElementById("codfis").value;
var l_n       = document.getElementById("l_n").value;
var prov_n    = document.getElementById("prov_n").value;

var mess      ="Attenzione, non è possibile continuare perchè:\n";
var err       = 0;
if (user=="")      { mess+=" - Il nome utente non è stato inserito\n"; err++; }
if (isAlfa(user)==false)  { mess+=" - Il nome utente non è valido\n"; err++; } 
if (pass=="")      { mess+=" - La password non è stata inserita\n"; err++; }
if (pass!=pass2)   { mess+=" - Il campo password e conferma password non coincidono\n"; err++; }
if (rag_soc=="")   { mess+=" - La ragione sociale della farmacia è obbligatoria\n"; err++; }
if (indirizzo=="") { mess+=" - L'indirizzo non è stato inserito\n"; err++; }
//if (isAlfanumerico(indirizzo)==false)  { mess+=" - L'indirizzo non è valido\n"; err++; } 
if (citta=="")     { mess+=" - La città non è stata inserita\n"; err++; }
//if (isAlfanumerico(citta)==false)  { mess+=" - La città non è valida\n"; err++; } 
if (cap=="")       { mess+=" - Il CAP non è stato inserito\n"; err++; }
if (email=="")     { mess+=" - L'indirizzo email\ non è stato inserito\n"; err++; }
if (checkMail(email)==false)     { mess+=" - L'indirizzo email\ non è corretto\n"; err++; }
if (email!=email2) { mess+=" - Il campo 'email' e 'conferma email' non coincidono\n"; err++;}
if (nome=="")      { mess+=" - Il Nome non è stato inserito\n"; err++; }
if (isAlfa(nome)==false)  { mess+=" - Il nome non è valido\n"; err++; } 
if (cognome=="")   { mess+=" - Il cognome non è stato inserito\n"; err++; }
if (isAlfa(cognome)==false)  { mess+=" - Il cognome non è valido\n"; err++; } 
if (check_piva(piva)==false) { mess+=" - La partita IVA non è corretta\n"; err++; }
if (dn=="")        { mess+=" - La data di nascita non è stata inserita\n"; err++; }
if (checkDataNascita(dn)==false) { mess+=" - La data di nascita non è nel formato corretto (gg/mm/aaaa) o non è una data corretta\n"; err++; }

if (codfis=="")  { mess+=" - Il codice fiscale non è corretto\n"; err++; }
if (l_n=="") { mess+=" - Il luogo di nascita non è stato inserito\n"; err++ }
if (prov_n==-1) { mess+=" - La provincia di nascita non è stata inserita\n"; err++; }
if (tel=="")   { mess+=" - Il Numero di Telefono non è stato inserito\n"; err++; }
if (reg=="")       { mess+=" - Il numero di registrazione all'albo non è stato inserito\n"; err++; }
if (privacy==false){ mess+=" - Non è stata accettata la normativa sulla privacy\n"; err++; }
if (err>0) 
  alert(mess);
else
  document.form_reg.submit();
}


function check_cont_reg_admin()
{
var user      = document.getElementById("user").value;
var pass      = document.getElementById("pass").value;
var pass2     = document.getElementById("pass2").value;
var rag_soc   = document.getElementById("rag_soc").value;
var indirizzo = document.getElementById("indirizzo").value;
var citta     = document.getElementById("citta").value;
var cap       = document.getElementById("cap").value;
var email     = document.getElementById("email").value;
var email2    = document.getElementById("email2").value;
var piva      = document.getElementById("piva").value;
var nome      = document.getElementById("nome").value;
var cognome   = document.getElementById("cognome").value;
var privacy   = document.getElementById("privacy").checked;
var reg       = document.getElementById("reg").value;
var dn		  = document.getElementById("dn").value;
var iban      = document.getElementById("iban").value;
var codfis    = document.getElementById("codfis").value;
var l_n       = document.getElementById("l_n").value;
var prov_n    = document.getElementById("prov_n").value;
//var tel		  = document.getElementById("tel").value;

var mess      ="Attenzione, non è possibile continuare perchè:\n";
var err       = 0;
if (user=="")      { mess+=" - Il nome utente non è stato inserito\n"; err++; }
if (isAlfa(user)==false)  { mess+=" - Il nome utente non è valido\n"; err++; } 
if (pass=="")      { mess+=" - La password non è stata inserita\n"; err++; }
if (pass!=pass2)   { mess+=" - Il campo password e conferma password non coincidono\n"; err++; }
if (rag_soc=="")   { mess+=" - La ragione sociale della farmacia è obbligatoria\n"; err++; }
if (indirizzo=="") { mess+=" - L'indirizzo non è stato inserito\n"; err++; }
//if (isAlfanumerico(indirizzo)==false)  { mess+=" - L'indirizzo non è valido\n"; err++; } 
if (citta=="")     { mess+=" - La città non è stata inserita\n"; err++; }
//if (isAlfanumerico(citta)==false)  { mess+=" - La città non è valida\n"; err++; } 
if (cap=="")       { mess+=" - Il CAP non è stato inserito\n"; err++; }
if (email=="")     { mess+=" - L'indirizzo email\ non è stato inserito\n"; err++; }
if (checkMail(email)==false)     { mess+=" - L'indirizzo email\ non è corretto\n"; err++; }
if (email!=email2) { mess+=" - Il campo 'email' e 'conferma email' non coincidono\n"; err++;}
if (nome=="")      { mess+=" - Il Nome non è stato inserito\n"; err++; }
if (isAlfa(nome)==false)  { mess+=" - Il nome non è valido\n"; err++; } 
if (cognome=="")   { mess+=" - Il cognome non è stato inserito\n"; err++; }
if (isAlfa(cognome)==false)  { mess+=" - Il cognome non è valido\n"; err++; } 
if (check_piva(piva)==false) { mess+=" - La partita IVA non è corretta\n"; err++; }
//if (dn=="")        { mess+=" - La data di nascita non è stata inserita\n"; err++; }
//if (checkDataNascita(dn)==false) 
 // { mess+=" - La data di nascita non è nel formato corretto (gg/mm/aaaa) o non è una data corretta\n"; err++; }
if (iban=="") { mess+=" - L'IBAN non è stato inserito\n"; err++; }
//if (codfis=="")  { mess+=" - Il codice fiscale non è corretto\n"; err++; }
//if (l_n=="") { mess+=" - Il luogo di nascita non è stato inserito\n"; err++ }
//if (prov_n==-1) { mess+=" - La provincia di nascita non è stata inserita\n"; err++; }
//if (tel=="")   { mess+=" - Il Numero di Telefono non è stato inserito\n"; err++; }
if (reg=="")       { mess+=" - Il numero di registrazione all'albo non è stato inserito\n"; err++; }
if (privacy==false){ mess+=" - Non è stata accettata la normativa sulla privacy\n"; err++; }
if (err>0) 
  alert(mess);
else
  document.form_reg.submit();
}
function check_piva(pi)
{
if (pi.length!=11 || isNum(pi)==false)
 return false;
else
 return true;
}

function check_cont_reg2()
{
var pass      = document.getElementById("pass").value;
var pass2     = document.getElementById("pass2").value;
/*var rag_soc   = document.getElementById("rag_soc").value;
var indirizzo = document.getElementById("indirizzo").value;
var citta     = document.getElementById("citta").value;
var cap       = document.getElementById("cap").value;*/
var email     = document.getElementById("email").value;
var nome      = document.getElementById("nome").value;
//var piva      = document.getElementById("piva").value;
var cognome   = document.getElementById("cognome").value;
var reg       = document.getElementById("reg").value;
var dn		  = document.getElementById("dn").value;


var mess      ="Attenzione, non è possibile continuare perchè:\n";
var err       = 0;
if (pass!=pass2)   { mess+=" - Il campo password e conferma password non coincidono\n"; err++; }
//if (rag_soc=="")   { mess+=" - La ragione sociale della farmacia è obbligatoria\n"; err++; }
//if (indirizzo=="") { mess+=" - L'indirizzo non è stato inserito\n"; err++; }
//if (isAlfanumerico(indirizzo)==false)  { mess+=" - L'indirizzo non è valido\n"; err++; } 
//if (check_piva(piva)==false) { mess+=" - La partita IVA non è corretta\n"; err++; }
//if (citta=="")     { mess+=" - La città non è stata inserita\n"; err++; }
//if (isAlfanumerico(citta)==false)  { mess+=" - La città non è valida\n"; err++; } 
//if (cap=="")       { mess+=" - Il CAP non è stato inserito\n"; err++; }
if (email=="")     { mess+=" - L'indirizzo email\n"; err++; }
if (checkMail(email)==false)     { mess+=" - L'indirizzo email\ non è corretto\n"; err++; }
//if (checkDataNascita(dn)==false) { mess+=" - La data di nascita non è nel formato corretto (gg/mm/aaaa) o non è una data corretta\n"; err++; }

if (nome=="")      { mess+=" - Il Nome non è stato inserito\n"; err++; }
if (isAlfa(nome)==false)  { mess+=" - Il nome non è valido\n"; err++; } 
if (cognome=="")   { mess+=" - Il cognome non è stato inserito\n"; err++; }
if (isAlfa(cognome)==false)  { mess+=" - Il cognome non è valido\n"; err++; } 

if (err>0) 
  alert(mess);
else
  document.form_reg.submit();
}


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_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function checkPIN()
{ var pin = document.getElementById("pin").value;
  if (pin=="") alert("Attenzione, è necessario inserire il pin ricevuto via email!");
  else document.form_pin.submit();
}

function makeNews(idNews)
{
  var myAjax = new Ajax.Updater( "divNews", "pages/news.php?idNews="+idNews, { method: 'get'});	
}

function makeRelated(page,idCat)
{
  var myAjax = new Ajax.Updater( "divRelated", "pages/related.php?idCat="+idCat+"&page="+page, { method: 'get'});	
}

function makePlayer(idVideo)
{
  document.getElementById("divPlayer").src="pages/player.php?v="+idVideo;
//  var myAjax = new Ajax.Updater( "divPlayer", "pages/player.php?v="+idVideo, { method: 'get'});	
}

function makeMagazine(page)
{
  var myAjax = new Ajax.Updater( "divMagazine", "pages/magazine.php?page="+page, { method: 'get'});	
}

function makeDescr(idVideo)
{
 var myAjax = new Ajax.Updater( "divNews", "pages/descrizione.php?idVideo="+idVideo, { method: 'get'});	
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function chVideo(idVideo,target,idCat)
{
 if (target==0)
 {
	 makeRelated(0,idCat);
	 makeDescr(idVideo);
	 makePlayer(idVideo)
 }
 if (target==1)
  { //if (tipo==1) alert('nuova finestra - indicizzato'); 
    //if (tipo==0) alert('nuova finestra - normale'); 
	MM_openBrWindow('pages/pop_video.php?idVideo='+idVideo,'','width=1018,height=845,scrollbars=1');
  }
}

function makeSponsor()
{ var myAjax = new Ajax.Updater( "divSponsor", "pages/sponsor.php", { method: 'get'});	}

function copyData()
{
 if(confirm("Si conferma la copia dei dati dal database di pharmatv?"))
 {
  document.getElementById("rag_soc2").value= document.getElementById("rag_soc1").value;
  document.getElementById("indirizzo2").value= document.getElementById("indirizzo1").value;
  document.getElementById("citta2").value= document.getElementById("citta1").value;
  document.getElementById("cap2").value= document.getElementById("cap1").value;
  document.getElementById("piva2").value= document.getElementById("piva1").value;
 }
}

function isAlfanumerico(stringa) {
//    var myregexp = /^[a-zA-Z0-9]+$/;
//alert(myregexp.test(stringa));
    var myregexp = /[a-zA-Z0-9]/;
    if ((myregexp.test(stringa) == false)  || (stringa.length<2))
     return false;
    else
    return true;

}

function isAlfa(stringa) {
//	  var myregexp = /^[a-zA-Z]+$/;
    var myregexp = /[a-zA-Z0-9]/;
    if ((myregexp.test(stringa) == false)  || (stringa.length<2))
    return false;
    else
    return true;
}

function isNum(stringa) {
    var myregexp = /[0-9]/;
    if (myregexp.test(stringa) == false)
    return false;
    else
    return true;
}
  
function checkDataNascita(s)
{ var anno = 0; var mese=0; var giorno=0; 
  var gg = s.charAt(0)+s.charAt(1);
  var mm = s.charAt(3)+s.charAt(4);
  var aa = s.charAt(6)+s.charAt(7)+s.charAt(8)+s.charAt(9);
  if (isNum(aa) && aa>1900) { anno = 1; }
  if (isNum(mm) && mm<13) { mese = 1; }
  if (gg>=32) giorno  = 0;
  //else
  //if ((gg>=30 && mm==2) || (mm==4  && gg>=31) || (mm==6 && gg>=31) || (mm==9 && gg>=31) || (mm==11 && gg>=31))
   // giorno = 0; 	
  else giorno=1;
  
  if (mese==1 && giorno==1 && anno==1) return true; else return false;	
   
}

function makeProv()
{ 
  var idRegione = document.getElementById("regione").value;
  var myAjax = new Ajax.Updater( "divProv", "pages/prov.php?idRegione="+idRegione, { method: 'get'});	
}

function makeCitta()
{ 
  var idRegione = document.getElementById("idProv").value;
  var myAjax = new Ajax.Updater( "divCitta", "pages/citta.php?idProv="+idRegione, { method: 'get'});	
}

function makeCap()
{ 
  var idRegione = document.getElementById("citta").value;
  var myAjax = new Ajax.Updater( "divCap", "pages/cap.php?idCitta="+idRegione, { method: 'get'});	
}

function confirmEnable(idUtente)
{ if (confirm("Si conferma l'abilitazione di questo utente?")) location.href='?page=stat&action=enable&idUtente='+idUtente; }

function confirmDeleteUser(idUtente)
{ if (confirm("Si conferma l'eliminazione di questo utente?")) location.href='?page=stat&action=delUser&idUtente='+idUtente; }

function confermaDeleteSelect()
{ if (confirm("Attenzione, procedendo tutti gli utenti selezionati verranno eliminati. Procedere?"))
  { if (confirm("E' la tua risposta definitiva?"))
    {  document.form_select.action='?page=stat&action=deleteselect';
	    document.form_select.submit(); 
	}
  }
}

function confermaEnableSelect()
{ if (confirm("Attenzione, procedendo tutti gli utenti selezionati verranno abilitati. Procedere?"))
  { if (confirm("E' la tua risposta definitiva?"))
    {  document.form_select.action='?page=stat&action=enableselect';
	    document.form_select.submit(); 
	}
  }
}

function confermaContrattoSelect()
{ if (confirm("Attenzione, procedendo tutti gli utenti selezionati impostati con \"contratto inviato\". Procedere?"))
      {  document.form_select.action='?page=stat&action=contratti';
	    document.form_select.submit(); 
	}
}


function confirmdelfattura(id)
{ if (confirm("Si conferma l'eliminazione di questo periodo di fatturazione?"))
  location.replace("?page=fatture&action=delete&id="+id); 
 }
 
 function checkPer()
 { var titolo = document.getElementById("titolo").value;
   if (titolo=="") alert ("Attenzione è necessario specificare un titolo per il periodo di fatturazione");
   else document.form1.submit();
 }
 
 function makePH2(piva)
{
	 var res   = "admin/pages/resph.php?piva="+piva;
	 var myAjax = new Ajax.Updater( "result", res, { method: 'get'})
}


function makePH(piva)
{
	 var res   = "pages/resph.php?piva="+piva;
	 var myAjax = new Ajax.Updater( "result", res, { method: 'get'})
}
