function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}
 
                                   
    
										   
 function ChangeRequiredField(obj,NewRequired){
				var ParamName = obj.name.split("[")
				var name  = ParamName [0]
				var ParamName1=ParamName[1].split("]")
				var SubParamName1=ParamName1[0].split(",")
				
				var Type=SubParamName1[0]
				var Required=SubParamName1[1]
				var DescField=SubParamName1[2]
                
				var FieldStyle=document.getElementById("FieldStyle_"+name)
				if (!FieldStyle){
					  obj.style.backgroundColor =''
              		  obj.style.border='';	
											  
				}
				obj.removeAttribute("readonly")
				obj.removeAttribute("tabindex")
					if (obj.readonly){
						obj.readonly=false
					}				
				
				if (NewRequired=="D"){
					obj.name=name + "["+ Type+",F,"+DescField
					obj.value=""
					obj.disabled=true
					if (FieldStyle){
						FieldStyle.className="CampoDis"
					}
					else
					{
						obj.className="CampoDis"
						obj.disabled=true
						obj.style.backgroundColor ='#FFFFFF'
						obj.style.border='1px solid #C9C9C2'; 						
					}
				}
				else if (NewRequired=="F"){
					obj.name=name + "["+ Type+","+NewRequired+","+DescField
 					obj.disabled=false
					if (FieldStyle){
						//FieldStyle.className="CampoFac"
					}
					else{
						obj.className="CampoFac"
						obj.style.backgroundColor ='#FFFFFF'
						obj.style.border='1px solid #009900'; 															
					}
				}
				else if(NewRequired=="N"){	
					obj.name=name + "["+ Type+","+NewRequired+","+DescField
 					obj.disabled=false		
					if (FieldStyle){										
						FieldStyle.className=obj.className
						FieldStyle.className="CampoNec"											
					}else{
						obj.className="CampoNec"
						obj.style.backgroundColor ='#FFFFFF'
						obj.style.border='1px solid #FF0000';  						
					}
				}
				else if(NewRequired=="A"){	
					obj.name=name + "["+ Type+","+NewRequired+","+DescField
 					obj.disabled=false		
					obj.setAttribute('readOnly','true');
					alert(obj.readonly)
					if (obj.readonly){
						obj.readonly=true
					}
				    obj.setAttribute("tabindex",-1)	
					obj.tabIndex=-1
					if (FieldStyle){										
						FieldStyle.className=obj.className
						FieldStyle.className="CampoAut"											
					}else{
						obj.className="CampoAut"
						obj.style.backgroundColor ='#FFFFFF'
						obj.style.border='1px solid #FFCC00';  						
					}	
					alert(obj.readonly)
				}

				for (var k=3;k<SubParamName1.length;k++){
					obj.name=obj.name+','+SubParamName1[k]
				}
				obj.name=obj.name + "]"		
				if (obj.tagName=="SELECT"){
					var o=obj
					while(o.parentElement !=null) {   // Parse the parent hierarchy up to the document element
							oParent = o.parentElement  // Get parent object reference
								if ((oParent.tagName=="TD") && (obj.className)){
									oParent.className=obj.className
									break;
								}								 
								o = oParent	
					}						
				}
		}
		
		
		 function ChangeTypeField(obj,NewType){
				var ParamName = obj.name.split("[")
				var name  = ParamName [0]
				var ParamName1=ParamName[1].split("]")
				var SubParamName1=ParamName1[0].split(",")
                
				obj.name=name + "["+ NewType

				
				for (var k=1;k<SubParamName1.length;k++){
					obj.name=obj.name+','+SubParamName1[k]
				}
				obj.name=obj.name + "]"		
				if (obj.tagName=="SELECT"){
					var o=obj
					while(o.parentElement !=null) {   // Parse the parent hierarchy up to the document element
							oParent = o.parentElement  // Get parent object reference
								if ((oParent.tagName=="TD") && (obj.className)){
									oParent.className=obj.className
									break;
								}								 
								o = oParent	
					}						
				}
		}
		
		function DisplayRowField(obj,ShowField){
				var o=obj
				while(o.parentElement !=null) {   // Parse the parent hierarchy up to the document element
						oParent = o.parentElement  // Get parent object reference
							if ((oParent.id=="ROW_FIELD")){
								 if (ShowField=="N"){
									oParent.style.display="none"
								 }
								 else{
									oParent.style.display="block"
								 }	
								 break;
							}								 
							o = oParent	
				}		
		}
		
	    function DisplayHiddenField(obj,HField){
				if (obj.name){
					var ParamName = obj.name.split("[")
					//alert("obj.name"+obj.name+" ParamName.length"+ParamName.length)
					if 	(ParamName.length > 1){							 
						var name  = ParamName [0]
						var ParamName1=ParamName[1].split("]")
						var SubParamName1=ParamName1[0].split(",")
						
						var Type=SubParamName1[0]
						var Required=SubParamName1[1]
						var DescField=SubParamName1[2]
						
						obj.name=name + "["+ Type+","+Required+","+DescField+","+HField
					}
				}
				var o=obj
				while(o.parentElement !=null) {   // Parse the parent hierarchy up to the document element
						oParent = o.parentElement  // Get parent object reference
						if ((oParent.id=="ROW_FIELD")){
							 if (HField=="S"){
								oParent.style.display="none"
							 }
							 else{
								oParent.style.display="block"
							 }	
							 
							break;
						}
						o = oParent	
				}	
				if (obj.name){
					if 	(ParamName.length > 1){	
						for (var k=4;k<SubParamName1.length;k++){
							obj.name=obj.name+","+SubParamName1[k]
						}	
						obj.name=obj.name+"]"	
					}
				}
		}
		
