 /*
 *provide JJSG
 *Ajax funcion
 *
 */
function ajax(aBuscar,aActualizar,Archivo,modulo,eeeaplic,bdaplic,idioma,valorLista)
{
		var aplicacion=eeeaplic;
		var arreglo = new Array();
		arreglo=aBuscar.split(".");
		var params="";
		var	i=0;
		var valor="";
		while (i < arreglo.length)
		{
			if($(arreglo[i]).value!='')
			{
				var valor=$F(arreglo[i]);
				params=params+"param"+[i]+"="+valor;
				if (i+1<arreglo.length)
					params=params+"&";
			}
			i++;
		}
		var url=Archivo+".php";
		var params=params+"&modulo="+modulo+"&eeeaplic="+aplicacion+"&bdaplic="+bdaplic+"&idiomapag="+idioma+"&aactualizar="+aActualizar+"&avalorLista="+valorLista;
		var ajx = new Ajax.Updater(aActualizar,url,
									  {method:"post",
									   parameters:params,
									   onComplete:function(resp){$(aActualizar).value=resp.responseText;},
									   onCreate:function(resp){$(aActualizar).value="Enviando datos al servidor.....";},
									   onFailure:function(resp){$(aActualizar).value="error.....";},
									   onLoaded:function(resp){$(aActualizar).value="Recibiendos datos del Servidor.....";},
									   onException:function(resp){$(aActualizar).value="Error en la Aplicación.....";}}
								  );
}

function ajax_datos(aBuscar,aActualizar,Archivo,modulo,eeeaplic,bdaplic,idioma)
{
		var aplicacion=eeeaplic;
		var arreglo = new Array();
		arreglo=aBuscar.split(".");
		var params="";
		var	i=0;
		var valor="";
		while (i < arreglo.length)
		{
			if($(arreglo[i]).value!='')
			{
				var valor=$F(arreglo[i]);
				params=params+"param"+[i]+"="+valor;
				if (i+1<arreglo.length)
					params=params+"&";
			}
			i++;
		}
		var url=Archivo+".php";
		var params=params+"&modulo="+modulo+"&eeeaplic="+aplicacion+"&bdaplic="+bdaplic+"&idiomapag="+idioma;
		var ajx = new Ajax.Updater(aActualizar,url,
									  {method:"post",
									   parameters:params,
									   onComplete:function(resp){$(aActualizar).value=resp.responseText;actualizar_datos();},
									   onCreate:function(resp){$(aActualizar).value="Enviando datos al servidor.....";},
									   onFailure:function(resp){$(aActualizar).value="error.....";},
									   onLoaded:function(resp){$(aActualizar).value="Recibiendos datos del Servidor.....";},
									   onException:function(resp){$(aActualizar).value="Error en la Aplicación.....";}}
								  );
}

