﻿
var GoNow = GoNow || {};
GoNow.Reservation = {
    UI: {
        Show: function(HTMLID){
	        $(HTMLID).style.display = 'block';
	    },
    	
	    Hide: function(HTMLID){
	        $(HTMLID).style.display = 'none';
	    }
    },
    
    Tabs: {
        Activate: function(id_flag){
			//all controls
			//set 01 [number_of_passengers]
			this.pax1 = 'number_of_passengers_1';
			this.pax2 = 'number_of_passengers_2';
			this.pax3 = 'number_of_passengers_3';
			//set 04 pax text to change[pax_1]
			this.pax_text1 = 'pax_1';
			this.pax_text2 = 'pax_2';
			this.pax_text3 = 'pax_3';
			//set 02 [number_of_persons]
			this.persons1 = 'number_of_persons_1';
			this.persons2 = 'number_of_persons_2';
			this.persons3 = 'number_of_persons_3';
			//set 03 [weight_capacity_div]
			this.cap1 = 'weight_capacity_div_1';
			this.cap2 = 'weight_capacity_div_2';
			this.cap3 = 'weight_capacity_div_3';
			//hdn field that saves the current tab
			var currentTab = $('current_tab');
			
			switch(id_flag){
				case 'tab1_':
					currentTab.value = 1;
					this.HighlightTab(id_flag);
					this.ShowAllPax();
					this.ChangeAllTextPax();
					this.HideAllPersons();
					this.HideAllWeightCapacity();
					break;
				
				case 'tab2_':
					currentTab.value = 2;
					this.HighlightTab(id_flag);
					this.ShowAllPax();
					this.ChangeAllTextPersons();
					this.ShowAllPersons();
					this.HideAllWeightCapacity();
					break;
				
				case 'tab3_':
					currentTab.value = 3;
					this.HighlightTab(id_flag);
					this.HideAllPax();
					this.ShowAllPersons();
					this.ShowAllWeightCapacity();
					break;
			}
		},
		
		HighlightTab: function(tab_id){
		    /*
		    Note:
		        Prototype JS Framework has a serious problem with gonow code in this point,
		        It doesn't apply some certain functions like:
		            Element.show
		            Element.hide
		            Element.invoke
		            Element.update
		            Element.addClassName
		            Element.removeClassName
		            Element.setStyle
		        I don't know why is that? ...
		    */
		    //release all tabs
		    $('tab1_').style.color = $('tab2_').style.color = $('tab3_').style.color = '#343333';
		    $('tab1_').style.background = $('tab2_').style.background = $('tab3_').style.background = 'url(images/tab-bg.jpg)';
		    $(tab_id).style.color = '#FFF';
		    $(tab_id).style.background = 'url(images/tab-bg-active.jpg)';
		},
		
		ShowAllPax: function(){
		    GoNow.Reservation.UI.Show(this.pax1);
		    GoNow.Reservation.UI.Show(this.pax2);
		    GoNow.Reservation.UI.Show(this.pax3);
			//$(this.pax1, this.pax2, this.pax3).invoke('show');
		},
		
		HideAllPax: function(){
		    GoNow.Reservation.UI.Hide(this.pax1);
		    GoNow.Reservation.UI.Hide(this.pax2);
		    GoNow.Reservation.UI.Hide(this.pax3);
			//$(this.pax1, this.pax2, this.pax3).invoke('hide');			
		},
		
		ShowAllPersons: function(){
		    GoNow.Reservation.UI.Show(this.persons1);
		    GoNow.Reservation.UI.Show(this.persons2);
		    GoNow.Reservation.UI.Show(this.persons3);
			//$(this.persons1, this.persons2, this.persons3).invoke('show');
		},
		
		HideAllPersons: function(){
		    GoNow.Reservation.UI.Hide(this.persons1);
		    GoNow.Reservation.UI.Hide(this.persons2);
		    GoNow.Reservation.UI.Hide(this.persons3);
			//$(persons1, persons2, persons3).invoke('hide');		
		},
		
		ShowAllWeightCapacity: function(){
		    GoNow.Reservation.UI.Show(this.cap1);
		    GoNow.Reservation.UI.Show(this.cap2);
		    GoNow.Reservation.UI.Show(this.cap3);
			//$(this.cap1, this.cap2, this.cap3).invoke('show');				
		},
		
		HideAllWeightCapacity: function(){
		    GoNow.Reservation.UI.Hide(this.cap1);
		    GoNow.Reservation.UI.Hide(this.cap2);
		    GoNow.Reservation.UI.Hide(this.cap3);
			//$(this.cap1, this.cap2, this.cap3).invoke('hide');	
		},
		
		ChangeAllTextPax: function(){
		    $(this.pax_text1).innerHTML = $(this.pax_text2).innerHTML = $(this.pax_text3).innerHTML = 'Number of passengers:';
			/*
			$(this.pax_text1).update('Number of passengers:');
			$(this.pax_text2).update('Number of passengers:');
			$(this.pax_text3).update('Number of passengers:');
			*/
		},
		
		ChangeAllTextPersons: function(){
		    $(this.pax_text1).innerHTML = $(this.pax_text2).innerHTML = $(this.pax_text3).innerHTML = 'Number of patients:';
			/*
			$(this.pax_text1).update('Number of patients:');
			$(this.pax_text2).update('Number of patients:');
			$(this.pax_text3).update('Number of patients:');
			*/
		}
    },
    
    IsEmpty: null
};

var Utilities = {
        $: function() {
            var elements = new Array();
            for (var i = 0 ; i < arguments.length ; i++) {
                var element = arguments[i];
                if ( typeof element == 'string' ) element = document.getElementById(element);
                if ( arguments.length == 1 ) return element;
                elements.push( element );
            }
            return elements;
        },
    
        convertObjectToQueryString: function(obj){
            if(obj || typeof obj === 'object'){
                //add ?
                var rQueryString = '?';
                
                for (var key in obj){
                    //build query string
                    rQueryString += key + '=' + obj[key] + '&';
                }
                //slice the last &
                rQueryString = rQueryString.substring(0, rQueryString.length-1);
            }
            return rQueryString;
        },
		
		attachEventListeners: function(){
			for(var i=0 ; i<arguments.length ; i++){
				if( $(arguments[i]) ){
					this.AddEventListener($(arguments[i]), 'click', function() {
						GoNow.Reservation.Tabs.Activate(this.id);
					}, false);
				}
			}
		},
		
		AddEventListener: function(element, eventType, handler, capture){
			if (element.addEventListener) element.addEventListener(eventType, handler, capture);
			else if (element.attachEvent) element.attachEvent("on" + eventType, handler);
		}
};
