/*
AJAX CLASS v2.01 /w Time out
Writen by: Phillip (OnSite Computer Services)
Email: phil@osComputerServices.ca
Use this to learn, don't jack my code sucka
*/

function AJAXClass() { }
AJAXClass.prototype.xmlhttp = false;
AJAXClass.prototype.httpCheckString = '';
AJAXClass.prototype.httpReturnData = '';
AJAXClass.prototype.httpReturnFunction = '';
AJAXClass.prototype.httpReturnErrorFunction = '';
AJAXClass.prototype.httpTimeOut = 2;
AJAXClass.prototype.httpRetry = 3;
AJAXClass.prototype.httpRetryVar = 0;
AJAXClass.prototype.Timerid;
AJAXClass.prototype._varRequestType;
AJAXClass.prototype._varRequestUrl;
AJAXClass.prototype._varRequestData;
AJAXClass.prototype.handleError = function() {
    this.Timerid = clearTimeout(this.Timerid);
    this.httpRetryVar++;
    if(this.httpRetryVar > this.httpRetry) {
        delete this.xmlhttp;
        if (this.httpReturnErrorFunction == '') { alert('AJAXClass failed on request for data'); }
        else { eval(this.httpReturnErrorFunction) } }
    else { this.DoGetRemoteData(this._varRequestType,this._varRequestUrl,this._varRequestData); } }
AJAXClass.prototype.createRequestObject = function() {
	var xmlhttp;
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHttp"); }
	catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHttp"); }
		catch(e2){ } }
	if(xmlhttp == undefined && (typeof XMLHttpRequest != 'undefined')) { xmlhttp = new XMLHttpRequest(); }
	return xmlhttp; }
AJAXClass.prototype.GetRemoteData = function(urlRequestType,urlObj,urlPostData) {
	var _this = this;
    this._varRequestType = urlRequestType;
    this._varRequestUrl = urlObj;
    this._varRequestData = urlPostData;
    this.httpRetryVar = 0;
    this.DoGetRemoteData(this._varRequestType,this._varRequestUrl,this._varRequestData); }
AJAXClass.prototype.DoGetRemoteData = function(urlRequestType,urlObj,urlPostData) {
    this.Timerid = clearTimeout(this.Timerid);
    this.Timerid = setTimeout(function(){_this.handleError();},this.httpTimeOut);
    var _this = this;
	if (this.xmlhttp == false) { this.xmlhttp = this.createRequestObject(); }
	this.httpReturnData = '';
	if (urlRequestType == 'post') {
    	this.xmlhttp.open('post',urlObj);
    	this.xmlhttp.onreadystatechange = function(){_this.handleResponse()};
		this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.xmlhttp.send(urlPostData); }
	else {
	    this.xmlhttp.open('get', urlObj);
    	this.xmlhttp.onreadystatechange = function(){_this.handleResponse()};
	    this.xmlhttp.send(null); } }
AJAXClass.prototype.handleResponse = function() {
if(this.xmlhttp.readyState == 4) {
	var response = this.xmlhttp.responseText;
    if(response.indexOf(this.httpCheckString) != -1) {
        this.Timerid = clearTimeout(this.Timerid);
		delete this.xmlhttp;
		this.httpReturnData = response;
		eval(this.httpReturnFunction);  } } }
//Other Misc useful functions
var nPosY;
var nPosX;
function ShowElement(ObjElm,PosX,PosY) {
	if (PosY != '' && PosX != '') { ObjElm.style.top = PosY; ObjElm.style.left = PosX; }
	ObjElm.style.display = 'block';
	ObjElm.style.visibility = 'visible'; }
function HideElement(ObjElm) {
	ObjElm.style.display = 'none';
	ObjElm.style.visibility = 'hidden'; }
function findPosition( oLink ) {
	if( oLink.offsetParent ) {
	    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
		    posX += oLink.offsetLeft;
	      	posY += oLink.offsetTop; }
		nPosY = posY;
		nPosX = posX;
  } else {
	nPosY = oLink.y;
	nPosX = oLink.x;  } }
function isEmpty(str) {
    if ((str == null) || (str.length == 0)) { return true; }
    else { return false; } 	}
function isEmail(str) {
	if ((str == null) || (str.length == 0) || (str.indexOf("@")) == -1 || (str.indexOf(".")) == -1) { return true; }
    else { return false; } }


