﻿/* initialize the Ajax handler */
$().ready(function(){	
						LeftHandPrompt.clickAddKeyword();
						LeftHandPrompt.FiltersOffersEmployment();
						LeftHandPrompt.clearItemsUnchecked();
						//LeftHandPrompt.Autocomplete();
						$(".btnRefine").click(clickBtnRefine);//LeftHandPrompt.Search();
						LoadLinkPagination();
						refreshDisabledLinks();
					})


/*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
*/

var _keywords="";
 
LeftHandPrompt={        
        
/*Add event click to the "Ajouter" button, your funtionality is add keywords
* to the keywords list */
   
    clickAddKeyword:function(){  
   
        var btnAdd=$("#btnAdd");                                                 
              
        btnAdd.unbind().click(function(){
                       var defaultValue="Insert your keywords here";
                       if(jQuery.trim($(".txtKeywords")[0].value)!=defaultValue){
                           if (jQuery.trim($(".txtKeywords")[0].value)!=""){
                               var keywordList=$(".keyword");
                               var duplicateValue=false;                                   
                               var txtKeywords=$(".txtKeywords")[0].value.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){
                                       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>");                                                                   
                                   }
                               }
                           }                                  
                       } 
                       if((jQuery.trim($(".txtKeywords")[0].value)!="Insert your keywords here") && ($(".txtKeywords")[0].value!="")){
                           $(".txtKeywords")[0].value="";                                                                      
                       }
                       $(".txtKeywords")[0].focus();
         });
                     
        $(".txtKeywords").keydown(function(e){      
                     if ($(".ac_results").length!=0){                               
                         if ($(".ac_results")[0].style.display=="none"){
                             if($("#btnAdd").length!=0){                                                                    
                                 return EnterPressAdd(e, function(){
                                    $("#btnAdd").click();
                                 });
                             }                                         
                         }                                                                             
                     }        
                     else{
                        return EnterPressAdd(e, function(){
                            $("#btnAdd").click(); 
                        });                                   
                     }                         
                    });       

    },   

    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*/
  	        WSK.OffAng.ClientServices.JobOfferServices.GetJobCategories(this.options[this.selectedIndex].value,onJobCategoriesReceived.bind(this));
		    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*/
			    
			    WSK.OffAng.ClientServices.JobOfferServices.GetDepartments(this.options[this.selectedIndex].value,onRegionReceived.bind(this));               			    
			    optDiv.animate({opacity:1},500);											    
			    optDiv.show(500);
				optSelect.show(500);													
			}else{
				optDiv.hide(500);
				optSelect[0].selectedIndex=0;
			}
	  
	});
		
	function onRegionReceived(res) 
    {
//       optDiv=$(".searchParameters .optionalSecond");
//       optSelect=optDiv.children("select");
//       optSelect.html(res.value);
         optSelect=$(".ddlDepartment");
         optSelect.html(res.value);
         optSelect.attr("contentHTML",optSelect.get(0).outerHTML);

    }
         
	function onJobCategoriesReceived(res) 
    {
//        optSelect=optDiv.children("select");
//        optSelect.html(res.value);
          optSelect=$(".JSJobCategory");
          optSelect.html(res.value);
          optSelect.attr("contentHTML",optSelect.get(0).outerHTML);
    }
								
//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=="choose"){
				        this.innerHTML="modify";
				        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: "/WebServices/Vacancies.asmx/GetJobCategories",
//                                    // Pass the "domainCategory" parameter, via JSON object.
//                                    data:"activityDomain=" + $(".main select")[0].selectedIndex,                                                         
//                                    success: function(msg) {
//                                         if ($.browser.msie){ 
//                                               optSelect.html(msg.text);                   
//                                            }
//                                            else{
//                                               optSelect.html(msg.documentElement.textContent);
//                                            }   
//                                    }
//                                  });																	    																																					
//				                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=="choose"){
				        this.innerHTML="modify";
				        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: "/WebServices/Vacancies.asmx/GetDepartments",
//                                    // Pass the "region" parameter
//                                    data:"region=" + $(".mainSecond select")[0].selectedIndex,                                                                                                                                                                        
//                                    success: function(msg) {
//                                        if ($.browser.msie){ 
//                                               optSelect.html(msg.text);                   
//                                            }
//                                            else{
//                                               optSelect.html(msg.documentElement.textContent);
//                                            }                                                          
//                                    }
//                                  });	
//                                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=="choose"){
				        this.innerHTML="modify";
				    }
				    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");	    	            	    
//}, 

