/* -------------------------- */
/*   XMLHTTPRequest Enable    */
/* -------------------------- */
function createObject()
{
 var request_type;
 var browser = navigator.appName;
 if(browser == "Microsoft Internet Explorer")
 {
  request_type = new ActiveXObject("Microsoft.XMLHTTP");
 } else
 {
  request_type = new XMLHttpRequest();
 }
 return request_type;
}

var http = null; createObject();

/* -------------------------- */
/*           doFunc           */
/* -------------------------- */

function doTop(rubid,ontop,ntop)
{
 if (http == null) http =createObject();
 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=top&rubid='+rubid+'&ontop='+ontop+'&ntop='+ntop+'&nocache='+nocache);
 http.onreadystatechange = inTopReply;
 http.send(null);
}

function inTopReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('top').innerHTML = response;
 }
}

function doHots(cval)
{
 if (http == null) http =createObject();

 hotstip=document.getElementById('hotstip').value;
 if (cval!=hotstip) {document.getElementById('hotpage').value=1;}
 hotstip=cval;
 nhotmax=encodeURI(document.getElementById('nhotmax').value);
 hotpage=encodeURI(document.getElementById('hotpage').value);
 document.getElementById('hotstip').value=hotstip;
 document.getElementById('hotscount').innerHTML=hotpage;

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=hots&hotstip='+hotstip+'&nhotmax='+nhotmax+'&hotpage='+hotpage+'&nocache='+nocache);
 http.onreadystatechange = inHotsReply;
 http.send(null);
}

function doHotsTurn(pval)
{
 hotpage=encodeURI(document.getElementById('hotpage').value);
 hotpage=parseInt(hotpage)+pval;
 if (hotpage<1) hotpage=1;
 document.getElementById('hotpage').value=hotpage;
 hotstip=document.getElementById('hotstip').value;
 doHots(hotstip);
}

function inHotsReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('hots').innerHTML = response;
 }
}

function doBlocks(rubid,subid,media,rubon)
{
 if (http == null) http =createObject();
 blockid='block'+rubid;

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=blocks&rubid='+rubid+'&subid='+subid+'&media='+media+'&rubon='+rubon+'&nocache='+nocache);
 http.onreadystatechange = inBlocksReply;
 http.send(null);
}

function inBlocksReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById(blockid).innerHTML = response;
 }
}

function doParts(rubid,subid,media,rubon)
{
 if (http == null) http =createObject();
 partid='part'+rubid;

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=parts&rubid='+rubid+'&subid='+subid+'&media='+media+'&rubon='+rubon+'&nocache='+nocache);
 http.onreadystatechange = inPartsReply;
 http.send(null);
}

function inPartsReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById(partid).innerHTML = response;
 }
}

function doFontSize(nsp)
{
 cursize=document.getElementById('dcont1');
 cursize=parseInt(cursize.style.fontSize.replace("px"));
 newsize=cursize+nsp+'px';
 document.getElementById('dcont1').style.fontSize=newsize;
 document.getElementById('dcont2').style.fontSize=newsize;
}

function doPops(poptip,poptop)
{
 if (http == null) http =createObject();

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=pops&poptip='+poptip+'&poptop='+poptop+'&nocache='+nocache);
 http.onreadystatechange = inPopsReply;
 http.send(null);
}

function inPopsReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('popnews').innerHTML = response;
 }
}

function doContext(notabs,ntabpage,sujetid,subid,nid,tip)
{
 if (http == null) http =createObject();

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=context&notabs='+notabs+'&ntabpage='+ntabpage+'&sujetid='+sujetid+'&subid='+subid+'&nid='+nid+'&tip='+tip+'&nocache='+nocache);
 http.onreadystatechange = inContextReply;
 http.send(null);
}

function inContextReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('contin').innerHTML = response;
 }
}

function doMedia(ntip,rubon,stat,page)
{
 if (http == null) http =createObject();

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=medianews&ntip='+ntip+'&rubon='+rubon+'&stat='+stat+'&page='+page+'&nocache='+nocache);
 http.onreadystatechange = inMediaReply;
 http.send(null);
}

function inMediaReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('medianews').innerHTML = response;
 }
}

function doPerson(swchto,persid)
{
 if (http == null) http =createObject();

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=person&swchto='+swchto+'&persid='+persid+'&nocache='+nocache);
 http.onreadystatechange = inPersonReply;
 http.send(null);
}

function inPersonReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('person').innerHTML = response;
 }
}

function doPloTab(scount)
{
 if (http == null) http =createObject();

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=plotab&scount='+scount+'&nocache='+nocache);
 http.onreadystatechange = inPloTabReply;
 http.send(null);
}

function inPloTabReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('plotab').innerHTML = response;
 }
}

function doCtrlMenu(rubid,nid,contmnu,ctrltab)
{
 if (http == null) http =createObject();

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=ctrlmenu&rubid='+rubid+'&nid='+nid+'&contmnu='+contmnu+'&ctrltab='+ctrltab+'&nocache='+nocache);
 http.onreadystatechange = inCtrlMenuReply;
 http.send(null);
}

function inCtrlMenuReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('ctrlmenu').innerHTML = response;
 }
}

function doCtrlRecs(nid,ctrltab)
{
 if (http == null) http =createObject();

 // Set te random number to add to URL request
 nocache = Math.random();
 http.open('get', global_base_path+'ajaxrout.php?routtip=ctrlrecs&nid='+nid+'&ctrltab='+ctrltab+'&nocache='+nocache);
 http.onreadystatechange = inCtrlRecsReply;
 http.send(null);
}

function inCtrlRecsReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('ctrlrec').innerHTML = response;
 }
}

function DoGolosovat()
{
  var v = getRadioGroupValue(document.OPROS.answerN);
  if(v==0) return false;
  if (http == null) http =createObject();
   nocache = Math.random();
   http.open('get', global_base_path+'ajaxrout.php?routtip=golosovat&golosid='+document.OPROS.GOLOSID.value+'&valu='+v+'&nocache='+nocache);
   http.onreadystatechange = inGolosovatReply;
   http.send(null);
}

function inGolosovatReply()
{
 if(http.readyState == 4)
 {
  var response = http.responseText;
  document.getElementById('dopros').innerHTML = response;
 }
}

function getRadioGroupValue(radioGroupObj)
{
  for (var i=0; i < radioGroupObj.length; i++)
    if (radioGroupObj[i].checked) return radioGroupObj[i].value;

  return 0;
}