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

var FORM_beding = "";
basket = [];
basketanzahl = [];
basketverkauf = [];
baskettext = [];
basketgravurtext = [];
basketbemerk = [];
basketmotiv = [];
basketfarbe = [];
basketgfarbe = [];
basketschrift = [];
basketgravurschrift = [];
kundendaten = [];
var zeit = new Date();
var newsession = 1;
var baskethtml = "";
var basketemail = "";
var basketart = "";
var minibaskethtml = "";
var minibaskethtmlanz = "";
var kunde = "";
var anrede = "";
var verkaufszahl = "";
var paymenttext = "";
var cookiesession = "";
cookiesession = getCookie("session");

var _gaq = _gaq || []; 
_gaq.push(['_setAccount', 'UA-27130904-1']);
_gaq.push(['_gat._anonymizeIp']); 
 _gaq.push(['_trackPageview']); 
(function() { 
  var ga = document.createElement('script'); 
  ga.type = 'text/javascript'; 
  ga.async = true; 
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
})();

window.___gcfg = {lang: $('html').attr('lang')};
(function() 
{var po = document.createElement("script");
po.type = "text/javascript"; po.async = true;po.src = "https://apis.google.com/js/plusone.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(po, s);
})();



if (cookiesession.indexOf("STAMPEX") != -1)
{
  window.name = cookiesession;
}
var catordersend = "";
var wcont = window.name.split("-!-");
var displaymod = 0;
var userid = "";
var fotostat = "";
if (!artliste)
{
  var artliste = "";
}

var ref = "";
var zhilfe = "";
hrefarr = document.location.href.split(/\?/);
var search = document.location.search.replace(/\?id=/,"");
var httpdoc = hrefarr[0].replace("https:","http:");
if (top==self)
{
  cookiesession = getCookie("session");
  if (window.name.indexOf("STAMPEX") == -1 && cookiesession.indexOf("STAMPEX") == -1 && top==self)
  {
    var zeit = new Date();
    var sessionid = "STAMPEX"+zeit.getTime();
    window.name = sessionid;
    document.write('<base target="'+sessionid+'">\n');
    var now = new Date();
    var time = new Date(now.getTime() + 1000*60*60*6);
    document.cookie = "session="+sessionid+"; expires="+time.toGMTString()+"; path=/";
    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) {
      var docref = document.referrer.replace(/\?|\&|\+/g," "); 
      docref = docref.replace(/=/g,":");
      jsHttp.open('GET', '/cgi-bin/custom/makesession.pl?ref='+docref+'&page='+hrefarr[0]+'&id='+sessionid+'&query='+search, true);
      jsHttp.send(null);
    }
    zhilfe = "1";
  }
  else
  {
    if (window.name.indexOf("STAMPEX") == -1)
    {
      var sessionid = cookiesession;
      window.name = sessionid;
    }
    else
    {
      var sessionid = wcont[0];
    }
    var jsHttp = false;
    if (typeof XMLHttpRequest != 'undefined'){jsHttp = new XMLHttpRequest()}
    jsHttp.open('GET', '/cgi-bin/custom/tracesession.pl?ref='+hrefarr[0]+'&id='+sessionid+'&query='+search, true);
    jsHttp.send(null);
    newsession = "";
  }
//  alert(window.name);
}

