/*
 *GLOBALI CHECK FORM
 */
var returnXML = null;
var ElencoCampiObbligatori = new Array();
var ElencoCampiObbligatoriDes = new Array();
var ElencoCampiNumerici = new Array();
var ElencoCampiNumericiDes = new Array();
var ElencoCampiData = new Array();
var ElencoCampiDataDes = new Array();
var ElencoCampiTime = new Array();
var ElencoCampiTimeDes = new Array();
var ElencoCampiMail = new Array();
var ElencoCampiMailDes = new Array();
var controllo = "false";
var strErr;


/*
 *GLOBALE X img Javascript
 */
 var pathImg='';
 if(location.host.indexOf('72.16.')>0){
 	pathImg = '/jsp'	;
 }
  

/*
 *FINE GLOBALI
 */
//############################################################
/*
 *GLOBALI LAYER LOADING
 */
var attesa="<FONT FACE='verdana' SIZE='-1'>L o a d i n g . . .</FONT>";
var imgloading="<img src='/html/Images/process_animation.gif'  alt='Loading' border='0'>";
var colore="#FFFFFF";
/*
 *FINE GLOBALI LAYER LOADING
 */
 
 
 
/******************************************
********** Start function lOADING ******
******************************************/
function writeLayerLoading(){
	if (document.layers){
		document.write("<LAYER NAME='loading' position=absolute z-index=0 top=0 left=0 width="+window.innerWidth+" height="+window.innerHeight+" bgColor="+colore+" visibility=show'><TABLE BORDER=0 WIDTH=100% HEIGHT=100% BGCOLOR="+colore+"><TR><TD ALIGN=center VALIGN=middle>"+attesa+"<br><br>" + imgloading + "</TD></TR></TABLE></LAYER>");
	}
	else{
		document.write("<DIV ID='loading' STYLE='position:absolute;z-index:0;top:0;left:0;width:"+eval(document.all?document.body.clientWidth:window.innerWidth)+";height:"+eval(document.all?document.body.clientHeight:window.innerHeight)+";layer-background-color:"+colore+";background:"+colore+";visibility:visible'><TABLE BORDER=0 WIDTH=100% HEIGHT=100% BGCOLOR="+colore+"><TR><TD ALIGN=center VALIGN=middle>"+attesa+"<br><br>" + imgloading + "</TD></TR></TABLE></DIV>");
	}
}

function closeLayerLoading(){
	try{
		document.getElementById('loading').style.visibility = 'hidden';
	}	
	catch(e){
	}
}

function loaded(){
	if (document.layers) // NN 4
		document.layers.loading.visibility="hide";
		else if (document.getElementById) // NN6, OP e IE5+
			document.getElementById('loading').style.visibility="hidden";
			else // IE4
				document.all.loading.style.visibility="hidden";
	}

/******************************************
********** Start function checkForm ******
******************************************/

//interagisce con delle variabili globali istanziate
//in manageDb.java
function checkForm(formName, boolCheckForm){
 	if(boolCheckForm=='true'){
 		if(isFull(formName)){
			return false;
		}
		if(isEmail(formName)){
            return false;
        }
 		if(isNumeric(formName)){
			return false;
		}
 		if(isData(formName)){
			return false;
		}
 		if(isTime(formName)){
			return false;
		}
	}
	return true;
}

/*
 *Problema con gli oggetti SELECT
 * SELECT.length restituisce un numero uguale al numero di OPTION
 * quindi viene interpretata come una collectio. x questo all'interno 
 * del ciclo -->for(j=0;j<myObj.length;j++)<-- viene gestita l'eccezione
 */
