/**

 * --------------------------------------------------------------------------
 * GENEL AJAX İŞLEMLERİNİ YÜRÜTÜR
 * --------------------------------------------------------------------------
 *
 * @author Ali OYGUR
 */
function ajax_start(form_id, url, loading) {	
	
	url = BASE_URL + clean_url(url);
	
    jQuery('form#' + form_id).hide();
    jQuery('#error').remove();
    jQuery('#loading').remove();
    jQuery('#success').remove();
	if(loading==null){
    	jQuery('form#' + form_id).before('<div class="notification loading" id="loading">&nbsp;</div>');
	}
	
    jQuery.ajax({
        type     : 'POST',
        url      : url,
        dataType : 'json',
        data     : jQuery('form#' + form_id).serialize(),
        success  : ajax_success
    });
	
    function ajax_success(response) {
        
        jQuery('div.loading').remove();
				
        if(response.error === true){
        	
			if (response.fb_get_perm) {
				if(loading==null){
					jQuery('form#' + form_id).before('<div class="notification loading" id="loading">&nbsp;</div>');
				}
				FB.login(function(fresponse) {
					
					if (fresponse.authResponse) {
						
						fresponse = 'page_id='+response.page_id;
						$.post(
							BASE_URL + 'user/sayfa_ekle',
							fresponse,
							function(response) {
								// hata varsa
								if(response.error) {
									alert(response.msg)
									window.location.reload();
								// hata yoksa
								} else {
									alert(response.msg)
									window.location.reload();						
								}
							},
							'json'
						);	  
						
				    
				   } else {
				   	
				     
				   }
				 }, {scope: response.fb_get_perm});
			}
				
            jQuery('form#' + form_id).before('<div class="notification error" id="error">' + response.msg + '</div>');
            jQuery('form#' + form_id).show();
            $.colorbox.resize();
			return true;
			
        } else {
		
            /* costums success */
            
			switch (form_id) {
				
				case 'register':
				case 'login':
				case 'reset_password':
	                window.location.href = response.redirect;
	                return true;
					break;
				
				default:
	                if(response.redirect){
	                	window.location.href = response.redirect;
                	}
	                jQuery('form#' + form_id).before('<div class="notification success" id="success">' + response.msg + '</div>');
	                jQuery('form#' + form_id).show();
	                $.colorbox.resize();

	                	
	                return true;
	                
					break;
			}
        }

    }
	
    return false;
}