function popupoff()
{
  document.getElementById('popup').style.display='none';
  document.getElementById('ifr1').getElementsByTagName('iframe')[0].src = '/onTEAM/layout/leer.html'
}

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 init()
{

    SPRACHE=$('html').attr('lang');
    readsession();
    mDecode();

    addFunctions()
  if (search.indexOf("ww=") != -1)
  {
    help = search.replace("?ww=","");
    warenkorbon(help);
  }

	$('#motive li .button').each(function(){
		var $t=$(this);
		$t.find('a').removeAttr('href').removeAttr('title');
		$t.append('<div class="auf"></div><div class="zu"></div>');
		$t.click(function(){
			$t.find('.auf,.zu').toggle();
			$t.next().find('.img').each(function(){
				if($(this).attr('title')){
					$(this).css('background-image','url('+$(this).attr('title')+')');
					$(this).removeAttr('title');
				}
			})
			$t.next().slideToggle();
		})
	})

	$('#hotline').mouseenter(function(){
		var $t=$(this).find('.text');
		$t.show();
		$t.animate({left:0},250);
	})
	$('#hotline').mouseleave(function(){
		var $t=$(this).find('.text');
		$t.animate({left:'-242px'},250,function(){$t.hide();});
	})
	$('#facebook').mouseenter(function(){
		var $b=$(this);
		var $i=$(this).find('iframe');
		$i.show();
		$i.animate({left:33},250);
		$b.animate({left:0},250);
	})
	$('#facebook').mouseleave(function(){
		var $b=$(this);
		var $i=$(this).find('iframe');
		$i.animate({left:'-250px'},250,function(){$i.hide();});
		$b.animate({left:"-3px"},250);
	})
	$('#googlep').mouseenter(function(){
		var $b=$(this);
		var $i=$(this).find('.googlep-box');
		$i.show();
		$i.animate({left:33},250);
		$b.animate({left:0},250);
	})
	$('#googlep').mouseleave(function(){
		var $b=$(this);
		var $i=$(this).find('.googlep-box');
		$i.animate({left:'-300px'},250,function(){$i.hide();});
		$b.animate({left:"-3px"},250);
	})

  var ilikeit = document.createElement("div");
  ilikeit.id="ilikeit";
  ilikeit.innerHTML='<iframe src="https://www.facebook.com/plugins/like.php?href='+encodeURIComponent(window.location.href)+'&amp;layout=button_count&amp;show_faces=true&amp;width=115&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=25" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:115px; height:25px;" allowTransparency="true"></iframe><br>';
  $("#M .in").prepend(ilikeit);

  $("#ilikeit").append('<div><g:plusone size="medium"></g:plusone></div>');
  window.___gcfg = {lang: SPRACHE};
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();


}

function imagecash()
{
  if (document.getElementById('motivsrc'))
  {
    if (document.getElementById('motivsrc').value)
    {
      selectImage(document.getElementById('motivsrc').value);
      openarticle();
    }
  }
}

function readsession (mini)
{
  zeit = new Date();
  if (newsession)
  {
  }
  else
  {
    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()+mini, true);
      jsHttp.onreadystatechange = function ()
      {
        if (jsHttp.readyState == 4)
        {
          if(jsHttp.status == 200)
//          if(jsHttp.responseText.indexOf("kunde")!=-1)
          {
            basket = [];
            telefon = [];
            basketverkauf = [];
            gebotszahl = 0;
            verkaufszahl = 0;
            gebotswert = 0;
            eval(jsHttp.responseText);
            if (!mini)
            {
              for (var artikel in basketverkauf)
              {
                if (basketverkauf[artikel] > 0 || basketverkauf[artikel] == "0.00")
                {
                  verkaufszahl++;
                }
                if (document.getElementById('bbox'+artikel) || document.getElementById('abox'+artikel))
                {
                  if (basketverkauf[artikel] > 99999999 || basketverkauf[artikel] == "0.00")
                  {
                    document.getElementById('abox'+artikel).style.display = '';
                    document.getElementById('bbox'+artikel).style.display = '';
//                    document.getElementById('bbox'+artikel).checked = true;
                    if (document.getElementById('textfeld') && baskettext[artikel])
                    {
                      document.getElementById('textfeld').value = baskettext[artikel].replace(/-!-/g,"\n");
                    }
                    if (document.getElementById('bemerk') && basketbemerk[artikel])
                    {
                      document.getElementById('bemerk').value = basketbemerk[artikel].replace(/-!-/g,"\n");
                    }
                    if (document.getElementById('farbe') && basketfarbe[artikel])
                    {
                      document.getElementById('farbe').options[basketfarbe[artikel]].selected=true;
                    }
                    if (document.getElementById('schrift') && basketschrift[artikel])
                    {
                      document.getElementById('schrift').options[basketschrift[artikel]].selected=true;
                    }
                    if (document.getElementById('gravurschrift') && basketgravurschrift[artikel])
                    {
                      document.getElementById('gravurschrift').options[basketgravurschrift[artikel]].selected=true;
                    }
                    if (document.getElementById('anzahl') && basketverkauf[artikel])
                    {
                      document.getElementById('anzahl').src = basketverkauf[artikel];
                    }
                    if (document.getElementById('motiv') && basketmotiv[artikel])
                    {
                      document.getElementById('motiv').src = basketmotiv[artikel];
                    }
                    if (document.getElementById('motivnummer') && basketmotiv[artikel])
                    {
                      var help = basketmotiv[artikel].replace("//","").replace("/onTEAM/motifs/","").replace(".png","").replace(/.*?\//,"");
                      if (help.indexOf("0.gif") == -1)
                      {
                        document.getElementById('motivnummer').value = help;
                      }
                    }
                  }
                  else
                  {
                    basket[artikel] = '';
                    document.getElementById('abox'+artikel).style.display = 'none';
                    document.getElementById('bbox'+artikel).style.display = '';
                  }
                }
              }
            }
            if (document.getElementById('basket'))
            {
              document.getElementById('basket').innerHTML = minibaskethtml;
            }
          }
          if (document.getElementById('miniwarenkorb'))
          {
            if (verkaufszahl)
            {
              document.getElementById('miniwarenkorb').style.display = "block";
            }
            else
            {
              document.getElementById('miniwarenkorb').style.display = "none";
            }
          }
        }
      }
      jsHttp.send(null);
    }
  }
}

