/* initialize the Ajax handler */
$().ready(function(){ 						 
                        optDiv=$("#quickBLDiv");                                											    
		                optDiv.hide(500);  
		                //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.show(500);
			//optDiv.css("display","block");
			optSelect=optDiv.children("select");
			$(".ddlBranchesList")[0].disabled = false;																	
			
			var request =
			{
				postalCode: jQuery.trim($(".txtQuickBranchLocator")[0].value),
				//url: location.protocol + "//" + location.host          
				url: location.host
			};		
	        
			var result;        
	                
				$.ajax({
						type: "GET",
						url: "/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();    
						}
					  });	  
			}          
				return false; 
		});         		
    },
    
    changeBranch:function(){
        $(".ddlBranchesList").change(function(){            
            if ($(".ddlBranchesList")[0].value != "0")
            {
                var request =
                {
                    url: location.host                    
                }
                $.ajax({
                    type: "GET",
                    url: "/WebServices/Vacancies.asmx/RedirectSearchBranch",                    
                    data:request,                                                         
                    success: function(msg) {
                        if ($.browser.msie){ 
                            var url = msg.text.split("||")[0] + $(".ddlBranchesList")[0].value;
                            var environment = msg.text.split("||")[1];
                        }
                        else{
                            var url = msg.documentElement.textContent.split("||")[0] + $(".ddlBranchesList")[0].value;                                 
                            var environment = msg.documentElement.textContent.split("||")[1];
                        } 
                        if (environment == 'ADIA')
                            window.open(url,'_blank')
                        else
                            location.href = url;                        
                   }
                });	
            }        
            return false;            
        });
    }
}