// Author: JS-Examples - http://www.js-examples.com
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
var isIE = document.all?true:false;
var isNS = document.layers?true:false;
function onlyDigits(e) {
	var _ret = true;
	var  decSeparator="."
	alert("enter")
	if (isIE) {
	if ((window.event.keyCode < 48 || window.event.keyCode > 57) && window.event.keyCode != decSeparator.charCodeAt(0)) {
		window.event.keyCode = 0;
		_ret = false;
	}
	}
	if (isNS) {
		if (e.which < 48 || e.which > 57) {
		e.which = 0;
		_ret = false;
		}
	}
	return (_ret); 
}

function onlyDigitsInt(e) {
	var _ret = true;
	var thisKey
		if (e && e.which) { //NS
		thisKey = e.which;
		}
		else if(window.event && window.event.keyCode) { //IE
		thisKey=window.event.keyCode;
		}
	if ((thisKey < 48 || thisKey > 57)) {
		try{
		window.event.keyCode = 0;
		}
		catch(e){
		}				
		_ret = false;
	}

	return (_ret); 
}

function onlyDigitsInt2(f) {
		var re = /^[0-9]*$/;
		if (!re.test(f.value)) {
			f.value = f.value.replace(/[^0-9]/g,"");
		}
}

function onlyDigitsDate(e) {
	var _ret = true;
	var  Barra="/";
	
	if (isIE) {
		//alert(window.event.keyCode+ "-"+Barra.charCodeAt(0) )
	if ((window.event.keyCode < 48 || window.event.keyCode > 57) && window.event.keyCode != Barra.charCodeAt(0)) {
		window.event.keyCode = 0;
		_ret = false;
	}
	}
	if (isNS) {
		if (e.which < 48 || e.which > 57) {
		e.which = 0;
		_ret = false;
		}
	}
	return (_ret); 
}
function onlyDigitsDate2(f) {
		var re = /^[0-9]*$^[\/]*$/;
		if (!re.test(f.value)) {
			f.value = f.value.replace(/[^0-9]/g,"");
		}
}
function ReplaceSep(Valore){
	var  decSeparator=FindSep();
	var SepatorToReplace=""
	if (decSeparator=="."){
		Valore=Valore.replace(/[^\d\.]+/g, '')
	}
	else{
		Valore=Valore.replace(/[^\d\,]+/g, '')
	}
	Valore=parseFloat(Valore)
	if (isNaN(Valore)){
		return ""
	}
	return Valore
}


