var s = "";
var nf_cookiename="";
nf_cookiename ='PpNewsFeeds_JsstateCookie';

function setCookiename(name) {
nf_cookiename =name;
}
 
function ns_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 ns_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) {
	ns_createCookie(name,"",-1);
	
}

function ns_checkcookies()
{  
 var crumbs = ns_readCookie(nf_cookiename);

if (crumbs != null) 
{var crumb = crumbs.split(",");
      
     for (var i = 0; i < crumb.length; i++){ 
    
     var e = document.getElementById(crumb[i]);
     s = crumb[i] +","+s;
     if (e!=null)
     e.style.display = 'block';
    
  
}


}

}
    function toggle_div(id) {

       var e = document.getElementById(id);
  var f = document.getElementById("div_" + id);

  
if (e!=null){   
       if( e.style.display== 'block')
      {  
      if (s.search(id)!=-1)
       {
   s = remove(s,id);
   ns_createCookie(nf_cookiename,s);
    
     }
       e.style.display='none';
       f.className = 'pp-portlet-head-sub pp-minimised';
               }
      
       else
          { 
            if (s.search(id)==-1)
            s = id +","+s;
    e.style.display='block';
    f.className = 'pp-portlet-head-sub';
            ns_createCookie( nf_cookiename,s);
          }
         
    }}
    
        function toggle_visibility_intro(id) {

       var e = document.getElementById(id);
  if (e!=null){ 
   
       if( e.style.display== 'none')
      {  
      if (s.search(id)!=-1)
       {
   s = remove(s,id);
   ns_createCookie(nf_cookiename,s);
    
     }
       e.style.display='block';
               }
      
       else
          { 
            if (s.search(id)==-1)
            s = id +","+s;
    e.style.display='none';
            ns_createCookie( nf_cookiename,s);
          }
         }
    }

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 ns_addToBodyOnload(oFunction) {
    var existingOnload = window.onload;
    window.onload = function () { oFunction(); existingOnload(); }
}

ns_addToBodyOnload(ns_checkcookies);


