/* Copyright Scientec Internet Applications + Media GmbH - www.scientec.de */

/****** sofort ******/

var newsession = true;
var wcont = window.name.split("-!-");
document.write('<style media="screen">#M .artikel .check{display:inline}</style>')


session();

function session()
{
  var zeit = new Date();
  cookiesession = getCookie("session");
  if (window.name.indexOf("SAMMLERCABINETT") == -1 && cookiesession.indexOf("SAMMLERCABINETT") == -1)
  {
    var t0 = zeit.getTime();
    sessionid = "SAMMLERCABINETT"+t0;
    window.name = sessionid;
    var t1 = new Date(t0 + 1000*60*60*6);
    document.cookie = "session="+sessionid+"; expires="+t1.toGMTString()+"; path=/";
  }
  else
  {
    if(cookiesession.indexOf("SAMMLERCABINETT") != -1)
    {
      var t0 = zeit.getTime();
      var t1 = new Date(t0 + 1000*60*60*6);
      document.cookie = "session="+cookiesession+"; expires="+t1.toGMTString()+"; path=/";
    }
    if (window.name.indexOf("SAMMLERCABINETT") == -1)
    {
      sessionid = cookiesession;
      window.name = sessionid;
    }
    else { sessionid = wcont[0] }
  }
  newsession = false;
}


/****** nach domready ******/


function init()
{
  SPRACHE=$("html")[0].lang;
  HTML();
  readsession();
  Suchfeld()

  Mailto();
  Links();
}


function readsession()
{
  var zeit = new Date();
  if (!newsession)
  {
    var jsHttp = false;

    /*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest) function XMLHttpRequest() { return new ActiveXObject('Microsoft.XMLHTTP')}@end @*/        

    if (typeof XMLHttpRequest != 'undefined'){jsHttp = new XMLHttpRequest()}
    if (jsHttp)
    {
      jsHttp.open('GET', '/sessions/'+sessionid+'.js?'+zeit.getTime(), true);
      jsHttp.onreadystatechange = function ()
      {
        if (jsHttp.readyState == 4)
        {
          if(jsHttp.status == 200)
          {
            basketverkauf = [];
            basketanzahl = [];
            baskettext = [];
            verkaufszahl = 0;

            for(var c = 0; c < document.getElementsByTagName("input").length; c++)
            {
              if(document.getElementsByTagName("input")[c].id.indexOf("bbox") != -1 && document.getElementsByTagName("input")[c].checked == true)
              {
                var cid = document.getElementsByTagName("input")[c].id.substr(4);
                document.getElementById('bbox'+cid).checked = false;
                document.getElementById('abox'+cid).style.display = '';
                document.getElementById('bbox'+cid).style.display = 'none';
              }
            }
            eval(jsHttp.responseText);
            {
              for (var artikel in basketverkauf)
              {
                if (basketverkauf[artikel] > 0)
                {
                  verkaufszahl++;
                }
                if (document.getElementById('bbox'+artikel))
                {
                  if (basketverkauf[artikel] > 0)
                  {
                    document.getElementById('abox'+artikel).style.display='none';
                    document.getElementById('bbox'+artikel).style.display='inline';
                    document.getElementById('bbox'+artikel).checked = true;
                  }
                  else
                  {
                    basket[artikel] = '';
                  }
                }
              }
            }
            if (document.getElementById('basket'))
            {
              document.getElementById('basket').innerHTML = minibaskethtml;
            }
          }
          if (document.getElementById('miniwarenkorb'))
          {
             document.getElementById('miniwarenkorb').style.display = (window.verkaufszahl)? "block" : "none" 
          }
        }
      }
      jsHttp.send(null);
    }
  }
}


function setarticle(obj,artno,sprache,cval,cbasket,del,anzahl,text)
{
  if (text && text != undefined)
  {
    text = encodeURIComponent(text.replace(/\r/g,"").replace(/\n/g,"-!!-"));
  }
  else
  {
    text = "";
  }
  var zeit = new Date();
  if (obj) { name1=obj.name }
  if (obj.tagName == "INPUT"){ cval = ''}
  var jsHttp = false;

  /*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest) function XMLHttpRequest() { return new ActiveXObject('Microsoft.XMLHTTP')}@end @*/        

  if (typeof XMLHttpRequest != 'undefined'){jsHttp = new XMLHttpRequest()}
  if (jsHttp)
  {
    if(anzahl==0) del = "del";
    if(!anzahl) anzahl = 1;
    jsHttp.open('GET', '/cgi-bin/shop/setarticle.pl?sessionid='+sessionid+'&artno='+artno+'&sprache='+sprache+'&val='+cval+'&del='+del+'&anzahl='+anzahl+'&text='+text+'&timestamp='+zeit.getTime(), true);
    jsHttp.onreadystatechange = function ()
    {
      if (jsHttp.readyState == 4)
      {
        eval(jsHttp.responseText);
        readsession();
        if (cbasket == "1")
        {
          document.getElementById('popup-inhalt').getElementsByTagName('iframe')[0].src='/cgi-bin/shop/warenkorb.pl?sessionid='+sessionid+'&sprache='+sprache;
        }
      }
    }
    jsHttp.send(null);
  }
}

