function frontpage_init() {
	
	$('#cityText').autocomplete('./helpers/get_locations.php', {
								minChars: 2,
								max: 20,
								width: 370
								});

	$('#when_check_out').datepicker({
		showOn: 'button', 
		buttonImage: './i/calendar_btn.png', 
		buttonImageOnly: true,
		dateFormat: 'dd/mm/yy',
		minDate: '+0d',
		maxDate: '+1y',
		buttonText: '',
		duration: ''		
		});
	$('#when_check_in').datepicker({
		showOn: 'button', 
		buttonImage: './i/calendar_btn.png', 
		buttonImageOnly: true,
		dateFormat: 'dd/mm/yy',
		minDate: '+0d',
		maxDate: '+1y',		
		onSelect: function(selected_date) {update_checkout_date(selected_date);},
		buttonText: '',
		duration: ''	
		});
		
	var update_checkout_date = function(cd_string) {
		days_forward = 2;
		ci_parts = cd_string.split('/');
		ud_checkout = new Date(ci_parts[2], parseInt(ci_parts[1], 10) - 1, parseInt(ci_parts[0], 10) + 2);
		min_checkout = new Date(ci_parts[2], parseInt(ci_parts[1], 10) - 1, parseInt(ci_parts[0], 10) + 1)
	
		$('#when_check_out, #check_out_date').datepicker('option', 'minDate', min_checkout);
		$('#when_check_out, #check_out_date').datepicker('setDate', ud_checkout);
		}
	$('#hotSearch').submit(function() {
		var check_value = $('#cityText').val();
		check_value = $.trim(check_value);
		if(check_value == '') {
			alert('We need to know where you are going. Please type your destination in the "Where To?" field and we\'ll do the rest.');
			return false;
			}
		});
	}

function setDestination(city, state, country) {
	var destination = '';
	if (city != "") {
		destination += city;
		if(state != '')
			destination += ', ' + state;
		if(country != '')
			destination += ', ' + country;
		$('#cityText').val(destination);
		}
	}
		
