// JavaScript Document
	function getInternetExplorerVersion()
	// Returns the version of Internet Explorer or a -1
	// (indicating the use of another browser).
	{
	  var rv = -1; // Return value assumes failure.
	  if (navigator.appName == 'Microsoft Internet Explorer')
	  {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		  rv = parseFloat( RegExp.$1 );
	  }
	  return rv;
	}
	
	function checkVersion()
	{
	  var msg = "You're not using Internet Explorer.";
	  var ver = getInternetExplorerVersion();
	
	  if ( ver > -1 )
	  {
		if ( ver >= 8.0 ) 
		  msg = "You're using a recent copy of Internet Explorer."
		else
		  msg = "You should upgrade your copy of Internet Explorer.";
	  }
	  alert( msg );
	}
	
	function encodeMyHtml(encodeHtml) {
		 encodedHtml = escape(encodeHtml);
		 encodedHtml = encodedHtml.replace(/\//g,"%2F");
		 encodedHtml = encodedHtml.replace(/\?/g,"%3F");
		 encodedHtml = encodedHtml.replace(/=/g,"%3D");
		 encodedHtml = encodedHtml.replace(/&/g,"%26");
		 encodedHtml = encodedHtml.replace(/@/g,"%40");
		 return encodedHtml;
	   } 


	function noHtml(txt) {
	  a = txt.indexOf('<');
	  b = txt.indexOf('>');
	  len = txt.length;
	  c = txt.substring(0, a);
	  if(b == -1) {
		 b = a;
	  }
	  d = txt.substring((b + 1), len);
	  txt = c + d;
	  cont = txt.indexOf('<');
	  if (cont != -1) {
		txt = noHtml(txt);
	  }
	  return txt;
	  }
	  
     var flashVideoPlayer;
	 function initialize() {
			var isIE = navigator.appName.indexOf("Microsoft") != -1;
			flashVideoPlayer = (isIE) ? window['myVideo'] : document['myVideo'];
	 }
	  function makeCall(str) {
		   if(flashVideoPlayer!=undefined)  flashVideoPlayer.playVideo(str);
	 }
	
	var undefined;
	
	// *************************************************************
	// *************************************************************
	// ******************  BROWSER SNIFFER *************************
	// *************************************************************
	// *************************************************************
		var exclude=1;
		var agt=navigator.userAgent.toLowerCase();
		var win=0;var mac=0;var lin=1;
		if(agt.indexOf('win')!=-1){win=1;lin=0;}
		if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
		var lnx=0;if(lin){lnx=1;}
		var ice=0;
		var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
		var op5=0;var op6=0;var op7=0;
		var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
		if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
			var thisKDE=agt;
			var splitKDE=thisKDE.split("konqueror/");
			var aKDE=splitKDE[1].split("; ");
			var KDEn=parseFloat(aKDE[0]);
			if(KDEn>=2.2){
				kde=1;
				ns6=1;
				exclude=0;
				}
			}
		else if(agt.indexOf('webtv')!=-1){exclude=1;}
		else if(typeof window.opera!="undefined"){
			exclude=0;
			if(/opera[\/ ][5]/.test(agt)){op5=1;}
			if(/opera[\/ ][6]/.test(agt)){op6=1;}
			if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
			}
		else if(typeof document.all!="undefined"&&!kde){
			exclude=0;
			ie=1;
			if(typeof document.getElementById!="undefined"){
				ie5=1;
				if(agt.indexOf("msie 6")!=-1){
					ie6=1;
					dcm=document.compatMode;
					if(dcm!="BackCompat"){com=1;}
					}
				}
			else{ie4=1;}
			}
		else if(typeof document.getElementById!="undefined"){
			exclude=0;
			if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
			else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
			else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
			if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
			}
		else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
			exclude=0;
			ns4=1;
			if(typeof navigator.mimeTypes['*']=="undefined"){
				exclude=1;
				ns4=0;
				}
			}
		if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
		if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}
	
	
	// *************************************************************
	// *************************************************************
	// ******************  BROWSER SNIFFER *************************
	// *************************************************************
	// *************************************************************
	

