/* Copyright 2008 Simply Extras Ltd */
var g_parking_form;function g_parking_form_init(c,b,d){g_parking_form=new ParkingForm("parking_form",c,b,d);g_parking_form.populate_locations();g_parking_form.setup_dates(b,d);g_parking_form.show_calendar_links();g_parking_form.populate_times(b,d);var a=document.getElementById("refresh-dates");if(a){a.style.display="none"}}function ParkingForm(b,j,d,l){var h=this;h.gosajax=new GOSAjax("/parking/ajax.php");h.gosajax.register_callback(function(n,o,p){if(h.gosajax.get_num_pending_requests()==0){h.hide_ajax_throbber()}});h.ajax_throbber=document.getElementById("search-throbber");h.post_throbber=document.getElementById("post-throbber");h.search_elements=document.getElementById("search-elements");h.form_name=b;h.form=document.forms[h.form_name];h.form_actions=new Array();h.form_action="";var f=String(j).split("-");h.default_location_value=f[0];h.default_terminal_value=f.length>1?f[1]:undefined;h.elements=new Array();h.elements.airport=h.form.airport;h.elements.location=h.form.location;h.elements.terminal=h.form.terminal;h.elements.arrive_t=h.form.arrive_t;h.elements.return_t=h.form.return_t;h.elements.submit=h.form.search_button;var e={locations:false,terminals:false,dates:false,times:false};var m=function(p){if(typeof(p)!=="undefined"){e[p]=true}var n=true;for(var o in e){if(!e[o]){n=false;break}}if(n){h.elements.submit.disabled=false}return n};h.flip_me=function(){var n=document.getElementById("search-form-amend");n.style.display=(n.style.display==""?"none":"")};h.show_ajax_throbber=function(){h.ajax_throbber.style.visibility="visible"};h.hide_ajax_throbber=function(){h.ajax_throbber.style.visibility="hidden"};h.show_post_throbber=function(){h.post_throbber.style.visibility="visible";h.search_elements.style.visibility="hidden"};h.hide_post_throbber=function(){h.post_throbber.style.visibility="hidden";h.search_elements.style.visibility="visible";GOSLib.DOM.hack_stop()};function a(n,o,p){var q="";if(o==-1){q="Sorry, the request to fetch the location list has timed out."}if(o==0){q="Sorry, there was an error fetching the location list."}if((o==1)&&(!p)){q=GOSAjax.get_response_error(n)}if(q==""){GOSLib.DOM.Select.empty(h.elements.location);GOSLib.DOM.Select.add_option(h.elements.location,0,"Select an Airport",false);GOSLib.DOM.Select.add_option(h.elements.location,0,"-------------------",false);GOSLib.DOM.Select.add_options_from_XML(h.elements.location,n.documentElement.getElementsByTagName("options")[0],(h.default_location_value=="0")?undefined:h.default_location_value);h.form_actions=GOSLib.DOM.get_options_from_XML(n.documentElement.getElementsByTagName("actions")[0],"action");h.changed_location();m("locations")}GOSAjax.done(q)}h.populate_locations=function(){h.show_ajax_throbber();h.gosajax.call("get_airports",Array(),a)};function g(n,o,p){var q="";if(o==-1){q="Sorry, the request to fetch the airport terminal list has timed out."}if(o==0){q="Sorry, there was an error fetching the airport terminal list."}if((o==1)&&(!p)){q=GOSAjax.get_response_error(n)}if(q==""){GOSLib.DOM.Select.empty(h.elements.terminal);GOSLib.DOM.Select.add_option(h.elements.terminal,0,"Select a Terminal",false);GOSLib.DOM.Select.add_option(h.elements.terminal,0,"-------------------",false);GOSLib.DOM.Select.add_options_from_XML(h.elements.terminal,n.documentElement.getElementsByTagName("options")[0],h.elements.location.value==h.default_location_value?h.default_terminal_value:undefined);if(h.elements.terminal.childNodes.length==3){h.elements.terminal.style.display="none";h.elements.terminal.selectedIndex=2}else{h.elements.terminal.style.display=""}h.changed_terminal();m("terminals")}GOSAjax.done(q)}h.populate_terminals=function(){if(parseInt(h.elements.location.value)==0){m("terminals");return undefined}h.show_ajax_throbber();h.gosajax.call("get_terminals",[h.elements.location.value],g)};h.setup_dates=function(o,r){var q="U";var p=Date.fromSeconds(o);var n=Date.fromSeconds(r);h.Arrive=new GOSCal(p,{parent_node:document.getElementById("arrive_output"),output:{name:"arrive_my",format:q},onchange:function(t){if(h.Return){h.Return.unrender();h.Return.each_control(function(u){u.unrender();h.Return.remove_control(u)});h.Return=new GOSCal(Date.max(h.Arrive.valueOf(),h.Return.valueOf()),{begin:h.Arrive.valueOf(),end:h.Arrive.options.end,parent_node:document.getElementById("return_output"),output:{format:q,name:"return_my"}});if(h.Arrive_drop.is_expanded()){h.Return_drop=h.Return.create_expanding_summary_control("return_");h.Return_drop.expand()}else{h.Return_drop=h.Return.create_expanding_summary_control("return_",{onexpand:function(){h.Arrive_drop.expand()}})}}return true}});h.Arrive_drop=h.Arrive.create_expanding_summary_control("arrive_",{onexpand:function(){if(h.return_drop){h.Return_drop.expand()}return true}});h.Return=new GOSCal(n,{begin:h.Arrive.valueOf(),end:h.Arrive.options.end,parent_node:document.getElementById("return_output"),output:{format:q,name:"return_my"}});h.Return_drop=h.Return.create_expanding_summary_control("return_",{onexpand:function(){h.Arrive_drop.expand()}});m("dates")};h.populate_times=function(v,C){var r;GOSLib.DOM.Select.empty(h.elements.arrive_t);GOSLib.DOM.Select.empty(h.elements.return_t);var A="00";var x="30";var B=Date.fromSeconds(v).format("H:i");var o=Date.fromSeconds(C).format("H:i");for(r=0;r<24;r++){var n=r.lpad(2,"0");var u=["00","15","30","45"];for(var q=0;q<u.length;q++){s=n+":"+u[q];if(r||q){var w={arrive_t:B,return_t:o};for(var D in w){GOSLib.DOM.Select.add_option(h.elements[D],n+u[q],s,(s==w[D])?1:0)}}}}m("times")};var k=undefined;h.showcal_arrive=function(){if((!h.showcal_arrive.cal)||!h.Arrive.has_control(h.showcal_arrive.cal)){h.showcal_arrive.cal=h.Arrive.create_calendar_control({parent_node:document.getElementById("arrive_cal")})}};var c=undefined;h.showcal_return=function(){if((!h.showcal_return.cal)||!h.Return.has_control(h.showcal_return.cal)){h.showcal_return.cal=h.Return.create_calendar_control({parent_node:document.getElementById("return_cal")})}};h.show_calendar_links=function(){document.getElementById("cal_link_from").style.display="";document.getElementById("cal_link_to").style.display=""};h.update_form_action=function(){var n=h.elements.location.value;if(n=="0"){return}for(i=0;i<h.form_actions.length;++i){if(h.form_actions[i]["value"]==n){h.form.action=h.form_actions[i]["text"];return}}};h.changed_location=function(){h.update_form_action();h.populate_terminals()};h.mousedowned_location=function(){h.elements.location.style.backgroundColor=""};h.changed_terminal=function(){h.elements.airport.value=h.elements.location.value+(h.elements.terminal.value==""||h.elements.terminal.value=="0"?"":("-"+h.elements.terminal.value))};h.mousedowned_terminal=function(){h.elements.terminal.style.backgroundColor=""};h.form_date=function(q,o){var p=parseInt(o.first(2),10);var n=parseInt(o.last(2),10);return Date.fromSeconds(parseInt(Date.fromSeconds(q).build({hour:0,minute:0,second:0,millisecond:0}).format("U"))+(p*60*60)+(n*60))};h.validate=function(){var q=0;var o=new Array();var p;if(h.gosajax.get_num_pending_requests()>0){return false}if(h.elements.location.value=="0"){q++;o.push(h.elements.location)}if(h.elements.terminal.value=="0"){q++;o.push(h.elements.terminal)}GOSLib.Flasher.flash(function(t,u){var r;for(r=0;r<u.length;r++){u[r].style.backgroundColor=(t%2?"#ffdddd":"")}},6,100,o);if(q==0){h.show_post_throbber();var n=document.getElementById("post-throbber-img");if(n){setTimeout('document.getElementById("post-throbber-img").src = "/img/elements/search-waiting.gif"',200)}}return q==0}};