function showLink() {
   if (document.getElementById) {
    	        if(document.getElementById("LnkSen"))
    	        {
		  linkSen = document.getElementById("LnkSen");
		  linkSen.className = "visibleSel";
	          linkSen.classString = "visibleSel";
		} 
		if(document.getElementById("LnkDep"))
		{ 
		  linkDep = document.getElementById("LnkDep");
		  linkDep.className = "visibleSel";
	          linkDep.classString = "visibleSel";
		}
		if(document.getElementById("LnkGov"))
		{
		  linkGov = document.getElementById("LnkGov");
		  linkGov.className = "visibleSel";
	          linkGov.classString = "visibleSel";
		}
		if(document.getElementById("LnkPol"))
		{  
		  linkPol = document.getElementById("LnkPol");
		  linkPol.className = "visibleSel";
	          linkPol.classString = "visibleSel";
		}  
		if(document.getElementById("LnkRif"))
		{  
		  linkRif = document.getElementById("LnkRif");
		  linkRif.className = "visibleSel";
	          linkRif.classString = "visibleSel";
		}  
	} else if (document.all) { 
		if(document.all["LnkSen"])
		{
		  linkSen = document.all["LnkSen"];
		  linkSen.className = "visibleSel";
	          linkSen.classString = "visibleSel";
		}
		if(document.all["LnkDep"])
		{
		  linkDep = document.all["LnkDep"];
		  linkDep.className = "visibleSel";
	          linkDep.classString = "visibleSel";
		}
		if(document.all["LnkGov"])
		{
		  linkGov = document.all["LnkGov"];
		  linkGov.className = "visibleSel";
	          linkGov.classString = "visibleSel";
		}
		if(document.all["LnkPol"])
		{
		  linkPol = document.all["LnkPol"];
		  linkPol.className = "visibleSel";
	          linkPol.classString = "visibleSel";
		}
		if(document.all["LnkRif"])
		{
		  linkPol = document.all["LnkRif"];
		  linkPol.className = "visibleSel";
	          linkPol.classString = "visibleSel";
		}

	} 
}

function showSel(idSel) {
 	elId = idSel;
	lnkId = idSel + "_Lnk";
	tipoSel = elId.substring(0, 6);
    if (document.getElementsByTagName) {
		divColl = document.getElementsByTagName("div");
		lnkColl = document.getElementsByTagName("a");
	} else if (document.all) { 
		divColl = document.all.tags("div");
		lnkColl = document.all.tags("a");
	} 
	if (divColl != null) {	
		for (i=0; i<divColl.length; i++) {
			if (divColl[i].id.indexOf(tipoSel) != -1)  {
				divColl[i].className = "hiddenSel";
				divColl[i].classString = "hiddenSel";
			}
		}
	}
	if (lnkColl != null) {	
		for (i=0; i<lnkColl.length; i++) {
			if (lnkColl[i].id.indexOf(tipoSel) != -1)  {
				lnkColl[i].className = "link4Liv";
				lnkColl[i].classString = "link4Liv";
			}
		}
	}
	
	if (document.getElementById) {
		if (document.getElementById(elId))
		{
		  lista = document.getElementById(elId);
		  lnk = document.getElementById(lnkId);
              lista.className = "activeSel"; 
	          lnk.className = "linkOn";
	          lista.classString = "activeSel";
	          lnk.classString = "linkOn";
	        }

	} else if (document.all) {
	        if (document.all[elId])
	        {
		  lista = document.all[elId];
		  lnk = document.all[lnkId];
		  lista.className = "activeSel"; 
        	  lnk.className = "linkOn";
	          lista.classString = "activeSel";
	          lnk.classString = "linkOn";
	        }  
	}
	
}

function checkOnLoad() {}

   function init() {
       // quit if this function has already been called
       if (arguments.callee.done) return;

       // flag this function so we don't do the same thing twice
       arguments.callee.done = true;
		showLink(); 
		showSel('SelSenA'); 
		showSel('SelDepA'); 
		showSel('SelSen0'); 
		showSel('SelDep0'); 
		showSel('SelGov0'); 
		showSel('SelPol0'); 
		showSel('SelRif0');		
		setPopup();		
	};

  
