function ajax_fetch_multi(output, path, return_path,  message )
{
  //document.getElementById('refreshed').value=new Date().getTime();
  var url   = 'http://www.linuxforums.org/common/control.php';
  var params = 'dummy=' + new Date().getTime()+'&'+path;
  if(output){output = document.getElementById(output);}
  if(return_path){return_path = return_path;}
  var xmlHttp=false;
  try {xmlHttp=new XMLHttpRequest();} // Firefox, Opera 8.0+, Safari  
  catch (e)// Internet Explorer  
  {
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e)
    {    
    try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
    catch (e){ alert("Your browser does not support AJAX!"); return false;}
    }
  }
  xmlHttp.open("POST", url, true); 
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); 
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.onreadystatechange=function()
  {
  if(xmlHttp.readyState==4)
    {
      output.innerHTML = xmlHttp.responseText;
      if(message){alert(message);}
    }
  }
  xmlHttp.send(params);
  if(return_path &&  return_path!='EVAL')
  {
  ajax_fetch_multi('container', return_path)
  }
}
function trim(inputString) 
{
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);}
   ch = retValue.substring(retValue.length - 1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length - 1);
      ch = retValue.substring(retValue.length - 1, retValue.length);}
  // Note that there are two spaces in the string - look for multiple spaces within the string
   while (retValue.indexOf("  ") != -1) {
    // Again, there are two spaces in each of the strings
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length); }
   return retValue;
}

function submit_comment(ID,PID)
{
  // VALIDATE INPUT
  var art_ID=document.getElementById('art_ID').value;
  var error='';
  switch(PID)
  {
  case 'parent': // NEW COMMENT
  PID=0;
  var $all='ALL';
  var div='comments';
  var title  =document.getElementById('com_title').value;
  var text  =document.getElementById('com_text').value;
  break;
  default: // REPLY TO COMMENT
  var $all=PID;
  var div=PID;
  var title  =document.getElementById(ID+'_reply').innerHTML;
  var text  =document.getElementById(ID+'_comment_text').value;
  break;
  }
  title=trim(title);
  text=trim(text);
  if(!title){error+='Missing title';}
  if(!text){error+='\nMissing comments';}
  if(error!=''){alert(error);}
  else{  var string='fn=submit_comment&art_ID='+art_ID+'&all='+$all+'&PID='+PID+'&title='+title+'&text='+text;
  ajax_fetch_multi(div,string);
  }  
}

function check_selected(data)
{
  var inputs = new Array();
  for (i = 0; i < inputs.length; i++)
  {
    if (!inputs[i].length){  if (inputs[i].type == 'radio'){inputs[inputs.length] = inputs[i];}  } 
    else { for(k = 0; k < inputs[i].length; k++) { if (inputs[i][k].type == 'radio'){inputs[inputs.length] = inputs[i];}  }  }
  }
return inputs;
}

function radio_val(btn) 
{
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) { if (btn[i].checked) {cnt = i; i = -1;} }
    if (cnt > -1){ return btn[cnt].value;} else {return null;}
}

function vote(art_ID)
{
  var vote=radio_val(document.forms['rate_form'].rate);
  if(vote==null){alert('SELECT RADIO BUTTON');}
  else
  {
  var string='fn=vote&art_ID='+art_ID+'&vote='+vote+'&action=SUBMIT';  
  var div='box-rate';
  ajax_fetch_multi(div,string);
  }
}
maxL=200;
var bName = navigator.appName;
function taLimit(taObj) {
  if (taObj.value.length==maxL) return false;
  return true;
}
function taCount(taObj,Cnt) { 
  objCnt=createObject(Cnt);
  objVal=taObj.value;
  if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
  if (objCnt) {
    if(bName == "Netscape"){  
      objCnt.textContent=maxL-objVal.length;}
    else{objCnt.innerText=maxL-objVal.length;}
  }
  return true;
}
function createObject(objId) {
  if (document.getElementById) return document.getElementById(objId);
  else if (document.layers) return eval("document." + objId);
  else if (document.all) return eval("document.all." + objId);
  else return eval("document." + objId);
}
function bookmarkthis(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
function fbs_click()
{
  u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}


