var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;
var http_request = getXMLHTTPRequest();

/*window.onresize = function () {
	 //alert("cambio de tamaņo");
	 
	 var ventanaObj=parent.document.getElementById("boletinBtn");
	 //ventanaObj.style.width=(document.body.clientWidth-23);
	 var anchoDynamic=(document.body.clientWidth-980)/2;
	  
	 ventanaObj.style.left=(anchoDynamic+10);
	
	  // ventanaObj.style.display="block";
}*/



function getXMLHTTPRequest() {
   if (window.XMLHttpRequest) {
       return new XMLHttpRequest();
    }else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
}
 

function ejecutaAjax(url,accion,funcion,params){
	 url=url+accion;
     if(http_request) {
	     http_request.open('GET', url, true);
	     http_request.send(null);
	     http_request.onreadystatechange = funcion;
	    
     }
} 


var anchoTotal=screen.availWidth;
var altoTotal=screen.availHeight;

function muestraSubmenu(nombreDiv){
  var divObj = document.getElementById(nombreDiv);
	if(divObj.style.display=="none"){
		divObj.style.display="block";
	}else{
		divObj.style.display="none";
	}  
}

function contraerDiv(nombreDiv){

	var divObj = document.getElementById(nombreDiv);
	if(divObj.style.display=="none"){
		divObj.style.display="block";
	}else{
		divObj.style.display="none";
	}
}
function muestraOcultaFrame(nombreDiv,url){
  var divObj = document.getElementById(nombreDiv+"_div");
  var frameObj = document.getElementById(nombreDiv+"_frame");
 
  
	if(divObj.style.display=="none"){
		divObj.style.display="block";
	}else{
		divObj.style.display="none";
	}
}

function cargaFramesInicial(url0,url1){

     var frameList=document.getElementsByTagName("IFRAME");
     var res=frameList[0].src
     alert(frameList.length);

   
         frameList[0].src=url0;
         frameList[1].src=url1;
       

}


var transicionBackground = null;
var transicionColor = null;
function seleccionarRenglon(indice) {
	var renglon = document.getElementById("id"+indice);   
	transicionBackground = renglon.style.backgroundColor;
	transicionColor = renglon.style.color;
	renglon.style.backgroundColor = "#daa25a";
	renglon.style.color = "#FFFFFF";
}

function deseleccionarRenglon(indice) {
    var renglon = document.getElementById("id"+indice);
	renglon.style.backgroundColor = transicionBackground;
	renglon.style.color = transicionColor;
}

function cambiarRollover(categoria,id) {  
	fotoCatego = document.getElementById(id);
	if (categoria=="ins"){
		fotoCatego.src = "imagenes/botones/insertarOver.png";
	}else if (categoria=="insBorrar") {
		fotoCatego.src = "imagenes/botones/insertarUp.png";
	}else if (categoria=="bor") {
		fotoCatego.src = "imagenes/botones/borrarOver.png";
	}else if (categoria=="borBorrar") {
		fotoCatego.src = "imagenes/botones/borrarUp.png";
	}else if (categoria=="AceptarOver") {
		fotoCatego.src = "imagenes/botones/btnAceptarOver.png";
	}else if (categoria=="AceptarOut") {
		fotoCatego.src = "imagenes/botones/btnAceptarUp.png";
	}else if (categoria=="catalogoOver") {
		fotoCatego.src = "imagenes/botones/catalogoOver.png";
	}else if (categoria=="catalogoOut") {
		fotoCatego.src = "imagenes/botones/catalogoUp.png";
	}else if (categoria=="posOver") {
		fotoCatego.src = "imagenes/botones/posOver.png";
	}else if (categoria=="posOut") {
		fotoCatego.src = "imagenes/botones/posUp.png";
	}else if (categoria=="usuariosOver") {
		fotoCatego.src = "imagenes/botones/usuariosOver.png";
	}else if (categoria=="usuariosOut") {
		fotoCatego.src = "imagenes/botones/usuariosUp.png";
	}else if (categoria=="inventarioOver") {
		fotoCatego.src = "imagenes/botones/inventarioOver.png";
	}else if (categoria=="inventarioOut") {
		fotoCatego.src = "imagenes/botones/inventarioUp.png";
	}else if (categoria=="ventasOver") {
		fotoCatego.src = "imagenes/botones/ventasOver.png";
	}else if (categoria=="ventasOut") {
		fotoCatego.src = "imagenes/botones/ventasUp.png";
	}else if (categoria=="devoOver") {
		fotoCatego.src = "imagenes/botones/devoOver.png";
	}else if (categoria=="devoOut") {
		fotoCatego.src = "imagenes/botones/devoUp.png";
	}else if (categoria=="modificarOver") {
		fotoCatego.src = "imagenes/botones/modificarOver.png";
	}else if (categoria=="modificarOut") {
		fotoCatego.src = "imagenes/botones/modificarUp.png";
	}							
}//EndFUNCTION
            


