function validarTexto(e) { // 1
	    tecla = (document.all) ? e.keyCode : e.which; // 2	  
	    alert(tecla);   
	     if (tecla==0) return true; // TECLAS DE CTRL
	     if (tecla==241) return true; // 
	     if (tecla==209) return true; // 
	    if (tecla==8) return true; // 3
	    patron =/[A-Za-z\s]/; // 4
	    te = String.fromCharCode(tecla); // 5
	    return patron.test(te); // 6
	} 
	function validarNumero(e) { // 1
	    tecla = (document.all) ? e.keyCode : e.which; // 2
	 
	    if (tecla==8) return true; // 3
	    if (tecla==0) return true; // TECLAS DE CTRL
	    patron =/[0-9.\s]/; // 4
	    te = String.fromCharCode(tecla); // 5
	    return patron.test(te); // 6
	}
	function validarNumeroReal(e) { // 1 	
	    tecla = (document.all) ? e.keyCode : e.which; // 2}
	    //alert(tecla)
	    if (tecla==8) return true; // 3
	    if (tecla==0) return true; // TECLAS DE CTRL
	    //if (tecla==45) return true;
	    //if (tecla==43) return true;	
	    patron =/[-+]?([0-9-.\s])/; // 4
	    te = String.fromCharCode(tecla); // 5
	    return patron.test(te); // 6
	    }
	function validarNumeroEntero(e) { // 1
	    tecla = (document.all) ? e.keyCode : e.which; // 2
	 
	    if (tecla==8) return true; // 3
	    if (tecla==0) return true; // TECLAS DE CTRL
	    patron =/[0-9]/; // 4
	    te = String.fromCharCode(tecla); // 5
	    return patron.test(te); // 6
	} 
		function validarNumeroGuion(e) { // 1
	    tecla = (document.all) ? e.keyCode : e.which; // 2
	 
	    if (tecla==8) return true; // 3
	    if (tecla==0) return true; // TECLAS DE CTRL
	    patron =/[0-9-]/; // 4  
	    te = String.fromCharCode(tecla); // 5
	    return patron.test(te); // 6
	} 
	function validarNumerosLetras(e) { // 1
	    tecla = (document.all) ? e.keyCode : e.which; // 2
	 	//alert(tecla);
	    if (tecla==8) return true; // 3
	    if (tecla==0) return true; // TECLAS DE CTRL
	    patron =/[0-9a-zA-Z\s]/; // 4
	    te = String.fromCharCode(tecla); // 5
	   
	    return patron.test(te); // 6
	} 

function asignaClase(e,c) 
{ 
	for(var q=0;q<e.attributes.length;q++) 
	{ 
		if(e.attributes.item(q).nodeName=="class") 
		{ 
			e.attributes.item(q).nodeValue=c; 
		} 
	} 
} 


////disable right-click
//document.oncontextmenu = function(){
//	alert('Right-click is disabled');
//	window.status = 'Right-click is disabled';
//	return false;
//}
//PARA COPIAR Y PEGAR CON JAVASCRIPT
function copy_to_clipboard(text)
{
    if(window.clipboardData)
    {
	window.clipboardData.setData('text',text);
    }
    else
    {
        var clipboarddiv=document.getElementById('divclipboardswf');
	if(clipboarddiv==null)
	{
	   clipboarddiv=document.createElement('div');
           clipboarddiv.setAttribute("name", "divclipboardswf");
	   clipboarddiv.setAttribute("id", "divclipboardswf");
	   document.body.appendChild(clipboarddiv);
	}
        clipboarddiv.innerHTML='<embed src="images/flash/clipboard.swf" FlashVars="clipboard='+
		encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    }
  //  alert('The text is copied to your clipboard...');
    return false;
}
 
// Documento JavaScript
//PARA OCULTAR O MOSTRAR CAPAS
function mostrar(capa){
  var objE = document.getElementById(capa)
  objE.style.visibility= "visible";
} 

function ocultar(capa){
  var objE = document.getElementById(capa)
  objE.style.visibility= "hidden";  
}

// Esta función cargará las paginas


