var empezar = true;
var anclas = new Array ("ancla1,ancla2,ancla3,ancla4,ancla5,ancla6,ancla7,");
var capas = new Array("indicador_1","indicador_2","indicador_3","indicador_4","indicador_5","indicador_6");
//var capas = new Array("indicador_1");
var retardo;
var ocultar;

function oculta_retarda(capa){
	if (empezar){
		ocultar =capa
		clearTimeout(retardo)
		retardo = setTimeout("oculta('" + ocultar + "')",200)
	}
}

function muestra_coloca(capa){
	if (empezar){
		for (i=0;i<capas.length;i++){
			if (capas[i] != capa) oculta(capas[i])
		}
		clearTimeout(retardo)
		muestra(capa)
	}
}

function muestra_retarda(ind){
	if (empezar){
		clearTimeout(retardo)
	}
}
function muestra(capa){
	menu = document.getElementById(capa);
	menu.style.visibility='visible';
	//xShow(capa);
}

function oculta(capa){
	menu = document.getElementById(capa);
	menu.style.visibility='hidden';
	//xHide(capa);
}
function resize(ancho,alto){
	self.resizeTo(ancho,alto); 
	LeftPosition = (screen.width) ? (screen.width-ancho)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-alto)/2 : 0;
	self.moveTo(LeftPosition,TopPosition-70);
}
function abrir_ventana_noscroll(name){
	ventana2 = window.open(name, "ventana", "width=5,height=5,dependent=yes,screenX=0,screenY=0,titlebar=no,directories=no,menubars=no,status=no,scrollbars=no,resizable=no"); 
}
function abrir_ventana(name){
	ventana = window.open(name, "ventana"+name, "width=5,height=5,dependent=yes,screenX=0,screenY=0,titlebar=no,directories=no,menubars=no,status=no,scrollbars=yes,resizable=no"); 
}

function abrir_ventana2(name,ancho,alto){
	window.name="Tope";
	window.open(name, "ventana", "width="+ancho+",height="+alto+",dependent=yes,screenX=0,screenY=0,titlebar=no,directories=no,menubars=no,status=no,scrollbars=yes,resizable=no"); 
}

function abrir_ventana3(name,ancho,alto,mensaje){
	window.name="Tope";
	if (mensaje==1) {
		if (confirm("Esta acción actualizará los datos de los usuarios. Esta seguro de querer realizarla?")) { 
			window.open(name, "ventana", "width="+ancho+",height="+alto+",dependent=yes,screenX=0,screenY=0,titlebar=no,directories=no,menubars=no,status=no,scrollbars=yes,resizable=no"); 
		}
	}else{
		window.open(name, "ventana", "width="+ancho+",height="+alto+",dependent=yes,screenX=0,screenY=0,titlebar=no,directories=no,menubars=no,status=no,scrollbars=yes,resizable=no"); 
	}
}

function validar_todo(laforma){
	for(var i = 0; i < laforma.elements.length; i++){
		if(laforma.elements[i].value == ""){
			alert("Ingrese todos los campos requeridos como obligatorios");
			laforma.elements[i].focus();
			return false;
		}
		if(laforma.elements[i].value.indexOf ("'", 0) != -1){
			alert("Elimine las comillas!");
			laforma.elements[i].focus();
			return false;
		}
	}
	return true;
}

function validar_perdio(laforma){
	for(var i = 0; i < laforma.elements.length; i++){
		if(laforma.elements[i].value == ""){
			alert("Ingrese todos los campos requeridos como obligatorios");
			laforma.elements[i].focus();
			return false;
		}
		if(laforma.elements[i].value.indexOf ("'", 0) != -1){
			alert("Elimine las comillas!");
			laforma.elements[i].focus();
			return false;
		}
		if((laforma.elements[i].name.indexOf("mail",0)!=-1) && ((laforma.elements[i].value.indexOf('@', 0) == -1) || (laforma.elements[i].value.indexOf('.', 0) == -1))){
			alert("Ingrese una dirección de E-Mail valida");
			laforma.elements[i].focus();
			return false;
		}
	}
	return true;
}