function verificarCheck(form, permisos){
	var valorCheck = document.getElementsByName("perms");
	if (permisos && valorCheck) {
			for (i = 0; i < valorCheck.length; i++) {
				for (j = 0; j < permisos.length; j++) {
					if (valorCheck[i].value == permisos[j]) {
						form.perms[i].checked="checked";
						break;
					}
				}
			}
	}
}

function checkEnter(form,event) { 	
	var code = 0;
	if (event && event.which) {
		code = event.which;
	} else if (window.event && window.event.keyCode) {
		code = window.event.keyCode;
	}
	if (code==13)
		submitForm(form,'autentificaUsuario','');
}

function AceptaSoloTeclaNumerica(event){

	if (!event) var event = window.event;
	if(event.keyCode >= 48 && event.keyCode <= 57)
	  	event.returnValue = true;
  	else
		event.returnValue = false;
}

function eliminaCatalogo(form){
	var check = document.getElementsByName("checks");
	if(check){
		var ids = "";
		for(i = 0; i < check.length; i++){
			if(check[i].checked){
				ids += check[i].value + ",";
			}
		}
		ids = ids.substring(0,ids.length-1);
		if(ids == ""){
			alert("No has seleccionado ningun registro...");
		}else{
			if(confirm("Estas seguro que deseas eliminar los registros seleccionados?")){
				form.accion.value = "eliminarRegistros";
				form.idLink.value = ids;
				form.submit();
				
			}
		}
	}
}

function obtenCalendario(field){
 Calendar.setup({
					        inputField     :    field,
					        ifFormat       :    "%d/%m/%Y",
					        button         :    field,
					        align          :    "Br", 
					        weekNumbers	   :	false,
					        showOthers     :    true,
					        singleClick    :    true
					    });
}


function mostrarDiv(div1,div2){
       var divMostrar = document.getElementById(div1);
       var divOcultar = document.getElementById(div2);
       document.body.style.cursor="pointer";
       with(divMostrar.style){
			display="block";
			}
	   with(divOcultar.style){
			display="none";
			}

}

function ocultarDiv(){
       var divOcultar = document.getElementById(div);
       with(divOcultar.style){
			display="none";
			}
}

function teclaSumarRestar(idMerc,ctrl){
         // alert(ctrl);
          document.onkeydown = checkKeycode;	
       function checkKeycode(e) {
             var keycode;
             if (window.event) keycode = window.event.keyCode;
             else if (e) keycode = e.which;
             
             //restar(189,109="-")
             if (keycode == 189 || keycode == 109){
              eliminaExistencia(idMerc,ctrl);
          
             }
             //restar(187,107="+")
             else if (keycode == 187 || keycode == 107){
              agregaExistencia(idMerc,ctrl);
           
             }
             }
}




var muestraOculta=0;
function desplazarPrueba(div){
     var divObj=document.getElementById(div);
   
     if(muestraOculta==0){
      if(divObj.style.position=="absolute"){
        divObj.style.left="1px";
       divObj.style.top="-17px";
       divObj.style.position="relative";
        }else{
       divObj.style.left="-170px";
       divObj.style.top="95px";
       divObj.style.position="absolute";
       muestraOculta=1;
       
      }
     }else if(muestraOculta==1){
        
       divObj.style.left="1px";
       divObj.style.top="-17px";
       divObj.style.position="relative";
       muestraOculta=0;
     }
}

