/**
 * @title       Travel guide results scripts Touring Nature 
 */
$(document).ready(function(){

    
    
    //initializeGmap();

    var changeSelect = function(sTargetSelectId, iId) {
        $.get(l10n.url.selectOptions + eval("l10n.url." + sTargetSelectId + "Select"), {id:iId, eid:getUrlParameter('eid'), offer:'renting'}, 
            function(data){
               var newOptions = new Array();
               //newOptions[0] = {value:'',text:eval("l10n."+sTargetSelectId+"Choice"),selected:true}; 
                xmlDoc = (data).getElementsByTagName('city'); 
                xmlDocLen = xmlDoc.length;
                if (xmlDocLen) {
                    $('#' + sTargetSelectId).parent(".select").removeClass('disabled');
                    for (var i=0; i<xmlDocLen; i++) {
                        var j = i;
                        newOptions[j] = {
                            value: xmlDoc[i].getAttribute("id"),
                            text: xmlDoc[i].firstChild.nodeValue,
                            selected:false
                        };
                        j++;
                    } 
                } else if (sTargetSelectId == 'region') {
                    $('#' + sTargetSelectId).parent(".select").addClass('disabled');
                }
               box.ui('form.rentSearch').field(sTargetSelectId).setOptions(newOptions, true); 
               box.ui('form.rentSearch').field(sTargetSelectId).setIndex(box.ui('form.rentSearch').field(sTargetSelectId).getIndex()); 
            });
    }

    box.bind({
        'change.field.select.rentCountry' : function(e) {
            if (e.source.getValue() != null) {
                changeSelect('rentCity', this.getValue());
            }
        }
    });
    
    
});
