NS=(navigator.appName == "Netscape")?true:false; 

// AbrirVentana: Abre una nueva ventana de navegador
function AbrirVentana(url,poswidth,posheigth)  {
	(NS)? PosX="screenX=" : PosX="left=";
	(NS)? PosY=",screenY=" : PosY=",top=";
	factorancho=parseInt((poswidth/10)+0.5);
	factoralto=parseInt((posheigth/10)+0.5);
	var alto=100+factoralto;
	var ancho=100+factorancho;
	var CVentana='ventana=window.open("","","'+PosX+parseInt((screen.width - poswidth)/2)+PosY+parseInt((screen.height - posheigth)/2)+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+ancho+',height='+alto+'")';
	eval(CVentana);
	ventana.document.write("<br><div class='c'><strong><font color='#18188C'><font size='+1'>CARGANDO. . .</font></font></strong></div>")
	do {
		((ancho+factorancho)<poswidth) ? ancho=ancho+factorancho: ancho=poswidth;
		((alto+factoralto)<posheigth) ? alto=alto+factoralto: alto=posheigth;
		ventana.resizeTo(ancho,alto);
	}
	while ((ancho<poswidth) || (alto<posheigth))
		ventana.location=url;
}

var comboReq;

// fillCombo: Rellena un combo mediante AJAX
function fillCombo(combo, url) {
    var result;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		comboReq = new XMLHttpRequest();
		comboReq.onreadystatechange = function() {
			fillComboChange(combo);
		}
		comboReq.open("GET", url, true);
		comboReq.send(null);
	// branch for IE/Windows ActiveX version
	} 
	else if (window.ActiveXObject) {
		comboReq = new ActiveXObject("Microsoft.XMLHTTP");
		if (comboReq) {
			comboReq.onreadystatechange = function() {
				fillComboChange(combo);			
			}
			comboReq.open("GET", url, true);
			comboReq.send();
		}
	}
}

function fillComboChange(combo) {
	var key, value;
	if (comboReq.readyState == 4) {
		if (comboReq.status == 200) {
			// Combo vacío
			for (i=combo.options.length-1; i>=0; i--) {
				combo.options[i] = null;
			}
			// Rellenar combo
			comboXML = comboReq.responseXML;
			items = comboXML.getElementsByTagName('item');
			for (var i = 0; i < items.length; i++) {
				key = items[i].attributes.getNamedItem('key').value;
				value = items[i].attributes.getNamedItem('value').value;
				combo.options[i] = new Option(value,key);
				if (i % 2 == 0) {
					combo.options[i].className = 'opcion_par';															
			    }
			}
			// Llamada a su onchange
			combo.options[0].selected = true;
			if (combo.onchange) {
				combo.onchange();
			}		
						
		} 
		else {	
		    alert("There was a problem retrieving the XML data:\n" + comboReq.statusText);		    
	    }
	}
}

// Oculta un tag DIV
function hidediv(layer_ref) {
    var state = 'none';
    if (document.all) { //IS IE 4 or 5 (or 6 beta)
        eval( "document.all." + layer_ref + ".style.display = state");
    }
    if (document.layers) { //IS NETSCAPE 4 or below
        document.layers[layer_ref].display = state;
    }
    if (document.getElementById &&!document.all) {
        hza = document.getElementById(layer_ref);
        hza.style.display = state;
    }
}
// Muestra un tag DIV
function showdiv(layer_ref) {
    var state = 'block';
    if (document.all) { //IS IE 4 or 5 (or 6 beta)
        eval( "document.all." + layer_ref + ".style.display = state");
    }
    if (document.layers) { //IS NETSCAPE 4 or below
        document.layers[layer_ref].display = state;
    }
    if (document.getElementById &&!document.all) {
        hza = document.getElementById(layer_ref);
        hza.style.display = state;
    }
} 
// Muestra un tag DIV en línea
function showdivinline(layer_ref) {
    var state = 'inline';
    if (document.all) { //IS IE 4 or 5 (or 6 beta)
        eval( "document.all." + layer_ref + ".style.display = state");
    }
    if (document.layers) { //IS NETSCAPE 4 or below
        document.layers[layer_ref].display = state;
    }
    if (document.getElementById &&!document.all) {
        hza = document.getElementById(layer_ref);
        hza.style.display = state;
    }
} 