function toggleStatus(checkboxId, toggledDiv)
{
	if ( $('#' + checkboxId).is(':checked') )
    {
        enableToggledDiv( toggledDiv);
    }
    else
    {
        disableToggledDiv( toggledDiv);
    }
};  
  

function toggleMultipleStatus(checkboxIds, toggledDiv)
{
    for( i=0; i<checkboxIds.length; i++ )
    { 
      checkboxId = checkboxIds[ i ];
      value = $('#' + checkboxId).is(':checked');
      if ( value )
      {
          enableToggledDiv( toggledDiv );
          return;
      }
    }
    
    disableToggledDiv( toggledDiv );
};  

function enableToggledDiv( toggledDiv )
{
    $('#' + toggledDiv + ' input').removeAttr('disabled');
    $('#' + toggledDiv + ' button').removeAttr('disabled');
    $('#' + toggledDiv + ' select').removeAttr('disabled');
    $('#' + toggledDiv + ' label').css({ 'color': 'black'});
    $('#' + toggledDiv + ' span[class!="token-input-delete-token"]').css({ 'color': 'black'});
    $('#' + toggledDiv + ' select').css({ 'color': 'black'});
        
    $('#' + toggledDiv + ' li[class="token-input-token"]').css({ 'background-color': '#3399ff'});        
    $('#' + toggledDiv + " span[class='token-input-delete-token']").show();
}  



function disableToggledDiv( toggledDiv )
{
	//$('#' + toggledDiv + ' input').attr('checked', false);
    
	$('#' + toggledDiv + ' input').attr('disabled', true);
    $('#' + toggledDiv + ' button').attr('disabled', true);                
    $('#' + toggledDiv + ' select').attr('disabled', true);                        
    $('#' + toggledDiv + ' label').css({ 'color': '#aaa'});
    $('#' + toggledDiv + ' span[class!="token-input-delete-token"]').css({ 'color': '#aaa'});
    $('#' + toggledDiv + ' select').css({ 'color': '#aaa'});
        
    $('#' + toggledDiv + ' li[class="token-input-token"]').css({ 'background-color': '#aaa'});        
    $('#' + toggledDiv + " span[class='token-input-delete-token']").css({ 'display': 'none'});
}


function submitForm( x )
{
	search = x.search.substring( 1 );
	parameters = search.split( '&' );

	var form = document.createElement( "form" );
	form.setAttribute( "method", "post" );
	form.setAttribute( "accept-charset", "utf-8" );
	
	path = x.pathname;
	port = x.port;

	
	action = "http://" + x.hostname;

    if( port == '8080')
    {
	  action = action + ":" + port;
    }	

	if( !path.indexOf('/') == 0 )
	{
	  action = action + "/";
	}
	action = action + path;
	
	
	form.setAttribute( "action", action );

	for ( i = 0; i < parameters.length; i++ )
	{
		param = parameters[i];
		pair = param.split( '=' );
		paramName = pair[ 0 ];
		//paramValue = unescape(pair[ 1 ].ReplaceAll('+', ' '));
		paramValue = decodeURI(pair[ 1 ].ReplaceAll('+', ' '));
		//paramValue = pair[ 1 ].ReplaceAll('+', ' ');
						
		var hiddenField = document.createElement( "input" );
		hiddenField.setAttribute( "type", "hidden" );
		hiddenField.setAttribute( "name", paramName );
		hiddenField.setAttribute( "value", paramValue );
		form.appendChild( hiddenField );
	}

	document.body.appendChild( form );
	form.submit();
}

String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
    var temp = this;
    var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
    }

function manageCercaInDivs( idCheckbox, idRadio, divRadio) 
{
	if ( $("#" + idCheckbox).is(':checked') ) 
	{
		toggleStatus(idRadio, divRadio);
	}
	else 
	{
		disableToggledDiv( divRadio );
	}
}

   /* for Mozilla */
   if (document.addEventListener) {
       document.addEventListener("DOMContentLoaded", init, false);
   }
   /* for Internet Explorer */
   /*@cc_on @*/
   /*@if (@_win32)
       document.write('<script defer type="text/javascript" src="/js/ricerche/init.js"><'+'/script>');
   /*@end @*/

   /* for other browsers */
   window.onload = init;