//ChangedIndex:function(){
//    $(".ddlRegion").change(function(){
//        //$(".ddlDepartment").innerHTML
//    });   
//},

//Search:function(){	            
//    $(".btnRefine").click(function() { 
//                      	                	                
//        var contractTypes=$(".contractType label input");
//        var filters="";               	                	                
//        var j=0;
//        
//        //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=="modify")&&($(".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")[0].selectedIndex>-1){
//                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")[0].selectedIndex!=-1){
//                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;;
//                }
//                  /*See if selected exists if so, get the selected value*/
//                else
//                    if($(".JSselectedDepartment")[0]!=undefined)
//                    {
//                        if(filters!=""){
//                            filters+="&";
//                        }
//                        filters+="department=" + $(".JSselectedDepartment")[0].id.toString().replace("D","");
//                    }
//            }	                    
//        }   
//        
//        //Check if exists any publication date selected	                 	                
//        if (($(".editPublicationDate")[0].innerHTML=="modify")&&($(".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.replace(/\-/g,"%2B");
//                        }
//                        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);
//                if(_keywords!="")
//                    _keywords=encodeURIComponent(keywords[i].value)+";";
//                else
//                    _keywords+=encodeURIComponent(keywords[i].value);
//                j++;
//            }                    	                   
//        }                           
//      
//      if(filters!=""){                        	                                 
//        // clear job alert container
//        //19/01/09
//        //To be reactivated during phase 3
//        //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()));
//		
//		$(".lnkRssFeed").each(function(){
//            this.href=this.href.substring(0,this.href.indexOf("?"))+"?"+filters;    
//        });
//		
//		LoadResultsAjax(filters);           
//      }
//      else{
//          alert("You must get at least a search criteria.");
//      }
//        	              
//    });
//}

}
function LoadResultsAjax(filters)
{

   WSK.OffAng.ClientServices.JobOfferServices.GetJobResults(filters,onResultsReturned.bind(this));
   if(($(".relatedJobPanel")[0]!=undefined)&&(_keywords!="")){
        WSK.OffAng.ClientServices.JobOfferServices.GetRelatedJobs(_keywords,onRelatedJobsReturned.bind(this)); 
        _keywords="";
   }
}

function GetQueryStringParams (url)
{
    return url.split("?")[1];
}

function onResultsReturned(res){
     //alert(res.value);
     //$(".wpJobSearchResults").html(res.value);
     document.getElementById("searchResultsPanel").innerHTML=res.value;
     LoadLinkPagination();
     refreshDisabledLinks(); 
     window.scrollTo(140,140);
}
     
     


function onRelatedJobsReturned(res){
    //document.getElementById("searchResultsPanel").innerHTML=res.value;
    $(".relatedJobPanel ul")[0].outerHTML=res.value;
}




function LoadLinkPagination()
{
    $(".pagination li a").unbind().click(ClickLinkPagination);
    $(".sortBy li a").unbind().click(ClickLinkPagination);
}

function ClickLinkPagination()
{
   
    if (!this.disabled) //Esto no funciona revisar!!!
    {
        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 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;          
}


/******************/

//    $(".btnRefine").click(function() { 

        function clickBtnRefine(){
                      	                	                
        var contractTypes=$(".contractType label input");
        var filters="";               	                	                
        var j=0;
      
        //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=="modify")&&($(".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")[0].selectedIndex>-1){
                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")[0].selectedIndex!=-1){
                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;;
                }
                  /*See if selected exists if so, get the selected value*/
                else
                    if($(".JSselectedDepartment")[0]!=undefined)
                    {
                        if(filters!=""){
                            filters+="&";
                        }
                        filters+="department=" + $(".JSselectedDepartment")[0].id.toString().replace("D","");
                    }
            }	                    
        }   
        
        //Check if exists any publication date selected	                 	                
        if (($(".editPublicationDate")[0].innerHTML=="modify")&&($(".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.replace(/\-/g,"%2B");
                        }
                        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);
                if(_keywords!="")
                    _keywords=encodeURIComponent(keywords[i].value)+";";
                else
                    _keywords+=encodeURIComponent(keywords[i].value);
                j++;
            }                    	                   
        }
      filters+="&offerDestiny="+offerDestiny;                           
      
      if(filters!=""){                        	                                 
        // clear job alert container
        //19/01/09
        //To be reactivated during phase 3
        //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()));
		
		$(".lnkRssFeed").each(function(){
            this.href=this.href.substring(0,this.href.indexOf("?"))+"?"+filters;    
        });
		
		LoadResultsAjax(filters);           
      }
      else{
          alert("You must get at least a search criteria.");
      }
        	              
    }
