$(function() {
	http_val = '';
	if ($('input#http').length > 0)
		http_val = $('input#http').attr('value');

	$('#quick_search input[@type=text]').focus(function() {
		if ($(this).attr('value') == $(this).attr('title'))
			$(this).attr('value', '');
	});

	$('#quick_search input[@type=text]').blur(function() {
		if ($(this).attr('value') == '')
			$(this).attr('value', $(this).attr('title'));
	});

	if ($('#frm').length > 0)
		$('#frm_search').remove();

	$('#but_post_review').click(function() {
		if ($('#post_review').css('display') != 'none')
		{
			rating_val = $('#post_review .star_on').length;
			$('#frm_post_review input[@name=rating]').attr('value', rating_val);
			text_review_val = $('#text_review').attr('value');
			if (text_review_val == '') {
				alert('Please enter the review text!');
				return;
			}
			$('#frm_post_review').submit();
			return;
		}

		if ($('#authenticated').length > 0 && $('#authenticated').css('display') != 'none')
			$('#post_review').show('fast');
		else
			$('#login_review').show('fast');
	});

	$('#link_logout').click(function() {
		$.get(http_val+'?review_logout', {}, function(response) {
			if (response.indexOf(1) == -1) return;
			$('#authenticated').hide();
			$('#login_review').hide();
			$('#post_review').hide();
			alert('You were logged out!');	
		})
	});

	$('#frm_login').submit(function() {
		user_val = $('#btn_user').attr('value'); 
		pass_val = $('#btn_password').attr('value');

		$.post(http_val+'?review_login', {user: user_val, pass: pass_val}, function(response) {
			if (response && response.trim() != '0') {
				$('#login_review').hide();
				$('#post_review').show();
				$('#authenticated .login_user').text(response);
				$('#authenticated').show();
			}
			else alert('Invalid Login!');
		});
		return false;
	});

	$('#text_review').keyup(limit_text);
	$('#text_review').keydown(limit_text);
})

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function limit_text() 
{
	limitNum = 1000;
	val = $(this).attr('value');
	if (val.length > limitNum)
		$(this).attr('value', val.substring(0, limitNum))
}

  
  function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}