// JavaScript Document
function setup_rate_review()
{
	showMyBox("#ajaxRateReview");
}

function validate_reviews_form()
{
	var errorMessage = "";
	var valid = true;
	if ($('select[name=vote]')[0].selectedIndex == 0){ valid = false; errorMessage += "Please select a vote value!\n";}
	if (!$('input[name=review_author]').val().length){ valid = false; errorMessage += "Please enter at the least your first name!\n";}
	if (!$('textarea[name=review_message]').val().length){ valid = false; errorMessage += "Please enter a review message for the product!\n";}
	

	if ($('input[name=antibot_input_str]').length)
	{
		if(!$('input[name=antibot_input_str]').val().length)
		{
			valid = false; errorMessage += "Please enter the text in the image above the \"Add Review\" button!\n";
		}
		
	}
	if (!valid) { alert(errorMessage); return false; }
	else { 	 do_reg_rate_submit(); return false;}
}

function finalize_rate_review()
{
	$('#rate_review').html("<br/>Rate and Review Submitted!</b>");
								disableAllMyBoxes();
								return;
}

function do_reg_rate_submit()
{

	var pid = $('input[name=productid]').val();
	if (!pid || pid == '') return;
	str = 'product.php?mode=review_vote&amp;productid=' + pid;
	$('#review_vote_form')[0].action = str;
	$('#review_vote_form').ajaxSubmit(
					function (res)
					{
						$('#review_vote_form')[0].action = '';
						res = res.replace(/\s+/g,'');
						if (res == 'true')
						{
								alert("Thank you! Your Vote and Review has been submitted.");
						}
						else
						{
							if (res == 'antibot')
							{
								alert( "Please enter the correct text in the image above the \"Add Review\" button!\n");
								change_antibot_image('on_reviews');
								$('input[name=antibot_input_str]').val('');
							}
							else if (res == 'both')
							{
								alert ("You have already submited a vote and review for this product!");
							}
							else if (res == 'voted')
							{
								alert ("You have already submited a vote for this product. You review has however been submited!");
							}
							else if (res == 'reviewed')
							{
								alert ("You have already submited a review for this product. You vote has however been submited!");
							}
						}
						if (res != 'antibot' && res != '')
						{
															finalize_rate_review();
						}
						
					}
	);

}




