jQuery(document).ready(function(){
	jQuery("#hrhome").validate({
  		errorElement:"div",
		rules: {
			chsearch:{
				required: true, 
                number: true,                     
				minlength: 2,
				maxlength:50
			}
		},
		messages: {
			chsearch:{
				chsearch:" Please enter location",
                number: "Zipcode must be numeric",         
				minlength:jQuery.format("Enter at least {0} characters"),
				maxlength:jQuery.format("Enter maximum {0} characters")
			}
		},
        submitHandler: function() {
            var chsearch = $('#chsearch').val();
            $.post(SITEROOT+"/default/index/ajaxrecentjob/",{ 'location': chsearch},function(data){
                $('#recentsrch').html(data);
                $.post(SITEROOT+"/default/index/ajaxrecentjobsess/",{},function(data1){
                    $('#changeid').html(data1+' <a href="javascript:void(0);" onclick="javascript:changerecent(\''+data1+'\');">change</a>');
                    $('#changeid').show();
                    $('#changeid1').hide();
                    $('#city_txt').hide();
                    $('#state_txt').hide();
                },'html');
            },'html');
            return false;
        }      
	});
});


$(document).ready(function() {
    
    // ajax get city/state
//     $('#ny_transporation').hide();
    $('#chsearch').keyup(function() {
        var zip = $(this).val();
        if(zip.length == 5) {
            processZip1(zip);        
        }
    });
    if($('#chsearch').val().length == 5) {
        processZip1($('#chsearch').val());        
    }   
    
}); 

function processZip1(zip_code) {
    var url = SITEROOT+'/job/post/ajax-process-zip';
    var arr_data = {zip:zip_code};
    
    $.post(url, arr_data, function(data) {
        if(data.result) {
            $('#city').val(data.location.city);
            $('#city_txt').text(data.location.city + ', ');
            $('#state').val(data.location.state);
            $('#state_txt').text(data.location.state);
        } else {
            $('#city').val('');
            $('#city_txt').text('Zip not found');
            $('#state').val('');
            $('#state_txt').text('');
        }
    }, 'json');
    
}
