
function isEmail(field,strMsg){
   field.value = field.value.toLowerCase();
   strDate = field.value;
   if(strDate.length>0){
      var dateregex=/^[\w\.=-]+@[\w\.-]+\.[a-z]{2,3}$/; // mm/dd/yyyy
	  var match=strDate.match(dateregex);
  	  if (match){
	     return true;
	  }
 	  alert(strMsg);
      return false;
   }else {
     return true;
   }
}

function isEmail2(field,strMsg)
{
// lunghezza 0
if (field.value.length==0) return true;
	email = field.value;
   // controllo della presenza del carattere '@'
   var index     = email.indexOf('@', 0);
   var address   = "";
   var ok = true;

   if (index == -1)
   {
      ok = false;
   }
   else
   {
      var size = email.length;
      address = email.substring(size + 1, index + 1);
      userid =  email.substring(1, index);

      // controlla: l'unicit? del carattere "@";
      // - la presenza del "." nella parte DX dell'indirizzo;
      // - l'assenza di spazi e
      // - che la stringa non sia del tipo userid@.address o userid.@address
      if ((address.indexOf('@') != -1) || (userid.indexOf('@') != -1) ||
          (address.indexOf('.') == -1) || (!nospace(email)) ||
          (email.charAt(index - 1) == '.') || (email.charAt(index + 1) == '.'))
      {
         ok = false;
      }
   }
   if (ok == false)
   {
      alert(strMsg);
      return false;
   }
   else
   {
      return true;
   }
}

/******* Validazione Data *********/
function isDate(field,strMsg){
	 if(field.value==""){
	  		  alert(strMsg);
      return false;
	 }
   strDate = field.value;
   if(strDate.length>0){
      var dateregex=/^[ ]*[0]?(\d{2})\/(\d{2})\/(\d{4,})[ ]*$/; // mm/dd/yyyy
	    var match=strDate.match(dateregex);
  	  if (match){
    	  var tmpdate=new Date(match[3],parseInt(match[2],10)-1,match[1]);
        if (tmpdate.getDate()==parseInt(match[1],10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[2],10)){ 
      	  return true; 
        }
	    }
 		  alert(strMsg);
      return false;
   }else {
     return true;
   }
}

// VERIFICA Data di nascita
function isBirthDate(field,strMsg)
{
	var what = field.value;
   var i=new RegExp("^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$");
   if(i.test(what))
   {
	datePart=what.split("/");
	giorno=(datePart[0]>=1) && (datePart[0]<=31);
	mese=(datePart[1]>=1) && (datePart[1]<=12);
	anno=(datePart[2]>=1900) && (datePart[2]<=2005);

	if(!giorno || !mese || !anno) { alert(strMsg); return false }
	
   }  
   else
   {
	alert(strMsg); return false
   }
   return isDate(field,strMsg);
}

function isCodChip(field,strMsg) {
   str = field.value.toUpperCase();
   if(str.length>0){
      var dateregex=/^[A-Z0-9]{7}$/; // mm/dd/yyyy
	  var match=str.match(dateregex);
  	  if (match){
	     return true;
	  }
 	  alert(strMsg);
      return false;
   }else {
     return true;
   }
}

function isCell(field,strMsg)
{
// lunghezza 0
if (field.value.length==0) return true;
// se inizia con 0 li strippo
while (field.value.substring(0,1)=='0') {
field.value = field.value.substring(1,field.value.length);
}
// se contiene spazi
while (field.value.indexOf(' ',0)!=-1) {
pos = field.value.indexOf(' ',0);
field.value = field.value.substring(0,pos) + field.value.substring(pos+1,field.value.length);
}

// se non inizia con + aggiung un 39
if (field.value.length<12 && field.value.substring(0,1)!='+') {
field.value = "+39" + field.value;
}
	genRegExp = /^[\x2b]{1}[0-9]{7,}$/;
	itaRegExp = /^[\x2b]{1}333|334|335|336|337|338|339|330|360|368|340|347|348|349|320|328|329|380|388|389|392|393[0-9]{6,}$/;
	str = field.value;
	var match=str.match(genRegExp);
  	if (match){
  		if (str.substring(0,3)=='+39') {
			match=str.match(itaRegExp);
		  	if (match){
				return true;
		  	}
  		} else {
			return true;
  		}
	}
	alert (strMsg);
	return false;
}

