var win = null;
function NewWindow(mypage,myname,w,h,scroll)
{
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}


function textCounter(field,  maxlimit) 
{
if (field.value.length > maxlimit) 
	field.value = field.value.substring(0, maxlimit);
}

function replacechar(testo)
{
	testo=testo.replace(/\%/g,"%25");
	testo=testo.replace(/\&/g,"%26");
	testo=testo.replace(/\$/g,"%24");
	testo=testo.replace(/\#/g,"%23");
	testo=testo.replace(/\"/g,"%22");
	testo=testo.replace(/[\']/g,"''");
    return testo;
}

function isInt(testo)
{
	var myMod = testo % 1;
	if (myMod == 0) 
		{
  	return testo;
  	} 
  else 
  	{
    return 0;
    }
}
function chk_login(chk_stato)
{
	if(chk_stato!="SI")
		self.location="public/login_error.asp";
}

function chk_pwd_mod(result_str)
{
	if(result_str=="OLDPWDERROR")
		alert("Attenzione: Vecchia password errata. Operazione cambio password non eseguita");
	if(result_str=="PWDMODOK")
		alert("Operazione cambio password eseguita correttamente.");	
}

function controllasevuoto(oggetto)
{
  if (oggetto == "")
  {
    return (0);
  }
}

function validateEmail(email)
{
    if(email.length <= 0)
	{
	  return false;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function valida_acq_dati(theForm)
{
  // validazione email  
  if (validateEmail(theForm.Email.value) == false){alert("Campo Email non valido"); theForm.Email.focus(); return (false);} 
  return (true);
}