var rootpath = "http://www.entecarifirenze.it/";

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function SelectPage(base,indice)
{
	if (window.confirm('La pagina selezionata verrà aperta in un\'altra finestra \nchiudere la finestra corrente?\n\nCliccando sul pulsante ANNULLA la finestra rimarrà aperta.'))
	{
		self.close();
	}
	if (indice != "") 
	{
		window.opener.location=base + '&Item=' + indice;
		window.opener.focus();
	}else{
		window.opener.location=base;
		window.opener.focus();
	}	
}


function loadImages() {
if (document.getElementById) {  // DOM3 = IE5, NS6
	document.getElementById('hidepage').style.visibility = 'hidden';
}
else {
	if (document.layers) {  // Netscape 4
		document.hidepage.visibility = 'hidden';
	}
else {  // IE 4
	document.all.hidepage.style.visibility = 'hidden';
      }
   }
}


function CheckChange(target)
{
if (confirm('Hai scelto di cambiare sezione,\nClicca su OK per trasferirti su un altra pagina.\nClicca su Annulla per proseguire l\'elaborazione della pagina attualmente visualizzata.\n\nPer poter presentare il seguente progetto è necessario compilare tutti i campi obbligatori (contraddistinti dal doppio asterisco) presenti in ogni singola pagina/sezione e salvarli tramite l\'apposito pulsante denominato \'Salva\''))
	{
	//if (ControllaCampi()==1)
	//	{
	//	alert(target);
		//document.frmMainForm.submit();
		self.location = target + '.asp'
	//	}
	}
else 
	{
	//self.location = target + '.asp'
	}
}

function inizia_ricerca()
{
var testo;
testo=document.all.cerca.value;
if (testo != "" && testo.length >= 3) 
	{
	var open = NewWindow('cerca.asp?testo=' + testo, 'cerca', 700, 400, 'yes');
	}else{
	window.alert('ATTENZIONE, per effettuare una ricerca è necessario inserire una o più chiavi di ricerca \ncomposte da almeno 5 caratteri');
	}
	return;
}




var message="";

function clickIE() 
{
	if (document.all) 
	{
		(message);
		return false;
	}
}

function clickNS(e) 
{
	if (document.layers||(document.getElementById&&!document.all))
	{
		if (e.which==2||e.which==3) 
		{
			(message);
			return false;
		}
	}
}

if (document.layers)
{
	//document.captureEvents(Event.MOUSEDOWN);
	//document.onmousedown=clickNS;
}

else
{
	//document.onmouseup=clickNS;
	//document.oncontextmenu=clickIE;
}




function openSettori(valore){
	var myname='settori'
	var mypage = 'settori.asp?stringaVal=' + valore
	var winl = (screen.width - 700) / 2;
	var wint = (screen.height - 500 ) / 2 ;
	winprops = 'height='+500+',width='+700+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) 
	{ 
		win.window.focus();
	}	
}



function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function StampaForm() 
{
	var ua;
	var msie;
	var theVer;
	ua = new String();
	ua = window.navigator.userAgent;
	msie = ua.indexOf ("MSIE");
	if (msie > 0){
		theVer = ua.substring (msie+5, ua.indexOf(".", msie));
	}else{
		theVer = "5";
	}
	if (theVer < 5) 
	{
		StampaForm4x()
	}else{
		window.print();		
	}
}

function StampaForm4x() 
{
	document.body.insertAdjacentHTML("beforeEnd","<object id=\"idWBPrint\" width=0 height=0 \classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\"></object>");
	idWBPrint.ExecWB(6, 1);
	idWBPrint.outerHTML ="";
}


