﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
/// <reference path="adecco.core.js" />
/// <reference path="adecco.jobsearch.js" />
/// <reference path="adecco.jobsearch.JobResultsViewController.js" />
/// <reference path="interface.js" />
/// <reference path="jquery.form.js" />
/// <reference path="jquery-latest.js" />


// -- Define the Refine Search Controller --
$(document).ready(function() {
    //    var url = jQuery(location).attr('href');
    //    var param = document.URL.split('?')[1];
    $("#layer1").hide();
    $('#Resultupdate').hide();
   // $("#layer1").draggable();
   
    $('#close').click(function() {
        $("#layer1").hide();
        $('#Resultupdate').show();
    });

    $('#Resultupdate').click(function() {
        $("#layer1").hide();
        var url = location.href;
        var preURL = "";
        var postURL = "";
        var updatedURL = "";
        var jobkeywordFilter = $("#kws").val();
        var jobstrCityCheckFilter = $("#cty").val();
        var UpdatedUrl, CookiesSplit, CookiesLength;
        var filter_para = new Array();
        filter_para[0] = 'kws';
        //        filter_para[1] = 'cty';
        filter_para[1] = 'cat';
        filter_para[2] = 'ind';
        filter_para[3] = 'ctp';
        filter_para[4] = 'edu';
        filter_para[5] = 'dist';
        filter_para[6] = 'postedage';
        filter_para[7] = 'sft';
        filter_para[8] = 'ctr';
        filter_para[9] = 'yexp'

        this._rawQueryString = window.location.search;
        CookiesSplit = document.cookie.split(";");
        CookiesLength = CookiesSplit.length;
        for (jLoop = 0; jLoop < CookiesLength; jLoop++) {
            xIndex = CookiesSplit[jLoop].substr(0, CookiesSplit[jLoop].indexOf("="));
            yIndex = CookiesSplit[jLoop].substr(CookiesSplit[jLoop].indexOf("=") + 1);
            xIndex = xIndex.replace(/^\s+|\s+$/g, "");
            filterLength = filter_para.length;

            for (iIndex = 0; iIndex < filterLength; iIndex++) {
                if (xIndex == filter_para[iIndex]) {
                    if (yIndex != '-1') {
                        updatedURL += '&' + filter_para[iIndex] + '=' + yIndex;
                    }
                }
            }
        }
        jobkeywordFilter = encodeURIComponent($.trim(jobkeywordFilter)).replace(/%20/g, '+');
        //if (jobkeywordFilter != '' || jobstrCityCheckFilter != '') {
        window.location = window.location.href.split("?")[0] + '?' + 'kws=' + jobkeywordFilter + '&cty=' + jobstrCityCheckFilter + updatedURL;
        // } 

    });

    $('#SubmitPara').click(function() {
        $("#layer1").hide();
        //debugger;
        var url = location.href;
        var preURL = "";
        var postURL = "";
        var updatedURL = "";
        var UpdatedUrl, CookiesSplit, CookiesLength;
        var jobkeywordFilter = $("#kws").val();
        var jobstrCityCheckFilter = $("#cty").val();
        var filter_para = new Array();
        filter_para[0] = 'kws';
        //        filter_para[1] = 'cty';
        filter_para[1] = 'cat';
        filter_para[2] = 'ind';
        filter_para[3] = 'ctp';
        filter_para[4] = 'edu';
        filter_para[5] = 'dist';
        filter_para[6] = 'postedage';
        filter_para[7] = 'sft';
        filter_para[8] = 'ctr';
        filter_para[9] = 'yexp'

        this._rawQueryString = window.location.search;
        CookiesSplit = document.cookie.split(";");
        CookiesLength = CookiesSplit.length;
        for (jLoop = 0; jLoop < CookiesLength; jLoop++) {
            xIndex = CookiesSplit[jLoop].substr(0, CookiesSplit[jLoop].indexOf("="));
            yIndex = CookiesSplit[jLoop].substr(CookiesSplit[jLoop].indexOf("=") + 1);
            xIndex = xIndex.replace(/^\s+|\s+$/g, "");
            filterLength = filter_para.length;

            for (iIndex = 0; iIndex < filterLength; iIndex++) {
                if (xIndex == filter_para[iIndex]) {
                    if (yIndex != '-1') {
                        updatedURL += '&' + filter_para[iIndex] + '=' + yIndex;
                    }
                }
            }
        }
        jobkeywordFilter = encodeURIComponent($.trim(jobkeywordFilter)).replace(/%20/g, '+');
        //if (jobkeywordFilter != '' || jobstrCityCheckFilter != '') {
        window.location = window.location.href.split("?")[0] + '?' + 'kws=' + jobkeywordFilter + '&cty=' + jobstrCityCheckFilter + updatedURL;
        // }       

    });

});
adecco.jobsearch.RefineSearchController = function() {
    this._jobResultsController = null;
    this._gdsClientId = null;
};

adecco.jobsearch.RefineSearchController.prototype.setJobResultsController = function(controller) {
    this._jobResultsController = controller;
}

