// File: readXML.js

// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the customer.xml file
	$.get("customers.xml",{},function(xml){
      	
		theParameter = jQuery.url.param("industry");

	var result = null;
	switch (theParameter) {
		case "01": result = 'Aérospatiale, Défense et Sécurité'; break;
		case "02": result = 'Agroalimentaire'; break;
		case "03": result = 'Banque et Assurance'; break;
		case "04": result = 'Eau et Energie'; break;
		case "05": result = 'E-commerce'; break;
		case "06": result = 'Enseignement Supérieur et Recherche'; break;
		case "07": result = 'Grande distribution'; break;
		case "08": result = 'Hautes Technologies'; break;
		case "09": result = 'Industrie'; break;
		case "10": result = 'Ingénierie, Construction et Opérations'; break;
		case "11": result = 'Luxe'; break;
		case "12": result = 'Média'; break;
		case "13": result = 'Santé'; break;
		case "14": result = 'Sciences de la Vie'; break;
		case "15": result = 'Secteur Public'; break;
		case "16": result = 'Services'; break;
		case "17": result = 'Services en ligne'; break;
		case "18": result = 'Services financiers et Investissement'; break;
		case "19": result = 'Télécommunication'; break;
		case "20": result = 'Transport et Logistique'; break;
		default: result = 'Tous nos clients';
	}


		// Build an HTML string
		myHTMLOutput = '';
		myHTMLOutput = '<h2 style="margin-bottom: 20px; margin-left: 20px;">'+ result + '</h2>';
		myHTMLOutput += '<dl class="customerList">';
	  	
		// Run the function for each customer tag in the XML file
		$('customer',xml).each(function(i) {
										
			customerName = $(this).find("name").text();
			customerDesc = $(this).find("description").text();
			customerInd = $(this).find("industry").text();
			customerSite = $(this).find("website").text();
			customerCaseStudy = $(this).find("case_study").text(); 
			customerCountry = $(this).find("country").text(); 
			customerLogo = $(this).find("logo").text(); 
			
			var customerPreLink = "";
			var customerPostLink = "";
			if (customerLogo == "") {customerLogo = "nologo.gif";}
			if (customerSite != "") {
				customerPreLink = '<a href="http://' + customerSite + '">';
				customerPostLink = '</a>';
			}
			
			// Build row HTML data and store in string
			if (result == "Tous nos clients") {
				mydata = BuildCustomerHTML(customerName,customerDesc,customerInd,customerCaseStudy,customerCountry,customerLogo, customerPreLink, customerPostLink);
				myHTMLOutput = myHTMLOutput + mydata;
			}
			else if (customerInd == result) {
				mydata = BuildCustomerHTML(customerName,customerDesc,customerInd,customerCaseStudy,customerCountry,customerLogo, customerPreLink, customerPostLink);
				myHTMLOutput = myHTMLOutput + mydata;
			}
			
		});
		myHTMLOutput += '</dl>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea").append(myHTMLOutput);
	});
});
 
 
 
 function BuildCustomerHTML(customerName,customerDesc,customerInd,customerCaseStudy,customerCountry,customerLogo, customerPreLink, customerPostLink){
	
	
	// Build HTML string and return
	output = '';
	output += '<dt></dt>';
	output += '<dd>';
	output += customerPreLink + '<img alt="'+ customerName +'" src="../../pics/logos/customers/generic/'+ customerLogo +'" />' + customerPostLink;
	output += '   <div>';
	output += '<h3>'+ customerName +'</h3>' + customerInd;
	output += '		<p>'+ customerDesc +'</p>';
	output += '   </div>';
	output += '</dd>';
	return output;
}
	 