  

   
    function setGroupDDevents() {
         $$("._ticketgroupSelect").each(function(el) {
             el.addEvent('change', function(e) {
              if ($('submitdate')) { getSpecFeatTotalPrice(); }
              else { getTotalPrice(); }
              if($("_attractionsBody")){
                getAttractions();
              }
              
             });
         });
     }
     

//Touring stuff
     
     function dateFromSQLdate(str, spltChr){
        var oD = new Date();
        var d = str.substr(0,str.indexOf('T'));
        var dps = d.split(spltChr);
        return oD.setFullYear(Number(dps[0]),Number(trimNumber(dps[1])),Number(trimNumber(dps[2])));
     }
     
     function dateFromVB2(str){
        var oD = new Date();
        var dps = str.split('/');
        return oD.setFullYear(Number(dps[2]),Number(trimNumber(dps[1])),Number(trimNumber(dps[0])));
     }
     
     function trimNumber(s) {
        while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
        return s;
     }
     
     function setCalendarButtonEvents(){
    
         var touringDates = '';
         $$('#calendarList li table tbody tr td input').each(function(el) {
             el.addEvent('click', function() {
              //  if(el.checked)el.checked=false;
              //  else el.checked=true;
                getTotalPrice();
             });
         });
     }
     
     
     
     function setCalendarEventDates(){
     
        var startDate;
        var endDate;
        
        var ticketStartDate;
        var ticketLength;
             
         if($$('#content .vevent .description .dtstart')&& $$('#content .vevent .description .dtend') && $('bookcamping')){
            if($("ticketstart")){
                if($("ticketstart").selectedIndex>0){
                    ticketStartDate = dateFromVB2($("ticketstart").value);
                    ticketStartDateNonCon = $("ticketstart").value;
                }
            }
            if($$('#content .vevent .description .dtstart').length > 0 ) {
                startDate = dateFromSQLdate($$('#content .vevent .description .dtstart')[0].title, '-');
                endDate = dateFromSQLdate($$('#content .vevent .description .dtend')[0].title, '-'); //No idea if any of it works properly.
            }
         }

        var newEndDate = (endDate+(60*60)*24);
        var ticketLength=0;
         $$('#calendarList li table tbody tr td input').each(function(el) {
               if( (dateFromVB2(el.value)>=startDate) && (dateFromVB2(el.value)<=newEndDate) )
               {  
                    if(ticketStartDateNonCon==el.value){
                        el.getParent().getParent().addClass("eventDate"); 
                        
                        $$(".ticketGroup ._ticketgroupSelect").each(function(e){
                            var val = e.getAttribute("ref");
                            if(Number(val)>ticketLength && e.selectedIndex>0){
                                ticketLength = Number(val);
                            }
                        });                       

                    }else{
                        if((ticketLength+1)>1){
                             el.getParent().getParent().addClass("eventDate"); 
                        }else{
                            el.getParent().getParent().addClass("eventValid"); // eventDate
                        }
                   }
                   ticketLength--;
              }
         });
     }


     function showHideTouringOptions() {
 /*
         cOrC = $('campingorcaravan');
         if (cOrC.options[cOrC.selectedIndex].value == 'Camping') {
             $('touring-electricity').checked=false;
             $('_tourElectricityOption').setStyle("display", "none");
             $('touring-water').checked=false;
             $('_tourWaterOption').setStyle("display", "none");
             
         } else if (cOrC.options[cOrC.selectedIndex].value == 'Caravan') {
             $('_tourElectricityOption').setStyle("display", "block");
             $('_tourWaterOption').setStyle("display", "block");
         }
        $('touring-electricity').removeAttribute("checked");
        $('touring-water').removeAttribute("checked");
       // $('touring-mealpacks').removeAttribute("checked");
 */
        setCalendarButtonEvents();
        setCalendarEventDates();
     }


    function initCalCar() {
         var myCarousel = new Carousel($("calendarList"), {
             autoStyle: true,
             idPrevious: $("previousMonth"),
             idNext: $("nextMonth"),
             visibleItems: 3, //amount that fits in the container
             scrollAmount: 175, //how wide each item is
             scrollInterval: 500, //how quick it should scroll in ms
             fxTransition: Fx.Transitions.quadOut //http://docs.mootools.net/Effects/Fx-Transitions.js <- pick one
         });
     }

   
     function getCampingDates(cb){
        // @AttractionID int,
        // @CampingBerthID int
        var attId = 0;
         if($("MainAttractionID")){
           attId = $("MainAttractionID").value; 
         }
         var berthId = 0;
         if($('berthsize'))
            berthId = $('berthsize').options[$('berthsize').selectedIndex].value;

         var urlInd = '/bookings/camping-dates/?requestType=ajax'
         + '&CampingBerthID=' + berthId +'&MainAttractionID='+attId;

          var retHTML = '';
             new Request.HTML({
                 "url": urlInd,
                 "onRequest": function() {
                     $("_campingDates").set("html", "<ul><li>loading calendar ....</li></ul>");
                 },
                 "onSuccess": function(nl, el, hutmull) {
                    $("_campingDates").set("html", hutmull);
                    
                    initCalCar();    
                    makeCalFancy(true);
                    setCalendarButtonEvents();  
                    setCalendarEventDates(); // Event hilights
                    
                    if(cb)return cb();
                 }
             }).get(); 
     }
     
     
     
     

     function makeCalFancy(update){
         var chkBoxes = new Array(); //Used with FancyForm()
         chkBoxes = $$('#calendarContainer input[@type="checkbox"], #calendarContainer input[@type="radio"]');
         if(!update){
            FancyForm.start(chkBoxes);
        }else{
            FancyForm.initing = undefined;
            FancyForm.start(chkBoxes);
         }
     }