function actualizar_datos()
{
	if ($('registros').value!='')
	{
		var arreglos=$('registros').value.split('*');
		if (arreglos.length>0)
		{
			if (arreglos[0]!="")
			{
				$('codigo_nac').value=arreglos[0];
			}
			else
			{
				$('codigo_nac').value='';
			}
			if (arreglos[2]!="")
			{
				$('p_nombre').value=arreglos[2];
			}
			else
			{
				$('p_nombre').value='';
			}
			if (arreglos[3]!="")
			{
				$('s_nombre').value=arreglos[3];
			}
			else
			{
				$('s_nombre').value='';
			}
			if (arreglos[4]!="")
			{
				$('p_apellido').value=arreglos[4];
			}
			else
			{
				$('p_apellido').value='';
			}
			if (arreglos[5]!="")
			{
				$('s_apellido').value=arreglos[5];
			}
			else
			{
				$('s_apellido').value='';
			}
			if (arreglos[6]!="")
			{
				$('pasaporte').value=arreglos[6];
			}
			else
			{
				$('pasaporte').value='';
			}
			if (arreglos[7]!="")
			{
				$('email').value=arreglos[7];
			}
			else
			{
				$('email').value='';
			}
			if (arreglos[8]!="")
			{
				$('telefono').value=arreglos[8];
			}
			else
			{
				$('telefono').value='';
			}
			if (arreglos[9]!="")
			{
				$('sexo').value=arreglos[9];
			}
			else
			{
				$('sexo').value='';
			}
			if (arreglos[10]!="")
			{
				$('nacionalidad').value=arreglos[10];
			}
			else
			{
				$('nacionalidad').value='';
			}
			if (arreglos[11]!="")
			{
				$('edo_civil').value=arreglos[11];
			}
			else
			{
				$('edo_civil').value='';
			}
			if (arreglos[12]!="")
			{
				$('n_educativo').value=arreglos[12];
			}
			else
			{
				$('n_educativo').value='';
			}
			if (arreglos[13]!="")
			{
				$('profesion').value=arreglos[13];
			}
			else
			{
				$('profesion').value='';
			}
			if (arreglos[14]!="")
			{
				$('ocupacion').value=arreglos[14];
			}
			else
			{
				$('ocupacion').value='';
			}
			if (arreglos[15]!="")
			{
				$('codigo_pais').value=arreglos[15];
			}
			else
			{
				$('codigo_pais').value='';
			}
			if (arreglos[16]!="")
			{
				$('codigo_area').value=arreglos[16];
			}
			else
			{
				$('codigo_area').value='';
			}
		}
	}
	else
	{
		$('p_nombre').value="";
		$('s_nombre').value="";
		$('p_apellido').value="";
		$('s_apellido').value="";
		$('pasaporte').value="";
		$('email').value="";
		$('telefono').value="";
		$('sexo').value="";
		$('nacionalidad').value="";
		$('edo_civil').value="";
		$('n_educativo').value="";
		$('profesion').value="";
		$('ocupacion').value="";
		$('codigo_pais').value="";
		$('codigo_area').value="";
	}
}

function ajax_datos_juridicos(aBuscar,aActualizar,Archivo,modulo,eeeaplic,bdaplic,idioma)
{
		var aplicacion=eeeaplic;
		var arreglo = new Array();
		arreglo=aBuscar.split(".");
		var params="";
		var	i=0;
		var valor="";
		while (i < arreglo.length)
		{
			if($(arreglo[i]).value!='')
			{
				var valor=$F(arreglo[i]);
				params=params+"param"+[i]+"="+valor;
				if (i+1<arreglo.length)
					params=params+"&";
			}
			i++;
		}
		var url=Archivo+".php";
		var params=params+"&modulo="+modulo+"&eeeaplic="+aplicacion+"&bdaplic="+bdaplic+"&idiomapag="+idioma;
		var ajx = new Ajax.Updater(aActualizar,url,
									  {method:"post",
									   parameters:params,
									   onComplete:function(resp){$(aActualizar).value=resp.responseText;actualizar_datos_juridicos();},
									   onCreate:function(resp){$(aActualizar).value="Enviando datos al servidor.....";},
									   onFailure:function(resp){$(aActualizar).value="error.....";},
									   onLoaded:function(resp){$(aActualizar).value="Recibiendos datos del Servidor.....";},
									   onException:function(resp){$(aActualizar).value="Error en la Aplicación.....";}}
								  );
}

