/**
 * @author Vlad Balmos
 */

// updater function
function UPDATER(_if) {
	this._if		= _if;

	this.doIt		= function() {
		$j.post(
			siteurl+'/statsupdate.php',
			{val: _if}
		);
	}
}

function deletechannel(chid, uid, cachename) {
	$j.post(
			siteurl+'/deletefavorite.php',
			{val1: chid, val2: uid, val3:cachename},
			function(response) {
				$j('#ch_'+chid).remove();
			}
	);
}


// comment class
var comment = new function() {

	this.send_logged = function() {
		if(!$j('#message_field').val()) {
			alert('Message can not be left blank');
			return false;
		};
		$j('#comment_loader').css('display', 'inline');
		$j('#submit_comment').attr('disabled', true);
		data = $j('#comment_form').serialize()
		$j.post(
			siteurl+'/comment.php',
			data,
			function(response) {
				if(response == 'ok') {
					$j('#comment_loader').css('display', 'none');								
					$j('#message_field').attr('disabled', true);
					$j('#message_field').css('background', '#cccccc');
					$j('#submit_comment').remove();
					alert('Your message has been posted');
				} else {
					$j('#submit_comment').attr('disabled', false);								
					$j('#comment_loader').css('display', 'none');																
					alert('Your comment could not be posted, due to a technical problem');
				}
			}
		);
	}
	
	this.send_guest = function() {
		if(!$j('#message_field').val()) {
			alert('Message can not be left blank');
			return false;
		};

		if(!$j('#guest_name').val()) {
			alert('Your name is required');
			return false;
		};
			
		answer = $j('#answer').val();
		$j.post(
			siteurl+'/checkcaptcha.php',
			{val: answer},
			function(response) {
				if(response == 'true') {
					$j('#comment_loader').css('display', 'inline');
					$j('#submit_comment').attr('disabled', true);
					data = $j('#comment_form').serialize()
					$j.post(
						siteurl+'/comment.php',
						data,
						function(response) {
							if(response == 'ok') {
								$j('#comment_loader').css('display', 'none');								
								$j('#message_field').attr('disabled', true);
								$j('#message_field').css('background', '#cccccc');
								$j('#guest_name').attr('disabled', true);
								$j('#submit_comment').remove();
								$j('#answer').remove();
								$j('#smg').remove();								
								$j('#captcha_hint').remove();																
								alert('Your message has been posted');
							} else {
								$j('#submit_comment').attr('disabled', false);								
								$j('#comment_loader').css('display', 'none');																
								alert('Your comment could not be posted, due to a technical problem');
							}
						}
					);
	
				} else {
					alert('Please enter the correct security letters');
					return false;
				}
			}
		);
	}
	
	this.show = function(page, id) {
		img = '<img src="'+siteurl+'/images/ajaxloader.gif" style="display: block; margin-top: 150px; margin-left: 290px"/>';
		$j('#comments_container').html(img);
		$j.get(siteurl+'/comments.php?f='+id+'&p='+page,
			function(data) {
				$j('#comments_container').html(data);
			}
		);
	}
}
