
function init() {
	pepe.write("headerFlash");
	
	for (var n=0; n < banners.length; n++) {
		banners[n].addParam("wmode", "transparent");
		banners[n].write('banner' + (n+1));
	}
}

var http_request = false;
function createRequest() {
	http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {}
		}
	}
	return http_request;
}

var dtTitle = {"ES" : {
				"date" : "Fecha:",
				"time" : "Horario:",
				"location" : "Lugar:",
				"city" : "Ciudad:",
				"country" : "Pais:" },
			"EN" : {
				"date" : "Date:",
				"time" : "Time:",
				"location" : "Institution:",
				"city" : "City:",
				"country" : "Country:" } };
var rip = false;

function loadCongress(congressId, langId) {
	if (rip == false) {
		rip = true;
		var congressInfo = document.getElementById('congressInfo');
		http_request = createRequest();
	
		if (!http_request) {
			alert( 'Error: No se pudo crear objeto HttpXmlRequest.' )
			return;
		}
		
		http_request.open( 'POST', '/xml.congress.php', true );
		http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http_request.onreadystatechange = showCongress;
		http_request.send( 'congressId=' + congressId + '&langId=' + langId );
		
	}
}

function showCongress() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var content = document.getElementById('content');
			while (content.firstChild) 
				content.removeChild(content.firstChild);
			
			root = http_request.responseXML.getElementsByTagName('congress').item(0);
			lang = root.getAttribute('lang');
			var title, startdate, enddate, starttime, endtime, location, city, country;
			
			title = root.getElementsByTagName('title').item(0).firstChild.data;
			startdate = root.getElementsByTagName('startdate').item(0).firstChild.data;
			enddate = root.getElementsByTagName('enddate').item(0).firstChild.data;
			starttime = root.getElementsByTagName('starttime').item(0).firstChild.data;
			endtime = root.getElementsByTagName('endtime').item(0).firstChild.data;
			if (root.getElementsByTagName('location').item(0).firstChild)
				location = root.getElementsByTagName('location').item(0).firstChild.data;
			else
				location = '';
				
			if (root.getElementsByTagName('city').item(0).firstChild)	
				city = root.getElementsByTagName('city').item(0).firstChild.data;
			else
				city = '';
				
			if (root.getElementsByTagName('country').item(0).firstChild)
				country = root.getElementsByTagName('country').item(0).firstChild.data;
			else
				country = '';

			var h2title = document.createElement('h2');
			h2title.appendChild(document.createTextNode(title));
			content.appendChild(h2title);
			
			var congressInfo = document.createElement('dl');
			congressInfo.id = 'congressInfo';
			content.appendChild(congressInfo);
		
			if (startdate != '0000-00-00') {
				dt = document.createElement('dt');
				dtText = document.createTextNode(dtTitle[lang].date);
				dt.appendChild(dtText);
				congressInfo.appendChild(dt);
				
				dd = document.createElement('dd');
				if (enddate != startdate) {
					ddText = document.createTextNode(startdate + ' al ' + enddate);	
				} else {
					ddText = document.createTextNode(startdate);
				}
				dd.appendChild(ddText);
				congressInfo.appendChild(dd);
			}
			
			if (starttime != '00:00:00') {
				dt = document.createElement('dt');
				dtText = document.createTextNode(dtTitle[lang].time);
				dt.appendChild(dtText);
				congressInfo.appendChild(dt);
				
				dd = document.createElement('dd');
				if (endtime != starttime) {
					ddText = document.createTextNode(starttime + ' a ' + endtime);	
				} else {
					ddText = document.createTextNode(starttime);
				}
				dd.appendChild(ddText);
				congressInfo.appendChild(dd);
			}

			dt = document.createElement('dt');
			dtText = document.createTextNode(dtTitle[lang].location);
			dt.appendChild(dtText);
			congressInfo.appendChild(dt);
			
			dd = document.createElement('dd');
			ddText = document.createTextNode(location);
			dd.appendChild(ddText);
			congressInfo.appendChild(dd);
			
			dt = document.createElement('dt');
			dtText = document.createTextNode(dtTitle[lang].city);
			dt.appendChild(dtText);
			congressInfo.appendChild(dt);
			
			dd = document.createElement('dd');
			ddText = document.createTextNode(city);
			dd.appendChild(ddText);
			congressInfo.appendChild(dd);
			
			dt = document.createElement('dt');
			dtText = document.createTextNode(dtTitle[lang].country);
			dt.appendChild(dtText);
			congressInfo.appendChild(dt);
			
			dd = document.createElement('dd');
			ddText = document.createTextNode(country);
			dd.appendChild(ddText);
			congressInfo.appendChild(dd);

			rip = false;
		} else {
			alert( 'Se ha producido un error enviando la información.\nInténtelo más tarde (' + http_request.status + ')' );
		}
	}
}

function showCountry(regionId) {
	region = document.getElementById('region'+regionId);
	countries = region.getElementsByTagName('ul').item(0);
	if (region.className == '') {
		countries.style.display = 'block';
		region.className = 'expanded';
	} else {
		countries.style.display = 'none';
		region.className = '';
	}
	return false;
}

function showDistributor(countryId) {
	
	var distributors = document.getElementById('distributors');
	distributors.style.display = 'block';
	var h2 = distributors.getElementsByTagName('h2');
	for (i=0; i<h2.length; i++) {
		if (h2[i].className == countryId) {
			h2[i].style.display = 'block';
		} else {
			h2[i].style.display = 'none';
		}
	}
	
	var dl = distributors.getElementsByTagName('dl');
	for (i=0; i<dl.length; i++) {
		if (dl[i].className == countryId) {
			dl[i].style.display = 'block';
		} else {
			dl[i].style.display = 'none';
		}
	}
	
	return false;
}

function openpdf(fileName) {
	window.open ('/media/pdf/'+fileName);
}