//parseSOSData 

//Public variables from Common.js
	//var county = "";
	//var IE = 0;
	//var Firefox = 0;
	//var xmlDoc3;

//variables for XML data values
var strSOSContent = "";
var strProvider = "";
var strMailAddr1 = "";
var strMailAddr2 = "";
var strPhysAddr1 = "";
var strPhysAddr2 = "";
var strPhone = "";
var strContact = "";
var strTitle = "";
var strEmail = "";

function verify3()
{
	// 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 (xmlDoc3.readyState != 4)
 	{
   		return false;
 	}
}

function importSOSInformationXML(processCounty)
{
	county = processCounty;
	var xmlFile = '../XMLData/SOS/SOSProviderData.xml';
	//Check if IE(ActiveX) or FireFox
	if (window.ActiveXObject) {
		IE=1;
    xmlDoc3 = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc3.async="false";
    xmlDoc3.onreadystatechange=verify3;
    xmlDoc3.load(xmlFile);
  	xmlObj=xmlDoc3.documentElement;
	} else {
			Firefox=1;
  		xmlDoc3 = document.implementation.createDocument("", "", null);
			xmlDoc3.load(xmlFile);
	}
	 if ( !xmlDoc3.load(xmlFile) ) {        
	 	alert ("Failed to load SOSData XML data source: ");    
	}
	SOSInformation();
		
} //End Function

function SOSInformation() 
{ 
	//Need to set a Time Delay for Firefox
	intTime = 0;
	if (Firefox == 1) intTime = 1000;
	setTimeout("parseSOSData()",intTime);	 
}

function parseSOSData()
{	
	strSOSContent = "";
	var label="";
	var value="";
	var x = xmlDoc3.getElementsByTagName('ROW');
	//alert("Number of 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
	
	// Loop through each Row	
	for (i=0;i<x.length;i++) {
	//Loop thru all Child Nodes within 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.indexOf(county) >= 0) { 
					
					// Now read the rest of the ChildNodes until end of Row 
					for (k=j+1;k<x[i].childNodes.length;k++) {
						if (x[i].childNodes[k].nodeType == 1) {	
							label=x[i].childNodes[k].nodeName;
							value="";
							if(x[i].childNodes[k].firstChild) 
								value=x[i].childNodes[k].firstChild.nodeValue;
							
							//Check write out the label/value line
							if(value!="(null)" && value!="(none)" && value!="") 
							{
								//alert(label + ' ' + value);
								if(label == "Grantee_Org") strProvider = value;
								if(label == "Grantee_Mailing_Addr") strMailAddr1 = value;
								if(label == "Grantee_City_State_Zip") strMailAddr2 = value;
								if(label == "Grantee_Physical_Addr") strPhysAddr1 = value;
								if(label == "Grantee_Physical_City_State_Zip") strPhysAddr2 = value;
								if(label == "Grantee_Telephone") strPhone = value;
								if(label == "Grantee_Ctc") strContact = value;
								if(label == "Grantee_Ctc_Title") strTitle = value;
								if(label == "Grantee_Email") strEmail = value; 
	     				}// End If value
							
						} //End If nodeType = 1
			
					} //End For k
					
					generateSOSData ();
					// Set j to end since there's only one SOS Program per County
					j=x[i].childNodes.length;
										
				} //End If strCounty = County
				
			} //End If nodeType = 1
						
	  } //End For j
		
		// Set i to the end since all Childnodes were processed
		if (strCounty.indexOf(county) >= 0) i = x.length;

	} //For i End
	
	//Replace countyservices2 DIV with new SOS strSOSContent
	var newdiv = document.createElement("div");
	newdiv.innerHTML = strSOSContent;
	var container = document.getElementById("communityservices2");
	container.appendChild(newdiv);
	
} //Function End

function generateSOSData()
{	
	strSOSContent = strSOSContent + '<table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="F3F3F3">';
	strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td>';
	strSOSContent = strSOSContent + '<td colspan=2>These are the Support-Our-Students (SOS) Programs for  <b>' + county + '</b> county</td></tr>';
	strSOSContent = strSOSContent + '<tr><td colspan=3>&nbsp;</td></tr>';
	strSOSContent = strSOSContent + '<tr><td colspan=3><img src="../resources/graphics/county_services/banners/table_spliter.gif" width="500" height="7"></td></tr>';
	strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2><b><i>' + strProvider + '</b>,</i></td></tr>';
	if (strPhysAddr1 == "Same as Mailing Address" || strPhysAddr1 == "") 
	{
		//There is no different Physical Address
		strSOSContent = strSOSContent + '<tr><td colspan=3>&nbsp;</td></tr>';
  	strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2><u>Mailing Address:</u></td></tr>';
		strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2>' + strMailAddr1 + '</td></tr>';
		strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2>' + strMailAddr2 + '</td></tr>';
	} else {
		strSOSContent = strSOSContent + '<tr><td colspan=3>&nbsp;</td></tr>';
		strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td><u>Mailing Address:</u></td><td><u>Physical Address:</u></td></tr>';
		strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td>' + strMailAddr1 + '</td><td>' + strPhysAddr1 + '</td></tr>';
		strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td>' + strMailAddr2 + '</td><td>' + strPhysAddr2 + '</td></tr>';
	}
	strSOSContent = strSOSContent + '<tr><td colspan=3>&nbsp;</td></tr>';
	strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2><u>Contact:</u></td></tr>';
	strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2>' + strContact + '</td></tr>';
	strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2>' + strTitle + '</td></tr>';
	strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2>' + strPhone + '</td></tr>';
	strSOSContent = strSOSContent + '<tr><td width="10">&nbsp;</td><td colspan=2>' + strEmail + '</td></tr>';
	strSOSContent = strSOSContent + '<tr><td colspan=3>&nbsp;</td></tr>';
	strSOSContent = strSOSContent + '<tr><td colspan=3><img src="../resources/graphics/county_services/banners/table_spliter.gif" width="500" height="7"></td></tr>';
	strSOSContent = strSOSContent + '<tr><td colspan=3>&nbsp;</td></tr>';	
	strSOSContent = strSOSContent + '</table>';
  strSOSContent = strSOSContent + '<br>';

	//Reset variables for next read
	strProvider = "";
	strMailAddr1 = "";
	strMailAddr2 = "";
	strPhysAddr1 = "";
	strPhysAddr2 = "";
	strPhone = "";
	strContact = "";
	strTitle = "";
	strEmail = "";

}// END Function