function NewWinSmall(str,Nome,Larghezza,Altezza,Scrollbar,Resizable,Menubar) {

  _info  = "toolbar=no";      // yes|no 
  _info += ",location=no";    // yes|no 
  _info += ",directories=no"; // yes|no 
  _info += ",status=no";      // yes|no 
  _info += ",menubar=" + Menubar;     // yes|no
  _info += ",scrollbars=" + Scrollbar; // yes|no 
  _info += ",resizable=" + Resizable;  // yes|no
  _info += ",alwaysRaised=yes";      
  _info += ",dependent=1";      // close the parent, close the popup, omit if you want otherwise 
  _info += ",height=" + Altezza;
  _info += ",width=" + Larghezza;
  _info += ",left=" + (screen.width - Larghezza)/2;
  _info += ",top=" + (screen.height - Altezza)/2;
  //searchWin = window.open(str,Nome,'alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,z-lock=0,screenX=0,screeny=0,left=' + (screen.height-" + Altezza + ")/2 + ',top=' + (screen.width-" + Larghezza + ")/2 );
  
  searchWin = window.open(str,Nome,_info);
}

function createModal(url_source,Nome,Larghezza,Altezza) {
  var modal_dim="dialogWidth:" + Larghezza + "px; dialogHeight:" + Altezza + "px; center:yes";
  var searchWin = window.showModalDialog(url_source,Nome,modal_dim);
}



function Trim(stringa){
	reTrim=/\s+$|^\s+/g;
	return stringa.replace(reTrim,"");
}

function CodiceFiscale(Valore){
	var re=/^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
	Codice=Trim(Valore.toUpperCase());
	CodiceFiscale=re.test(Codice);
}

function PartitaIVA(Valore){
	var re=/^\d{5}\d{6}$/;
	Codice=Trim(Valore.toUpperCase());
	PartitaIVA=re.test(Codice);
}

function EMail(Valore){
	var re=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([ a-zA-Z0-9]{2,})+$/;
	Codice=Trim(Valore.toUpperCase());
	EMail=re.test(Codice);
	//return EMail;
}

function Check_Articolo(frm) {
	if (frm.Cod.value.length==0) {
		alert('Inserire il CODICE dell\'articolo!');
		frm.Cod.focus();
		return false;
	}

	if (frm.UniNome.value.length==0) {
		alert('Inserire la DESCRIZIONE dell\'articolo!');
		frm.UniNome.focus();
		return false;
	}
	document.all.loading.style.visibility='visible';
	return true;
}

function CheckReg(frm,Cnt) {

	//frm: modulo da controllare
	//Cnt: True se è un Contatto, False altrimenti
	if (frm.Azienda.value.length==0) {
		if (!Cnt) alert('Inserire la RAGIONE SOCIALE dell\'azienda!');
		else alert('Inserire il NOME del contatto!');
		frm.Azienda.focus();
		return false;
	}

	if (!Cnt) {
		if (frm.Naz.value=='IT') {
			if (frm.PIVA.value.length>0) {
				re=/^\d{5}\d{6}$/;
				Codice=Trim(frm.PIVA.value.toUpperCase());
				PartitaIVA=re.test(Codice);
				if (PartitaIVA==false){
					alert('La PARTITA IVA è errata!');
					if (frm.PIVA.style.visibility != 'hidden') frm.PIVA.focus();
					return false;
				}
			}
		}
	}
	
	else {
			if (frm.CodFisc.value.length>0) {
				re=/^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
				Codice=Trim(frm.CodFisc.value.toUpperCase());
				CodiceFiscale=re.test(Codice);		
				if (CodiceFiscale==false) {
					alert('Il CODICE FISCALE è errato!');
					if (frm.CodFisc.style.visibility != 'hidden') frm.CodFisc.focus();
					return false;
				}
			}
	//	if (frm.Username.value.length==0) {
	//		alert('Inserire lo Username!');
	//		frm.Username.focus();
	//		return false;
	//	}
	
	//	if (frm.PswAz.value.length==0) {
	//		alert('Inserire la Password!');
	//		frm.PswAz.focus();
	//		return false;
	//	}
	}
	


	if (frm.Mail.value.length>0) {
		re=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([ a-zA-Z0-9]{2,})+$/;
		Codice=Trim(frm.Mail.value.toUpperCase());
		EMail=re.test(Codice);
		if (EMail==false) {
			alert('L\'E-Mail è errata!');
			if (frm.Mail.style.visibility != 'hidden') frm.Mail.focus();
			return false;
		}
	}

	Loading_Vis();
	return true;
}



