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 imCodeProt() {
   document.oncontextmenu = function()
   { if (window.location.hostname!="localhost")
     {
       return false;
     } 
   }
}

function replacechar(testo)
{   // vecchie impostazioni:
	testo=testo.replace(/\%/g,"%25");
    testo=testo.replace(/\+/g,"&#43");
    testo=testo.replace(/\'/g,"&#39");
	testo=testo.replace(/\&/g,"%26");
	testo=testo.replace(/\$/g,"%24");
	testo=testo.replace(/\#/g,"%23");
	testo=testo.replace(/\"/g,"%22");
    testo=testo.replace(/\°/g,"&#176");
    //testo=testo.replace(/[\']/g,"''");
    // impostazioni che potrebbero servire:
    //testo=testo.replace(/\!/g,"&#33");
    //testo=testo.replace(/\"/g,"&#34");
    //testo=testo.replace(/\#/g,"&#35");
    //testo=testo.replace(/\$/g,"&#36");
    //testo=testo.replace(/\%/g,"&#37");
    //testo=testo.replace(/\&/g,"&#38");
    //testo=testo.replace(/\(/g,"&#40");
    //testo=testo.replace(/\)/g,"&#41");
    //testo=testo.replace(/\*/g,"&#42");
    //testo=testo.replace(/\+/g,"&#43");
    //testo=testo.replace(/\,/g,"&#44");
    //testo=testo.replace(/\-/g,"&#45");
    //testo=testo.replace(/\//g,"&#47");
    //testo=testo.replace(/\</g,"&#60");
    //testo=testo.replace(/\=/g,"&#61");
    //testo=testo.replace(/\>/g,"&#62");
    //testo=testo.replace(/\?/g,"&#63");
    //testo=testo.replace(/\@/g,"&#64");
    //testo=testo.replace(/\[/g,"&#91");
    //testo=testo.replace(/\\/g,"&#92");
    //testo=testo.replace(/\]/g,"&#93");
    //testo=testo.replace(/\^/g,"&#94");
    //testo=testo.replace(/\_/g,"&#95");
    //testo=testo.replace(/\`/g,"&#96");
    //testo=testo.replace(/\{/g,"&#123");
    //testo=testo.replace(/\|/g,"&#124");
    //testo=testo.replace(/\}/g,"&#125");
    //testo=testo.replace(/\~/g,"&#126");
    //testo=testo.replace(/\€/g,"&#128");
    //testo=testo.replace(/\‚/g,"&#130");
    //testo=testo.replace(/\ƒ/g,"&#131");
    //testo=testo.replace(/\„/g,"&#132");
    //testo=testo.replace(/\†/g,"&#134");
    //testo=testo.replace(/\‡/g,"&#135");
    //testo=testo.replace(/\ˆ/g,"&#136");
    //testo=testo.replace(/\‰/g,"&#137");
    //testo=testo.replace(/\Š/g,"&#138");
    //testo=testo.replace(/\‹/g,"&#139");
    //testo=testo.replace(/\Œ/g,"&#140");
    //testo=testo.replace(/\Ž/g,"&#142");
    //testo=testo.replace(/\‘/g,"&#145");
    //testo=testo.replace(/\’/g,"&#146");
    //testo=testo.replace(/\“/g,"&#147");
    //testo=testo.replace(/\”/g,"&#148");
    //testo=testo.replace(/\–/g,"&#150");
    //testo=testo.replace(/\—/g,"&#151");
    //testo=testo.replace(/\˜/g,"&#152");
    //testo=testo.replace(/\™/g,"&#153");
    //testo=testo.replace(/\š/g,"&#154");
    //testo=testo.replace(/\›/g,"&#155");
    //testo=testo.replace(/\œ/g,"&#156");
    //testo=testo.replace(/\ž/g,"&#158");
    //testo=testo.replace(/\Ÿ/g,"&#159");
    //testo=testo.replace(/\¡/g,"&#161");
    //testo=testo.replace(/\¢/g,"&#162");
    //testo=testo.replace(/\£/g,"&#163");
    //testo=testo.replace(/\¤/g,"&#164");
    //testo=testo.replace(/\¥/g,"&#165");
    //testo=testo.replace(/\¦/g,"&#166");
    //testo=testo.replace(/\§/g,"&#167");
    //testo=testo.replace(/\¨/g,"&#168");
    //testo=testo.replace(/\©/g,"&#169");
    //testo=testo.replace(/\ª/g,"&#170");
    //testo=testo.replace(/\«/g,"&#171");
    //testo=testo.replace(/\¬/g,"&#172");
    //testo=testo.replace(/\ /g,"&#173");
    //testo=testo.replace(/\®/g,"&#174");
    //testo=testo.replace(/\¯/g,"&#175");
    //testo=testo.replace(/\°/g,"&#176");
    //testo=testo.replace(/\±/g,"&#177");
    //testo=testo.replace(/\²/g,"&#178");
    //testo=testo.replace(/\³/g,"&#179");
    //testo=testo.replace(/\´/g,"&#180");
    //testo=testo.replace(/\µ/g,"&#181");
    //testo=testo.replace(/\¶/g,"&#182");
    //testo=testo.replace(/\·/g,"&#183");
    //testo=testo.replace(/\¸/g,"&#184");
    //testo=testo.replace(/\¹/g,"&#185");
    //testo=testo.replace(/\º/g,"&#186");
    //testo=testo.replace(/\»/g,"&#187");
    //testo=testo.replace(/\¼/g,"&#188");
    //testo=testo.replace(/\½/g,"&#189");
    //testo=testo.replace(/\¾/g,"&#190");
    //testo=testo.replace(/\¿/g,"&#191");
    //testo=testo.replace(/\À/g,"&#192");
    //testo=testo.replace(/\Á/g,"&#193");
    //testo=testo.replace(/\Â/g,"&#194");
    //testo=testo.replace(/\Ã/g,"&#195");
    //testo=testo.replace(/\Ä/g,"&#196");
    //testo=testo.replace(/\Å/g,"&#197");
    //testo=testo.replace(/\Æ/g,"&#198");
    //testo=testo.replace(/\Ç/g,"&#199");
    //testo=testo.replace(/\È/g,"&#200");
    //testo=testo.replace(/\É/g,"&#201");
    //testo=testo.replace(/\Ê/g,"&#202");
    //testo=testo.replace(/\Ë/g,"&#203");
    //testo=testo.replace(/\Ì/g,"&#204");
    //testo=testo.replace(/\Í/g,"&#205");
    //testo=testo.replace(/\Î/g,"&#206");
    //testo=testo.replace(/\Ï/g,"&#207");
    //testo=testo.replace(/\Ð/g,"&#208");
    //testo=testo.replace(/\Ñ/g,"&#209");
    //testo=testo.replace(/\Ò/g,"&#210");
    //testo=testo.replace(/\Ó/g,"&#211");
    //testo=testo.replace(/\Ô/g,"&#212");
    //testo=testo.replace(/\Õ/g,"&#213");
    //testo=testo.replace(/\Ö/g,"&#214");
    //testo=testo.replace(/\×/g,"&#215");
    //testo=testo.replace(/\Ø/g,"&#216");
    //testo=testo.replace(/\Ù/g,"&#217");
    //testo=testo.replace(/\Ú/g,"&#218");
    //testo=testo.replace(/\Û/g,"&#219");
    //testo=testo.replace(/\Ü/g,"&#220");
    //testo=testo.replace(/\Ý/g,"&#221");
    //testo=testo.replace(/\Þ/g,"&#222");
    //testo=testo.replace(/\ß/g,"&#223");
    //testo=testo.replace(/\à/g,"&#224");
    //testo=testo.replace(/\á/g,"&#225");
    //testo=testo.replace(/\â/g,"&#226");
    //testo=testo.replace(/\ã/g,"&#227");
    //testo=testo.replace(/\ä/g,"&#228");
    //testo=testo.replace(/\å/g,"&#229");
    //testo=testo.replace(/\æ/g,"&#230");
    //testo=testo.replace(/\ç/g,"&#231");
    //testo=testo.replace(/\è/g,"&#232");
    //testo=testo.replace(/\é/g,"&#233");
    //testo=testo.replace(/\ê/g,"&#234");
    //testo=testo.replace(/\ë/g,"&#235");
    //testo=testo.replace(/\ì/g,"&#236");
    //testo=testo.replace(/\í/g,"&#237");
    //testo=testo.replace(/\î/g,"&#238");
    //testo=testo.replace(/\ï/g,"&#239");
    //testo=testo.replace(/\ð/g,"&#240");
    //testo=testo.replace(/\ñ/g,"&#241");
    //testo=testo.replace(/\ò/g,"&#242");
    //testo=testo.replace(/\ó/g,"&#243");
    //testo=testo.replace(/\ô/g,"&#244");
    //testo=testo.replace(/\õ/g,"&#245");
    //testo=testo.replace(/\ö/g,"&#246");
    //testo=testo.replace(/\÷/g,"&#247");
    //testo=testo.replace(/\ø/g,"&#248");
    //testo=testo.replace(/\ù/g,"&#249");
    //testo=testo.replace(/\ú/g,"&#250");
    //testo=testo.replace(/\û/g,"&#251");
    //testo=testo.replace(/\ü/g,"&#252");
    //testo=testo.replace(/\ý/g,"&#253");
    //testo=testo.replace(/\þ/g,"&#254");
    //testo=testo.replace(/\ÿ/g,"&#255");
    //testo=testo.replace(/\Ð/g,"&#272");
    return testo;
}

function textCounter(field,  maxlimit) 
{
if (field.value.length > maxlimit) 
	field.value = field.value.substring(0, maxlimit);
}

function _TrimString(s) {
  if (!s || s=="") return "";
  while ((s.charAt(0)==' ') || (s.charAt(0)=='\n') || (s.charAt(0,1)=='\r')) s=s.substring(1,s.length);
  while ((s.charAt(s.length-1)==' ') || (s.charAt(s.length-1)=='\n') || (s.charAt(s.length-1)=='\r')) s=s.substring(0,s.length-1);
  return s;
}

function is_IE()
{	var browName = navigator.appName;
	alert("browName="+browName)
	if (browName!='Microsoft Internet Explorer')
	{	   
		return (0);	
	}
	else	
	{	   
		return (1);   	
	}
} 

////////////////////////////////////////funzioni di controllo sui campi///////////////////////////////////////

function controllasevuoto(oggetto)
{
  if (oggetto == "")
  {
    return (0);
  }
}

function controllasepositivo(oggetto)
{
  if (oggetto < 1)
  {
    return false;
  }
}

function controllalunghezzaminima(oggetto,lunghezza)
{
if (oggetto.length < lunghezza)
  {
    return (0);
  }
}

function controllalunghezzamassima(oggetto,lunghezza)
{
if (oggetto.length > lunghezza)
  {
    return (0);
  }
}

function controllalunghezzaesatta(testo,lunghezza)
{
if (testo.length != lunghezza)
  {
    return false;
  }
  return true;
}

function numeric(testo)
{ 
  var charpos = testo.search("[^0-9]"); 
  if(testo.length > 0 &&  charpos >= 0) 
  { 
    return false; 
  }
  return true; 
}

function alpha(testo)
{ 
  var charpos = testo.search("[^A-Za-z]"); 
  if(testo.length > 0 &&  charpos >= 0) 
  { 
    return false; 
  }
  return true; 
}

function alpha_esteso(testo)
{ 
  var charpos = testo.search("[^A-Za-z' ]"); 
  if(testo.length > 0 &&  charpos >= 0) 
  { 
    return false; 
  }
  return true; 
}

function alphanumeric(testo)
{ 
  var charpos = testo.search("[^A-Za-z0-9]"); 
  if(testo.length > 0 &&  charpos >= 0) 
  { 
    return false; 
  }
  return true; 
}

function alphanumeric_esteso(testo)
{ 
  var charpos = testo.search("[^A-Za-z0-9_]"); 
  if(testo.length > 0 &&  charpos >= 0) 
  { 
    return false; 
  }
  return true; 
}
           
function validateEmail(email)
{
    if(email.length <= 0)
	{
	  return true;
	}
    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;
}


