﻿/* initialize the Ajax handler */ 
$().ready(function(){
    LeftHandPrompt.init();

    //domain && category
    UnCheckChildBox(".searchParameters .domain .chkBoxLabel input", ".searchParameters .category .chkBoxLabel input");
    CheckParentBox(".searchParameters .domain .chkBoxLabel input", ".searchParameters .category .chkBoxLabel input");
    //region && department
    UnCheckChildBox(".searchParameters .region .chkBoxLabel input", ".searchParameters .department .chkBoxLabel input");
    CheckParentBox(".searchParameters .region .chkBoxLabel input", ".searchParameters .department .chkBoxLabel input");      		
});


/*Post-search left-hand prompt
* This describes an element that appears on the left side of the screen, this search bar must be displayed in the left-hand column of the screen
* Within this element, several sub-elements must be displayed according to the search criteria available in the Advanced/Quick Search interface
* i.e: 
*       - Keywords
*       - JobType
*       - Type de contract
*       - Localisation
*       - Date de publication
*/
LeftHandPrompt = {

    wrongKeywords: "", //It contains the wrong keywords

    init: function() {
        if (TFI.ClientServices.JobSearch != null) {
            LeftHandPrompt.initWrongKeywords();
            LeftHandPrompt.clickAddKeyword();
            LeftHandPrompt.FiltersOffersEmployment();
            LeftHandPrompt.clearItemsUnchecked();
            LeftHandPrompt.Autocomplete();
            LeftHandPrompt.Search();
            LoadLinkPagination();
            refreshDisabledLinks();
            LoadLinkRelatedJobs();
        }
    },

    /*Add event click to the "Ajouter" button, your funtionality is add keywords
    * to the keywords list */
    clickAddKeyword: function() {

        var btnAdd = $("#btnAdd");

        btnAdd.click(function() {
            LeftHandPrompt.acceptKeywords();
        });

        $(".txtKeywords").keydown(function(e) {
            if (isEnterPressed(e)) {
                if ($(".ac_results").length == 0 || $(".ac_results")[0].style.display == "none") {
                    LeftHandPrompt.acceptKeywords();
                }
                return false;
            }
            return true;
            /*                                   
            if ($(".ac_results").length!=0){                               
            if ($(".ac_results")[0].style.display=="none"){
            if($("#btnAdd").length!=0){
            if(isEnterPressed(e))
            LeftHandPrompt.acceptKeywords();
            }                                         
            }                                                                             
            }        
            else{
            if(isEnterPressed(e))
            LeftHandPrompt.acceptKeywords();
            }
            */
        });

    },

    initWrongKeywords: function() {

        var res = TFI.ClientServices.JobSearch.GetWrongKeyWords();
        LeftHandPrompt.wrongKeywords = res.value;
    },

    clearItemsUnchecked: function() {
        var lnkClear = $(".lnkCleanCheckBoxList");
        lnkClear.click(function() {
            var keywordList = $(".keyword");
            var keywordsValue = keywordList.children("label");
            var checkboxKeyword = keywordsValue.children("input");
            for (i = 0; i < checkboxKeyword.length; i++) {
                if (!checkboxKeyword[i].checked) {
                    $(checkboxKeyword[i]).parent().remove();
                }
            }
        })
    },

    FiltersOffersEmployment: function() {

        //defining the dropDown behaviour left-hand Prompt			
        $(".searchParameters .main select").change(function() {
            optDiv = $(".searchParameters .optional");
            optSelect = optDiv.children("select");

            if (this.options[this.selectedIndex].value.length > 0) {
                /*Load job category dropdownlist*/
                $.ajax({
                    type: "GET",
                    url: "/_layouts/AdiaFR/WebServices/Vacancies.asmx/GetJobCategories",
                    // Pass the "domainCategory" parameter, via JSON object.
                    data: "activityDomain=" + this.options[this.selectedIndex].value,
                    success: function(msg) {
                        if ($.browser.msie) {
                            optSelect.html(msg.text);
                        }
                        else {
                            optSelect.html(msg.documentElement.textContent);
                        }
                        //optSelect.removeAttr("contentHTML");
                        //optSelect.attr("contentHTML",optSelect[0].outerHTML); 
                        if (optSelect[0].updateOptions) optSelect[0].updateOptions();
                    }
                });
                optDiv.animate({ opacity: 1 }, 500);
                optDiv.show(500);
                optSelect.show(500);
            } else {
                optDiv.hide(500);
                optSelect[0].selectedIndex = 0;
            }

        });

        //defining the dropDown behaviour left-hand Prompt			
        $(".searchParameters .mainSecond select").change(function() {
            optDiv = $(".searchParameters .optionalSecond");
            optSelect = optDiv.children("select");

            if (this.options[this.selectedIndex].value.length > 0) {
                /*Load department dropdownlist*/
                $.ajax({
                    type: "GET",
                    url: "/_layouts/AdiaFR/WebServices/Vacancies.asmx/GetDepartments",
                    // Pass the "region" parameter
                    data: "region=" + this.options[this.selectedIndex].value,
                    success: function(msg) {
                        if ($.browser.msie) {
                            optSelect.html(msg.text);
                        }
                        else {
                            optSelect.html(msg.documentElement.textContent);
                        }
                        //optSelect.removeAttr("contentHTML");
                        //optSelect.attr("contentHTML",optSelect[0].outerHTML); 
                        if (optSelect[0].updateOptions) optSelect[0].updateOptions();
                    }
                });
                optDiv.animate({ opacity: 1 }, 500);
                optDiv.show(500);
                optSelect.show(500);
            } else {
                optDiv.hide(500);
                optSelect[0].selectedIndex = 0;
            }

        });

        //defining the dropDown behaviour left-hand Prompt			
        $(".searchParameters .mainThird select").change(function() {
            optDiv = $(".searchParameters .optionalThird");
            optInput = optDiv.children("input");

            if (this.options[this.selectedIndex].value == "5") {
                /*Load job category dropdownlist*/
                optDiv.show(500);
                optInput.show(500);
                $(this).hide(0);
                optInput.focus();
            } else {
                optDiv.hide(500);
                /*optInput[0].selectedIndex=0;*/
            }

        });

        $('.searchParameters .edit').click(function() {
            if ($(this).hasClass("open")) {
                $('.contractType label input[checked=""]').parent("label").hide(500);
                $(this).removeClass("open");
            } else {
                if (this.innerHTML == "choisir") {
                    this.innerHTML = "modifier";
                }
                $('.contractType label input[checked=""]').parent("label").show(500);
                $(this).addClass("open");
            }


        });


        $('.searchParameters .editDomain').click(function() {
            //Display content "Poste recherche"		                                                                
            if ($(this).hasClass("open")) {
                mainDiv = $(this.parentNode).children(".main");
                mainSelect = mainDiv.children("select");
                optDiv = $(this.parentNode).children(".optional");
                optSelect = optDiv.children("select");
                mainDiv.hide(500);
                mainSelect.hide(500);
                optDiv.hide(500);
                optSelect.hide(500);
                $(this).removeClass("open");
            } else {
                var isIterationFirst = false;
                var isChoisir = false;
                if (this.innerHTML == "choisir") {
                    this.innerHTML = "modifier";
                    isChoisir = true;
                }


                domainDiv = $(this.parentNode).children(".domain");
                //The user selected activity domain in the previous search (QuickJobSearch or AdvancedJobSearch)
                if (domainDiv.length != 0) {
                    if (domainDiv[0].style.display != "none") {
                        isIterationFirst = true;
                        domainDiv.hide(500);
                    }
                    categoryDiv = $(this.parentNode).children(".category");
                    if (categoryDiv.length != 0) {
                        if (categoryDiv[0].style.display != "none") {
                            isIterationFirst = true;
                            categoryDiv.hide(500);
                        }
                    }
                    else {
                        isIterationFirst = true;
                    }
                }
                else {
                    isIterationFirst = true;
                }

                mainDiv = $(this.parentNode).children(".main");
                mainDiv.animate({ opacity: 1 }, 500);
                mainSelect = mainDiv.children("select");
                if ((mainSelect[0].style.display == "none") && (isIterationFirst)) {
                    mainDiv.show(500);
                    mainSelect.show(500);
                }
                if (!isChoisir) {
                    optDiv = $(this.parentNode).children(".optional");
                    optDiv.animate({ opacity: 1 }, 500);
                    optSelect = optDiv.children("select");
                    /*Load job category dropdownlist*/
                    $.ajax({
                        type: "GET",
                        url: "/_layouts/AdiaFR/WebServices/Vacancies.asmx/GetJobCategories",
                        // Pass the "domainCategory" parameter, via JSON object.
                        data: "activityDomain=" + mainSelect[0].options[mainSelect[0].selectedIndex].value,
                        success: function(msg) {
                            if ($.browser.msie) {
                                optSelect.html(msg.text);
                            }
                            else {
                                optSelect.html(msg.documentElement.textContent);
                            }
                            optSelect.removeAttr("contentHTML");
                            optSelect.attr("contentHTML", optSelect[0].outerHTML);
                        }
                    });
                    optDiv.show(500);
                    optSelect.show(500);
                }
                $(this).addClass("open");
            }
        });

        $('.searchParameters .editLocation').click(function() {
            //Display content "Localisation"			                                                                
            if ($(this).hasClass("open")) {
                mainDiv = $(this.parentNode).children(".mainSecond");
                mainSelect = mainDiv.children("select");
                optDiv = $(this.parentNode).children(".optionalSecond");
                optSelect = optDiv.children("select");
                mainDiv.hide(500);
                mainSelect.hide(500);
                optDiv.hide(500);
                optSelect.hide(500);
                $(this).removeClass("open");
            } else {
                var isIterationFirst = false;
                var first = false;
                if (this.innerHTML == "choisir") {
                    this.innerHTML = "modifier";
                    first = true;
                }

                regionDiv = $(this.parentNode).children(".region");
                //The user selected region in the previous search (QuickJobSearch or AdvancedJobSearch)
                if (regionDiv.length != 0) {
                    if (regionDiv[0].style.display != "none") {
                        isIterationFirst = true;
                        regionDiv.hide(500);
                    }
                    departmentDiv = $(this.parentNode).children(".department");
                    if (departmentDiv.length != 0) {
                        if (departmentDiv[0].style.display != "none") {
                            isIterationFirst = true;
                            departmentDiv.hide(500);
                        }
                    }
                    else {
                        isIterationFirst = true;
                    }
                }
                else {
                    isIterationFirst = true;
                }

                mainDiv = $(this.parentNode).children(".mainSecond");
                mainDiv.animate({ opacity: 1 }, 500);
                mainSelect = mainDiv.children("select");
                if ((mainSelect[0].style.display == "none") && (isIterationFirst)) {
                    mainDiv.show(500);
                    mainSelect.show(500);
                }

                if (!first) {
                    optDiv = $(this.parentNode).children(".optionalSecond");
                    optDiv.animate({ opacity: 1 }, 500);
                    optSelect = optDiv.children("select");
                    /*Load department dropdownlist*/
                    $.ajax({
                        type: "GET",
                        url: "/_layouts/AdiaFR/WebServices/Vacancies.asmx/GetDepartments",
                        // Pass the "region" parameter
                        data: "region=" + mainSelect[0].options[mainSelect[0].selectedIndex].value,
                        success: function(msg) {
                            if ($.browser.msie) {
                                optSelect.html(msg.text);
                            }
                            else {
                                optSelect.html(msg.documentElement.textContent);
                            }
                            //optSelect.removeAttr("contentHTML");
                            //optSelect.attr("contentHTML",optSelect[0].outerHTML); 
                            if (optSelect[0].updateOptions) optSelect[0].updateOptions();
                        }
                    });
                    optDiv.show(500);
                    optSelect.show(500);
                }

                $(this).addClass("open");
            }


        });


        $('.searchParameters .editPublicationDate').click(function() {
            if ($(this).hasClass("open")) {
                optDiv = $(this.parentNode).children(".optionalThird");
                mainDiv = $(this.parentNode).children(".mainThird");
                //mainDiv.animate({opacity:1},500);
                mainSelect = mainDiv.children("select");
                if (mainSelect[0].options[mainSelect[0].selectedIndex].value == "5") {
                    if (mainSelect[0].style.display != "none") {
                        mainDiv.hide(500);
                        mainSelect.hide(500);
                    }
                    else {
                        mainDiv.show(500);
                        mainSelect.show(500);
                        optDiv.show(500);
                    }
                }
                else if (mainSelect[0].style.display == "none") {
                    mainDiv.show(500);
                    mainSelect.show(500);
                }
                else {
                    mainDiv.hide(500);
                    mainSelect.hide(500);
                }
                $(this).removeClass("open");
            } else {
                if (this.innerHTML == "choisir") {
                    this.innerHTML = "modifier";
                }
                optDiv = $(this.parentNode).children(".optionalThird");
                dateDiv = $(this.parentNode).children(".publicationDate");
                dateDiv.hide(500);
                mainDiv = $(this.parentNode).children(".mainThird");
                mainDiv.animate({ opacity: 1 }, 500);
                mainSelect = mainDiv.children("select");
                if (mainSelect[0].options[mainSelect[0].selectedIndex].value == "5") {
                    if (mainSelect[0].style.display != "none") {
                        mainDiv.hide(500);
                        mainSelect.hide(500);
                        optDiv.hide(500);
                    }
                    else {
                        mainDiv.show(500);
                        mainSelect.show(500);
                        optDiv.show(500);
                    }
                }
                else if (mainSelect[0].style.display != "none") {
                    mainDiv.hide(500);
                    mainSelect.hide(500);
                }
                else {
                    mainDiv.show(500);
                    mainSelect.show(500);
                }
                $(this).addClass("open");
            }
        });

        $('.searchParameters select').hide(0);
        $('.contractType label input[checked=""]').parent("label").hide(0);
        $('.publicationDate label input[checked=""]').parent("label").hide(0);
        $('.searchParameters .datePicker').hide(0);

    },

    Autocomplete: function() {
        $(".txtKeywords").autocomplete("/Services/AutoComplete.ashx");
    },

    Search: function() {
        $(".btnRefine").click(function() {
            var contractTypes = $(".contractType label input");
            var filters = "";
            var j = 0;

            xt_searchEngine = 'PromptSearch';

            //Check if exists contract types selected
            for (i = 0; i < contractTypes.length; i++) {
                if (contractTypes[i].checked) {
                    if (j == 0) {
                        filters = "contractTypes=";
                    }
                    else {
                        filters += "+";
                    }
                    filters += contractTypes[i].id;
                    j++;
                }
            }

            //Check if exists any activity domain selected               	                
            if (($(".editDomain")[0].innerHTML == "modifier") && ($(".domain label input").length != 0) && ($(".domain")[0].style.display != "none")) {
                if ($(".domain label input")[0].checked) {
                    if (filters != "") {
                        filters += "&";
                    }
                    filters += "activityDomain=" + $(".domain label input")[0].id.replace("AD", "");
                }
                if ($(".category label input").length != 0) {
                    if ($(".category label input")[0].checked) {
                        if (filters != "") {
                            filters += "&";
                        }
                        filters += "jobCategory=" + $(".category label input")[0].id.replace("JC", "");
                    }
                }
            }
            else if ($(".main")[0].style.length != "0") {
                if (($(".main select").length != 0) && ($(".main select")[0].options[$(".main select")[0].selectedIndex].value != 0)) {
                    if (filters != "") {
                        filters += "&";
                    }
                    filters += "activityDomain=" + $(".main select")[0].options[$(".main select")[0].selectedIndex].value;
                    if (($(".optional select").length != 0) && ($(".optional select")[0].options[$(".optional select")[0].selectedIndex].value != 0)) {
                        if (filters != "") {
                            filters += "&";
                        }
                        filters += "jobCategory=" + $(".optional select")[0].options[$(".optional select")[0].selectedIndex].value; ;
                    }
                }
            }


            //Check if exists any region selected               	                
            if (($(".editLocation")[0].innerHTML == "modifier") && ($(".region label input").length != 0) && ($(".region")[0].style.display != "none")) {
                if ($(".region label input")[0].checked) {
                    if (filters != "") {
                        filters += "&";
                    }
                    filters += "region=" + $(".region label input")[0].id.replace("R", "");
                }
                if ($(".department label input").length != 0) {
                    if ($(".department label input")[0].checked) {
                        if (filters != "") {
                            filters += "&";
                        }
                        filters += "department=" + $(".department label input")[0].id.replace("D", "");
                    }
                }
            }
            else if ($(".mainSecond")[0].style.length != "0") {
                if (($(".mainSecond select").length != 0) && ($(".mainSecond select")[0].options[$(".mainSecond select")[0].selectedIndex].value != 0)) {
                    if (filters != "") {
                        filters += "&";
                    }
                    filters += "region=" + $(".mainSecond select")[0].options[$(".mainSecond select")[0].selectedIndex].value;
                }

                if (($(".optionalSecond select").length != 0) && ($(".optionalSecond select")[0].options[$(".optionalSecond select")[0].selectedIndex].value != 0)) {
                    if (filters != "") {
                        filters += "&";
                    }
                    filters += "department=" + $(".optionalSecond select")[0].options[$(".optionalSecond select")[0].selectedIndex].value; ;
                }
            }

            //Check if exists any publication date selected	                 	                
            if (($(".editPublicationDate")[0].innerHTML == "modifier") && ($(".publicationDate label input").length != 0) && ($(".publicationDate")[0].style.display != "none")) {
                if ($(".publicationDate label input")[0].checked) {
                    if (filters != "") {
                        filters += "&";
                    }
                    filters += "publicationDate=" + $(".publicationDate label input")[0].id.replace("PD", "");
                }
            }
            else if ($(".mainThird")[0].style.length != "0") {
                if (($(".mainThird select").length != 0) && ($(".mainThird select")[0].options[$(".mainThird select")[0].selectedIndex].value != 0)) {
                    if (filters != "") {
                        filters += "&";
                    }
                    if ($(".mainThird select")[0].options[$(".mainThird select")[0].selectedIndex].value == "5") {
                        var aux = $(".datePicker")[0].value.replace("/", "-");
                        aux = aux.replace("/", "-");
                        filters += "publicationDate=" + aux;
                    }
                    else {
                        filters += "publicationDate=" + $(".mainThird select")[0].options[$(".mainThird select")[0].selectedIndex].value;
                    }
                }
            }


            //Check if exists any keyword selected
            j = 0;
            var keywords = $(".keyword label input");
            for (i = 0; i < keywords.length; i++) {
                if (keywords[i].checked) {
                    if (j == 0) {
                        if (filters != "") {
                            filters += "&";
                        }
                        filters += "keywords=";
                    }
                    else {
                        filters += "+";
                    }
                    filters += encodeURIComponent(keywords[i].value);
                    j++;
                }
            }

            if (filters != "") {
                // clear job alert container
                ClearJobAlert();
                // clear the results container and append the LOADING icon//	                    
                $("<img>").attr("src", "/asset/images/loading.gif").prependTo($('<p class="loading">').text("loading...").appendTo($(".recordsContainer").empty()));

                LoadResultsAjax(filters);
                LoadResultsAjax2(filters);
                LoadRssGeneratorLink(filters);
                LoadRssHelpLink(filters);
            }
            else {
                alert("Veuillez sélectionner au moins un critère de recherche");
            }
        });
    },

    acceptKeywords: function() {
        var defaultValue = "Insérez vos mots-clés";
        if (jQuery.trim($(".txtKeywords")[0].value) != defaultValue) {
            if (jQuery.trim($(".txtKeywords")[0].value) != "") {

                var keywordList = $(".keyword");
                var duplicateValue = false;
                var wrongValue = false;
                var correctedWords = ReplaceSpecialCharacters($(".txtKeywords")[0].value);
                var txtKeywords = correctedWords.split(" ");
                var NotAllowedWords = LeftHandPrompt.wrongKeywords.split(";");
                for (i = 0; i < txtKeywords.length; i++) {
                    keywordsValue = keywordList.children("label");
                    for (j = 0; j < keywordsValue.length; j++) {
                        if ($.browser.msie) {
                            if (keywordsValue[j].innerText == txtKeywords[i]) {
                                duplicateValue = true;
                            }
                        }
                        else {
                            if (keywordsValue[j].textContent == txtKeywords[i]) {
                                duplicateValue = true;
                            }
                        }
                    }
                    if (!duplicateValue) {
                        for (k = 0; k < NotAllowedWords.length; k++) {
                            if (txtKeywords[i] == NotAllowedWords[k]) {
                                wrongValue = true;
                            }
                        }
                        if (!wrongValue) {
                            var count = txtKeywords[i].length;
                            var composedKeyword;
                            if (count > 31) {
                                composedKeyword = txtKeywords[i].substring(0, 1) + txtKeywords[i].substring(1, 27).toLowerCase() + "...";
                            }
                            else {
                                composedKeyword = txtKeywords[i];
                            }
                            keywordList.append("<label class=\"chkBoxLabel " + txtKeywords[i] + "KW \" for=\"" + txtKeywords[i] + "KW \">" + "<input type=\"checkbox\" id=\"" + txtKeywords[i] + "KW \" name=\"" + txtKeywords[i] + "\" value=\"" + txtKeywords[i] + "\" checked=\"checked\" /><span>" + composedKeyword + "</span></label>");
                        }
                        else {
                            wrongValue = false;
                        }
                    }
                }
            }
        }
        if ((jQuery.trim($(".txtKeywords")[0].value) != "Insérez vos mots-clés") && ($(".txtKeywords")[0].value != "")) {
            $(".txtKeywords")[0].value = "";
        }
        $(".txtKeywords")[0].focus();
    }


}//End of LefthandPrompt


