var po = "";
var cookiename="";
cookiename='PpUsefulinks_JsstateCookie';
 

function setCookiename(name) {
cookiename =name;
}

function createCookie(name,value) {

		var date = new Date();
		date.setTime(date.getTime()+(365*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	
	document.cookie = name+"="+value+expires+"; path=/wps/";
}

function readCookie(name)
{
var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	{	return unescape( document.cookie.substring( len, end ) )};
}

function eraseCookie(name) {
	createCookie(name,"",-1);
	
}

function checkcookies()
{

 var crumbs = readCookie(cookiename);
if (crumbs != null) 
{var crumb = crumbs.split(",");
      
     for (var i = 0; i < crumb.length; i++){ 
    
     var e = document.getElementById(crumb[i]);
     po = crumb[i] +","+po;
     var u = crumb[i];
 
    if (u=="introduc")
   {
if(e!=null)
   e.style.display = 'none';
    
    }
    else

if(e!=null)
       e.style.display = 'block';
      } 

}


}


    function toggle_visibility(id) {
          
       var e = document.getElementById(id);
var f = document.getElementById("use_" + id);
       if( e.style.display== 'block')
      {  
      if (po.search(id)!=-1)
       {
   po = remove(po,id);
   createCookie(cookiename,po);
    
     }
     if ( e!=null)
       e.style.display='none';
 if ( f!=null)
 f.className = 'pp-portlet-head-sub pp-minimised';
               }
      
       else
          { 
            if (po.search(id)==-1)
            po = id +","+po;
    if ( e!=null)
    e.style.display='block';
 if ( f!=null)
 f.className = 'pp-portlet-head-sub';
            createCookie( cookiename,po);
          }
         
    }
    
        function toggle_visibility_intro(id) {

       var e = document.getElementById(id);
  
    if ( e!=null)
       if( e.style.display== 'none')
      {  
      if (po.search(id)!=-1)
       {
   po = remove(po,id);
   createCookie(cookiename,po);
    
     }
       e.style.display='block';
               }
      
       else
          { 
            if (po.search(id)==-1)
            po = id +","+po;
 if ( e!=null)   
 e.style.display='none';
            createCookie( cookiename,po);
          }
         
    }

function remove(s, t) {
  /*
  **  Remove all occurrences of a token in a string
  **    s  string to be processed
  **    t  token to be removed
  **  returns new string
  */

  i = s.indexOf(t+',');
  var r = "";

  if (i == -1) return s;
  r += s.substring(0,i) + remove(s.substring(i + t.length), t);

  return r;
  }

    function rename(id) {
       var e = document.getElementById(id);
 if ( e!=null)        
 e.click();
          }

function addToBodyOnload(oFunction) {
    var existingOnload = window.onload;
    if(existingOnload){
    	window.onload = function () { oFunction(); existingOnload(); }
    } else {
    	window.onload = function () { oFunction(); }
    }
}



addToBodyOnload(checkcookies);


