//determines if the string is empty
function IsEmpty(mytext) 
{
	var re = /^\s{1,}$/g; //match any white space including space, tab, form-feed, etc.
	var textString = mytext;
	
	if ((textString.length==0) || (textString==null) || ((textString.search(re)) > -1)) 
	{
		return true;
	}
	else 
	{
		return false;
	}
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
	  { 
	  Char = sText.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1) 
		 {
		 IsNumber = false;
		 }
	  }
   return IsNumber;
   
   }
  
  
//impose maxlength attribute of a textarea
function textCounter(field, maxlimit) 
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
	}
}

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}


function AJAXrequest(url, id, params)
{
	var httpRequest;
	//alert(url + '?' + params);
	//if (window.XMLHttpRequest) 
	//{ // Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) 
		{
			httpRequest.overrideMimeType('text/xml');
			// See note below about this line
		}
	//} 
	/*else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) 
			{
				//do nothing
			}
		}
	}*/

	if (!httpRequest) 
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	httpRequest.onreadystatechange = function() { displayRequest(httpRequest, id); };
	httpRequest.open('GET', url + '?' + params, true);
	httpRequest.send(null);

}

function displayRequest(httpRequest, id) 
{
	if (httpRequest.readyState == 4) 
	{
		if (httpRequest.status == 200) 
		{
			document.getElementById(id).align = 'left';
			document.getElementById(id).innerHTML = '';
			document.getElementById(id).innerHTML = httpRequest.responseText;
		} 
		else 
		{
			//alert('There was a problem with the request.');
		}
	}

}