// JavaScript Document
function openpopup(Tabella, IdNews, Campoindice)
{
 x = screen.width;
 y = screen.height;

 lef=0;
 to=0;
 if(x==800)
 {
 lef=150;
 to=100;
 }
 else if(x==1024)
 {
 lef=250;
 to=150;
 }
 he=428;
 window.open("Popup_news.jsp?Tabella="+Tabella+"&News="+IdNews+"&Campoindice="+Campoindice,"popup","width=500,height="+he+",scrollbars=yes,tollbar=no,status=no,resizeable=no,left="+lef+",top="+to);
}


function insertNewsl()
{
  x = screen.width;
 y = screen.height;

 lef=0;
 to=0;
 if(x==800)
 {
 lef=100;
 to=100;
 }
 else if(x==1024)
 {
 lef=100;
 to=100;
 }
 he=380;
 window.open("insertNewsL.jsp","popup","width=780,height="+he+",scrollbars=no,tollbar=no,status=no,resizeable=no,left="+lef+",top="+to);
}

function chiudiInsertNewsl()
{

  window.opener.document.fnewsletter.action="index.jsp?VDMCP=5|!|newsletter|!|X|!|X|!|X";
 // window.opener.document.fnewsletter.action="newsletter.jsp";
  window.opener.document.fnewsletter.submit();
  window.close();
}

function scrivinewsl(idtipo,percorso)
{
 x = screen.width;
 y = screen.height;

 lef=0;
 to=0;
 if(x==800)
 {
 lef=100;
 to=100;
 }
 else if(x==1024)
 {
 lef=100;
 to=0;
 }
 he=550;
 window.open("scriviNewsL.jsp?tipo="+idtipo+"&percorso="+percorso,"popup","width=780,height="+he+",scrollbars=no,tollbar=no,status=no,resizeable=no,left="+lef+",top="+to);
}

