/*----------------------------------------------------------------------------\
|                       AIP on CD internationalization support 1.0            |
|-----------------------------------------------------------------------------|
|                          Created by Javier Fenoll                           |
|                            For AIS Spain - Aena                             |
|-----------------------------------------------------------------------------|
| Support for internationalization in the AIP - CD .                          |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| This  software is  available under the  GPL licenses  mentioned below.      |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| GPL - The GNU General Public License    http://www.gnu.org/licenses/gpl.txt |
| Permits anyone the right to use and modify the software without limitations |
| as long as proper  credits are given  and the original  and modified source |
| code are included. Requires  that the final product, software derivate from |
| the original  source or any  software  utilizing a GPL  component, such  as |
| this, is also licensed under the GPL license.                               |
|-----------------------------------------------------------------------------*/


function StartLanguage() {		
	
	var language  = ""
	// look if language is pased as url parameter
	var urlquery=location.href.split("?");	
	
	if (urlquery.length >= 2 ) {
		urlterms=urlquery[1].split(",");
		if (urlterms[0] != "")  
			language =  urlterms[0];
				
		}
		
	if (language == "") {
		
	
		if (navigator.appName == 'Netscape')
			language = navigator.language;
		else
			language = navigator.browserLanguage;
	
		if (language.substring(0,2) == 'es')
			language = 'es';
		else
			language = 'en';
	
		
		
	}
	
	setLanguage(language);
	
}


function setLanguage(cual) {
	
	document.getElementById("vTexts_lang").innerHTML = cual;
	
	LoadLanguage("language/" + cual + "/lang.xml");
	
}

	
function LoadLanguage(sFile) {
	
	var xmlChartTypes = XmlDocument.create();
	xmlChartTypes.async = false;
	
	xmlChartTypes.load(sFile);
	
	LoadLanguageElements(xmlChartTypes);	
	
	
}

function LoadLanguageElements(node) {
		
	
	if (node == null)
		return "";
	
	if (node.nodeType == 1) {
		
		var id = "";		
		var desc = "";
		var link = "";
		var src= "";
		var value = "";
		var value1 = "";
		var value2 = "";
		
		var attrs = node.attributes;
		for (var i = 0; i < attrs.length; i++) { 			
			
			if (attrs[i].nodeName == "id")
				id = attrs[i].nodeValue;
			if (attrs[i].nodeName == "link")
				link = attrs[i].nodeValue;
			if (attrs[i].nodeName == "src")
				src = attrs[i].nodeValue;
			if (attrs[i].nodeName == "value")
				value = attrs[i].nodeValue;
			if (attrs[i].nodeName == "value1")
				value1 = attrs[i].nodeValue;
			if (attrs[i].nodeName == "value2")
				value2 = attrs[i].nodeValue;
			
			
		}
										
		if (id != "") {
			if (node.firstChild) desc = node.firstChild.nodeValue;

			if (desc != "") document.getElementById(id).innerHTML = desc;
			if (link != "") document.getElementById(id).href = link;
			if (src != "") document.getElementById(id).src = src;
			if (value != "") document.getElementById(id).value = value;
			if (value1 != "") document.getElementById(id).value1 = value1;
			if (value2 != "") document.getElementById(id).value2 = value2;
		}
						
	}
	var cs = node.childNodes;
	for (var i = 0; i < cs.length; i++)
		LoadLanguageElements(cs[i]);
}	
	

