function expandCollapse(div,changeImage){
	toggleDiv(div);
}
function getObject(id){
	if(typeof(id)!='object'){
		return ocument.getElementById(id);
	}
	return id;
}
function verPagina(nombre,div){
	if(typeof(div)=='undefined'){
		div='nivel5';
	}
	div=new String(div);
	if(div.indexOf('nivel')==0){
		if(document.getElementById(div) ){
			var funct=function callResizeColumns(){
				resizeColumns(div);
			}
			loadPage('index.php?do=admin.verPagina','id='+nombre,div,false,true,funct);
			return;
		}
		document.location.href='static/'+nombre;
		return;
	}
	if(div=='blank'){
		//implementar abrir en nueva ventana
	}
	if(document.getElementById(div) ){
		loadPage('index.php?do=admin.verPagina','id='+nombre,div,false,true);
		return;
	}
	alert('bloque \''+div+'\' no encontrado');
	return;
}
function resizeColumns(nivel){
	var maxSize=300;
	var div;
//	var divNames=new Array('nivel3','menuIzquierdo','nivel4','menuDerecho','nivel5');
	var divNames1=new Array('menuIzquierdo','menuDerecho',nivel);
	var divNames2=new Array('nivel3','nivel4','nivel5');
	for(x in divNames1){
		div=document.getElementById(divNames1[x]);
		if(div){
			maxSize=Math.max(maxSize,parseInt(div.offsetHeight));
		}
	}
	for(x in divNames2){
		div=document.getElementById(divNames2[x]);
		if(div){
			div.style.height=maxSize+'px';
		}
	}
}
function verPagina2(nombre,contenedor){
	if(!contenedor){
		contenedor='mainCommand';
	}
	loadPage('index.php?do=verPagina','id='+nombre,contenedor,false,true);
}
function editarNodoWeb(params){
	var contenedor='celdaEdicionDerecha';
	loadCommand('editarNodoWeb',params,contenedor);
}
function editarCarpeta(id){
	var params="id="+id;
	editarNodoWeb(params);
}
function editarPagina(id){
	var params="id="+id;
	editarNodoWeb(params);
}
function editarPrograma(id){
	var params="id="+id;
	editarNodoWeb(params);
}
function agregarCarpeta(idPadre){
	var params="id=NUEVA&idNodoWebPadre="+idPadre+"&tipo=Carpeta";
	editarNodoWeb(params);
}
function agregarPagina(idPadre){
	var params="id=NUEVA&idNodoWebPadre="+idPadre+"&tipo=Pagina";
	editarNodoWeb(params);
}
function agregarPrograma(idPadre){
	var params="id=NUEVA&idNodoWebPadre="+idPadre+"&tipo=Programa";
	editarNodoWeb(params);
}


function elegirDiv(selectInput,inline){
	if(typeof(selectInput)!='object'){
		selectInput=document.getElementById(selectInput);
	}
	for(x=0;x<selectInput.length;x++){
		if(dv=document.getElementById(selectInput.options[x].value)){
			ocultarDiv(dv);
		}
	}
	if(dv=document.getElementById(selectInput.value)){
		mostrarDiv(dv,inline);
	}
}



function winOpen(url,tgt,par){
	window.open(url,tgt,par);
}

/*funcion que carga command+params dentro de un div especifico (id=idDiv)
 no muestra resultados
 */
function runCommand(commandName,params,idDiv){
	loadPage('index.php?do='+commandName,params,idDiv,false,false);
}
/*funcion que carga command+params dentro de un div especifico (id=idDiv)
muestra mientras se carga y muestra cuando esta listo
 */
function loadCommand(commandName,params,idDiv,showLoading){
	loadPage('index.php?do='+commandName,params,idDiv,showLoading,true);
}
// ----------------------------------------------------------------------------------------------------------
function loadTab2(commandName,params,tab){
	if(typeof(tab)!='object'){
		tab=document.getElementById(tab);
	}
	tabSet=tab.parentNode;
	tabContentId='c_'+tabSet.id;
	elem=tabSet.childNodes;
	for(x=0;x<elem.length;x++){
		if(elem[x].className=="front"){
			elem[x].className="back";
			break;
		}
	}
	tab.className="front";
	loadPage('index.php?do='+commandName,params,tabContentId,false,true);
}
/*Funcion que envia el formulario indicado para ser procesado por el commandName.
El resultado se inserta en el div contenedor del formulario.
*/
function verContenido(nombre,contenedor){
	loadPage('index.php?do=contenido.verContenido','nombre='+nombre,contenedor,false,true);
}


