  

  /* VOORSTELLING - THEATERSTUKDETAILS */
  function ajaxShowModalVoorstellingDetails(voorstellingId)
  {    
    var mytext = voorstellingId;
       $('<div id="dialog">&nbsp;</div>').appendTo('body');            
        //event.preventDefault();
    
    var dialogOpts = {
          modal: true,
          autoOpen: false,
          height: 600,
          width: 960,
          open: function() {
            //display correct dialog content
            $("#dialog").load('/2010/client-ajax/programmalistitemdetails.aspx?pageId=' + voorstellingId, function() {
                $('#dialog').fadeIn();
                });        
          },
      beforeclose: function () {        
      $('.slider').remove();
      },
      close: function () {
          $('#dialog').remove();
          }
    };

    $("#dialog").dialog(dialogOpts);    
    $("#dialog").dialog("open");
  }
  
   function ajaxShowModalWinkelwagenAfrekenen()
  {    

       $('<div id="dialogShoppingCart">&nbsp;</div>').appendTo('body');            
        //event.preventDefault();
    
    var dialogOpts = {
          modal: true,
          autoOpen: false,
          height: 400,
          width: 600,
          open: function() {
            //display correct dialog content
            $("#dialogShoppingCart").load('/2010/client-ajax/winkelwagenafrekenen.aspx', function() {
                $('#dialogShoppingCart').fadeIn();
                });        
          },      
      close: function () {
          $('#dialogShoppingCart').remove();
          }
    };

    $("#dialogShoppingCart").dialog(dialogOpts);    
    $("#dialogShoppingCart").dialog("open");
  }
  
  /* VIDEO DIALOG */
  function showVideoDialog(html,width,height)
  {        
       $('<div class="videoDialog" id="videoDialog">' + html + '</div>').appendTo('body');            
        //event.preventDefault();
    
    var dialogOpts = {
          modal: true,
          autoOpen: false,
          height: height + 100,
          width: width + 20,
          open: function() {
              $('#videoDialog').fadeIn();                        
        ;},
      close: function () {
        $('#videoDialog').remove();
        }
          };

    $("#videoDialog").dialog(dialogOpts);    
    $("#videoDialog").dialog("open");
  }

  function ajaxVoorstellingAddToCartDialog(voorstellingId)
  {  
    var mytext = voorstellingId;
       $('<div id="dialogAddToCart">&nbsp;</div>').appendTo('body');            
        //event.preventDefault();
    
    var dialogOpts = {
        modal: true,
        autoOpen: false,
        height: 520,
        width: 550,
        open: function() {
        //display correct dialog content
        $("#dialogAddToCart").load('/2010/client-ajax/winkelwagenadditemdialog.aspx?voorstellingId=' + voorstellingId, function() {
          $('#dialogAddToCart').fadeIn();
          });        
        },     
        close: function () {
        $('#dialogAddToCart').remove();
        }
    };

    $("#dialogAddToCart").dialog(dialogOpts);    
    $("#dialogAddToCart").dialog("open");
  } 
  
  
  //ADD TO CART
  function ajaxVoorstellingAddToCart(voorstellingId,numberOfTickets)
  { 
    //Setup
    var newCartItem = false;
    var myCartArray = new Array();
    var cookieVal = readCookie("2010MyCart");
  
  //Do checking and add voorstellingId to Array
    if(cookieVal) 
    {  
      myCartArray = cookieVal.split(',');
      //Check if myFavsArray already contains 'voorstellingId'
      newCartItem = !(myCartArray.contains(voorstellingId + '_' + numberOfTickets));
      //Get nextPosition and add voorstellingId to array
      if(newCartItem){        
        var nextPosition = myCartArray.length;
        myCartArray[nextPosition] = voorstellingId + '_' + numberOfTickets;
        eraseCookie('2010MyCart');
        createCookie('2010MyCart',myCartArray,7);                
      }else{
        alert('Deze voorstelling moet je wel HEEEEL erg leuk vinden... Hij staat namelijk al in je winkelwagentje ;)');  
      }        
     }else{
      //Cookie does not exist.. create and add voorstellingId
      myCartArray[0] = voorstellingId + '_' + numberOfTickets;
      createCookie('2010MyCart',myCartArray,7);    
      newCartItem = true;
      }
    
    //UPDATE MYCART
      if(newCartItem){
         //firstFadeOut
        $('#myCartContent').fadeOut();                
            //Load new list and fadeIn
        $("#myCartContent").load('/2011/client-ajax/winkelwagentoonartikelen.aspx', function() {
                  $('#myCartContent').fadeIn();
            $('#dialogAddToCart').remove();
              });              
      }
  }
  
  function ajaxClearCart(){
   eraseCookie('2010MyCart');
   $('#myCartContent').fadeOut();                
            //Load new list and fadeIn
     $("#myCartContent").load('/2011/client-ajax/winkelwagentoonartikelen.aspx', function() {
                  $('#myCartContent').fadeIn();
            $('#dialogAddToCart').remove();
              });       
  }

  //ADD TO FAVORITES
  function ajaxShowModalVoorstellingAddToFavorites(voorstellingId)
  {    
    //Setup
    var newFav = false;
    var myFavsArray = new Array();
    var cookieVal = readCookie("2010MyFavs");
    

    //Do checking and add voorstellingId to Array
    if(cookieVal) 
    {  
      myFavsArray = cookieVal.split(',');
      //Check if myFavsArray already contains 'voorstellingId'
      newFav = !(myFavsArray.contains(voorstellingId));
      //Get nextPosition and add voorstellingId to array
      if(newFav){        
        var nextPosition = myFavsArray.length + 1;
        myFavsArray[nextPosition] = voorstellingId;
        eraseCookie('2010MyFavs');
        createCookie('2010MyFavs',myFavsArray,7);                
      }else{
        alert('Deze voorstelling moet je wel HEEEEL erg leuk vinden... Hij staat namelijk al in je favorieten ;)');  
      }        
     }else{
      //Cookie does not exist.. create and add voorstellingId
      myFavsArray[0] = voorstellingId;
      createCookie('2010MyFavs',myFavsArray,7);    
      newFav = true;
      }
  
      //UPDATE MYFAVSLIST
      if(newFav){
         //firstFadeOut
        $('#favListContent').fadeOut();                
            //Load new list and fadeIn
        $("#favListContentContainer").load('/2011/client-ajax/programmamyfavslist.aspx?random=' + Math.random()*99999, function() {
                 $('#favListContent').fadeIn();
              });              
      }
  }
  
  function ajaxRemoveItemFromFavorites(voorstellingId)
  {
     var myFavsArray = new Array();
     var cookieVal = readCookie("2010MyFavs");

    //Do checking and add voorstellingId to Array
    if(cookieVal) 
    {
      myFavsArray = cookieVal.split(',');
      //Check if myFavsArray already contains 'voorstellingId'
      favExists = myFavsArray.contains(voorstellingId);
      if(favExists)
      {        
        // item do array que dever� ser removido
         myFavsArray = jQuery.grep(myFavsArray, function(value) {
                return value != voorstellingId;
              });          
              
        //$('#favListContent').fadeOut();    
        $('#myFav' + voorstellingId.toString()).remove();
        $('#favListContent').fadeIn();  
        
        eraseCookie('2010MyFavs');
        createCookie('2010MyFavs',myFavsArray,7);  
      }
    }
    
    }
  
    Array.prototype.contains = function (element) {
    for (var i = 0; i < this.length; i++) {
      if (this[i] == element) {
        return true;
      }
    }
    return false;
  }
  
  
  
  Array.prototype.containsToIndex = function (element) {
    for (var i = 0; i < this.length; i++) {
      if (this[i] == element) {
        return i;
      }
    }
    return -1;
  }
  
  
  function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  }
  
  function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }

  function eraseCookie(name) {
    createCookie(name,"",-1);
  }

