function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";

  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }


  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }


  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

///PARA SABER QUE BROWSER TENGO
/*ASI LO LLAMO
var browser1 = new Browser();
if (browser1.isIE)
  var Width=Width;
else
  var Width=Width1;
*/

//var browser = new Browser();


function expandirObj(obj){ 
	var capa = document.getElementById(obj); 
	if(capa.style.display=='') 
		capa.style.display='none'; 
	else 
		capa.style.display=''; 
} 


function SwitchMenu(obj) {
	if (document.getElementById) {
	var el = document.getElementById(obj);
	var ar = document.getElementById("ppal").getElementsByTagName("td"); //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";
		}
	}
}


function removeRow(tabla,idFila) { 
	if (confirm("Realmente desea eliminar este registro?")==true) {
 		document.getElementById(tabla).deleteRow(idFila);
		return true;
	} else {
	 	return false;
	}
}


function removeRowAjax(tablaDB,where,nivel,idFila,tabla) {	
	var elimino = 0;
	elimino = DeleteAjaxFull(tablaDB,where,nivel);
	if (elimino == 1) {
		document.getElementById(tabla).deleteRow(idFila);
	}

}

function getValor(){
	return ajax_con;
}

function setValor(valor){
	ajax_con=valor;
} 

function KeyF5Check() {
	//var tecla=window.event.keyCode;
  	//if (tecla==116) {
	// alert("Lo sentimos por seguridad no debe recargar la página.\n Utilice la nevegaci&oacute;n de la aplicaci&oacute;n"); 
	 //event.keyCode=0;
	 //event.returnValue=false;
	//}
}


function Browser() {
  var ua, s, i;
  this.isIE    = false;  
  this.isNS    = false;  
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}


	
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_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 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_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];}
}
///////////////////FGORMULARIO DE CONSULTAS consultas.php
function MM_jumpMenu(targ,selObj,restore) { //v3.0
	if (selObj.options[selObj.selectedIndex].value!=0) {
		  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		  if (restore) selObj.selectedIndex=0;
	}
}





function ocultar() {
	if (document.getElementById) {
		var c = document.getElementsByTagName("table");
		  for (var x=0;x<c.length;x++) {			
			if (c[x].id == 'oculta'){
				c[x].style.display='none';
				}
			}	
	}
}
//ocultar();

function ocultarObj(id) {
	if (document.getElementById) {
		var c = document.getElementsByTagName("table");
		  for (var x=0;x<c.length;x++) {			
			if (c[x].id == id){
				c[x].style.display='none';
				}
			}	
	}
}

function ocultarSetTime(id,time) {
	setTimeout("ocultarObj('"+id+"')",time);
}
function restablecer() {
  setTimeout("window.location.reload()",1)
}


function IrUrl(URL) {
   window.location.replace(URL);
   
}

function IrUrlTimeOut(URL,time) {
  setTimeout("window.location.replace('"+URL+"')",time);
   
}

function IrUrlWindow(URL) {
   window.opener.location.replace(URL);
   parent.close();   
}



function CheckedAll(campo,t) {
 var objeto=document.getElementsByName(campo+'[]');
	if (t==1) {
		for (i=0;i<objeto.length;i++)
				objeto[i].checked='checked';
	} else {
		 for (i=0;i<objeto.length;i++)
				objeto[i].checked='';
		 }
}


function OpenUrlResizable(Url,Titulo,Width,Height)
{
   var izquierda = (screen.availWidth - Width) / 2; 
    var arriba = (screen.availHeight - Height) / 2; 

    var opciones =",toolbar='NO'"+ 
				 ",titlebar='NO'"+ 
                 ",location='NO'"+ 
                 ",status='NO'"+ 
                 ",menubar='NO'"+ 
                 ",resizable=yes"+ 
				 ",scrollbars=yes"+ 
                 ",width=" + Width + 
                 ",height=" + Height + 
                 ",left=" + izquierda + 
                 ",top=" + arriba; 
   window.open(Url,'', opciones);  
}


function OpenUrl(Url,Titulo,Width,Height)
{
   var izquierda = (screen.availWidth - Width) / 2; 
    var arriba = (screen.availHeight - Height) / 2; 

    var opciones =",toolbar='NO'"+ 
				 ",titlebar='NO'"+ 
                 ",location='NO'"+ 
                 ",status='NO'"+ 
                 ",menubar='NO'"+ 
				 ",scrollbars=yes"+ 
                 ",width=" + Width + 
                 ",height=" + Height + 
                 ",left=" + izquierda + 
                 ",top=" + arriba; 
   window.open(Url,Titulo, opciones);  
}