function HTML()
{
  $('#R').append('<div id="ipayment"><a href="http://www.ipayment.de" rel="nofollow" target="_blank"><img src="/onTEAM/layout/img/ipayment.png"></a></div>');
  $('#R').append('<div id="paypal"><a href="#" onclick="javascript:window.open(\'https://www.paypal.com/de/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside\',\'olcwhatispaypal\',\'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=500\');" rel="nofollow"><img src="/onTEAM/layout/img/paypal.png" border="0" alt="PayPal-Standard-Logo"></a></div>');

  if(SPRACHE == "en")
  {
    $('#O').append('<div id="toc" title="Fast navigator"></div>')
    $('#R').append('<div id="miniwarenkorb" class="block"><div class="titel">Selected Items</div><div class="in"><div id="basket"></div><div class="button"><button type="button">Buy now</button></div></div></div>');
    mwst0 = "<a href='/agb_e.html?a#endpreis'>Price</a>";
    mwst7 = "<a href='/agb_e.html?a#endpreis'>Price</a> including VAT";
    mwst19 = "<a href='/agb_e.html?a#endpreis'>Price</a> including VAT";
    mwst = ", excl. <a href='/versandkosten_e.html'>shipment</a>";
    $('body').append('<div id="popup"><div class="abdeckung"></div><div id="popup-titel"><div id="popup-titel-text">Order</div><div id="popup-titel-nav"><a href="#">Back to shop</a></div></div><div id="popup-inhalt"><iframe src="/onTEAM/layout/leer.html" frameborder="0" id="popup-iframe" allowtransparency="1"></iframe></div><div id="popup-hintergrund"></div></div>')
    $('body').append('<div id="popupshow"><div class="abdeckung"></div><div id="popupshow-titel"><div id="popupshow-titel-text">Showroom</div><div id="popupshow-titel-nav"><a href="#">Back to shop</a></div></div><div id="popupshow-inhalt"><iframe src="/onTEAM/layout/leer.html" frameborder="0" id="popupshow-iframe" allowtransparency="1"></iframe></div><div id="popupshow-hintergrund"></div></div>')
    $('#O').append('<div id="print" title="Print this page printerfriendly"></div>')
    $('#O').append('<a id="cc" href="http://fxtop.com/en/adv.htm" target="_blank" rel="nofollow" title="Currency converter"></a>')
    $('#nav').append('<a id="showroom" href="#">Showroom<br><img src="/onTEAM/layout/img/showroom.jpg"></a>')
    $('#R').append('<div title="This site chose Thawte SSL for secure e-commerce and confidential communications" id="ssl"><a target="ssl" href="https://sealinfo.thawte.com/thawtesplash?form_file=fdf/thawtesplash.fdf&amp;dn=WWW.SAMMLER-CABINETT.DE&amp;lang=de"><img src="/onTEAM/layout/img/ssl.png"></a></div>')

    $('#showroom').bind('click', function() { popupshow('on'); document.getElementById('popupshow-iframe').src='/e/showroom/index.shtml';return false});
    $('#miniwarenkorb').bind('click', function() { warenkorb('e')});
  }
  else
  {
    $('#O').append('<div id="toc" title="Schnellauswahl"></div>')
    $('#R').append('<div id="miniwarenkorb" class="block"><div class="titel">Warenkorb</div><div class="in"><div id="basket"></div><div class="button"><button type="button">Jetzt kaufen</button></div></div></div>');
    mwst0 = "<a href='/agb.html?a#endpreis'>Preis</a> ";
    mwst7 = "<a href='/agb.html?a#endpreis'>Preis</a> inklusive Mehrwertsteuer, ";
    mwst19 = "<a href='/agb.html?a#endpreis'>Preis</a> inklusive Mehrwertsteuer, ";
    mwst = " exklusive <a href='/versandkosten.html'>Versandkosten</a>";
    $('body').append('<div id="popup"><div class="abdeckung"></div><div id="popup-titel"><div id="popup-titel-text">Bestellvorgang</div><div id="popup-titel-nav"><a href="#">Zum Shop</a></div></div><div id="popup-inhalt"><iframe src="/onTEAM/layout/leer.html" frameborder="0" id="popup-iframe" allowtransparency="1"></iframe></div><div id="popup-hintergrund"></div></div>')
    $('body').append('<div id="popupshow"><div class="abdeckung"></div><div id="popupshow-titel"><div id="popupshow-titel-text">Showroom</div><div id="popupshow-titel-nav"><a href="#">Zum Shop</a></div></div><div id="popupshow-inhalt"><iframe src="/onTEAM/layout/leer.html" frameborder="0" id="popupshow-iframe" allowtransparency="1"></iframe></div><div id="popupshow-hintergrund"></div></div>')
    $('#O').append('<div id="print" title="Diese Seite druckerfreundlich drucken"></div>')
    $('#O').append('<a id="cc" href="http://fxtop.com/en/adv.htm" target="_blank" rel="nofollow" title="W&auml;hrungsrechner"></a>')
    $('#nav').append('<a id="showroom" href="#">Showroom<br><img src="/onTEAM/layout/img/showroom.jpg"></a>')
    $('#R').append('<div title="Diese Website verwendet Thawte SSL für sicheres E-Commerce und vertrauliche Kommunikation" id="ssl"><a target="ssl" href="https://sealinfo.thawte.com/thawtesplash?form_file=fdf/thawtesplash.fdf&amp;dn=WWW.SAMMLER-CABINETT.DE&amp;lang=de"><img src="/onTEAM/layout/img/ssl.png"></a></div>')
 

    $('#showroom').bind('click', function() { popupshow('on'); document.getElementById('popupshow-iframe').src='/d/showroom/index.shtml';return false});
    $('#miniwarenkorb').bind('click', function() { warenkorb('d')});


 }

  $('#print').bind('click', function() { self.print() });
  $('#popup-titel-nav a').bind('click', function() { popup('off'); return false });
  $('#popup-hintergrund').bind('click', function() { popup('off') });
  $('#popupshow-titel-nav a').bind('click', function() { popupshow('off'); return false });
  $('#popupshow-hintergrund').bind('click', function() { popupshow('off') });
      
  $('#O').append('<div id="TOC"></div>')
  $('#toc').click(function() {
    $('#TOC').load('/katalog.html #cat', function(){
      datei=window.location.pathname.split("26");
      $('#TOC a[href="'+datei+'"]').addClass('on').attr("id","TOCON");
      $('#TOC').css('display','block');
      //if(document.getElementById("TOCON")){ $('#TOC').animate({scrollTop: $("#TOCON").offset().top},200) };
      if($("#TOCON").index()!=-1){ $('#TOC').animate({scrollTop: $("#TOCON").offset().top-20},200) };
      $('#TOC').mouseleave(function()  {
        $('#TOC').animate({scrollTop: 0},0)
        $('#TOC').css('display','none');
      });
    });
  });

  if(document.title.indexOf("Fehler/Error")!=-1){$('#home').before('<div id="e404">Seite nicht gefunden<br>Page not found</div>')}

  $('.mwst').each(function(){
    if($(this).html()==7)$(this).html(mwst7+mwst);
    else if($(this).html()==0)$(this).html(mwst0+mwst);
    else if($(this).html()==19)$(this).html(mwst19+mwst);
    $(this).css("display","block")
  });


}