adecco.jobsearch.RefineSearchController.prototype.initialize = function(options) {
    this._gdsClientId = options.gdsClientId;
}


adecco.jobsearch.RefineSearchController.prototype.addSliderCriteria = function(criteriaCollection, fieldName, QueryStringParam, slider, container) {
    //Bug ID : #DE3017 Closed On : 09-Sept-2011 Remarks : Added Condition to filter only enabled Slider.
    var silederDisabled = $(slider).slider("option", "disabled");
    if (typeof (silederDisabled) !== 'undefined') {
        if (silederDisabled !== true) {
            var values = $(slider).slider("values"),
                    includeUnknownCheckbox = $(container).find('.include-unknown:checkbox:checked');

            // Duplicate the array to avoid modifying the original.
            values = values.slice(0);

            criteriaCollection.push({ 'field': fieldName, 'range': values, 'querystringParam': QueryStringParam, 'includeUnknown': (includeUnknownCheckbox.length > 0) });
        }

    }
}

adecco.jobsearch.RefineSearchController.prototype.addDropDownCriteria = function(criteriaCollection, fieldName, QueryStringParam, dropDown, container) {
    var value;

    value = $(dropDown).val();
    if (value) {
        criteriaCollection.push({ 'field': fieldName, 'value': value, 'querystringParam': QueryStringParam });
    }
}


adecco.jobsearch.RefineSearchController.prototype.isMatch = function(job, filters) {
    /// <summary>Determines whether the specified job matches the search filter.</summary>
    /// <returns>true if the job matches the filter; otherwise, false.</returns>

    var jobMatches = true, i, criterion, propertyValue;

    for (i = 0; i < filters.length; i++) {
        criterion = filters[i];

        // Because the ExtendedProperties property doesn't serialize as a nice dictionary,
        // we have to use a little hack.
        if (criterion.field.startsWith('ExtendedProperties')) {
            propertyValue = this._jobResultsController.getExtendedProperty(job, criterion.field.substring('ExtendedProperties.'.length)).Value;
        } else {
            propertyValue = adecco.getValueForPath(job, criterion.field);
        }

        if (typeof (criterion.value) !== 'undefined') {

            // Criterion has a unique value (e.g. from a drop-down, textbox or single value slider)
            if (propertyValue !== criterion.value) {
                return false;
            }
        } else if (typeof (criterion.range) !== 'undefined') {
        // Criterion is a range (e.g. from a range slider)

        // Check if value isn't available (i.e. null or undefined) and the "include unknown" checkbox
        // has NOT been set.
        if ((typeof (propertyValue) === 'undefined' || propertyValue === null)
                         && !criterion.includeUnknown) {
            return false;
        }

        if (criterion.field == 'Distance') {
            var distanceValue = $("#IsAllDistance").val();
            if (distanceValue === '1') {
                // Value is available, check if it's in the range.
                if ((propertyValue > criterion.range[1])) {
                    return false;
                }
            }
            else {
                // Value is available, check if it's in the range.
                if ((propertyValue < criterion.range[0] || propertyValue > criterion.range[1]) && propertyValue === -1) {
                    return false;
                }
            }
        }

        // Value is available, check if it's in the range.
        if ((propertyValue < criterion.range[0] || propertyValue > criterion.range[1]) && propertyValue !== -1) {
            return false;
        }
           

        } else {
            // Hmmm unexpected case... what to do?
        }
    }

    return true;
}

////adecco.jobsearch.RefineSearchController.prototype.isRangeMatch = function(job, filters) {

adecco.jobsearch.RefineSearchController.prototype.getFilterCriteria = function() {
var 
        that = this,
        webPartContainer = $('.refined-search-part'),
        filterCriteria = [];

        webPartContainer.find('.filter').each(function(index, elt) {
    var component;
    elt = $(elt);

    if ((component = elt.find('.ui-slider')).length > 0) {
        that.addSliderCriteria(filterCriteria, elt.attr('fieldPath'), elt.attr('querystringParam'), component, elt);
    } else if ((component = elt.find('select')).length > 0) {
        that.addDropDownCriteria(filterCriteria, elt.attr('fieldPath'), elt.attr('querystringParam'), component, elt);
    }
});


    return filterCriteria;
}

adecco.jobsearch.RefineSearchController.prototype.filter = function() {
    var 
    filterCriteria = [],
    allJobs,
    filteredJobs,
    item,
    i;

    log.debug('Starting filtering operation.');

    filterCriteria = this.getFilterCriteria();

    for (i = 0; i < filterCriteria.length; i++) {
        log.debug('Detected filter: ' + filterCriteria[i].field + '<br/> (include unknown:' + filterCriteria[i].includeUnknown + ').');
    }

    // Get all the jobs returned from the server.
    allJobs = this._jobResultsController.getResults();

    // Iterate over every job and add it to the filtered list if it meets the criteria
    filteredJobs = [];
    for (i = 0; i < allJobs.length; i++) {
        item = allJobs[i];
        if (this.isMatch(item, filterCriteria)) {
            filteredJobs.push(item);
        }
    }

    log.debug(filteredJobs.length + ' jobs match the filters');

    // Now that we've filtered the jobs we can display them.    
    this._jobResultsController.setFilteredResults(filteredJobs, true);

    $('.number-of-jobs').text(filteredJobs.length);

    adecco.jobsearch.mapManager.addData();

    log.debug('Filtering operation completed.');
}

