//===Global Config===//
var currlang = window.location.pathname.split('/')[1];
var currUrl = 'http://'+window.location.host+'/'+currlang;
var fullurl = document.URL;
//=== Cart Config Start ====//
 var warenkorbname = 'warenkorb';
 var valuesep=';';
 var itemsep='|';
 var warenkorbphp = '/warenkorb.php5';
 var weiterleitung = false;


function test(wort) {
 alert($.cookie(warenkorbname ));
}

function clearCart() {
      $.ajax({
      url: warenkorbphp + "?write=",
      context: document.body,
      success: function(content){
        return(content);
      }
    });
}

function clearAndWrite(text){
    $.ajax({
      url: "/warenkorb.php5?write=",
      context: document.body,
      success: function(content){
            $.ajax({
            url: warenkorbphp + "?write=" + text,
            context: document.body,
            success: function(content){
              return(content);
            }
          });
      }
    });
}

function setAnfrageSession(key, value) {
  $.ajax({
     type: "POST",
     url: "/jsAnfrageSession.php5",
     data: "name=" + key + "&value=" + value + "",
     success: function(msg){

     }
   });
}

function getSessionArray(ArrayName) {
  $.ajax({
     type: "POST",
     url: "/jsAnfrageSession.php5",
     data: "name=" + ArrayName + "",
     success: function(msg){

     }
   });
}

function writeCookie(text,weiterleitung) {
      $.ajax({
        url: warenkorbphp + "?write=" + text,
        context: document.body,
        success: function(content){
          if(weiterleitung == true){
           setNaviCountProducts();
          }
        }
      });
}

function verarbeiteAntwort(antwort, produktnr, anzahl, produktname,weiterleitung) {
if(produktnr != ""){
   if(antwort !="") {
     addToCart(antwort.split(itemsep), produktnr, anzahl, produktname,weiterleitung);
   } else {
    writeCookie(produktnr+valuesep+anzahl+valuesep+produktname,weiterleitung);
   }
 }
}

function editProduct(produktnr,anz){
     $.ajax({
      url: warenkorbphp + "",
      context: document.body,
      success: function(content){
        inhalt=content;
      }
    });
}

function fillCart(produktnr, anzahl, produktname, weiterleitung) {
var inhalt="";
    $.ajax({
      url: warenkorbphp + "",
      context: document.body,
      success: function(content){
        inhalt=content;
        parent.$("h1").css("font-family","LeagueGothicSemiCondensed");
        parent.$("h2").css("font-family","LeagueGothicSemiCondensed");
        verarbeiteAntwort(inhalt, produktnr, anzahl, produktname, weiterleitung);
      }
    });
}

/* Addiert die bestehende Produktanzahl + die Eingabe
function addToCart(itemArray, produkt, anzahl) {
   var items = itemArray;
   var itemFound = false;
   for (var i = 0; i < items.length ; i++)
   {
    if (items[i].split(valuesep)[0] == produkt) {
      items[i] = items[i].split(valuesep)[0] + valuesep + (parseInt(items[i].split(valuesep)[1]) + parseInt(anzahl));
      itemFound= true;
    }
   }
   if (itemFound != true) {items.push(produkt + valuesep + anzahl); }
   saveToCookie(items);
}*/


function addToCart(itemArray, produkt, anzahl, produktname, weiterleitung) {
   var items = itemArray;
   var itemFound = false;
   for (var i = 0; i < items.length ; i++)
   {
    if (items[i].split(valuesep)[0] == produkt) {
      items[i] = items[i].split(valuesep)[0] + valuesep + (anzahl) + valuesep + produktname;
      itemFound= true;
    }
   }
   if (itemFound != true) {items.push(produkt + valuesep + anzahl + valuesep + produktname); }
   saveToCookie(items, weiterleitung);
}

function saveToCookie(itemArray, weiterleitung) {
   var itemstring = "";
   if (itemArray.length > 0){
     for (var i = 0; i < itemArray.length; i++) {
      itemstring = itemstring + itemArray[i] + itemsep;
     }
     itemstring=itemstring.substr(0, itemstring.length - 1);
   }else {
     itemstring = "";
     }
   writeCookie(itemstring, weiterleitung);
}

function deleteProduct(elem) {
  answer = confirm(txtquest);
  if (answer){
     $(elem).hide();
     var newCart = new Array();
     $.ajax({
       url: warenkorbphp + "",
       context: document.body,
       success: function(content){
        var cart = content.split(itemsep);
        if (cart.length > 0 ){
          for (var i = 0; i < cart.length; i++) {
             if(cart[i].split(valuesep)[0] != $(elem).attr("id"))
             {
              newCart.push(cart[i]);
             }
          }
          if(cart.length==1) {
            $("#nav_produktauswahl").html('<li id="nav_produktauswahl" class="navLevel1"><span id="produktauswahl_anzahl"></span></li>');
          } else {
          var cartCount=parseInt(cart.length)-1;
            $("#produktauswahl_anzahl").html("(" + cartCount +")");
          }
        } else { newCart=true;
         }
        saveToCookie(newCart);
       }
     });
  }
  else{
    return 0;
  }
}

