var ajaxReq;   //The request object to send and receive AJAX request
var htmlIncludeArea;//The <span tag where the dynamic html will be embedded
var toggleDisplayArea; //The area id where the dynamic data will be displayed(We cannot hide a span in a <tr tag)
var isContentReturned=false; //Whether the url returned any data
var ajaxAnimArea;
var ajaxAniFn=false; //ONCE UPGRADED TO HAVE THIS ANIMATION FUNCTION REMOVE THIS VARIABLE
//UPGRADE all AJAX FUNCTION WITH THIS FUNCTION
function retrieveAjaxBlock(url,htmlIncludeSection,toggleDisplaySection,ajaxAnimSection) {
  ajaxAniFn=true
  htmlIncludeArea=htmlIncludeSection
  ajaxAnimArea=ajaxAnimSection
  toggleDisplayArea=toggleDisplaySection
  isContentReturned=true
  document.getElementById(ajaxAnimArea).style.display="inline"

  if (window.XMLHttpRequest) { // Non-IE browsers
    ajaxReq = new XMLHttpRequest();
    ajaxReq.onreadystatechange = ajaxProcessChanged;
    try {
      ajaxReq.open("POST", url, true);
    } catch (e) {
      alert(e);
    }
    ajaxReq.send(null);
  }
  else if (window.ActiveXObject) { // IE
      ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
      if (ajaxReq) {
        ajaxReq.onreadystatechange = ajaxProcessChanged;
        ajaxReq.open("POST", url, true);
        ajaxReq.send();
      }
    }
}

function retrieveAjaxUrl(url,htmlIncludeArea,toggleDisplayArea) {
  ajaxAniFn=false
  htmlIncludeArea=htmlIncludeArea
  toggleDisplayArea=toggleDisplayArea
  isContentReturned=true
  if (window.XMLHttpRequest) { // Non-IE browsers
    ajaxReq = new XMLHttpRequest();
    ajaxReq.onreadystatechange = ajaxProcessChanged;
    try {
      ajaxReq.open("POST", url, true);
    } catch (e) {
      alert(e);
    }
    ajaxReq.send(null);
  }
  else if (window.ActiveXObject) { // IE
      ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
      if (ajaxReq) {
        ajaxReq.onreadystatechange = ajaxProcessChanged;
        ajaxReq.open("POST", url, true);
        ajaxReq.send();
      }
    }
}

function ajaxProcessChanged() {
  if (ajaxReq.readyState == 4) { // Complete
    if (ajaxReq.status == 200) { // OK response
      content=ajaxReq.responseText;
      if(ajaxAniFn) {
        document.getElementById(ajaxAnimArea).style.display="none"
      }
      if(content.length==0) {
        isContentReturned=false
      }
      document.getElementById(htmlIncludeArea).innerHTML = content;
      if(isContentReturned){
        document.getElementById(toggleDisplayArea).style.display="inline"
      }
      else {
        document.getElementById(toggleDisplayArea).style.display="none"
      }
    } else {
        alert("Problem: " + ajaxReq.statusText);
    }
  }
}
function fadeImage(cur,which){
  if (which==0)
    cur.filters.alpha.opacity=90
  else
    cur.filters.alpha.opacity=100
}

// This function to check if the field is empty
// input parameter is the object of the field
function isEmpty(aThis) {
    	str=aThis.value
    	for (var intLoop = 0; intLoop < str.length; intLoop++)  	{
		if (" " != str.charAt(intLoop)) 		{
			return false;
		}
	}
	return true;
}
// This function to trim any field value
// input parameter is the object of the field which requered to be trim
function txtTrim(e) {
	var trimvalue = e.value
	//Right trim
	while(''+trimvalue.charAt(trimvalue.length-1)==' ')
		trimvalue=trimvalue.substring(0,trimvalue.length-1)
	//Left trim
	var2=trimvalue.substr(0,1)
	stlen=0
	while(var2==" ")  	{
            stlen=stlen+1
	    var2=trimvalue.substr(stlen,1)
	}
	var2=trimvalue.substr(stlen)
	e.value = var2
        return e.value
}

function isNumber(val){
  var  result = val.match(/^-?\d+(\.\d+)?$/);
  return (result != null);
}
