$(document).ready(function(){

$("span[rel*=zanox], a[href*=mm=zx], a img[src*=zanox]").click(
    function(){

        //$.post("http://www.shopping-rabatt.de/wp-content/themes/dilectio/dilectio/link_prufen.php",{link : $(this).attr("src")});
      //  alert ( "Unser Partner ist im Moment nicht erreichbar!\nVersuchen Sie es später noch einmal - Danke" );
      //  return false;
    }
);




  $(".gutscheincode").click(
    function(){
    var bh = $(window).height();
    
    if(bh<400){
      $("#cuponpoup").css({
         "bottom" : 0,
          top : "auto",
          margin : "0 0 0 -250px"
      });
    }
   
    var p = $(this).parent().parent().parent();
    
    var wert = p.find(".wert").html();
    var gultig = p.find(".gultig").html();
    var mindest = p.find(".mindest").html();
    var link = $(this).attr("rel");
    var code = $(this).attr("name"); 
    var titel = $(this).attr("title");
     
    $("#cuponpoup .titel").html(titel);
    $("#cuponpoup .wert").html(wert);
    $("#cuponpoup .gutscheincode_insert").html(code);
    $("#cuponpoup .mindest").html(mindest);
    $("#cuponpoup .gultig").html(gultig);
    $("#cuponpoup .zlk").attr("href",link);
    $(".gutscheincode_neu").html(code);
    var bed2 = "top=0, left=0, width="+screen.width+", height=260, menubar=yes, resizable=yes, scrollbars=yes, status=yes, toolbar=yes, location=yes";
    
    
    
  $("#schwarz_bg").css("opacity",0.6).fadeIn(500,function(){
    $("#cuponpoup").fadeIn(500);
  });
     var gutschein_code = window.open(link,"fenster1",bed2);
      gutschein_code.focus(); 
    $(this).html(code); 
    return false;
      }
  );
  
  
     var topfen = screen.height-$(window).height()+100; 
     var whh =$(window).height()-250;
  
  //neu
    $(".gutscheincode2").click(
    function(){
    $("#gframe table td:eq(3)").show();
    var bh = $(window).height();
         
    var p = $(this).parent().parent().parent();
    var hier = $(this);
    var wert = p.find(".wert").html();
    var gultig = p.find(".gultig").html();
    var mindest = p.find(".mindest").html();
    var link = $(this).attr("rel");
    var code = $(this).attr("name"); 
    var titel = $(this).attr("title");
    var exclusive = code.match( /([A-Za-z]+)_([A-Za-z]+)$/);
    var topfen = screen.height-$(window).height()+100;
    var whh =$(window).height()-250; 
    $("#cuponpopup .titel").html(titel);
    $("#cuponpopup .wert").html(wert);
    $("#cuponpopup .gutscheincode_insert").html(code);
    $("#cuponpopup .mindest").html(mindest);
    $("#cuponpopup .gultig").html(gultig);
    $("#cuponpopup .zlk").attr("href",link);
    if(exclusive){
       if(exclusive[1] == "verschiedeneCodes"){
        $.get("../mehr_codes.php?kunden_id="+exclusive[2],
            function(data){
              hier.html(data);
                $("#cuponpopup .gutscheincode_insert").html(data);
                if(exclusive[2]=="connox"){
                            var link_neu = link+encodeURIComponent(data);
                            var bed2 = "top="+topfen+", left=0, width="+screen.width+", height="+whh+", menubar=yes, resizable=yes, scrollbars=yes, status=yes, toolbar=yes, location=yes";
                              var gutschein_code = window.open(link_neu,"fenster1",bed2);
                              gutschein_code.focus(); 
                              
                            $("#schwarz_bg").css("opacity",0.6).fadeIn(500,function(){
                           
                            
                              $("#cuponpopup").css("display" , "block").animate({
                                top : 0
                                },1000);
                            });
                            return false;
                  }
              });
         
        }             
        
    }else{
    $(this).html(code); 
    $(".gutscheincode_neu").html(code);
    }
   
    var bed2 = "top="+topfen+", left=0, width="+screen.width+", height="+whh+", menubar=yes, resizable=yes, scrollbars=yes, status=yes, toolbar=yes, location=yes";
    var gutschein_code = window.open(link,"fenster1",bed2);
    gutschein_code.focus(); 
    
  $("#schwarz_bg").css("opacity",0.6).fadeIn(500,function(){
 
  
    $("#cuponpopup").css("display" , "block").animate({
      top : 0
      },1000);
  });
     
    
    return false;
      }
  );
    $("#cuponpopup .close_img, #zzsr").click(function(){
      $("#cuponpopup").animate({
        top : "-77"
        
      },500).css("display" , "none"); 
      $("#schwarz_bg").fadeOut(500); 
      return false;
  });
  //neu ende
  
  
  
  
  
  $("#cuponpoup img").click(function(){
      $("#cuponpoup").fadeOut(500); 
      $("#schwarz_bg").fadeOut(500); 
  });
  
   $("em.cflabel").each(
    function(){
        $(this).find("a").addClass("cflabel");
        $(this).removeClass("cflabel");
    }
);
  
  
  $(".cflabel").each(
    function(){
    $(this).attr("name",$(this).html())
    .html("klicken für Gutscheincode")
    .click(function(){
        $(this).html($(this).attr("name"));
        var bh = $(window).height();
        var p = $(this).parent().parent().parent();
        var hier = $(this);
        var link = $(this).attr("href");
        var code = $(this).attr("name");
         $("#gframe table td:eq(3)").hide();
    $("#cuponpopup .titel").html($(this).closest("p strong").html());
    $("#cuponpopup .wert").html("k.A.");
    $("#cuponpopup .gutscheincode_insert").html(code);
    $("#cuponpopup .mindest").html("k.A.");
    $("#cuponpopup .gultig").html("k.A.");
    $("#cuponpopup .zlk").attr("href",link);
        
        var bed2 = "top="+topfen+", left=0, width="+screen.width+", height="+whh+", menubar=yes, resizable=yes, scrollbars=yes, status=yes, toolbar=yes, location=yes";
        var gutschein_code = window.open(link,"fenster1",bed2);
        gutschein_code.focus(); 
       
       $("#schwarz_bg").css("opacity",0.6).fadeIn(500,function(){
 
  
          $("#cuponpopup").css("display" , "block").animate({
            top : 0
            },1000);
        });
        
        return false;
       });
    }
  );
   
 });