function MaxiLung(textInput,MaxInt) 
	{
//		alert('maxilung - ' + textInput + '--' + MaxInt);
		
		var strAppoggio = new String();
		strAppoggio=textInput.value
		//strAppoggio=textInput;
		//alert(strAppoggio.length);
		if (strAppoggio.length > MaxInt+1){
			textInput.value=strAppoggio.substring(0,MaxInt);
			alert('Attenzione, il campo appena elaborato contiene un numero eccessivo di caratteri [' + strAppoggio.length + '].\nVerrà adeguato al numero massimo di caratteri consentito [' + MaxInt + ']')
			}
	}



function onLonger(objParam, intParam, nomeParam)
{
	var strPriv;
	
	strPriv = new String();
	strPriv = objParam.value;
	if (strPriv.length>intParam)
	{
		alert("Limitare il campo " + nomeParam + " ad un massimo di " + intParam + " caratteri.");
		objParam.focus();
		return 0;
	}
	else
	{
		return 1;
	}
}
//===============================================================================================
function onErrDigit(objParam)
{
	var strPriv; 
	
	strPriv = new String();
	strPriv = objParam.value;
	if (strPriv.length>0)
	{
		if (SoloNumeri(strPriv)>0)
		{
			alert("Esprimere il campo utilizzando solamente mumeri (0..9)");
			objParam.focus();
			return 0;
		}
		else
		{
			return 1;
		}
	}
	else
	{
		return 1;
	}
}
//===============================================================================================
function SoloNumeri(strX)
{
	var	blnRet;
	var intX;
	
	blnRet = 0;
	for (var i = 0; i < strX.length; i++)
	{
		if (isNaN(parseInt(strX.substr(i,1))) && (strX.charAt(i)!='.'))
			blnRet += 1;
	}
	return blnRet;
}
//===============================================================================================
function goOnBlur(objX)
{
	sepSI(objX);
}
//===============================================================================================
//********************************************************************************************************
function gOF(objX) {
	sepNO(objX, true);
}

//********************************************************************************************************
function gOB(objX, blnComma) {
	sepSI(objX, false);
}

//********************************************************************************************************
function sepNO(objX, boolM) {
	var i;
	var strX;
	var strD;
	
	strD = new String();
	strX = new String();
	strX = objX.value;
	
	for (i=0; i<strX.length; i++)
		if (strX.charAt(i) != '.')
			strD += strX.charAt(i);
	
	if (boolM == true)
	{
		objX.value = strD;
		objX.select();
	}
	else
	{
		return strD;
	}
}	

function sepSI(objX, blnComma) {
	if (blnComma != true && blnComma != false) blnComma = true;
	var i;
	var strX;
	var strD;
	var j;
	var strDec;
	
	strDec = new String();
	strD = new String();
	strX = new String();
	strX = objX.value;

	if (strX.length > 0)
	{
		if (strX.charAt(0) == ',') strX = '0' + strX;
		if (strX.charAt(strX.length-1) == ',') strX = strX + '00';
		
		j = strX.lastIndexOf(',')
		if (j != -1)
		{	
			strDec = strX.substr(j, strX.length -j);
			if (strDec.length < 3) strDec = strDec + '0';
			strX = strX.substr(0, j);
		}
		else
		{	
			strDec = ',00';
		}
		
		j = 1;
		for (i=strX.length-1; i>=0; i--)
		{
			//if (strX.charAt(i)!='.')
			if (!(isNaN(strX.charAt(i))))
			{
				strD += strX.charAt(i);
				if (j==3 && i!=0)
				{
					strD += '.';
					j = 0;
				}
				j ++;
			}
		}
		strX = '';
		for (i=strD.length-1; i>=0; i--)
			strX += strD.charAt(i);
		
		if (parseInt(strX) == 0) strX = '0'
		if (parseInt(strDec.substr(1, strDec.length-1)) == 0) strDec = ',00'
		if (blnComma)
			if ((strX + strDec) != "0,00")
				objX.value = strX + strDec
			else
				objX.value = "";
		else
			if (strX != "0")
				objX.value = strX
			else
				objX.value = "";
	}
}

