function cleardefault(def,id)
{
    var txt = document.getElementById(id);
    if (txt != null && txt.value == def)
      txt.value = '';
}

//Blendet nicht benoetigte Buttons aus
function hideButtons() 
{
  var ids = new Array('small_favorite_order');
  for (var i in ids) 
  {
	var btn = document.getElementById(ids[i]);
	if (btn != null)
	  btn.style.display = "none";
  }
}



//Popup:
var g_req;
var g_popupOpen = 0;

function replStr(str,oldStr,newStr)
{ var strPos=str.indexOf(oldStr);
  return (strPos>=0) ?
    str.substring(0,strPos) + newStr +
       replStr( str.substring(strPos +
       oldStr.length), oldStr, newStr ) :
    str
}

function getTextBetween(sAll, sStart, sEnd)
{
    var sPart = "";
    var posStart = sAll.indexOf(sStart);
    var posEnd = sAll.indexOf(sEnd);
    if (posStart >= 0 && posEnd >= 0 && posEnd > posStart) {
        sPart = sAll.substring(posStart + sStart.length, posEnd);
    }
    return sPart;
}


function clickPopupLink(sUrl)
{
  if (g_popupOpen == 0)
  {
    g_popupOpen = sUrl;
    prepareFillPopup(sUrl);
  }
}
  