function isFull(formName){
	var strErr = '';
	var skipName = '';//gestione SELECT
	var normalCycle = true;
	for (i=0; i<ElencoCampiObbligatori.length; i++){
		with(eval("document.forms['" + formName + "']")){
			if (ifExist(formName, ElencoCampiObbligatori[i])){
				//alert('ooo');
			//cerco di inserire in myObj la collection dei campi con lo stesso nome
				myObj = eval("elements." + ElencoCampiObbligatori[i]);
				//se nn è una collection 
				if(myObj.length==undefined){
					//alert(eval(ElencoCampiObbligatori[i] + ".value"));
					if ((eval(ElencoCampiObbligatori[i] + ".value == ''")) || (eval(ElencoCampiObbligatori[i] + ".value == '-1'"))){
						strErr += "\n" + ElencoCampiObbligatoriDes[i];
						changeColor(formName,ElencoCampiObbligatori[i],'ERROR','#75A1D0');
					}
					else{
						changeColor(formName,ElencoCampiObbligatori[i],'OK','');
					}
				}
				//altrimenti itero x tutti gli elementi
				else{
					//alert(myObj.length + " " + myObj.name + " " + myObj.type);
					for(j=0;j<myObj.length;j++){
						//se l'elemento è "SELECT"
						if(myObj.type == 'select-one'){
							normalCycle = false;
							oText = myObj.options[myObj.selectedIndex].value;
							//alert(oText);
						}
						else{
							normalCycle = true;
							oText = myObj[j].value;
						}
						//fine gestione SELECT
						
						if(myObj.name!=skipName || normalCycle){
							//alert(oText);
							skipName = myObj.name;
							if ((oText == '') || (oText == '-1')){
								if(strErr=='' || (strErr!='' && myObj.type == 'select-one')){
									strErr += "\n" + ElencoCampiObbligatoriDes[i];
								}
								changeColor(formName,"elements." + ElencoCampiObbligatori[i] + "[" + j + "]",'ERROR','#75A1D0');
							}
							else{
								changeColor(formName,"elements." + ElencoCampiObbligatori[i] + "[" + j + "]",'OK','');
							}
						}
					}
				}
			}
		}
	}
	if (strErr!='') {
		alert(strErrObbligatori + strErr);
		return true;
	}
	else{
		return false;
	}
}

function isNumeric(formName){
	
	var strErr = '';
	for (i=0; i<ElencoCampiNumerici.length; i++){
		with(eval("document.forms['" + formName + "']")){

			if (ifExist(formName, ElencoCampiNumerici[i])){
				//cerco di inserire in myObj la collection dei campi con lo stesso nome
				myObj = eval("elements." + ElencoCampiNumerici[i]);
				//se nn è una collection ma ho un solo campo myObj=undefined
				if(myObj.length==undefined){
					if (isNaN(eval(ElencoCampiNumerici[i]+ ".value.replace('.', ',')")) && isNaN(eval(ElencoCampiNumerici[i]+ ".value.replace(',', '.')"))){
						strErr += "\n" + ElencoCampiNumericiDes[i];
						changeColor(formName,ElencoCampiNumerici[i],'ERROR','#75A1D0');
					}
					else{
						changeColor(formName,ElencoCampiNumerici[i],'OK','');
					}	
				}
				//altrimenti itero x tutti gli elementi
				else{
					for(j=0;j<myObj.length;j++){
						if (isNaN(myObj[j].value.replace('.', ',')) && isNaN(myObj[j].value.replace(',', '.'))){
							if(strErr==''){
								strErr += "\n" + ElencoCampiNumericiDes[i];
							}
							changeColor(formName,"elements." + ElencoCampiNumerici[i] + "[" + j + "]",'ERROR','#75A1D0');
						}
						else{
							changeColor(formName,"elements." + ElencoCampiNumerici[i] + "[" + j + "]",'OK','');
						}
					}
				}
			}
		}
	} 
	if (strErr!='') {
		alert(strErrNumerici + strErr);
		return true;
	}
	else{
		return false;
	}
}

function isNumeric_old(formName){
	var strErr = '';
	for (i=0; i<ElencoCampiNumerici.length; i++){
		if (ifExist(formName, ElencoCampiNumerici[i])){
			if (isNaN(eval("document.forms['" + formName + "']." + ElencoCampiNumerici[i]+ ".value.replace('.', ',')")) && isNaN(eval("document.forms['" + formName + "']." + ElencoCampiNumerici[i]+ ".value.replace(',', '.')"))){
				strErr += "\n" + ElencoCampiNumericiDes[i];
				changeColor(formName,ElencoCampiNumerici[i],'ERROR','#75A1D0');
			}
			else{
				changeColor(formName,ElencoCampiNumerici[i],'OK','');
			}
		}
	}
	if (strErr!='') {
		alert(strErrNumerici + strErr);
		return true;
	}
	else{
		return false;
	} 
}
function isData(formName){
	var strErr = '';
	for (i=0; i<ElencoCampiData.length; i++){
		with(eval("document.forms['" + formName + "']")){
			if (ifExist(formName, ElencoCampiData[i])){
				//cerco di inserire in myObj la collection dei campi con lo stesso nome
				myObj = eval("elements." + ElencoCampiData[i]);
				//se nn è una collection ho un solo campo 
				if(myObj.length==undefined){
					if(!checkData(eval(ElencoCampiData[i]+ ".value"))){
						strErr += "\n" + ElencoCampiDataDes[i];
						changeColor(formName,ElencoCampiData[i],'ERROR','#75A1D0');
					}
					else{
						changeColor(formName,ElencoCampiData[i],'OK','');
					}
				}
				//altrimenti itero x tutti gli elementi
				else{
					for(j=0;j<myObj.length;j++){
						if(!checkData(myObj[j].value)){
							if(strErr==''){
								strErr += "\n" + ElencoCampiDataDes[i];
							}
							changeColor(formName,"elements." + ElencoCampiData[i] + "[" + j + "]",'ERROR','#75A1D0');
						}
						else{
							changeColor(formName,"elements." + ElencoCampiData[i] + "[" + j + "]",'OK','');
						}
					}
				}
			}
		}	
	}
	if (strErr!='') {
		alert(strErrData + strErr);
		return true;
	}
	else{
		return false;
	}
}