adecco.jobsearch.RefineSearchController.prototype.sliderDidMove = function(event, ui) {
    /// <summary>Occurs when the slider moves.</summary>
    //debugger;
    var 
        fromValue = Math.round(ui.values[0]),
        toValue = Math.round(ui.values[1]),
        sliderHandle = $(ui.handle),
        container = sliderHandle.parents('.slider-filter-wrapper'),
        associatedLabel;


    // Only update from-to labels here as filtering on every slider move would be costly.
    $('.from-value', container).html(fromValue);
    $('.to-value', container).html(toValue);

    // Move the handle labels
    if (ui.value === fromValue) {
        // The current slider is the "from" slider
        associatedLabel = '.from-value';
    } else {
        // The current slider is the "to" slider.
        associatedLabel = '.to-value';
    }

    setTimeout(function() {
        $(associatedLabel, container).css('left', sliderHandle.css('left'));
    }, 5);
    //debugger;
    var associatedQueryStringParam = container.attr('querystringParam');
    var path = ';path=/';

    document.cookie = associatedQueryStringParam + '=' + Math.round(toValue) + path;
    if (toValue != null && typeof (toValue) != 'undefined')
        document.cookie = associatedQueryStringParam + 'Range' + '=' + Math.round(fromValue) + '|' + Math.round(toValue) + path;


//    var url = location.href;
//    var preURL = "";
//    var postURL = "";
//    var updatedURL = "";
//    var jobkeywordFilter = $("#kws").val();
//    var jobstrCityCheckFilter = $("#cty").val();
//    var UpdatedUrl, CookiesSplit, CookiesLength;
//    var filter_para = new Array();
//    filter_para[0] = 'kws';
//    filter_para[1] = 'cty';
//    filter_para[2] = 'cat';
//    filter_para[3] = 'ind';
//    filter_para[4] = 'ctp';
//    filter_para[5] = 'edu';
//    filter_para[6] = 'dist';
//    filter_para[7] = 'postedage';
//    filter_para[8] = 'sft';
//    filter_para[9] = 'ctr';
//    filter_para[10] = 'yexp'

//    this._rawQueryString = window.location.search;
//    CookiesSplit = document.cookie.split(";");
//    CookiesLength = CookiesSplit.length;
//    for (jLoop = 0; jLoop < CookiesLength; jLoop++) {
//        xIndex = CookiesSplit[jLoop].substr(0, CookiesSplit[jLoop].indexOf("="));
//        yIndex = CookiesSplit[jLoop].substr(CookiesSplit[jLoop].indexOf("=") + 1);
//        xIndex = xIndex.replace(/^\s+|\s+$/g, "");
//        filterLength = filter_para.length;

//        for (iIndex = 0; iIndex < filterLength; iIndex++) {
//            if (xIndex == filter_para[iIndex]) {
//                updatedURL += '&' + filter_para[iIndex] + '=' + yIndex;
//            }
//        }
//    }

//    //if (jobkeywordFilter != '' || jobstrCityCheckFilter != '') {
//    window.location = window.location.href.split("?")[0] + '?' + 'kws=' + jobkeywordFilter + '&cty=' + jobstrCityCheckFilter + updatedURL;
    // } 

}

adecco.jobsearch.RefineSearchController.prototype.sliderRefineDidMove = function(event, ui) {
    /// <summary>Occurs when the slider moves.</summary>
    //debugger;
    var 
        fromValue = Math.round(ui.values[0]),
        toValue = Math.round(ui.values[1]),
        sliderHandle = $(ui.handle),
        container = sliderHandle.parents('.slider-filter-wrapper'),
        associatedLabel;


    // Only update from-to labels here as filtering on every slider move would be costly.
    $('.from-value', container).html(fromValue);
    $('.to-value', container).html(toValue);

    // Move the handle labels
    if (ui.value === fromValue) {
        // The current slider is the "from" slider
        associatedLabel = '.from-value';
    } else {
        // The current slider is the "to" slider.
        associatedLabel = '.to-value';
    }

    setTimeout(function() {
        $(associatedLabel, container).css('left', sliderHandle.css('left'));
    }, 5);
    //debugger;
    var associatedQueryStringParam = container.attr('querystringParam');
    var path = ';path=/';

    document.cookie = "postedage" + '=' + Math.round(toValue) + path;

}