function validar_mail(laforma){
		if(laforma.var_mail.value == ""){
			abrir_ventana_noscroll("p_mensaje.php?id_men=1");
			return false;
		}
	if(laforma.var_mail.value.indexOf ("'", 0) != -1){
		alert("Elimine las comillas!");
		laforma.var_mail.focus();
		return false;
	}
	return true;
}

function mostrar(id){
	eval(id + ".style.display=\"block\"");
}

function no_mostrar(id){
     eval(id + ".style.display =\"none\"");
}

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_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_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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function trim(sString)
{
   sTrimmedString = "";
   if (sString != "")
   {
      var iStart = 0;
      var iEnd = sString.length - 1;
      var sWhitespace = " \t\f\n\r\v";
     
      while (sWhitespace.indexOf(sString.charAt(iStart)) != -1)
      {
         iStart++;
         if (iStart > iEnd)
            break;
      }
     
      // If the string not just whitespace
      if (iStart <= iEnd)
      {
         while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
            iEnd--;
         sTrimmedString = sString.substring(iStart,++iEnd);
      }
   }
   return sTrimmedString;
} 

function validar_nuevo_usuario(laforma){
	for(var i = 0; i < laforma.elements.length; i++){
		if(laforma.elements[i].value == "" && laforma.elements[i].name!="Observaciones"){
			alert("Ingrese todos los campos requeridos como obligatorios");
			laforma.elements[i].focus();
			return false;
		}
		if(laforma.elements[i].value.indexOf ("'", 0) != -1){
			alert("Elimine las comillas!");
			laforma.elements[i].focus();
			return false;
		}
	}
	return true;
}

function validar_forma_pub(){
	la_forma = eval("window.document.forma_usuario");
	if(la_forma.titulo.value == ""){
		alert("Ingrese el titulo, es campo requerido como obligatorio");
		la_forma.titulo.focus();
		return false;
	}
	if(la_forma.resena.value == ""){
		alert("Ingrese la reseña, es campo requerido como obligatorio");
		la_forma.resena.focus();
		return false;
	}
	if (la_forma.resena.value.length >= 255) {
		alert("La reseña solo puede contener 255 caracteres maximo.\nReduzca la cantidad de información.");
		la_forma.resena.focus();
		return false;
	}
	la_forma.submit();
}


function expandir(id) {
	var obj = objHtml(id)
	
	for (i=0; i<=document.numero_capas.Numero_Capas.value-1 ; i++) {		
		cerrar("capa_"+document.numero_capas.Nombres_Capas[i].value);
	}

	if (miNavegador.standard) {
		if (obj.style.display == "none")
		   obj.style.display = 'block'
		else
		   obj.style.display = 'none'
	}else{
		if (obj.display == "none")
		   obj.display = 'block'
		else
		   obj.display = 'none'
	} 
}

function cerrar(id) {
	var obj = objHtml(id)
	if (miNavegador.standard) {
		obj.style.display = 'none'
	}else{
		obj.display = 'none'
	}	  
}

/***Objetos globales definidos aquí**********/
function oNavegador(  ) {
	this.nombre = navigator.appName;
	this.iniciar = iniciar;
	this.IE = this.nombre.toUpperCase().indexOf('MICROSOFT') >=0;
	this.NS = this.nombre.toUpperCase().indexOf('NETSCAPE') >=0;
	this.OP = this.nombre.toUpperCase().indexOf('OPERA') >= 0;
	this.XX = !this.IE && !this.NS && !this.OP;
	this.version = this.iniciar();
	this.Verent = parseInt(this.version);
	this.standard = (this.IE && this.Verent >=5) || (this.NS && this.Verent >=6)

/* ======================================================================
	FUNCION:	iniciar( ), miembro de oNavegador
	ARGS: 		none.
	DEVUELVE:	nada
	DESCRIP:	Inicializa los valores del objeto
====================================================================== */
  function iniciar() {
  var ver = navigator.appVersion;
  if(ver+"" != "NaN")
	if (this.IE)
		{
		ver.match(/(MSIE)(\s*)([0-9].[0-9]+)/ig);
  		ver = RegExp.$3;
		}
  return ver;
  } //Termina la funcion iniciar el objeto
}

