$().ajaxStop($.unblockUI); 

$(document).ready(function() {        
    $('#frmComment').ajaxForm({
        beforeSubmit: function(a,f,o) {
				    var theForm = f[0]; 
				    if (!theForm.CommentsField.value || !theForm.CommentsFieldID.value || !theForm.CommentsName.value || !theForm.CommentsEmail.value) { 
				        alert('All field must be filled!'); 
				        return false; 
				    }
				    
            o.dataType = 'html';
            $('div#CommentsBoxInput').block('<b>Processing</b>', { border: '3px solid #1F4266' }); 
        },
        success: function(data) {
						if (typeof data == 'object' && data.nodeType)
				        data = elementToString(data.documentElement, true);
				    else if (typeof data == 'object')
				        data = objToString(data);    
				        		    
				    if (data.indexOf('SUKSES') == -1) {
				    	alert('Error:\n' + data);
				    } else {
				    	iditem = $("#CommentsFieldID").val();
				    	ShowDiveSitesComments(iditem);
				    	$("#CommentsField").val("");
				    	$("#CommentsName").val("");
				    	$("#CommentsEmail").val("");
				    	$("#CommentsBoxInput").html('<p align="center">Thank You</p>');
				    	ShowDiveSitesStatComments();
				    }
				    $('div#CommentsBoxInput').unblock();    
        }
    });
}); 

		function ShowDiveSitesComments(iditem) {
			 
			 surl = "/divesites/showcomment/" + iditem;
			 $.ajax({
			   type: "GET",
			   url: surl,
			   dataType: "html",
			   beforeSend: function(){
						$('div#theDiveSitesComments').block('<b>Processing</b>', { border: '3px solid #1F4266' }); 
			   },
			   success: function(msg){
				   	$("#theDiveSitesComments").html(msg);
				   	$('div#theDiveSitesComments').unblock(); 
				   	ShowDiveSitesStatComments();
			   }
			 });
		}

		function ShowDiveSitesStatComments(idx) {
			 
			 surl = "/divesites/statcomment/" + idx;
			 $.ajax({
			   type: "GET",
			   url: surl,
			   dataType: "html",
			   beforeSend: function(){
						$('div#theDiveSitesStatComments').block('<b>Processing</b>', { border: '3px solid #1F4266' }); 
			   },
			   success: function(msg){
				   	$("#theDiveSitesStatComments").html(msg);
				   	$('div#theDiveSitesStatComments').unblock();
			   }
			 });
		}
		
		function DeleteComments(iditem) {
			 
			 surl = "/divesites/delcomment/" + iditem;
			 $.ajax({
			   type: "GET",
			   url: surl,
			   dataType: "html",
			   beforeSend: function(){
						$('div#theBestshotsComments').block('<b>Processing</b>', { border: '3px solid #1F4266' }); 
			   },
			   success: function(msg){
				   	if (msg.indexOf('SUKSES') == -1) {
					    	alert('Error:\n' + msg);
					  } else {
					  		document.getElementById("theCommentID" + iditem).style.display = "none";
						}
						$('div#theBestshotsComments').unblock();
						
						ShowDiveSitesStatComments();
			   }
			 });
		}