function setInputCount(produktnr,elem) {
    var anzahl = 0;
    $.ajax({
      url: warenkorbphp + "",
      context: document.body,
      success: function(content){
         if (content != ""){
         var cart = content.split(itemsep);
         for (var i = 0; i < cart.length; i++) {
          if(cart[i].split(valuesep)[0] == produktnr)
          {
           anzahl = cart[i].split(valuesep)[1];
           $(elem).attr("value",anzahl);
          }
         }
       }
      }
    });
}

function setTableCount(produktnr,elem) {
    var produktliste = new Array();
    var warenkorb = "";
     $("table.produktAnzahl").each(function(i, elem) {
       produktliste.push(elem);
     });
     $.ajax({
      url: warenkorbphp + "",
      context: document.body,
      success: function(content)
      {
         var cart = content.split(itemsep);
         for (var i = 0; i < cart.length; i++)
         {
          for (var k = 0; k < produktliste.length; k++)
          {
           if (cart[i].split(valuesep)[0] == produktliste[k].id)
           {
            $(produktliste[k]).show();
           }
          }
         }
      }
    });
}

function hideProducts()
{
      $("table.produktAnzahl[name=0]").each(function(i, elem) {
      if (elem.attr("name") > 0) {
       $(elem).show();
      } else { $(elem).hide(); }
         });
}

//=== CART ENDE==============//

function getStandort() {

    var standorte={
      "11": "standort-heiligenhaus.php",
      "12": "standort-muenchen.php",
      "13": "standort-gelnhausen.php",
      "14": "standort-stuttgart.php",
      "15": "standort-hannover.php",
      "16": "standort-hamburg_glinde.php",
      "22": "standort-gerstungen.php",
      "24": "standort-karlsruhe.php",
      "25": "standort-dohna.php",
      "26": "standprt-rostock.php",
      "27": "standort-berlin.php",
      "28": "standort-dohna.php"
    };//28-standort-gerichshain.php

    var standortPLZ=$('#standortPLZ').val();
    $.ajax({
      url: "/standorte.php?plz="+standortPLZ,
      context: document.body,
      success: function(content){
        if(typeof standorte[content]=='undefined') {
          document.location.href=currUrl+'/standorte/index.php';
        } else {
          document.location.href=currUrl+'/standorte/' + standorte[content];
        }
      }
    });
  }


function getStandort2() {

    var standorte={
      "11": "standort-heiligenhaus.php",
      "12": "standort-muenchen.php",
      "13": "standort-gelnhausen.php",
      "14": "standort-stuttgart.php",
      "15": "standort-hannover.php",
      "16": "standort-hamburg_glinde.php",
      "22": "standort-gerstungen.php",
      "24": "standort-karlsruhe.php",
      "25": "standort-dohna.php",
      "26": "standprt-rostock.php",
      "27": "standort-berlin.php",
      "28": "standort-dohna.php"
    };//28-standort-gerichshain.php

    var standortPLZ2=$('#standortPLZ2').val();
    $.ajax({
      url: "/standorte.php?plz="+standortPLZ2,
      context: document.body,
      success: function(content){
        if(typeof standorte[content]=='undefined') {
          document.location.href=currUrl+'/standorte/index.php';
        } else {
          document.location.href=currUrl+'/standorte/' + standorte[content];
        }
      }
    });
  }

/* Fügt eine Leerzeile in die Navigation ein und zeigt, wenn vorhanden, die Anzahl der Produkte an */
function setNaviCountProducts() {

  $.ajax({
      url: warenkorbphp + "",
      context: document.body,
      success: function(content) {
      if(content.length > 0 && typeof content != 'undefined') {
          if(parent.$("#nav_produktauswahl").html()=="") {
            parent.$("#nav_produktauswahl").html('<a class="navLevel1" href="'+currUrl+'/produktauswahl/index.php">'+produktauswahl+' <span id="produktauswahl_anzahl">(' + content.split(itemsep).length + ')</span></a>');
          } else {
            parent.$("#produktauswahl_anzahl").html("(" + content.split(itemsep).length + ")");
          }
          document.location.href=currUrl+'/produktauswahl/done.php';
        }
      }
    });
}

/* Fügt eine Leerzeile in die Navigation ein und zeigt, wenn vorhanden, die Anzahl der Produkte an (aus der Fancybox heraus) */
function setNaviCountProductsFancy() {
  $.ajax({
      url: warenkorbphp + "",
      context: document.body,
      success: function(content) {
        if(content.length > 0 && typeof content != 'undefined') {
          if (content.split(itemsep).length > 0) {
            parent.$("#nav_produktauswahl").css("visibility", "hidden");
            $("#produktauswahl_anzahl").html("(" + content.split(itemsep).length + ")");
          } else {
            parent.$("#nav_produktauswahl").css("visibility", "hidden");
          }
        }
      }
    });
}

