/* ********************************************************************************* */
/* *******  Librería de JavaScripts Consultas.js  		      ******* */
/* Valida datos faltantes en las paginas HMTL de Busquedas
/* 
/* ******************************************************************************** */
// Funcion que valida la pagina sid_ventas_cliente.jsp
function validacion_ventas(){
	if (document.miform.txt_cliente_ventas.value == "" ) {
		alert("Ingrese Codigo de Cliente");
		document.miform.txt_cliente_ventas.focus();
		return; 
	}
	if (ValidarDigitos(document.miform.txt_cliente_ventas.value) ==0){
		alert("Ingrese Numeros en el Codigo de Cliente");
		document.miform.txt_cliente_ventas.value = "";
		document.miform.txt_cliente_ventas.focus();
		return;
	}
	if (VerificarFecha(document.miform.txt_fecha_ini) == 0){
		return;
	}
	if (VerificarFecha(document.miform.txt_fecha_fin) == 0){
		return;
	}		
	ap_showWaitMessage('panelEsperar', 1); 
	document.miform.submit();
}
// Funcion que valida la pagina sid_cons_ventascliente.jsp - PARA CLIENTES
function validacion_ventas_cliente(){
	if (document.miform.txt_fecha_ini_dia.value == "" ) {
		alert("Ingrese Dia Inicial de Busqueda");
		document.miform.txt_fecha_ini_dia.focus();		
		return ; 
	}
	if (document.miform.txt_fecha_ini_mes.value == "" ) {
		alert("Ingrese Mes Inicial de Busqueda");
		document.miform.txt_fecha_ini_mes.focus();
		return ; 
	}
	if (document.miform.txt_fecha_ini_ano.value == "" ) {
		alert("Ingrese Año Inicial de Busqueda");
		document.miform.txt_fecha_ini_ano.focus();
		return ; 
	}
	if (document.miform.txt_fecha_fin_dia.value == "" ) {
		alert("Ingrese Dia Final de la Busqueda");
		document.miform.txt_fecha_fin_dia.focus();
		return ; 
	}
	if (document.miform.txt_fecha_fin_mes.value == "" ) {
		alert("Ingrese Mes Final de la Busqueda");
		document.miform.txt_fecha_fin_mes.focus();
		return ; 
	}
	if (document.miform.txt_fecha_fin_ano.value == "" ) {
		alert("Ingrese Año Final de la Busqueda");
		document.miform.txt_fecha_fin_ano.focus();
		return ; 
	}
	ap_showWaitMessage('panelEsperar', 1); 
	document.miform.submit();
}
/* FUNCION QUE PERMITE MOSTRAR LA CAPA DE BUSQUEDA*/
function ap_getObj(name) 
{if (document.getElementById) 
{return document.getElementById(name).style; 
}else if (document.all) 
{return document.all[name].style; 
}else if (document.layers) 
{return document.layers[name]; 
}}

