
// declare a global  XMLHTTP Request object
var XmlHttpObj;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpObj = new XMLHttpRequest();
	}
}

// called from onChange or onClick event of the continent dropdown list
function SectionListOnChange(fac) 
{
    //var SectionList = document.getElementById("SectionList");
    
    // get selected continent from dropdown list
    //var selectedSection = SectionList.options[SectionList.selectedIndex].value;
	var selectedSection = fac;
    //alert (selectedSection);
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
    //requestUrl = "/ajax/xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedSection);
	requestUrl = "/Directory/ajax_Dp_GetApprovedTimes.asp" + "?fac=" + encodeURIComponent(selectedSection);
	//alert ('45: ' + requestUrl);
    // use the following line if using php
    // requestUrl = "xml_data_provider.php" + "?filter=" + encodeURIComponent(selectedContinent);
    
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}


function SectionListOnChange2() 
{
    var SectionList = document.getElementById("SectionList");
    
    // get selected continent from dropdown list
    var selectedSection = SectionList.options[SectionList.selectedIndex].value;
    //alert (selectedSection);
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
    requestUrl = "/ajax/xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedSection);
	
    // use the following line if using php
    // requestUrl = "xml_data_provider.php" + "?filter=" + encodeURIComponent(selectedContinent);
    //var thelist;
	 //thelist = form1.SiteSectionID.value;
	 //alert(thelist);
	 var varSectionList = document.getElementById("SectionList");
    
    // get selected continent from dropdown list
    var varselectedSection = SectionList.options[varSectionList.selectedIndex].value;
	 //var thevar = form1.SectionList.options[SectionList.selectedIndex].value;
	 //alert(varselectedSection);
	 document.form1.SiteSectionID.value = varselectedSection;
	
	
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = StateChangeHandler2;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}



// this function called when state of  XmlHttpObj changes
// we're interested in the state that indicates data has been
// received from the server
function StateChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			PopulateSubSectionList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// received from the server
function StateChangeHandler2()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			PopulateSubSectionList2(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// populate the contents of the country dropdown list
function PopulateSubSectionList(SubSectionNode)
{
    alert ('SubSectionNode: ' + SubSectionNode);
	var SubSectionList = document.getElementById("SubSectionList");
	// clear the country list 
	//for (var count = SubSectionList.options.length-1; count >-1; count--)
	//{
	//	SubSectionList.options[count] = null;
	//}

	var SubSectionNodes = SubSectionNode.getElementsByTagName('STypes');
	
	//var SubSectionNodes = SubSectionNode.getElementsByTagName('SubSection');
	//var SubSectionNodes = SubSectionNode.getElementsByTagName('SubSection');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < SubSectionNodes.length; count++)
	{
   		textValue = GetInnerText(SubSectionNodes[count]);
		idValue = SubSectionNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		SubSectionList.options[SubSectionList.length] = optionItem;
	}
}


// populate the contents of the country dropdown list in Edit Mode
function PopulateSubSectionList2(SubSectionNode)
{
    var SubSectionList = document.getElementById("SubSectionList");
	// clear the country list 
	for (var count = SubSectionList.options.length-1; count >-1; count--)
	{
		SubSectionList.options[count] = null;
	}

	var SubSectionNodes = SubSectionNode.getElementsByTagName('SubSection');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < SubSectionNodes.length; count++)
	{
   		textValue = GetInnerText(SubSectionNodes[count]);
		idValue = SubSectionNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		SubSectionList.options[SubSectionList.length] = optionItem;
	}
	//alert (idValue);
	//alert ('textValue is:' + textValue);
	//alert ('count is:' + count);
	//alert ('idValue is:' + idValue);
	//document.form1.SubSectionList.selected.value = 0;
	document.form1.SiteSubSectionID.value = idValue;
}

// populate the contents of the subsection dropdown list in Edit Mode
function PopulateSubSectionList3(SubSectionNode)
{
    var SubSectionList = document.getElementById("SubSectionList");
	// clear the country list 
	for (var count = SubSectionList.options.length-1; count >-1; count--)
	{
		SubSectionList.options[count] = null;
	}

	var SubSectionNodes = SubSectionNode.getElementsByTagName('SubSection');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < SubSectionNodes.length; count++)
	{
   		textValue = GetInnerText(SubSectionNodes[count]);
		idValue = SubSectionNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		SubSectionList.options[SubSectionList.length] = optionItem;
	}
	//alert (idValue);
	form1.SiteSubSectionID.value = idValue;
}


// returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}

function TextChange ()
{
	 var SubSectionList = document.getElementById("SubSectionList");
    
    // get selected continent from dropdown list
    var selectedSubSection = SubSectionList.options[SubSectionList.selectedIndex].value;
    //alert (selectedSection);
    // url of page that will send xml data back to client browser
    //var requestUrl;
    // use the following line if using asp
    //requestUrl = "/ajax/xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedSection);
    // use the following line if using php
    // requestUrl = "xml_data_provider.php" + "?filter=" + encodeURIComponent(selectedContinent);
    //var thelist;
	 //thelist = form1.SiteSectionID.value;
	 //alert(thelist);
	 //var varSectionList = document.getElementById("SectionList");
    
    // get selected continent from dropdown list
    //var varselectedSection = SectionList.options[varSectionList.selectedIndex].value;
	 //var thevar = form1.SectionList.options[SectionList.selectedIndex].value;
	 //alert (selectedSubSection);
	//alert ('textValue is:' + textValue);
	//alert ('count is:' + count);
	//alert ('idValue is:' + idValue);
	 //alert(selectedSection);
	 document.form1.SiteSubSectionID.value = selectedSubSection;	 
	
}


function getUpdatedTimes(fac)
	{
		//var fac = $F('Instances');
		//var y = $F('lstYears');
		var url = 'http://dev.umc.org/Directory/ajax_Dp_GetUpdatedTimes.asp';
		var pars = 'fac=' + fac;
		
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: showResponse
			});
		
	}

	function showResponse(originalRequest)
	{
		//put returned XML in the textarea
		alert('original responsetxt: ' + originalRequest.responseText);
		opener.document.getElementById("ajaxRequest").innerHTML = originalRequest.responseText;
		$('ajaxRequest').innerHTML = originalRequest.responseText;
		var thelocalDiv;
		thelocalDiv = $('ajaxRequest').innerHTML; 
		alert (thelocalDiv);
		alert ('the child/local div: ' + thelocalDiv);
		
		//alert ('parent to be:' + $('opener.document.ajaxRequest').innerHTML);
		var parentDiv = opener.document.getElementById("ajaxRequest").innerHTML;
		alert ('parent div: ' + opener.document.getElementById("ajaxRequest").innerHTML);
		alert (parentDiv);
		//parentDiv =  = $('ajaxRequest').innerHTML;
		
		//alert ('parent div after: ' + parentDiv);
		//opener.document.ajaxRequest.innerHTML = originalRequest.responseText;
		//$('ajaxRequest').innerHTML = originalRequest.responseText;
	}






