   /*
    * Workaround for the fp bug: Named Anchors in URL prevent SWF from being streamed in
   */

var startLocation;

function isFirstTime(){
   
   var pgHasAnchor = pageHasAnchor(); 
   var pgHasCookie = pageHasCookie();
   
   if (!pgHasAnchor && !pgHasCookie){
       return true; 
   }else if(!testCookieEnabled()){
       return true;  
   }else if(pgHasAnchor && !pgHasCookie){
      return true;
   }else
      return false;
}


function reloadIfAnchor() {

     var pgHasAnchor = pageHasAnchor(); 
     var pgHasCookie = pageHasCookie();

    //Don't have #, do nothing.   
    if (!pgHasAnchor && !pgHasCookie){
       return false; 
    }
    //If cookie is disable do nothing. 
    else if(!testCookieEnabled()){
       return false;  
    }
    //If page hasn't cookie -> first session.  
    else if(pgHasAnchor ){           //&& !pgHasCookie 
       saveStartLocation();
       loadPageWithoutAnchor();
       
       return true;           
    }
    // Second session
    else{                 
       readAndEraseCookie();  
       return false;
    }     
}  

function pageHasAnchor(){

    var url = window.location.toString();
    var anchor_index = url.indexOf('#');
    var hasAnchor = (anchor_index != -1) ? true : false ;
      
    return hasAnchor;
} 

function saveStartLocation(url) {
   
   if (!url)
      url = window.location.toString();
      
    var anchor_index = url.indexOf('#');
  
    if (anchor_index != -1) {
        urlWithAnchor = url.substring(anchor_index + 1 );
        saveUrl(urlWithAnchor); 
    }
}
function saveUrl(urlWithAnchor) {

   cookieTxt = readCookie("PearltreesPreloaderUrl");
   if(!cookieTxt)
      cookieTxt = urlWithAnchor + '$';
   else
      cookieTxt = cookieTxt + urlWithAnchor  + '$';

   createCookie("PearltreesPreloaderUrl",cookieTxt,60);
}

function readAndEraseCookie(){


   cookieTxt = readCookie("PearltreesPreloaderUrl");
   
   var cookie_index = cookieTxt.indexOf('$');
   
   startLocation = cookieTxt.substring(0, cookie_index ); 
   newCookieTxt = cookieTxt.substring(cookie_index + 1); 
   
   if(newCookieTxt == '')
       eraseCookie("PearltreesPreloaderUrl");
   else
       createCookie("PearltreesPreloaderUrl",newCookieTxt,60);

}

function ReadAndEraseAux(urlWithAnchor){

   startLocation = readCookie(urlWithAnchor);
   eraseCookie(urlWithAnchor);  

}

//Return true if there is redirection false otherwise.  
function loadPageWithoutAnchor(){     
      
     var url = window.location.toString();

     var anchor_index = url.indexOf('#');
     if (anchor_index != -1) {
         
         urlWithoutAnchor = url.substring(0, anchor_index);
         
         if(navigator.appName == "Netscape")       
            location.reload( true );       
 
         self.location = urlWithoutAnchor;
          
         return true;
     } 
     return false; 
 }     
 
function pageHasCookie(){
      
    if (readCookie("PearltreesPreloaderUrl")) 
         return true;
    
    return false;
    
} 

function getStartLocation() {
    return startLocation;
}


//Test if cookie is enable.
function testCookieEnabled(){ 

      var cookieEnabled=(navigator.cookieEnabled)? true : false
      //if not IE4+ nor NS6+
      if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
         document.cookie="testcookie"
         cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
      }
      return cookieEnabled;
}   