jQuery(document).ready(function(){
	jQuery("#agence").attr("disabled", "disabled");
	jQuery('#projet1_cp').blur(function(){
		if(jQuery('#projet1_cp').val().length > 1)
			checkAgence(jQuery('#projet1_cp').val());
	});
});

function checkAgence(code){
	jQuery.ajax({
		type: "POST",
		dataType: "html",
		data: "code="+code,
		url: "/zp/templates/gestion_loc_conseiller/JX_agence.php",
		beforeSend:function(){
			jQuery("#agence").attr("disabled", "disabled");
			jQuery("#img_load").remove();
			jQuery("#agence").before('<span id="img_load"><img src=/images/ajax-load-gestion-loc.gif /></span>');
		},
		error:function(msg){
			alert( "Error !: " + msg );
		},
		success:function(data){
			jQuery("#img_load").remove();
			if(data != ''){
				jQuery("#agence").attr("disabled", "");
				jQuery("#agence").html(data);
			}
		}
	});
}

function agencySelected() {
    if(jQuery("#img_load").length) return false;
    if(isNaN(jQuery('#projet1_cp').val()) || trim(jQuery('#projet1_cp').val()) == '') {
        if(trim(jQuery('#projet1_cp').val()) == '') {
            alert('Vous devez saisir un code postal');
        } else {
            alert('Vous devez choisir une agence');
        }
        return false;
    }
	return true;
}