function actualizar_datos_juridicos()
{
	if ($('registros_juridicos').value!='')
	{
		var arreglos=$('registros_juridicos').value.split('*');
		if (arreglos.length>0)
		{
			if (arreglos[0]!="")
			{
				$('rif_empresarial').value=arreglos[0];
			}
			else
			{
				$('rif_empresarial').value='';
			}
			if (arreglos[1]!="")
			{
				$('razon').value=arreglos[1];
			}
			else
			{
				$('razon').value='';
			}
			if (arreglos[2]!="")
			{
				$('nit_empresarial').value=arreglos[2];
			}
			else
			{
				$('nit_empresarial').value='';
			}
			if (arreglos[3]!="")
			{
				$('empresa').value=arreglos[3];
			}
			else
			{
				$('empresa').value='';
			}
			if (arreglos[4]!="")
			{
				$('web').value=arreglos[4];
			}
			else
			{
				$('web').value='';
			}
			if (arreglos[5]!="")
			{
				$('email_empresarial').value=arreglos[5];
			}
			else
			{
				$('email_empresarial').value='';
			}
			if (arreglos[6]!="")
			{
				$('sector').value=arreglos[6];
			}
			else
			{
				$('sector').value='';
			}
			if (arreglos[7]!="")
			{
				$('area').value=arreglos[7];
			}
			else
			{
				$('area').value='';
			}
			if (arreglos[8]!="")
			{
				$('codigo_pais_empresarial').value=arreglos[8];
			}
			else
			{
				$('codigo_pais_empresarial').value='';
			}
			if (arreglos[9]!="")
			{
				$('codigo_area_empresarial').value=arreglos[9];
			}
			else
			{
				$('codigo_area_empresarial').value='';
			}
			if (arreglos[10]!="")
			{
				$('telefono_empresarial').value=arreglos[10];
			}
			else
			{
				$('telefono_empresarial').value='';
			}
			if (arreglos[11]!="")
			{
				$('codigo_pais_fax').value=arreglos[11];
			}
			else
			{
				$('codigo_pais_fax').value='';
			}
			if (arreglos[12]!="")
			{
				$('codigo_area_fax').value=arreglos[12];
			}
			else
			{
				$('codigo_area_fax').value='';
			}
			if (arreglos[13]!="")
			{
				$('telefono_fax').value=arreglos[13];
			}
			else
			{
				$('telefono_fax').value='';
			}
		}
	}
	else
	{
		$('razon').value="";
		$('nit_empresarial').value="";
		$('empresa').value="";
		$('web').value="";
		$('email_empresarial').value="";
		$('sector').value="";
		$('area').value="";
		$('codigo_pais_empresarial').value="";
		$('codigo_area_empresarial').value="";
		$('telefono_empresarial').value="";
		$('codigo_pais_fax').value="";
		$('codigo_area_fax').value="";
		$('telefono_fax').value="";
	}
}


function verificar_cambio(variable,actualizar_div)
{
	if ($(variable).value=='1')
		{
				$(actualizar_div).show();
				$('verificotizacion').hide();
				$('email').value=$('email_verificacion').value;
		}

}
 /*
 *provide JJSG
 *Trabaja como cualquier trim
 *
 */
function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	return cadena;
}

 /*
 *provide JJSG
 *Ordena un arreglo de menor a mayor
 *
 */
 function ordenar_arreglo(arreglo)
 {
 	arreglo.sort(compareNum);
 	return arreglo;
 }


 /*
 *provide JJSG
 *Compara dos numero y retorna un valor
 *utilizada para el ordenar_arreglo
 */

 function compareNum(a,b)
 {
    return a-b;
 }

 /*
 *provide JJSG
 *Trae el entero de una caja de texto cuando se le da enter
 *
 */
function enternumero(e,id)
  {
    if (e.keyCode==13  || e.keyCode==9)


     valor = $(id).value;
     valor = parseInt(valor);

      if (isNaN(valor))
      {
            $(id).value='0';
            $(id).focus();
      }
      else
      {
            $(id).value=valor;
      }


  } //end function



 /*
 *provide JJSG
 *Verifica si esta escribiendo puro numeros
 *
 */

function num(id,alert12)
{
	valor=$(id).value;
	var log=valor.length;
	var sw="S";
	for (x=0; x<log; x++)
	{
		v1=valor.substr(x,1);
		v2 = parseInt(v1);
		//Compruebo si es un valor numérico
		if (isNaN(v2))
		{
			sw= "N";
		}
	}
	if (sw=="S")
	{
		return true;
	}
	else
	{
		$(id).value=valor.substring(0,x-1);
		alert(alert12)
		return false;
	}
}




 /*
 *provide ERG
 *Verifica si esta escribiendo solo letras
 *
 */