adecco.jobsearch.RefineSearchController.prototype.slideradvdatDidMove = function(event, ui) {
    //debugger;
    var 

        fromValue = Math.round(ui.values[0]),
        toValue = Math.round(ui.values[1]),
        sliderHandle = $(ui.handle),
        container = sliderHandle.parents('.slider-filter-wrapper'),
        associatedLabel;


    // Only update from-to labels here as filtering on every slider move would be costly.
    $('.from-value', container).html(fromValue);
    $('.to-value', container).html(toValue);

    // Move the handle labels
    if (ui.value === fromValue) {
        // The current slider is the "from" slider
        associatedLabel = '.from-value';
    } else {
        // The current slider is the "to" slider.
        associatedLabel = '.to-value';
    }

    setTimeout(function() {
        $(associatedLabel, container).css('left', sliderHandle.css('left'));
    }, 5);

    var fromValue = ui.values[0];
    var path = ';path=/';
    document.cookie = "postedage" + "=" + fromValue + path;
}
adecco.jobsearch.RefineSearchController.prototype.slideradvDistanceDidMove = function(event, ui) {
    //    debugger;
    var 

        fromValue = Math.round(ui.values[0]),
        toValue = Math.round(ui.values[1]),
        sliderHandle = $(ui.handle),
        container = sliderHandle.parents('.slider-filter-wrapper'),
        associatedLabel;


    // Only update from-to labels here as filtering on every slider move would be costly.
    $('.from-value', container).html(fromValue);
    $('.to-value', container).html(toValue);

    // Move the handle labels
    if (ui.value === fromValue) {
        // The current slider is the "from" slider
        associatedLabel = '.from-value';
    } else {
        // The current slider is the "to" slider.
        associatedLabel = '.to-value';
    }

    setTimeout(function() {
        $(associatedLabel, container).css('left', sliderHandle.css('left'));
    }, 5);

    var fromValue = ui.values[0];
    var path = ';path=/';
    document.cookie = "dist" + "=" + fromValue + path;
}
adecco.jobsearch.RefineSearchController.prototype.slideradvDistDidMove = function(event, ui) {
    /// <summary>Occurs when the slider moves.</summary>


var fromValue = ui.values[0];
var path = ';path=/';
document.cookie = "dist" + "=" + fromValue + path;
}
adecco.jobsearch.RefineSearchController.prototype.slideradvdistDidMove = function(event, ui) {
    /// <summary>Occurs when the slider moves.</summary>    
    // var 
    //   fromValue = ui.values[0],
    //    toValue = ui.values[1],
    //   sliderHandle = $(ui.handle),
    //   container = sliderHandle.parents('.slider-filter-wrapper'),
    //   associatedLabel;

    // Only update from-to labels here as filtering on every slider move would be costly.
    // $('.from-value', container).html(fromValue);
    //  $('.to-value', container).html(toValue);

    // Move the handle labels
    //  if (ui.value === fromValue) {
    // The current slider is the "from" slider
    //      associatedLabel = '.from-value';
    //  } else {
    // The current slider is the "to" slider.
    //      associatedLabel = '.to-value';
    //  }

    //  setTimeout(function() {
    //      $(associatedLabel, container).css('left', sliderHandle.css('left'));
    //  }, 5);

var fromValue = ui.values[0];
var path = ';path=/';
document.cookie = "dist" + "=" + fromValue + path;
}

sliderAdvanceDidMove = function(event, ui) {
    /// <summary>Occurs when the slider moves.</summary>

var fromValue = ui.values[0];
var path = ';path=/';
document.cookie = "dist=" + fromValue + path;
}
sliderAdvanceDatePostDidMove = function(event, ui) {
    /// <summary>Occurs when the slider moves.</summary>

var fromValue = ui.values[0];
var path = ';path=/';
    document.cookie = "postedage" + "=" + fromValue+path;
}


adecco.jobsearch.RefineSearchController.prototype.sliderDidChange = function(event, ui) {
    /// <summary>Occurs when the slider values has been changed (i.e. user stopped sliding)</summary>


    this.filter();

    // Notify any observers that the global search parameters have changed.
    var filterCriteria = this.getFilterCriteria();
    adecco.NotificationCenter.postNotificationName('SearchParametersChanged', this, filterCriteria);
}
adecco.jobsearch.RefineSearchController.prototype.sliderAdvDidChange = function(event, ui) {
    /// <summary>Occurs when the slider values has been changed (i.e. user stopped sliding)</summary>
    //debugger;

    this.filter();

    // Notify any observers that the global search parameters have changed.
    var filterCriteria = this.getFilterCriteria();
    adecco.NotificationCenter.postNotificationName('SearchParametersChanged', this, filterCriteria);
}

adecco.jobsearch.RefineSearchController.prototype.includeUnknownChange = function() {
    /// <summary>Occurs when the include unknown checkbox is clicked</summary>

    this.filter();

    // Either way, notify any observers that the global search parameters have changed.
    var filterCriteria = this.getFilterCriteria();
    adecco.NotificationCenter.postNotificationName('SearchParametersChanged', this, filterCriteria);
}

