var comment_widget = '/cgi-bin/infxwidgets/widget-comment.pl';

function comment_control(json){
	var submit = 1;
	if(json.validate){
		for(var p in json.validate){
			//alert("name: "+p+" json: "+json.validate[p]);
			var result = validate_single_field(rtnEl(p),json.validate);
			submit = (submit == 0)?submit:result;
		}
		delete json.validate;
	}
	if(submit){ 
		if(json.send_fields){
			for(var p in json.send_fields){
				if(rtnEl(json.send_fields[p])){
					json[p] = rtnEl(json.send_fields[p]).value;
					rtnEl(json.send_fields[p]).value = '';
				}
			}
			delete json.send_fields;
		}
		ajax_post_request(comment_widget,json,"comment_callback('comment-block-"+json.idx+"',http_request.responseText);");
	}
}

function comment_callback(target,jsonstr){
	var json;
	eval("json = "+jsonstr+";");
	
	var targetObj = rtnEl(target);
	if(json.success == 1){
		var message = rtnEl(json.idx+'_message');
		if(message){
			message.innerHTML = json.message_text;
			message.style.display = 'block';
		}
		targetObj.innerHTML += unescape(json.last_comment);
	}
	
}