window.miNavegador = new oNavegador()
window.miNavegador.iniciar();
/*=========================================================================
FUNCION:	objHtml(n, d), 
ARGS:		n: un atributo ID del elemento que se desea encontrar
			d: documento en el que se busca
RETURN:		Referencia javascript al elemento HTML cuyo ID es el atributo n
DESCRIP:	Esta función busca un elemento HTML (un nodo) cuyo atributo ID sea igual al 
			que se pasa como primer argumento ( n ). La b´suqueda se realiza en el árbol
			que se le indique como segundo argumento, si éste no existe la busqueda se 
			realiza en document de la ventana actual. La función es recursiva.
================================================================================*/			
function objHtml(n, d) { 
  var p,i,x;  
  if(!d) d=document; 
  if (miNavegador.standard)
	  x = d.getElementById(n)	
  if(!(x=d[n]) && miNavegador.IE) 
      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=objHtml(n,d.layers[i].document); 
  return x;
}



function validar_contactenos(f){
if(f.nombre.value=="")
	{
		alert("El campo nombre es requerido");
		f.nombre.focus();
		return false;
	}
	if(f.apellido.value=="")
	{
		alert("El campo apellido es requerido");
		f.apellido.focus();
		return false;
	}

	if(f.comentarios.value=="")
	{
		alert("El campo comentarios es requerido");
		f.comentarios.focus();
		return false;
	}	

	if(f.mail.value=="" )
	{
		alert("El campo mail es requerido");
		f.mail.focus();
		
		return false;
		validarEmail(f.mail.value);
	}
	var valor=f.mail.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
	//	alert("La dirección de email " + valor    + " es correcta.");
		return (true);
	} else {
		alert("La dirección de email es incorrecta.");
		f.mail.focus();
		return (false);
  }



	return true;
	}





 
 function validar_registro(f)
 {
	if(f.cb_customer.value=="")
	{
		alert("Seleccione el tipo Cédula/Rif");
		f.cb_customer.focus();
		return false;
	}
	if(f.cedula.value=="")
	{
		alert("El campo cédula es requerido");
		f.cedula.focus();
		return false;
	}
	if(f.placa.value=="")
	{
		alert("El campo placa es requerido");
		f.placa.focus();
		return false;
	}
	if(f.contrato.value=="")
	{
		alert("El campo contrato es requerido");
		f.contrato.focus();
		return false;
	}
	if(f.monto.value=="")
	{
		alert("El campo monto es requerido");
		f.monto.focus();
		return false;
	}
	if(f.email.value=="")
	{
		alert("El campo email es requerido");
		f.mail.focus();
		return false;
	}
	var valor=f.email.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
	//	alert("La dirección de email " + valor    + " es correcta.");
		return (true);
	} else {
		alert("La dirección de email es incorrecta.");
		f.email.focus();
		return (false);
  }
	return true;
 }
 

 function validar_olvido(f)
 {
	if(f.cb_customer.value=="")
	{
		alert("Seleccione el tipo Cédula/Rif");
		f.cb_customer.focus();
		return false;
	}
	if(f.cedula.value=="")
	{
		alert("El campo cédula es requerido");
		f.cedula.focus();
		return false;
	}
	return true;
 }
 
 function cambio_pin_cliente()
{
	if (document.pin.cb_customer.value=="")
	{
		alert ("Debe seleccionar el tipo de Cliente");
		document.pin.cb_customer.focus();
		return false;
	}
	else if (document.pin.cedula.value=="")
	{
		alert ("Debe Ingresar la Cédula o Rif");
		document.pin.cedula.focus();
		return false;
	}
	else if (document.pin.vigente.value=="")
	{
		alert ("Debe Ingresar el Pin Vigente del Usuario");
		document.pin.vigente.focus();
		return false;
	}
	else if (document.pin.nuevo.value=="")
	{
		alert ("Debe Ingresar el nuevo Pin del Usuario");
		document.pin.nuevo.focus();
		return false;
	}
	else if (document.pin.confirmar.value=="")
	{
		alert ("Debe confirmar el nuevo Pin del Usuario");
		document.pin.confirmar.focus();
		return false;
	}else{
		if (document.pin.nuevo.value==document.pin.confirmar.value)
		{
			if (numeros(document.pin.nuevo.value)==true)
			{
				if (eval(document.pin.nuevo.value.length)==6)
				{
					document.pin.cedula.value=parseInt(document.pin.cedula.value,10);
					document.pin.submit();
					return false;
				}else{
					alert ("El Nuevo Pin debe ser de 6 dígitos");
					document.pin.nuevo.focus();
					return false;
				}
			}else{
				alert ("El Nuevo Pin no es de tipo Numérico");
				document.pin.nuevo.focus();
				return false;
			}
		}else{
			alert ("No coincide el Nuevo Pin con la Confirmación");
			document.pin.nuevo.focus();
			return false;
		}
	}
return true;
}