/*
codigo copiado desde:
http://www.webdeveloper.com/forum/showthread.php?t=32317
para la inclusión de tabs dentro de textarea y evitar perder el foco
*/
function setSelectionRange(input, selectionStart, selectionEnd) {
	if (input.setSelectionRange) {
		input.focus();
		input.setSelectionRange(selectionStart, selectionEnd);
	}else if (input.createTextRange) {
		var range = input.createTextRange();
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}
}

function replaceSelection (input, replaceString) {
	if (input.setSelectionRange) {
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd);
		if (selectionStart != selectionEnd){ 
			setSelectionRange(input, selectionStart, selectionStart + 	replaceString.length);
		}else{
			setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length);
		}
	}else if (document.selection) {
		var range = document.selection.createRange();
		if (range.parentElement() == input) {
			var isCollapsed = range.text == '';
			range.text = replaceString;
			 if (!isCollapsed)  {
				range.moveStart('character', -replaceString.length);
				range.select();
			}
		}
	}
}


// We are going to catch the TAB key so that we can use it, Hooray!
function catchTab(item,e){
	if(navigator.userAgent.match("Gecko")){
		c=e.which;
	}else{
		c=e.keyCode;
	}
	if(c==9){
		replaceSelection(item,String.fromCharCode(9));
		setTimeout("document.getElementById('"+item.id+"').focus();",0);	
		return false;
	}
}
/*fin de funciones para incluir tabulaciones en textarea*/
function updateModificado(obj){
	objeto=getObject(obj);
	objeto.value="1";
}

function resizeBorderE(){
	/*altura de borde sombreado derecho (hack for IE)*/
	var border_e=document.getElementById('border_e');
	var cajaSombra=border_e.parentNode;
	border_e.style.height=cajaSombra.offsetHeight-15;
}
function getObject(obj){
	if(typeof(obj)!='object'){
		obj=document.getElementById(obj);
	}
	return (obj);
}
function loadTab(commandName,tab){
	if(typeof(tab)!='object'){
		tab=document.getElementById(tab);
	}
	loadPage('index.php?do='+commandName,'','mainCommand',true);
//	loadCommand('public.comoDonar','','mainCommand',true);
	activarTab(tab);
}
function activarTab(tab){
	var menuSuperior=document.getElementById('menuSuperior');
	tab.className=tab.className+'Activa';
}
function resetMenu(){
	var menu=document.getElementById('menuIzquierdo');
	var botones=menu.childNodes;
/*getProp(botones,'test');*/
	for(x=0;x<botones.length;x++){
		if(botones[x].className=='opcionIzqActiva'){
			botones[x].className='opcionIzq';
			return;
		}
	}
}
function cargaModulo(commandName,clickedTab){
	var tab=getObject(clickedTab);
	resetMenu();
	loadPage('index.php?do='+commandName,'clearlayout=1','mainCommand',false,true);
	tab.className='opcionIzqActiva';
}

function getReturnData( jsCode , statusCode , statusMessage){
alert(jsCode);
	if( statusCode == AJForm.STATUS['SUCCESS'] ) {
		eval(jsCode);
		return returnValue;
	}else{
		alert("Error de conexion, no se pueden\nenviar los datos del formulario");
		return false;
	}
}
function selectByVal(idSelect,val){
	sel=document.getElementById(idSelect);
	if(!sel){
		return false;
	}
	for(x=0;x<sel.length;x++){
		if(sel[x].value==val){
			sel[x].selected=true;
			return true;
		}
	}
}
function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57)){
		return false;
	}
	return true;
}
function esDigitoVerificador(evt){
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	if(charCode==107 || charCode==75){
		return true;
	}
	if (charCode > 31 && (charCode < 48 || charCode > 57)){
		return false;
	}
	return true;
}