function LoadResultsAjax(filters)
{
    //var url = window.location.protocol + '//' + window.location.host + window.location.pathname;
    filters = filters + '&UrlRef=' + escape(window.location.pathname);
    $(".searchResultsPanel").load("http://" + window.location.host + "/Services/Vacancies.ashx?" + filters + " .searchResultsPanel", function(){
        LoadXitiParam
        LoadLinkPagination();
        refreshDisabledLinks(); 
        window.scrollTo(140,140);
    });
}

function LoadXitiParam()
{    
    // get the list of keywords
    var keywords = new Array();
    var keywordList = $(".keyword");
    var keywordsValue = keywordList.children("label");
    for (j = 0; j < keywordsValue.length; j++) {
        if ($.browser.msie) {
            keywords[j] = FormatXitiString(keywordsValue[j].innerText);
        }
        else {
            keywords[j] = FormatXitiString(keywordsValue[j].textContent);
        }
    }
    xt_mtcl = xt_searchEngine + '-' + keywords.join('_');
    
	// get page #
	if($(".pagination li a").length==0) { // no results
		xt_npg = "0";
	} else { // at least one result, get the selected page link text
		xt_npg = $(".pagination li.selected a").eq(0).text();
	}

	// set window.xtparam
    if (window.xtparam!=null){  
        var values = window.xtparam.split('&');
        var newXtparam = '';
        // pass through all the parameter to recreate xtparam without mc and np parameters
        for (var i=0; i<values.length; i++) {
            // skip the parameter if it is 'mc' or 'np'
            // otherwise, recreate the string of parameters
            if (values[i].indexOf('mc=')!=0 && values[i].indexOf('np=')!=0 && values[i]!='') {
                newXtparam += "&" + values[i];
            }
        } 
        window.xtparam = newXtparam;
    
        window.xtparam+="&mc="+xt_mtcl+"&np="+xt_npg;
    } 
    else{window.xtparam ="&mc="+xt_mtcl+"&np="+xt_npg;};
    
    // Load Xiti xtcore
    $("body").append("<script type='text/javascript' src='/asset/js/xtcore2.js' ></script>");
}

