
function show_page(page) {
	var params;

	$('busy_top').setStyle('display','block');
	params = '&object_id=' + $('object_id').value + '&page=' + page;
/*	thecomments_ajax_do('ajax_show_page', 'jc', params);*/

	new Ajax('index2.php', 
		{ method: 'get', 
		  update: 'jc', 
		  data: 'option=com_thecomments&task=ajax_show_page' + params,
		  onSuccess: function() {
			if($defined($('busy_top'))){
				$('busy_top').setStyle('display','none');
			}
		  }
		}).request();  

}

function do_add_comment() {
	var params;

	$('busy').setStyle('display','block');
	if($defined($('comments-form-captcha'))){
		params = '&object_id=' + $('object_id').value + '&user_name=' + replace_special($('comments-form-name').value) + '&email=' + replace_special($('comments-form-email').value) + '&comment=' + replace_special($('comments-form-comment-text').value) + '&captcha=' + $('comments-form-captcha').value;
	} else {
		params = '&object_id=' + $('object_id').value + '&user_name=' + replace_special($('comments-form-name').value) + '&email=' + replace_special($('comments-form-email').value) + '&comment=' + replace_special($('comments-form-comment-text').value);
	}
	thecomments_ajax_do('ajax_add_comment', 'thecomments-form-message', params);
}

function clear_comment() {
	$('comments-form-name').value = '';
	$('comments-form-email').value = '';
	$('comments-form-comment-text').value = '';
	$('comments-form-captcha').value = '';
	return false;
}

function thecomments_ajax_do(ajax_do, div_id, get_params) {
	new Ajax('/thecomments_saver/thecomments.saver.php', 
		{ method: 'get', 
		  update: div_id, 
		  data: 'task=' + ajax_do + get_params,
		  onSuccess: function() {
			if($defined($('busy'))){
				$('busy').setStyle('display','none');
			}
			if($defined($('busy_top'))){
				$('busy_top').setStyle('display','none');
			}
			if($defined($('form-clear'))){
				$('comments-form-name').value = '';
				$('comments-form-email').value = '';
				$('comments-form-comment-text').value = '';
				$('comments-form-captcha').value = '';
			}
			if($defined($('comments-form-captcha-image'))){
				$('comments-form-captcha-image').src = '/thecomments_saver/thecomments.saver.php?task=captcha&tmpl=component&ac=' +  + Math.floor( Math.random( ) * (99999 - 10000 + 1) ) + 10000;
			}
		  }
		}).request();  
}

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}

function replace_special(subject) {
	subject = str_replace('&','',subject);
	return subject;
}