// File: readXML.js

// This function loads the XML
function get_xml(user_state){ 

	// fade out div
	$("#services").fadeOut('fast');

	// Open the services.xml file
	$.ajax({
        type: "GET",
		url: "/xml/services.xml",
		dataType: "xml",
		success: function(xml) {
			
		// Alert mime type	
		//	$(document).ajaxComplete(function(e, x) {
   		//		alert(x.getResponseHeader("Content-Type"));
		//	});
			
			//parsexml(xml); // IE fix

			// Start building the HTML string
			myHTMLOutput = '';

			// Run the function for each service tag in the XML file
			$(xml).find('service').each(function() {
				
				var title = $(this).find("title").text();
				var description = $(this).find("description").text();
				var states = $(this).find("states").text();
				var url_title = $(this).find("url_title").text();
				
				
				
				// If the state XML string contains the user selected state or is designated as ALL

				if (states.match(user_state) || (states == "ALL")) {
					// Build row HTML data and store in string
					mydata = BuildHTML(title,description,states,url_title);
					myHTMLOutput = myHTMLOutput + mydata;
					
				}

			
			});
			
	// clear div and insert new html
	//alert(myHTMLOutput);
	$("#services").text('').append(myHTMLOutput);
		
	    }
	});

	// fade in
	$("#services").fadeIn('fast');

}

// Build HTML string and return
function BuildHTML(title,description,states,url_title){
	output = '<div>';
	output += '<h2>'+ title + '</h2>';
	output += '<p>'+ description +'</p>';
	output += '<p class="more"><a href="/about-availity/what-is-availity/products-services/' + url_title + '/">Read more &raquo;</a></p>';
	output += '<hr></div>';
	return output;
}


// IE FIX:
function parsexml(xml)	{   
    if (jQuery.browser.msie)
    {
       xmlie = new ActiveXObject("Microsoft.XMLDOM");
       xmlie.async = false;
       xmlie.loadXML(xml);
	   xml=xmlie;
    }
 
    return xml;
}  
	 