//********************************************************************************************************//===============================================================================================
function goOnFocus(objX)
{
	sepNO(objX, true);
}
//===============================================================================================
//===============================================================================================

//===============================================================================================
function DataValida(strX) {
	var aAppo = new Array();
	var dAppo = new Date();	
	var blnRet
	var intD;
	var intM;
	var intY;
	
	blnRet = true;
	aAppo=strX.split("/");
	
	if (aAppo.length !=3)
	{
		blnRet =  false;
	}
	else
	{
	//alert(aAppo[2].valueOf());
		if (aAppo[2].valueOf()<70)
			aAppo[2]="20" + aAppo[2];
			
		strX=aAppo[1] + "/" + aAppo[0] + "/" +aAppo[2];
		//alert(Date.parse(strX));
		if (Date.parse(strX) <-2208992400000 || isNaN(Date.parse(strX)))
		//if (isNaN(Date.parse(strX)))
		{
		//	alert(Date.parse(strX));
			blnRet =  false;
		}
		else
		{
			if (aAppo[0].valueOf()>31)
			{
				blnRet = false;
				return blnRet;
			}
			if (aAppo[1].valueOf()>12)
			{
				blnRet = false;
				return blnRet;
			}
			intD = aAppo[0].valueOf();
			intM = aAppo[1].valueOf();
			intY = aAppo[2].valueOf();
			
			if (intM==4 || intM==6 || intM==9 || intM==11)
			{
				if (intD>30)
				{
					blnRet = false;
					return blnRet;
				}
			}
			if (intM==2)
			{
				if ((intY%4)==0)
				{
					if (intD>29)
					{
						blnRet = false;
						return blnRet;
					}
				}
				else
				{
					if (intD>28)
					{
						blnRet = false;
						return blnRet;
					}
				}
			}
		}
	}	
	return blnRet;
}


function ResetForm() 
{
	if (confirm('Confermi la cancellazione dei dati all\'interno del modulo corrente?')==true)
		document.frmMainForm.reset();
}


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=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function presenta(id_domanda) 
{
	NewWindow('presenta.asp?id_domanda='+id_domanda,'presenta','450','170','no');
	return;
}

function stampa_cart(id_domanda) 
{
	NewWindow('stampa_cart.asp?id_domanda='+id_domanda,'cart','550','500','yes');
	return;
}


function checkKey() 
{
	var theKey = window.event.keyCode;
	var strUP;
	if (theKey == 8) 
	{
		if (document.frmMainForm || null) 
		{
			for (i=0; i<document.frmMainForm.length;i++)
			{
				strUP = new String();
				strUP = document.frmMainForm.elements[i].name;
				if (document.activeElement.name == strUP){
					//window.alert('ciao ciccio');
				return true;
				break;
				}
			}
		}
		return false;
	}
}


function notice(){
menutext.style.left=document.body.scrollLeft+event.clientX
menutext.style.top=document.body.scrollTop+event.clientY
menutext.style.visibility="visible"
return false }
function hidenotice(){
menutext.style.visibility="hidden"
 } 
 
var highlightcolor="lightyellow"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function OpenLink(mypage) {
		if (mypage.indexOf(".xxx") > 0){
			var w = 402;
			var h = 241;
			var winl = (screen.width - w) / 2;
			var wint = (screen.height - h + 60) / 2 ;
			winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=no'
			//alert(rootpath + 'decripta.asp?nf=' + URLEncode(mypage), 'link', winprops);
			win = window.open(rootpath + 'decripta.asp?nf=' + URLEncode(mypage), 'link', winprops);
		} else {
			var w = 750;
			var h = 500;
			var winl = (screen.width - w) / 2;
			var wint = (screen.height - h + 60) / 2 ;
			winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes'
			window.open(mypage, 'link', winprops);
		}
		//if (parseInt(navigator.appVersion) >= 4) {
		//	win.window.focus();
		//}
	}
	