function ap_showWaitMessage(div,flag){
	ancho=window.document.body.scrollWidth;
	ancho=(ancho/2)-150;
	alto=window.document.body.scrollHeight;
	alto=(alto/2)-45;

	if (!DHTML) return;
	var x = ap_getObj(div); 
	x.top='120px';
	x.left=ancho;
	x.visibility = (flag) ? 'visible':'hidden' 
	if(! document.getElementById) 
		if(document.layers) 
			x.left=280/2; 
	return true; 
}
/* Function que valida los Datos de la pagina sid_cuentas_cliente.jsp */
function valida_cxc(){
	if (document.miform.txt_cliente_cxc.value == "" ) {
		alert("Ingrese Codigo de Cliente");
		document.miform.txt_cliente_cxc.focus();
		return; 
	}
	if (ValidarDigitos(document.miform.txt_cliente_cxc.value) ==0){
		alert("Ingrese Numeros en el Codigo de Cliente");
		document.miform.txt_cliente_cxc.value = "";
		document.miform.txt_cliente_cxc.focus();
		return;
	}
	if (document.miform.estado.value ==3){
		if (document.miform.txt_fecha_ini_dia.value == "" ) {
			alert("Ingrese Dia Inicial de Busqueda");
			document.miform.txt_fecha_ini_dia.focus();
			return ; 
		}
		if (document.miform.txt_fecha_ini_mes.value == "" ) {
			alert("Ingrese Mes Inicial de Busqueda");
			document.miform.txt_fecha_ini_mes.focus();
			return ; 
		}
		if (document.miform.txt_fecha_ini_ano.value == "" ) {
			alert("Ingrese Dia Inicial de Busqueda");
			document.miform.txt_fecha_ini_ano.focus();
			return ; 
		}
		if (document.miform.txt_fecha_fin_dia.value == "" ) {
			alert("Ingrese Dia Final de la Busqueda");
			document.miform.txt_fecha_fin_dia.focus();
			return ; 
		}
		if (document.miform.txt_fecha_fin_mes.value == "" ) {
			alert("Ingrese Mes Final de la Busqueda");
			document.miform.txt_fecha_fin_mes.focus();
			return ; 
		}
		if (document.miform.txt_fecha_fin_ano.value == "" ) {
			alert("Ingrese Año Final de la Busqueda");
			document.miform.txt_fecha_fin_ano.focus();
			return ; 
		}
	}	
	ap_showWaitMessage('panelEsperar', 1); 
	document.miform.submit();
}
/* Function que valida los Datos de la pagina sid_cuentas_cliente.jsp */
function valida_cxc_cliente(){
	if (document.miform.estado.value ==3){
		if (document.miform.txt_fecha_ini_dia.value == "" ) {
			alert("Ingrese Dia Inicial de Busqueda");
			document.miform.txt_fecha_ini_dia.focus();
			return ; 
		}
		if (document.miform.txt_fecha_ini_mes.value == "" ) {
			alert("Ingrese Mes Inicial de Busqueda");
			document.miform.txt_fecha_ini_mes.focus();
			return ; 
		}
		if (document.miform.txt_fecha_ini_ano.value == "" ) {
			alert("Ingrese Dia Inicial de Busqueda");
			document.miform.txt_fecha_ini_ano.focus();
			return ; 
		}
		if (document.miform.txt_fecha_fin_dia.value == "" ) {
			alert("Ingrese Dia Final de la Busqueda");
			document.miform.txt_fecha_fin_dia.focus();
			return ; 
		}
		if (document.miform.txt_fecha_fin_mes.value == "" ) {
			alert("Ingrese Mes Final de la Busqueda");
			document.miform.txt_fecha_fin_mes.focus();
			return ; 
		}
		if (document.miform.txt_fecha_fin_ano.value == "" ) {
			alert("Ingrese Año Final de la Busqueda");
			document.miform.txt_fecha_fin_ano.focus();
			return ; 
		}
	}	
	ap_showWaitMessage('panelEsperar', 1); 
	document.miform.submit();
}	
/* Function cuando hace click con el boton derecho del mouse*/
function click(e) {
	var message="SiderPeru S.A. - Derechos Reservados 2007";
	if (document.all) {
		if (event.button==2||event.button==3) {
			alert(message);
			return false;
		}
	}

	if (document.layers) {
		if (e.which == 3) {
			alert(message);
			return false;
		}
	}	
}
// Funcion que valida la pagina sid_ventas_cliente.jsp
function validacion_sugerencias(){
	if (document.miform.nombre.value == "" ) {
		alert("Ingrese Nombre y Apellidos");
		document.miform.nombre.focus();
		return; 
	}
    /*if (document.miform.email.value.indexOf("@") = -1)
          alert('Debe escribir una dirección válida');
          return;
    }*/
	if (!validarEmail(document.miform.email.value)){		
        return;
	}
	if (document.miform.empresa.value == "" ) {
		alert("Ingrese el Nombre de la Empresa");
		document.miform.empresa.focus();
		return; 
	}
	if (document.miform.pais.value == "Seleccione un País..." ) {
		alert("Seleccione el País");
		document.miform.pais.focus();
		return; 
	}
	if (document.miform.sugerencia.value == "" ) {
		alert("Ingrese la Sugerencia");
		document.miform.sugerencia.focus();
		return; 
	}
	document.miform.submit();
}
// Función que valida si el Email es Correcto
function validarEmail(valor) {
  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.");
    return (false);
  }
}
function ValidarDigitos( texto ) {
	/* Valida solo números sin signos de decimales o miles - OP 03/10/2003 */
	var valid = "0123456789"
	var temp;
	
	for (var i=0;  i < texto.length; i++) {
		temp = "" + texto.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")  { return 0 } ; 
	}	
	return 1 ;
}
/* Funcion que convierte a Mayusculas el valor de un cuadro de Texto */
function aMayusculas(campo){
     campo.value=campo.value.toUpperCase();
}
// Funcion que valida las Fechas de consulta de Percepciones
function validacion_percepcion(){	
	if (document.miform.txt_fecha_ini_dia.value == "" ) {
		alert("Ingrese Dia Inicial de Busqueda");
		document.miform.txt_fecha_ini_dia.focus();
		return ; 
	}
	if (document.miform.txt_fecha_ini_mes.value == "" ) {
		alert("Ingrese Mes Inicial de Busqueda");
		document.miform.txt_fecha_ini_mes.focus();
		return ; 
	}
	if (document.miform.txt_fecha_ini_ano.value == "" ) {
		alert("Ingrese Año Inicial de Busqueda");
		document.miform.txt_fecha_ini_ano.focus();
		return ; 
	}
	if (document.miform.txt_fecha_fin_dia.value == "" ) {
		alert("Ingrese Dia Final de la Busqueda");
		document.miform.txt_fecha_fin_dia.focus();
		return ; 
	}
	if (document.miform.txt_fecha_fin_mes.value == "" ) {
		alert("Ingrese Mes Final de la Busqueda");
		document.miform.txt_fecha_fin_mes.focus();
		return ; 
	}
	if (document.miform.txt_fecha_fin_ano.value == "" ) {
		alert("Ingrese Año Final de la Busqueda");
		document.miform.txt_fecha_fin_ano.focus();
		return ; 
	}		
	ap_showWaitMessage('panelEsperar', 1); 
	document.miform.submit();
}
// Funcion que valida la pagina sid_cons_ventascliente.jsp - PARA CLIENTES
function valida_resumen_ventas(){
	alert("Ingrese Dia Inicial de Busqueda");
	if (VerificarFecha(document.miform.txt_fecha_ini) == 0){
		return;
	}
	if (VerificarFecha(document.miform.txt_fecha_fin) == 0){
		return;
	}
	ap_showWaitMessage('panelEsperar', 1); 
	document.miform.submit();	
}