// Touring stuff - end

     function showHideAttractions() {
        if($("_attractions")){
             $$("#_attractions .selectattractions li input ").each(function(el) {
                 hideOnStart = 1;
                 divToHide = el.getParent().getElement("._ashowhide");
                 var divToHideID = divToHide.id;
                 if (el.getAttribute("checked")) { hideOnStart = 0; }
                 if (hideOnStart == 1) {
                     divToHide.setStyle("display", "none");
                 }
                 el.addEvent("click", function(e) {
                     if ($(divToHideID) && $(divToHideID).getStyle("display") == "none")
                     { $(divToHideID).setStyle("display", "block"); }
                     else { $(divToHideID).setStyle("display", "none"); }
                 });
             });
         }
     }




     function getGroupValues() {
         var arrRet = new Array();
         var strgroupVals = '';
         var strpriceIDs = '';
         var strgroupIDs = '';
         $$("._ticketgroupSelect").each(function(el) {
             if (el.selectedIndex > 0) {
                 strgroupVals += el.options[el.selectedIndex].value + ',';
                 arrGP = el.id.split('_');
                 strgroupIDs += arrGP[1] + ',';
                 strpriceIDs += arrGP[2] + ',';
             }
         });
         arrRet[0] = strgroupVals;
         arrRet[1] = strpriceIDs;
         arrRet[2] = strgroupIDs;
         return arrRet;
     }

    function getSpecFeatTotalPrice(cb) {
    
        var attVars = '';
        var tourVars='';
        if($('timeslot')) {
            arrGroupVals = getGroupValues();
             tsID = $('timeslot').options[$('timeslot').selectedIndex].value;
             
            attVars = '&TimeSlotID=' + tsID + '&TicketPrices=' + arrGroupVals[1]
            + '&TicketAmounts=' + arrGroupVals[0] + '&TicketGroups=' + arrGroupVals[2];
         }

         // Do calendar things

         var touringDates = '';
         $$('#calendarList li table tbody tr td input').each(function(el) {
             if (el.checked) { touringDates += el.value + ','; }
         });

         touringDates = touringDates.replace(new RegExp("/", "g"), '-');
         

         if($('calendarList')){
             
            tourVars = '&TouringDates=' + touringDates;
        }

         var urlInd = '/bookings/prices/?requestType=ajax&priceType=specfeat&' + attVars + tourVars;
         
         var retHTML = '';
         new Request.HTML({
             "url": urlInd,
             "onRequest": function() {
                 $("grandtotal").set("html", "finding prices ...");
             },
             "onSuccess": function(nl, el, hutmull) {
                 $("grandtotal").set("html", hutmull);
                 if(cb)return cb();
             }
         }).get();
     }

     function getTotalPrice(cb) {
     
        var attVars = '';
        var tourVars='';
        var dateSelect = '';
        var sID='';
        var sttID='';
        if($('tickettype')) {
            arrGroupVals = getGroupValues();
             ttID = $('tickettype').options[$('tickettype').selectedIndex].value;
             if($('seasontype')) {sttID = $('seasontype').options[$('seasontype').selectedIndex].value; }
             if($('seasonselect')) {sID = $('seasonselect').options[$('seasonselect').selectedIndex].value; }
             if($('dayofticket')) {dayA = $('dayofticket').options[$('dayofticket').selectedIndex].value; }
             if($('monthofticket')) {monthA = $('monthofticket').options[$('monthofticket').selectedIndex].value; }
             if($('yearofticket')) { yearA = $('yearofticket').options[$('yearofticket').selectedIndex].value; }
             
             if($('ticketstart')){
                dateSelect = $('ticketstart').options[$('ticketstart').selectedIndex].value;
             }else{
                dateSelect = yearA + '-' + monthA + '-' + dayA;
             }
             
            attVars = '&TicketTypeID=' + ttID + '&SeasonTicketType=' + sttID
            + '&SeasonID=' + sID + '&DateAttend=' + dateSelect + '&TicketPrices=' + arrGroupVals[1]
            + '&TicketAmounts=' + arrGroupVals[0];
         }

         // Do calendar things

         var touringDates = '';
         $$('#calendarList li table tbody tr td input').each(function(el) {
             if (el.checked) { touringDates += el.value + ','; }
         });

         touringDates = touringDates.replace(new RegExp("/", "g"), '-');
       //  alert('getPrices' + touringDates);
         tElec = '0';
         tWater = '0';
         tMeal = '0';
         carOrCamp='';
         berthSize='';
         if($('campingorcaravan')){
             carOrCamp = $('campingorcaravan').options[$('campingorcaravan').selectedIndex].value;
             berthSize = $('berthsize').options[$('berthsize').selectedIndex].value;
             if ($('touring-electricity').checked) { tElec = '1'; }
          //   if ($('touring-water').checked) { tWater = '1'; }
          //   if ($('touring-mealpacks').checked) { tMeal = '1'; }
             
            tourVars = '&TouringDates=' + touringDates
            + '&touring-electricity=' + tElec + '&touring-water=' + tWater + '&touring-mealpacks=' + tMeal + '&campingorcaravan=' + carOrCamp + '&CampingBerthID=' + berthSize;

        }

         var urlInd = '/bookings/prices/?requestType=ajax' + attVars + tourVars;

         var retHTML = '';
         new Request.HTML({
             "url": urlInd,
             "onRequest": function() {
                 $("grandtotal").set("html", "finding prices ...");
             },
             "onSuccess": function(nl, el, hutmull) {
                 $("grandtotal").set("html", hutmull);
                 if(cb)return cb();
             }
         }).get();
     }
     
     function getSpecFeatTicketGroups(cb) {
        // @AttractionID int,
        // @CheckedDate
        var attId = 0;
         if($("MainAttractionID")){
           attId = $("MainAttractionID").value; 
         }
         var touringDates = '';
         $$('#calendarList li table tbody tr td input').each(function(el) {
              if(el.checked){
                touringDates = el.value; 
              }
         });

         if(touringDates !=''){
             touringDates = touringDates.replace(new RegExp("/", "g"), '-');
             var urlInd = '/bookings/ticket-groups/?requestType=ajax&groupType=specfeat'
             + '&CheckedDate=' + touringDates +'&MainAttractionID='+attId;

              var retHTML = '';
                 new Request.HTML({
                     "url": urlInd,
                     "onRequest": function() {
                         $("_ticketGroupsBody").set("html", "<tr><td colspan=3>loading groups ....</td></tr>");
                     },
                     "onSuccess": function(nl, el, hutmull) {
                        $("_ticketGroupsBody").set("html", hutmull);
                         setGroupDDevents();
                         if(touringDates!=''){ getSpecFeatTimeSlots( attId, touringDates ); }
                         if(cb)return cb();
                     }
                 }).get();
             $('_ticketGroupsContainer').setStyle("display", "block");
        }
     }



    function getSpecFeatTimeSlots( attID, attDate, cb ) {

         var urlInd = '/bookings/specialfeature-timeslots/?requestType=ajax&AttractionID=' + attID + '&DateAttend=' + attDate;

         var retHTML = '';
         new Request.HTML({
             "url": urlInd,
             "onSuccess": function(nl, el, hutmull) {
                 var replacement = new Element("select").set("html", hutmull);
                 replacement.setAttribute("name", "timeslot");
                 replacement.setAttribute("id", "timeslot");
                 replacement.replaces($("timeslot"));
                 if(cb)return cb();
             }
         }).get();
     }
     
     function showHideTicketTypeOptions(){
         var sSelectedIDs = '';
         $('tickettype').getChildren("option").each(function(el) {
             if (el.selected) {
                 if (el.innerHTML.indexOf('Season') > -1) {
                     $('_seasondropdowns').setStyle("display", "block")
                     $('dayofticket').selectedIndex = 0; $('monthofticket').selectedIndex = 0; $('yearofticket').selectedIndex = 0;
                     $$('fieldset .dateselect')[0].setStyle("display", "none");
                 }
                 else {
                    if ($('_seasondropdowns')) {
                        $('_seasondropdowns').setStyle("display", "none")
                        $('seasonselect').selectedIndex = 0;
                        $$('fieldset .dateselect')[0].setStyle("display", "block");
                     }
                 }
             }
         });
     
     }
     
     function getEventTicketGroups(cb) {

         ttID = $('tickettype').options[$('tickettype').selectedIndex].value;
         dateAttend = $('ticketstart').options[$('ticketstart').selectedIndex].value;
         if($("MainAttractionID")){
           attId = $("MainAttractionID").value; 
         }
         var urlInd = '/bookings/ticket-groups/?requestType=ajax&TicketTypeID=' 
         + ttID + '&DateAttend=' + dateAttend +'&MainAttractionID='+attId;

        if( $('ticketstart').selectedIndex>0 && $('tickettype').selectedIndex>0 ){
             $('_ticketGroupsContainer').setStyle("display", "block");
             var retHTML = '';
             new Request.HTML({
                 "url": urlInd,
                 "onRequest": function() {
                     $("_ticketGroupsBody").set("html", "<tr><td colspan=3>loading groups ....</td></tr>");
                 },
                 "onSuccess": function(nl, el, hutmull) {
                    $("_ticketGroupsBody").set("html", hutmull);
                     setGroupDDevents();
                     setCalendarEventDates();
                     if(cb)return cb();
                 }
             }).get();
         }
     }

     function getTicketGroups(cb) {
     
         var ajaxtemp = $('_ajaxtemp');
         var tblBody = $("_ticketGroupsBody");
         ttID = $('tickettype').options[$('tickettype').selectedIndex].value;
         sttID = $('seasontype').options[$('seasontype').selectedIndex].value;
         sID = $('seasonselect').options[$('seasonselect').selectedIndex].value;
         dayA = $('dayofticket').options[$('dayofticket').selectedIndex].value;
         monthA = $('monthofticket').options[$('monthofticket').selectedIndex].value;
         yearA = $('yearofticket').options[$('yearofticket').selectedIndex].value;
         if($("MainAttractionID")){
           attId = $("MainAttractionID").value; 
         }
         var urlInd = '/bookings/ticket-groups/?requestType=ajax&TicketTypeID=' 
         + ttID + '&SeasonTicketType=' + sttID + '&SeasonID=' + sID + '&DateAttend=' 
         + yearA + '-' + monthA + '-' + dayA+'&MainAttractionID='+attId;

        if(($('dayofticket').selectedIndex>0 && $('monthofticket').selectedIndex>0 && $('yearofticket').selectedIndex >0) || ( $('seasonselect').selectedIndex >0) ){
             $('_ticketGroupsContainer').setStyle("display", "block");
             var retHTML = '';
             new Request.HTML({
                 "url": urlInd,
                "onRequest": function() {
                    $("_ticketGroupsBody").set("html", "<tr><td colspan=\"3\">loading groups ....</td></tr>")
                 },
                 "onSuccess": function(nl, el, hutmull) {
                    $("_ticketGroupsBody").set("html", hutmull);
                     setGroupDDevents();
                     if(cb)return cb();
                 }
             }).get();
         }

     }

     function addTimeSlotevents() {
         $$("#_attractions .selectattractions li ._attDate").each(function(el) {
            getTimeSlots(el.id);
             $(el.id).addEvent('change', function(e) {
                 getTimeSlots(el.id);
             });
         });
     }


     function getTimeSlots(elID, cb) {
         var attID;
         attID = elID.replace('attraction_', '').replace('-date', '');
         el = $(elID);
              
         attDate = el.options[el.selectedIndex].value;
         var urlInd = '/bookings/attraction-timeslots/?requestType=ajax&AttractionID=' + attID + '&DateAttend=' + attDate;

         var retHTML = '';
         new Request.HTML({
             "url": urlInd,
             "onSuccess": function(nl, el, hutmull) {
                 var replacement = new Element("select").set("html", hutmull);
                 replacement.setAttribute("name", "attraction_" + attID + "-time");
                 replacement.setAttribute("id", "attraction_" + attID + "-time");
                 replacement.replaces($("attraction_" + attID + "-time"));
                 if(cb)return cb();
             }
         }).get();
     }
     


     function getAttractions(cb) {

        var dateSelect = '';
        var sID='';
        var sttID='';
         ttID = $('tickettype').options[$('tickettype').selectedIndex].value;
         if($('seasontype')) {sttID = $('seasontype').options[$('seasontype').selectedIndex].value; }
         if($('seasonselect')) {sID = $('seasonselect').options[$('seasonselect').selectedIndex].value; }
         if($('dayofticket')) {dayA = $('dayofticket').options[$('dayofticket').selectedIndex].value; }
         if($('monthofticket')) {monthA = $('monthofticket').options[$('monthofticket').selectedIndex].value; }
         if($('yearofticket')) {yearA = $('yearofticket').options[$('yearofticket').selectedIndex].value; }
         
         
         if($('ticketstart')){
            dateSelect = $('ticketstart').options[$('ticketstart').selectedIndex].value;
         }else{
            dateSelect = yearA + '-' + monthA + '-' + dayA;
         }
         
         if($("MainAttractionID")){
           attId = $("MainAttractionID").value; 
         }
         var canLook = false;
         if($('dayofticket')){
             if(($('dayofticket').selectedIndex>0 && $('monthofticket').selectedIndex>0 && $('yearofticket').selectedIndex >0) || ( $('seasonselect').selectedIndex >0)){
             canLook = true;
             }
         }else if ($('ticketstart')){
            if($('ticketstart').selectedIndex>0) { canLook = true;  }
         }
// upper limit
        var upperLimit=0;
        $$(".ticketGroup ._ticketgroupSelect").each(function(e){
            var val = e.value;
            if(Number(val)>upperLimit && e.selectedIndex>0){
                upperLimit = Number(val);
            }
        });  


         var urlInd = '/bookings/attractions/?requestType=ajax&TicketTypeID=' + ttID + '&SeasonTicketType=' + sttID + '&SeasonID=' + sID + '&DateAttend=' + dateSelect+ "&MainAttractionID="+ attId + "&UpperLimit=" + upperLimit;

        if($("_attractionsBody") && canLook ){
             var retHTML = '';
             new Request.HTML({
                 "url": urlInd,
                 "onRequest": function() {
                      $("_attractionsBody").set("html", "<li>loading attractions ....</li>");
                 },
                 "onSuccess": function(nl, el, hutmull) {
                     $("_attractionsBody").set("html", hutmull);
                     showHideAttractions();
                     addTimeSlotevents();
                     if(cb)return cb();
                 }
             }).get();             
             $('_attractions').setStyle("display", "block");
         }
     }
     

     
     
     
     function reMakePage(){
        if(window.location.href){
 
            var pageURI = new URI(window.location.href);
            var BasketID='';
            var type='';
            if(window.location.href.indexOf("?")>-1){
               var  query = pageURI.get('query').parseQueryString();
               BasketID = query.BasketID;
               type = query.type;
            }
             //   if(query.BasketID){
            var attId;
            if($("MainAttractionID")){
               attId = $("MainAttractionID").value; 
             }
             var urlInd = '/bookings/ajax-basket/?requestType=ajax&BasketID='+BasketID+'&type='+type+'&AttractionID='+attId;
             new Request.JSON({
                 "url": urlInd,
                 "onSuccess": function(resJSON, resTxt) {
                     handleBasketJSON( resJSON );
                 },
                 "onFailure":function(){
			      // alert("FAIL");
		        }
             }).get();             
           
           // }
        }
     }
     
     
     function handleBasketJSON ( objBskt ){
        if(!$type(objBskt)){
           // alert("invalid object :(");
        }else{
		    resetEvent( objBskt );
    		
		    resetTouring( objBskt );
    		
		    resetSpecFeat( objBskt );
		    
		    resetPark( objBskt );
		}
     }
     
     
     
     
     function resetSpecFeat( objBskt ){
     
        if(objBskt.SpecialFeatureBasketItem){
             if(objBskt.SpecialFeatureBasketItem.BasketID){
                 $("_editBasketID").value= objBskt.SpecialFeatureBasketItem.BasketID;
                 $("_editType").value= 'specfeat';
             }
           // alert(objBskt.SpecialFeatureBasketItem[0].DateAttending);
             $$('#calendarList li table tbody tr td input').each(function(el) {
                  if(objBskt.SpecialFeatureBasketItem[0].DateAttending==el.value){
                    el.setAttribute("selected", "selected");
                    el.getParent().addClass("checked");
                  }
             });

            getSpecFeatTicketGroups(function(){
                objBskt.SpecialFeatureBasketItem.each(function(el){
                    setFormControl("ticketgroupprice_"+el.GroupID + "_" +el.PriceID , el.Amount, "dd");
                    getSpecFeatTimeSlots( el.AttractionID, el.DateAttending, function(){
                        getSpecFeatTotalPrice();
                    
                    });
                });
            
            });
        }
     }
     
     function resetPark( objBskt ){
     
        if(objBskt.BasketItem){
             if(objBskt.BasketItem.BasketID){
                 $("_editBasketID").value= objBskt.BasketItem.BasketID;
                 $("_editType").value= 'park';
             }
            setFormControl("tickettype", objBskt.BasketItem[0].TicketTypeID, "dd");
            showHideTicketTypeOptions();
            
            if($("seasontype")){
                setFormControl("seasontype", objBskt.BasketItem[0].SeasonTicketTypeID, "dd");
                setFormControl("seasonselect", objBskt.BasketItem[0].SeasonID, "dd");
            }
            if(objBskt.BasketItem[0].DateAttending){
                var arrDA = objBskt.BasketItem[0].DateAttending.split("/");
                setFormControl("dayofticket", trimNumber(arrDA[0]), "dd");
                setFormControl("monthofticket", trimNumber(arrDA[1]), "dd");
                setFormControl("yearofticket", arrDA[2], "dd");
                
                objBskt.BasketItem[0].DateAttending
            }
            
            
            getTicketGroups(function() { 
            
                var TicketGroupID, TicketPriceID;
                objBskt.BasketItem.each(function(el){
                    $each(el, function(value, index){
                        switch(index){
                            case "TicketGroupID":
                                TicketGroupID = value;
                                break;
                            case "TicketPriceID":
                                TicketPriceID = value;
                                break;
                            case "Amount":
                                setFormControl("ticketgroupprice_"+TicketGroupID+"_" + TicketPriceID, value, "dd");
                                break;
                        }
			        });
			    });
			    
			    getTotalPrice();
			});
		
		    resetAttractions( objBskt );	
        }
     }
     
     function resetTouring( objBskt ){
     
        if(objBskt.TouringPrice){
             if(objBskt.TouringPrice.BasketID){
                 $("_editBasketID").value= objBskt.TouringPrice.BasketID;
                 $("_editType").value= 'camping';
             }
            if($("bookcamping")){
                $("bookcamping").setAttribute("checked", "checked");
                $("showhide").setStyle("display", "block");
            
            }
            
            setFormControl("berthsize", objBskt.TouringPrice[0].CampingBerthID, "dd");
            setFormControl("campingorcaravan", objBskt.TouringPrice[0].TouringType, "dd");
            showHideTouringOptions();
            setFormControl("touring-electricity", Number(objBskt.TouringPrice[0].incElec), "cb");
         //   setFormControl("touring-water", Number(objBskt.TouringPrice[0].incWater), "cb"); // All equating to true for some reason.
         //   setFormControl("touring-mealpacks", Number(objBskt.TouringPrice[0].incMealPacks), "cb");
            
            getCampingDates(function() { 
            
                objBskt.TouringPrice[0].Touringdates.each(function(date){
                    var cDate = date;
                     $$('#calendarList li table tbody tr td input').each(function(el) {
                          if(cDate==el.value){
                            el.setAttribute("checked", "checked");
                            el.getParent().addClass("checked");
                          }
                     });
                });

			    getTotalPrice();
			});
		
		    resetAttractions( objBskt );	
        }
     }
     
     function resetEvent (objBskt){
     
     	if(objBskt.EventBasketItem){
     	    if (objBskt.BasketItem) {
     	     if(objBskt.BasketItem.BasketID){
                 $("_editBasketID").value= objBskt.EventBasketItem.BasketID;
                 $("_editType").value= 'event';
             }
             }
		  //  alert("event");
		    setFormControl("ticketstart", objBskt.EventBasketItem[0].DateAttending, "dd");
		    setFormControl("tickettype", objBskt.EventBasketItem[0].TicketTypeID, "dd");
		    
		    getEventTicketGroups(function(){
		         var TicketGroupID, TicketPriceID;
		         objBskt.EventBasketItem.each(function(el){
                    $each(el, function(value, index){
                        switch(index){
                            case "TicketGroupID":
                                TicketGroupID = value;
                                break;
                            case "TicketPriceID":
                                TicketPriceID = value;
                                break;
                            case "Amount":
                                setFormControl("ticketgroupprice_"+TicketGroupID+"_" + TicketPriceID, value, "dd");
                                break;
                        }
			        });
			    });
			    
			     resetAttractions( objBskt );
		    	 getTotalPrice();
		    });
		}
     }
     
     function resetAttractions( objBskt ) { 
		    getAttractions(function() {
	        if(objBskt.AttractionBasketItem){
	        // { "AttractionBookingDate" : "06/09/2009", "AttractionID" : "84", "AttractionAttending" : "3", "SeasonTimeSlotID" : "51" }
	            var TicketGroupID, TicketPriceID;

    	        objBskt.AttractionBasketItem.each(function(el){
	                $each(el, function(value, index){
	                    var AttractionID;
	                    if(index == "AttractionID"){
	                        AttractionID = value;
	                        setFormControl("attraction_"+ AttractionID , 1, "cb");
	                      // alert(AttractionID);
	                      $("attractionoptions" + AttractionID).setStyle("display", "block");
        	            
                            $each(el, function(value, index){
                                switch(index){
                                    case "AttractionBookingDate":
                                        setFormControl("attraction_"+ AttractionID + "-date", value, "dd");
                                        break;
                                    case "AttractionAttending":
                                        setFormControl("attraction_"+ AttractionID + "-attending", value, "dd");
                                        break;
                                    case "SeasonTimeSlotID":
                                        setFormControl("attraction_"+ AttractionID + "-time", value, "dd");
                                        break;
                                }
	                        });
	                    }
	                });
	            });
	        }
	    });
     }
     
     
     function setFormControl(id, value, type){
        // type: dd, cb, rb
         switch(type){
            case "dd":
                var x=0;
                $$("#"+id+" option").each(function(el){
                    if(el.value==value){
                        $(id).selectedIndex= x;
                    }
                    x++;
                });
                break;
            case "cb":
                var bool = new Boolean(value);
                if(bool){ $(id).setAttribute("checked", "checked"); } else { removeAttribute("checked"); }
                break;
            case "rb":
                var bool = new Boolean(value);
                if(bool){ $(id).setAttribute("selected", "selected"); } else { removeAttribute("selected"); }
                break;
            default:
                $(id).value = value;
                break;
        }
     }


     // end book online JS


