$(document).ready(function(){
	
    if ($(".savebtn").length ) {
        $('.savebtn').click(function() {   
            $.ajax({
                type: "POST",
                url: document.base_url+'jobs/save',
                dataType: 'json',
                data: {'id' : $(this).attr('id')}
            }).done(function( response ) {
                alert( response.msg );
            });
        //            var id = $(this).attr('id');  
        //            $.post(document.base_url+'jobs/save',{ 'id':id },
        //            function(result) {       
        //                if (result=="0") {
        //                    alert('This job was already saved.');
        //                } else if (result=="1") {
        //                    alert('Successfully saved.');
        //                } else {
        //                    alert('Please register or log in.');
        //                }
        //            }
        //            );
        });  
    }
    
    //	if ($("#sidebar form").length ) {
    //		$("#sidebar form label").inFieldLabels();
    //    }  
    if ($("#state").length ) {
        $('#country').change(function(){
        
            country = $(this).attr('value')
			  
            $('#state').replaceWith('<select name="state" id="state"></select>');
			  
            $('#state').load(
                document.base_url + 'ajax/states/' + country,
                function complete(){
                //$('select[name=subcategory]').attr('disabled', 0);
                }
                );
        });
    //$('#country').trigger('change');
    }
        
    if ($(".secure").length ) {
        $.get("../jobs/token",function(txt){
            $(".secure").append('<input type="hidden" name="ts" id="ts" value="'+txt+'" />');
        });
    }
        
    var form = $('.dropdown-menu').find('form');
    form.click(function(e) {
        e.stopPropagation();
    });
  
    
    //Autocomplete 
    var get_auto = {
        get_auto_list: function (id_name,method_name) {
            
                         $(id_name).autocomplete({
                source: "/autocomplete/"+method_name,
                minLength: 2		
            });
        }
    };
    
    if($("#position").length)
        get_auto.get_auto_list("#position", "get_profile/position");
    if($("#city").length)
        get_auto.get_auto_list("#city", "get_profile/city");
    if($("#place").length)	
        get_auto.get_auto_list("#place", "get_edu/place");
    if($("#degree").length)
        get_auto.get_auto_list("#degree", "get_edu/degree");
    if($("#location").length)	
        get_auto.get_auto_list("#location", "get_edu/location");
    if($("#company").length)	
        get_auto.get_auto_list("#company", "get_employment/company");
    if($("#emp_position").length)	
        get_auto.get_auto_list("#emp_position", "get_employment/position")
    
    //notifications
    if($("#head_notifications").length)
    {
        $.get(document.base_url + 'profile/get_notifications', function(data) {
            $.each(data, function(i,item){     
                if (item.messages_num > 0) {
                    $('#head_messages').append('('+item.messages_num+')');
                }
                if (item.referral_num > 0) {
                    $('#head_referral').append('('+item.referral_num+')');       
                }   
                if (item.messages_num > 0 || item.referral_num > 0) {
                    var total = parseInt(item.messages_num) + parseInt(item.referral_num);
                    $('#head_notifications').append('('+ total +')');  
                    $("#head_notifications").parent('.dropdown').show();
                }
            });
 
        });
    }  
    
    
//    $("[rel=twipsy]").twipsy({
//        live: true
//    })
//    if (RegExp(" Mobile/").test(navigator.userAgent)) {
//        $.getScript("http://code.jquery.com/mobile/1.0rc3/jquery.mobile-1.0rc3.min.js");
//    }

});


