var bIsLoading = false; //to prevent multiple posting in AJAX

// called from onChange or onClick event of the continent dropdown list
function PopulateRecordOnDiv(strURL, strData, objTarget, busyID, lngRefID) 
{
    // url of page that will send xml data back to client browser
    // use the following line if using asp
    document.getElementById(objTarget).innerHTML = "";
    show(busyID);
    var requestUrl = strURL + "?" + strData; 
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', requestUrl, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
         	//alert(requestUrl);
            strText = self.xmlHttpReq.responseText;
            strText  = replaceAll( strText  , [["<PRE>", ""], [ "</PRE>", ""]]  );
			strText  = replaceAll( strText  , [["<pre>", ""], [ "</pre>", ""]]  ); 
			
            if(navigator.userAgent.indexOf("MSIE")!=-1)
				document.getElementById(objTarget).innerText = strText;
			else
			{		
				document.getElementById(objTarget).innerHTML = "<pre width='30'>" + strText + "</pre>";
			}
		
            hide(busyID);
        }
    }
    self.xmlHttpReq.send(null);
}


// populate the contents of the target dropdown list
function PopulateRecordList(recordNode, cboTarget, busyID, lngRefID)
{
	// clear the target list 
	for (var count = cboTarget.options.length-1; count >-1; count--)
	{
		cboTarget.options[count] = null;
	}
	
	var recordNodes = recordNode.getElementsByTagName('record');
	var idValue, bTempIsSelected;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < recordNodes.length; count++)
	{
   		textValue = GetInnerText(recordNodes[count]);
		idValue = recordNodes[count].getAttribute("id");
		if (idValue == lngRefID)
			bTempIsSelected = true;
		else
			bTempIsSelected = false;
		optionItem = new Option( textValue, idValue,  false, bTempIsSelected);
		cboTarget.options[cboTarget.length] = optionItem;
		
	}
	hide(busyID);
}

// returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}

function hide(divId)
{
	var id = document.getElementById(divId);
	id.style.display = 'none';
	var btnObjects, btnObject;
	btnObjects = window.document.getElementsByTagName("input")
	for(i=0; i<= btnObjects.length - 1 ; i++)
	{
		btnObject = window.document.getElementsByTagName("input")[i];
		if(btnObject.type == "submit")
		{
			btnObject.disabled=false;
		}
	}
	bIsLoading = false; //for the main window
}

function show(divId)
{
	var id = document.getElementById(divId);
	id.style.display = 'inline';
	var btnObjects, btnObject;
	btnObjects = window.document.getElementsByTagName("input")
	for(i=0; i<= btnObjects.length - 1 ; i++)
	{
		btnObject = window.document.getElementsByTagName("input")[i];
		if(btnObject.type == "submit")
		{
			btnObject.disabled=true;
		}
	}
	bIsLoading = true; //for the main window
}