function desacoplarPanel(div){
      var divObj=document.getElementById(div);
       divObj.style.left="1px";
       divObj.style.top="113px";
       divObj.style.position="absolute";
      
}




function modificaMenu(form,obj1,obj2,id){
	var res=document.forms[0].btnMenuTxt.length;
    var listaVacios=new Array();
    var html1="";
    
    if(obj1=="borrar"){
    	var nombreBoton=document.forms[0].btnMenuTxt[id].value;
    	alert(document.forms[0].btnMenuTxt[id].value);
    	
    	ejecutaAjax("ManejadorAjax?accion=borraCarpeta&cadena=",nombreBoton,generaRes);
    	
    	
    	
    	 var tbody = document.getElementById("tablaListaBtnMenu").getElementsByTagName("TBODY")[0];
  	   var tR = document.getElementById("tablaListaTR"+id);
  	  tbody.removeChild(tR);
  	  
  	 // ejecutaAjax("ManejadorAjax?accion=borraCarpeta&cadena=",nombreBoton,generaRes);
    	
    }
    
    res=document.forms[0].btnMenuTxt.length;
    var i=0;
    for(i=0;i<res;i++){
    var sse=parseInt(i)+1;	
    if(document.forms[0].btnMenuTxt[i].value==""){
    	alert("campo Vacio N:"+sse);
    }
    
    }
    
    
   if(res==null){
    res=1;
    if(document.forms[0].btnMenuTxt.value==""){
       html1+="sinCategos";
       
       alert(html1);
     
    }else{
    html1+=document.forms[0].btnMenuTxt.value;
    alert(html1);
    	
    }
    }else{

    
     var iter=0;
     for(i=0;i<res;i++){
       
        if(document.forms[0].btnMenuTxt[i].value==""){
        iter++;
        }else{
        	html1+=document.forms[0].btnMenuTxt[i].value + ",";
        }
     }
   
     if(iter==res){
       html1="sinCategos,";
       }
     var cad=html1.substring(0, html1.length-1);
    // alert(cad+"--aqui");
     ejecutaAjax("ManejadorAjax?accion=actualizaMenu&cadena=",cad,generaRes);
     	
     }
}

function generaRes(){

    if(http_request.readyState == READY_STATE_COMPLETE) {
    if (http_request.status == 200) {
    	var resultDiv=document.getElementById("objeto");
    	var frameRes=parent.document.getElementById("div2_frame");
    	var flashMovie=parent.document.getElementById("menuLateral");
    	//var res=http_request.responseText;
    	
    	//alert("goood!::"+res);
    	
    	frameRes.src="menuPrincipal.jsp";
    	
    cargaFlash();
    cargaIFramePrincipal('menu.midiat?accion=mostrarMenuConfig');
    	
    }
    }
	
}

//antes modifPedidod en larueca
function eliminaBtnMenu(obj1,id,code){

	 var n=document.getElementsByName(obj1);
	 
	   var tbody = document.getElementById(obj1).getElementsByTagName("TBODY")[0];
	   var tR = document.getElementById("tablaListaTR"+id);
	  tbody.removeChild(tR);
	  
	  
	}



function cargaIFramePrincipal(url){ 
	   var iFramePrincipal = document.getElementById("iFramePrincipal"); 
	   if(iFramePrincipal==null){
		   var iFramePrincipal = parent.document.getElementById("iFramePrincipal"); 
	   }
	    iFramePrincipal.src = url;
	} 

function cropFrame(obj1,obj2){
	
	var ras=document.getElementById(obj1);
    
  
    ras.height=obj2;
	
	
}

function cargaFlash() {
	//valor hidden
	var listaBtns=document.getElementById("listaBotones").value;
	
//var res="uno,dos,tres";

return listaBtns;
 
}


