/**
 * --------------------------------------------------------------------------
 * GENEL AJAX İŞLEMLERİNİ YÜRÜTÜR
 * --------------------------------------------------------------------------
 *
 * @author Ali OYGUR
 */
function ajax_start(form_id, url) {	
	
	url = BASE_URL + clean_url(url);
	
    jQuery('form#' + form_id).hide();
    jQuery('#error').remove();
    jQuery('#loading').remove();
    jQuery('#success').remove();
	
    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){
				
            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 'reset_password':
	                window.location.href = response.redirect;
	                return true;
					break;
					
				case 'login':
	                window.location.href = BASE_URL + CUR_LANG;
	                return true;
					break;
				case 'comment':
					jQuery('form#' + form_id).before('<div class="notification success" id="success">' + response.msg + '</div>');
	                jQuery('form#' + form_id).show();
	                $.colorbox.resize();
	                return true;
	                break;
				default:
				
	                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;
}

/**
 * kendisine verilen url adresinin başında / karekteri mevcutsa siler.
 */
function clean_url (url) {
	return url.substr(0,1) == '/' ? url.substr(1) : url;
}




