// JavaScript Document
function SwitchMenu(obj, padre){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById(padre).getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

//esta funcion despliega un menu anidado poniendo todos sus items con el color por defecto
//en caso de alguno haya cambiado
//entrada: recibe el id de la etiqueta que contiene todos los <div> de los items; y el color por defecto 
function colorPorDefecto(objeto, colorpordefecto){
	var bloque  = document.getElementById(objeto).getElementsByTagName("div");
	for (var i=0; i<bloque.length; i++){
		if (bloque[i].id)MM_changeProp(bloque[i].id,'','style.backgroundColor',colorpordefecto,'DIV');
	}
}

//esta funcion invoca una jsp sin cambiar el estado del menu 
function vincular(frm, destino, sobrinos){
	frm.action = destino;
	ocultar(sobrinos);
	frm.submit();
	return true;
}

//esta funcion oculta los 
function ocultar(padre){
	var ar = document.getElementById(padre).getElementsByTagName("span"); //DynamicDrive.com change
	for (var i=0; i<ar.length; i++){
		if (ar[i].className=="submenu"||ar[i].id=='menu') //DynamicDrive.com change
		ar[i].style.display = "none";
	}
}

function colorItemSeleccionado(){
	if (colorItemSeleccionado.arguments.length<3){
		alert ('colorItemSeleccionado(listado de items(primero el que cambia), color_que_tiene, color_que_quiero), utilice bien el script');
		return;
	}
	var objetos = colorItemSeleccionado.arguments;
	color_que_tiene = objetos[objetos.length-2];
	color_que_quiero = objetos[objetos.length-1];
	MM_changeProp(objetos[0],'','style.backgroundColor',color_que_quiero,'DIV');	
	for (var i=1; i<objetos.length; i++){
		MM_changeProp(objetos[i],'','style.backgroundColor',color_que_tiene,'DIV');
	}
}


function colorItemSeleccionado1(){
	if (colorItemSeleccionado1.arguments.length<3){
		alert ('colorItemSeleccionado(listado de items(primero el que cambia), color_que_tiene, color_que_quiero), utilice bien el script');
		return;
	}
	var objetos = colorItemSeleccionado1.arguments;
	color_que_tiene = objetos[objetos.length-2];
	color_que_quiero = objetos[objetos.length-1];
	MM_changeProp(objetos[0],'','style.backgroundColor',color_que_quiero,'TR');
	MM_changeProp(objetos[0],'','style.borderColor',color_que_quiero,'TR');	
	for (var i=1; i<objetos.length; i++){
		MM_changeProp(objetos[i],'','style.backgroundColor',color_que_tiene,'TR');
		MM_changeProp(objetos[i],'','style.borderColor',color_que_tiene,'TR');
	}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function hacerSubmit(frm){
	frm.submit();
	//return true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function enviar(frm){
	if(frm.usuario.value==""||frm.clave.value==""){
		alert('Debe ingresar un nombre de usuario y una contraseņa');
	}else{
		frm.submit();
		return true;
	}
}

function cambiarImagen(img){
	miNuevoSrc = img.src;
	indice = miNuevoSrc.length-9;
	final = miNuevoSrc.substring(indice, miNuevoSrc.length);
	if (final!='SELEC.gif'){	
		ind = miNuevoSrc.length-4;
		miNuevoSrc = miNuevoSrc.substring(0, ind)+'_SELEC.gif';
		img.src = miNuevoSrc;
	}
}

function cuadrar_resto(id_quieto){
	if(document.getElementById){
		var el = document.getElementById('columna');
		var ar = document.getElementById('columna').getElementsByTagName("img"); //DynamicDrive.com change
		for(i=0;i<ar.length;i++){
			if(id_quieto!=ar[i].id)
			{
				source = ar[i].src
				ind = source.length-4;
				isSelec = source.substring(ind-5, ind);
				if (isSelec=='SELEC'){
					ruta = source.substring(0, ind-6)+'.gif';
					ar[i].src = ruta;
				}
			}
		}
	}		
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function cuadrarItemsMenu(idn){
	MM_changeProp(idn,'','style.backgroundColor','#CCCCCC','DIV');
	MM_changeProp(idn,'','style.borderColor','#CCCCCC','DIV');
	var bloque = document.getElementById("submenu1").getElementsByTagName("div");
	for (i=0; i<bloque.length;i++){
		if(bloque[i].id!=idn){
			MM_changeProp(bloque[i].id,'','style.backgroundColor','#E6E6E6','DIV');
			MM_changeProp(bloque[i].id,'','style.borderColor','#E6E6E6','DIV');			
		}
	}
}

