 $(function() {  
   $('.error').hide();
   $(".vCommentsSaveBtn").click(function() { 
										 
     // validate and process form here  
     $('.error').hide();  
       var comment = $("textarea#v_comment_textarea").val();  
         if (comment == "") {  
       $("label#v_comment_textarea_error").show();  
       $("input#v_comment_textarea").focus();  
       return false;  
     }  
      var channelListId = $("input#channelListId").val();  
         if (channelListId == "") {  
       $("label#channelListId_error").show();  
       $("input#channelListId").focus();  
       return false;  
     }  
      var mediaId = $("input#mediaId").val();  
         if (mediaId == "") {  
       $("label#mediaId_error").show();  
       $("input#mediaId").focus();  
       return false;  
     }
	  var userId = $("input#userId").val();  
         if (mediaId == "") {  
       $("label#userId_error").show();  
       $("input#userId").focus();  
       return false;  
     }
	 //remove the users input text from the the form
 	document.getElementById('v_comment_textarea').value = "";
	
	var dataString = 'body='+ escape(comment) + '&channelListId=' + channelListId + '&mediaId=' + mediaId + '&userId=' + userId;
    $.ajax({
      type: "POST",
	  url: "../../mod/vcomments/actions/save.php",
      data: dataString,
	  //dataType: "JSON", // this is for the return data
	  dataType: "HTML", // this is for the return data
      success: function(nameOfResponse) {
		var type = typeof nameOfResponse;
		//alert("dataString= " + dataString);
        alert(dataString);
		alert("Your comment has been saved.");
		//alert("nameOfResponse= " + nameOfResponse);
	    if ((nameOfResponse) == null) {
			$("#vform_comments").html('Sorry, there was a problem loading the form');
	  	} else {
			$("#vform_comments").html(nameOfResponse);
	  	}
      }
    });
    return false;
	  
	   });  
	 }); 