function hideWarenkorbItems() {
  var alleprodukte = new Array(); //Array mit Produkten
  $("table.produktauswahl_liste_einspaltig_table").each(function(i, elem) {
     alleprodukte.push(elem);
     $(elem).hide();
  });
  $.ajax({
  url: warenkorbphp + "",
  context: document.body,
  success: function(content) {
   if (content != "") {
    var warenkorbprdukte = content.split(itemsep);
    for (var i = 0; i < warenkorbprdukte.length; i++) {
     for (var j = 0; j < alleprodukte.length; j++) {
      if(warenkorbprdukte[i].split(valuesep)[0] == $(alleprodukte[j]).attr('id')) {
       $(alleprodukte[j]).show(); //HTML Element anzeigen
       $('#input_'+($(alleprodukte[j]).attr('id'))).val(warenkorbprdukte[i].split(valuesep)[1]);
       //setInputCount($(alleprodukte[j]).attr('id'), '#input_'+$(alleprodukte[j]).attr('id'));
      }
     }
    }
   }
  }
  });
}

function ksort (inputArr, direction,sort_flags) {
    // +   original by: GeekFG (http://geekfg.blogspot.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    var tmp_arr = {},
        keys = [],
        sorter, i, k, that = this,
        strictForIn = false,
        populateArr = {};

    switch (sort_flags) {
    case 'SORT_STRING':        // compare items as strings
        sorter = function (a, b) {
            return that.strnatcmp(a, b);
        };
        break;    case 'SORT_LOCALE_STRING':
        // compare items as strings, based on the current locale (set with  i18n_loc_set_default() as of PHP6)
        var loc = this.i18n_loc_get_default();
        sorter = this.php_js.i18nLocales[loc].sorting;
        break;    case 'SORT_NUMERIC':
        // compare items numerically
        sorter = function (a, b) {
            return ((a + 0) - (b + 0));
        };
        break;
        // case 'SORT_REGULAR': // compare items normally (don't change types)
    default:
        sorter = function (a, b) {
            var aFloat = parseFloat(a),
                bFloat = parseFloat(b),
                aNumeric = aFloat + '' === a,
                bNumeric = bFloat + '' === b;
            if (aNumeric && bNumeric) {
                return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0;
            }
            else if (aNumeric && !bNumeric) {
                return 1;
            } else if (!aNumeric && bNumeric) {
                return -1;
            }
            if(direction=="ASC") {
              return a > b ? 1 : a < b ? -1 : 0;
            } else {
              return a < b ? 1 : a > b ? -1 : 0;
            }
        };
        break;
    }
     // Make a list of key names
    for (k in inputArr) {
        if (inputArr.hasOwnProperty(k)) {
            keys.push(k);
        }    }
    keys.sort(sorter);

    // BEGIN REDUNDANT
    this.php_js = this.php_js || {};    this.php_js.ini = this.php_js.ini || {};
    // END REDUNDANT
    strictForIn = this.php_js.ini['phpjs.strictForIn'] && this.php_js.ini['phpjs.strictForIn'].local_value && this.php_js.ini['phpjs.strictForIn'].local_value !== 'off';
    populateArr = strictForIn ? inputArr : populateArr;
     // Rebuild array with sorted key names
    for (i = 0; i < keys.length; i++) {
        k = keys[i];
        tmp_arr[k] = inputArr[k];
        if (strictForIn) {
          delete inputArr[k];
        }
    }
    for (i in tmp_arr) {
        if (tmp_arr.hasOwnProperty(i)) {
          populateArr[i] = tmp_arr[i];
        }
    }
    return strictForIn || populateArr;
}

function loadFancy(elemid) {
                $(elemid).attr(elemid, elemid).fancybox({
    'titlePosition'     : 'inside',
    'overlayShow'       : true
  });
  //$('#fancy_overlay').css('background-color', '#000000');
}


function sortreferences(currentsorting,sortto)
{
  var htmlContent="";
  var items={};
  items[0]={};
  $.each($(".ein_eintrag"), function(i, elem) {
   items[0][$(this).children().attr(sortto)]=$(this).html();
  });
  $("#listCompact").html("");

  if (currentsorting == "ASC") { $("#listCompact").attr("sorting", "DESC"); items[0]=ksort(items[0],"DESC"); }
                         else  { $("#listCompact").attr("sorting", "ASC"); items[0]=ksort(items[0],"ASC"); }
  var CurCounter=0;
  $.each(items[0], function(i, elem) {
    $("#listCompact").append("<li class='ein_eintrag'>"+elem+"</li>");
  });
}

// decrypt helper function
function decryptCharcode(n,start,end,offset) {
  n = n + offset;
  if (offset > 0 && n > end) {
    n = start + (n - end - 1);
  } else if (offset < 0 && n < start) {
    n = end - (start - n - 1);
  }
  return String.fromCharCode(n);
}