adecco.jobsearch.RefineSearchController.prototype.dropDownChanged = function(event) {

    var dropDown, newValue, container, associatedQueryStringParam, newUrl;
    var jobSearchService = '/_layouts/AdeccoGroup/WebParts/JobSearch/services/JobSearch.ashx';

    dropDown = $(event.target);
    newValue = $(dropDown).val();

    container = dropDown.parents('.filter');
    associatedQueryStringParam = container.attr('querystringParam');
    if (associatedQueryStringParam) {
        newUrl = new adecco.QueryString();
        newUrl.setValue(associatedQueryStringParam, newValue);
        newUrl.setValue("clientid", $("#gdsClientId").val());
        newUrl.setValue("psz", $("#defaultMaxJobs").val());
        newUrl.setValue("rds", this._jobResultsController.getRadius());

        // Instead of doing a page reload, get jobs through an ajax call to the JobSearch Handler.
        var searchServiceParams = newUrl._params;

        // Make the loading background cover the entire job results web part area
        var jobResultsWidth = $(".job-results-part").width();
        var jobResultsHeight = $(".job-results-part").height();

        $(".loading-background").width(jobResultsWidth);
        $(".loading-background").height(jobResultsHeight + 30);  // Add 30px to cover the "Next/Prev" paging links at the bottom.

        // If there are no job results, position the ajax loading animation close to the top of the web part.
        // Otherwise, position it closer to the middle of the page vertically.
        if (jobResultsHeight < 100) {
            $(".spinner-view-refine-search").css("top", "40px");
        }
        else {
            $(".spinner-view-refine-search").css("top", "300px");
        }

        $(".loading-background").css("opacity", "0.5");
        $(".loading-container").show();

        $.ajax({
            url: jobSearchService,
            data: searchServiceParams,
            dataType: "json",
            success: function(data) {
                $(".loading-container").hide();
                $(".job-list").show();
                $(".not-found").hide();
                $(".job-results-part").removeClass("has-error");

                adecco.jobsearch.resultsController._results = data.Results;
                adecco.jobsearch.resultsController.refineSearchController.filter();

                if (data.Results.length === 0) {
                    $(".not-found").show();
                }
            },
            error: function(XMLHttpRequest) {
                $(".job-list").hide();
                $(".not-found").hide();
                $(".job-results-part").addClass("has-error");
                $(".loading-container").hide();
            }
        });
    }
    else {
        this.filter();
    }
}

adecco.jobsearch.RefineSearchController.prototype.localfilter = function(associatedQueryStringParams, newValues, jobSearchServices, containers) {
var path = ';path=/';
document.cookie = associatedQueryStringParams + '=' + newValues + path;
//    var url = location.href;
//    var preURL = "";
//    var postURL = "";
//    var updatedURL = "";
//    var jobkeywordFilter = $("#kws").val();
//    var jobstrCityCheckFilter = $("#cty").val();
//    var UpdatedUrl, CookiesSplit, CookiesLength;
//    var filter_para = new Array();
//    filter_para[0] = 'kws';
//    filter_para[1] = 'cty';
//    filter_para[2] = 'cat';
//    filter_para[3] = 'ind';
//    filter_para[4] = 'ctp';
//    filter_para[5] = 'edu';
//    filter_para[6] = 'dist';
//    filter_para[7] = 'postedage';
//    filter_para[8] = 'sft';
//    filter_para[9] = 'ctr';
//    filter_para[10] = 'yexp'

//    this._rawQueryString = window.location.search;
//    CookiesSplit = document.cookie.split(";");
//    CookiesLength = CookiesSplit.length;
//    for (jLoop = 0; jLoop < CookiesLength; jLoop++) {
//        xIndex = CookiesSplit[jLoop].substr(0, CookiesSplit[jLoop].indexOf("="));
//        yIndex = CookiesSplit[jLoop].substr(CookiesSplit[jLoop].indexOf("=") + 1);
//        xIndex = xIndex.replace(/^\s+|\s+$/g, "");
//        filterLength = filter_para.length;

//        for (iIndex = 0; iIndex < filterLength; iIndex++) {
//            if (xIndex == filter_para[iIndex]) {
//                updatedURL += '&' + filter_para[iIndex] + '=' + yIndex;
//            }
//        }
//    }
//    window.location = window.location.href.split("?")[0] + '?' + 'kws=' + jobkeywordFilter + '&cty=' + jobstrCityCheckFilter + updatedURL;


    newUrl = new adecco.QueryString();
    newUrl.setValue(associatedQueryStringParams, newValues);
    newUrl.setValue("clientid", $("#gdsClientId").val());
    newUrl.setValue("psz", $("#defaultMaxJobs").val());
    newUrl.setValue("rds", containers._jobResultsController.getRadius());

    // Instead of doing a page reload, get jobs through an ajax call to the JobSearch Handler.
    var searchServiceParams = newUrl._params;

    // Make the loading background cover the entire job results web part area
    var jobResultsWidth = $(".job-results-part").width();
    var jobResultsHeight = $(".job-results-part").height();

    $(".loading-background").width(jobResultsWidth);
    $(".loading-background").height(jobResultsHeight + 30);  // Add 30px to cover the "Next/Prev" paging links at the bottom.

    // If there are no job results, position the ajax loading animation close to the top of the web part.
    // Otherwise, position it closer to the middle of the page vertically.
    if (jobResultsHeight < 100) {
        $(".spinner-view-refine-search").css("top", "40px");
    }
    else {
        $(".spinner-view-refine-search").css("top", "300px");
    }

    $(".loading-background").css("opacity", "0.5");
    $(".loading-container").show();

    $("#layer1").hide();
    $.ajax({
        url: jobSearchServices,
        data: searchServiceParams,
        dataType: "json",
        success: function(data) {
            $(".loading-container").hide();
            $(".job-list").show();
            $(".not-found").hide();
            $(".job-results-part").removeClass("has-error");

            adecco.jobsearch.resultsController._results = data.Results;
            adecco.jobsearch.resultsController.refineSearchController.filter();

            if (data.Results.length === 0) {
                $(".not-found").show();
            }
        },
        error: function(XMLHttpRequest) {
            $(".job-list").hide();
            $(".not-found").hide();
            $(".job-results-part").addClass("has-error");
            $(".loading-container").hide();
        }
    });
}

