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

/*if(window.XMLHttpRequest){
  window.onload=resizeNav;
  window.onresize=resizeNav;
	var L=115;
}
function resizeNav(){
  //var h = document.getElementById("links").offsetHeight;
	document.getElementById("links").style.position="fixed";
  var b = (document.all)? (document.documentElement)?document.documentElement:document.body : window;
  var H=(document.all)? b.clientHeight : b.innerHeight;
  document.getElementById("links").style.height=H-L+"px";
}
*/
basket = [];
kundendaten = [];
var zeit = new Date();
var newsession = 1;
var baskethtml = "";
var basketemail = "";
var basketart = "";
var minibaskethtml = "";
var minibaskethtmlanz = "";
var kundendaten = "";
var kundennummer = "";
var paymenttext = "";
if (window.name.indexOf("SMPMEDIENSHOP") == -1 && top==self)
{
  var zeit = new Date();
  var sessionid = "SMPMEDIENSHOP"+zeit.getTime();
  window.name = sessionid;
  document.write('<base target="'+sessionid+'">\n');
  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', '/cgi-bin/custom/makesession.pl?id='+sessionid, true);
    jsHttp.send(null);
  }
}
else
{
  var sessionid = window.name;
  newsession = "";
}

function init (){
  if (document.location.href.indexOf('produkte/index.html') != -1 || document.location.href.indexOf('produkte/index_e.html') != -1)
  {
    var togglep = document.location.search.replace("?","");
    if (togglep)
    {
      toggle(togglep);
    }
  }
  readsession();
  hier();
 // if (document.body.id=="homepage"){schwabbel(); window.onresize=schwabbel}
  if (document.location.href.indexOf("cgi-bin/onteamsuche/suche")!=-1){document.getElementById("suchfeld").value=document.getElementById("Begriff").value}

}

function readsession (mini)
{
  var rzeit = new Date();
  if (newsession)
  {
    document.getElementById('loginlink').style.display = '';
  }
  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?'+rzeit.getTime(), true);
      jsHttp.onreadystatechange = function ()
      {
        if (jsHttp.readyState == 4)
        {
		if(jsHttp.responseText.indexOf("baskethtml")!=-1 || jsHttp.responseText.indexOf("kundennummer")!=-1)
		{
                  basket = [];
			eval(jsHttp.responseText);
			if (!mini)
			{
				for (var artikel in basket)
				{
					cartikel = artikel.replace(/ /g,"");
					if (document.getElementById('box'+cartikel))
					{
						$('#box'+cartikel).val(Number(basket[artikel]))	
					}
				}
			}
                     document.getElementById('artikel').innerHTML = baskethtml;
			document.getElementById('artikelorder').innerHTML = basketart;
			document.getElementById('artikelemail').innerHTML = basketemail;
			document.getElementById('basket').innerHTML = minibaskethtml;
      document.getElementById('miniwarenkorb').innerHTML = document.getElementById('miniwarenkorb').innerHTML;
			if (minibaskethtmlanz > 0)
			{
				document.getElementById('seite').style.padding = '40px 0 0 0';
				document.getElementById('miniwarenkorb').style.display = 'block';
			}
			if (kundennummer)
			{
				document.getElementById('logoutlink').style.display = '';
			}
			else
			{
				document.getElementById('loginlink').style.display = '';
			}
		}
		else
		{
		  document.getElementById('loginlink').style.display = '';
		}
     }
      }
    
      jsHttp.send(null);
    }
  }
}