// decrypt string
function decryptString(enc,offset) {
  var dec = "";
  var len = enc.length;
  for(var i=0; i < len; i++) {
    var n = enc.charCodeAt(i);
    if (n >= 0x2B && n <= 0x3A) {
      dec += decryptCharcode(n,0x2B,0x3A,offset); // 0-9 . , - + / :
    } else if (n >= 0x40 && n <= 0x5A) {
      dec += decryptCharcode(n,0x40,0x5A,offset); // A-Z @
    } else if (n >= 0x61 && n <= 0x7A) {
      dec += decryptCharcode(n,0x61,0x7A,offset); // a-z
    } else {
      dec += enc.charAt(i);
    }
  }
  return dec;
}

function activateNavipoint(id) {

  $(id).attr("class","navLevel1Selected");
  $(id).children().attr("class","navLevel1Selected");
  //alert($(id).child.html());
  //$(id).child[0].addClass("navLevel1Selected");
}

// decrypt spam-protected emails
function linkTo_UnCryptMailto(s) {
  location.href = decryptString(s,-1);
}

 function checkBrowserName(name){
   var agent = navigator.userAgent.toLowerCase();
   if (agent.indexOf(name.toLowerCase())>-1) {
     return true;
   }
   return false;
 }

  function checkBrowserVers(name, version, major){
   if (checkBrowserName(name)) {
    var agent = navigator.userAgent.toLowerCase();
    var vers = agent.substr(agent.indexOf(name.toLowerCase())+name.length+1,agent.indexOf(name.toLowerCase())+3);
    if(major) { vers = vers.substr(0,1); }
    if (vers == version) {
      return true;
    }
   }
   return false;
 }