function agregarBotonesTxt(categoActuales,form,div){
   var res=document.forms[0].btnMenuTxt.length;
   //var valor=document.forms[0].btnMenuTxt[0].value;
   var resultDiv=document.getElementById(div);
   var lista=new Array();
 
 
 textohtml="<table>";
 
  if(res==null){
  res=1;
  lista[0]=document.forms[0].btnMenuTxt.value;
  //alert(lista[0]);
  }else{
  
   
   var i=0;
   for(i=0;i<res;i++){
     lista[i]=document.forms[0].btnMenuTxt[i].value;
   
   }
   
   }
 
   i=0;
   for(i=0;i<res+1;i++){
   
     textohtml+="<tr>";
    
     if(lista[i]==null){
         textohtml+="<td width='20px' align='right'>";
         textohtml+=i+1+"</td>";
         textohtml+=" <td> <input type='text' id='btnMenuTxt' size='13' value=''/> </td>";
     
     }else{
         textohtml+="<td width='20px' align='right'>";
         textohtml+=i+1+"</td>";
         textohtml+=" <td> <input type='text' id='btnMenuTxt' size='13' value='"+lista[i]+"'/> </td>";
       
     }
   
     textohtml+="</tr>";
    
   }
   textohtml+="</table>";
   resultDiv.innerHTML=textohtml;   

}

function eliminaBotonesTxt(form,div){
   var res=document.forms[0].btnMenuTxt.length;
   var valor=document.forms[0].btnMenuTxt[0].value;
   var resultDiv=document.getElementById(div);
   
  if(res!=1){
   var lista=new Array();
   textohtml="<table>";
   var i=0;
   for(i=0;i<res;i++){
   lista[i]=document.forms[0].btnMenuTxt[i].value;
   }
  
   i=0;
   for(i=0;i<res-1;i++){
   
     textohtml+="<tr>";
     textohtml+="<td>";
     if(lista[i]==null){
         textohtml+="<td width='20px' align='right'>";
         textohtml+=i+1+"</td>";
         textohtml+=" <td> <input type='text' id='btnMenuTxt' size='13' value=''/> </td>";
        
     
     }else{
         textohtml+="<td width='20px' align='right'>";
         textohtml+=i+1+"</td>";
         textohtml+=" <td> <input type='text' id='btnMenuTxt' size='13' value='"+lista[i]+"'/> </td>";
         
     }
     textohtml+="</td>";
     textohtml+="</tr>";
    
   }
   textohtml+="</table>";
   resultDiv.innerHTML=textohtml;   
   }
}



function textVacio(obj1,obj2){
     var res=document.forms[0].btnMenuTxt.length;
     
  if(res==null){
	  
      res=1;
  
      if(document.forms[0].btnMenuTxt.value==""){
          document.forms[0].btnMenuTxt.value=obj2;
          }
     
     }else{
    	
     if(document.forms[0].btnMenuTxt[obj1].value==""){
        document.forms[0].btnMenuTxt[obj1].value=obj2;
     }
     }

}

function validarGuestbook(form1, accion1){
	//alert(accion1);
	var form=document.getElementById(form1);
	if(accion1=="insertarMensajeTmp"){

	    if(form.nombre.value==""){
	      alert("Nombre vacio!");
	    }else if(form.contenido.value==""){
	      alert("Mensaje vacio!");
	    }
	    else{
	    	
	
	    	submitForm(form,accion1,null);
	    	
	    }
	    
	    
	    } 
	  
	  
	}

/*function cargarPass(){
  var usuarioText=document.getElementById("usuarioTxt");
  var passText=document.getElementById("passTxt");
  
  usuarioText.value="xgress";
  passText.value="cxggcxgg";

}*/

function cargaMensajes(res){
	
	ejecutaAjax("ManejadorAjax?accion=muestraMensajes&ctrl=",res,muestraMensajes,"");
	
}