function OpenWindowFlat(Url,Titulo,Width,Height)
{
   var izquierda = (screen.availWidth - Width) / 2; 
    var arriba = (screen.availHeight - Height) / 2; 

    var opciones =",toolbar=no"+ 
				 ",titlebar=no"+ 
                 ",location=no"+ 
                 ",status=no"+ 
                 ",menubar=no"+ 
                 ",scrollbars=no"+ 
                 ",width=" + Width + 
                 ",height=" + Height + 
                 ",left=" + izquierda + 
                 ",top=" + arriba; 
   window.open(Url,Titulo, opciones);  
}


function Confirmar(msg) {
var sn=confirm(msg);
 if (sn==true)
  return false;
 else
   return false;
}




function CheckPorcentaje(campo) {
	
	if ((campo.value<=0 || campo.value>100) && campo.value!='') {
			alert("El porcentaje debe ser mayor que 0 y menor de 100");
			campo.value='';
			campo.focus();
		}
}

//C&oacute;digo para colocar 
//los indicadores de miles mientras se escribe
//script por tunait!
//<input type="text" name="pepe" onkeyup = "puntitos(this,this.value.charAt(this.value.length-1))">

function miles(donde,caracter) {
	pat = /[\*,\+,\(,\),\?,\,$,\[,\],\^]/
	valor = donde.value
	largo = valor.length
	crtr = true
	if (isNaN(caracter) || pat.test(caracter) == true) {
		if (pat.test(caracter)==true) { 
			caracter = "\\" + caracter
		}
		carcter = new RegExp(caracter,"g")
		valor = valor.replace(carcter,"")
		donde.value = valor
		crtr = false
	}
	else {
		var nums = new Array()
		cont = 0
		for(m=0;m<largo;m++) {
			if (valor.charAt(m) == "." || valor.charAt(m) == " ")
				{continue;}
			else {
				nums[cont] = valor.charAt(m)
				cont++
			}
		}
	}
	var cad1="",cad2="",tres=0
	if (largo > 3 && crtr == true) {
		for (k=nums.length-1;k>=0;k--) {
			cad1 = nums[k]
			cad2 = cad1 + cad2
			tres++
			if ((tres%3) == 0) {
				if (k!=0) {
					cad2 = "." + cad2
				}
			}
		}
		donde.value = cad2
	}
}	

/*****************************************************************************
C&oacute;digo para colocar los indicadores de miles  y decimales mientras se escribe
Script creado por Tunait!
Si quieres usar este script en tu sitio eres libre de hacerlo con la condici&oacute;n de que permanezcan intactas estas líneas, osea, los créditos.

http://javascript.tunait.com
tunait@yahoo.com  27/Julio/03

//onkeyup="puntitos(this,this.value.charAt(this.value.length-1),'decimales')"
// onclick="puntitos(this.form.textfield,this.form.textfield.value.charAt(this.form.textfield.value.length-1),this.name)" 2 decimales
******************************************************************************/
function decimales(donde,caracter,campo)
{
var decimales = false
campo = eval("donde.form." + campo)
	for (d =0; d < campo.length; d++)
		{
		if (campo[d].checked == true)
			{
			dec = new Number(campo[d].value)
			break;
			}
		}
	if (dec != 0)
		{decimales = true}




pat = /[\*,\+,\(,\),\?,\\,\$,\[,\],\^]/
valor = donde.value
largo = valor.length
crtr = true
if (isNaN(caracter) || pat.test(caracter) == true)
	{
	if (pat.test(caracter)==true) 
		{caracter = "\\" + caracter}
	carcter = new RegExp(caracter,"g")
	valor = valor.replace(carcter,"")
	donde.value = valor
	crtr = false
	}
else
	{
	var nums = new Array()
	cont = 0
	for(m=0;m<largo;m++)
		{
		if (valor.charAt(m) == "." || valor.charAt(m) == " " || valor.charAt(m) == ",")
			{continue;}
		else {
			nums[cont] = valor.charAt(m)
			cont++
			}
		
		}
	}

if (decimales == true) {
	ctdd = eval(1 + dec);
	nmrs = 1
	}
else {
	ctdd = 1; nmrs = 3
	}
var cad1="",cad2="",cad3="",tres=0
if (largo > nmrs && crtr == true)
	{
	for (k=nums.length-ctdd;k>=0;k--) {
		cad1 = nums[k]
		cad2 = cad1 + cad2
		tres++
		if ((tres%3) == 0) {
			if (k!=0) {
				cad2 = "." + cad2
				}
			}
		}
		
	for (dd = dec; dd > 0; dd--)	
	{cad3 += nums[nums.length-dd] }
	if (decimales == true)
	{cad2 += "," + cad3}
	 donde.value = cad2
	}
donde.focus()
}