function LoadResultsAjax2(filters)
{
    $(".relatedJobPanel").load("http://" + window.location.host + "/Services/RelatedJobsService.ashx?" + filters + " .relatedJobPanel", function(){
        LoadLinkRelatedJobs();
    });
}

function LoadRssGeneratorLink(filters)
{
    $(".lnkRssFeed")[0].href = $(".lnkRssFeed")[0].href.split("?")[0] + "?" + filters;
}

function LoadRssHelpLink(filters)
{
    $(".lnkRSSHelp")[0].href = $(".lnkRSSHelp")[0].href.split("?")[0] + "?" + filters;         	     
}

function GetQueryStringParams (url)
{
    return url.split("?")[1];
}

function LoadLinkPagination()
{
    $(".pagination li a").click(ClickLinkPagination);
    $(".sortBy li a").click(ClickLinkPagination);
    if (LastsOffers)
        LastsOffers.addEventHandlers();
}

function LoadLinkRelatedJobs()
{
    $(".lnkRelatedJob").click(ClickLinkRelatedJobs);
}

function ClickLinkRelatedJobs()
{   
    var keywordList=$(".keyword");                                                                                                         
    var keywordsValue=keywordList.children("label");                                    
    var checkboxKeyword=keywordsValue.children("input");
    
    for (i=0;i<checkboxKeyword.length;i++)
    {                                          
        $(checkboxKeyword[i]).parent().remove();                                             
    } 
    
    /*var aux1 = GetQueryStringParams(this.href).split("keywords=");
    aux1 = aux1[1].split("&")[0]; */
    $(".txtKeywords")[0].value = this.innerHTML.split(" (")[0]; /*encodeURIComponent(aux1)*/                                               
    LeftHandPrompt.acceptKeywords();
    $(".txtKeywords").keydown();
	$(".btnRefine").click();

    return false;
}