function checkData(obj){
	if (obj != ''){
		gg=obj.substr(0,2);
		mm=obj.substr(3,2);
		aa=obj.substr(6,2);
		strdata=gg+"/"+mm+"/"+aa;
		data = new Date(aa,mm-1,gg);
		daa=data.getYear().toString();
		dmm=(data.getMonth()+1).toString();
		dmm=dmm.length==1?"0"+dmm:dmm;
		dgg=data.getDate().toString();
		dgg=dgg.length==1?"0"+dgg:dgg;
		dddata=dgg+"/"+dmm+"/"+daa;
		if (dddata!=strdata){
			return false;
		}
		else{
			return true;
		}
	}
	else{
		return true;	
	}
}

function isEmail(formName) {
    var strErr = '';
    for (i=0; i<ElencoCampiMail.length; i++){
        with(eval("document.forms['" + formName + "']")){

            if (ifExist(formName, ElencoCampiMail[i])){
                //cerco di inserire in myObj la collection dei campi con lo stesso nome
                myObj = eval("elements." + ElencoCampiMail[i]);
                //se nn è una collection ma ho un solo campo myObj=undefined
                if(myObj.length==undefined){
                    mailText = eval(ElencoCampiMail[i]+ ".value");
                    if(mailText!=""){
                        if (checkMail(mailText)){
                            strErr += "\n" + ElencoCampiMailDes[i];
                            changeColor(formName,ElencoCampiMail[i],'ERROR','#75A1D0');
                        }
                        else{
                            changeColor(formName,ElencoCampiMail[i],'OK','');
                        }   
                    }
                }
                //altrimenti itero x tutti gli elementi
                else{
                    for(j=0;j<myObj.length;j++){
                        mailText = eval(myObj[j]+ ".value");
                        if(mailText!=""){
                            if (checkMail(mailText)){
                                if(strErr==''){
                                    strErr += "\n" + ElencoCampiMailDes[i];
                                }
                                changeColor(formName,"elements." + ElencoCampiMail[i] + "[" + j + "]",'ERROR','#75A1D0');
                            }
                            else{
                                changeColor(formName,"elements." + ElencoCampiMail[i] + "[" + j + "]",'OK','');
                            }
                        }
                    }
                }
            }
        }
    } 
    if (strErr!='') {
        alert(strErrMail + strErr);
        return true;
    }
    else{
        return false;
    }   
}

/*
 * controllo se la mail è valida
 */