adecco.jobsearch.RefineSearchController.prototype.dropDownRefineChanged = function(event) {
    

    var dropDown, newValue, container, associatedQueryStringParam, newUrl;
    var jobSearchService = '/_layouts/AdeccoGroup/WebParts/JobSearch/services/JobSearch.ashx';


    var jobCategoryFilterID = document.getElementById("cat").id;

    var jobEmploymentTypeID = document.getElementById("ctp").id;
    var jobIndustryFilteIDr = document.getElementById("ind").id;
    var jobEducationLevelFilterID = document.getElementById("edu").id;
    var jobCountryFilterID = document.getElementById("ctr").id;
    var jobCityCheckID = document.getElementById("cty").id;
    var jobkeywordID = document.getElementById("kws").id;
    var jobShiftFilterID = document.getElementById("sft").id;

    var jobCategoryFilter = $("#cat").val();
    var jobEmploymentType = $("#ctp").val();
    var jobIndustryFilter = $("#ind").val();
    var jobEducationLevelFilter = $("#edu").val();
    var jobCountryFilter = $("#ctr").val();
    var jobCityCheck = $("#cty").val();
    var jobkeyword = $("#kws").val();
    var jobShiftFilter = $("#sft").val();

    var advanced_array = new Array();
    advanced_array['cat'] = jobCategoryFilter;
    advanced_array['ctp'] = jobEmploymentType;
    advanced_array['ind'] = jobIndustryFilter;
    advanced_array['edu'] = jobEducationLevelFilter;
    advanced_array['ctr'] = jobCountryFilter;
    advanced_array['cty'] = jobCityCheck;
    advanced_array['kws'] = jobkeyword;
    advanced_array['sft'] = jobShiftFilter;



    dropDown = $(event.target);
    newValue = $(dropDown).val();


    container = dropDown.parents('.filter');
    associatedQueryStringParam = container.attr('querystringParam');
    if (associatedQueryStringParam) {
        newUrl = new adecco.QueryString();
        newUrl.setValue(associatedQueryStringParam, newValue);
        newUrl.setValue("clientid", $("#gdsClientId").val());
        newUrl.setValue("psz", $("#defaultMaxJobs").val());
        newUrl.setValue("rds", this._jobResultsController.getRadius());

        var filterLength;
        filterLength = advanced_array.length;
        var ilength;

        if (newValue != "") {
            for (var i in advanced_array) {
                if (associatedQueryStringParam == i) {
                    if (advanced_array[i] == "") {
                        adecco.jobsearch.RefineSearchController.prototype.localfilter(associatedQueryStringParam, newValue, jobSearchService, this);
                    }
                    else {
                        var pos = $(dropDown).offset();
                        var width = $(dropDown).width();
                        $("#layer1").css({ "left": (pos.left + width) + "px", "top": pos.top + "px" });
                        $("#layer1").show();
                        var dats = new Date();
                        dats.setTime(dats.getTime() + (1 * 1 * 60 * 60 * 1000 + 29000 - 3600000 + 1990000));
                        var expires = '; expires=' + dats.toUTCString();
                        var path = ';path=/';
                        document.cookie = associatedQueryStringParam + '=' + newValue + expires + path;
                    }
                }
            }
        }
        else {

            var pos = $(dropDown).offset();
            var width = $(dropDown).width();
            $("#layer1").css({ "left": (pos.left + width) + "px", "top": pos.top + "px" });
            $("#layer1").show();
            //document.cookie = associatedQueryStringParam + '=' + newValue;
            var dats = new Date();
            dats.setTime(dats.getTime() + (1 * 1 * 60 * 60 * 1000 + 29000 - 3600000 + 1990000));
            var expires = '; expires=' + dats.toUTCString();
            var path = ';path=/';
            document.cookie = associatedQueryStringParam + '=' + '-1' + expires + path;
        }
    }
    else {
        this.filter();
    }
    // Notify any observers that the global search parameters have changed.
    var filterCriteria = this.getFilterCriteria();
    adecco.NotificationCenter.postNotificationName('SearchParametersChanged', this, filterCriteria);
}