function numeros (field)
{
	var valid = "0123456789"
	var ok = "Si";
	var temporal;
	for (var i=0; i<field.length; i++)
	{
		temporal = "" + field.substring(i, i+1);
		if (valid.indexOf(temporal) == "-1") ok = "no";
	}
	if (ok == "no")
	{
		return false;
	}else{
		return true;
	}
}

function revisar_tsv()
{
	if (document.sesion2.cb_customer.value=="")
	{
		alert ("Debe seleccionar el tipo de cliente");
		document.sesion2.cb_customer.focus();
	}
	else if (document.sesion2.cedula.value=="")
	{
		alert ("Debe Ingresar su Cédula o RIF");
		document.sesion2.cedula.focus();
	}
	else if (document.sesion2.pin.value=="")
	{
		alert ("Debe Ingresar el Pin de validación");
		document.sesion2.pin.focus();
	}else{
//		document.sesion2.cedula.value=parseInt(document.sesion2.cedula.value,10);
		var alto = parseInt(screen.height)-68;
                var ancho = parseInt(screen.width) - 10;
		window.open("about:blank","myNewWinTSV","height="+alto+",left=0,toolbar=0,top=0,width="+ancho + ",resizable=yes");
		document.sesion2.submit();
		document.sesion2.cb_customer.value="";
		document.sesion2.cedula.value="";
		document.sesion2.pin.value="";                
	}
}

function revisar_concesionario()
{
	if (document.sesion3.cedula.value=="")
	{
		alert ("Debe Ingresar La Cédula");
		document.sesion3.cedula.focus();
	}
	else if (document.sesion3.user.value=="")
	{
		alert ("Debe Ingresar el Rif");
		document.sesion3.user.focus();
	}
	else if (document.sesion3.pin.value=="")
	{
		alert ("Debe Ingresar el Pin de validación");
		document.sesion3.pin.focus();
	}else{
                var alto = parseInt(screen.height)-68;
                var ancho = parseInt(screen.width) - 10;
		window.open("about:blank", "myNewWinTSV", "height="+alto+",left=0,toolbar=0,top=0,width="+ancho);

		document.sesion3.submit();
		document.sesion3.user.value="";
                document.sesion3.pin.value="";
                document.sesion3.cedula.value="";
				document.sesion2.cb_customer.value="";
	}
}