// JavaScript Document
function redireccion(url) {
	window.location.href = url;
	return false;
}

function nueva_pagina(url) {
	window.open(url); 
	return false;
}

function imprimirMapa(opcion) {
	switch (opcion) {
		case 0: window.location.href = "imprimir.php?oficina=0"; break;
		case 1: window.location.href = "imprimir.php?oficina=1"; break;
	}
}

function cambiarColor(capa,color,id) {
	switch (color) {
		case 'naranja': document.getElementById(capa + id).style.color = '#ff4c00'; break;
		case 'negro': document.getElementById(capa + id).style.color = '#000'; break;
	}
	return false;
}

var net = new Object();

net.READY_STATE_UNINITIALIZED=0; 
net.READY_STATE_LOADING=1; 
net.READY_STATE_LOADED=2; 
net.READY_STATE_INTERACTIVE=3; 
net.READY_STATE_COMPLETE=4; 

net.CargadorContenidosCompleto = function(url, funcion, funcionError, metodo, parametros, contentType, sincrona) {
	this.url = url;
	this.req = null;
	this.onload = funcion;
	this.onerror = (funcionError) ? funcionError : this.defaultError;
	this.cargaContenidoXML(url, metodo, parametros, contentType, sincrona);
}

net.CargadorContenidosCompleto.prototype = { 
	cargaContenidoXML: function(url, metodo, parametros, contentType, sincrona) {
		/*
		try {
			// Firefox, Opera 8.0+, Safari
			this.req = new XMLHttpRequest();
			alert('entroFF');

		} catch (e){
			// Internet Explorer
			try {
				this.req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					this.req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					alert("Tu navegador no soporta AJAX!");
					return false;
				}
			}
			alert('entroExp');
		}
		*/
		
		if (window.XMLHttpRequest) {
			this.req = new XMLHttpRequest(); 
			//alert('entroFF2');
		} else if (window.ActiveXObject) {
			this.req = new ActiveXObject("Microsoft.XMLHTTP"); 
			//alert('entroExp2');
		} 
		
		if(this.req) { 
			try {
				var loader = this;
				
				this.req.open(metodo, url, (sincrona===false)?false:true);
				if(contentType) {
					this.req.setRequestHeader("Content-Type", contentType);
				}
				this.req.onreadystatechange = function() { 
					loader.onReadyState.call(loader); 
				} 
				this.req.send(parametros);

			} catch (err) { 
				alert(err);
				this.onerror.call(this);
			} 
		}
	},

	onReadyState: function() {
		var req = this.req; 
		var ready = req.readyState; 
		//alert('entro ' + ready);
		
		switch (ready) {
			case net.READY_STATE_LOADING:
				//document.write('sip');
			break;
			case net.READY_STATE_COMPLETE:
				var httpStatus = req.status; 
				if(httpStatus == 200 || httpStatus == 0) { 
					this.onload.call(this);
				}
				else if (httpStatus == 404) {
					alert("La página no existe");
				} else { 
					alert(httpStatus);
					this.onerror.call(this);
				} 
			break;
		}
		/*
		if (ready == net.READY_STATE_COMPLETE) { 
			var httpStatus = req.status; 
			if(httpStatus == 200 || httpStatus == 0) { 
				this.onload.call(this);
			}
			else if (httpStatus == 404) {
				alert("La página no existe");
			} else { 
				alert(httpStatus);
				this.onerror.call(this);
			} 
		} 
		*/
	}, 

	defaultError: function() { 
		alert("Se ha producido un error al obtener los datos" 
				+ "\n\nreadyState: " + this.req.readyState 
				+ "\nstatus: " + this.req.status 
				+ "\nheaders: " + this.req.getAllResponseHeaders()
				+ "\nurl: " + this.url
				); 
	} 
}