function checkMail(obj){
    if(obj.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return false;
    else
        return true;
}


function isTime(formName){

	var strErr = '';

	for (i=0; i<ElencoCampiTime.length; i++){
		with(eval("document.forms['" + formName + "']")){
			if (ifExist(formName, ElencoCampiTime[i])){
				//cerco di inserire in myObj la collection dei campi con lo stesso nome
				myObj = eval("elements." + ElencoCampiTime[i]);
				//se nn è una collection ho un solo campo 
				if(myObj.length==undefined){
					if(!checkTime(eval(ElencoCampiTime[i]+ ".value"))){
						strErr += "\n" + ElencoCampiTimeDes[i];
						changeColor(formName,ElencoCampiTime[i],'ERROR','#75A1D0');
					}
					else{
						changeColor(formName,ElencoCampiTime[i],'OK','');
					}
				}
				//altrimenti itero x tutti gli elementi
				else{
					for(j=0;j<myObj.length;j++){
						if(!checkTime(myObj[j].value)){
							if(strErr==''){
								strErr += "\n" + ElencoCampiTimeDes[i];
							}
							changeColor(formName,"elements." + ElencoCampiTime[i] + "[" + j + "]",'ERROR','#75A1D0');
						}
						else{
							changeColor(formName,"elements." + ElencoCampiTime[i] + "[" + j + "]",'OK','');
						}
					}
				}
			}
		}	
	}
	if (strErr!='') {
		alert(strErrData + strErr);
		return true;
	}
	else{
		return false;
	}
	
}

function checkTime(obj){
	var tH='';
	var tM='';
	var test='';
	var strErr = '';
   	var boolErr = false;
	
	if (obj!=''){
		tH  = obj.substring(0,2);
		tM  = obj.substring(3,5);
		if (obj.substring(2,3)!='.' && obj.substring(2,3)!=':'){
			boolErr = true;
		}
		else{
			if (tH.length!=2){
				boolErr = true;
			}
			else{
				if (tM.length!=2){
					boolErr = true;
				}
				else{
					test = new Date();
					test.setHours(tH);
					if (tH != test.getHours()){
						boolErr = true;
					}		
					else{
						test.setMinutes(tM);
						if (tM != test.getMinutes()){
							boolErr = true;
						}
					}
				}
			}
		}
	}
	if(boolErr){
		return false;
	}
	else{
		return true;
	}	
}

function prepareCheckTime(value){
	value=value.replace(':','');
	//alert(value);
	//00:00
	if(value == "0000"){
		return 9999;
	}
	//00:05
	if(value.charAt(0)=='0' && value.charAt(1)=='0' && value.charAt(2)=='0'){
		return parseInt(value.substr(3,value.length));
	}
	//00:15
	if(value.charAt(0)=='0' && value.charAt(1)=='0'){
		return parseInt(value.substr(2,value.length));
	}
	//08:15
	if(value.charAt(0)=='0'){
		return parseInt(value.substr(1,value.length));
	}	
	//18:15
	return parseInt(value);
}

function checkTimeUpper(formName, valFrom, valTo){

	with(eval("document.forms['" + formName + "']")){
		//cerco di inserire in myObj la collection dei campi con lo stesso nome
		myObj1 = eval("elements." + valFrom);
		myObj2 = eval("elements." + valTo);
		//se nn è una collection ho un solo campo 
		if(myObj1.length==undefined){
			val1 = prepareCheckTime(myObj1.value);
			val2 = prepareCheckTime(myObj2.value);
			if(!checkUpper(val1, val2)){
				strErr += "\n" + valFrom;
				changeColor(formName,valFrom,'ERROR','#75A1D0');
			}
			else{
				changeColor(formName,valFrom,'OK','');
			}
		}
		//altrimenti itero x tutti gli elementi
		else{
			for(j=0;j<myObj.length;j++){
				val1 = prepareCheckTime(myObj1[j].value);
				val2 = prepareCheckTime(myObj2[j].value);
				if(!checkUpper(val1, val2)){
					if(strErr==''){
						strErr += "\n" + valFrom;
					}
					changeColor(formName,"elements." + valFrom + "[" + j + "]",'ERROR','#75A1D0');
				}
				else{
					changeColor(formName,"elements." + valFrom + "[" + j + "]",'OK','');
				}
			}
		}
	
	}
	if (strErr!='') {
		alert(strErrData + strErr);
		return true;
	}
	else{
		return false;
	}
}

function checkUpper(va1,val2){
		//alert(va1 +'|' + val2 + "=KO" );
	if(val1>val2){
		//alert(va1 +'|' + val2 + "=KO" );
		return false;	
	}
	else{
		//alert(va1 +'|' + val2 + "=OK" );
		return true;
	}
}

/*
 *controlla se nel form è presente l'oggetto richiesto
 */
function ifExist(formName, fieldName){
	if(eval("document.forms['" + formName + "'].elements['" + fieldName + "']")==undefined){
		return false;
	}
	else{
		return true;
	}
}

function deleteRow(QueryString){
	if (confirm(strAreYouSure)){
		return true;
	}
	else{
		return false;
	}
}
function changeColor(formName, formField, event, myColor){
	//alert("document.forms['" + formName + "']." + formField + ".style.backgroundColor='#75A1D0'");
	//window.status=formName + '-' + formField  + '-' +  event + '-' +  myColor;
	if(event=='ERROR'){
		if(myColor!=''){
			eval("document.forms['" + formName + "']." + formField + ".style.backgroundColor='" + myColor + "'");	
		}
		else{
			eval("document.forms['" + formName + "']." + formField + ".style.backgroundColor='#75A1D0'");
		}
	}
	else{
		eval("document.forms['" + formName + "']." + formField + ".style.backgroundColor='#EFEFEF'");
	}
}
/******************************************
********** End function checkform ******
******************************************/


/*
 *seleziona tutti i checkBox
 */

function all_check(formName, fieldName, boolCheck){
	
	var myEl = fieldName.split("|"); 
	for (var loop=0; loop < myEl.length; loop++) {
		try{
			var i;
			with(eval("document.forms['" + formName + "']")){
				if(eval("elements." + myEl[loop] + ".length")==undefined){
					eval(myEl[loop] + ".checked=boolCheck");
				}
				else{
					for(i=0;i<eval("elements." + myEl[loop] + ".length");i++){
						eval(myEl[loop] + "[i].checked=boolCheck");
					}
				}
			}
		}
		catch(e){
		}
	}
}
/*
 *replica il valore in tutti i campi
 */

function replyValue(formName, fieldName, fieldValue){

	try{
		with(eval("document.forms['" + formName + "']")){
			for(i=0;i<eval("elements." + fieldName + ".length");i++){
				eval(fieldName+"[i].value=" + fieldValue);
			}
		}
	}
	catch(e){
	}
}


function changeBoolCheckForm(formName){

	eval("document.forms['" + formName + "'].boolCheckForm.value = 'false'");

}

function refreshAgenda(day, month, year){
	window.opener.location.href="/jsp/Agenda/agendaHP.jsp?dayAgenda=" + day + "&monthAgenda=" + month + "&yearAgenda=" + year;
	window.close();
}


/*
inserisce il valore dal pop-up al campo della pagina
*/
function inserisci(valore, campo, nomeForm){	
	eval("window.opener.document.forms['" + nomeForm + "']." + campo + ".value='" + valore + "'");
}


/*
apre popup generico
*/

function newPopUp(newurl,newname,param) {
	apopup = window.open(newurl,newname,param);}


/* trim di una stringa */
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

if(document.all){
	var xmlResult = new ActiveXObject("Msxml2.DOMDocument");
	xmlResult.async = false;
	xmlResult.validateOnParse = false;
}
else{
	var xmlResult = document.implementation.createDocument("","",null)
}

function loadXML(httpURL,qryXMLToSend){

	var r, re;
	//re = /http:\/\//;    //Create regular expression pattern.
	re = /http/;
	try{
		if (re.test(httpURL)){			
			//TEST browser
			if(document.all){			//IE
				var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			else{						//NETSCAPE 7
										//da sviluppare
				var xmlHttp = new XMLHttpRequest();
				
				//httpURL = httpURL.replace("https://dc.dolomitisuperski.com"," ").trim();
				//alert(httpURL);
				netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
			}
			
            try{
    			xmlHttp.Open("POST", httpURL, false, "", "");
    			//alert(qryXMLToSend);
			}
            catch(e){
            	
				message  =	"Unable to reach the site: " + httpURL + "\n\nErrMsg: " + e.description 
                alert(message);
                return;
            }
    		xmlHttp.Send(qryXMLToSend);
			
			if (!xmlHttp.responseXML.documentElement){
				//Some servers don't send the contenttype correctly, and even
				//though they send back good XML, the xmlHttp object fails to parse it
				//especially where the URL doesn't end in .xml
				//Serializing the XML isn't the best approach, but it works in those cases.
				//one must be careful of encoding in this case.
				xmlResult.loadXML(xmlHttp.responseText);
				alert(xmlHttp.responseText);
			}
			else{
				xmlResult.load(xmlHttp.responseXML);
			}	
		}
		else{			
			xmlResult.load(httpURL);
		}
	
		if (!xmlResult.documentElement){			
			throw httpURL + " failed to load!"
		}
	}
	catch (e){
		alert("Error: " + e);
		//hin.innerText = "error: " + e	; 
		return;
	}
	if (xmlResult.documentElement && xmlResult.documentElement){
		return xmlResult;
//		alert(xmlResult);
	}
}


function fillPercRefund(URL,Id_Period){
	if(ifExist("form_1", "ID_TICKETPERSONTYPEDEF")){
		var httpURL = location.protocol + '//' + location.host + URL;
		//costruisco la QRY in XML
		var qryXMLToSend = "<?xml version=\"1.0\"?><root><QRY IDPERIOD=\"" + Id_Period + "\"/></root>";
		//returnXML -->GLOBALE
		returnXML = loadXML(httpURL,qryXMLToSend);
		
		with(eval("document.forms['form_1']")){
			if(elements.ID_TICKETPERSONTYPEDEF.length==undefined){//un solo elemento
				newValue = catchValue(ID_TICKETPERSONTYPEDEF.value);
				if(newValue != PERCREFUND.value){
					temp = changedElement.value + '|';
					//se nn ho gia' memorizzato l'elemento
					if(temp.indexOf("|0|")==-1)
						changedElement.value += '|0';
					
					PERCREFUND.value = newValue;
				}
			}
			else{
				for(i=0;i<elements.ID_TICKETPERSONTYPEDEF.length;i++){
					newValue = catchValue(ID_TICKETPERSONTYPEDEF[i].value);
					if(newValue != PERCREFUND[i].value){
						temp = changedElement.value + '|';
						//se nn ho gia' memorizzato l'elemento
						if(temp.indexOf("|" + i + "|")==-1)
							changedElement.value += '|' + i;
						
						PERCREFUND[i].value = newValue;
					}
				}
			}
		}
	}
}


function fromValleyBuildCompany(httpURL,formName,Id_Valley, Id_Operator){
	if(ifExist(formName, "ID_COMPANY")){
		//costruisco la QRY in XML
		var qryXMLToSend = "<?xml version=\"1.0\"?><root><QRY IDVALLEY=\"" + Id_Valley + "\" IDOPERATOR=\"" + Id_Operator + "\"/></root>";
	//	alert(qryXMLToSend);
		//returnXML -->GLOBALE
		returnXML = loadXML(httpURL,qryXMLToSend);
		//alert(returnXML.xml);
		with(eval("document.forms['" + formName + "'].ID_COMPANY")){
			while (options.length >0)
				options[0]=null;
				
			var oNodeList = returnXML.selectNodes("//COMPANY");//qry 
			options[0]=new Option('---','-1');
			options.selectedIndex=0;
			for(var i=0; i<oNodeList.length; i++){
				oNodeIdCompany 	= oNodeList[i].getAttribute("ID");
				oNodeCompany 	= oNodeList[i].text;
				options[i+1]=new Option(oNodeCompany,oNodeIdCompany);//costruisco una nuova option
			}
		}
	}
}

function fromValleyBuildLift(httpURL,formName,Id_Valley, Id_Operator){
	if(ifExist(formName, "ID_LIFT")){
		//costruisco la QRY in XML
		var qryXMLToSend = "<?xml version=\"1.0\"?><root><QRY IDVALLEY=\"" + Id_Valley + "\" IDOPERATOR=\"" + Id_Operator + "\"/></root>";
		//alert(qryXMLToSend);
		//returnXML -->GLOBALE
		returnXML = loadXML(httpURL,qryXMLToSend);
		//alert(returnXML.xml);
		with(eval("document.forms['" + formName + "'].ID_LIFT")){
			while (options.length >0)
				options[0]=null;
				
			var oNodeList = returnXML.selectNodes("//LIFT");//qry 
			options[0]=new Option('---','-1');
			options.selectedIndex=0;
			for(var i=0; i<oNodeList.length; i++){
				oNodeId 	= oNodeList[i].getAttribute("ID");
				oNodeText 	= oNodeList[i].text;
				options[i+1]=new Option(oNodeText,oNodeId);//costruisco una nuova option
			}
		}
	}
}


function reloadDataBySeason(httpURL,formName,Id_Season,Id_Operator){
	writeLayerLoading();
	var sLink = document.location.href.substring(0,document.location.href.indexOf('?'));
	sLink += "?ID_SEASON=" + Id_Season;
	document.location.href = sLink;
}


function fromEntityBuildTicketType(URL,formName,Id_Entity, Id_Operator){
	if(ifExist(formName, "ID_TICKETTYPE") && Id_Entity!= "-1"){
		var httpURL = location.protocol + '//' + location.host + URL;
		//costruisco la QRY in XML
		var qryXMLToSend = "<?xml version=\"1.0\"?><root><QRY IDENTITY=\"" + Id_Entity + "\" IDOPERATOR=\"" + Id_Operator + "\"/></root>";
		//alert(qryXMLToSend);
		//returnXML -->GLOBALE
		returnXML = loadXML(httpURL,qryXMLToSend);
		//alert(returnXML.xml);
		with(eval("document.forms['" + formName + "'].ID_TICKETTYPE")){
			while (options.length >0)
				options[0]=null;
				
			var oNodeList = returnXML.selectNodes("//TICKETTYPE");//qry 
			if(oNodeList.length==0){
				options[0]=new Option('---','-1');	
			}
			else{
				for(var i=0; i<oNodeList.length; i++){
					oNodeId 	= oNodeList[i].getAttribute("ID");
					oNodeNotAss	= oNodeList[i].getAttribute("NOTASS");
					oNodeText 	= oNodeList[i].text;
					options[i]=new Option('[' + oNodeNotAss + '] - ' + oNodeText,oNodeId);//costruisco una nuova option
				}
			}
			var oNode = returnXML.selectSingleNode("//NOTASSIGNED");
			document.getElementById('666').innerHTML = oNode.getAttribute("NUMERO");
			//alert(oNode.getAttribute("NUMERO"));
		}
	}
}


function catchValue(id){
	var oNode = returnXML.selectNodes("//PERIOD[@ID='" + id + "']");//qry sugli attributi
	if(oNode[0]!=null){
		return oNode[0].text;
	}
	else{
		return "";
	}
}


function getPeriod(URL,formName,IdSeason, Id_Operator){
	if(ifExist(formName, "IDPERIOD")){
		var httpURL = location.protocol + '//' + location.host + URL;
		//costruisco la QRY in XML
		var qryXMLToSend = "<?xml version=\"1.0\"?><root><QRY IDSEASON=\"" + IdSeason + "\" IDOPERATOR=\"" + Id_Operator + "\"/></root>";
		//alert(qryXMLToSend);
		//returnXML -->GLOBALE
		returnXML = loadXML(httpURL,qryXMLToSend);
		//alert(returnXML.xml);
		with(eval("document.forms['" + formName + "'].IDPERIOD")){
			while (options.length >0)
				options[0]=null;
				
			var oNodeList = returnXML.selectNodes("//PERIOD");//qry 
			options[0]=new Option('---','-1');
			options.selectedIndex=0;
			for(var i=0; i<oNodeList.length; i++){
				oNodeId 	= oNodeList[i].getAttribute("ID");
				oNodeText 	= oNodeList[i].text;
				options[i+1]=new Option(oNodeText,oNodeId);//costruisco una nuova option
			}
		}
	}
}

function openUpload(campo,formName){
	//alert(formName);
	var sLink = "popUpUploadGen.jsp?campo=" + campo + "&formName=" + formName;
	newPopUp(sLink ,'popUpUpload','toolbar=no,  location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=510,height=420');

}


function showCalendarDa(dataDa){
	//alert(dataDa);
	displayCalendar(document.forms['fl'].dataDa,'dd-mm-yyyy',document.forms['fl'].dataDa);
	
	//alert(iframeObj);
	calendarDiv.style.left = '244px';
	calendarDiv.style.top = '432px';
	
	if(iframeObj){
		iframeObj.style.left = calendarDiv.style.left;
		iframeObj.style.top =  calendarDiv.style.top;
		//// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2.style.left = calendarDiv.style.left;
		iframeObj2.style.top =  calendarDiv.style.top;
	}
}

function showCalendarA(dataA){
	
	displayCalendar(document.forms['fl'].dataA,'dd-mm-yyyy',document.forms['fl'].dataA);
	
	//alert(iframeObj);
	calendarDiv.style.left = '244px';
	calendarDiv.style.top = '460px';
	
	if(iframeObj){
		iframeObj.style.left = calendarDiv.style.left;
		iframeObj.style.top =  calendarDiv.style.top;
		//// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2.style.left = calendarDiv.style.left;
		iframeObj2.style.top =  calendarDiv.style.top;
	}
}

function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }


function setFlashDateDa(dataDa){
	thisMovie("mappa").setDataDa(dataDa);
	
}

function setFlashDateA(dataA){
	thisMovie("mappa").setDataA(dataA);
}





