/**
 * @author r
**/
	//funcions.js
	//Funcio para crear un objecte XMLHttp.
	function getxmlhttp (){
		//Crear una variable de Bool para omprobar si se puede utilizar una instancia ActiveX de Microsoft.
		var xmlhttp = false;
		
		//Comprobar si se est� utilizando Internet Explorer.
		try {
			//Si la versi�n de javascript es superior a la 5.
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//Si no, utilizar el objeto ActiveX tradicional.
			try {
				//Si se est� utilizando Internet Explorer.
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				//En caso contrario no debe estarse utilizando Internet Explorer.
				xmlhttp = false;
			}
		}
		
		//Si no se est� utilizando Internet Explorer, crear una instancia JavaScript del objeto.
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}
	
	//Funci�n para procesar un XMLHttpRequest.
	function processajax (obj, serverPage){    
		//Obtener el objeto XMLHttpRequest a utilizar.
		var theimg;
		xmlhttp = getxmlhttp ();
		xmlhttp.open("GET", serverPage);        
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {            
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
	
/**
 * Funcio per a canviar l'idioma
 */	

function Toeng(pag)
{
	$('#jailaits').load('htmls/jailaits_eng.html');
	$('#menu').load('htmls/menu_eng.html');
	
	switch(pag)
	{
		case "ecmbcn":
		nPag = "#ecmbrcn";
		location.href=(nPag);
		break;
		case "contacte":
		nPag = "#contact";
		location.href=(nPag);
		break;
		case "descarregues":
		nPag = "#downloads";
		location.href=(nPag);
		break;
		case "monecm":
		nPag = "#ecmworld";
		location.href=(nPag);
		break;
		case "patrocinadors":
		nPag = "#sponsors";
		location.href=(nPag);
		break;
		case "fotos":
		nPag = "#photos";
		location.href=(nPag);
		break;
		case "newsletter":
		nPag = "#newslett";
		location.href=(nPag);
		break;	
		case "noticies":
		nPag = "#news";
		location.href=(nPag);
		break;
		case "programacio":
		nPag = "#schedule";
		location.href=(nPag);
		break;
		case "concert1":
		nPag = "#show1";
		location.href=(nPag);
		break;
		case "concert2":
		nPag = "#show2";
		location.href=(nPag);
		break;
		case "concert3":
		nPag = "#show3";
		location.href=(nPag);
		break;
		case "concert4":
		nPag = "#show4";
		location.href=(nPag);
		break;
		case "concert5":
		nPag = "#show5";
		location.href=(nPag);
		break;
		case "concert6":
		nPag = "#show6";
		location.href=(nPag);
		break;
		case "concert7":
		nPag = "#show7";
		location.href=(nPag);
		break;
		default:
		nPag = "#news";
		location.href=(nPag);
		break;
	}
	//
}

function Tocat(pag)
{
	$('#jailaits').load('htmls/jailaits_cat.html');
	$('#menu').load('htmls/menu_cat.html');
	
	switch(pag)
	{
		case "ecmbrcn":
		nPag = "#ecmbcn";
		location.href=(nPag);
		break;
		case "contact":
		nPag = "#contacte";
		location.href=(nPag);
		break;
		case "downloads":
		nPag = "#descarregues";
		location.href=(nPag);
		break;
		case "ecmworld":
		nPag = "#monecm";
		location.href=(nPag);
		break;
		case "sponsors":
		nPag = "#patrocinadors";
		location.href=(nPag);
		break;
		case "photos":
		nPag = "#fotos";
		location.href=(nPag);
		break;
		case "newslett":
		nPag = "#newsletter";
		location.href=(nPag);
		break;	
		case "news":
		nPag = "#noticies";
		location.href=(nPag);
		break;
		case "schedule":
		nPag = "#programacio";
		location.href=(nPag);
		break;
		case "show1":
		nPag = "#concert1";
		location.href=(nPag);
		break;
		case "show2":
		nPag = "#concert2";
		location.href=(nPag);
		break;
		case "show3":
		nPag = "#concert3";
		location.href=(nPag);
		break;
		case "show4":
		nPag = "#concert4";
		location.href=(nPag);
		break;
		case "show5":
		nPag = "#concert5";
		location.href=(nPag);
		break;
		case "show6":
		nPag = "#concert6";
		location.href=(nPag);
		break;
		case "show7":
		nPag = "#concert7";
		location.href=(nPag);
		break;
		default:
		nPag = "#noticies";
		location.href=(nPag);
		break;
	}
}
	
function PromptMe() {
	// some application vars
	var stateVar = "nothin'", displayDiv = document.getElementById("main");
	
	// the sole public method to manipulate this application
	this.promtForNew = function() {
		// do the stuff that changes the state
		var newVal = window.prompt("Please enter some value to store in the history and url");
		// Set the new history hash. This value must be a string, so serializtion is up to you.
		// JSON works nicely, if you need something quick: http://www.json.org
		// When a new entry is made, unFocus.History will notify the historyListener 
		// method of the change, even on the first call. For this demo app we can 
		// rely on the historyListener method to update the state, and view.
		unFocus.History.addHistory(newVal);
	};
	
	// This is the method that will recieve notifications from the History Keeper,
	// which will then update the state of the app.
	// :NOTE: This will be called when a new entry is added.
	// :NOTE: This will be called if another app on the page sets a history,
	//        so you will need to watch out for this, if you have more than
	//        one script using the history keeper, by doing some kind of 
	//        check to make sure that the new hash belongs to this app.
	//        I wouldn't expect this to be a problem all that frequently.
	this.historyListener = function(historyHash) {
		// update the stateVar
		stateVar = historyHash;
		// update display content
		processajax ('main',"htmls/"+ historyHash+".html");
		// update document title
		document.title = "ECM Barcelona || " + historyHash;
		
	};
	// subscribe to unFocus.History
	unFocus.History.addEventListener('historyChange', this.historyListener);
	
	// Check for an initial value (deep link).
	// In this demo app, the historyListener can handle the task.
	this.historyListener(unFocus.History.getCurrent());
};
// instantiate and inialize the app. DOM has to be ready so we can get a ref to
// the HistoryState DOM element (aka the view), so we use QuickLoader to make
// sure it's ready.
var ECMNav;