/**********************************************************************
   Validazione di una data passata in un unico campo 
***********************************************************************/
	function isDateString(dateStr) {
		var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?
		var TipoDiErrore = '';
		if (matchArray == null) {
			return false;
		}
	   day = matchArray[1]; // parse date into variables
	   month = matchArray[3]; 
	   year = matchArray[5];
		if (month < 1 || month > 12) { // check month range
			return false;
		}
		if (day < 1 || day > 31) {
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			return false;
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
				return false;
			}
		}
		return true; // date is valid
	}

	function isTime (sTime, bSeconds){
		var timePat;
		if (bSeconds == true){
			timePat = /^(\d{1,2})(\.)(\d{2})(\.)(\d{2})$/;			
		}else{
			timePat = /^(\d{1,2})(\.)(\d{2})$/;			
		}
		var matchArray = sTime.match(timePat); // is the format ok?

		if (matchArray == null) {
			return false;
		}
		var intHour, intMinute, intSecond;
		intHour = matchArray[1]; 
		intMinute = matchArray[3]; 
		if (bSeconds == true) { intSecond = matchArray[5] } else { intSecond = 00 };

		var objTempTime = new Date( 0, 0, 1, intHour, intMinute, intSecond );
		return	( ( objTempTime.getHours()   == intHour   ) &&
				  ( objTempTime.getMinutes() == intMinute ) &&
				  ( objTempTime.getSeconds() == intSecond ) ) ? true : false
	}

/**********************************************************************
   Controllo se campo passato è un anno valido compreso fra 1900 e oggi
***********************************************************************/
function isYear (s) {
		var d;
		d = new Date();
		var yyyy = d.getFullYear()
		if ((notNull(s)) && (notBlank(s)) && (isSize(s, 4)) && (!isNaN(s)) && (isInRange(s, 1900, yyyy)) ) { 
			return true; 
		} else { 
			return false;
		}
}

/*************************************************************
	Controllo del Codice Fiscale - solo a livello di sintassi
**************************************************************/
	function Trim(stringa)
	   {
	   reTrim=/\s+$|^\s+/g;
	   return stringa.replace(reTrim,"");
	   }
	function isCodFisc(cod_fisc)
	   {
	   var re = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
	   Codice=Trim(cod_fisc.toUpperCase());
		return re.test(Codice)
	   }