function muestraMensajes(){
	if(http_request.readyState == READY_STATE_COMPLETE) {
	    if (http_request.status == 200) {
	    	var divProductos=document.getElementById("contenedorMensajes");
	    //	var divProductos=document.getElementById("contenedorMensajesTemp");
	    	//var temas=eval("("+http_request.responseText+")");
	    	 var msg = http_request.responseXML.getElementsByTagName("mensajes")[0];
	         // var msg = msgs.getElementsByTagName("mensajes")[0];
	          
	    	//alert(msg.childNodes.length);
	    	 var obj1=document.getElementsByName("tablaMensajes");
	    	
             if(obj1==null){
	            alert("no hay mensajes");
              }
             
             
             
	    	var html1="";
	          var j=1;
	    	 for (var i = 0; i < msg.childNodes.length; i++){
	    		 //ultimo=msg.childNodes.length-1;
	    		 
	    		 
	    		 html1=html1+"<table id='tablaMensajes' name='tablaMensajes' width='400px' border='1'>";
	             html1=html1+"<tr colspan='2'>";
	             html1=html1+"<td width='100%' colspan='2'>";
	             html1=html1 + msg.childNodes[msg.childNodes.length-j].getAttribute('nombre');
	             html1=html1 + "  ("+msg.childNodes[msg.childNodes.length-j].getAttribute('fecha')+")";
	             html1=html1+"</td>";
	             html1=html1+"</tr>";
	             html1=html1+"<tr>";
	             html1=html1+"<td width='100%'>";
	             html1=html1 + msg.childNodes[msg.childNodes.length-j].getAttribute('contenido');
	             html1=html1+"</td>";
	             html1=html1+"<tr>";
	             html1=html1+"</table><br>";
	            
	              j++;
	           }
	    	
	          divProductos.innerHTML=html1;
	    	
	    }
	}
}

function borraMensajes(id , archivo){
	
	ejecutaAjax("ManejadorAjax?accion=borraMensajes&ctrl=",archivo,mensajeBorrado,"");

	
function mensajeBorrado(){
	if(http_request.readyState == READY_STATE_COMPLETE) {
	    if (http_request.status == 200) {
	    	//alert("Mensaje Eliminado!");
	    	var res=document.getElementsByName("tablaMensajesTmp");
	    	//alert(res.length);
	    	//for(var i = 0; i < res.length; i++){
	    		//if(i==id){
	    			
	    			//var mensajeBorrar=document.tablaMensajesTmp[id];
	    			
	    			Effect.toggle(res[id], 'blind', {scaleX: 'false', scaleY: 'true;', scaleContent: true});
	    			
	    		//}
	    		
	    	//}
	    	
	    	
	    	//Effect.toggle(res(id), 'blind', {scaleX: 'false', scaleY: 'true;', scaleContent: true});
	    	
	    }
	}
}
}

function insertaMensaje(form,ctrl){
	
	var res=document.getElementsByName("tablaMensajesTmp");
	
	
	
	if(ctrl=="todos"){
		
			
		
		//Effect.toggle('tablaMensajesTmp1', 'blind', {scaleX: 'false', scaleY: 'true;', scaleContent: true});
		ejecutaAjax("ManejadorAjax?accion=","insertarMensaje",mensajeInsertado,"");
		
		Effect.toggle('contenedorMensajesTemp', 'blind', {scaleX: 'false', scaleY: 'true;', scaleContent: true});
		
		//cargaMensajes('cargar');
		//form.submit()
		//document.forms[0].submit();
		setTimeout("cargaIFramePrincipal('guestbook.midiat?accion=mostrarGuestBook');",4000);

		
		
		
	}
	
	
}

function mensajeInsertado(){
	if(http_request.readyState == READY_STATE_COMPLETE) {
	    if (http_request.status == 200) {
	    	//alert("Mensaje Insertado??!");
	    	//Effect.toggle(id, 'blind', {scaleX: 'false', scaleY: 'true;', scaleContent: true});
	    	
	    }
	}
}

function habilitarInputText(obj1){
    
      var inputText=document.getElementById(obj1);
      inputText.value="";
      inputText.style.color="#000000";
      inputText.style.fontSize="14px";
      inputText.style.fontStyle="normal";

}



