function raiseCommandEvent(commandName, params) {
	var element = document.createElement("flexCommandEvent");
	element.setAttribute("commandName", commandName);
	document.documentElement.appendChild(element);
	
	var evt = document.createEvent("Events");
	evt.initEvent("flexCommandEvent", true, false);
	element.dispatchEvent(evt);	
}
function notifyLogin() {
	raiseCommandEvent("login");
}
function notifyLogout() {
   raiseCommandEvent("logout");
}
function detectPearlbar() {
   raiseCommandEvent("detectPearlbar");
}

function callPearlbarCommand(commandName, params) {
   document.getElementById(swfName).pearlbarCommand(commandName);
}
function onPearlbarCommandEvent(event) {
	var commandName = event.target.getAttribute("commandName");
	if(commandName == "pearlbarIsInstalled") {
       callPearlbarCommand("pearlbarIsInstalled");
	}
}
if (window.addEventListener) {
	   window.addEventListener("pearlbarCommandEvent", onPearlbarCommandEvent, false);
	}
	else if(window.attachEvent) {
	   window.attachEvent("pearlbarCommandEvent", onPearlbarCommandEvent)
	}

function getBrowserName() {
    return BrowserDetect.browser;
}
function getSessionID() {
    return readCookie('PEARLTREES-AUTH');
}    
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
       var c = ca[i];
       while (c.charAt(0)==' ') c = c.substring(1,c.length);
       if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function getUserLang() {
	return userLang;
}

function getClientLang() {
	return clientLang;
}

function PTGetClientLang() {

  var l_lang;
  
  if (navigator.userLanguage) // Explorer
    l_lang = navigator.userLanguage;
  else if (navigator.language) // FF
    l_lang = navigator.language;
  else
    l_lang = "df";
    
    return l_lang;
}

function createCookie(name,value,seconds) {
   if (seconds) {
      var date = new Date();
      date.setTime(date.getTime()+(seconds*1000));
      var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
   createCookie(name,"",-1);
}

function hideWaitingPanel(){
    stopPreloader();
    document.getElementById(swfName).style.width='100%';
    document.getElementById(swfName).style.height='100%';
    document.getElementById('page').style.display='none';
    document.getElementById('page').innerHTML='';
}
function onApplicationExit(){
    document.getElementById(swfName).onApplicationExit();
}
function getInvitationEmail(){
    return invitationEmail;
}
function getInvitationKey(){
    return invitationKey;
}
function getLostPasswordToken(){
    return lostPasswordToken;
}
function getOrigin() {
    return origin;
} 
function getUserName() {
    return userName;
}
function getStartTime() {
    return startTime;
}
function getWebSiteUrl() {
    return webSiteUrl;
}
function getStaticContentUrl() {
    return staticContentUrl;
}
function getServicesUrl() {
    return servicesUrl;
}
function getShortenerDomain() {
	return shortenerDomain;
}
function getInnerWidth(){
   return innerWidth;
}

function loadIFrame(frameID, iframeID, url) {
  document.getElementById(iframeID).src = url;
}

function sendStats(title){
	// stats only for production
	if(self.location.hostname != "www.pearltrees.com"){
		return;
	}
    // piwik
    (new Image).src = "http://piwik.pearltrees.com/piwik.php?url=" +
    escape(window.location) + "&action_name=" + escape(title) + "&idsite=1&title=" +
    escape(title) + "&urlref=" + escape(document.referrer);
    // xiti
    xt_med('F','0', escape(title).split(' > ').join('::'));
}

function reloadPage(){
	    
	var cookieAlreadyReloaded = readCookie("reloadCookie");
	    
    if (!cookieAlreadyReloaded){
    
   		var url = window.location.toString();
    	newUrl = url + '?'
         
    	if(navigator.appName == "Netscape")       
        	location.reload( true );       
 
    	self.location = newUrl;
  	}
  	
  	createCookie("reloadCookie","true",10);
}

function getLocalLastSaveDate() {
	var lastSaveDate = readCookie("lastSaveDate");
	if (lastSaveDate==null) {
		return 0;
	}
	return lastSaveDate
}
function setLocalLastSaveDate(lastSaveDate) {
   createCookie("lastSaveDate", lastSaveDate,5);
}