function setarticle (obj,artno,sprache,cval,cbasket,del)
{
  if (obj)
  {
    name1=obj.name;
  }
  if (!obj.checked && obj.tagName != 'BUTTON')
  {
    cval = '';
//    document.getElementById('a'+name1).style.display = '';
//    obj.style.display = 'none';
  }
  zeit = new Date();
  var jsHttp = false;
  var textfeld = "";
  var gravurtext = "";
  var bemerk = "";
  var farbe = "";
  var gfarbe = "";
  var motiv = "";
  var anzahl = "";
  var schrift = "";
  var gravurschrift = "";
/*@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 (document.getElementById('textfeld'))
    {
      textfeld = encodeURIComponent(document.getElementById('textfeld').value.replace(/\r/g,"").replace(/\n/g,"-!-"));
    }
    if (document.getElementById('gravurtext'))
    {
      gravurtext = encodeURIComponent(document.getElementById('gravurtext').value.replace(/\r/g,"").replace(/\n/g,"-!-"));
    }
    if (document.getElementById('bemerk'))
    {
      bemerk = encodeURIComponent(document.getElementById('bemerk').value.replace(/\r/g,"").replace(/\n/g,"-!-"));
    }
    if (document.getElementById('motiv'))
    {
      motiv = document.getElementById('motiv').src.replace(/http/i,"https");
    }
    if (document.getElementById('farbe'))
    {
      farbe = document.getElementById('farbe').selectedIndex+1;
    }
    if (document.getElementById('gfarbe'))
    {
      gfarbe = document.getElementById('gfarbe').selectedIndex+1;
    }
    if (document.getElementById('anzahl'))
    {
      anzahl = document.getElementById('anzahl').value;
    }
    else
    {
      anzahl = 1;
    }
    if (document.getElementById('schrift'))
    {
      schrift = document.getElementById('schrift').selectedIndex+1;
    }
    if (document.getElementById('gravurschrift'))
    {
      gravurschrift = document.getElementById('gravurschrift').selectedIndex+1;
    }
    jsHttp.open('GET', '/cgi-bin/shop/setarticle.pl?sessionid='+sessionid+'&motiv='+motiv+'&gfarbe='+gfarbe+'&farbe='+farbe+'&textfeld='+textfeld+'&gravurtext='+gravurtext+'&bemerk='+bemerk+'&gravurschrift='+gravurschrift+'&schrift='+schrift+'&artno='+artno+'&sprache='+sprache+'&anzahl='+anzahl+'&val='+cval+'&del='+del+'&timestamp='+zeit.getTime(), true);
    jsHttp.onreadystatechange = function ()
    {
      if (jsHttp.readyState == 4)
      {
        eval(jsHttp.responseText);
//        if (document.getElementById('miniwarenkorb'))
//        {
//          document.getElementById('basket').innerHTML = baskethtml;
//          document.getElementById('miniwarenkorb').style.display = "block";
//        }
        readsession();
        if (cbasket == "1")
        {
          document.getElementById('ifr1').getElementsByTagName('iframe')[0].src='/cgi-bin/shop/warenkorb.pl?sessionid='+sessionid+'&sprache='+sprache;
        }
      }
    }
    jsHttp.send(null);
  }
}


function warenkorb(sprache){
  document.location.href = document.location.href.replace("http:","https:")+"?ww="+sprache;
}

function warenkorbon(sprache)
{
  document.getElementById('popup').style.display='block';
  document.getElementById('ifr1').getElementsByTagName('iframe')[0].src='/cgi-bin/shop/warenkorb.pl?sessionid='+sessionid+'&sprache='+sprache+'&timestamp='+zeit.getTime();
}

function motivauswahl (auswahl,sprache)
{
  document.getElementById('popup').style.display='block';
  if (sprache == 'd')
  {
    document.getElementById('ifr1').getElementsByTagName('iframe')[0].src='/onTEAM/layout/'+auswahl+'.html';
  }
  else
  {
    document.getElementById('ifr1').getElementsByTagName('iframe')[0].src='/onTEAM/layout/'+auswahl+'_'+sprache+'.html';
  }
}

function selectImage (img)
{
  if (document.getElementById('motiv'))
  {
    document.getElementById('motiv').src = img;
    document.getElementById('motivsrc').value = img;
    if (document.getElementById('uploadform'))
    {
      document.getElementById('uploadform').reset();
    }
  }
}

function togglenav (id)
{
  if (document.getElementById(id))
  {
    if (document.getElementById(id).style.display == 'none')
    {
      document.getElementById(id).style.display = '';
    }
    else
    {
      document.getElementById(id).style.display = 'none';
    }
  }
}

function validateContact(){
  document.contact.Name.style.borderColor="#999";
  document.contact.Firma.style.borderColor="#999";
  document.contact.Email.style.borderColor="#999";
  document.contact.Telefon.style.borderColor="#999";
  if ((document.contact.Name.value=="" || document.contact.Name.value=="Ihr Name") && (document.contact.Firma.value=="" ||document.contact.Firma.value=="Ihre Firma" )){
    document.contact.Name.style.borderColor="red";
    document.contact.Firma.style.borderColor="red";
    alert("Bitte tragen Sie Ihren Namen oder Ihre Firma ein")
    return false;
  }
  if ((document.contact.Email.value=="" || document.contact.Email.value=="Ihre E-Mail Adresse")&& (document.contact.Telefon.value=="" || document.contact.Telefon.value=="Ihre Telefonnummer")){
    document.contact.Email.style.borderColor="red";
    document.contact.Telefon.style.borderColor="red";
    alert("Bitte tragen Sie Ihre Telefonnummer oder Ihre E-Mail-Adresse ein")
    return false;
  }
  document.contact.Submit.disabled="disabled";
  return true
}

function validateContacte(){
  document.contact.Name.style.borderColor="#999";
  document.contact.Firma.style.borderColor="#999";
  document.contact.Email.style.borderColor="#999";
  document.contact.Telefon.style.borderColor="#999";
  if ((document.contact.Name.value=="" || document.contact.Name.value=="Your name") && (document.contact.Firma.value=="" ||document.contact.Firma.value=="Your company" )){
    document.contact.Name.style.borderColor="red";
    document.contact.Firma.style.borderColor="red";
    alert("Please enter your name or your company")
    return false;
  }
  if ((document.contact.Email.value=="" || document.contact.Email.value=="Your e-mail address")&& (document.contact.Telefon.value=="" || document.contact.Telefon.value=="Your telephone number")){
    document.contact.Email.style.borderColor="red";
    document.contact.Telefon.style.borderColor="red";
    alert("Please enter your telephone number or your email address")
    return false;
  }
  document.contact.Submit.disabled="disabled";
  return true
}

function validateContactf(){
  document.contact.Name.style.borderColor="#999";
  document.contact.Firma.style.borderColor="#999";
  document.contact.Email.style.borderColor="#999";
  document.contact.Telefon.style.borderColor="#999";
  if ((document.contact.Name.value=="" || document.contact.Name.value=="Votre nom") && (document.contact.Firma.value=="" ||document.contact.Firma.value=="Votre club" )){
    document.contact.Name.style.borderColor="red";
    document.contact.Firma.style.borderColor="red";
    alert("Veuillez indiquer votre nom ou votre club")
    return false;
  }
  if ((document.contact.Email.value=="" || document.contact.Email.value=="Votre adresse mail")&& (document.contact.Telefon.value=="" || document.contact.Telefon.value=="Votre numéro de téléphone")){
    document.contact.Email.style.borderColor="red";
    document.contact.Telefon.style.borderColor="red";
    alert("Veuillez indiquer votre adresse mail ou votre numéro de téléphone")
    return false;
  }
  document.contact.Submit.disabled="disabled";
  return true
}

function hier(){
}
function over(o){
	o.src=o.src.replace(/-0/,'-1');
	if(!o.onmouseout){o.onmouseout=function(){out(this)}}
}
function out(o){
	if(o.className!="hier")o.src=o.src.replace(/-1/,'-0')
}

function showBestellvorgang(){
  document.getElementById("abdeckung").style.display="block"
  document.getElementById("warenkorbcont").style.display="block"
  document.getElementById("bestellungifr").style.visibility="hidden";
  document.getElementById('warenkorb').contentWindow.document.getElementById("inhalt").innerHTML = document.getElementById('artikel').innerHTML;
}

function hideBestellvorgang(){
  document.getElementById("abdeckung").style.display="none"
  document.getElementById("warenkorbcont").style.display="none"
  document.getElementById("bestellungifr").style.visibility="hidden";
}

function displayOrderForm(lang) {
	if (lang == "e")
	{
	  document.getElementById("bestellungifr").src = "/onTEAM/admin/onselect/info/kundeninfoe.htm";
	}
	else
	{
	  document.getElementById("bestellungifr").src = "/onTEAM/admin/onselect/info/kundeninfo.htm";
	}
	document.getElementById("bestellungifr").style.visibility="visible";
}

function linksMarkieren() {
  for (var i=0; i<document.getElementsByTagName("a").length; i++){
    thisA=document.getElementsByTagName("a")[i];
    thisA.className=(thisA.href==document.location.href)?"hier":"";
  }
}

function abdeckungSchliessen() {
  if (catordersend)
  {
    document.location.reload()
  }
  else
  {
    document.getElementById('gebot').style.display='none';
    document.getElementById('ifr1').getElementsByTagName('iframe')[0].src = '/onTEAM/admin/html/dummy1.htm'
  }
}



/*Allgemeine Funktionen*/

function addFunctions(){
	if(document.getElementById('dyn'))
	{
   // document.getElementById('dyn').innerHTML+='<a href="#" onclick="document.getElementById(\'sitemap\').style.display=\'block\';return false" id="f_sitemap"><img src="/onTEAM/layout/img/sitemap.png" title="Sitemap"></a>';
    if (document.all)document.getElementById('dyn').innerHTML+='<a href="javascript:window.external.AddFavorite(location.href,document.title)" id="f_favoriten" title="Bookmark"><img src="/onTEAM/layout/img/favoriten.png"></a>';
    document.getElementById('dyn').innerHTML+='<a href="#" onclick="self.print();return false" id="f_drucken" title="Print"><img src="/onTEAM/layout/img/drucken.png"></a>';
	}
}



function addLog()
{
  LINKS = document.getElementsByTagName("A");
  for(var i = 0; i < LINKS.length; i++)
  {
    var thisLink= LINKS[i];
    thisLink.onmousedown = function(){clickLog(this,location);this.removeAttribute('onmousedown')};
  }
}

function clickLog(link,location)
{
  var Img = new Image();
  Img.src = "http://www.onwatch.de/onclick.php?url="+link.href+"&location="+location.href+"&pid=wi";
}

function refLog()
{
  if(document.referrer.indexOf(self.location.host) == -1)
  {
    var Img = new Image();
    var ref=encodeURI(document.referrer).replace(/\&/,"__");
    Img.src = "http://www.onwatch.de/referrer.php?referrer="+ref+"&location="+location.href+"&pid=wi";
  }
}

function mDecode()
{
  var EM=document.getElementsByTagName("em");
  if(EM.length>0){
    var mt="m"+"ai"+"lto:";
    for(var i=0;i<EM.length;i++){
      thisEM=EM[i];
      if(thisEM.className=="em"){
        EMSTR=String(thisEM.innerHTML).replace(/~AT~/,"@");
        thisEM.innerHTML='<a href="'+mt+EMSTR+'">'+EMSTR+'</a>';
      }
    }
  }
}

function showWindow(url){
  var h=640;
  var w=480;
  var t=20;
  var l=screen.availWidth-w-30;
  window.open(url,'win','screenX='+l+',screenY='+t+';top='+t+',left='+l+',height='+h+',width='+w+',location=no,menubar=no,toolbar=no,scrollbars=yes, resizable=yes,status=no');
}