function sendNewsl()
{
 if(window.confirm("INVIARE LA NEWSLETTER AGLI UTENTI REGISTRATI?"))
 {
 
   if(Trim(fsendletter.oggetto.value)=="")
	{
	 alert("L'OGGETTO E' OBBLIGATORIO");
	 fsendletter.oggetto.value="";
	 fsendletter.oggetto.focus();
	 return;
  }
   
   if(Trim(fsendletter.testo.value)=="")
	{
	 alert("IL TESTO E' OBBLIGATORIO");
	 fsendletter.testo.value="";
	 fsendletter.testo.focus();
	 return;
  }
  	var apice=fsendletter.testo.value;
	apice=apice.replace(/[\']/g,"`");
    fsendletter.testo.value=apice;
	
	apice=fsendletter.oggetto.value;
	apice=apice.replace(/[\']/g,"`");
    fsendletter.oggetto.value=apice;
	
    document.fsendletter.submit();
 }
}

function newslelimina(record)
{
if(window.confirm("SEI SICURO DI ELIMINARE L'ARGOMENTO E TUTTE LE ISCRIZIONI DEGLI UTENTI?"))
 {
  window.location.href="index.jsp?VDMCP=5|!|newsletter|!|X|!|X|!|X&da=elimina&record="+record;
 }
}

function vislista(record,nome)
{
 x = screen.width;
 y = screen.height;

 lef=0;
 to=0;
 if(x==800)
 {
 lef=150;
 to=100;
 }
 else if(x==1024)
 {
 lef=250;
 to=150;
 }
 he=428;
 window.open("Popup_utenti.jsp?record="+record+"&nome="+nome,"popup","width=620,height="+he+",scrollbars=yes,tollbar=no,status=no,resizeable=no,left="+lef+",top="+to);
}

function openpopupStat(Id_stat)
{
 x = screen.width;
 y = screen.height;

 lef=0;
 to=0;
 if(x==800)
 {
 lef=150;
 to=100;
 }
 else if(x==1024)
 {
 lef=250;
 to=150;
 }
 he=428;
 window.open("Popup_stat.jsp?Id_stat="+Id_stat,"popup","width=500,height="+he+",scrollbars=yes,tollbar=no,status=no,resizeable=no,left="+lef+",top="+to);
}



function Trim(stringa)   
{   
	while(stringa.charAt(0)==' ' || stringa.charAt(0)=="\n" || stringa.charAt(0)=="\r")
	  stringa=stringa.substring(1,stringa.length);
	//re=/\s+$|^\s+/g; //REGULAR SXPRESSION     
    //stringa.replace(re,"");
	return stringa;
}

function testnewsl(item)
{

var i=0;

if(Trim(item.email.value)=="" || Trim(item.nome.value)=="" || Trim(item.cognome.value)=="")
{
   alert("inserire correttamente tutti i campi obbligatori");
   return;
}
Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (!Filtro.test(item.email.value))
   {
      alert("Controlla l'indirizzo di e-mail inserito");
      item.email.focus();
      return;
   }

for (var l=0; l < item.checkis.length; l++) {
	if (item.checkis[l].checked) 
	{
	i=1;
	}
}
	if(i==1) 
	{
	item.submit();	
	}
	else
	{
	item.submit();
	//alert("Bisogna selezionare almeno un argomento di newsletter");
	}
}



function testiscr(item)
{
var i=0;

if(Trim(item.indirizzo.value)=='')
{
   alert("inserire l'indirizzo");
   item.indirizzo.value="";
   item.indirizzo.focus();
   return;
}

if(Trim(item.referente.value)=='')
{
   alert("inserire un referente");
   item.referente.value="";
   item.referente.focus();
   return;
}

if(Trim(item.cittą.value)=='')
{
   alert("Inserire la cittą");
   item.cittą.value="";
   item.cittą.focus();
   return;
}
if(Trim(item.numerotelefonico.value)=='')
{
   alert("Inserire numero telefonico");
   item.numerotelefonico.value="";
   item.numerotelefonico.focus();
   return;
}
if(Trim(item.fax.value)=='')
{
   alert("Inserire numero fax");
   item.fax.value="";
   item.fax.focus();
   return;
}


if(Trim(item.provincia.value)=='' ||  !isNaN(item.provincia.value)  || item.provincia.value.length!=2)
{
   alert("Inserire la provincia");
   item.provincia.value="";
   item.provincia.focus();
   return;
}

if(Trim(item.partitaiva.value)=='' || item.partitaiva.value.length!=11 || isNaN(item.partitaiva.value))
{
   alert("Inserire la Partita IVA");
   item.partitaiva.value="";
   item.partitaiva.focus();
   return;
}


if(Trim(item.cap.value)=='' || item.cap.value.length!=5 || isNaN(item.cap.value))
{
   alert("inserire il CAP");
   item.cap.value="";
   item.cap.focus();
   return;
}


item.submit();	
	 alert("Dati modificati correttamente!!");
}






function contrivass(item)
{


if(Trim(item.nomerichiedente.value)=='')
{
   alert("Inserire il nome richiedente");
   item.nomerichiedente.value="";
   item.nomerichiedente.focus();
   return;
}

if(Trim(item.inserimento.value)=='')
{
   alert("Inserire la descrizione!");
   item.inserimento.value="";
   item.inserimento.focus();
   return;
}

if(Trim(item.menu1.value)=='0')
{
   alert("selezionare lo stato del prodotto!");
  
   item.menu1.focus();
   return;
}
if(Trim(item.menu2.value)=='0')
{
   alert("Selezionare il prodotto!");
 
   item.menu2.focus();
   return;
}
var apice=clienti.inserimento.value;
	apice=apice.replace(/[\']/g,"`");
    clienti.inserimento.value=apice;
	
	apice=clienti.malfun.value;
	apice=apice.replace(/[\']/g,"`");
    clienti.malfun.value=apice;
	
	apice=clienti.nomerichiedente.value;
	apice=apice.replace(/[\']/g,"`");
    clienti.nomerichiedente.value=apice;
	
	apice=clienti.altro.value;
	apice=apice.replace(/[\']/g,"`");
    clienti.altro.value=apice;
	
	var maiuscolo=clienti.nomerichiedente.value;
	maiuscolo=maiuscolo.toUpperCase();
	clienti.nomerichiedente.value=maiuscolo;
	
    document.clienti.submit();	
alert("Modulo di richiesta assistenza inviato! Grazie per averci scelto!"); 
}




function commenti(item)
{


if(Trim(item.nome.value)=='')
{
   alert("Inserire il nome!!");
   item.nome.value="";
   item.nome.focus();
   return;
}

if(Trim(item.cognome.value)=='')
{
   alert("Inserire il cognome!");
   item.cognome.value="";
   item.cognome.focus();
   return;
}
if(Trim(item.tipcom.value)=='0')
{
   alert("Selezionare la tipologia del commento!");
   item.tipcom.value="";
   item.tipcom.focus();
   return;
}

if(Trim(item.tipgiu.value)=='0')
{
   alert("Selezionare la tipologia del giudizio!");
   item.tipgiu.value="";
   item.tipgiu.focus();
   return;
}
if(Trim(item.descrizione.value)=='')
{
   alert("Inserire la descrizione!");
   item.descrizione.value="";
   item.descrizione.focus();
   return;
}
if(Trim(item.email.value)=='')
{
   alert("Inserire email");
   item.email.value="";
   item.email.focus();
   return;
}
Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (!Filtro.test(item.email.value))
   {
      alert("Controlla l'indirizzo di e-mail inserito");
      item.email.focus();
      return;
   }

	var apice=com.nome.value;
	apice=apice.replace(/[\']/g,"`");
    com.nome.value=apice;
	
	apice=com.cognome.value;
	apice=apice.replace(/[\']/g,"`");
    com.cognome.value=apice;
	
	apice=com.descrizione.value;
	apice=apice.replace(/[\']/g,"`");
    com.descrizione.value=apice;
	
    document.com.submit();
	
alert("Modulo Inviato correttamente! Grazie per averci scelto!"); 
}


function eliminadanewsl(record,utente,nome)
{
if(window.confirm("SEI SICURO DI ELIMINARE L'ISCRIZIONE DELL'UTENTE ALLA NEWSLETTER CORRENTE?"))
 {
  window.location.href="Popup_utenti.jsp?da=elimina&record="+record+"&utente="+utente+'&nome='+nome;
 }
}

function modificautentenewsL(utente)
{
 x = screen.width;
 y = screen.height;

 lef=0;
 to=0;
 if(x==800)
 {
 lef=150;
 to=100;
 }
 else if(x==1024)
 {
 lef=250;
 to=150;
 }
 he=428;
 window.open("Popup_utente.jsp?utente="+utente,"popup","width=500,height="+he+",scrollbars=yes,tollbar=no,status=no,resizeable=no,left="+lef+",top="+to);
}

function testmod(item)
{
var i=0;

if(Trim(item.email.value)=="" || Trim(item.nome.value)=="" || Trim(item.cognome.value)=="")
{
   alert("inserire correttamente tutti i campi obbligatori");
   return;
}
Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (!Filtro.test(item.email.value))
   {
      alert("Controlla l'indirizzo di e-mail inserito");
      item.email.focus();
      return;
   }
item.submit();

}



function checkdate(objName) {
var datefield = objName;
if (chkdate(objName) == false) {
datefield.select();
alert("Data errata, reinserirla correttamente nel formato gg/mm/aaaa oppure gg/mm/aa");
datefield.focus();
return false;
}
else {
return true;
   }
}
function chkdate(objName) {
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
//var strSeparatorArray = new Array("-"," ","/",".");
var strSeparatorArray = new Array("/");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
else
{
 return false;
}
}

if (strYear.length == 2) {
strYear = '20' + strYear;
}
else
{
if (strYear.length == 4) {
strYear = strYear;
}
else
return false;
}

// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
//datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}
function doDateCheck(from, to) {
if (Date.parse(from.value) <= Date.parse(to.value)) {
alert("The dates are valid.");
}
else {
if (from.value == "" || to.value == "") 
alert("Both dates must be entered.");
else 
alert("To date must occur after the from date.");
   }
}

function conferma(formme)
{
if(checkdate(formme.datefield))
formme.submit();
else
return false;
}