function llamarasincrono(url, id_contenedor){
var pagina_requerida = false
if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
pagina_requerida = new XMLHttpRequest()
} else if (window.ActiveXObject){ // pero si es IE
try {
pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){ // en caso que sea una versión antigua
try{
pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
pagina_requerida.onreadystatechange=function(){ // función de respuesta
cargarpagina(pagina_requerida, id_contenedor)
}
pagina_requerida.open('GET', url, true) // asignamos los métodos open y send
pagina_requerida.send(null)
}
// todo es correcto y ha llegado el momento de poner la información requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor){
if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(id_contenedor).innerHTML=pagina_requerida.responseText
}




var peticion = false; 

if (window.XMLHttpRequest) {
      peticion = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
            peticion = new ActiveXObject("Microsoft.XMLHTTP");
}


function MandaInfoHTML(info,divID)
{
	
	var obj = document.getElementById(divID);
	obj.innerHTML = info;	
}
function ObtenerDatosMultiple(datos,divID,posAr) {

	var obj = document.getElementById(divID);
	var varAjax = new Array();
	varAjax[posAr]=nuevoAjax();	
	//aqui creamos una instancia del objeto ajax	
	varAjax[posAr].open("GET", datos);
	
	varAjax[posAr].onreadystatechange = function() {
	 
		if (varAjax[posAr].readyState < 4) {                
					    obj.innerHTML = "<img src ='images/varias/ajax-loader-combos.gif'> Cargando ...";
		          }
		if (varAjax[posAr].readyState==4) {
			
		  		  temp = (varAjax[posAr].responseText);	          	  
				  var encuentra1 = temp.indexOf("<script>");				 		
				  temp = temp.substring(encuentra1);
				  var encuentra2 = temp.indexOf("</script>");				  			  
				  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  eval(temp.substring(8,encuentra2));	
			   //En esta parte del código, se revisa cuando el ha sido procesada la carga del AJAX
			   obj.innerHTML = varAjax[posAr].responseText;
			   //CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor"		
		}		
		// aqui se hace el envio del objeto
	}
	varAjax[posAr].send(null);	
}
function ObtenerDatos(datos,divID) { 
	if(peticion) {
		
	     var obj = document.getElementById(divID);
	     var dejaloPasar=true;
	    
	     if (dejaloPasar)
	     {  	     	
	     	 peticion.open("GET", datos); 
		     peticion.onreadystatechange = function()  {
		    
		     	  
			 	  if (peticion.readyState < 4) {     
			 	  	
			 	  	           
					    obj.innerHTML = "<center><img src ='images/varias/ajax-loader.gif'><br>Cargando Informaci&oacute;n...</center>";
					 if (peticion.readyState == 1)      
					{
						try
						{
						 temp = (peticion.responseText);	          	  
						  var encuentra1 = temp.indexOf("<div");				 		
						  temp = temp.substring(encuentra1);
						  var encuentra2 = temp.indexOf("</div>");
						  		  			  
						  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:
						  {						  
							  obj.innerHTML +=(temp.substring(encuentra1,encuentra2)); 
						  }
						}
						catch (e)
						{
						}
					}   
			        	 
		          }
			 
		          if (peticion.readyState == 4) {
		        	  
					//PINTAMOS CONTENIDO:
			          obj.innerHTML = peticion.responseText;
			          //SCRIPTS QUE SE EJECUTEN ANTES DE PINTAR PAGINA
		        	  temp = (peticion.responseText);	          	  
					  var encuentra1 = temp.indexOf("<script>");				 		
					  temp = temp.substring(encuentra1);
					  var encuentra2 = temp.indexOf("</script>");				  			  
					  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:
					  {						  
//						  alert('AQUI SI ENTRA');
						  eval(temp.substring(8,encuentra2));
//						  alert('AQUI YA NO ENTRA');
						  //obj.innerHTML =temp.substring(8,encuentra2);
					  }
			          
			        //	SCRIPTS QUE SE EJECUTEN DEPUES DE PINTAR PAGINA
			          
			          temp = (peticion.responseText);
					  var encuentra3 = temp.indexOf("<script language=javascript>");				 		
					  temp = temp.substring(encuentra3);
					  var encuentra4 = temp.indexOf("</script>");				  			  
					  if (encuentra3 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  {			
//						  alert (temp.substring(28,encuentra4));
						  eval(temp.substring(28,encuentra4));
//						  obj.innerHTML +=temp.substring(28,encuentra4);
						  //obj.innerHTML = peticion.responseText;
					  }
					  temp = (peticion.responseText);
					 
					  var encuentra3 = temp.indexOf("<script type='text/javascript'>");				 		
					  temp = temp.substring(encuentra3);
					  var encuentra4 = temp.indexOf("</script>");				  			  
					  if (encuentra3 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  {			
//						  alert (temp.substring(31,encuentra4));
						  eval(temp.substring(31,encuentra4));
//						  obj.innerHTML +=temp.substring(28,encuentra4);
						  //obj.innerHTML = peticion.responseText;
					  }
					 
					 
		          	          
		          	
		          } 
		     } 
	     }
	peticion.send(null); 
	}
}
function ObtenerDatosPopups(datos,divID) { 
	if(peticion) {
		 var grid="";
		//BORRAMOS LOS GRID DE AJAX: 
    	 var objGrid = document.getElementById("grid");
     	   objGrid.innerHTML="";
	     var obj = document.getElementById(divID);
	     var dejaloPasar=true;
	     var encuentracrit = datos.indexOf("criterio=");
	     var encuentrabuscx = datos.indexOf("buscx=");
       	 if (encuentracrit > 0) //SI ENCONTRO LA VARIABLE CRITERIO QUE VALIDE	
         {	         	
        	if(document.getElementById('criterio').value.length<1)		
        	{			
				alertPersonalizado("Busqueda","Debe de introducir un criterio válido","error");
				dejaloPasar=false;
			}	 
			
         }  
         if (encuentrabuscx > 0) //SI ENCONTRO LA VARIABLE BUSCX QUE VALIDE
         {
	         if(document.getElementById('buscx').value=='-1')
				{
					alertPersonalizado("Busqueda","Debe de seleccionar un tipo de búsqueda","error");
					dejaloPasar=false;
				}
		 }  
	     if (dejaloPasar)
	     {  	     	
	     	 peticion.open("GET", datos); 
		     peticion.onreadystatechange = function()  {
		     	 
		     	  
			 	  if (peticion.readyState < 4) {                
					    obj.innerHTML = "<center><img src ='images/varias/ajax-loader.gif'><br>Cargando Informaci&oacute;n...</center>";
					     var objGrid = document.getElementById("grid");
					     	if(objGrid==null)
					     		grid="<div id=grid></div>";
		          }
			 
			     
			        
			 
		          if (peticion.readyState == 4) {
		        	
		        	  
					//PINTAMOS CONTENIDO:
			          obj.innerHTML = peticion.responseText+grid;
			        
		        	  temp = (peticion.responseText);	          	  
					  var encuentra1 = temp.indexOf("<script>");				 		
					  temp = temp.substring(encuentra1);
					  var encuentra2 = temp.indexOf("</script>");				  			  
					  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:
					  {						  
						  eval(temp.substring(8,encuentra2));
					  }
			          
			        //	SCRIPTS QUE SE EJECUTEN DEPUES DE PINTAR PAGINA
			          
			          temp = (peticion.responseText);
					  var encuentra3 = temp.indexOf("<script language=javascript>");				 		
					  temp = temp.substring(encuentra3);
					  var encuentra4 = temp.indexOf("</script>");				  			  
					  if (encuentra3 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  {							  
						  eval(temp.substring(28,encuentra4));
					  }
					  temp = (peticion.responseText);
					  encuentra3 = temp.indexOf("<script language='javascript'>");				 		
					  temp = temp.substring(encuentra3);
					  encuentra4 = temp.indexOf("</script>");				  			  
					  if (encuentra3 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  {							  
						  eval(temp.substring(30,encuentra4));
					  }
					 
					
		          	          
		          	
		          } 
		     } 
	     }
	peticion.send(null); 
	}
}
function cargarContenido(datos,divID,destino){
	var t1, t2, contenedor;
	contenedor = document.getElementById(divID);
	
	ajax=nuevoAjax();
	ajax.open("POST", destino,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(datos)
}

function nuevoAjax(){

  var xmlhttp=false;
  try {
   // Creación del objeto ajax para navegadores diferentes a Explorer
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   // o bien
   try {
     // Creación del objet ajax para Explorer
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) {
     xmlhttp = false;
   }
  }

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
   xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
} 
function ObtenerDatosCombo3(datos,divID) {

	var obj = document.getElementById(divID);
	
	ajax3=nuevoAjax();	
	//aqui creamos una instancia del objeto ajax	
	ajax3.open("GET", datos);
	
	ajax3.onreadystatechange = function() {
	 
		if (ajax3.readyState < 4) {                
					    obj.innerHTML = "<img src ='images/varias/ajax-loader-combos.gif'> Cargando ...";
		          }
		if (ajax3.readyState==4) {
			
		  		  temp = (ajax3.responseText);	          	  
				  var encuentra1 = temp.indexOf("<script>");				 		
				  temp = temp.substring(encuentra1);
				  var encuentra2 = temp.indexOf("</script>");				  			  
				  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  eval(temp.substring(8,encuentra2));	
			   //En esta parte del código, se revisa cuando el ha sido procesada la carga del AJAX
			   obj.innerHTML = ajax3.responseText;
			   //CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor"
			 
		
		}
		
		// aqui se hace el envio del objeto
	}
	ajax3.send(null);
	
	
}
function ObtenerDatosCombo2(datos,divID) {

	var obj = document.getElementById(divID);
	
	ajax2=nuevoAjax();	
	//aqui creamos una instancia del objeto ajax	
	ajax2.open("GET", datos);
	ajax2.onreadystatechange = function() {
	 
		if (ajax2.readyState < 4) {                
					    obj.innerHTML = "<img src ='images/varias/ajax-loader-combos.gif'> Cargando...";
		          }
		if (ajax2.readyState==4) {
			
		  		  temp = (ajax2.responseText);	          	  
				  var encuentra1 = temp.indexOf("<script>");				 		
				  temp = temp.substring(encuentra1);
				  var encuentra2 = temp.indexOf("</script>");				  			  
				  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  eval(temp.substring(8,encuentra2));	
			   //En esta parte del código, se revisa cuando el ha sido procesada la carga del AJAX
			   obj.innerHTML = ajax2.responseText;
			   //CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor"
			 
		
		}
		
		// aqui se hace el envio del objeto
	}
	ajax2.send(null);
	
	
}
function ObtenerDatosCombo(datos,divID) {

	var obj = document.getElementById(divID);
	
	ajax=nuevoAjax();	
	//aqui creamos una instancia del objeto ajax	
	ajax.open("GET", datos);
	
	ajax.onreadystatechange = function() {
	 
		if (ajax.readyState < 4) {                
					    obj.innerHTML = "<img src ='images/varias/ajax-loader-combos.gif'> Cargando ...";
		          }
		if (ajax.readyState==4) {
			
		  		  temp = (ajax.responseText);	          	  
				  var encuentra1 = temp.indexOf("<script>");				 		
				  temp = temp.substring(encuentra1);
				  var encuentra2 = temp.indexOf("</script>");				  			  
				  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  eval(temp.substring(8,encuentra2));	
			   //En esta parte del código, se revisa cuando el ha sido procesada la carga del AJAX
			   obj.innerHTML = ajax.responseText;
			   //CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor"
			 
		
		}
		
		// aqui se hace el envio del objeto
	}
	ajax.send(null);
	
	
}
function ObtenerDatosMultiple(datos,divID,posAr) {

	var obj = document.getElementById(divID);
	var varAjax = new Array();
	varAjax[posAr]=nuevoAjax();	
	//aqui creamos una instancia del objeto ajax	
	varAjax[posAr].open("GET", datos);
	
	varAjax[posAr].onreadystatechange = function() {
	 
		if (varAjax[posAr].readyState < 4) {                
					    obj.innerHTML = "<img src ='images/varias/ajax-loader-combos.gif'> Cargando ...";
		          }
		if (varAjax[posAr].readyState==4) {
			
		  		  temp = (varAjax[posAr].responseText);	          	  
				  var encuentra1 = temp.indexOf("<script>");				 		
				  temp = temp.substring(encuentra1);
				  var encuentra2 = temp.indexOf("</script>");				  			  
				  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  eval(temp.substring(8,encuentra2));	
			   //En esta parte del código, se revisa cuando el ha sido procesada la carga del AJAX
			   obj.innerHTML = varAjax[posAr].responseText;
			   //CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor"		
		}		
		// aqui se hace el envio del objeto
	}
	varAjax[posAr].send(null);	
}
function ObtenerDatosBusquedaCliente(datos) {
	ajaxBusqueda=nuevoAjax();	
	//aqui creamos una instancia del objeto ajax	
	ajaxBusqueda.open("GET", datos);
	ajaxBusqueda.onreadystatechange = function() {
		if (ajaxBusqueda.readyState==4) {
  		  temp = (ajaxBusqueda.responseText);	          	  
		  var encuentra1 = temp.indexOf("<script>");				 		
		  temp = temp.substring(encuentra1);
		  var encuentra2 = temp.indexOf("</script>");				  			  
		  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
			  eval(temp.substring(8,encuentra2));	
	
		}		
		// aqui se hace el envio del objeto
	}
	ajaxBusqueda.send(null);	
}

function ObtenerDatosScriptRemoto(datos,posAr) {
	var ajaxBusqueda = new Array();
	ajaxBusqueda[posAr]=nuevoAjax();	
	//aqui creamos una instancia del objeto ajax	
	ajaxBusqueda[posAr].open("GET", datos);
	ajaxBusqueda[posAr].onreadystatechange = function() {
		if (ajaxBusqueda[posAr].readyState==4) {
  		  temp = (ajaxBusqueda[posAr].responseText);	          	  
		  var encuentra1 = temp.indexOf("<script>");				 		
		  temp = temp.substring(encuentra1);
		  var encuentra2 = temp.indexOf("</script>");				  			  
		  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
			  eval(temp.substring(8,encuentra2));	
	
		}		
		// aqui se hace el envio del objeto
	}
	ajaxBusqueda[posAr].send(null);	
}



function ObtenerDatosTablasAjax(datos,divID,divID2) {

	var obj = document.getElementById(divID);
	var obj2 = document.getElementById(divID2);
	obj2.innerHTML="";
	ajax=nuevoAjax();	
	//aqui creamos una instancia del objeto ajax	
	ajax.open("GET", datos);
	ajax.onreadystatechange = function() {	
	 var objGrid = document.getElementById("grid");
		objGrid.innerHTML="";
		if (ajax.readyState < 4) {                
					    obj.innerHTML = "<img src ='images/varias/ajax-loader-combos.gif'> Cargando ...";
		          }
		if (ajax.readyState==4) {
		  		  temp = (ajax.responseText);	          	  
				  var encuentra1 = temp.indexOf("<script>");				 		
				  temp = temp.substring(encuentra1);
				  var encuentra2 = temp.indexOf("</script>");				  			  
				  if (encuentra1 > 0) //PARA QUE EJECUTE JAVASCRIPTS:		
					  eval(temp.substring(8,encuentra2));	
			   //En esta parte del código, se revisa cuando el ha sido procesada la carga del AJAX
			   obj.innerHTML = ajax.responseText;
			   //CON en esta línea, decimos que pinte el resultado en nuestro div "contenedor"
		
		}
		
		// aqui se hace el envio del objeto
	}
	ajax.send(null);
	return true;
}

function damefecha()
{
	//en estas líneas creamos las fechas 
	miFechaActual = new Date() 
	miFechaPasada = new Date(1998,4,23) 
	
	//extraemos el año de las dos fechas 
	anoActual = miFechaActual.getFullYear() 
	anoPasado = miFechaPasada.getFullYear() 
	
	//extraemos el día mes y año 
	dia = miFechaActual.getDate() 
	mes = parseInt(miFechaActual.getMonth()) + 1 
	
	switch(mes) {
      case 1 :
          nombremes="Enero";
          break;
      case 2 :
          nombremes="Febrero";
          break;
      case 3 :
          nombremes="Marzo";
		  break;
      case 4 :
          nombremes="Abril";
		  break;
      case 5 :
          nombremes="Mayo";
		  break;
      case 6 :
          nombremes="Junio";
		  break;		  		  		  
      case 7 :
          nombremes="Julio";
		  break;		  
      case 8 :
          nombremes="Agosto";
		  break;		  
      case 9 :
          nombremes="Septiembre";
		  break;		  
      case 10 :
          nombremes="Octube";
		  break;		  
      case 11 :
          nombremes="Noviembre";
		  break;		  
      case 12 :
          nombremes="Diciembre";
		  break;		  
      default :
          document.write("Opción por defecto");
          break;
      }
 	ano = miFechaActual.getFullYear() 
	//escribimos la fecha en un formato legible 
	document.write (dia + " de " + nombremes + " del " + ano)
}


function eliminaPersonalizado(texto,laurl)
{	
	Ext.MessageBox.confirm('Confirmación', texto+'?', function(btn){     
    if (btn == 'yes'){
    	ObtenerDatos(laurl,'Principal');
    	retorna= true;  
        // process text value and close...
    }        
	});	
}
function confirmPersonalizado(texto,laurl)
{	
	Ext.MessageBox.confirm('Confirmación', texto, function(btn){     
    if (btn == 'yes'){
    	location.replace(laurl);   	
    	return true;
        // process text value and close...
    }        
    else
    	return false;
	});
	
}
function confirmPersonalizado2(texto,laurlYES,laurlNO)
{	
	Ext.MessageBox.confirm('Confirmación', texto, function(btn){     
    if (btn == 'yes'){
    	location.replace(laurlYES);   	
    	return true;
        // process text value and close...
    }        
    else
    {
    	location.replace(laurlNO);   	
    	return false;
    }
	});	
	
}

function confirmPersonalizadoAcciones(texto,actionYes,actionNO)
{	
	Ext.MessageBox.confirm('Confirmación', texto, function(btn){     
    if (btn == 'yes'){
    	eval(actionYes);
    	return true;
        // process text value and close...
    }        
    else
    {
    	eval(actionNO); 	
    	return false;
    }
	});	
	return false;
}
function alertPersonalizado(titulo,mensaje,icono)
{

	 Ext.MessageBox.show({
           title: titulo,
           msg: mensaje,
           buttons: Ext.MessageBox.OK,     
           icon: "ext-mb-"+icono+""
       });      
}
function alertPersonalizadoAccion(titulo,mensaje,icono,accion)
{
	Ext.Msg.alert(titulo, mensaje, function(btn) {
		if (btn == 'ok') {
			eval(accion);
			}
		else
			eval(accion);
		});
	
		
	 
}
function promptPersonalizadoRedirect(titulo,mensaje,url)
{
	Ext.Msg.prompt(titulo,mensaje, function(btn, text){
	    if (btn == 'ok'){
	    	location.replace(url+text)    	
// process text value...
	    }
	});

}
function promptPassword(titulo,mensaje,url)
{
//	alert('test');
	//
	try
	{
		Ext.MessageBox.getDialog().body.child('input').dom.type='password';
		Ext.MessageBox.prompt(titulo,mensaje, function(btn, text){
			    if (btn == 'ok'){
			    	ObtenerDatos(url+text,'Principal');
			    }
		});
		
	}
	catch (e)
	{//EN EL CASO DE IE
		
   		Ext.MessageBox.prompt(titulo,mensaje, function(btn, text){
			    if (btn == 'ok'){
			    	ObtenerDatos(url+text,'Principal');
			    }
		});
			
	} 
	//Ext.MessageBox.getTextField().el.dom.type = 'password';
}
 
function muestraDatePicker(campo)
{
	var datefield2 = new Ext.DatePicker(function(btn){     
     alert(btn);
	});	
    datefield2.render('pruebaDate');
    alert(datefield2.getValue());
}


function muestraVentanaArchivo()
{ 
  Ext.onReady(function(){ 
	// Panel for the west
	var nav2 = new Ext.Panel({
	    title       : '',  
	    autoScroll:true,	           
	    autoLoad: 'incidencias.php'	   
	   
	}); 

	var win2 = new Ext.Window({
	    title    : 'titulo',
	    closable : true,
	    width    : 600,
	    resizable:false,
	    draggable : false,
	    height   : 400,
	    border : false,
	    plain    : false,	 
	    layout   : 'fit',
	    items    : [nav2]
	});
	 win2.show(this);
  });
}

function muestraVentanaContenido(titulo,ancho,alto,contenido)
{
   
	// Panel for the west
	var nav2 = new Ext.Panel({
	    title       : '',  
	    autoScroll:true,
	    style :'width:100px',	           
	    html:contenido	   
	   
	}); 

	var win2 = new Ext.Window({
	    title    : titulo,
	    closable : true,
	    width    : ancho,
	    style :'width:100px',
	    draggable : false,
	    resizable:false,	   
	    height   : alto,	    	    	 
	    layout   : 'fit',
	    items    : [nav2]
	});
	 win2.show(this);
 
}
function AbrirVentanaCentrada(Url,NombreVentana,width,height,extras) 
{
	 var largo = width;
	 var altura = height;
	 var adicionales= extras;
	 var top = (screen.height-altura)/2;
	 var izquierda = (screen.width-largo)/2; 
	 nuevaVentana=window.open(''+ Url + '',''+ NombreVentana + '','width=' + largo + ',height=' + altura + ',top=' + top + ',left=' + izquierda + ',features=' + adicionales + ''); 
	 nuevaVentana.focus();	 
}

function busquedaCP(controlCP,controlMuni,controlEstado,controlColonia,capaMunicipio)
{
	 Ext.onReady(function(){ 
   var contenido="<div  style='min-width:100%;min-height:100%;background:#CACACA;position :absolute;z-index:20000;left:0;top:0;width:auto!important;width:100%;height:auto!important;height:100%;'>" +
   		"<br><br><br><table width=500><tr><td>Codigo Postal:</td><td><input maxlength=5 size=5 type=text id=cp name=cp class=impu></td></tr>";
   contenido+="<tr><td>Colonia</td><td><input type=text id=col name=col class=impu size=50></td></tr>";
   contenido+="<tr><td>Estado</td><td><div id=BusEstado></div></td></tr>";
   contenido+="<tr><td>Municipio</td><td><div id=BusMunic></div></td></tr>";
   contenido+="<tr><td></td><td><input type=button name=Busca  id=Busca Value=Buscar onclick='buscaDatosCp()'></td></tr>";
   
   contenido+="</table><br><br>";   
   contenido+="<div id=capaTablaBusq></div></div>";
  	
  
	// Panel for the west
	var nav2 = new Ext.Panel({
	    title       : '',  
	    autoScroll:true,
	    style :'background-color:#CCCCCC',	           
	    html:contenido,
	    buttons:
        	[            	 
            	{
            	text: 'Aceptar Busqueda',
            	handler: function () {
            		document.getElementById(controlCP).value=document.getElementById('cp').value;
            		ObtenerDatosCombo2('cargaComboDinamico.php?nombre='+controlMuni+'&tabla=Cat_Municipios&value='+document.getElementById('MunicBus').value+'&llave=Id_Municipio&campos=Desc_Municipio&filtros=Id_Estado='+document.getElementById('EstadoBUS').value+' ORDER BY Desc_Municipio',capaMunicipio);
            		//document.getElementById(controlMuni).value=document.getElementById('MunicBus').value;
            		document.getElementById(controlEstado).value=document.getElementById('EstadoBUS').value;
            		document.getElementById(controlColonia).value=document.getElementById('col').value;
            		win2.close();
            		}
            	}
            ]

	   
	}); 

	var win2 = new Ext.Window({
	    title    : 'Búsqueda de Códigos Postales',
	    closable : true,
	    id: "win2",
	    width    : 730,
	    style :'background-color:#CCCCCC',
	    draggable : false,
	    resizable:false,	   
	    height   : 400,	    	    	 
	    layout   : 'fit',
	    items    : [nav2] 
	});
	 win2.show(this);
	 
	ObtenerDatosCombo2("cargaComboDinamico.php?nombre=EstadoBUS&code=onCHANGE=muestraMunicipiosBusqueda()&tabla=Cat_Estados&llave=Id_Edo&campos=Desc_Edo&filtros=Status_Edo =1 ORDER BY Desc_Edo","BusEstado");
	/*ObtenerDatosCombo('cargaComboDinamico.php?nombre=MunicBus&tabla=Cat_Municipios&llave=Id_Municipio&campos=Desc_Municipio&filtros=Id_Estado='+document.getElementById('EstadoBUS').value+' ORDER BY Desc_Municipio','BusMunic');
	*/
	document.getElementById('cp').value=document.getElementById(controlCP).value;
	document.getElementById('col').value=document.getElementById(controlColonia).value;
	buscaDatosCp2();
	 });
	 
}

function muestraMunicipiosBusqueda()
{
	ObtenerDatosCombo2('cargaComboDinamico.php?nombre=MunicBus&tabla=Cat_Municipios&llave=Id_Municipio&campos=Desc_Municipio&filtros=Id_Estado='+document.getElementById('EstadoBUS').value+' ORDER BY Desc_Municipio','BusMunic');

}
function buscaDatosCp()
{
	var isok=true;
	var mensaje='';
	if(document.getElementById('EstadoBUS').value=='-1' && document.getElementById('col').value=='' && document.getElementById('cp').value=='')						
	{
		isok=false;
	}
	if (!isok)
		alertPersonalizado('Busqueda','Debe establecer por lo menos un criterio de busqueda','error');
	else
	{
		try
		{
			ObtenerDatos('lib/TablaBusquedaCP.php?colonia='+document.getElementById('col').value+'&cp='+document.getElementById('cp').value+'&edo='+document.getElementById('EstadoBUS').value+'&munic='+document.getElementById('MunicBus').value,'capaTablaBusq');
		}
		catch (error)
		{
			ObtenerDatos('lib/TablaBusquedaCP.php?colonia='+document.getElementById('col').value+'&cp='+document.getElementById('cp').value+'&edo='+document.getElementById('EstadoBUS').value+'&munic=-1','capaTablaBusq');
		}
	}
}
function buscaDatosCp2()
{
	var isok=true;
	var mensaje='';
	if( document.getElementById('col').value=='' && document.getElementById('cp').value=='')						
	{
		isok=false;
	}
	if (isok)		
	{
		try
		{
			ObtenerDatos('lib/TablaBusquedaCP.php?colonia='+document.getElementById('col').value+'&cp='+document.getElementById('cp').value+'&edo='+document.getElementById('EstadoBUS').value+'&munic='+document.getElementById('MunicBus').value,'capaTablaBusq');
		}
		catch (error)
		{
			ObtenerDatos('lib/TablaBusquedaCP.php?colonia='+document.getElementById('col').value+'&cp='+document.getElementById('cp').value+'&edo=-1&munic=-1','capaTablaBusq');
		}
	}
}
function mandaInfoBusqueda(codp,edo,munic,colo)
{

	document.getElementById('EstadoBUS').value=edo;	
	document.getElementById('col').value=colo.replace(/_/g,' ');
	document.getElementById('cp').value=codp;
	ObtenerDatosCombo2('cargaComboDinamico.php?nombre=MunicBus&tabla=Cat_Municipios&value='+munic+'&llave=Id_Municipio&campos=Desc_Municipio&filtros=Id_Estado='+edo+' ORDER BY Desc_Municipio','BusMunic');
	document.getElementById('cp').focus();
}

//DA FORMATO DE MONEDA (PESOS)
function formatCurrency(num)
{	
	campo=num;
	num=document.getElementById(num).value;
	
	num = num.toString().replace(/$|\,/g,'');
	
	if (isNaN(num))
		num= num.substring(1,num.length );
	
	var signo = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	centavos = num % 100;
	num = Math.floor(num / 100).toString();
	
	if (centavos < 10)
	centavos = '0' + centavos;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
	num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
	num= (((signo) ? '' : '-') + '$' + num + '.' + centavos);
	document.getElementById(campo).value=num;
	
}
//VERIFICA SI EN EL SELECT ELIGIERON LA OPCION DE OTRO Y PINTA UN CAMPO DE CAPTURA:
function verificaSeleccionOtro(nombreSelect,valor)
{
//	SI LA OPCION QUE ELIGIERON ES OTRO (0)
	if(document.getElementById(nombreSelect).value==0)
	{
		ObtenerDatosMultiple("lib/cargaTextDinamico.php?nombre=otro"+nombreSelect+"&value="+valor,'otro'+nombreSelect,10);
	}
	else
		ObtenerDatosMultiple("lib/cargaTextDinamico.php?muestra=false&nombre=otro"+nombreSelect,'otro'+nombreSelect,10);
	
}