function contaChar(d,CampoStr,CampoNum,NumChar) {
//Conta il numero di caratteri rimanenti per arrivare a 0
//CampoStr-->Campo Stringa da inserire
//CampoNum-->Campo caratteri rimanenti
//NumChar-->Lunghezza campo in caratteri
	 if (CampoStr.value.length > NumChar) {
	 	alert('Numero eccessivo di caratteri inseriti!')
		return false;
	    }
	else
		CampoNum.value = NumChar - CampoStr.value.length;
	return true;
}


function frmCheckTextArea(frm,cifreQta,Old) {
	var tmp;

	for (var i=0; i < frm.value.length; i++){
   		tmp = frm.value.substring(i,i+1);
		if (tmp=='"') {
            alert('Hai inserito un carattere non ammesso!');
			frm.value = Old;
            frm.focus();
            return (false);
		}
	}
	return true;
}

function frmCheckApice(frm,cifreQta,Old) {
 
var tmp;

	for (var i=0; i < frm.value.length; i++){
   		tmp = frm.value.substring(i,i+1);
		if ((tmp=='"') || (cifreQta.indexOf(tmp)==-1)) {
            alert('Hai inserito un carattere non ammesso!');
			frm.value = Old;
            frm.focus();
            return (false);
		}
	}
	return true;
}

function frmCheck(frm,cifreQta,Old) {
var tmp;

	//if (window.event.keyCode==13) return true;

	for (var i=0; i < frm.value.length; i++){
   		tmp = frm.value.substring(i,i+1);
		if (cifreQta.indexOf(tmp)==-1) {
            alert('Hai inserito un carattere non ammesso!');
			frm.value = Old;
            frm.focus();
            return false;
		}
	}
	return true;
}

function frmCheckVir(frm,cifreQta,Old) {
var tmp;

	tmp=frm.value;
	frm.value=tmp.replace(".",",");
	for (var i=0; i < frm.value.length; i++){
   		tmp = frm.value.substring(i,i+1);
		if (cifreQta.indexOf(tmp)==-1) {
            alert('Hai inserito un carattere non ammesso!');
			frm.value = Old;
            frm.focus();
            return false;
		}
	}
	return true;
}

function ContaCarattere(frm,cifreQta,Old,LimiteTot) {
	var NumChar=0;
	
	for (var i=0; i < frm.value.length; i++){
   		tmp = frm.value.substring(i,i+1);
		if (cifreQta.indexOf(tmp)!=-1)
			NumChar=NumChar+1;

		if  (NumChar>LimiteTot) {
			alert('Hai inserito troppi \'' + cifreQta + '\'!');
			frm.value = Old;
            frm.focus();
            return false;
		}	
	}
	return true;
}


Char = '€ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
CharStd = '€ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,0123456789+-*\\!£$%&/()=?^èéìòàùÀÀÁÈÉÌÍ;:<>_§°ç[]{}\'<>@#'
Cifre = '0123456789'
CifreNoZero = '123456789'
CifreSegno = '+-0123456789'
CifreVir = '.,0123456789'
CifreVirSegno = '+-.,0123456789'
CifreData = '/0123456789'
CharData = '/ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
CharCifre = '€ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
CifreRic = '<>0123456789'
CifreVirRic = '<>.,0123456789'
CifreVirRicSegno = '+-<>.,0123456789'
CharDataRic = '<>/ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
CharLabel = ' abcdhjinortuACEFGHJILOPSUYZ0123456789'


function Loading_Vis() {
	document.all.loading.style.visibility='visible';
}

function LimitAttach(form, file, p_Tipo) {
//Controllo delle estensioni degli upload

	switch(p_Tipo) {
		case ('Database'): 	extArray = new Array('.dbf','.dbt','.DBF','.DBT')
						break;

		case ('Mailing'): 	extArray = new Array('.zip','.ZIP')
						break;

		default:		extArray = new Array('')
						break;
	}
	
	allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	
	for (var i = 0; i < extArray.length; i++) {
	if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit) { 
		alert("ATTENZIONE! Solo file con estensione: " 
		+ (extArray.join(" ")));
	}
	else  Loading_Vis();
	return allowSubmit;
}

function right(e) {
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) {
		alert("Spiacenti...");
		return false;
	}
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
		alert("Spiacenti...");
		return false;
	}
	return true;
}