function ClickLinkPagination()
{
    if (!this.disabled) 
    {
        LoadResultsAjax(GetQueryStringParams(this.href));
    }
    return false;
}

function refreshDisabledLinks()
{
    var disabledLinks = $("a[disabled=disabled]");
    disabledLinks.addClass("disabled");
    disabledLinks.unbind();
    disabledLinks.click(function() { return false; });
}

function EnterPressAdd(oEvent, fn)
{    
    var iAscii;
    if (window.event){
    iAscii = event.keyCode; 
    }
    else
    iAscii = oEvent.which; 

    if (iAscii == 13)
    {      
        fn(); 
        return false;        
    }
    return true;
} 

function isEnterPressed(oEvent)
{    
    var iAscii;
    if (window.event){
    iAscii = event.keyCode; 
    }
    else
    iAscii = oEvent.which; 

    return (iAscii == 13);
}
 
function ClearJobAlert()
{       
    $(".pnlFailEmailActivation")[0].style["display"] = "none";
    $(".pnlOverrideEmailSubs")[0].style["display"] = "none";
    $(".pnlSuccessEmailActivation")[0].style["display"] = "none";
    $(".SetAlertSubscribe")[0].style["display"] = "none";  
    $(".AlertSubscribe_txtEmail")[0].value = "";
    $(".AlertSubscribe_ddlFrequency")[0].value = 0;          
}


