//parseCourtServicesData 

//Public variables from Common.js
	//var county;
	//var IE = 0;
	//var Firefox = 0;
	//var xmlDoc1;

var strCourtContent = "";

function verify1()
{
	// 0 Object is not initialized
 	// 1 Loading object is loading data
 	// 2 Loaded object has loaded data
 	// 3 Data from object can be worked with
 	// 4 Object completely initialized
 	if (xmlDoc1.readyState != 4)
 	{
   		return false;
 	}
}

function importCourtServicesXML(processCounty)
{
	county = processCounty;
	var xmlFile = '../XMLData/CourtServices/qryCountyData.xml';
	//Check if IE(ActiveX) or FireFox
	if (window.ActiveXObject) {
		IE = 1;
		//alert("IE");
  	xmlDoc1 = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc1.async="false";
    xmlDoc1.onreadystatechange=verify1;
    xmlDoc1.load(xmlFile);
  	xmlObj=xmlDoc1.documentElement;
	} else {
		//alert("NotIE");
		Firefox = 1;
		//alert("load1");
  	xmlDoc1 = document.implementation.createDocument("", "", null);
		//alert("load2");
		
		//************** Sarfi not loading ***********
		xmlDoc1.load(xmlFile);
		//alert("load3");
	}
	 if ( !xmlDoc1.load(xmlFile) ) {        
	 	alert ("Failed to load XML data source!");    
	}
	CourtServices();	
}

function CourtServices() 
{ 
	//Need to set a Time Delay for Firefox
	intTime = 0;
	if (Firefox == 1) intTime = 2000;
	//alert(intTime);
	setTimeout("parseCourtServicesData()",intTime);	 
}

function parseCourtServicesData()
{		
	strCourtContent = "";
	var label="";
	var value="";
	var strCounty = "";
	var strDistrictId = "";
	var strAreaId = "";
	var intDistrictCount = 0;
	var x = xmlDoc1.getElementsByTagName('qryCountyData');
	//alert("Rows="+x.length);
	// x is the number of Rows in the XML file
	// loop thru xml file looking for this County and generate html code
	// store the Area code
	// finally look for the Area and generate html code
		
	for (i=0;i<x.length;i++) {
		//Loop thru all Child Nodes for the Row and look for County match
		for (j=0;j<x[i].childNodes.length;j++) {
			nodeFound=0;	
			if (x[i].childNodes[j].nodeType == 1) {	
				//Look for the County node
				if (x[i].childNodes[j].nodeName == "County") {
					nodeFound=1;
					strCounty = x[i].childNodes[j].firstChild.nodeValue;
				}
				// If County was found, then continue processing remaining child nodes
				if (strCounty==county) { 
					//Check for the District node
					if (x[i].childNodes[j].nodeName == "District") {
						nodeFound=1;
						strDistrictId = x[i].childNodes[j].firstChild.nodeValue;
						//Skip over the Area rows where District begins with "A_" 
						if (strDistrictId.substring(1,2)=="_") {
							intDistrictCount = 1;
						} else{
							//Write out the table tag for District Contact Information
							strCourtContent = strCourtContent + '<table width="500" cellpadding="0">';
						}
					} //End IF District
					
					//Check for Area node
					if (x[i].childNodes[j].nodeName == "Area") {
						nodeFound=1;
						strAreaId = x[i].childNodes[j].firstChild.nodeValue;
					} //End If Area
					
					//If no node was found to be a previous match the process it here
					if (nodeFound != 1 && intDistrictCount == 0) {
						label=x[i].childNodes[j].nodeName;
						value="";
						if(x[i].childNodes[j].firstChild) 
							value=x[i].childNodes[j].firstChild.nodeValue;
						//write out the label/value line
						if(value!="(null)" && value!="(none)" && value!="") {
							if(label=="Contact") label="Chief Court Counselor";
							if(label=="Address2" || label=="Address3") label=" ";
							strCourtContent = strCourtContent + '<tr><td width="200"><strong>' +label+ '</strong></td>';
							strCourtContent = strCourtContent + '<td><div align="left">'+value+'</div></td></tr>';	
						}
					} //End If process other nodes
	     				
	   			} //End If County
			
			} //End If Type = 1
		
		} //End For j
		
		// If County was found and processed, then write end tags and set i to max length to end search
		if(strCounty == county) {
			i = x.length;
			strCourtContent = strCourtContent + '</table>';
       		strCourtContent = strCourtContent + '<br>';
			strCourtContent = strCourtContent + '<img src="../resources/graphics/county_services/banners/table_spliter.gif" alt="table splitter" width="500" height="7">';

		} //End If County found and processed

	} //End For i

	//Check is the Area ID exists for this County; if so, then find/write Area information
	if(strAreaId !="") {
		//Write out the table tag for District Area Administrator
		strCourtContent = strCourtContent + '<table width="500" cellpadding="0">';
		var strAreaCheck = "A_"+strAreaId;
		var strAreaFound = "";
		for (i=0;i<x.length;i++) {
		  for (j=0;j<x[i].childNodes.length;j++) {
			if (x[i].childNodes[j].nodeType == 1) {	
			  if (x[i].childNodes[j].nodeName == "District" &&
			      strAreaCheck == x[i].childNodes[j].firstChild.nodeValue) {
					// Now read the rest of the ChildNodes until end of Row 
			    strAreaFound = "Yes";
					for (k=j+1;k<x[i].childNodes.length;k++) {
						if (x[i].childNodes[k].nodeType == 1) {	
							if (x[i].childNodes[k].nodeName != "District" &&
								x[i].childNodes[k].nodeName != "Area") {
								label=x[i].childNodes[k].nodeName;
								value="";
								if(x[i].childNodes[k].firstChild) 
									value=x[i].childNodes[k].firstChild.nodeValue;
								//write out the label/value line
								if(value!="(null)" && value!="(none)" && value!="") {
									if(label=="Contact") label="Area Administrator";
									if(label=="Address2" || label=="Address3") label=" ";
									strCourtContent = strCourtContent + '<tr><td width="200"><strong>'+label+'</strong></td>';
									strCourtContent = strCourtContent + '<td><div align="left">'+value+'</div></td></tr>';	
								}
							}
	     				} // End If Type = 1
					} //EndFor k 
					strCourtContent = strCourtContent + '</table>';
	    			j=k;
		  	  } //End If Area found
		  	}//End If Type =1
		  } //End For j
		  if (strAreaFound == "Yes")i=x.length; 
		} //End For i
	} //End If Area
	
	//Replace courtservices DIV with new strCourtContent
	var newdiv = document.createElement("div");
	newdiv.innerHTML = strCourtContent;
	var container = document.getElementById("courtservices");
	container.appendChild(newdiv);
	
		
} //Function End