adecco.jobsearch.RefineSearchController.prototype.dropDownvalueChanged = function(event) {

    var newparam, dropDown, newValue, container, associatedQueryStringParam, newUrl, count, i, url = '', oldurl, temp, value;
    dropDown = $(event.target);
    newValue = $(dropDown).val();
    container = dropDown.parents('.filter');
    associatedQueryStringParam = container.attr('querystringParam');
    document.cookie = associatedQueryStringParam + '=' + newValue;

    var string = window.location.search;
    var queries = string.split("&");
    var counter = queries.length;

    for (k = 0; k < counter; k++) {
        xx = queries[k].substr(0, queries[k].indexOf("="));
        xx = xx.replace('?', '');
        yy = queries[k].substr(queries[k].indexOf("=") + 1);
        xx = xx.replace(/^\s+|\s+$/g, "");
        if (xx != associatedQueryStringParam)
            document.cookie = xx + '=' + yy;
    }
    var newUrl;
    var c_name = new Array();
    c_name[0] = 'cat';
    c_name[1] = 'ind';
    c_name[2] = 'ctp';
    c_name[3] = 'edu';
    c_name[4] = 'rad';
    c_name[5] = 'kws';
    c_name[6] = 'cty';
    this._rawQueryString = window.location.search;
    var i, x, y, ARRcookies = document.cookie.split(";");
    var count = ARRcookies.length;
    var counter;
    for (j = 0; j < count; j++) {
        x = ARRcookies[j].substr(0, ARRcookies[j].indexOf("="));
        y = ARRcookies[j].substr(ARRcookies[j].indexOf("=") + 1);
        if (ARRcookies[j] != c_name[i] && x == '') {
            y = '';
            ARRcookies[j] = ARRcookies[j].replace(/^\s+|\s+$/g, "");
        }
        x = x.replace(/^\s+|\s+$/g, "");
        counter = c_name.length;
        for (i = 0; i < counter; i++) {
            if (x == c_name[i] || ARRcookies[j] == c_name[i] && x == '') {
                url += '&' + c_name[i] + '=' + y;
            }
        }
    }

    window.location = window.location.href.split("?")[0] + '?' + url;
}



//debugger;
adecco.jobsearch.RefineSearchController.prototype.dropDownvalueSChanged = function(event) {
    var newparam, dropDown, newValue, container, associatedQueryStringParam, newUrl, count, i, url, oldurl, temp, value;
    dropDown = $(event.target);
    newValue = $(dropDown).val();
    container = dropDown.parents('.filter');
    associatedQueryStringParam = container.attr('querystringParam');
    var path = ';path=/';
    document.cookie = associatedQueryStringParam + '=' + newValue + path;
}