/*************************************************************

	varie
	
**************************************************************/


	function openPopupStd( url, dimx, dimy, sScroll) {
		dimwidth = dimx;
		dimheight = dimy;
		x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
		if (screen) {
			x = (screen.availWidth - dimwidth)/2;
			y = (screen.availHeight - dimheight)/2;
		}
		var rand_no = Math.random().toString().Replace(".", "");

		var finestra1 = window.open(url,'win_'+rand_no,'location=no,status=no,scrollbars='+sScroll+',resizable=no,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
		finestra1.focus();
	}
	   
	function confirmLink( sMessage, sUrl ) {
		//alert( sMessage+'\n'+sUrl );
		if (confirm(sMessage)) window.navigate(sUrl);
	}

	function ShowHideElement( sObjectId ) {
		var oObj = document.getElementById(sObjectId);
		if (oObj.style.display=='') { oObj.style.display='none' }
		else { oObj.style.display='' }
	}
	
	function lyChange( sId ) {
		var oNote = document.getElementById(sId);
		if (oNote.style.display=="none") { oNote.style.display='' }
		else { oNote.style.display="none" }
	}
	
	function todayDate(){
	   var d, s = "";          
	   d = new Date();
	   var giorno, mese, anno;
	   giorno = d.getDate();
	   if (giorno.toString().length <= 1) {
		giorno = '0' + giorno;
	   }  
	   mese = d.getMonth() + 1;
	   if (mese.toString().length <= 1) {
		mese = '0' + mese;
	   }  
	   anno = d.getYear();
	   
	   s += giorno + "/";                   
	   s += mese + "/";            
	   s += anno;                         
	   return(s);                               
	}
	
	function calendarOnClick(obj){
		if (notBlank(obj.value)) {
			if (!isDateString(obj.value)) {
				obj.value = todayDate();
			}
		}
	}
	
	// sostituisce , con .
	function replaceComma( obj ){
	   var r, re;                    
	   var ss = obj.value;
	   re = new RegExp(",");
	   obj.value = ss.replace(re, ".");    
	   return(obj.value);                   
	}

	// sostituisce 0 con 0.00
	function setZero( obj ){
	   var ss = Trim(obj.value);
	   if ( (isNumber(ss) && parseFloat(ss)==0) || !isNumber(ss) )  ss = "0.00" ;
	   obj.value = ss;
	   return(obj.value);                   
	}

	function isBoxChecked(obj) {
		if (obj.length != undefined ) {
			for (var i=0; i < obj.length ;i++) {
				if (obj[i].checked) return true;
			}
		} else {
			if (obj.checked) return true;
		}
	}
	
	function moveCheckedValues(obj1, obj2){
		obj2.value = '';
		if (obj1.length != undefined) {
			for (var i=0; i < obj1.length ;i++) {
				if (obj1(i).checked) obj2.value += obj1(i).value + ",";
			}
		} else {
			if (obj1.checked) obj2.value += obj1.value + ",";
		}
	}
	
	function chkUnchkAllElements( oForm, sElementType, sElementCheckAll ){
		var sElementType = sElementType;
		var sElementCheckAll = sElementCheckAll;
		if (oForm.elements.length != undefined) {
			 for(i=0; i<oForm.elements.length; i++){
				  if(oForm.elements[i].type == "checkbox" && oForm.elements[i].name == ""+sElementType+"" && oForm.elements[i].name != ""+sElementCheckAll+"")
							oForm.elements[i].checked = eval("oForm."+sElementCheckAll+".checked");
			 }
		} else {
			  if(oForm.elements.type == "checkbox" && oForm.elements.name == ""+sElementType+"" && oForm.elements.name != ""+sElementCheckAll+"")
						oForm.elements.checked = eval("oForm."+sElementCheckAll+".checked");
		}
	}
	
	 function showToolTip(current,e,text){
	  if (document.all&&document.readyState=="complete"){
	   /*
	   var X=event.offsetX;
	   var Y=event.offsetY;
	   var oPhImg = document.all.divToolTip;
	   oPhImg.innerHTML=text;
	   alert(Y +";"+ event.clientY +";"+ document.body.scrollTop);
	   oPhImg.style.pixelLeft = event.clientX - X + document.body.scrollLeft+10;
	   oPhImg.style.pixelTop = event.clientY - Y + document.body.scrollTop+10;
	   oPhImg.style.visibility="visible"
	   */
	   document.all.divToolTip.innerHTML=text
	   document.all.divToolTip.style.pixelLeft=event.clientX-event.offsetX+document.body.scrollLeft+150;
	   document.all.divToolTip.style.pixelTop=event.clientY-event.offsetY+document.body.scrollTop+30;
	   document.all.divToolTip.style.visibility="visible"
	  }
	  else if (document.layers){
	   document.divToolTip.document.nstip.document.write(text)
	   document.divToolTip.document.nstip.document.close()
	   document.divToolTip.document.nstip.left=100;
	   document.divToolTip.left=e.pageX+150;
	   document.divToolTip.top=e.pageY+30;
	   document.divToolTip.visibility="show"
	  }
	 }
	 function hideToolTip() {
	  if (document.all)
	   document.all.divToolTip.style.visibility="hidden"
	  else if (document.layers) {
	   document.divToolTip.visibility="hidden"
	  }
	 }

	function textCounter(field, countfield, maxlimit) {
		if (field.value.length > maxlimit) { // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
			// otherwise, update 'characters left' counter
		} else { 
			countfield.value = maxlimit - field.value.length;
		}
	}
	
	String.prototype.Replace = function(s1, s2){
		return this.split(s1).join(s2);
	}
	
	function replaceHtmlSpecialChars(str) {
		var sHtml = str;
		return sHtml.Replace("’","'").Replace("“","\"").Replace("”","\"").Replace("–", "-");
	}


