//Cookie functions

function getCookieVal (offset) 
   {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
   }

function GetCookie (name) 
   {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) 
      {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
      }
   return null;
   }

function SetCookie (name, value) 
   {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : null;
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
   }

function DeleteCookie (name) 
   {
   var exp = new Date();
   exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time)
   var cval = GetCookie ( name );
   document.cookie =name + "=" + cval + "; expires=" + exp.toGMTString();
   }


//Qarbon demo functions
function isViewletCompliant()
{
  answer=true;
  version=Math.round(parseFloat(navigator.appVersion) * 1000);
  if (navigator.appName.substring(0,9) == "Microsoft")
  {
    if(version<4000) answer=false;
  }
  if (navigator.appName.substring(0,8) == "Netscape")
  {
    if ((navigator.appVersion.indexOf("Mac")> 0) && (version<5000))
      answer=false;
    else
    if (version<4060)
      answer=false;
  }

  plugins=navigator.plugins;
  if (answer==false && plugins!=null)
  {
    for(i=0;i!=plugins.length;i++)
    if((plugins[i].name.indexOf("Java Plug-in")>=0) && (plugins[i].name.indexOf("1.0")<0))
    answer=true;
  }
  return answer;
}

function openViewlet(htmlFile,htmlWidth,htmlHeight)
{
  str = 'resizable=0,toolbar=0,menubar=0,';
  str = str + 'scrollbars=0,status=0,location=0,directory=0,width=350,height=200';

  version=Math.round(parseFloat(navigator.appVersion) * 1000);

  if(navigator.appName.indexOf("Konqueror")!=-1) // konqueror
  {
    htmlWidth+=18;
    htmlHeight+=96;
  }

  if(navigator.appName.indexOf("Netscape")!=-1)
  {
    if(version>=5000)
    {
      if(navigator.appVersion.indexOf("Mac")!=-1) // Netscape6+ on mac
      {
        htmlHeight+=5;
      }
    }
  }

  if(navigator.appName.indexOf("Microsoft")!=-1)
  {
    if(navigator.appVersion.indexOf("Mac")!=-1) // IE on Mac
    {
       htmlWidth  -= 11;
       htmlHeight -= 11;
    }
  }

    if(!isViewletCompliant())
    {
      open("http://www.qarbon.com/warning/index.html",'Leelou',str);
    }
    else
    {
      window.open(htmlFile,'Leelou','width='+htmlWidth+',height='+htmlHeight+',top=10,left=20');
    }

}


//Qarbon demo functions
function isDemoOk(){     IsOk=true;     bver=Math.round(parseFloat(navigator.appVersion) * 1000);     if (navigator.appName.substring(0,8) == "Netscape")     {         if ((bver<5000) && (navigator.appVersion.indexOf("Mac")> 0))             IsOk=false;         else if (bver<4060)             IsOk=false;     }	 if (navigator.appName.substring(0,9) == "Microsoft")     {         if(bver<4000)             IsOk=false;     }     plugins=navigator.plugins;     if (plugins!=null && IsOk==false)     {         for(i=0;i!=plugins.length;i++)              if((plugins[i].name.indexOf("1.0")<0) && (plugins[i].name.indexOf("Java Plug-in")>=0))                  IsOk=true;     }     return IsOk;}function openDemo(htmlFile,htmlWidth,htmlHeight){var bua = navigator.userAgent;     s = 'resizable=0,toolbar=0,menubar=0,scrollbars=0,status=0,location=0,directory=0,width=350,height=200';     if(!isDemoOk())     {          open("http://www.turbodemo.com/error.html",'',s);     }     else     {     if (bua.indexOf("Opera")!= -1)       {          window.open(htmlFile+".htm",'','width='+htmlWidth+',height='+htmlHeight+',top=10,left=10');      }     else      {          window.open(htmlFile+".htm",'','width='+htmlWidth+',height='+htmlHeight+',top=10,left=10');      }      }}



//Set a cookie with the referring URL if it is not already set
if ( 
     (GetCookie ("found_us") == "") 
   )
{
  var ExpireDate = new Date ();
  ExpireDate.setTime(ExpireDate.getTime() + (2 * 365 * 24 * 3600 * 1000));

  //no previous referrer - so set it if we can
  if (document.referrer && document.referrer != "")
    SetCookie('found_us', document.referrer, ExpireDate );
}


