/*
'--------------------------------------------------------------------------------------------------
' Title			: (modal?) Dialog "Member Rating" JavaScript
' Description	: JavaScript function for the pop up form (div) on (for example) the member profile page
'					see php file named similarly in inc folder
'--------------------------------------------------------------------------------------------------
' History
' 1/6/2009	: GF - Created Page
'					some code used from http://jqueryui.com/demos/dialog/#modal-form
'--------------------------------------------------------------------------------------------------
*/

$(document).ready(function(){
	
	var txtFeedback = $("#TxtFeedback"),
		allFields = $([]).add(txtFeedback),
		tips = $("#validateTips");
	
	// Initialize the Member Rating dialog
	$('#RateMemberDialog').dialog({
		autoOpen:false,
		width:800,
		height:600,
		modal:true,
		buttons:{
				
				'Submit Rating':function()
				{					
					if (document.getElementById('TxtFeedback'))
					{
						//Submit the form for processing...

						var bValid = true;
						allFields.removeClass('ui-state-error');
												
						if (bValid) {
							document.getElementById('rate_member_submitted').value = 'Rating Form Submitted!';

							tips.text("Processing...");
		
							//Submit the form for processing...
							$("form:RateMemberDialog").submit();
		
						}
						else
						{
							//tips.text("No");
						}


					}
					else
					{
						alert('Please login in order to rate this member.');
						$(this).dialog('close');
					}

				},
				Cancel:function()
				{
					$(this).dialog('close');
				}
		}
	});
	$('#RateMemberDialogBtn').click(function() {
		$('#RateMemberDialog').dialog('open');
	});
	
	// tips are like instructions
	function updateTips(t) {
		tips.text(t).effect("highlight",{},1500);
	}

	function checkLength(o,n,min,max) {

		if ( o.val().length > max || o.val().length < min ) {
			o.addClass('ui-state-error');
			if (min == max)
			{
				updateTips("Length of " + n + " must be "+min+".");
			}
			else
			{
				updateTips("Length of " + n + " must be between "+min+" and "+max+".");
			}
			return false;
		} else {
			return true;
		}

	}

	function checkRegexp(o,regexp,n) {

		if ( !( regexp.test( o.val() ) ) ) {
			o.addClass('ui-state-error');
			updateTips(n);
			return false;
		} else {
			return true;
		}

	}

	
	

});


