// JavaScript Document

// GetXmlHttpObject()

function GetXmlHttpObject() {
	
	var xmlHttp=null;
	
	try {
		
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		
	}
	
	catch (e) {
		
		// Internet Explorer
		try {
			
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			
		}
		
		catch (e) {
			
			try {
				
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				
			}
			
			catch (e) {
				
				alert("Esta aplicación solo funciona con exploradores que soportan AJAX");
				
			}
			
		}
		
	}
	
	return xmlHttp;
	
}


// displayError(text)

function displayError(text) {
	
	str	= '<table width="100%"><tr><td align="center" class="error">'+text+'</td></tr></table>';
	
	obj	= document.getElementById('warnings');
	obj.innerHTML = str;
	obj.style.display="block";
	
}

// displayNotice(text)

function displayNotice(text) {
	
	str	= '<table width="100%"><tr><td align="center" class="notice">'+text+'</td></tr></table>';
	
	obj	= document.getElementById('warnings');
	obj.innerHTML = str;
	obj.style.display="block";
	
}

// clearErrorNotice()

function clearErrorNotice() {
	
	str	= '';
	
	obj	= document.getElementById('warnings');
	obj.innerHTML = str;
	obj.style.display="none";
	
}


// displaySubmenu(level)

function displaySubmenu(level) {
	
	switch(level) {
		
		case 1:
		
			displayNotice('cargando...');
		
			var xmlHttp = GetXmlHttpObject();
			
			xmlHttp.onreadystatechange=function() {
			
				if(xmlHttp.readyState==4) {
				
					obj	= document.getElementById('contenido');
					obj.innerHTML = xmlHttp.responseText;
				
				}
				
			}
			
			xmlHttp.open("GET","facturas.php",true);
			xmlHttp.send(null);
	
			str	= '';
			
			clearErrorNotice();
			
		break;
		
		case 2:
		
			str	= '<a href="#">submenu 2</a>';
			
		break;
		
		case 3:
		
			str	= '<a href="#">submenu 3</a>';
			
		break;
		
	}
		
	obj	= document.getElementById('submenu');
	obj.innerHTML = str;
	
}

/* displayLoading(div) */

function displayLoading(div) {
	
	obj	= document.getElementById(div);
	obj.innerHTML = '<table style="width:100%;height=100%;"><tr><td><img src="images/loading.gif" /></td></tr></table>';
	
}


/* loadNoticias() */

function loadNoticias() {
	
	// display loading image
	
	displayLoading('div_noticias_index');

	// xmlhttpobject and results

	var xmlHttp = GetXmlHttpObject();
	
	xmlHttp.onreadystatechange=function() {
	
		if(xmlHttp.readyState==4) {
		
			obj	= document.getElementById('div_noticias_index');
			str	= unescape(xmlHttp.responseText);
			str = str.replace(/\+/gi," ");
			obj.innerHTML = str;
		
		}
		
	}
	
	xmlHttp.open("GET","load_noticias.php",true);
	xmlHttp.send(null);

}



