function AjaxRequest(url, data, callback, szDivId)
{
	this.params='';
	this.callback = callback;
	this.pageUrl=url;
	this.div=szDivId;
	
	if (window.XMLHttpRequest) 
	{
		//Opera, Firefox, Safari , IE 7+
	    this.xmlHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		//IE 6-
		var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];

		for (var i = 0; i < versions.length ; i++) 
		{
			try 
			{
				this.xmlHttp = new ActiveXObject(versions[i]);
				if (this.xmlHttp) 
				{
					break;
				}
			}
			catch (objException) 
			{
				// trap; try next one
			};
		}
	}
	var objThis	 = this;
	this.xmlHttp.onreadystatechange = function(){libCallback(objThis);}	
	if(data!=null)
	{
		this.xmlHttp.open("POST", url, 	true);		
	}
	else
	{
		this.xmlHttp.open("GET", url, 	true);
	}
}

AjaxRequest.prototype.setParams=setParamsFunc;
AjaxRequest.prototype.call=sendRequest;

function setParamsFunc(params)
{
	this.params	= params;
}

function sendRequest()
{	
	if (window.XMLHttpRequest) 
	{	
		 this.xmlHttp.setRequestHeader('X-Requested-With','XMLHttpRequest');
 		 this.xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		 this.xmlHttp.send(this.params);
	}
	else
	{
		if(this.params)
		{
			this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			this.xmlHttp.send(this.params);
		}
		else
		{
			this.xmlHttp.send(this.params);
		}
	}
}

function libCallback(obj)
{
	
	if (obj.xmlHttp.readyState == 4) 
	{
	  // Complete
      if (obj.xmlHttp.status == 200) 
      {
		  var transport	=	"obj.xmlHttp";
		  var szDivId="obj.div";
			  var funcName	=	obj.callback + "(" + transport + ","+ szDivId +")";
		  eval(funcName);
      } 
    }
}

function isValidContent(szTestData, szTestElementId, szRegExpPattern)
{
	if(szRegExpPattern == null)
	{
		return false;
	}
	var oElement = document.getElementById(szTestElementId); 
	if (szTestData == null || szTestData.length == 0)
	{
		if(oElement!=null)
		{
			oElement.focus();
		}
		return false;	
	}
	var szValidData = new RegExp(eval(szRegExpPattern));
	if(!szValidData.test(szTestData))
	{
		if(oElement!=null)
		{
			oElement.focus();
		}
		return false;
	}
	return true;
}

Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

var ScriptFragment= '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
Object.extend(String.prototype, {
  stripScripts: function() {
    return this.replace(new RegExp(ScriptFragment, 'img'), '');
  },

  extractScripts: function() {
    var matchAll = new RegExp(ScriptFragment, 'img');
    var matchOne = new RegExp(ScriptFragment, 'im');
    return (this.match(matchAll) || []).map(function(scriptTag) {
      return (scriptTag.match(matchOne) || ['', ''])[1];
    });
  },

  evalScripts: function() {
    return this.extractScripts().collect(eval);
  }
});


var Enumerable = {
  each: function(iterator) {
    var index = 0;
    try {
      this._each(function(value) {
        try {			
          iterator(value, index++);
        } catch (e) {
          throw e;
        }
      });
    } catch (e) {
      throw e;
    }
  },

  collect: function(iterator) {
    var results = [];
    this.each(function(value, index) {
      results.push(iterator(value, index));
    });
    return results;
  }
}

Object.extend(Enumerable, {
  map:     Enumerable.collect
});

Object.extend(Array.prototype, Enumerable);
Object.extend(Array.prototype, {
  _each: function(iterator) {
    for (var i = 0; i < this.length; i++)
      iterator(this[i]);
  }
});

function updateElement(element, html) 
{
    element.innerHTML = html.stripScripts();
    setTimeout(function() {html.evalScripts()}, 10);
}