function letras(id,alert13)
{
	valor=$(id).value;
	var log=valor.length;
	var sw="N";
	for (x=0; x<log; x++)
	{
		v1=valor.substr(x,1);
		v2 = parseInt(v1);
		//Compruebo si es un valor es texto
		if (!isNaN(v2))
		{
			sw= "S";
		}
	}
	if (sw=="S")
	{
		$(id).value=valor.substring(0,x-1);
		alert(alert13)
		return false;
	}
	else
	{
		return true;
	}
}


  /*
 *provide jheredia
 *Valida la dirección de correo
 *
 */
 function validarcorreo(campoemail,alert14)
  {
	var RegExPattern = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/; //Variable que defidene el argumento de expresion valida
   // var errorMessage = 'Cuenta de Correo Incorrecta .'; //Variable que defidene el argumento de expresion valida
    if ((document.getElementById(campoemail).value.match(RegExPattern)) && (document.getElementById(campoemail).value!=''))
	{
		return true; //Modificado por descalona 30-07-08
	}
	else
	{
		alert(alert14);
		document.getElementById(campoemail).value='';
		/*document.getElementById(campoemail).focus(); no permitia avanzar si no se colocaba un email valido       ********Modificado por descalona 30-07-08 a peticion de Sra. Marbella*/
		return false;
    }

}


  /*
 *provide jheredia
 *Valida campos de un formulario
 *
 */
 /****Modificado el 31-07-08 por descalona para agregar parametros msjCorreo,msjFInicio,msjFDev,msjNoEsta con mensajes
 de respuesta si no son validas las fechas o el correo no son validas***/
  function validar_campos(arreglo_campos,mensaje,msjCorreo,msjFInicio,msjFDev,msjNoEsta)
  {
	var pass=true;
	var arreglo = new Array();
	arreglo = arreglo_campos.split(",");
	i=0;
	while (i < arreglo.length)
	{
		if (arreglo[i]=='noesta' && $(arreglo[i]).value==''){
			pass=false;
			alert(msjNoEsta);
			break;
		}
		if($(arreglo[i]).value=='')
		{
			pass=false;
			alert(mensaje);
			break;
		}
		/***Modificado el 31-07-08 por descalona para realizar validacion de fechas y correo antes del submit****/
			if( arreglo[i]=='email_verificacion') {
				pass=validarcorreo('email_verificacion',msjCorreo);
				if (pass===false) break;
			}
			if( arreglo[i]=='fecha_ini'){
				pass=validar_fechainicio('fecha_ini',$('fHoy').value,msjFInicio);
				if (pass===false) break;
			}
			if( arreglo[i]=='fecha_fin'){
				pass=validar_fechafin('fecha_ini','fecha_fin',msjFDev)
				if (pass===false) break;
			}
		i++;
	}
	return pass;
  }

/*
 *provide jheredia
 *Valida contraseña
 *
 */


 /*********************************************Creado por descalona 30-07-08 Validar Fechas********************************************/

function validar_fechainicio(inicio,hoy,alerta){
	if(DiferenciaFechas($(inicio).value,hoy)<=0){
		alert(alerta);
		return false;
	}else{
		return true;
	}
}


function validar_fechafin(inicio,devolucion,alerta){
	if(DiferenciaFechas ($(devolucion).value,$(inicio).value)<=0){
		alert(alerta);
		return false;
	}else{
		return true;
	}
}


 function DiferenciaFechas (CadenaFecha1,CadenaFecha2) {
   //Obtiene dia, mes y año
   var fecha1 = new fecha( CadenaFecha1 );
   var fecha2 = new fecha( CadenaFecha2 );

   //Obtiene objetos Date
   var miFecha1 = new Date( fecha1.anio, fecha1.mes, fecha1.dia );
   var miFecha2 = new Date( fecha2.anio, fecha2.mes, fecha2.dia );

   //Resta fechas y redondea
   var diferencia = miFecha1.getTime() - miFecha2.getTime();
   var dias = Math.floor(diferencia / (1000 * 60 * 60 * 24));
   //alert ('dias;'+dias+' miFecha1:'+miFecha1+'miFecha2:'+miFecha2);
   return dias;
}