function warenkorb(sprache)
{
  popup("on");
  var zeit = new Date();
  document.getElementById('popup-inhalt').getElementsByTagName('iframe')[0].src='/cgi-bin/shop/warenkorb.pl?sessionid='+sessionid+'&sprache='+sprache+'&timestamp='+zeit.getTime();
}


function validateForm() {
 var send = 1;
 if (send == 1){if (document.contact.name.value == ""){SPRACHE=="de" ? alert("Bitte tragen Sie Ihren Namen ein.") : alert("Please enter your name."); send = 0; document.contact.name.focus();}}
 if (send == 1){if (document.contact.nachricht.value == ""){SPRACHE=="de" ? alert("Bitte tragen Sie Ihre Nachricht ein.") : alert("Please enter your message."); send = 0; document.contact.nachricht.focus();}}
 if (send==1){return true}
 else {return false}
}


function popup(modus)
{
	if(modus=="on")
	{
        document.getElementById("popup-iframe").src="/onTEAM/layout/leer.html";
        document.getElementsByTagName("body")[0].style.overflow = "hidden";
        document.getElementById("popup").style.visibility = "visible";
        document.getElementById("popup").style.left = "0";
	}
	else if(modus=="off")
	{
        document.getElementById("popup-iframe").src="/onTEAM/layout/leer.html";
        if(window.location.href.indexOf("https:") != -1)
        {
          window.location.href = window.location.href.replace("https:","http:").replace(window.location.search,"");
        }
        else
        {
          readsession();
          document.getElementsByTagName("body")[0].style.overflow = "auto";
          document.getElementById("popup").style.visibility = "hidden";
          document.getElementById("popup").style.left = "-200%";
	  }
	}
}

