/*
  website integration code (direct chat start)
    yalst LiveSupportTool
    Author: Dr. Markus Jasinski
    Copyright (c) 2003-2010 by Visisoft, Rostock, Germany
    http://www.visisoft.de
*/

var liveoperators=0;

function str_replace(search,replace,oldstring)
  {
  result=""+oldstring;
  while (result.indexOf(search)>-1)
    {
    pos=result.indexOf(search);
    result=""+(result.substring(0,pos)+replace+result.substring((pos+search.length),result.length));
    }
  return result;
  }

// Cookie handling
function setcookie8(value)
  { //v2.0
  var expDate = new Date();
  expDate.setFullYear(expDate.getFullYear() + 30);
  document.cookie = "YALSTSESSION=" + value + "; path=/; expires=" + expDate.toGMTString();
  }
function readcookie10()
  {
  var allcookies = document.cookie;
  var pos = allcookies.indexOf("YALSTSESSION=");
  if (pos != -1)
    {
    var start = pos + 13;
    var end = allcookies.indexOf(";",start);
    if (end == -1)
      end = allcookies.length;
    var value = allcookies.substring(start,end);
    if (value != "")
      {return value;}
    else
      {return "none";}
    }
  else
    {return "none";}
  }
// Chat handling
function open_direct_livechat(url,width,height)
  {
  if (!width) width=500;
  if (!height) height=350;
  Fpopupwindow=window.open(url,"livechat_34000_1","width="+width+",height="+height+",location=no,menubar=no,statusbar=no,scrollbars=no,dependent=no,screenX=20,screenY=20,left=20,top=20");
  if (Fpopupwindow.opener == null) Fpopupwindow.opener = self;
  Fpopupwindow.focus();
  }
function startchat()
  {
  mycookie=readcookie10();
  if (mycookie=="none")
    {
    setcookie8('');
    var newcookie=readcookie10();
    if (newcookie=='')
      {mycookie=newcookie;}
    else
      {mycookie="none";}
    }
  else
    {
    if (mycookie.length!=30)
      {
      setcookie8('');
      var newcookie=readcookie10();
      if (newcookie=='')
        {mycookie=newcookie;}
      else
        {mycookie="none";}
      }
    }
  var today = new Date();
  var localtime = today.getHours() + ":" + today.getMinutes();
  dc="&localtime="+escape(localtime);
      if (typeof(screen)=="object")
    {
    dc+="&screenxy="+screen.width+"x"+screen.height;
    dc+="&screencd="+screen.colorDepth;
    }
  if (navigator.javaEnabled())
    {dc+="&java=true";}
  if (document.livechat)
    {
    if (document.livechat.livechat_name)
      {dc+="&name="+escape(document.livechat.livechat_name.value);}
    if (document.livechat.livechat_question)
      {dc+="&question="+escape(document.livechat.livechat_question.value);}
    }
  dc+="&newlang=1";
  open_direct_livechat('http://en.livesupportserver.de/yalst/dchat.php?yinit=true&cookie='+escape(mycookie)+'&site=34000-1&from='+escape(window.document.URL)+dc,550,540);
  }
