var bIsLoading = false; //to prevent multiple posting in AJAX

// called from onChange or onClick event of the continent dropdown list
function RecordListOnChange(strURL, strData, cboTarget, busyID, lngRefID) 
{
    // url of page that will send xml data back to client browser
    // use the following line if using asp
    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) {
            PopulateRecordList(self.xmlHttpReq.responseXML.documentElement, cboTarget, busyID, lngRefID);
        }
    }
    self.xmlHttpReq.send(null);
}

// called from onChange or onClick event of the continent dropdown list
function RecordListOnChange_New(strURL, strData, cboTarget, busyID, lngRefID) 
{
    // url of page that will send xml data back to client browser
    // use the following line if using asp
    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) {
            PopulateRecordList(self.xmlHttpReq.responseXML.documentElement, cboTarget, busyID, lngRefID);
        }
    }
    self.xmlHttpReq.send(null);
}

// called from onChange or onClick event of the continent dropdown list
function GetImageSource(strURL, strData, busyID, objImg) 
{
    // url of page that will send xml data back to client browser
    // use the following line if using asp
    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) {
			tmp = self.xmlHttpReq.responseText;
			//tmpSrc = Left(tmp,InStr(tmp,"|"));
			//strFrameRefID = Right(tmp,Len(tmp) - Len(tmpSrc) - 1);
			
			objImg.src = tmp;
			//alert(strRefID);
			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;
	
	optionItem = new Option( "Select", "-1",  false, false);
	cboTarget.options[cboTarget.length] = 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
}

