var GuidedNavigation = {
    //Controls the price dropdowns Ajax engine for property search results
    setPriceOptions: function(objSourceElement, targetContainer) {
        var objTargetContainer;
        var objTargetElement;
        var options;
        var targetElement;
        var sourceContainer;
        var targetSelectedValue;

        //Get the prefix for Min and Max components
        targetElement = objSourceElement.name.substring(0, objSourceElement.name.length - 3);
        sourceContainer = targetContainer.substring(0, targetContainer.length - 3);

        if (objSourceElement.name.indexOf('m_ddlListPriceMin') >= 0) {
            //Set the elements names when Minimum price dropdown was selected
            targetElement += "Max";
            sourceContainer += "Min";
        }
        else {
            //Set the elements names when Maximum price dropdown was selected
            targetElement += "Min";
            sourceContainer += "Max";
        }

        //Get the selected value of the target element to later pass it as a parameter to the aspx page
        //The aspx page will then use it to remain the selected option on the new dropdown
        objTargetElement = document.getElementsByName(targetElement)[0];
        targetSelectedValue = objTargetElement.value;

        //Set the url query string parameters
        originalParameters = window.location.search;

        //PropertySearchZero should never user old parameters
        if (!originalParameters || window.location.pathname == '/PropertySearchZero.aspx') {
            originalParameters = '?N=12';
        }

        if (originalParameters.indexOf('N=') < 0 || originalParameters.indexOf('curr=') >= 0) {
            originalParameters = originalParameters + '&N=12';
        }

        if (originalParameters.indexOf('lang=') < 0) {
            originalParameters = originalParameters + "&lang=" + window.location.pathname.substr(1, 2);
        }

        options = originalParameters + "&SourceNValue=" + objSourceElement.value + "&TargetElementName=" + targetElement + "&SourceContainerName=" + sourceContainer + "&TargetSelectedValue=" + targetSelectedValue;

        //Display the Loading message instead of the old dropdown
        //The message will be replaced with the new dropdown by the Ajax.Updater call
        objTargetContainer = document.getElementById(targetContainer);
        objTargetContainer.innerHTML = "Loading...";

        //Call the ajax framework
        //passing the the target container (div)
        //and the aspx page that will execute the endeca query and then build and return the new dropdown		

        new Ajax.Updater(objTargetContainer, "AjaxPriceMinMax.ashx" + options, { method: 'get' });
        return false;
    }
}

var GuidedNavigationWithSize = {
    setPriceOptions: function(objSourceElement, targetContainer, size) {
        var objTargetContainer;
        var objTargetElement;
        var options;
        var targetElement;
        var sourceContainer;
        var targetSelectedValue;

        //Get the prefix for Min and Max components
        targetElement = objSourceElement.name.substring(0, objSourceElement.name.length - 3);
        sourceContainer = targetContainer.substring(0, targetContainer.length - 3);

        if (objSourceElement.name.indexOf('m_ddlListPriceMin') >= 0) {
            //Set the elements names when Minimum price dropdown was selected
            targetElement += "Max";
            sourceContainer += "Min";
        }
        else {
            //Set the elements names when Maximum price dropdown was selected
            targetElement += "Min";
            sourceContainer += "Max";
        }

        //Get the selected value of the target element to later pass it as a parameter to the aspx page
        //The aspx page will then use it to remain the selected option on the new dropdown
        objTargetElement = document.getElementsByName(targetElement)[0];
        targetSelectedValue = objTargetElement.value;

        //Set the url query string parameters
        originalParameters = window.location.search;

        //PropertySearchZero should never user old parameters
        if (!originalParameters || window.location.pathname == '/PropertySearchZero.aspx') {
            originalParameters = '?N=12';
        }

        if (originalParameters.indexOf('N=') < 0 || originalParameters.indexOf('curr=') >= 0) {
            originalParameters = originalParameters + '&N=12';
        }

        if (originalParameters.indexOf('lang=') < 0) {
            originalParameters = originalParameters + "&lang=" + window.location.pathname.substr(1, 2);
        }

        options = originalParameters + "&SourceNValue=" + objSourceElement.value + "&TargetElementName=" + targetElement + "&SourceContainerName=" + sourceContainer + "&TargetSelectedValue=" + targetSelectedValue;

        if (options.length > 0)
            options = options + "&size=" + size;
        else
            options = "?size=" + size;

        //Display the Loading message instead of the old dropdown
        //The message will be replaced with the new dropdown by the Ajax.Updater call
        objTargetContainer = document.getElementById(targetContainer);
        objTargetContainer.innerHTML = "Loading...";

        //Call the ajax framework
        //passing the the target container (div)
        //and the aspx page that will execute the endeca query and then build and return the new dropdown		

        new Ajax.Updater(objTargetContainer, "AjaxPriceMinMax.ashx" + options, { method: 'get' });
        return false;
    }

}
