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 'vm': {theUrl='VisualizzaMappa.htm'; theTitle='Visualizza la mappa'; thePreTextVisible='none';break}
        case 'cu': {theUrl='CondizioniGenerali.htm'; theTitle='Condizioni Generali'; thePreTextVisible='none';break}
        case 'ct': {theUrl='Contatti.htm'; theTitle='Contatti'; thePreTextVisible='none';break}
        default: {theUrl='Default.aspx'; theTitle='Prenota Parcheggio'; thePreTextVisible='none';break}
    }

    var anch = document.getElementById('aPP');
    if (anch  != null)    
    if (theID != 'pp') 
    {
        anch.setAttribute("class", "");
        anch.setAttribute("className", "");                
    }
    else
    {
        anch.setAttribute("class", "attivo");
        anch.setAttribute("className", "attivo");                
    }

    var obj;
    obj = document.getElementById('FrameContentPage');
    if (obj != null)
    {
        obj.src = theUrl;
//        if (theUrl == 'Default.aspx')
//            obj.width = '600px';
//        else
//            obj.width = '735px';
    }
    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]);
	}   

    //Questo frammento di codice serve SOLO per settare l'attributo ACTIVE all'anchor 'Prenota Parcheggio' la prima volta in cui apro la pagina!
//    var anch = document.getElementById('aPP');
//    if (anch  != null) 
//    {
//	    if (arrParamNames.length==0)
//        {
//            anch.setAttribute("class", "active");
//	        anch.setAttribute("className", "active");
//        }				
//	    else
//        {
//            anch.setAttribute("class", "");
//	        anch.setAttribute("className", "");                
//	    }
//	}
  
}	

var newwindow = '';   
function popupWindow(url, name)
{
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		var width=760;
		var height=500;
        var attr = "scrollbars=yes, resizable=1, width=" + width + ",height=" + height;
		newwindow = window.open(url, null, attr);
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
} 

// 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('+', ' '));
}