
function ajaxSubmitReview(){
  var errors=false; 
  var msg='';
  
  //check form for errors
  var reqFields = new Array("RatingAttendDate","RatingTitle","RatingCommentary");
	var reqFieldsName = new Array("Date Attended","Title","Commentary");

	// Check all required fields are filled
	for (var i=0; i < reqFields.length; i++)
		{
		if (document.ratingForm[reqFields[i]].value == "")
			{
			msg=msg+"* Please provide the " + reqFieldsName[i] + " in the space provided \n";
			errors=true;
			}
		}

	if (document.ratingForm.Rating.value == 0)
		{
		msg=msg+"* Please choose a Rating by clicking on one of the smiley faces.\n\n1 smiley = lowest, 5 = highest";
		errors=true;
		}
	//if (document.ratingForm.PPR_Code.value == ""){document.ratingForm.PPR_Code.value = 0;}
	
	
	if (errors==true){
		alert(msg);
	}
	else{
		//get the variables 
		ratingActivityID=$('input#RatingActivityID').val();
		ratingEventID=$('input#RatingEventID').val();
		ratingSRClassID=$('input#RatingSRClassID').val();
		
		if (ratingActivityID!=0){
			groupID=1;
			groupRecordID=ratingActivityID;
		}
		
		if (ratingEventID!=0){
			groupID=2;
			groupRecordID=ratingEventID;
		}
		
		if (ratingSRClassID!=0){
			groupID=3;
			groupRecordID=ratingSRClassID;
		}
		
		rating=$('input#Rating').val();
		ratingAttendDate=$('input#RatingAttendDate').val();
		ratingTitle=$('input#RatingTitle').val();
		ratingCommentary=$('textarea#RatingCommentary').val();
		//PPR_Code=$('input#PPR_Code').val();
		childAges=$('input#ChildAges').val();
		emailAddress=$('input#emailAddress').val();
		
		
		dataToSend='action=saveReview&groupID='+groupID+'&groupRecordID='+groupRecordID+'&rating='+rating+'&ratingAttendDate='+ratingAttendDate+'&ratingTitle='+ratingTitle+'&ratingCommentary='+ratingCommentary+'&childAges='+childAges+'&emailAddress='+emailAddress
		
		//submit the form via ajax!
		//alert(dataToSend)
		$.ajax({
    url: 'ajax_Functions.aspx',
    type: 'GET',
    dataType: 'html',
    data: dataToSend, 
    timeout: 10000,
    error: function(){
        alert('error');
    },
    success: function(html){
     if (html=='success'){
      alert('Thank you for your submition! \n It will be published and credited to you after review.');
      $('#userRatingForm').hide('slow');
     }
     else{
     	alert(html);
    }
    }
});
	
	}
		

}
