function wait_class () {

	var load = 0;

	var div ="";

	this.init = function () {

		div = document.createElement("div");

		div.style.cursor = "wait";

		div.style.width = "100%";

		div.style.height = "100%";

		div.style.position = "fixed";

		div.style.zindex = 50;

		div.style.top = "0px";

		div.style.left = "0px";

		document.body.appendChild(div);

	};

	this.addLoad = function (){

		load++;

		if (load == 1)

		{

			if (div != "")

				div.style.display = "";

		}

	};

	this.kilLoad = function (){

		load--;

		if (load == 0)

		{

			setTimeout (function () {

				if (load == 0)

				{

					if (div != "")

						div.style.display = "none";

				}

			}, 1000);

			

			

		}

	};

}

var wait = new wait_class();



function ajaxcall (url, poststring)

{

	this.get 	= function (ajaxobj)

	{

		if (window.XMLHttpRequest)

			var XHR = new XMLHttpRequest();

		else if (window.ActiveXObject)

			var XHR = new ActiveXObject("Microsoft.XMLHTTP");

		XHR.onreadystatechange = function()

		{

			if (XHR.readyState ==2)

			{

				wait.addLoad();

				ajaxobj.load(XHR);

			}

			if (XHR.readyState ==4)

			{

				wait.kilLoad();

				ajaxobj.onload(XHR);

			}

		};

		XHR.open("GET", url, true);

		XHR.send("");

	};

	this.post 	= function (ajaxobj)

	{

		if (window.XMLHttpRequest)

			var XHR = new XMLHttpRequest();

		else if (window.ActiveXObject)

			var XHR = new ActiveXObject("Microsoft.XMLHTTP");

		XHR.open("POST", url, true);

		XHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 

		XHR.onreadystatechange = function()

		{

			if (XHR.readyState ==2)

			{

				wait.addLoad();

				ajaxobj.load(XHR);

			}

			if (XHR.readyState ==4)

			{

				wait.kilLoad();

				ajaxobj.onload(XHR);

			}

		};

		

		XHR.send(poststring);

	};

	this.toJSON	= function (XHR)

	{

		var json = "json = " + XHR.responseText + ";";

		eval (json);

		return json;

	};

	this.load = function ()

	{ }

	this.onload = function ()

	{ }

	if (poststring == undefined)

		this.get(this);

	else

		this.post(this);

}



function sortArray (array, index, comma) {

    var sortFunction = function (a, b) {

          if (a[index]<b[index]) return -1;

          if (a[index]>b[index]) return 1;

          return 0;

    };

    

    var sortPriceFunction = function (a, b) {

        if (parseFloat(a[index]) < parseFloat(b[index])) return -1;

        if (parseFloat(a[index]) > parseFloat(b[index])) return 1;

        return 0;

    };

    if (comma === undefined ||

    	comma === false)

    	array.sort(sortFunction);

    else

    	array.sort(sortPriceFunction);

    return array;

}


