var xmlHttpReq;
var t;
var tid;
var time = 30;

if(typeof XMLHttpRequest != 'undefined') 
{
  try 
  {
    xmlHttpReq = new XMLHttpRequest();
  } 
  catch(e) 
  {
	  try {
	    xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (e) {
	  try {
	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	    xmlHttpReq = false;
	  }
	 }
  }
}
else
{
  try {
	  xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	  xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	  xmlHttpReq = false;
	}
  }
}

function tick()
{
  t = parseInt(document.getElementById('tick').innerHTML);
  if(t - 1 < 0)
  {
    reloadWhoIs();
  }
  else
  {
    document.getElementById('tick').innerHTML = t - 1;
    tid = setTimeout(tick, 1000);
  }
}

function reloadWhoIs()
{
  document.getElementById('main_who').innerHTML = sendRequest("POST", "http://www.tutorialy.com/ajax.php", "sender=sendRequest&type=reloadwhois");
  document.getElementById('tick').innerHTML = time;
  clearTimeout(tid);
  tid = setTimeout("tick()", 1000);
}

function addMessage(text, tut_id)
{
  document.getElementById('comment_form').style.display = "none";
  document.getElementById('comments_count').innerHTML = parseInt(document.getElementById('comments_count').innerHTML) + 1;
  document.getElementById('comments_js').innerHTML = sendRequest("POST", "http://www.tutorialy.com/ajax.php", "sender=sendRequest&type=addmessage&text=" + text + "&tut_id=" + tut_id);
}

function sendRequest(getOrPost, page, params)
{
  var strResult;
  if(getOrPost.toUpperCase() == "POST")
  {
    xmlHttpReq.open("POST", page, false);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.send(params);
  }
  else
  {
    xmlHttpReq.open("GET", page + "?" + params, false);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.send(null);
  }
  strResult = xmlHttpReq.responseText;
  return strResult;
}