function setarticle (obj,sprache,artnum,del,cbasket,pcountry,subm,pm,extraid)
{
//alert(pcountry)
//alert($(obj).val())
  if (!pm || pm == undefined)
  {
    pm = paymenttext;
  }
  if(!sprache){sprache="d";}
  if (obj)
  {
    if (!extraid || extraid == undefined)
    {
      name1=obj.id.replace(/box/,'').replace(/box/,'').replace(/box/,'');
    }
    else
    {
      name1=extraid.replace(/box/,'').replace(/box/,'').replace(/box/,'');
    }
    if (!cbasket)
    {
      $(obj).val($(obj).val().replace(/[^0-9]/,''));
    }
    var val=$(obj).val();
  }
  else
  {
    var val="";
    name1="";
  }
  zeit = new Date();
  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', '/cgi-bin/custom/setarticle.pl?payment='+paymenttext+'&id='+sessionid+'&val='+val+'&name='+name1+'&artnum='+artnum+'&del='+del+'&country='+pcountry+'&subm='+subm+'&sprache='+sprache+'&cbasket='+cbasket+'&'+zeit.getTime(), true);
    jsHttp.onreadystatechange = function ()
    {
      if (jsHttp.readyState == 4)
      {
	  eval(jsHttp.responseText);
        if (document.getElementById('miniwarenkorb'))
        {
          document.getElementById('artikel').innerHTML = baskethtml;
          document.getElementById('basket').innerHTML = minibaskethtml;
	    document.getElementById('artikelorder').innerHTML = basketart;
	    document.getElementById('artikelemail').innerHTML = basketemail;
          document.getElementById('miniwarenkorb').innerHTML = document.getElementById('miniwarenkorb').innerHTML;
          document.getElementById('miniwarenkorb').style.display = "block";
          document.getElementById('seite').style.padding = '40px 0 0 0';
        }
        if (cbasket)
        {
          document.getElementById('warenkorb').contentWindow.document.getElementById("inhalt").innerHTML = document.getElementById('artikel').innerHTML;
        }
        if (document.art && cbasket)
        {
          if (val < 1)
          {
            document.art.reset();
            basket = [];
          }
         // readsession();
        }
        else
        {
        //  readsession('mini');
        }
      }
    }
    jsHttp.send(null);
  }
}

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 hier(){
  for (var i=0; i<document.getElementById("links").getElementsByTagName("a").length; i++){
		thisA=document.getElementById("links").getElementsByTagName("a")[i];
		thisA.className=(thisA.href==document.location.href || thisA.href==document.location.href+"index.html"  )?"hier":"";
	}
/*
  for (var i=0; i<document.getElementById("top").getElementsByTagName("a").length; i++){
		thisA=document.getElementById("top").getElementsByTagName("a")[i];
		thisA.className=(thisA.href==document.location.href || thisA.href==document.location.href+"index.html"  )?"hier":"";
	}
*/
}

function show (){
	document.getElementsByTagName("html")[0].style.overflow="hidden";
	document.getElementById("abdeckung").style.display="block";
	document.getElementById("splash").style.display="block";
	document.getElementById("miniwarenkorb").style.visibility="hidden";
	document.getElementById("bestellungifr").style.visibility="hidden";
  document.getElementById('warenkorb').contentWindow.document.getElementById("inhalt").innerHTML = document.getElementById('artikel').innerHTML;
}
function hide (){
	document.getElementById("abdeckung").style.display="none";
	document.getElementById("splash").style.display="none";
	document.getElementsByTagName("html")[0].style.overflow="auto";
	document.getElementById("miniwarenkorb").style.visibility="visible";
	document.getElementById("bestellungifr").style.visibility="hidden";
}

function displayOrderForm(lang) {
	document.getElementById("bestellungifr").style.visibility="visible";
	if (lang == "e")
	{
	  document.getElementById("bestellungifr").src = "/onTEAM/admin/onteam/ordere.htm";
	}
	else
	{
	  document.getElementById("bestellungifr").src = "/onTEAM/admin/onteam/order.htm";
	}
}

function setKontaktForm() {
   params=document.location.href.split(/type=|\&box=/);
   if (params[1])
   {
     if (params[2].indexOf("info") != -1)
     {
       document.getElementById(params[1]+"i").checked = true;
     }
     if (params[2].indexOf("angebot") != -1)
     {
       document.getElementById(params[1]+"a").checked = true;
     }
   }
}

function validateForm() {
 var send = 1;
 var pattern=/.*\@.*\..*/;
 if (send == 1){if (document.contact.realname.value == ""){alert("Bitte tragen Sie Ihren Namen ein."); send = 0; document.contact.realname.focus();}}
 if (send == 1){if (document.contact.firma.value == ""){alert("Bitte tragen Sie Ihre Firma ein."); send = 0; document.contact.firma.focus();}}
 if (send == 1){if (document.contact.streetno.value == ""){alert("Bitte tragen Sie die Straße ein."); send = 0; document.contact.streetno.focus();}}
 if (send == 1){if (document.contact.code.value == ""){alert("Bitte tragen Sie die Postleitzahl ein."); send = 0; document.contact.code.focus();}}
 if (send == 1){if (document.contact.town.value == ""){alert("Bitte tragen Sie die Stadt ein."); send = 0; document.contact.town.focus();}}
 if (send == 1){if (document.contact.country.value == ""){alert("Bitte tragen Sie das Land ein."); send = 0; document.contact.country.focus();}}
 if (send == 1){if (document.contact.email.value == ""){alert("Bitte tragen Sie Ihre Emailadresse ein."); send = 0; document.contact.email.focus();}}
 if (send == 1){if ((pattern.test(document.contact.email.value))==false){alert("Bitte geben Sie eine korrekte E-Mailadresse an."); send = 0; document.contact.email.focus();}}
 if (send == 1){if (document.contact.phone.value == ""){alert("Bitte tragen Sie Ihre Telefonnummer ein."); send = 0; document.contact.phone.focus();}}
 if (send==1)
 {
   return true;
 }
 else {return false;}
}

