var currentAjax;
function ajax(sUrl, sOutPutDiv, sWaitImage, sStartFunc, sEndFunc, bReplaceContent)
{
this.StartFunction = sStartFunc;
this.EndFunction = sEndFunc;
this.Url = sUrl;
this.DivElement = String(sOutPutDiv); 
this.WaitImage = sWaitImage;
this.HTTPobject =  this.getHTTPObject();
this.isWorking = false;
this.WaitID = 'wait_'+ this.DivElement + String(Math.floor(Math.random()*9999999));
this.responseHTML = '';
this.replaceContent = bReplaceContent;
}

ajax.prototype.getValues = function()
{
if (this.StartFunction !='')
    {
    eval(this.StartFunction);
    }

    document.getElementById(this.DivElement).innerHTML = document.getElementById(this.DivElement).innerHTML + '<div id="' + this.WaitID + '" style="top:0px;padding-top:5px;display:inline;z-index:1000; left:0px; background-color:transparent;position:absolute;width:100%;height:100%;text-align:center;"><img style=""  src="/ajax/images/' + this.WaitImage + '.gif"></div>'
    if (!this.isWorking && this.HTTPobject)
            {
			this.HTTPobject.open("GET", this.Url, true);
			var that = this;
            this.HTTPobject.onreadystatechange = function(){that.handleHttpResponse()};
 			this.HTTPobject.send(null);
			this.isWorking  = true;
			}
}

ajax.prototype.handleHttpResponse = function()
{ 
    if (this.HTTPobject.readyState == 4) 
    { 
    //alert(this.HTTPobject.responseText);
    //var xmlDocument = this.HTTPobject.responseXML;
    try
    {
        document.getElementById(this.WaitID).innerHTML = '';
    }
    catch(err)
    {
        //Handle errors here
    }
   
    this.responseHTML = this.HTTPobject.responseText;
    this.removeTags();

    if (this.replaceContent)
    {
        document.getElementById(this.DivElement).innerHTML = this.responseHTML;   
    }
    else
    {
        document.getElementById(this.DivElement).innerHTML = document.getElementById(this.DivElement).innerHTML +  this.responseHTML;
    }
	
	this.isWorking  = false;
	
	    if (this.EndFunction !='')
        {
        eval(this.EndFunction);
        }
	}	
}


ajax.prototype.getHTTPObject = function () 
        {
			var xmlhttp;
			/*@cc_on
			@if (@_jscript_version >= 5)
				try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) {
					xmlhttp = false;
				}
				}
			@else
			xmlhttp = false;
			@end @*/
			if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
				try {
				xmlhttp = new XMLHttpRequest();
				} catch (e) {
				xmlhttp = false;
				}
			}
			return xmlhttp;
		}
			
			
ajax.prototype.removeTags = function()
{
this.responseHTML  =  this.responseHTML.replace(/\<\s*form[^\>]*[\s ]*\>/,'');
this.responseHTML  =  this.responseHTML.replace(/\<\s*\/s*form[^\>]*[\s ]*\>/,'');
this.responseHTML  =  this.responseHTML.replace(/\<\s*input[^\>]*[\s ]*\>/,'');
var contentBegin, contentEnd
contentBegin = this.responseHTML.indexOf("<!--AJAXB-->") +12;
contentEnd = this.responseHTML.indexOf("<!--AJAXE-->");

this.responseHTML = this.responseHTML.substring(contentBegin, contentEnd);
//alert(this.responseHTML);
//document.writeln(this.responseHTML);
}
