/* initialize the Ajax handler */
$().ready(function(){                          
                        optDiv=$("#quickBLDiv");                                                                                
                        optDiv.hide(0);  
                        //optDiv.css("display","none");                                                              
                        QuickBranchLocator.clickUpdateDDL();
                        QuickBranchLocator.changeBranch();                        
                    })

QuickBranchLocator={
    clickUpdateDDL:function(){                                              
                
        $(".btnOk").click(function(){     
           
        if (($(".txtQuickBranchLocator")[0].value.length == 2)||
        ($(".txtQuickBranchLocator")[0].value.length == 5)){
            optDiv=$("#quickBLDiv");        
            //optDiv.animate({opacity:1},500);                                                
            optDiv.hide(500);
            //optDiv.css("display","block");
            optSelect=optDiv.children("select");
            $(".ddlBranchesList")[0].disabled = true;                                                                    
            
            var request =
            {
                postalCode: jQuery.trim($(".txtQuickBranchLocator")[0].value),
                //url: location.protocol + "//" + location.host          
                url: location.host
            };        
            
            var result;        
                    
                $.ajax({
                        type: "GET",
                        url: "/_layouts/AdeccoFR/WebServices/Vacancies.asmx/UpdateQuickBranchLocator",                    
                        data:request,                                                         
                        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();    
                          $(".ddlBranchesList")[0].disabled = false;                                                                    
                          optDiv.show(500);
                        }
                      });      
            }          
                return false; 
        });                 
    },
    
    changeBranch:function(){
        $(".ddlBranchesList").change(function(){            
            if ($(".ddlBranchesList")[0].value != "0")
            {
                var request =
                {
                    branchId: $(".ddlBranchesList")[0].value                   
                }
                $.ajax({
                    type: "GET",
                    url: "/_layouts/AdeccoFR/WebServices/Vacancies.asmx/RedirectSearchBranch",                    
                    data:request,                                                         
                    success: function(msg) {
                        if ($.browser.msie){ 
                            var url = msg.text;
                        }
                        else{
                            var url = msg.documentElement.textContent;                       
                        } 

                        location.href = url;                        
                   }
                });    
            }        
            return false;            
        });
    }
}