function validateForme() {
 var send = 1;
 var pattern=/.*\@.*\..*/;
 if (send == 1){if (document.contact.realname.value == ""){alert("Please enter your name."); send = 0; document.contact.realname.focus();}}
 if (send == 1){if (document.contact.firma.value == ""){alert("Please enter your company."); send = 0; document.contact.firma.focus();}}
 if (send == 1){if (document.contact.streetno.value == ""){alert("Please enter the street."); send = 0; document.contact.firma.focus();}}
 if (send == 1){if (document.contact.code.value == ""){alert("Please enter the zip code."); send = 0; document.contact.code.focus();}}
 if (send == 1){if (document.contact.town.value == ""){alert("Please enter the town."); send = 0; document.contact.town.focus();}}
 if (send == 1){if (document.contact.country.value == ""){alert("Please enter the country."); send = 0; document.contact.country.focus();}}
 if (send == 1){if (document.contact.email.value == ""){alert("Please enter your email address."); send = 0; document.contact.email.focus();}}
 if (send == 1){if ((pattern.test(document.contact.email.value))==false){alert("Please enter a correct E-Mail address."); send = 0; document.contact.email.focus();}}
 if (send == 1){if (document.contact.phone.value == ""){alert("Please enter your phone number."); send = 0; document.contact.phone.focus();}}
 if (send==1)
 {
   return true;
 }
 else {return false;}
}

function schwabbel() {
  var leftTableH=document.getElementById("leftTable").offsetHeight;
  var leftColH=document.getElementById("leftCol").offsetHeight;
  var rightColH=document.getElementById("rightCol").offsetHeight;
  var rightColDivsH=document.getElementById("angebote").offsetHeight+document.getElementById("news").offsetHeight+document.getElementById("infos").offsetHeight+document.getElementById("partner").offsetHeight;

  var bottomColsH=document.getElementById("lfpCol").offsetHeight+(leftColH-leftTableH)-65;
  document.getElementById("lfpText").style.height=bottomColsH+"px";
  document.getElementById("signText").style.height=bottomColsH+"px";
  document.getElementById("systemsText").style.height=bottomColsH+"px";
  document.getElementById("partnerText").style.height=document.getElementById("partnerText").offsetHeight+rightColH-rightColDivsH-20+"px";
}

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

function plus(ID,lang,extraid) {
  $('#input #'+ID).val( $('#'+ID).val() * 1 + 1  )
  if (extraid && extraid != "undefined")
  {
    setarticle(document.getElementById(ID),lang,'','','','','','',extraid)
  }
  else
  {
    setarticle(document.getElementById(ID),lang,'','','','','','','')
  }
}
function minus(ID,lang,extraid) {
  if ($('#'+ID).val() > 0)
  {
    if ($('#'+ID).val() == 1)
    {
      $('#input #'+ID).val( '' )
    }
    else
    {
      $('#input #'+ID).val( $('#'+ID).val() * 1 - 1  )
    }
    if (extraid && extraid != "undefined")
    {
      setarticle(document.getElementById(ID),lang,'','','','','','',extraid)
    }
    else
    {
      setarticle(document.getElementById(ID),lang,'','','','','','','')
    }
  }
}


function plusminus() {

  $('table.artikel .cart').each(function(){
    var $this=$(this);
    var ID=String($this.attr('id'));
    $this.wrap('<div class="wrap" />');
    $this.after('<div id="'+ID+'plus" class="plus"></div>')
    $this.after('<div id="'+ID+'minus" class="minus"></div>')
    var $plus=$('#'+ID+'plus');
    var $minus=$('#'+ID+'minus');
    $plus.click(function(){
     // $(this).prev().prev().val(($this.val())*1+1);
    //  $this.val(($this.val())*1+1);
      $this.attr('value',$this.attr('value')*1+1);
//document.getElementById(ID).setAttribute('value',document.getElementById(ID).getAttribute('value')*1+1);
//alert(document.getElementById(ID).value)
      setarticle(document.getElementById(ID),'d')
    })
    $minus.click(function(){
      if($this.val()>0){
        $this.val(($this.val())*1-1)
        setarticle(document.getElementById(ID),'d')
      }
    })
  })
}

