// JavaScript Document
var btnSbm = document.getElementById("btnSbm");
var btnDel = document.getElementById("btnDel");

if (btnSbm.addEventListener)
    btnSbm.addEventListener("click", iscrivi, false);
else if (btnSbm.attachEvent)
    btnSbm.attachEvent("onclick", iscrivi);
	
if (btnDel.addEventListener)
    btnDel.addEventListener("click", rimuovi, false);
else if (btnDel.attachEvent)
    btnDel.attachEvent("onclick", rimouvi);
	
function iscrivi()  {
	var cliente = document.getElementById("intClt").value;
	var gruppo = document.getElementById("intGrp").value;
	var mail = document.getElementById("mail").value;
	if(!isValidEmail(mail)) return false;
	//set default values
	document.getElementById('nome')?nome=document.getElementById('nome').value:nome=mail;
	document.getElementById('cognome')?cognome=document.getElementById('cognome').value:cognome='';
	document.getElementById('indirizzo')?indirizzo=document.getElementById('indirizzo').value:indirizzo='';
	document.getElementById('localita')?localita=document.getElementById('localita').value:localita='';
	document.getElementById('azienda')?azienda=document.getElementById('azienda').value:azienda='';
	//compose querystring
	qstring = 'http://www.bitmail.net/iscrivi.php?mode=subscribe';
	qstring += '&cliente=' + cliente;
	qstring += '&gruppo=' + gruppo;
	qstring += '&mail=' + mail;
	qstring += '&nome=' + nome;
	qstring += '&cognome=' + cognome;
	qstring += '&indirizzo=' + indirizzo;
	qstring += '&localita=' + localita;
	qstring += '&azienda=' + azienda;
	pp = window.open(qstring,'_blank','scrollbars=no,resizable=no,menubar=no,toolbar=no,location=no,status=no,width=360,height=150,top='+(window.screen.height/2-75)+',left='+(window.screen.width/2-180));
	//pp.close();
	return true;
}

function rimuovi()  {
	var cliente = document.getElementById("intClt").value;
	var mail = document.getElementById("mail").value;
	if(!isValidEmail(mail)) return false;

	//compose querystring
	qstring = 'http://www.bitmail.net/iscrivi.php?mode=cancel';
	qstring += '&cliente=' + cliente;
	qstring += '&mail=' + mail;
	pp = window.open(qstring,'_blank','scrollbars=no,resizable=no,menubar=no,toolbar=no,location=no,status=no,width=360,height=150,top='+(window.screen.height/2-75)+',left='+(window.screen.width/2-180));
	//pp.close();
	return true;
}

//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      alert('Indirizzo mail non valido');
      return false;
    } 
    return true; 
}

//function to check value is valid and greater than 0
function isValidNum(intNum)  {
	if(intNum!=null && isNumeric(intNum) && intNum>0) return true
	else return false;
}