// 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 demoApp;
function filtrosAdicionales(valor, marcado)
{
	var strlink;
	if (marcado){
		strlink='_-'+valor+':si';
	}else{
		strlink='_-'+valor+':no';
	}
	return strlink;
}

var historial={};

historial.request=function(url){
	http_request=historial.XHRequest();
	http_request.open('GET', url, false);
	http_request.setRequestHeader('X_REQUESTED_WITH','XMLHttpRequest');
	http_request.send(null);
	return http_request.responseText;
}

historial.XHRequest=function(){
	http_request=null;
	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){
			}
		}
	}
	if(!http_request)
	{
		alert('Lo siento no se puede crear una instancia XMLHTTP. Considere actualizar su navegador a la mÃ¡s reciente versiÃ³n.');
		return false;
	}else{
		return http_request;
	}
}

historial.buildHistory=function(){
	var array_json=new Array();
	var str_jason='';
	if(typeof(jasonvars)=='object')
	{
		for (var name in jasonvars)
		{
			if(jasonvars[name]!='')
				array_json.push(';'+name+';:'+jasonvars[name]+'');
		}
		this.currentHistoryHash=array_json.join(',');
		tmpHistoryHash=this.currentHistoryHash.replace(/;/g,'"');
		this.historyHash=tmpHistoryHash.replace(/#/g,'');
		this.jasonvars='{'+this.historyHash+'}';
		this.obJasonvars=jsonParse('{'+this.historyHash+'}');
	}
}

historial.json=function(){
	var str_uri=window.location.hash;
	var str_uri2='';
	var array_uri=new Array();
	var array_jason=new Array();
	var vars_jason=new Array();
		
	typeof(typeof(str_uri));
	
	if(str_uri!='')
	{
		this.currentHistoryHash=str_uri;
		
		tmpHistoryHash=str_uri.replace(/;/g,'"');
		this.historyHash=tmpHistoryHash.replace(/#/g,'');

		str_uri2=str_uri.replace(/;/g,'');
		str_uri=str_uri2.replace(/,/g,';');

		array_uri=str_uri.split('#');
		str_uri=array_uri[1];
		array_uri=str_uri.split(';');
		for (var i in array_uri)
		{
			if(array_uri[i]!="")
			{
				array_campos=array_uri[i].split(':');
				if(array_campos[1]!='undefined')
				{
					str_jason='"'+array_campos[0]+'":"'+array_campos[1]+'"';
					eval(array_campos[0]+'="'+array_campos[1]+'";');
					array_jason.push(str_jason);
				}
			}
		}
		str_json=array_jason.join(',');
		
		this.jasonvars='{'+str_json+'}';
		this.obJasonvars=jsonParse('{'+str_json+'}');
	}else{
		this.historyHash='';
		this.jasonvars='{}';
		this.obJasonvars={};
	}
}

historial.PromptMe=function(){
	var stateVar = "nothin'";
	displayDiv = document.getElementById("HistoryState");
	
	// Se ejecuta objeto historial.json para generar hash y jsonvars
	historial.json();
	
	strHistoryHash=historial.historyHash;
	
	this.historyListener = function() {
		if (historial.historyHash!='')
		{
			// Ejecución de function de usuario	
			historial.cache();
		}
	};
	
	unFocus.History.addEventListener('historyChange', this.historyListener);
	this.historyListener(unFocus.History.getCurrent());
};