$(document).ready(function() {
	$('#subscribe-email').focus(function() {
		if ($(this).val() == $('#enter-email-txt').html()) {
			$(this).val('');
		}
	});

	$('#subscribe-email').blur(function() {
		if ($(this).val() == '') {
			$(this).val($('#enter-email-txt').html());
		}
	});

	$('#search-input').focus(function() {
		if ($(this).val() == $('#search-input-txt').html()) {
			$(this).val('');
		}
	});
	
	$('#search-input').blur(function() {
		if ($(this).val() == '') {
			$(this).val($('#search-input-txt').html());
		}
	});
});


function submitComment(iid, type) {
	var url = '/' + $('#lang-code').html() + '/index/axaddcomment';
	$.post(url, {
		type : type,
		id : iid,
		body : $('#commentText').val()
	}, function(data) {
		var n = parseInt($('#comment-total').html()) + 1;
		
		var nocomment = $('.nocomment');
		if (nocomment.length > 0) {
			nocomment.html(data);
			nocomment.removeClass('nocomment');
		} else {
			$("#comments-list").append('<li>' + data + '</li>');
		}
		
		$('#commentText').val('');
		$('#comment-total').html(n);
	});
}

function submitQuestion(id) {
	$('#err-msg').hide();
	var url = '/' + $('#lang-code').html() + '/feedback/axaddcomment';
	$.post(url, {
		qid : id,
		body : $('#commentText').val()
	}, function(data) {
		if (data == '') {
			$('#err-msg').show();
		} else {
			var n = parseInt($('#comment-total').html()) + 1;
			
			var nocomment = $('.nocomment');
			if (nocomment.length > 0) {
				nocomment.html(data);
				nocomment.removeClass('nocomment');
			} else {
				$("#comments-list").append('<li>' + data + '</li>');
			}
			
			$('#commentText').val('');
			$('#comment-total').html(n);
			
			$('#ok-msg').fadeIn();
			delayHide('ok-msg', 3000);
		}
	});
}

function submitQuestionIndex(id) {
	$('#err-msg').hide();
	var url = '/' + $('#lang-code').html() + '/feedback/axaddcomment';
	$.post(url, {
		qid : id,
		body : $('#commentText').val()
	}, function(data) {
		if (data == '') {
			$('#err-msg').show();
		} else {
			$('#commentText').val('');
			$('#ok-msg').fadeIn();
			var url2 = '/' + $('#lang-code').html() + '/feedback/view?qid=' + id;
			redirectPage(url2);
		}
	});
}

function delayHide(id, t) {
	var timer = setInterval('hideElement(\'' + id + '\')', t);
}

function hideElement(id) {
	$('#' + id).fadeOut();
}

function delayedRedirect(url, sec) {
    setTimeout('redirectPage(\'' + url + '\')', sec * 1000);
}

function redirectPage(url) {
    window.location = url;
}

function rc(cid) {
	var url = '/' + $('#lang-code').html() + '/index/axreportcomment';
	$.post(url, {
		id : cid,
	}, function(data) {
		if (data.status == 'ok') {
			$('#report-' + cid).hide();
		}
	}, "json");
}

function validatePoll() {
	$('#poll-err').hide();
	var checked = false;
	$('.poll-option').each(function(){
		if ($(this).attr('checked')) {
			checked = true;
		}
	});
	
	if (checked) {
		return true;
	}
	
	$('#poll-err').show();
	return false;
}
