function onElementFocused(e)
{
    if (e && e.target)
        document.activeElement = 
        e.target == document ? null : e.target;
} 
if(!$.browser.msie) {
    if (document.addEventListener) 
        document.addEventListener("focus", onElementFocused, true); 
    }


RegistrationTargetJob = {

    init: function() {
        RegistrationTargetJob.setEventHandlers();
        RegistrationLookUpDepartments.init();      
        SearchProfessionByActivitySector.init();
        LookUpCountries.init();
        RegistrationTargetJob.updateMobilityType();
        RegistrationTargetJob.hideWaitingImage();
        //TODO: prepare Task and Tools for edit mode
        $(".pnlTaskAndToolsTJ").css("display", "none"); //Hide panel
		if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit) { //PersonalProfile
			DisplayProfession.init();
			AddTaskAndTools.init();
			$(".btnNextTJ").val("Enregistrer");
        }
        $(".txtKeywords").autocomplete("/Services/AutoCompleteProfessionCV.ashx",{minChars: 3, max: 50});
        RegistrationTargetJob.initHover();
        RegistrationTargetJob.updateMobilityType();
    },  
    
    initHover: function(){
        if($.browser.msie) {
		$("input.submit[type=submit]")
			.focus(function(){ $(this).addClass("submit-hover") } )
			.blur(function(){ $(this).removeClass("submit-hover") })
			.hover(function(){ $(this).addClass("submit-hover") }, function() { $(this).removeClass("submit-hover") } );
		$("input.linkButton")
			.focus(function() { $(this).addClass("linkButton-hover") } )
			.blur(function() { $(this).removeClass("linkButton-hover") } )
			.hover(function() { $(this).addClass("linkButton-hover") }, function() { $(this).removeClass("linkButton-hover") } );
        $("input.submit[type=button]")
			.focus(function(){ $(this).addClass("submit-hover") } )
			.blur(function(){ $(this).removeClass("submit-hover") })
			.hover(function(){ $(this).addClass("submit-hover") }, function() { $(this).removeClass("submit-hover") } );
	    }
    },     
    
    setEventHandlers: function() {
        $(".btnPreviousTJ").unbind().click(RegistrationTargetJob.onClickPrevious);
        $(".btnNextTJ").unbind().click(RegistrationTargetJob.onClickNext);
        $(".btnCancelTJ").unbind().click(RegistrationTargetJob.onClickCancel);    
        $(".btnLookUpDepartmentsTJ").unbind().click(RegistrationTargetJob.showDialogDepartments);
        $(".btnLookUpCountriesTJ").unbind().click(RegistrationTargetJob.showDialogCountries);    
        $(".btnSearchBySectorTJ").unbind().click(RegistrationTargetJob.showDialogSearchActivitySector);
        $(".rbNoInternationalTJ").unbind().click(RegistrationTargetJob.updateMobilityType);
        $(".rbCountryTJ").unbind().click(RegistrationTargetJob.updateMobilityType);
        $(".rbDepartmentsTJ").unbind().click(RegistrationTargetJob.updateMobilityType);         
        $(".rbAllFranceTJ").unbind().click(RegistrationTargetJob.updateMobilityType);        
        $(".btnCountryDeleteTJ").unbind().click(TFI.ClientUtils.onDeleteRow);
        $(".btnDepartmentDeleteTJ").unbind().click(TFI.ClientUtils.onDeleteRow);
        $(".btnAddDepartmentsTJ").unbind().click(RegistrationTargetJob.onAddDepartments);
        $(".txtEmployTJ").unbind().blur(RegistrationTargetJob.onBlurValidate);
        $(document).click(RegistrationTargetJob.onClickDocument); 
        RegistrationLookUpDepartments.addEventHandlerDepartmentsSelected(RegistrationTargetJob.onDepartmentsSelected);
        SearchProfessionByActivitySector.addEventHandlerProfessionSelected(RegistrationTargetJob.onProfessionSelected);        
    },    
    
    validate: function() {
        var result = TFI.Validation.validateGroup("TargetJob");
        if (result) {
            $(".validationWarning").hide(); 
        } else {
            $(".validationWarning").show(); 
        }        
        return result;
    },
    
    validateEmployDataBase: function() {
        var result = TFI.Validation.validateGroup("EmployDataBase");
        if (result) {
            $(".validationWarning").hide(); 
        } else {
            $(".validationWarning").show(); 
        }        
        return result;
    },   
    
    validateAddDepartments: function() {
        var result = TFI.Validation.validateGroup("TargetJobDepartments");
        if (result) {
            $(".validationWarning").hide(); 
        } else {
            $(".validationWarning").show(); 
        }        
        return result;
    },      
    
    saveValues: function(candidateCV) {
		
        if(candidateCV != null) {
            //if(RegistrationTargetJob.validate()) {
				if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit) { //PersonalProfile
					//Save DisplayProfession values				
					candidateCV = DisplayProfession.saveValues(candidateCV);
				} else { //Registration
					//Save JobTitle
					var profId = $(".txtEmployTJ").attr("profId");
					if(!isNaN(profId)) {
						candidateCV.Job.JobTitles = [{ JobTitleId: parseInt(profId, 10) }];
					}
				}

				if(candidateCV != null) {
					//Save Mobilities
					candidateCV.Mobility.Mobilities = RegistrationTargetJob.getMobilities();	                
					//Save ContractTypes
					candidateCV.candidateState.candidateAssignment.TypeContracts = RegistrationTargetJob.getContractTypes();
				}                
            //} else {
            //    candidateCV = null;
            //}
        }        
        return candidateCV;
    },
       
    getProfId: function()
    {
        return $(".txtEmployTJ").attr("profId");
    },
       
    getContractTypes: function() {
        var contracts = [];
        
        $(".chkListContractsDCT :input:checked").each(function(index, element) {
            contracts.push( { ContractId: element.value } ); //, CandidateId: 0
        });
        return contracts;    
    },    
    
    getDepartmentCodes: function() {
		var departments = [];
		var controls = $(".txtDepartmentsTJ");
		var i, value;
		
		for(i=0; i<controls.length; i++) {
			value = controls.eq(i).val();
			if(value != null && value.length > 0) {
				departments.push(value);					
			}			
		}
		return departments;
    },
    
    getMobilities: function() {
    
        var mobilities = [];
        var mobilitiesTable = [];
        
        /************BEGIN CR 199033 *************/
        
        /*if($(".rbRegionTJ :input").is(":checked")) {
            var select = $(".ddlRegionsTJ")[0];
            var option = select.options[select.selectedIndex];                
            mobilities.push({
                GeoAreaId: option.value,
                GeoAreaName: option.text,
                TypeGeoAreaId: TFI.Const.EnumTypeGeoAreaId.Region,
                TypeGeoAreaName: "Region"
            });
        
        } else*/ 
        
        /************END CR 199033 *************/
        
        if($(".rbDepartmentsTJ :input").is(":checked")) {
            if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit) {
			    mobilitiesTable = TFI.ClientUtils.getDepartmentsTableValues(".rptDepartmentsTJ[editMode=1] .pnlRow", "GeoAreaId", "TypeGeoAreaId");
			} else {
                mobilitiesTable = TFI.ClientUtils.getDepartmentsTableValues(".rptDepartmentsTJ .pnlRow", "GeoAreaId", "TypeGeoAreaId");			
			}
            for(i=0; i<mobilitiesTable.length; i++) {
                mobilities.push({
					GeoAreaId: mobilitiesTable[i].GeoAreaId,
					TypeGeoAreaId: mobilitiesTable[i].TypeGeoAreaId
				});
            } 
        } 
        /************BEGIN CR 199033 *************/
        else if(($(".rbAllFranceTJ :input").is(":checked") && TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Create)
                || ($(".rbAllFranceTJ :input").is(":checked") && $(".rbNoInternationalTJ :input").is(":checked"))) {
            mobilities.push({
                GeoAreaId: TFI.Const.FRANCE_GEO_AREA_ID,
                GeoAreaName: "FRANCE",
                TypeGeoAreaId: TFI.Const.EnumTypeGeoAreaId.Country,
                TypeGeoAreaName: "PAYS"
            });          
        }
        /************END CR 199033 *************/

        if($(".rbCountryTJ :input").is(":checked")) {
            mobilitiesTable = TFI.ClientUtils.getTableValues(".rptCountriesTJ[editMode=1] .pnlRow", "GeoAreaId");
            for(i=0; i<mobilitiesTable.length; i++) {
                mobilities.push({
					GeoAreaId: mobilitiesTable[i].GeoAreaId,
					TypeGeoAreaId: TFI.Const.EnumTypeGeoAreaId.Country
				});
            }
        }
        
        return mobilities;
    },
    
    getMobilityTypeDepartments: function() {
        var type = TFI.Const.EnumMobilityType.None;
        
//      if($(".rbRegionTJ :input").is(":checked")) {
//          type = TFI.Const.EnumMobilityType.Region;
//      } else 
        if($(".rbDepartmentsTJ :input").is(":checked")) {
            type = TFI.Const.EnumMobilityType.Departments;
        } else if($(".rbAllFranceTJ :input").is(":checked")) {
            type = TFI.Const.EnumMobilityType.AllFrance;
        } 
        return type;
    },
    
    getMobilityTypeCountries: function() {
        var type = TFI.Const.EnumMobilityType.None;

        if($(".rbNoInternationalTJ :input").is(":checked")) {
            type = TFI.Const.EnumMobilityType.NoInternacional;
        }else if($(".rbCountryTJ :input").is(":checked")) {
            type = TFI.Const.EnumMobilityType.Countries;
        }
        return type;
    },
    
    updateMobilityType: function() {
        var typeDepartment = RegistrationTargetJob.getMobilityTypeDepartments();
        var typeCountry = RegistrationTargetJob.getMobilityTypeCountries();
        var mobilities = [];
        //$(".ddlRegionsTJ").attr('disabled', (type != TFI.Const.EnumMobilityType.Region) );
        var item = {
    	        value: TFI.Const.FRANCE_GEO_AREA_ID,
                text: "FRANCE"
        };
        
        //DEPARTMENTS SECTION
        $(".btnLookUpDepartmentsTJ").attr('disabled', (typeDepartment != TFI.Const.EnumMobilityType.Departments) );
        $(".btnAddDepartmentsTJ").attr('disabled', (typeDepartment != TFI.Const.EnumMobilityType.Departments) );
        if (typeDepartment != TFI.Const.EnumMobilityType.Departments){
            $(".btnLookUpDepartmentsTJ").addClass("linkButtonWithoutHover");
            $(".btnLookUpDepartmentsTJ").removeClass("linkButton");
            $(".btnAddDepartmentsTJ").addClass("linkButtonWithoutHover");
            $(".btnAddDepartmentsTJ").removeClass("linkButton");
            $(".rptDepartmentsTJ .removeButton").hide();
            
            //Add France to the countries table
            for (i=0;i<$(".rptCountriesTJ .pnlRow").length;i++){
            
                if ($.browser.msie){ 
                    mobilities.push({
			            value: $(".rptCountriesTJ .pnlRow")[i].attributes["rowId"].nodeValue,
			            text: $(".rptCountriesTJ .pnlRow")[i].innerText,
			            type: TFI.Const.GeographicalAreaType.Country
			        });                       
                }
                else{
                    mobilities.push({
			            value: $(".rptCountriesTJ .pnlRow")[i].attributes["rowId"].nodeValue,
			            text: $(".rptCountriesTJ .pnlRow")[i].textContent,
			            type: TFI.Const.GeographicalAreaType.Country
			        });             
                }         
			}
            
            if (mobilities.indexOf(item) == -1){ 
                //Not exist France into the countries table
                //Add France to the countries table
    	        mobilities.push({
    	            value: TFI.Const.FRANCE_GEO_AREA_ID,
                    text: "FRANCE",
                    type: TFI.Const.GeographicalAreaType.Country
                });    
                mobilities.sort(compareGeoAreaName);
                $(".rptCountriesTJ .pnlTable").empty();

                TFI.ClientUtils.addTableValues(".rptCountriesTJ", mobilities); 
            }       
        }
        else{
            $(".btnLookUpDepartmentsTJ").removeClass("linkButtonWithoutHover");
            $(".btnLookUpDepartmentsTJ").addClass("linkButton");
            $(".btnAddDepartmentsTJ").removeClass("linkButtonWithoutHover");
            $(".btnAddDepartmentsTJ").addClass("linkButton");
            $(".rptDepartmentsTJ .removeButton").show();
            
            //Remove France to the countries table
            
            for (i=0;i<$(".rptCountriesTJ .pnlRow").length;i++){
                if ($.browser.msie){ 
			        mobilities.push({
			            value: $(".rptCountriesTJ .pnlRow")[i].attributes["rowId"].nodeValue,
			            text: $(".rptCountriesTJ .pnlRow")[i].innerText,
			            type: TFI.Const.GeographicalAreaType.Country
			        });
			    }
			    else{
			        mobilities.push({
			            value: $(".rptCountriesTJ .pnlRow")[i].attributes["rowId"].nodeValue,
			            text: $(".rptCountriesTJ .pnlRow")[i].textContent,
			            type: TFI.Const.GeographicalAreaType.Country
			        });
			    }
			}
           
            var index = mobilities.indexOf(item);
            if (index != -1) //France is inside the table, we must remove it
                mobilities.splice(index,1);
            $(".rptCountriesTJ .pnlTable").empty();
            mobilities.sort(compareGeoAreaName);
            TFI.ClientUtils.addTableValues(".rptCountriesTJ", mobilities);
        }
        $(".txtDepartmentsTJ").attr('disabled', (typeDepartment != TFI.Const.EnumMobilityType.Departments) );
        
        //COUNTRY SECTION
        $(".btnLookUpCountriesTJ").attr('disabled', (typeCountry != TFI.Const.EnumMobilityType.Countries) );
        if (typeCountry != TFI.Const.EnumMobilityType.Countries){
            $(".btnLookUpCountriesTJ").addClass("linkButtonWithoutHover");
            $(".btnLookUpCountriesTJ").removeClass("linkButton");
            $(".rptCountriesTJ .removeButton").hide();
        }
        else{
            $(".btnLookUpCountriesTJ").removeClass("linkButtonWithoutHover");
            $(".btnLookUpCountriesTJ").addClass("linkButton");
            $(".rptCountriesTJ .removeButton").show();
        }
    },
    
    getDepartments: function() {
        var departments = [];
        $(".txtDepartmentsTJ").each(function(index, element) {
			if(element.value != null && element.value.length > 0) {        
				departments.push( { "value" : element.value } );
			}
        });
        return departments;
    },
    
    setDepartments: function(departments) {
        var i=0;
        $(".txtDepartmentsTJ").each(function(index, element) {
            if(i<departments.length) {
                element.value = departments[i].value;
                i++;
            } else {
                element.value = "";
            }
        });        
    },
    
    showDialogDepartments: function() {
     /************ BEGIN CR 199033 ************/
        var selectedDepartments = [];
        if ($(".rptDepartmentsTJ .pnlRow .textDelete").length != 0){
            $(".rptDepartmentsTJ .pnlRow .textDelete").each(function(index, element) {
                var value;
                if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit){
                    value = element.innerHTML.replace(/\n/g, " ").trim().split(" ")[0];
                }
                else{
                   value = element.innerHTML.split(" ")[0];
                }
                selectedDepartments.push(value);
            });
        }
        RegistrationLookUpDepartments.show(selectedDepartments, RegistrationTargetJob.onSelectDepartments);
        /************ END CR 199033 ************/
        return false;
    },

    showDialogCountries: function(e) {
		/************ BEGIN CR 199033 ************/
        var selectedCountries = [];
        
        selectedCountries = TFI.ClientUtils.getTableValues(".rptCountriesTJ .pnlRow", "GeoAreaId");
        
        /*if ($(".rptCountriesTJ .pnlRow .textDelete").length != 0){
            $(".rptCountriesTJ .pnlRow .textDelete").each(function(index, element) {
                var value;
                if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit){
                    value = element.innerHTML.replace(/\n/g, " ").trim().split(" ")[0];
                }
                else{
                   value = element.innerHTML.split(" ")[0];
                }
                selectedCountries.push(value);
            });
        }*/
        
        LookUpCountries.show(selectedCountries, RegistrationTargetJob.onSelectCountries);
        /************ END CR 199033 ************/
		return false;
    },
            
    showDialogSearchActivitySector: function() {
        SearchProfessionByActivitySector.show();
        return false;
    },
    
    onSelectDepartments: function(result) {
    /************ BEGIN CR 199033 ************/
    
//        var maxNumber;
//        
//        if (result.mobilities.length < TFI.Const.MaxDepartmentsSelected) {
//            maxNumber = result.mobilities.length;
//        } else {
//            maxNumber = TFI.Const.MaxDepartmentsSelected;
//        }
//        result.mobilities
//        for(i=0; i<maxNumber; i++) {
//            ($(".txtDepartmentsTJ")[i]).value = result.mobilities[i].value;
//        }
//        return false;

       // var departments = RegistrationTargetJob.getDepartmentCodes();
       
        var departments = [];
       
        for(i=0; i<result.mobilities.length; i++) {
            departments.push(result.mobilities[i].value);
        }
        var mobilities = TFI.ClientServices.Candidate.GetDepartments(departments).value;
        var listDepartments = [];
        for (i=0; i<mobilities.length; i++) {
            listDepartments.push({
			    value: mobilities[i].GeoAreaId,
			    text: mobilities[i].Code + " " + mobilities[i].GeoAreaName,
			    type: TFI.Const.GeographicalAreaType.Department,
			    name: mobilities[i].GeoAreaName
		    })
        }
        
        //Add towns and regions
        for (i=0;i<$(".rptDepartmentsTJ .pnlRow").length;i++){
            if ($(".rptDepartmentsTJ .pnlRow")[i].attributes["type"].nodeValue != TFI.Const.GeographicalAreaType.Department){
			    if ($.browser.msie){ 
			        listDepartments.push({
			            value: $(".rptDepartmentsTJ .pnlRow")[i].attributes["rowId"].nodeValue,
			            text: $(".rptDepartmentsTJ .pnlRow")[i].innerText.replace(/\n/g, "").trim(),
			            type: $(".rptDepartmentsTJ .pnlRow")[i].attributes["type"].nodeValue,
			            name: $(".rptDepartmentsTJ .pnlRow")[i].attributes["name"].nodeValue
			        });
			    }
			    else{
			        listDepartments.push({
			            value: $(".rptDepartmentsTJ .pnlRow")[i].attributes["rowId"].nodeValue,
			            text: $(".rptDepartmentsTJ .pnlRow")[i].textContent.replace(/\n/g, "").trim(),
			            type: $(".rptDepartmentsTJ .pnlRow")[i].attributes["type"].nodeValue,
			            name: $(".rptDepartmentsTJ .pnlRow")[i].attributes["name"].nodeValue
			        });
			    }
			}
		}
        
        $(".rptDepartmentsTJ .pnlTable").empty();
        
        listDepartments.sort(compareGeoAreaNameDep);
        
        TFI.ClientUtils.addTableValues(".rptDepartmentsTJ", listDepartments);

        $(".txtDepartmentsTJ").each(function(index, element) {
            element.value = "";
        }); 
        
        return false;
        
        /************ END CR 199033 ************/

    },
    
    onSelectCountries: function(result) {
        $(".rptCountriesTJ .pnlTable").empty();
        
        if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit && $(".rbAllFranceTJ :input").is(":checked")) {
            //Add France to the countries table
            var item = {
                    value: TFI.Const.FRANCE_GEO_AREA_ID,
                    text: "FRANCE",
                    type: TFI.Const.GeographicalAreaType.Country
            }   
    	    result.mobilities.push(item);   
    	}
    	
    	result.mobilities.sort(compareGeoAreaName);
        
    	TFI.ClientUtils.addTableValues(".rptCountriesTJ", result.mobilities);
    },
    
    onAddDepartments: function(result) {
        if(RegistrationTargetJob.validateAddDepartments())
        {
            var departments = RegistrationTargetJob.getDepartmentCodes();
            /************ BEGIN CR 199033 ************/
            if ($(".rptDepartmentsTJ .pnlRow .textDelete").length != 0){
                $(".rptDepartmentsTJ .pnlRow .textDelete").each(function(index, element) {
                    var value;
                    if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit){
                        value = element.innerHTML.replace(/\n/g, " ").trim().split(" ")[0];
                    }
                    else{
                       value = element.innerHTML.split(" ")[0];
                   }
                   departments.push(value);
                });
            }
            /************ END CR 199033 ************/
            var mobilities = TFI.ClientServices.Candidate.GetDepartments(departments).value;
            var listDepartments = [];
            for (i=0; i<mobilities.length; i++) {
                listDepartments.push({
				    value: mobilities[i].GeoAreaId,
				    text: mobilities[i].Code + " " + mobilities[i].GeoAreaName,
				    type: TFI.Const.GeographicalAreaType.Department,
				    name: mobilities[i].GeoAreaName
			    })
            }
            /************ BEGIN CR 199033 ************/
            
            //Add towns and regions
            for (i=0;i<$(".rptDepartmentsTJ .pnlRow").length;i++){
                if ($(".rptDepartmentsTJ .pnlRow")[i].attributes["type"].nodeValue != TFI.Const.GeographicalAreaType.Department){
			        if ($.browser.msie){ 
			            listDepartments.push({
			                value: $(".rptDepartmentsTJ .pnlRow")[i].attributes["rowId"].nodeValue,
			                text: $(".rptDepartmentsTJ .pnlRow")[i].innerText.replace(/\n/g, "").trim(),
			                type: $(".rptDepartmentsTJ .pnlRow")[i].attributes["type"].nodeValue,
			                name: $(".rptDepartmentsTJ .pnlRow")[i].attributes["name"].nodeValue
			            });
			        }
			        else{
			            listDepartments.push({
			                value: $(".rptDepartmentsTJ .pnlRow")[i].attributes["rowId"].nodeValue,
			                text: $(".rptDepartmentsTJ .pnlRow")[i].textContent.replace(/\n/g, "").trim(),
			                type: $(".rptDepartmentsTJ .pnlRow")[i].attributes["type"].nodeValue,
			                name: $(".rptDepartmentsTJ .pnlRow")[i].attributes["name"].nodeValue
			            });
			        }
			    }
		    }
		
            $(".rptDepartmentsTJ .pnlTable").empty();
            /************ END CR 199033 ************/
            
            listDepartments.sort(compareGeoAreaNameDep);
            
            TFI.ClientUtils.addTableValues(".rptDepartmentsTJ", listDepartments);

            $(".txtDepartmentsTJ").each(function(index, element) {
                element.value = "";
            }); 
        }
        return false;
    },
    
    onProfessionSelected: function(e, profession) {
		if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit) { //PersonalProfile
			DisplayProfession.onAddProfession(profession);
		} else { //Registration
			$(".txtEmployTJ").val(profession.text).attr("profId", profession.value);
		}
        return false;
    },
    
    onDepartmentsSelected: function(e, departments) {
        RegistrationTargetJob.setDepartments(departments);    
        return false;
    },
    
    onClickPrevious: function() {
        if(RegistrationTargetJob.validateEmployDataBase())
        {
            Registration.showPanel(TFI.Const.EnumRegistrationViewPanels.CivilStatus); 
        }
        RegistrationCivilStatus.hideWaitingImage();   
        return false;
    },

    onClickNext: function() {
        RegistrationTargetJob.showWaitingImage();	
        RegistrationTargetJob.hideAreaSelected();
        
        var isAreaSelected = TFI.Validation.IsAreaSelectedValidating();
        
        if(RegistrationTargetJob.validate() && isAreaSelected) {   
			if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit) { //PersonalProfile
				TFI.Candidate.updateCandidateJobs(function(result) {
					if(result) {
						PersonalProfile.refreshPanelDisplay();
					} else {
						//TODO: what if Save Jobs fails (show message in french)
						alert(TFI.Labels.getLabel("msgErrorUpdatingProfile"));
						RegistrationTargetJob.hideWaitingImage();
					}
				});
			} else { //Registration
				Registration.showPanel(TFI.Const.EnumRegistrationViewPanels.DefinePassword);    
			}
        }
        else if(!TFI.Validation.IsAreaSelectedValidating()) {
            RegistrationTargetJob.showAreaSelected();
            RegistrationTargetJob.hideWaitingImage();
        }
        else {
            RegistrationTargetJob.hideWaitingImage();
        }
        
        return false;
    },
    
    onClickCancel: function() {
		if(TFI.Candidate.pageMode == TFI.Const.EnumPageMode.Edit) { //PersonalProfile
			PersonalProfile.showPanel(TFI.Const.EnumPersonalProfileViewPanels.DisplayProfile);
		} else { // Reload Registration
		    window.location = window.location;
		}
        return false;
    },
	
	onClickDocument: function() {
		if($(".txtEmployTJ").val()!="")
			RegistrationTargetJob.validateEmployDataBase();
	},
	
	onBlurValidate: function(e)
	{
		if(!$.browser.msie)
			document.focus();	
		if(document.activeElement.id.replace(/^\s*/, "").replace(/\s*$/, "")!="")	
		    RegistrationTargetJob.validateEmployDataBase();
	},
    
    showWaitingImage: function()
    {
        $(".btnNextTJ").hide();
        $(".btnCancelTJ").hide();
        $(".AjaxLoaderEnregistrerTJ").show(); 	
    }, 
    
    hideWaitingImage: function()
    {
        $(".btnNextTJ").show();
        $(".btnCancelTJ").show();
        $(".AjaxLoaderEnregistrerTJ").hide(); 	
    },
    
    showAreaSelected: function()
    {
        $(".tdAreaSelectedTJ1").attr("class", "tdAreaSelectedTJ1 warningArea1");
        $(".tdAreaSelectedTJ2").attr("class", "tdAreaSelectedTJ2 warningArea2");            
        $(".litNameErrorSelectTJ").show();
    },
    
    hideAreaSelected: function()
    {
        $(".tdAreaSelectedTJ1").attr("class", "tdAreaSelectedTJ1");
        $(".tdAreaSelectedTJ2").attr("class", "tdAreaSelectedTJ2");  
        $(".litNameErrorSelectTJ").hide();;   
    }
};

function compareGeoAreaName(a, b){
  if (a.text < b.text)
     return -1;
  if (a.text > b.text)
     return 1;
  return 0;
};

function compareGeoAreaNameDep(a, b){
  if (a.name < b.name)
     return -1;
  if (a.name > b.name)
     return 1;
  return 0;
};

Array.prototype.indexOf = function(s) {
	for (var x=0;x<this.length;x++) 
	    if(this[x].value == s.value) {
	        return x;
	    }
	return -1;
};

