var xhr=false;

function get_connection()
{
	var xhr=false;	
	 if (window.XMLHttpRequest)
	 {
        xhr = new XMLHttpRequest();
     }
     else 
	 {
        if (window.ActiveXObject) 
		{
           try 
		   {
              xhr = new ActiveXObject ("Microsoft.XMLHTTP");
			}
              catch (e) { }
        }
     }
	 return (xhr);
}
function search_topic(form)
{
	//alert ("contact called");
	xhr=get_connection();
	document.getElementById("mydiv").innerHTML="<center><img src='./img/loading.gif' style='margin-top:20px;'><br><span style='font-size:24px; color:#666666;'>Loading...</span></center>";

	 if (xhr) 
	 {
        xhr.onreadystatechange = setContent;
        xhr.open("GET", "search.php?u1="+form.search.value+"&u2="+form.catid.value, true);
        xhr.send(null);
     }
     else {
        alert("Sorry, but I couldn't create an XMLHttpRequest");
     }
		return false;
}
function topic_author(x,y)
{
	//alert ("contact called");
	xhr=get_connection();
	document.getElementById("mydiv").innerHTML="<center><img src='./img/loading.gif' style='margin-top:20px;'><br><span style='font-size:24px; color:#666666;'>Loading...</span></center>";

	 if (xhr) 
	 {
        xhr.onreadystatechange = setContent;
        xhr.open("GET", "auth_topic.php?u1="+x+"&u2="+y, true);
        xhr.send(null);
     }
     else {
        alert("Sorry, but I couldn't create an XMLHttpRequest");
     }
		return false;
}
function topic_normal(x)
{
	//alert ("contact called");
	xhr=get_connection();
	document.getElementById("mydiv").innerHTML="<center><img src='./img/loading.gif' style='margin-top:20px;'><br><span style='font-size:24px; color:#666666;'>Loading...</span></center>";

	 if (xhr) 
	 {
        xhr.onreadystatechange = setContent;
        xhr.open("GET", "norm_topic.php?u1="+x, true);
        xhr.send(null);
     }
     else {
        alert("Sorry, but I couldn't create an XMLHttpRequest");
     }
		return false;
}
function topic_hot(x)
{
	//alert ("contact called");
	xhr=get_connection();
	document.getElementById("mydiv").innerHTML="<center><img src='./img/loading.gif' style='margin-top:20px;'><br><span style='font-size:24px; color:#666666;'>Loading...</span></center>";

	 if (xhr) 
	 {
        xhr.onreadystatechange = setContent;
        xhr.open("GET", "hot_topic.php?u1="+x, true);
        xhr.send(null);
     }
     else {
        alert("Sorry, but I couldn't create an XMLHttpRequest");
     }
		return false;
}
function topic_vhot(x)
{
	//alert ("contact called");
	xhr=get_connection();
	document.getElementById("mydiv").innerHTML="<center><img src='./img/loading.gif' style='margin-top:20px;'><br><span style='font-size:24px; color:#666666;'>Loading...</span></center>";

	 if (xhr) 
	 {
        xhr.onreadystatechange = setContent;
        xhr.open("GET", "vhot_topic.php?u1="+x, true);
        xhr.send(null);
     }
     else {
        alert("Sorry, but I couldn't create an XMLHttpRequest");
     }
		return false;
}

function next_topic(x,y)
{
	//alert ("contact called");
	xhr=get_connection();
	document.getElementById("mydiv").innerHTML="<center><img src='./img/loading.gif' style='margin-top:20px;'><br><span style='font-size:24px; color:#666666;'>Loading...</span></center>";

	 if (xhr) 
	 {
        xhr.onreadystatechange = setContent;
        xhr.open("GET", "next_topic.php?u1="+x+"&u2="+y, true);
        xhr.send(null);
     }
     else {
        alert("Sorry, but I couldn't create an XMLHttpRequest");
     }
		return false;
}



function setContent() 
{
     if (xhr.readyState == 4) 
	 {
 			     document.getElementById("mydiv"). innerHTML = "";
			     document.getElementById("mydiv"). innerHTML =  xhr.responseText;
     }
}

function queryString(parameter) 
{ 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;

  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return false; //Here determine return if no parameter is found
  }
}