function ReplaceSpecialCharacters(sWords)
{

     var re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
     sWords=sWords.replace(re, "");

     var rExps=[ /[\xC0-\xC2]/g, /[\xE0-\xE2]/g,
    /[\xC8-\xCA]/g, /[\xE8-\xEB]/g,
    /[\xCC-\xCF]/g, /[\xEC-\xEF]/g,
    /[\xD2-\xD4]/g, /[\xF2-\xF4]/g,
    /[\xD9-\xDC]/g, /[\xF9-\xFC]/g, 
    /[\xE7]/g, /[\xC7]/g ];
    var repChar=['A','a','E','e','I','i','O','o','U','u','c','C'];

    for(var i=0; i<rExps.length; i++)
    sWords=sWords.replace(rExps[i],repChar[i]);
    sWords=sWords.replace("  "," ");

    return sWords;
}

function FormatXitiString(sValue)
{
    sValue = ReplaceSpecialCharacters(sValue);
    sValue = sValue.split(' ').join('_');

    return sValue;
}

function UnCheckChildBox(parentSelector, childSelector) {
    $(parentSelector).click(function() {
        if (this.checked == false) {
            $(childSelector).attr("checked", false);
        }
    });
}

function CheckParentBox(parentSelector, childSelector) {
    $(childSelector).click(function() {
        if (this.checked == true) {
            $(parentSelector).attr("checked", true);
        }
    });
}