function fecha( cadena ) {
	//Separador para la introduccion de las fechas
	var separador = "/";
	//Separa por dia, mes y año
    if ( cadena.indexOf( separador ) != -1 ) {
        var posi1 = 0
        var posi2 = cadena.indexOf( separador, posi1 + 1 )
        var posi3 = cadena.indexOf( separador, posi2 + 1 )
        this.dia = cadena.substring( posi1, posi2 )
        this.mes = cadena.substring( posi2 + 1, posi3 )
        this.anio = cadena.substring( posi3 + 1, cadena.length )
   } else {
        this.dia = 0
        this.mes = 0
        this.anio = 0
   }
}
 /***********************************Modificado por descalona 30-07-08 fin de validar fechas******************************************/



function validarclave (campo1,campo2,alert1,alert2,alert3,alert4,alert5) {
  var p1 = $(campo1).value;
  var p2 = $(campo2).value;
  var espacios = true;
  var cont = 0;
  var minuscula = false;
  var mayuscula = false;
  var numero = false;
  var caracter = false;
  // Este bucle recorre la cadena para comprobar
  // que no todo son espacios
	  while (espacios && (cont < p1.length)) {

	   if (p1.charAt(cont) != " ") {
	    espacios = false;
	   }
	   cont++;
	  }

	  if (espacios) {
	   alert (alert1);
	   document.getElementById(campo1).value='';
	   document.getElementById(campo2).value='';
	   document.getElementById(campo1).focus();
	   return false;
	  }

	  if (p1.length == 0 || p2.length == 0) {
	   alert(alert2);
	   document.getElementById(campo1).value='';
	   document.getElementById(campo2).value='';
	   document.getElementById(campo1).focus();
	   return false;
	  }

	  if (p1!= p2) {
	   alert(alert3);
	  document.getElementById(campo1).value='';
	  document.getElementById(campo2).value='';
	  document.getElementById(campo1).focus();
	   return false;
	  }


	  if(p1.length<6) {
	  alert(alert4);
	  document.getElementById(campo1).value='';
	  document.getElementById(campo2).value='';
	  document.getElementById(campo1).focus();
	  return false;
	  }

 for(i=0;i<p1.length;i++) {
    //si el codigo ASCII es el de las minusculas, pone a true el flag de minusculas y mayusculas
   if(p1.charCodeAt(i)>=97 && p1.charCodeAt(i)<=122 && p1.charCodeAt(i)>=65 && p1.charCodeAt(i)<=90) {
	minuscula=true;
        mayuscula=true;

         //si el codigo ASCII es el de loss numeros, pone a true el flag de numeros
    } else if(p1.charCodeAt(i)>=48 && p1.charCodeAt(i)<=57) {
             numero=true;

         //si no es ninguno de los anteriores, a true el flag de caracter simbolico
	} else {
             caracter=true;

        }
}
     if((caracter==true && numero==true) || ( minuscula==true || mayuscula==true) ){
        /*alert("El password elegida contiene todos los caracteres requeridos.")
         return false;   //cambiar false por true para hacer el submit  */
     } else {
		alert(alert5);
		document.getElementById(campo1).value='';
		document.getElementById(campo2).value='';
		document.getElementById(campo1).focus();
		return false;
        }
}