function popupshow(modus)
{
	if(modus=="on")
	{
        document.getElementById("popupshow-iframe").src="/onTEAM/layout/leer.html";
        document.getElementsByTagName("body")[0].style.overflow = "hidden";
        document.getElementById("popupshow").style.visibility = "visible";
        document.getElementById("popupshow").style.left = "0";
	}
	else if(modus=="off")
	{
        document.getElementById("popupshow-iframe").src="/onTEAM/layout/leer.html";
        document.getElementsByTagName("body")[0].style.overflow = "auto";
        document.getElementById("popupshow").style.visibility = "hidden";
        document.getElementById("popupshow").style.left = "-200%";
	}
}

function showroom(para)
{
  popupshow('on');
  document.getElementById('popupshow-inhalt').getElementsByTagName('iframe')[0].src='/shop/'+para+'.shtml';
}

/*Allgemeine Funktionen*/

function Mailto()
{
	$('em.em').each(function(){
		var EM = $(this).text().replace(/~at~/i,"@");
		$(this).html('<a href="mailto:'+EM+'">'+EM+'</a>');
	});
}

function Links()
{
	$('#nav a[href='+document.location.pathname+']').addClass(function(){ return "on" });
	if($('#pfad').get(0))
	{
		$('#nav a').addClass(function(){
 			if($('#pfad').html().indexOf($(this).attr('href'))!=-1) return "aktiv" 
 			else return  
		});
	}
}

function Suchfeld()
{
	var VAL = {"de":"Suche","en":"Search"};
	var MIN = 2;

	if(document.location.href.indexOf("suche.pl")!=-1)
	{
		$("#q").val(decodeURI(document.location.search.replace(/\?/,"").split("beding=")[1].split("&")[0]).replace(/\+/," "));
	}
	else
	{
		$("#q").val(VAL[SPRACHE]);
	}

	$("#q").bind({
		focus: function(){ if(this.value==VAL[SPRACHE])this.value="" }
	});
	$("#q").bind({
		blur: function(){ if(this.value=="")this.value=VAL[SPRACHE] }
	});
	$("#search").bind({
		submit: function(){ return ($("#q").val().length>=MIN && $("#q").val()!=VAL[SPRACHE]) }
	});
}


function getCookie(name)
{ 
  var c=document.cookie+";";
  start=c.indexOf(name)+name.length+1;
  stop=c.indexOf(";",start);
  keks=c.substring(start,stop);
  return keks
}

function validateNews() {
 var send = 1;
 if (send == 1){if (document.news.name.value == ""){alert("Bitte tragen Sie Ihren Namen ein."); send = 0; document.news.name.focus();}}
 if (send == 1){if (document.news.email.value=="" || document.news.email.value.indexOf('@')== -1 || document.news.email.value.indexOf('.')== -1 || document.news.email.value.length<8){alert("Inkorrekte Emailadresse."); send = 0; document.news.email.focus();}}
 if (send==1){
  return true;
 }
 else {return false;}
}

function validateNewsE() {
 var send = 1;
 if (send == 1){if (document.news.name.value == ""){alert("Please enter your name."); send = 0; document.news.name.focus();}}
 if (send == 1){if (document.news.email.value=="" || document.news.email.value.indexOf('@')== -1 || document.news.email.value.indexOf('.')== -1 || document.news.email.value.length<8){alert("incorrect emailaddress."); send = 0; document.news.email.focus();}}
 if (send==1){
  return true;
 }
 else {return false;}
}