function resizeIframe(currentfr){
	if (currentfr && !window.opera){
		currentfr.style.display="block"
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
				currentfr.height = currentfr.Document.body.scrollHeight;
	}
}

function Help(ID){
		//Open a modal window with an iframe page inside, and assign the result to a global variable called "emailwindow"
		    HelpWindow=dhtmlmodal.open('WinHelp', 'iframe', 'help.asp?ID='+ID, 'Help', 'width=-1,height=-1,center=1,resize=1,scrolling=1')				
}
function ShowSaldiVis(idSes){
		//Open a modal window with an iframe page inside, and assign the result to a global variable called "emailwindow"
		    SaldiWindow=dhtmlmodal.open('WinSaldi', 'iframe', 'utenti_visure_saldi.asp?idSes='+idSes, 'Saldi visure', 'width=450,height=250,center=1,resize=1,scrolling=1')				
}


function showMainWin(Page){
		var mainWinHV
		mainWinHV=window.open(Page, 'mainWinHV', 'toolbar=0,status=1,menubar=0,fullscreen=no,resizable=1,maximize=1');		
		if (!mainWinHV){
			alert("Attenzione è necessario disattivare il blocco popup!!")
			return mainWinHV
		}		
		return mainWinHV
}

function ResizeFullScreen(win){
		if (win){
			win.window.moveTo(0,0);			
			if (document.all) 
			{
			  win.window.resizeTo(screen.availWidth,screen.availHeight);
			}
			else if (document.layers||document.getElementById) 
			{
			  if (win.window.outerHeight<screen.availHeight||win.window.outerWidth<screen.availWidth)
			  {
				win.window.outerHeight = screen.availHeight;
				win.window.outerWidth = screen.availWidth;
			  }
			}
		}
}
function ResizeWin(win,w,h){
		if (document.all) 
		{
		  win.window.resizeTo(w,h);
		}
		else if (document.layers||document.getElementById) 
		{ 
			win.window.outerHeight = w;
			win.window.outerWidth = h;
		}
}

function LoginUser(){	
	var win =showMainWin('')
	win.focus()
	if (win){
		ResizeWin(win,500,500)
		document.getElementById('fmLogin').submit();
		document.location.href='default.asp'
		win.focus()
	}	
}

function logout_mainWin(){	
	var WinLogout
	WinLogout=window.open('logout.asp', 'WinLogout', 'toolbar=0,status=1,menubar=0,fullscreen=no,resizable=1,maximize=1');		
	ResizeWin(WinLogout)
		
	var win =showMainWin('')
	if (win){
		ResizeWin(win,400,300)
		//document.getElementById('fmLogin').submit();
		//document.location.href='default.asp'
	}	
}


function FormatJsNumber(num,decimalNum,decimalSep,MiglaiaSep)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseFloat(num))) return "NaN";

	var tmpNum = parseFloat(num).toFixed(decimalNum);
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	/*tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	*/
	var tmpNumStr = new String(tmpNum);
	//alert(tmpNumStr)
	var tmpInt=parseInt(tmpNum)
	var tmpDecimalStr=tmpNumStr.substring(tmpNumStr.indexOf(".")+1,tmpNumStr.length)
	
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpIntStr = new String(tmpInt);
	if ((tmpInt >= 1000 || tmpInt <= -1000)&&(MiglaiaSep!='')) {
		var iStart = tmpIntStr.length;
		if (iStart < 0)
			iStart = tmpIntStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpIntStr = tmpIntStr.substring(0,iStart) + MiglaiaSep + tmpIntStr.substring(iStart,tmpIntStr.length)
			iStart -= 3;
		}		
	}
	var tmpNumStr=''
	if (decimalSep!=''){
		tmpNumStr=tmpIntStr+decimalSep+tmpDecimalStr
	}
	return tmpNumStr;		// Return our formatted string!
}