function ajax(URL) {
    var req = false;
	if (window.XMLHttpRequest) {  
		req = new XMLHttpRequest();
		if (req.overrideMimeType) {
			req.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject) { 
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if (!req) { 
		return false;
	}
	
	req.open('GET', URL, false);
	req.send(null);
	return req;
};

function Numerico(e) 	{
	key=(document.all) ? e.keyCode : e.which;
	if ((key==33||key==34||key==35||key==36||key==37||key==38||key==39||key==40||key==41||key==42||key==43||key==44||key==45||key==46||key==47||key>57)) {
		return false;
	}
	return true;
	//onkeypress="return Numerico(event)"
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function pop(URL,nm,w,h,x,y) {
	if (w=="") {w=300;}
	if (h=="") {h=300;}
	if (x=="") {x=300;}
	if (y=="") {y=300;}
	var Atributos = "";
	Atributos += "height=" + h + ",";
	Atributos += "width=" + w + ",";
	Atributos += "top=" + y + ",";
	Atributos += "left=" + x + ",";
	Atributos += "location=no,";
	Atributos += "resizable=no,";
	Atributos += "scrollbars=no,";
	Atributos += "menubar=no,";
	Atributos += "status=no,";
	Atributos += "toolbar=no";
	nm=window.open(URL,nm,Atributos);
	nm.focus();
};

function pop2(URL,nm,w,h,x,y) {
	if (w=="") {w=300;}
	if (h=="") {h=300;}
	if (x=="") {x=300;}
	if (y=="") {y=300;}
	var Atributos = "";
	Atributos += "height=" + h + ",";
	Atributos += "width=" + w + ",";
	Atributos += "top=" + y + ",";
	Atributos += "left=" + x + ",";
	Atributos += "location=no,";
	Atributos += "resizable=no,";
	Atributos += "scrollbars=yes,";
	Atributos += "menubar=no,";
	Atributos += "status=no,";
	Atributos += "toolbar=no";
	nm=window.open(URL,nm,Atributos);
	nm.focus();
};


//############################
//####### MENU
//############################

var tiempoabierto=0;
var navegador = navigator.appName;
var UsarTimeouts = true;
var version	= parseFloat(navigator.appVersion.indexOf("MSIE")>0?navigator.appVersion.split(";")[1].substr(6):navigator.appVersion);
if ((navegador != "Microsoft Internet Explorer")||(version < 5)) {  UsarTimeouts = false; }

function ShowMenu(Menu) {
	if (UsarTimeouts == false) {  return; }
	var MenuId = "m" + Menu;
	if (typeof(document.getElementById(MenuId))=="undefined") {  return;  }
	if (tiempoabierto != 0) { clearTimeout(tiempoabierto); }
	document.getElementById(MenuId).style.display = "inline";
	CerrarMenus(Menu);
}

function CerrarMenus(Menu) {
	if (Menu != 1)  { document.getElementById('m1').style.display = "none"; }
	/*if (Menu != 2)  { document.getElementById('m2').style.display = "none"; }
	if (Menu != 3)  { document.getElementById('m3').style.display = "none"; }*/
}

function CerrarMenu() {
	if (UsarTimeouts == false) {  return; }
	tiempoabierto = setInterval(CerrarMenus, 500);
}

function mantenerMenu() { 
		if (UsarTimeouts == false) {  return; }
		if (tiempoabierto != 0) { clearTimeout(tiempoabierto); }
}
// FIN MSIE

function AbreClick(Menu) {
	var MenuId = "m" + Menu;
	//alert(document.getElementById(MenuId).style.display);
	if (document.getElementById(MenuId).style.display == "none" || document.getElementById(MenuId).style.display == "") { document.getElementById(MenuId).style.display = "inline"; }
	else { document.getElementById(MenuId).style.display = "none"; }
	CerrarMenus(Menu);
}
//Fin menu 

function mClk(src) { src.children.tags('A')[0].click(); }

function TdMenuOver(src) {
	src.style.cursor="hand";
	src.style.backgroundColor = "#292929";
	//src.children.tags('A')[0].style.color="#ffcc00";
}

function TdMenuOut(src) {
	src.style.backgroundColor="transparent";
	src.children.tags('A')[0].style.color="#ffffff";
}

// ### FIN MENU

function limitartexto(casilla,longitud,div) {
Cadena = casilla.value;
	if (casilla.value.length > longitud) {
		alert("You have already completed the maximum of allowed characters (" + longitud + ").")
		casilla.value = Cadena.substring(0,longitud);
	}
	document.getElementById(div).innerText="";
	document.getElementById(div).innerText="Written characters " + casilla.value.length + ".";
};

//###################################################
function FillCbo(cbo,Num,url) {
	

	//document.getElementById('ajaxwait').style.display="inline";	
	//document.getElementById('BuscaCombos').style.visibility="hidden";
	
	//Resetea los combos siguientes.
	for (i=0;i<4;i++) {
		if (i > Num) {
			document.getElementById("MIdC"+i).options.length=0;
		}
	}
	
	var nc = parseInt(Math.random()*1000000000);
	if (Num==0) { url += "&md=tipo&id=" + cbo.value + "&nc=" + nc; }
	else { url += "&md=cat&id=" + cbo.value + "&nc=" + nc; }
	
	var docXML = ajax(url);
	var XML = docXML.responseXML;
	
	var NextCboId = "MIdC" +  parseInt(Num+1);
	var miCombo = document.getElementById(NextCboId);
		
	var opciones = XML.getElementsByTagName('op');
	
	for (i=0;i<opciones.length;i++) {
		var texto = opciones[i].getElementsByTagName('txt')[0].childNodes[0].nodeValue;
		var valor = opciones[i].getElementsByTagName('val')[0].childNodes[0].nodeValue;
		if (valor==0) { valor=""; }
		var opcion = new Option(texto,valor);
		miCombo.options.add(opcion);
	}
	
	//document.getElementById('BuscaCombos').style.visibility="visible";
	//document.getElementById('ajaxwait').style.display="none";	
}