function submitForm(form) {
    if (document.hotSearch.destination.value == "") {
        alert('must enter city');
        return false;
    	}
    return submitGuestInfoForm(form);
	}


    
	
	// NOTE: customize variables in this javascript block as appropriate.
    var defaultAdults="2";
    var cellStyle=' class="ps_label"';
	var altStyle=' class="ps_prompt"';
	var kidStyle=' class="kid_prompt"';
    var childHelp="Please provide the ages of children in each room. Children's ages should be their age at the time of travel.";
    var adultHelp="";
    var textRooms="Rooms";
    var textAdults='Adults <span class="byline">(age 18+)</span>';
    var textChildren='Children <span class="byline">(age 0-17)</span>';
    var textChildError="Please specify the ages of all children.";
    var pad='';
    // NOTE: Question marks ("?") get replaced with a numeric value
    var textRoomX="Room ?";
    var textChildX="Child ?";

    var adultsPerRoom=new Array(defaultAdults);
    var childrenPerRoom=new Array();
    var childAgesPerRoom=new Array();
    var numRooms=1;
    var maxChildren=0;
	
    function setChildAge(room, child, age) {
        if (childAgesPerRoom[room] == null) {
            childAgesPerRoom[room] = new Array();
        }
        childAgesPerRoom[room][child] = age;
    }

    function setNumAdults(room, numAdults) {
        adultsPerRoom[room] = numAdults;
    }

    function setNumChildren(room, numChildren) {
        childrenPerRoom[room] = numChildren;
        refresh();
    }

    function setNumRooms(x) {
        numRooms = x;
        for (i = 0; i < x; i++) {
            if (adultsPerRoom[i] == null) {
                adultsPerRoom[i] = 2;
            }
            if (childrenPerRoom[i] == null) {
                childrenPerRoom[i] = 0;
            }
        }
        refresh();
    }

    function renderRoomSelect() {
        var x = '';
        x += '<select name="numberOfRooms" onchange="setNumRooms(this.options[this.selectedIndex].value);">';
        for (var i = 1; i < 9; i++) {
            x += '<option value="'+i+'"'+(numRooms == i ? ' selected' : '')+'>' + i;
        }
        /*x += '<option value="9"'+(numRooms == 9 ? ' selected' : '')+'>9+';*/
        x += '</select>';
        return x;
    }

    function refresh() {
        maxChildren = 0;
        for (var i = 0; i < numRooms; i++) {
            if (childrenPerRoom[i] > maxChildren) {
                maxChildren = childrenPerRoom[i];
            }
        }

        var x = '';
        if (adultHelp.length > 0) {
            x = adultHelp + "<p>\n";
        }

        if (numRooms > 8) {
            x += textRooms;
            x += renderRoomSelect();

        } else {
            x += '<table class="how_many_params">\n';
            x += '<tr><td'+cellStyle+'><label>'+textRooms+pad+'</label></td>';
            if (numRooms > 1) {
                x += '<td'+cellStyle+'> </td>';
            }
            x += '<td'+cellStyle+'><label>'+textAdults+pad+'</label></td><td'+cellStyle+'><label>'+textChildren+pad+'</label></td></tr>\n';
            for (var i = 0; i < numRooms; i++) {
                x += '<tr><td'+cellStyle+'>';
                if (i == 0) {
                    x += renderRoomSelect();
                } else {
                    x += ' ';
                }
                x += '</td>';
                if (numRooms > 1) {
                    x += '<td'+altStyle+'>'+getValue(textRoomX, i+1)+pad + '</td>';
                }
                x += '<td'+cellStyle+'>';
                x += buildSelect('room-' + i + '-adult-total', 'setNumAdults(' + i + ', this.options[this.selectedIndex].value)', 1, 4, adultsPerRoom[i]);
                x += '</td><td'+cellStyle+'>';
                x += buildSelect('room-' + i + '-child-total', 'setNumChildren(' + i + ', this.options[this.selectedIndex].value)', 0, 4, childrenPerRoom[i]);
                x += '</td></tr>\n';
            }
            x += '</table>\n';

            var didHeader = false;
            for (var i = 0; i < numRooms; i++) {
                if (childrenPerRoom[i] > 0) {
                    if (!didHeader) {
                        x += '<table border="0" cellpadding="0" cellspacing="2">\n';
                        x += '<tr><td'+cellStyle+' colspan="'+(maxChildren+1)+'">';
                        x += '<p class="instructions">'+childHelp+'</p>';
                        x += '</td></tr>\n<tr><td'+cellStyle+'> </td>';
                        for (var j = 0; j < maxChildren; j++) {
                            x += '<td'+kidStyle+'><nobr>'+getValue(textChildX, j+1)+pad+'</nobr></td>\n';
                        }
                        didHeader = true;
                    }
                    x += '</tr>\n<tr><td'+altStyle+'><nobr>'+getValue(textRoomX, i+1)+pad+'</nobr></td>';
                    for (var j = 0; j < childrenPerRoom[i]; j++) {
                        x += '<td'+cellStyle+'>';
                        var def = -1;
                        if (childAgesPerRoom[i] != null) {
                            if (childAgesPerRoom[i][j] != null) {
                                def = childAgesPerRoom[i][j];
                            }
                        }
                        x += '<select name="room-'+i+'-child-'+j+'-age" onchange="setChildAge('+i+', '+j+', this.options[this.selectedIndex].value);">';
                        x += '<option value="-1"'+(def == -1 ? ' selected' : '')+'>-?-';
                        x += '<option value="0"'+(def == 0 ? ' selected' : '')+'><1';
                        for (var k = 1; k <= 18; k++) {
                            x += '<option value="'+k+'"'+(def == k ? ' selected' : '')+'>'+k;
                        }
                        x += '</td>';
                    }
                    if (childrenPerRoom[i] < maxChildren) {
                        for (var j = childrenPerRoom[i]; j < maxChildren; j++) {
                            x += '<td'+cellStyle+'> </td>';
                        }
                    }
                    x += '</tr>\n';
                }
            }
            if (didHeader) {
                x += '</table>\n';
            }
        }

        document.getElementById("hot-search-params").innerHTML = x;
    }

    function buildSelect(name, onchange, min, max, selected) {
        var x = '<select name="' + name + '"';
        if (onchange != null) {
            x += ' onchange="' + onchange + '"';
        }
        x +='>\n';
        for (var i = min; i <= max; i++) {
            x += '<option value="' + i + '"';
            if (i == selected) {
                x += ' selected';
            }

            x += '>' + i + '\n';
        }
        x += '</select>';
        return x;
    }

    function validateGuests(form) {
        if (numRooms < 9) {
            var missingAge = false;
            for (var i = 0; i < numRooms; i++) {
                var numChildren = childrenPerRoom[i];
                if (numChildren != null && numChildren > 0) {
                    for (var j = 0; j < numChildren; j++) {
                        if (childAgesPerRoom[i] == null || childAgesPerRoom[i][j] == null || childAgesPerRoom[i][j] == -1) {
                            missingAge = true;
                        }
                    }
                }
            }

            if (missingAge) {
                alert(textChildError);
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }

    function submitGuestInfoForm(form) {
        if (!validateGuests(form)) {
            return false;
        }
        return true;
    }

    function getValue(str, val) {
        return str.replace(/\?/g, val);
    }
//-->