function fixCell(field)
{
// lunghezza 0
if (field.value.length==0) return true;
// se inizia con 0 li strippo
while (field.value.substring(0,1)=='0') {
 field.value = field.value.substring(1,field.value.length);
}
// se contiene spazi
while (field.value.indexOf(' ',0)!=-1) {
 pos = field.value.indexOf(' ',0);
 field.value = field.value.substring(0,pos) + field.value.substring(pos+1,field.value.length);
}

// se non inizia con + aggiung un 39
if (field.value.length<12 && field.value.substring(0,1)!='+') {
 field.value = "+39" + field.value;
}
}
function nospace(str)
{
   if (str != "")
   {
      var index = str.indexOf(" ", 0);
      if (index != -1)
      {
         return false;
      }
   }

   return true;
}

var smooth_timer;
function go2(selID, link) {
  var selOBJ = (document.getElementById) ? document.getElementById(selID) : eval("document.all['" + selID + "']");
  window.location=link + selOBJ.options[selOBJ.selectedIndex].value;
}
function toclip(string) { window.clipboardData.setData('Text', string); }
function ShowTip(fArg) {
  var tooltipOBJ = (document.getElementById) ? document.getElementById('ih' + fArg) : eval("document.all['ih" + fArg + "']");
  if (tooltipOBJ != null) {
    var tooltipLft = (document.body.offsetWidth?document.body.offsetWidth:document.body.style.pixelWidth) - (tooltipOBJ.offsetWidth?tooltipOBJ.offsetWidth:(tooltipOBJ.style.pixelWidth?tooltipOBJ.style.pixelWidth:$TOOLTIPWIDTH)) - 30;
    var tooltipTop = 10;
    if (navigator.appName == 'Netscape') {
      if (parseFloat(navigator.appVersion) >= 5) { tooltipTop = (document.body.scrollTop>=0?document.body.scrollTop+10:event.clientY+10); }
      tooltipOBJ.style.left = tooltipLft; tooltipOBJ.style.top = tooltipTop;
    }
    else {
      tooltipTop = (document.body.scrollTop>=0?document.body.scrollTop+10:event.clientY+10);
      if ((event.clientX > tooltipLft) && (event.clientY < (tooltipOBJ.scrollHeight?tooltipOBJ.scrollHeight:tooltipOBJ.style.pixelHeight) + 10)) tooltipTop = (document.body.scrollTop?document.body.scrollTop:document.body.offsetTop) + event.clientY + 20;
      tooltipOBJ.style.pixelLeft = tooltipLft; tooltipOBJ.style.pixelTop = tooltipTop;
    }
    tooltipOBJ.style.visibility = "visible";
  }
}
function HideTip(fArg) {
  var tooltipOBJ = (document.getElementById) ? document.getElementById('ih' + fArg) : eval("document.all['ih" + fArg + "']");
  if (tooltipOBJ != null) tooltipOBJ.style.visibility = "hidden";
}
function smoothHeight(id, curH, targetH, stepH, mode) {
  diff = targetH - curH;
  if (diff != 0) {
    newH = (diff > 0) ? curH + stepH : curH - stepH;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
    if (smooth_timer) window.clearTimeout(smooth_timer);
    smooth_timer = window.setTimeout( "smoothHeight('" + id + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", 20 );
  }
  else if (mode != "o") ((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";
}
function rowOver(i, nColor) {
  if (!nColor) nColor = "#ECECD9";
  var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
  if (nameObj != null) nameObj.style.background=nColor;
}
function rowOut(i, nColor) {
  var trObj = (document.getElementById) ? document.getElementById('ihtr' + i) : eval("document.all['ihtr" + i + "']");
  var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
  if (trObj == null || trObj.style.display=="none") nameObj.style.background=nColor;
}
function servOC(i, href, nColor) {
  var trObj = (document.getElementById) ? document.getElementById('ihtr' + i) : eval("document.all['ihtr" + i + "']");
  var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
  var ifObj = (document.getElementById) ? document.getElementById('ihif' + i) : eval("document.all['ihif" + i + "']");
  if (trObj != null) {
    if (trObj.style.display=="none") {
      trObj.style.display="";
      nameObj.style.background="#ECECD9";
      if (!ifObj.src) ifObj.src = href;
      smoothHeight('ihif' + i, 0, 210, 42, 'o');
    }
    else {
      nameObj.style.background=nColor;
      smoothHeight('ihif' + i, 210, 0, 42, 'ihtr' + i);
    }
  }
}
function servOCopen(i, href, nColor) {
  var trObj = (document.getElementById) ? document.getElementById('ihtr' + i) : eval("document.all['ihtr" + i + "']");
  var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
  var ifObj = (document.getElementById) ? document.getElementById('ihif' + i) : eval("document.all['ihif" + i + "']");
  if (trObj != null) {
      trObj.style.display="";
      nameObj.style.background="#ECECD9";
      ifObj.src = href;
      smoothHeight('ihif' + i, 0, 210, 42, 'o');
  }
}
function servOCclose(i) {
  var trObj = (document.getElementById) ? document.getElementById('ihtr' + i) : eval("document.all['ihtr" + i + "']");
  var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
  var ifObj = (document.getElementById) ? document.getElementById('ihif' + i) : eval("document.all['ihif" + i + "']");
  if (trObj != null) {
    if (trObj.style.display=="none") {
    }
    else {
      nameObj.style.background='#B6BDe2';
      smoothHeight('ihif' + i, 210, 0, 42, 'ihtr' + i);
    }
  }
}
function trOC(idHL, idOC, idArrow) {
  var trObj = (document.getElementById) ? document.getElementById(idOC) : eval("document.all['" + idOC + "']");
  var hlObj = (document.getElementById) ? document.getElementById(idHL) : eval("document.all['" + idHL + "']");
  var arrowObj = (document.getElementById) ? document.getElementById(idArrow) : eval("document.all['" + idArrow + "']");
  if (trObj != null && hlObj != null) {
    if (trObj.style.display=="none") {
      trObj.style.display="";
      hlObj.style.background="#003366";
      hlObj.style.color="#EDF6F9";
      arrowObj.innerHTML="v";
    }
    else {
      trObj.style.display="none";
      hlObj.style.background="#ECECD9";
      hlObj.style.color="#000000";
      arrowObj.innerHTML="^";
    }
  }
}
function firstFocus()
{
   if (document.forms.length > 0)
   {
      var TForm = document.forms[0];
      for (i=0;i<TForm.length;i++)
      {
         if ((TForm.elements[i].type=="text")||
           (TForm.elements[i].type=="textarea")||
           (TForm.elements[i].type.toString().charAt(0)=="s"))
         {
            document.forms[0].elements[i].focus();
            break;
         }
      }
   }
}
function HighlightAll(theField) {
  var tempval=eval("document."+theField);
  tempval.focus();
  tempval.select();
  if (document.all) {
    therange=tempval.createTextRange();
    therange.execCommand("Copy");
    window.status="Contents highlighted and copied to clipboard!";
    setTimeout("window.status=''",5000);
  }
}
function NewWindow(mypage, myname, w, h, scroll) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function stripEnter(){
var characterCode ;
if(event.which){characterCode = event.which.keyCode;}else{characterCode = event.keyCode;}
if(characterCode == 13){return false;}
return true;
}


