	function validate(field)
	{
		return validate(field, null, null);
	}

	function validate(field, msg_field, msg)
	{
		if (msg_field)
			msg_field.innerHTML = '';
		
		if (!field.value || field.value==0) {
			if (msg_field)
				msg_field.innerHTML = msg;
			return false;
		}
		
		return true;
	}


	function submit_review()
	{
		if (validate($('rating'), $('validation_msg'), 'Please share your rating using the stars.'))
		{
			var frm = $('comments_form');
			var inp = frm['comment'];
			if (validate($(inp), $('validation_msg'), 'Use the text box above to compose your review.'))
			{
		        Spinner.show();
		        new Ajax.Request($('comments_form').action, {
		            method:$('comments_form').method, 
		            parameters:$('comments_form').serialize(), 
		            onComplete:function(){
		                Spinner.hide();
		            }
		        });
			}
		}
	}
	
	function submit_comment()
    {
		var frm = $('comments_form');
		var inp = frm['comment'];
		if (validate($(inp), $('validation_msg'), 'Please enter a comment above.'))
		{
	        Spinner.show();
	        new Ajax.Request($('comments_form').action, {
	            method:$('comments_form').method, 
	            parameters:$('comments_form').serialize(), 
	            onComplete:function(){
	                Spinner.hide();
	            }
	        });
		}
    }

    function show_reply_form(reply_to_id)
    {
        $$('a.leave-a-comment').each(function(item) { item.show(); }); 
        $$('form.reply').each(function(item) { item.hide(); }); 
        $('reply_form_'+reply_to_id).show(); 
        $('reply_form_'+reply_to_id).down('textarea').focus(); 
    }

    function submit_reply(reply_to_id)
    {
		if (validate($('reply_'+reply_to_id), $('validation_msg_'+reply_to_id), 'Please enter your response above.'))
		{
	        Spinner.show();
	        new Ajax.Request($('reply_form_'+reply_to_id).action, {
	            method:$('reply_form_'+reply_to_id).method, 
	            parameters:$('reply_form_'+reply_to_id).serialize(), 
	            onComplete:function(){
	                Spinner.hide();
	            }
	        }); 
		}
    }
