var locationHash = "";
var target="";
var domain = "http://" + location.host + "/";
var isIE=false;
var typeid="";

ajaxRequest = function(u,f, m, b, h, s)
{
  this.url      = u;
  this.wState   = f || function() { };
  this.method   = m || "GET";
  this.body     = b || null;
  this.headers  = h || false;
  this.sync     = s || true;
  this.abortReq = false;
  this.http = (window.XMLHttpRequest) ? new XMLHttpRequest() : ((window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : false);

  this.doRequest = function()
  {
  	this.http.open(this.method,this.url,this.sync);
    if (this.headers)
    {
      for (var i=0; i<this.headers.length; i+=2)
      {
        this.http.setRequestHeader(this.headers[i],this.headers[i+1]);
      }
    }
    this.http.onreadystatechange = this.wState;
    (!this.abortReq) ? this.http.send(this.body) : this.http.abort();
  }
}

var AjaxCall = function(url)
{
	BrowserHistory(url); 
  if(target)
  { 
		var xmlhttp = new ajaxRequest(domain + locationHash, 
	  															function()
														      {
														        var handle = xmlhttp.http;
														        if (handle.readyState==4) 
														        { 
														        	document.getElementById(target).innerHTML = handle.responseText; 
														        }
														      }
	  );
	  xmlhttp.doRequest();
  }
}

var BrowserHistory = function(url)
{
	locationHash = url.replace(domain, "");
  location.hash = locationHash;
  target = locationHash.substring(locationHash.search(/ajaxid=/)+7, locationHash.length)
  target = target.substring(0, (target.search(/&/)>0) ? target.search(/&/) : target.length)	
  typeid = locationHash.substring(0, locationHash.search("/"));
  if (isIE) 
  {
  	ieFrame.src = "blank.html?"+ locationHash;
  	ieFrame.location.href = ieFrame.src;
  }
}


var checkUrl = function()
{
	if (isIE) { loc = (locationHash!="") ? ieFrame.location.search.substring(1, ieFrame.location.search.length) : "";  }
  else { loc = location.hash.substring(1, location.hash.length); }
  if (loc != locationHash) AjaxCall(loc);
  setTimeout("checkUrl()", 500); 
}

window.onload = function()
{
	var ie = navigator.userAgent.toLowerCase();
	isIE = (ie.indexOf("msie")>-1) ? true : false;  
	checkUrl();
}
