
    jQuery.noConflict();
                    

jQuery(function(){

    jQuery.getJSON('/ajaxscript/check_courses_product.php?typeCheck=check&rand='+Math.random(),function(data){

      var callBack ={ call:function (){button()}  };
       var OSX = oxD(data,false);
       
      if(data.is_mixed==true){
            var objExtra = {close:''}
            loadModel(OSX,objExtra);
            
            
        }
 
    });
 });  
function button(){
    
   jQuery("#keepProd").click(function(){
       jQuery.modal.close();
               jQuery.getJSON('/ajaxscript/check_courses_product.php?typeCheck=remove&what=courses&rand='+Math.random(),function(data){
                   
                   
                   var objExtra = {close:'<div class="close"><a href="#" class="simplemodal-close">x</a></div>',
                                   cart:data.cart,
                                   cart_link_id:data.link_id,
                                   cart_quantity:data.cart_count,
                                   cart_id:data.cart_id 
                   }
                   var OSX = oxD(data,true);
                   loadModel(OSX,objExtra);
                   
               });
            });

   jQuery("#keepCourses").click(function(){
       jQuery.modal.close();
               jQuery.getJSON('/ajaxscript/check_courses_product.php?typeCheck=remove&what=product&rand='+Math.random(),function(data){
                  var objExtra = {close:'<div class="close"><a href="#" class="simplemodal-close">x</a></div>',
                                   cart:data.cart,
                                   cart_link_id:data.link_id,
                                   cart_quantity:data.cart_count,
                                   cart_id:data.cart_id 
                   }
                 //  jQuery.modal.close();
                   var OSX = oxD(data ,true);
                   loadModel(OSX,objExtra);
               });
            });
   jQuery("#CanceLog").click(function(){
                
              window.location.href='/log-ud/';      
             });
   
}
function oxD(data,$reload){
    
      var OSX = {
        container: null,
        open: function (d) {
            var self = this;
            self.container = d.container[0];
            d.overlay.fadeIn('slow', function () {
                jQuery("#osx-modal-content", self.container).show();
                jQuery("#osx-modal-title").html(data.text);
                jQuery("#content_replace").html(data.content_r);
                var title = jQuery("#osx-modal-title", 'self.container');
                
                title.show();
                d.container.slideDown('slow', function () {
                    setTimeout(function () {
                        var h = jQuery("#osx-modal-data", self.container).height()
                            + title.height()
                            + 20; // padding
                        d.container.animate(
                            {height: h}, 
                            200,
                            function () {
                                jQuery("div.close", self.container).show();
                                jQuery("#osx-modal-data", self.container).show();
                            }
                        );
                    }, 300);
                     if($reload===false){
                         button();
                     }
                });
            });
             
        },
        close: function (d) {
            var self = this;
            d.container.animate(
            {top:"-" + (d.container.height() + 20)},
            500,
            function () {
            self.close(); // or $.modal.close();
            if($reload)
               window.location.reload(true);
            }
            );
        }
    };

    return  OSX  ;
}
function loadModel(OSX,objExtra){
    
    jQuery("#osx-modal-content").modal({
            overlayId: 'osx-overlay',
            containerId: 'osx-container',
            closeHTML: objExtra.close,
            minHeight:80,
            opacity:65, 
            autoResize:true, 
            position:['0',],
            overlayClose:false,
            onOpen:OSX.open,
            onClose:OSX.close
        });
            if(typeof objExtra.cart_id!='undefined'){

                
               jQueryimagePath  =jQuery('#'+objExtra.cart_id).html(objExtra.cart);
    
    }
}

jQuery(function(){
    
        jQuery('.buy_now_list').click(function(event){
           var $this =jQuery(this),
             $numP  = jQuery('#currentid').val(),
             $ch=true,
            $id = $this.attr('id').split('_')[2];
            if($numP<1){
                event.preventDefault();
                
                alert('Skriv venligst antal deltagere');
                addProductAjax($this,$id,0);
               return $this;
            }else{
             ix =0;
               while (ix <$numP) {
                var boxname = '#names'+ix;
                 var elName = jQuery(boxname);
                 if(elName.val().replace(/^\s+|\s+$/,'')==''){
                 //  alert("Please filled  all the name ");
                   
            
                alert("Udfyld venligst navn på alle deltagerne")
                   addProductAjax($this,$id,0);
                   $ch= false;
                   return false;
                 }
                 ix++;
                $ch=true; 
             }
             if($ch){
            $id = $this.attr('id').split('_')[2];
            jQuery.getJSON('/ajaxscript/check_courses_product.php?checkClick=Add&rand='+Math.random(),function(data){
                if(data.kurserA!=''){
                   // event.preventDefault();
                    jQuery('.buy_now_list').parent().html(data.kurserA);
                    jQuery('.add_basket').css({cursor:'default'});
                   // jQuery('.participants').remove();
                    
                }
        })
             }
            };
});
});

jQuery(function(){
    if(jQuery('#products').length>0){
        
        $this = jQuery('#products');
        $elM   = jQuery('[id^=product_qty_]');
        $elM.each(function(){
            var $elm =jQuery(this),
            $nextel = $elm.siblings('[id^=products_id]');
            jQuery.getJSON('/ajaxscript/check_courses_product.php?typeCheck=shopcheck&idE='+$nextel.val()+'&rand='+Math.random(),function(data){
                
                
                if(data.Disable!=''){
                    
                    
                    
                   $elM.attr('disabled','disabled');
                    
                }
        })            
        });
    }

});