function getURLParameters(arrParamNames, arrParamValues) 
{
	var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		//var arrParamNames = new Array(arrURLParams.length);
		//var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		
		/*
		for (i=0;i<arrURLParams.length;i++)
		{
			alert(arrParamNames[i]+" = "+ arrParamValues[i]);
		}
		*/
	}
	else
	{
	    //Nessun parametro...
		//alert("No parameters.");
	}
}

function ChangeIframeSrc(theUrl, theTitle, showDivPretext){
	        var obj;
            obj = document.getElementById("FrameContentPage");
	        if (obj != null)
	            obj.src = theUrl;
	        
	        var TDTit;
	        TDTit = document.getElementById("TDTitle")
	        if (TDTit != null)
	            TDTit.innerText = theTitle;
	            
	        var DivPreTxt;
	        DivPreTxt = document.getElementById("preText")
	        if (DivPreTxt != null)
	            DivPreTxt.style.display = showDivPretext ? "inline" : "none";	            
	    }
	    

function ChangeIframeSrcID(theID){
    var theUrl, theTitle, thePreTextVisible;
    switch (theID)
    {
        //case "pp": {theUrl="Default.aspx"; theTitle="Prenota il tuo parcheggio"; thePreTextVisible="inline";break}
        case "cf": {theUrl="ComeFunziona.htm"; theTitle="Come funziona"; thePreTextVisible="none";break}
        case "mp": {theUrl="ModalitaPagamento.htm"; theTitle="Modalità di pagamento"; thePreTextVisible="none";break}
        case "vm":
            {
                popupWindow('VisualizzaMappa.htm', 'Visualizza mappa', false);
                theTitle = 'Visualizza la mappa';
                thePreTextVisible = 'none';
                return;
                break
                /* theUrl = 'VisualizzaMappa.htm'; theTitle = 'Visualizza la mappa'; thePreTextVisible = 'none'; break */
            }
        case "cu": {theUrl="CondizioniGenerali.htm"; theTitle="Condizioni generali di utilizzo"; thePreTextVisible="none";break}
        case "am": {theUrl="AccumulaMiglia.htm"; theTitle="Accumula miglia con il parcheggio"; thePreTextVisible="none";break}
        default: {theUrl="Default.aspx"; theTitle="Prenota il tuo parcheggio"; thePreTextVisible="inline";break}
    }

    var obj;
    obj = document.getElementById("FrameContentPage");
    if (obj != null)
        obj.src = theUrl;
    
    var TDTit;
    TDTit = document.getElementById("TDTitle")
    if (TDTit != null)
        TDTit.innerText = theTitle;
        
    var DivPreTxt;
    DivPreTxt = document.getElementById("preText")
    if (DivPreTxt != null)
        DivPreTxt.style.display = thePreTextVisible;	            
}

function SetIframe(){
		var arrParamNames = new Array();
		var arrParamValues = new Array();

        ChangeIframeSrcID("pp"); //Di default carico SEMPRE la pagina di prenotazione parcheggi

        getURLParameters (arrParamNames, arrParamValues);
	    for (i=0;i<arrParamNames.length;i++)
		{
		    if (arrParamNames[i]=="pg")
		    {
		        //Devo caricare una pagina specifica nell'iFrame
		        ChangeIframeSrcID (arrParamValues[i]);
		    }
		    else if (arrParamNames[i]=="eel")
		    {
	            if (document.getElementById("FrameContentPage")  != null)
	            {
	                document.getElementById("FrameContentPage").src += ("?eel=" + arrParamValues[i]);
	            }
	                
		    }
		    else if (arrParamNames[i]=="PrId")
		    {
	            if (document.getElementById("FrameContentPage")  != null)
	            {
	                document.getElementById("FrameContentPage").src += ("?PrId=" + urlencode(arrParamValues[i]));
	            }
	                
		    }
		    else
		    {
		        //Parametro non riconosciuto. Lo ignoro
		    }
			//alert(arrParamNames[i]+" = "+ arrParamValues[i]);
		}   
      
      
}	    

// UrlENCODING - UrlDECODING
function urlencode(str) {
    return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}
function urldecode(str) {
    return unescape(str.replace('+', ' '));
}