function setCookie(name, value, path) {	
	var today = new Date();
	var expdate = new Date ();
	expdate.setTime(today.getTime() + (1000*60*60*24*365));
	
  document.cookie= name + "=" + escape(value) +
        "; expires=" + expdate +
        ((path) ? "; path=" + path : "");
}

function deleteCookie(name, path) {
    //if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    //}
}

function SHSub (oid,dir)
{	
  alert('ciao');
	var obj=document.getElementById(oid);
	if (obj.style.display=='none')
	{
		obj.style.display='block';
		setCookie(oid, true, dir);
	}
	else
	{
		obj.style.display='none';
		deleteCookie(oid,dir);
	}
}

function Show(ev,evento){
    var src=Event.element(evento);
    $('part').hide();
    $('oper').hide();
    $('estate').hide();
    $('advisory').hide();
    $('management').hide();
    
    $$('#box img').each(
      function (x){      
        if(x.readAttribute('src').match('_over')){
           var nuovo = x.readAttribute('src').replace('_over','');
           x.setAttribute('src',nuovo); 
        }
      }
    );
      
    var img = src.readAttribute('src');
    var img_r = img.replace('.jpg','_over.jpg');
    src.setAttribute('src',img_r);
    $(ev).show();
}

function over(evento){
      $$('#box img').each(
      function (x){      
        if(x.readAttribute('src').match('_over')){
           var nuovo = x.readAttribute('src').replace('_over','');
           x.setAttribute('src',nuovo); 
        }
      }
    );
  var src=Event.element(evento);
  var img = src.readAttribute('src');

  var img_r = img.replace('.jpg','_over.jpg');
  src.setAttribute('src',img_r);
}


function Showx(ev){
    $('part').hide();
    $('oper').hide();
    $('estate').hide();
    $('advisory').hide();
    $(ev).show();
}

function Showbox(ev,evento){
  
  if(evento != '')  
    var src=Event.element(evento); 
  /*$('main').hide();*/
  $('amministrazione').hide();
  $('collegio').hide();
  $('interno').hide();
  $('remunerazione').hide();
  $('revisione').hide();
 
  
  $$('.try').each(
      function (x){      

       var pippo = x.readAttribute('id');
       
        x.setStyle({color: '#f0f0f0'});
        
      }
    );
   
    if(evento != '' )
      src.setStyle({color: '#abcfdb'});

   $(ev).show();
}

function Showcurr(from,ev){

    $$('#'+from+' .curriculum div').each(
      function (x){      
        x.hide();
      }
    );
    $(ev).show();
}

function Showlog(ev){
    $('part').hide();
    $('oper').hide();
    $('estate').hide();
    $('advisory').hide();
    $('management').hide();
    $(ev).show();
}

function Showstat(ev,evento){
    var src=Event.element(evento); 
    $('oggetto_txt').hide();
    $('amministrazione_txt').hide();
    $('assemblee_txt').hide();
    $('azioni_txt').hide();
    $('bilancio_txt').hide();
    $('sindaci_txt').hide();
   $(ev).show();
   
    $$('.test').each(
      function (x){      
        
        x.setStyle({backgroundImage: "url(../img/contenuti-griggio.png)"});
      }
    );
    
   src.setStyle({backgroundImage: "url(../img/contenuti-blu.png)"});
   $(ev).show();
}

function Blank(evento){
  
    $$('.'+evento).each(
      function (x){      
        
        x.setStyle({color: '#bb0000'});

      }
    );
  
 // $$('.'+evento).setStyle({color: '#f0f0f0'});
}

//-------------------------------------per menu

function doSearch (id) {	
	window.location.href='/ricerca/ricerca.php?chiave='+escape($('chiave_ricerca').value);
}

function highLight () {
	var query=window.location.href.split('?').last();
	if (query=='')
		return false;
	var vars=query.toQueryParams();
	if (!vars.skw)
		return false;
		
	highlightSearchTerms(vars.skw,false,false);
}

/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font class=\"search_res\">";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}