function prepareFillPopup(sUrl)
{
  if(sUrl.indexOf('?') > -1)sUrl += "&" + getCachePrevent();
  else sUrl += "?" + getCachePrevent();
  if (window.XMLHttpRequest) {
    g_req = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    g_req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  g_req.onreadystatechange = fillPopup;
  g_req.open("GET", sUrl, true);
  g_req.send(null);
}
  
function getCachePrevent()
{
  return "rand=" + escape( Math.round( Math.random() * 10000 ) );
}

function fillPopup()
{
  if (g_req.readyState == 4)
  {
    if (g_req.status == 200)
    {
      var s = "";
  
      var elmKB = document.getElementById("popup");

      s = g_req.responseText;
      
      var sRun = getTextBetween(s, "// <![CDATA[", "// ]]>");
      sRun = replStr(sRun, ",wmode=opaque", ",");

      elmKB.innerHTML = s;

      elmKB.style.display = "block";
      
      if (sRun != "") { eval(sRun); }
    }
    else
    {
      alert("Can't retrieve XML: " + g_req.statusText);
    }
  }
}

function closePopup()
{
  var elm = document.getElementById("popup");
  elm.innerHTML = "<p>&nbsp;</p>";
  elm.style.display = "none";

  g_popupOpen = 0;
}


//Liveshopping
var enddate;
var cdif;
var ival;

function LSSetTime(endtime, ctime)
{
  var y = parseInt(endtime.substring(0, 4),10);
  var m = parseInt(endtime.substring(5, 7), 10) - 1;
  var d = parseInt(endtime.substring(8, 10), 10);
  var h = parseInt(endtime.substring(11, 13), 10);
  var mi = parseInt(endtime.substring(14, 16), 10);
  var s = parseInt(endtime.substring(17), 10);
  enddate = new Date(y, m, d, h, mi, s);

  var y = parseInt(ctime.substring(0, 4), 10);
  var m = parseInt(ctime.substring(4, 6), 10) - 1;
  var d = parseInt(ctime.substring(6, 8), 10);
  var h = parseInt(ctime.substring(8, 10), 10);
  var mi = parseInt(ctime.substring(10, 12), 10);
  var s = parseInt(ctime.substring(12), 10);
  var cdate = new Date(y, m, d, h, mi, s);

  var now = new Date();
  cdif = Math.floor((cdate.getTime() - now.getTime()) / 1000);  //in sek
  if (cdif < 20 && cdif > 0)
  {
    cdif = 0;
  }
  LSUpdateTime()
  ival = window.setInterval('LSUpdateTime()', 1000);
}

function LSUpdateTime()
{
    var date = new Date();
    var dif = Math.floor((enddate.getTime() - date.getTime()) / 1000);  //in sek
    dif = dif - cdif;

    var day = 0;  //Math.floor(dif / (60 * 60 * 24)); //keine Taganzeige
    var hour = Math.floor((dif - day * 60 * 60 * 24) / (60 * 60));
    var min = Math.floor((dif - day * 60 * 60 * 24 - hour * 60 * 60) / 60);
    var sek = Math.floor(dif - day * 60 * 60 * 24 - hour * 60 * 60 - min * 60);
    
    if (dif < 0)
    {
        document.getElementById('ls1').innerHTML = "";
        document.getElementById('ls2').innerHTML = "<img src=\"" + imagelist[0].src + "\"/>";
        document.getElementById('ls3').innerHTML = "";
        document.getElementById('ls4').innerHTML = "<img src=\"" + imagelist[0].src + "\"/>";
        document.getElementById('ls5').innerHTML = "";
        document.getElementById('ls6').innerHTML = "<img src=\"" + imagelist[0].src + "\"/>";

        document.getElementById('lsbasket').innerHTML = "";
        if (document.getElementById('lsimg').getAttribute("src").indexOf("_end&abtype=") < 0)
          document.getElementById('lsimg').setAttribute("src", document.getElementById('lsimg').getAttribute("src").replace("&abtype=", "_end&abtype="));
        window.clearInterval(ival);
        window.clearInterval(LSaval);
    }
    else
    {
        if (hour > 99)
        {
          hour = 99;
        }
        if (hour > 9)
            document.getElementById('ls1').innerHTML = "<img src=\"" + imagelist[Math.floor(hour / 10)].src + "\"/>";
        else
            document.getElementById('ls1').innerHTML = "";
        document.getElementById('ls2').innerHTML = "<img src=\"" + imagelist[(hour - Math.floor(hour / 10) * 10)].src + "\"/>";

        if (min > 9)
            document.getElementById('ls3').innerHTML = "<img src=\"" + imagelist[Math.floor(min / 10)].src + "\"/>";
        else
            document.getElementById('ls3').innerHTML = "";
        document.getElementById('ls4').innerHTML = "<img src=\"" + imagelist[(min - Math.floor(min / 10) * 10)].src + "\"/>";

        if (sek > 9)
            document.getElementById('ls5').innerHTML = "<img src=\"" + imagelist[Math.floor(sek / 10)].src + "\"/>";
        else
            document.getElementById('ls5').innerHTML = "";
        document.getElementById('ls6').innerHTML = "<img src=\"" + imagelist[(sek - Math.floor(sek / 10) * 10)].src + "\"/>";
    }
}

var LSpRequest;
var LSaval;
var LSurl;
var LSquery;

function LSInit(url, art, ac)
{
    LSurl = url;
    LSquery = "artid=" + art + "&action=" + ac;
    LSaval = window.setInterval('LSstartAjax()', 60000); //60 sek
}


function LSstartAjax()
{
    var requestURL = LSurl + (LSurl.indexOf('?') > 0 ? "&" : "?") + LSquery + "&ajax=1";
    try
    {
        if (window.XMLHttpRequest)
        {
            LSpRequest = new XMLHttpRequest();
        } else if (window.ActiveXObject)
        {
            LSpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }

        if (LSquery != "")
        {
            LSpRequest.open("GET", requestURL, true);
            LSpRequest.onreadystatechange = LScallbackAjax;
            LSpRequest.send(null);
        } 
    } catch (ex)
    {
    }
}

function LScallbackAjax()
{
    if (LSpRequest.readyState == 4)
    {
        if (LSpRequest.status == 200)
        {
            LShandleResponse(LSpRequest.responseText);
        }
    }
}

function LShandleResponse(text)
{
    try
    {
        var t = parseInt(text, 10)/10;
        if (t >= 0 && t <= 10)
        {
            var elem = document.getElementById('lsavailable');
            var src = elem.getAttribute("src");
            var arr = src.split("_");
            elem.setAttribute("src", arr[0] + "_" + text + ".png");
            if (t == 0)
            {
                document.getElementById('lsbasket').innerHTML = "";
                if (document.getElementById('lsimg').getAttribute("src").indexOf("_end&abtype=") < 0)
                  document.getElementById('lsimg').setAttribute("src", document.getElementById('lsimg').getAttribute("src").replace("&abtype=", "_end&abtype="));
                window.clearInterval(LSaval);
            }
        }
    }
    catch (ex)
    {
    }
}