/* ON LOAD ****/
function onPageLoad() {

  hideWarenkorbItems();

  //Standort Finder
  $("#standortPLZ").keypress(function(event) {
  if(event.keyCode == '13')
  {getStandort();}
});

  $("#standortPLZ2").keypress(function(event) {
  if(event.keyCode == '13')
  {getStandort2();}
});

  /* Positionierung für Formulare*/

  //KONTAKTFORMULAR
  $("#kontakt_kommentar").parent().css("position", "absolute");
  $("#kontakt_kommentar").parent().css("bottom", "184px");
  $("#kontakt_kommentar").parent().css("left", "370px");
  $("#kontakt_kommentar").css("width", "372px");
  $("#kontakt_kommentar").css("height", "447px");

  $("#kontakt_rueckruf").parent().parent().css("margin-top", "20px");

  $("#infotext_kontakt").parent().css("position", "absolute");
  $("#infotext_kontakt").parent().css("bottom", "680px");
  $("#infotext_kontakt").parent().css("left", "370px");
  $("#infotext_kontakt").css("white-space", "normal");
  $("#infotext_kontakt").parent().css("width", "365px");
  $("#infotext_kontakt").parent().css("background", "transparent");
  $("#infotext_kontakt").parent().css("padding-left", "0px");

  $("label[for=element_377425]").parent().css("margin-top", "20px");
  $("label[for=element_377425]").parent().css("margin-bottom", "20px");


  //CALLBACKFORMULAR
  if(checkBrowserName('firefox')){
  $("#Mitteilung").parent().css("position", "absolute");
  $("#Mitteilung").parent().css("bottom", "123px");
  $("#Mitteilung").parent().css("left", "370px");
  $("#Mitteilung").css("width", "372px");
  $("#Mitteilung").css("height", "340px");
  } else if (checkBrowserName('MSIE')) {
    $("#Mitteilung").parent().css("position", "absolute");
    $("#Mitteilung").parent().css("bottom", "123px");
    $("#Mitteilung").parent().css("left", "370px");
    $("#Mitteilung").css("width", "372px");
    $("#Mitteilung").css("height", "340px");
    }
  else {
    $("#Mitteilung").parent().css("position", "absolute");
    $("#Mitteilung").parent().css("bottom", "123px");
    $("#Mitteilung").parent().css("left", "370px");
    $("#Mitteilung").css("width", "372px");
    $("#Mitteilung").css("height", "360px");
  }
  $("#kontakt_rueckruf").parent().parent().css("margin-top", "20px");


  $("label[for=element_377425]").parent().css("margin-top", "20px");
  $("label[for=element_377425]").parent().css("margin-bottom", "20px");

  //BESTELLUNG - IHRE KUNDENDATEN
  $("label[for=element_155768]").parent().css("margin-top", "20px");
  $("label[for=element_155768]").parent().css("margin-bottom", "20px");

  $("label[for=element_369311]").parent().css("position", "absolute");
  $("label[for=element_369311]").parent().css("bottom", "50px");
  $("label[for=element_369311]").parent().css("left", "370px");
  $("label[for=element_369311]").css("white-space", "normal");
  $("label[for=element_369311]").parent().css("width", "357px");

  $("#bestellung_kundendaten_infotext").parent().css("padding-left", "0px");

  //BESTELLUNG - IHRE LIEFERDATEN
  $("label[for=lieferdaten_land]").parent().css("margin-bottom", "50px");
  $("label[for=label1]").parent().css("margin-bottom", "10px");
  $("label[for=lieferdaten_ansprechpartner_telefon]").parent().css("margin-bottom", "50px");
  $("label[for=lieferdaten_liefertermin_datum]").parent().css("margin-bottom", "20px");
  //$("label[for=liegt_noch_nicht_fest_Abholterminliegtnochnichtfest]").parent().parent().css("margin-bottom", "20px");
  $('input[name*="liegt_noch_nicht_fest"]').parent().parent().css("margin-bottom", "20px");

  $("label[for=lieferdaten_liefertermin_bemerkung]").parent().css("position", "absolute");
  $("label[for=lieferdaten_liefertermin_bemerkung]").parent().css("bottom", "113px");
  $("label[for=lieferdaten_liefertermin_bemerkung]").parent().css("left", "370px");

  $("#lieferdaten_liefertermin_bemerkung").css("width", "357px");
  $("#lieferdaten_liefertermin_bemerkung").css("height", "117px");

  $("label[for=label4]").parent().css("margin-top", "20px");

  $("label[for=element_347954]").parent().css("position", "absolute");
  $("label[for=element_347954]").parent().css("bottom", "48px");
  $("label[for=element_347954]").parent().css("left", "370px");
  $("label[for=element_347954]").css("white-space", "normal");
  $("label[for=element_347954]").parent().css("width", "357px");

  $("#bestellung_lieferdaten_infotext").parent().css("padding-left", "0px");

  //ANFRAGE - IHRE KUNDENDATEN
  $("label[for=element_156074]").parent().css("position", "absolute");
  $("label[for=element_156074]").parent().css("bottom", "54px");
  $("label[for=element_156074]").parent().css("left", "370px");
  $("label[for=element_156074]").css("white-space", "normal");
  $("label[for=element_156074]").parent().css("width", "357px");

  $("label[for=kundendaten_kundennummer]").parent().css("margin-right", "10px");
  $("label[for=kundendaten_anrede]").parent().css("margin-right", "6px");
  $("label[for=kundendaten_firma]").parent().css("margin-right", "10px");

  $("#anfrage_kundendaten_infotext").parent().css("padding-left", "0px");
  $("#produktauswahl_infotext").parent().css("padding-left", "0px");

  //ANFRAGE - IHRE LIEFERDATEN
  $("label[for=element_191013]").parent().css("position", "absolute");
  $("label[for=element_191013]").parent().css("bottom", "50px");
  $("label[for=element_191013]").parent().css("left", "370px");
  $("label[for=element_191013]").css("white-space", "normal");
  $("label[for=element_156074]").parent().css("width", "357px");
  if($("#lieferdaten_liefertyp_anfrage").val()=="Event") {
  $("#lieferdaten_liefertermin_bemerkung").css("height","270px");
  }
  if($("#lieferdaten_liefertyp_bestellung").val()=="Event") {
  $("#lieferdaten_liefertermin_bemerkung").css("height","270px");
  }

  $("#anfrage_lieferdaten_infotext").parent().css("padding-left", "0px");

  //ANFRAGE - LIEFERDATEN (EVENT)
  $("#lieferdaten_event_infotext").parent().css("padding-left", "0px");

  //ANFRAGE - LIEFERDATEN (SONSTIGES)
  $("#lieferdaten_sonstiges_infotext").parent().css("padding-left", "0px");

  //RÜCKRUF
  $("label[for=element_237075]").parent().css("margin-top", "20px");
  $("label[for=element_237075]").parent().css("margin-bottom", "20px");

  $("label[for=element_299063]").parent().css("position", "absolute");
  $("label[for=element_299063]").parent().css("bottom", "54px");
  $("label[for=element_299063]").parent().css("left", "370px");
  $("label[for=element_299063]").css("white-space", "normal");
  $("label[for=element_299063]").parent().css("width", "357px");


  //IMPRESSUM
  $("#impressum_agb").parent().css("padding-left","0px");
  $("a#datenschutz").fancybox({
         'width': 500,
         'height': 400,
         'scrolling': 'yes',
         'titleShow': 'false',
         'type': 'iframe',
         'opacity': 'true',
         'overlayColor'  : '#000000',
         'onComplete'   : function(){
         $("#fancybox-title-main").css("display","none");
         $("#fancybox-frame").css("overflow","scroll");
         $("#fancybox-frame").attr("scrolling","yes");
         $("#fancybox-title-right").css("display","none");
         $("#fancybox-title-left").css("display","none");
         }
      });



 $.fn.exists = function(){
    return $(this).is('*');
  }

 if($('#textanfrage').exists()) // Deutsch
 {

     $.ajax({
      url: warenkorbphp + "",
      context: document.body,
      success: function(content){
      //Anfrage Bestellung - Text + Anzahl setzen
        if(content.length > 0 && content != 'undefined')
        {
         if (content.split(itemsep).length > 1) { //Sachen im Warenkorb?
           $('#textanfrage').parent().parent().parent().click(function() {
            self.location.href=currUrl+'/formulare/anfrage_kundendaten_privat.php';return false;
           });//Hyperlink setzen
           $('#textbestellung').parent().parent().parent().click(function() {
            self.location.href=currUrl+'/formulare/bestellung_kundendaten_privat.php';return false;
           });//Hyperlink setzen
          $('#textanfrage').html('<b>'+textanfrage_uschrift+'</b><br/>'+textanfrage_leer);
          $('#textbestellung').html('<b>'+textbestellung_uschrift+'</b><br/>'+textbestellung_leer);
         } else{
           $('#textanfrage').parent().parent().parent().click(function() {
            self.location.href=currUrl+'/formulare/anfrage_kundendaten_privat.php';return false;
           });//Hyperlink setzen
           $('#textbestellung').parent().parent().parent().click(function() {
            self.location.href=currUrl+'/formulare/bestellung_kundendaten_privat.php';return false;
           });//Hyperlink setzen
           $('#textbestellung').parent().parent().parent().attr('onclick', 'test'); //Hyperlink setzen
           $('#textanfrage').html('<b>'+textanfrage_uschrift+'</b><br/>'+textanfrage_leer);
           $('#textbestellung').html('<b>'+textbestellung_uschrift+'</b><br/>'+textbestellung_leer);
         }
        } else {
         $('#textanfrage').parent().parent().parent().click(function() {
          self.location.href=currUrl+'/produktauswahl/anfrage_vorauswahl.php';return false;
         });//Hyperlink setzen
         $('#textbestellung').parent().parent().parent().click(function() {
          self.location.href=currUrl+'/produkte/index.php';return false;
         });//Hyperlink setzen
         $('#textanfrage').html('<b>'+textanfrage_uschrift+'</b><br/>'+textanfrage_full);
         $('#textbestellung').html('<b>'+textbestellung_uschrift+'</b><br/>'+textbestellung_full);
        }
      }
    });
 }



//Change Events für die Formulare (Kundentypen, Lieferarten)
$('#kundendaten_kundentyp_anfrage').change(function () {
  if ($('#kundendaten_kundentyp_anfrage').val() == 'privater Kunde')
  {
   document.location.href=currUrl+'/formulare/anfrage_kundendaten_privat.php';
  }
  if ($('#kundendaten_kundentyp_anfrage').val() == 'Verein, Öffentliche Institution')
  {
   document.location.href=currUrl+'/formulare/anfrage_kundendaten_verein_oeffentliche_institution.php';
  }
  if ($('#kundendaten_kundentyp_anfrage').val() == 'Gewerblicher Kunde')
  {
   document.location.href=currUrl+'/formulare/anfrage_kundendaten_gewerblicher_kunde.php';
  }
});

$('#lieferdaten_liefertyp_anfrage').change(function () {
  if ($('#lieferdaten_liefertyp_anfrage').val() == 'Bau')
  {
   document.location.href=currUrl+'/formulare/anfrage_lieferdaten_bau.php';
  }
  if ($('#lieferdaten_liefertyp_anfrage').val() == 'Event')
  {
   document.location.href=currUrl+'/formulare/anfrage_lieferdaten_event.php';
  }
  if ($('#lieferdaten_liefertyp_anfrage').val() == 'Sonstiges')
  {
   document.location.href=currUrl+'/formulare/anfrage_lieferdaten_sonstiges.php';
  }
});


$('#kundendaten_kundentyp_bestellung').change(function () {
  if ($('#kundendaten_kundentyp_bestellung').val() == 'privater Kunde')
  {
   document.location.href=currUrl+'/formulare/bestellung_kundendaten_privat.php';
  }
  if ($('#kundendaten_kundentyp_bestellung').val() == 'Verein, Öffentliche Institution')
  {
   document.location.href=currUrl+'/formulare/bestellung_kundendaten_verein_oeffentliche_institution.php';
  }
  if ($('#kundendaten_kundentyp_bestellung').val() == 'Gewerblicher Kunde')
  {
   document.location.href=currUrl+'/formulare/bestellung_kundendaten_gewerblicher_kunde.php';
  }
});


$('#lieferdaten_liefertyp_bestellung').change(function () {
  if ($('#lieferdaten_liefertyp_bestellung').val() == 'Bau')
  {
   document.location.href=currUrl+'/formulare/bestellung_lieferdaten_bau.php';
  }
  if ($('#lieferdaten_liefertyp_bestellung').val() == 'Event')
  {
   document.location.href=currUrl+'/formulare/bestellung_lieferdaten_event.php';
  }
  if ($('#lieferdaten_liefertyp_bestellung').val() == 'Sonstiges')
  {
   document.location.href=currUrl+'/formulare/bestellung_lieferdaten_sonstiges.php';
  }
});

//Warenkorb Button Fancybox zuweisen
 $("span.produktWarenkorb").each(function(i, elem) {
     var name = $(elem).attr('name');
     jQuery(elem).fancybox({"type": "iframe", "href":currUrl+"/produktauswahl/add.php?pnr=" + elem.id +"&pname="+name, "width":500, "height":400});
 });



//Events - Produktauswahl "Weiter" Buttons
$('#btn_unten_anfrage').click(function() {
document.location.href=currUrl+'/formulare/anfrage_abschicken.php';
});

$('#btn_unten_bestellung').click(function() {
document.location.href='bestellung_abschicken.php';
});

$('#btn_unten_uebersicht').click(function() {
document.location.href=currUrl+'/formulare/index.php';
});

$('#btn_unten_uebersicht_anfordern').click(function() {
document.location.href=currUrl+'/formulare/anfrage_kundendaten_privat.php';
});

$('#btn_unten_uebersicht_bestellen').click(function() {
document.location.href=currUrl+'/formulare/bestellung_kundendaten_privat.php';
});

$('#btn_unten_anfrage_abschicken').click(function() {
if($("#anfrage_abschicken_checkbox_datenschutz").is(":checked")) {
  if($("#anfrage_abschicken_checkbox").is(":checked")) {
    setAnfrageSession($("#anfrage_abschicken_rufnummer").attr("id"), $("#anfrage_abschicken_rufnummer").find("input").val());
  }
    $("#datenschutz_err").hide();
    document.location.href=currUrl+'/formulare/anfrage_sent.php';
  } else {
    $("#datenschutz_err").show();
  }
});

$('#btn_unten_bestellung_abschicken').click(function() {
  if($("#anfrage_abschicken_checkbox_datenschutz").is(":checked")) {
    $("#datenschutz_err").hide();
    document.location.href=currUrl+'/formulare/bestellung_sent.php';
  } else {
    $("#datenschutz_err").show();
  }
});

//Neues Produkt hinzufügen, Input mit aktueller Auswahl füllen
setInputCount($('#pname').html(),$('#panz'));

//Grauer Button Hover Events
$(':button').mouseover(function() {
  $(this).css("background-color", "#F32837");
});

$(':button').mouseout(function() {
  $(this).css("background-color", "#8C8D8E");
});

//Checkbox Rufnummer ein/ausblenden (anfrage_abschicken.php)
if($('#anfrage_abschicken_checkbox:checked').val() == undefined) { $('#anfrage_abschicken_rufnummer').hide(); }
$('#anfrage_abschicken_checkbox').click(function() {
  if($('#anfrage_abschicken_checkbox:checked').val() != undefined) { //kein Rückruf Wunsch
      $('#anfrage_abschicken_rufnummer').show();
    } else {
      $('#anfrage_abschicken_rufnummer').hide();
    }
});

//Abholdatum ausblenden wenn nicht fest
    if ($('input[name*="liegt_noch_nicht_fest"]').is(':checked') == false) {
  //if($('#liegt_noch_nicht_fest_Abholdatumliegtnochnichtfest').is(':checked') == false) {
     $('#lieferdaten_abholtermin_datum').parent().show();
     $('label[for=lieferdaten_abholtermin_datum]').show();
     $('label[for=lieferdaten_abholtermin_datum]').parent().show();
    } else {
     $('#lieferdaten_abholtermin_datum').parent().hide();
     $('label[for=lieferdaten_abholtermin_datum]').hide();
     $('label[for=lieferdaten_abholtermin_datum]').parent().hide();
    }

$('input[name*="liegt_noch_nicht_fest"]').click(function() {
//$('#liegt_noch_nicht_fest_Abholdatumliegtnochnichtfest').click(function() {
    if($('input[name*="liegt_noch_nicht_fest"]').is(':checked') == false) {
  //if($('#liegt_noch_nicht_fest_Abholdatumliegtnochnichtfest').is(':checked') == false) {
    $('#lieferdaten_abholtermin_datum').parent().show();
    $('label[for=lieferdaten_abholtermin_datum]').show();
    $('label[for=lieferdaten_abholtermin_datum]').parent().show();
    } else {
    $('#lieferdaten_abholtermin_datum').parent().hide();
    $('label[for=lieferdaten_abholtermin_datum]').hide();
    $('label[for=lieferdaten_abholtermin_datum]').parent().hide();
    }
});


//Leereintrag in allen Combobox entfernen
  $('select option').each(function(index) {
 if($(this).val() == "") {
    // $(this).remove();
    }
  });

//Sortierung Stellenangebote
$("#stellenangebotsortOrt").live("click",function() {
  var currentSorting = $("#listCompact").attr("sorting");
  sortreferences(currentSorting,'niederlassung');
});

$("#stellenangebotsortDatum").live("click",function() {
  var currentSorting = $("#listCompact").attr("sorting");
  sortreferences(currentSorting,'datum');
});

//Tooltips

//$(".produkt_liste_einspaltig_optionen span[title]").tipTip();//Produktübersicht
//$(".ProductDetail_menu1 span[title]").tipTip();//Produktdetailseite
//$('.produktWarenkorb').tipTip(); //Standorte
$('.showInfo').tipTip();
$('.addToCart').tipTip();
$('.viewPDF').tipTip();
$('.ttip').tipTip();
$('.delOfCart').tipTip();
$('.ttipstandort').tipTip();

//$('.produktWarenkorb').tipTip();

/*
$(".ttip").mousemove(function(e) {
  $('#tiptip_holder').css('margin',0).css('position','absolute').css('left', e.pageX - 110).css('top', e.pageY - 58).css('display', 'block');
});*/

//Tooltip - Buttons positionieren
/*
$(".ttipstandorthamburg").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', e.pageY).css('top', e.pageX-130);
});

$(".ttipstandortrostock").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 725).css('top', 246);
});

$(".ttipstandortberlin").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 785).css('top', 400);
});

$(".ttipstandortdohna").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 800).css('top', 490);
});

$(".ttipstandortgerstungen").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 640).css('top', 495);
});

$(".ttipstandortgelnhausen").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 610).css('top', 545);
});

$(".ttipstandortheiligenhaus").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 520).css('top', 450);
});

$(".ttipstandortkarlsruhe").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 575).css('top', 620);
});

$(".ttipstandortstuttgart").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 615).css('top', 637);
});

$(".ttipstandortmuenchen").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 700).css('top', 675);
});

$(".ttipstandorthannover").mouseover(function(e) {
  $("#tiptip_holder").css('margin',0).css('position','absolute').css('left', 651).css('top', 410);
});*/

//Map Highlighting deaktiviert
//$('.map').maphilight({fade: false});

$tittext = "";
//Grundriss Title nicht anzeigen
$(".picturegrundriss").mouseover(function(e){ tittext = $(".picturegrundriss").attr("title");$(".picturegrundriss").attr("title",""); } );
$(".picturegrundriss").mouseout(function(e){ $(".picturegrundriss").attr("title",tittext); } );
$(".picturegrundriss").click(function(e){ $(".picturegrundriss").attr("title",tittext); } );

  $(".diaporama1").jDiaporama({
    animationSpeed: "slow",
    delay:5,
    infos: false
  });
/*
$(".galerielink").each(function(i, elem) {
 var htm = $(elem).html();
 var img= '<span id="ico"><img height="10px" style="margin-right:3px;" src="/ttd-wAssets/img/produkte/arrow_left_white.png"/></span>';
 if ($(elem).find("#ico").length == 0) {
     $(this).find("#ico").html(img+htm); }  else { $(elem).html(htm); }
});

   $(".galerielink").mouseover(function() {
     var img = '<img height="10px" style="margin-right:3px;" src="/ttd-wAssets/img/link_red.gif"/>';
     if ($(this).find("#ico").html() != img) {
     $(this).find("#ico").html(img); }
  });

  $(".galerielink").mouseout(function() {
      var img = '<img height="10px" style="margin-right:3px;" src="/ttd-wAssets/img/produkte/arrow_left_white.png"/>';
     if ($(this).find("#ico").html() != img) {
     $(this).find("#ico").html(img); }
  });


   $(".galerielink").mouseover(function() {
     $(this).attr('style','color:#FFFFFF;text-decoration:underline;');
  });

    $(".galerielink").mouseout(function() {
     $(this).attr('style','color:#FFFFFF;text-decoration:none;');
  });
  */

 $(".nextfancy").click(function() {
  if (fullurl.indexOf("wEditorWd") < 0) {
  parent.window.location = $(this).attr("href");}
 });

     $(".jDiaporama").mouseover(function() {
     $(".pause").attr('style','display:block;');
  });

//Anfrage Bestellung - Buttons


   $("#btn_unten_uebersicht_anfordern").mouseover(function() {
     $(this).attr('src','/ttd-wAssets/img/anfrage-bestellung/'+currlang+'/anfrage_over.gif');
  });

    $("#btn_unten_uebersicht_anfordern").mouseout(function() {
     $(this).attr('src','/ttd-wAssets/img/anfrage-bestellung/'+currlang+'/anfrage_normal.gif');
  });


   $("#btn_unten_uebersicht_bestellen").mouseover(function() {
     $(this).attr('src','/ttd-wAssets/img/anfrage-bestellung/'+currlang+'/bestellung_over.gif');
  });

    $("#btn_unten_uebersicht_bestellen").mouseout(function() {
     $(this).attr('src','/ttd-wAssets/img/anfrage-bestellung/'+currlang+'/bestellung_normal.gif');
  });

  var pos = checkBrowserVers("Firefox", "5", true);
  if (fullurl.indexOf("datenschutz") < 0) {
   $("#fancybox-title-main").css("display","none");
   //alert($("#fancybox-title-main").val());
  }
  
  $("#T1").parent().css("margin-bottom","0px");
  $("#lang").parent().css("margin-bottom","0px");
  
  if (fullurl.indexOf("kundenumfrage") > 0) {
   $("button[type=submit]").attr("name", "submit1");
   $("button[type=submit]").attr("value", "Login");
   $("button[type=submit]").parent().css("width", "370px");
   $("form").attr("action","http://www.netigate.se/answer.asp");
  }
}