//function valida_envia(alert6,alert7,alert8,alert9,alert10,alert11)
function valida_envia_natural(alert6,alert7,alert8,alert9,alert10,alert11,alert12,alert50)
{
	if (document.getElementById('codigo_nac').value.length==0){
	       alert(alert12)
	       document.getElementById('codigo_nac').focus()
		return 0;
		}

	if ((document.getElementById('clave').value.length==0) && (document.getElementById('cedula_registrada').value.length==''))
	{
	      /* Modificado por mvizcaya septiembre 2008---- en vez de : alert(alert2); se agregó  alert(alert6); */
	      alert(alert6);
	       document.getElementById('clave').focus();
		return 0;
	}

	if ((document.getElementById('conf_clave').value.length==0) && (document.getElementById('cedula_registrada').value.length==''))
	{
	          /* Modificado por mvizcaya septiembre 2008---- en vez de : alert(alert2); se agregó  alert(alert7); */
	       alert(alert7);
	       document.getElementById('conf_clave').focus();
		return 0;
	}

	if (document.getElementById('p_nombre').value.length==0){
	       alert(alert8)
	       document.getElementById('p_nombre').focus()
		return 0;
		}

	if (document.getElementById('p_apellido').value.length==0){
	       alert(alert9)
	     document.getElementById('p_apellido').focus()
		return 0;
		}

	if (document.getElementById('cedula').value.length==0){
	       alert(alert10)
	       document.getElementById('cedula').focus()
	       return 0;
	    }

	if (document.getElementById('email').value.length==0){
	alert(alert11)
	document.getElementById('email').focus()
	return 0;
	}

	if (document.getElementById('direccion').value.length==0){
		alert(alert50)
	    document.getElementById('direccion').focus()
		return 0;
	}


	//el formulario se envia
	document.getElementById('form2').submit()
	//return true;

}

//function valida_envia(alert6,alert7,alert8,alert9,alert10,alert11)
function valida_envia_empresarial(alert1,alert2,alert3,alert4)
{

	if (document.getElementById('rif_empresarial').value.length==0)
	{
	       alert(alert1);
	       document.getElementById('p_nombre').focus();
		return 0;
	}

	if ((document.getElementById('clave_empresarial').value.length==0) && (document.getElementById('rif_registrado').value.length==''))
	{
	       alert(alert2);
	       document.getElementById('clave_empresarial').focus();
		return 0;
	}

	if ((document.getElementById('conf_clave_empresarial').value.length==0) && (document.getElementById('rif_registrado').value.length==''))
	{
	       alert(alert2);
	       document.getElementById('conf_clave_empresarial').focus();
		return 0;
	}


	if (document.getElementById('razon').value.length==0)
	{
	     alert(alert3);
	     document.getElementById('p_apellido').focus();
		return 0;
	}


	if (document.getElementById('email_empresarial').value.length==0)
	{
		alert(alert4);
		document.getElementById('email').focus();
		return 0;
	}

	//el formulario se envia
	document.getElementById('form2').submit();
	//return true;

}


function abrir_popup (URL)
{
	window.open(URL,"ventana1","width=700, height=550, scrollbars=no, menubar=no, location=no, resizable=no")
}

function esconder(f)
{
	if (f=='N')
	{
		$('juridica').hide();
		$('parse_info').value='N';
		$('natural').show();
	}
	if (f=='J')
	{
		$('natural').hide();
		$('parse_info').value='J';
		$('juridica').show();
	}
}

function esconder_login()
{
	if ($('combo').value=='N')
	{
		$('accesUser').hide();
		$('accesUser_per').show();
	}
	if ($('combo').value=='J')
	{
		$('accesUser_per').hide();
		$('accesUser').show();
	}
}
function buscar_email_ajax(f)
{
	if (f=='N')
	{
		$('buscar_email').value='N';
	}
	if (f=='J')
	{
		$('buscar_email').value='J';
	}
}

function tecla_ie(e)
{
		var keyCode
		if(window.event)
			keyCode=window.event.keyCode;
		else if(e)
			keyCode=e.which;
		if (keyCode==13)
			return false;
}
function tecla_mozilla(e)
{
		evt = e ? e : event;
		tcl = (window.Event) ? evt.which : evt.keyCode;
		if ((tcl== 13))
		{
			return false;
		}
		return true;
}





