// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
if(!radioObj)
 return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
 if(radioObj.checked)
 return radioObj.value;
 else
 return "";
for(var i = 0; i < radioLength; i++) {                 
 if(radioObj[i].checked) {                 
 return radioObj[i].value;
 }
}
return "";
}
function updateElement(link, update) {
$.get(link,  function(data){
$("#" + update).html(data);
} );
//    new Ajax(link, { method: 'get',
//       update: $(update),
//      evalScripts: true }).request();
    return false;
}
function updatePollElementWithPost(formId, update, action) {
var form  = document.getElementById(formId);
$.ajax({   type: "POST",   url: action,  
data: "choice=" + getCheckedValue(form.elements['choice']) + "&postMode=ajax",  
success: function(data){    
$("#" + update).html(data);
} });
//var args = { method: 'post', update: $(updateId), evalScripts: true };
//    $(formId).send(args);
return false;
}
/*
function onPostCommentComplete() {
alert("onPostCommentComplete");
  window.fireEvent("comment-submitted");
}
function disposeCommentForm() {
alert("disposeCommentForm");
  if ($('commentEditor') != null) {
    var editor = tinyMCE.selectedInstance;
    if (editor) {  // fixes reload bug
    alert("mceRemoveControl");
      tinyMCE.execCommand('mceRemoveControl', false, 'commentEditor');
    }
  }
}
function postComment(id,targetId) {
//  var editor = tinyMCE.selectedInstance;
tinyMCE.execCommand('mceRemoveControl', true, 'textEditor_' + targetId);
// tinyMCE.execCommand('mceTriggerSave', true, 'textEditor');
//  editor.triggerSave();
//  tinyMCE.execInstanceCommand(editor,'mceCleanup');
 
  var args = {
    method: 'post',
    update: $("commentsArea_" + targetId),
    onComplete: function() { onPostCommentComplete(); },
    onFailure: function() { alert("Failed submitting comment!"); },
    evalScripts: true
  };
$("commentForm_" + id).id.value = targetId;
$("commentForm_" + id).send(args);
  return false;
}
*/
// - TinyMCE ------------------------------------------------------------------
//
// Have adopted the standard textEditor_id as textarea identifier. This means we only need
// to pass  the id. This is so we can set the richText flag in the form, to preserve the stat in
// a submit request
function toggleEditor(id) {
    $("richText_" + id).value=!tinyMCE.getInstanceById("textEditor_" + id);
    id="textEditor_" + id;
    if (!tinyMCE.getInstanceById(id))
        tinyMCE.execCommand('mceAddControl', false, id);
    else
        tinyMCE.execCommand('mceRemoveControl', false, id);
}
// Alternative version which also toggles the message in the toggle button
function toggleEditorAndButton(button,id,onText,offText) {
    var datalen = button.firstChild.nodeValue.length;
    $("richText_" + id).value=!tinyMCE.getInstanceById("textEditor_" + id);
    id="textEditor_" + id;
    if (!tinyMCE.getInstanceById(id)) {
        tinyMCE.execCommand('mceAddControl', false, id);
        button.firstChild.deleteData(0,datalen);
        button.firstChild.insertData(0,onText);
    }
    else {
        tinyMCE.execCommand('mceRemoveControl', false, id);
        button.firstChild.deleteData(0,datalen);
        button.firstChild.insertData(0,offText);
    }
    return false;
}
function submitFormWithTinyMCE(type, id) {
    var form = type + "_"+id+"_form";
    var update = type + "_" +id;
    var form = document.getElementById(form);
    var action = form.getAttribute('action');
    var inputs = new Object;
    $(':input', form).each(function() {     
         inputs[this.name] = this.value;                         
 });
   
    $.ajax({   type: "POST",   url: action,  
    data: inputs,  
    success: function(data){        
    $("#" + update).html(data);
    } });
    //if (!tinyMCE.getInstanceById("textEditor_" + id));
    //else tinyMCE.execCommand('mceRemoveControl', false, "textEditor_" + id);
    //var args = { method: 'post', update: update, evalScripts: true };
    //form.send(args);
    return false;
}
function showCommentForm(link, update) {
//    var current = $('current_comment_form');   
//    if (current!=null) {
//      id = current.getParent().id.replace("commentForm_","");
//    if (!tinyMCE.getInstanceById("textEditor_" + id));
//    else tinyMCE.execCommand('mceRemoveControl', false, "textEditor_" + id);;
//     //new Ajax(current.href, { method: 'get',
     //   update: current.getParent(),
     //   evalScripts: true }).request();
//     alert(current);
        //$.get(current.href,  function(data){
        //    $("#" + current.getParent()).html(data);
        //} );
//    }
    $.get(link,  function(data){
        $("#" + update).html(data);
    } );
    //new Ajax(link, { method: 'get',
     //   update: $(update),
     //   evalScripts: true }).request();
    return false;
}
function hideCommentForm(link, id) {
    if (!tinyMCE.getInstanceById("textEditor_" + id));
    else tinyMCE.execCommand('mceRemoveControl', false, "textEditor_" + id);;
    new Ajax(link, { method: 'get',
        update: $("commentForm_" + id),
        evalScripts: true }).request();
    return false;
}
function updateCommentsBlock(link, update) {
    new Ajax(link, { method: 'get',
        update: $(update),
        evalScripts: true }).request();
    return false;
}
function showloginform(e) {
 var overlay = $("#overlay");
 var w = $(window).width();
 var h = $(window).height();
 overlay.css('width', w);
 overlay.css('height', h);
 overlay.css('display','block');
 $("#login_result").html('').removeClass();
 $("#login_box").css('display','block');
e.preventDefault();
}