adecco.jobsearch.RefineSearchController.prototype.setQueryStringWithCookie = function(event) {

    var string = window.location.search;
    var newUrl;
    var c_name = new Array();
    c_name[0] = 'cat';
    c_name[1] = 'ind';
    c_name[2] = 'ctp';
    c_name[3] = 'edu';
    c_name[4] = 'dist';
    c_name[5] = 'postedage';
    c_name[6] = 'sft';
    c_name[7] = 'ctr';
    c_name[8] = 'yexp';
    this._rawQueryString = window.location.search;
    var i, x, y, ARRcookies = document.cookie.split(";");
    var count = ARRcookies.length;
    var counter;
    for (j = 0; j < count; j++) {
        x = ARRcookies[j].substr(0, ARRcookies[j].indexOf("="));
        y = ARRcookies[j].substr(ARRcookies[j].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        counter = c_name.length;
        for (i = 0; i < counter; i++) {
            if (x == c_name[i]) {
                this._rawQueryString += '&' + c_name[i] + '=' + y;
            }
        }
    }
    newUrl = window.location.href.substring(0) + '?' + this._rawQueryString;
    window.location = window.location = window.location.href + this._rawQueryString; // newUrl;
    window.location.href = window.location = window.location.href + this._rawQueryString;
     var path = ';path=/';
     window.document.cookie = "URL" + '=' + newUrl + path;
}

function getPathFromUrl(url) {
    return url.split("&")[0];
}


function containsAlphabets(checkString) {
    var tempString = "";
    var regExp = "?";
    if (checkString.charAt(0) == regExp)
        return true;
    else
        return false;

}

function containsValue(checkString, compare) {
    var tempString = "";
    var regExp = compare;
    if (checkString != null && checkString != "") {
        for (var i = 0; i < checkString.length; i++) {
            if (!checkString.charAt(i).match(regExp)) {
                return false;
            }
        }
    }
    else {
        return false;
    }
    return true;
}


adecco.jobsearch.RefineSearchController.prototype.getDropDowns = function(event) {

    var dropdown = document.getElementById(Distance);
}

adecco.jobsearch.addSliderHandleLabel = function(slider) {
    //var slider = this;
    // debugger;
    var 
        values = $(slider).slider("values"),
        parent = $(this).parents('.slider-filter-wrapper'),
        handles = $('.ui-slider-handle', slider);

    /* handles[0] will refer to the left handle (lower bound)
    * while handles[1] will refer to the right handle (upper bound) */

    // Add low-bound value.
    $('<div/>')
            .addClass('slider-label from-value')
            .css('left', $(handles[0]).css('left'))
            .html(values[0])
            .appendTo(slider);

    // Add upper-bound value.

    $('<div/>')
            .addClass('slider-label to-value')
            .css('left', $(handles[1]).css('left'))
            .html(values[1])
            .appendTo(slider);
}
adecco.jobsearch.addDistanceSliderHandleLabel = function(slider) {
    //var slider = this;

    var 
        values = $(slider).slider("values"),
        parent = $(this).parents('.slider-filter-wrapper'),
        handles = $('.ui-slider-handle', slider);

    /* handles[0] will refer to the left handle (lower bound)
    * while handles[1] will refer to the right handle (upper bound) */

    // Add low-bound value.
    $('<div/>')
            .addClass('slider-label from-value')
            //.css('right', $(handles[0]).css('right'))
            .html(values[0])
            .appendTo(slider);
    // Add upper-bound value.


}
//Added by sandeep
adecco.jobsearch.RefineSearchController.prototype.slideradvsliddatDidMove = function(event, ui) {
    //debugger;
    var 

        fromValue = Math.round(ui.values[0]),
        toValue = Math.round(ui.values[1]),
        sliderHandle = $(ui.handle),
        container = sliderHandle.parents('.slider-filter-wrapper'),
        associatedLabel;


    // Only update from-to labels here as filtering on every slider move would be costly.
    $('.from-value', container).html(fromValue);
    $('.to-value', container).html(toValue);

    // Move the handle labels
    if (ui.value === fromValue) {
        // The current slider is the "from" slider
        associatedLabel = '.from-value';
    } else {
        // The current slider is the "to" slider.
        associatedLabel = '.to-value';
    }

    setTimeout(function() {
        $(associatedLabel, container).css('left', sliderHandle.css('left'));
    }, 5);

    var fromValue = ui.values[0];
    var path = ';path=/';
    document.cookie = "yexp" + "=" + fromValue + path;
}

adecco.jobsearch.addAdvPostSliderHandleLabel = function(slider) {
    //var slider = this;
    // debugger;
    var 
        values = $(slider).slider("values"),
        parent = $(this).parents('.slider-filter-wrapper'),
        handles = $('.ui-slider-handle', slider);

    /* handles[0] will refer to the left handle (lower bound)
    * while handles[1] will refer to the right handle (upper bound) */

    // Add low-bound value.
    $('<div/>')
            .addClass('slider-label from-value')
            //.css('right', $(handles[0]).css('right'))
            .html(values[0])
            .appendTo(slider);

}

adecco.jobsearch.RefineSearchController.prototype.sliderAdvslidDateDidChange = function(event, ui) {
    /// <summary>Occurs when the slider values has been changed (i.e. user stopped sliding)</summary>
    //debugger;

    this.filter();

    // Notify any observers that the global search parameters have changed.
    var filterCriteria = this.getFilterCriteria();
    adecco.NotificationCenter.postNotificationName('SearchParametersChanged', this, filterCriteria);
}

//End here
adecco.jobsearch.addAdvSliderHandleLabel = function(slider) {
    //var slider = this;
    //    debugger;
    var 
        values = $(slider).slider("values"),
        parent = $(this).parents('.slider-filter-wrapper'),
        handles = $('.ui-slider-handle', slider);

    /* handles[0] will refer to the left handle (lower bound)
    * while handles[1] will refer to the right handle (upper bound) */

    // Add low-bound value.
    $('<div/>')
            .addClass('slider-label from-value')
            //.css('right', $(handles[0]).css('right'))
            .html(values[0])
            .appendTo(slider);

}

adecco.jobsearch.addAdvPostSliderHandleLabel = function(slider) {
    //var slider = this;
    //    debugger;
    var 
        values = $(slider).slider("values"),
        parent = $(this).parents('.slider-filter-wrapper'),
        handles = $('.ui-slider-handle', slider);

    /* handles[0] will refer to the left handle (lower bound)
    * while handles[1] will refer to the right handle (upper bound) */

    // Add low-bound value.
    $('<div/>')
            .addClass('slider-label from-value')
            //.css('right', $(handles[0]).css('right'))
            .html(values[0])
            .appendTo(slider);

}

/*
fadeoutDistanceSlider= function() {

$("#Distance").fadeOut("slow");
}
*/

