
AIM = {

	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}


function startCallback() {
      // make something useful before submit (onStart)
	  document.getElementById('preajax').style.display='none';
	  document.getElementById('postajax').style.display='block';
      return true;
}

function completeCallback(response) {
  p=response.split("@@@");
  goAJAX(p[0],p[1],p[2]);
}


function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function goAJAX(p, f, u)
 {
     xmlHttp1=GetXmlHttpObject()
     if (xmlHttp1==null)
        {  alert ("Your browser does not support AJAX!");  return;  } 
     var url=p+f+".php";
     url=url+"?"+u;
     url=url+"&sid="+Math.random();
     xmlHttp1.onreadystatechange=cResp;
     xmlHttp1.open("GET",url,true);
     xmlHttp1.send(null);
	 return false;
 }
 
function cResp()
 {
  if (xmlHttp1.readyState==4)
   {
     s=xmlHttp1.responseText;
	 var p=s.split("@@@");
	 if(p[0].length>20) alert(s);
	 document.getElementById(p[0]).innerHTML=p[1];
   }
 }
