function new_comment( form ){
	if( jQuery.active ){
		alert("Another request is being sent, please wait before requesting again."); return false;}
	
	var theform = $(form);
	
	var post_data = {}
	theform.find("input, select, textarea").map(function(){
		if( $(this).attr("disabled") == true ) return true;
		var name = $(this).attr("name");
		var value = $(this).val();
		var checked = true;
		if( $(this).attr("type") == "checkbox" )
			checked = $(this).attr("checked");
		
		if( checked && name && value )
			post_data[ name ] = value;
		return true;
	});
	
	if( ! post_data.comment || ! post_data.comment.length ){
		alert("A comment is required.");
		return false;
	}
	
	var ajax_data = {
		url: "./admin/jcustom_mod/plugins/more-comment/more-comment-ajax.php?nocache="+Math.random(),
		type: "POST",
		data: post_data,
		dataType: 'xml',
		timeout: 30000,
		complete:function(){
			theform.find("input, select, textarea").attr("disabled",false);
			theform.find(".loader").fadeOut("fast",function(){
				$(theform.find("input:submit").get(0)).fadeIn("slow");
			});
			theform.animate({opacity:1},200);
		},
		success: function( data, status ){
			var xml = $(data);
			var prompt_msg = xml.find('prompt').text();
			var error_no = parseInt( xml.find("error").text() );
			var status_no = parseInt( xml.find("status").text() );
			
			if( typeof(error_no) != 'undefined' ){
				if( prompt_msg ) alert( prompt_msg );
				if( error_no ){
					if( !prompt_msg ) alert("Unknown error occured, try again later.");
				}else if( error_no == 0 ){
					xml.find("inserthtml").children("*").each(function(){
						if( this.tagName == 'script' ){
							$(this).children("*").each(function(){ eval( $(this).text() ); });
						}else{
							if( $("#comment-"+ xml.find("insertid").text() ).length == 0 )
								$("#"+ this.tagName).prepend( $(this).text() );
						}
					});
				}
			}else alert("Error occured while parsing data.");
		},
		error: function(data, status, e){
			if( status == 'timeout' )
				alert( "Server was taking too long to respond.\nThe request may have been submitted but a response wasn't recieved.\nPlease try again later or refresh the page." );
			else if( status && e )
				alert( "["+ e.number +"] "+ e.message +"\n"+ status +"..");
/*			var s='';
			for( i in e ){
				s+= i+" - "+ e[i] +"\n\n";
			}
			alert( s );*/
		}
	};
	
	theform.find("input, select, textarea").attr("disabled",true);
	$(theform.find("input:submit").get(0))
		.fadeOut("fast",function(){ theform.find(".loader").fadeIn("slow"); })
		.animate({opacity:1},1000,null,function(){
			if( ! jQuery.active )
				$.ajax( ajax_data );
			else{
				alert("Another request is being sent, please wait before requesting again.");
				ajax_data.complete();
			}
		});
	theform.animate({opacity:0.5},200);
	
	return true;
}

function comment_page( page, data, container_id ){
	if( !data.relation || !data.rel_id || ! $("#"+container_id).length ) return false;
	if( !page ) page = 1;
	if( jQuery.active ){
		alert("Another request is being sent, please wait before requesting again."); return false;}
	
	var container = $("#"+container_id);
	data['container'] = container_id;
	data['get_comment_page'] = "82fe537898c13f6db7cbe2a88ff1ae30";
	data['p'] = page;
	
	var ajax_data = {
		url: "./admin/jcustom_mod/plugins/more-comment/more-comment-ajax.php?nocache="+Math.random(),
		type: "POST",
		data: data,
		dataType: 'xml',
		timeout: 30000,
		complete:function(){
			container.animate({opacity:1},500).fadeIn("fast");
			$("#comment_wrapper").removeClass("loading");
		},
		success: function( data, status ){
			var xml = $(data);
			var prompt_msg = xml.find('prompt').text();
			var error_no = parseInt( xml.find("error").text() );
			var status_no = parseInt( xml.find("status").text() );
			
			if( typeof(error_no) != 'undefined' ){
				if( prompt_msg ) alert( prompt_msg );
				if( error_no ){
					if( !prompt_msg ) alert("Unknown error occured, try again later.");
				}else if( error_no == 0 ){
					xml.find("inserthtml").children("*").each(function(){
						if( this.tagName == 'script' ){
							$(this).children("*").each(function(){ eval( $(this).text() ); });
						}else{
							if( $("#comment-"+ xml.find("insertid").text() ).length == 0 )
								$("#"+ this.tagName).html( $(this).text() );
						}
					});
					$("#comment_wrapper").animate({height:container.show().height()},200);
					container.hide();
					//container.animate({height:$("#comment_wrapper").get(0).offsetHeight},500);
				}
			}else alert("Error occured while parsing data.");
		},
		error: function(data, status, e){
			if( status == 'timeout' )
				alert( "Server was taking too long to respond.\nThe request may have been submitted but a response wasn't recieved.\nPlease try again later or refresh the page." );
			else if( status && e )
				alert( "["+ e.number +"] "+ e.message +"\n"+ status +"..");
		}
	};
	
	$("#comment_wrapper").animate({opacity:1},200,'linear',function(){
		$(this).addClass("loading")
	}).height( container.height() );
	container.fadeOut("fast")
		.animate({opacity:1},400,null,function(){
			if( ! jQuery.active )
				$.ajax( ajax_data );
			else{
				alert("Another request is being sent, please wait before requesting again.");
				ajax_data.complete();
			}
		});
}

function flag_comment( comment_id, flag ){
	if( !comment_id || !flag ) return false;
	if( typeof(comment_rel_id) == 'undefined' ){
		alert( 'rel id is required, js var: comment_rel_id' );
		return false;
	}
	
	var data = {
		rel_id: comment_rel_id,
		comment_id: comment_id,
		flag: flag > 0 ? 1 : -1,
		flag_comment: '8bcb0afe48970b59a3b1699238751f4c'
	}
	
	var ajax_data = {
		url: "./admin/jcustom_mod/plugins/more-comment/more-comment-ajax.php?nocache="+Math.random(),
		type: "POST",
		data: data,
		dataType: 'xml',
		timeout: 30000,
		complete:function(){},
		success:function( data, status ){
			var xml = $(data);
			var prompt_msg = xml.find('prompt').text();
			var error_no = parseInt( xml.find("error").text() );
			var status_no = parseInt( xml.find("status").text() );

			if( typeof(error_no) != 'undefined' ){
				if( prompt_msg ) alert( prompt_msg );
				if( error_no ){
					if( !prompt_msg ) alert("Unknown error occured, try again later.");
				}else if( error_no == 0 ){
					xml.find("inserthtml").children("*").each(function(){
						if( this.tagName == 'script' ){
							$(this).children("*").each(function(){ eval( $(this).text() ); });
						}else{
							if( $("#comment-"+ xml.find("insertid").text() ).length == 0 )
								$("#"+ this.tagName).html( $(this).text() );
						}
					});
				}
			}else alert("Error occured while parsing data.");
		},
		error: function(data, status, e){
			if( status == 'timeout' )
				alert( "Server was taking too long to respond.\nThe request may have been submitted but a response wasn't recieved.\nPlease try again later or refresh the page." );
			else if( status && e )
				alert( "["+ e.number +"] "+ e.message +"\n"+ status +"..");
		}
	};
	
	if( ! jQuery.active )
		$.ajax( ajax_data );
	else{
		alert("Another request is being sent, please wait before requesting again.");
		ajax_data.complete();
		return false;
	}
	return true;
}