// JavaScript Document

window.onerror = new Function("return true") 

function validarfrmRegistro(cod,tipo){
	var form = document.getElementById('frmRegistro');
	var er_email = /^([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(@)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(.)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(.)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)$/

	var ok = 1;
	if(tipo==1){
		if(form.PERFIL.value == -1 && ok == 1){
			alert('Seleccione su Perfil de Usuario!');
			form.PERFIL.focus();
			ok = 0;
		}
		
		if(form.TIPO_DOC.value == -1 && ok == 1){
			alert('Selecccione el tipo de documento!');
			form.TIPO_DOC.focus();
			ok = 0;
		}
		
		if(form.DOCUMENTO.value == '' && ok == 1){
			alert('Digite el número de documento!');
			form.DOCUMENTO.focus();
			ok = 0;
		}
		
		if(form.NOMBRES.value == '' && ok == 1){
			alert('Digite sus nombres!');
			form.NOMBRES.focus();
			ok = 0;
		}
		
		if(form.APELLIDOS.value == '' && ok == 1){
			alert('Digite sus apellidos!');
			form.APELLIDOS.focus();
			ok = 0;
		}
		
		if(form.EMAIL.value == '' && ok == 1){
			alert('Digite su correo electrónico!');
			form.EMAIL.focus();
			ok = 0;
		}
		
		if (!er_email.test(form.EMAIL.value)&& ok == 1){
			alert('El correo electrónico debe tener un formato válido');
			form.EMAIL.focus();
			ok = 0;
		}
		if(cod==1){
			if(form.CONTRA.value == '' && ok == 1){
				alert('Digite su contrasena!');
				form.CONTRA.focus();
				ok = 0;
			}
			
			if(form.RECONTRA.value == '' && ok == 1){
				alert('Confirme su contrasena!');
				form.RECONTRA.focus();
				ok = 0;
			}
			
			if(form.CONTRA.value != form.RECONTRA.value && ok == 1){
			alert('La contrasena y su confirmación no coinciden!');
			form.CONTRA.value='';
			form.RECONTRA.value='';
			form.CONTRA.focus();
			ok = 0;
		}
		}else{
			if(form.CONTRA.value != '' && ok == 1){
				if(form.RECONTRA.value == ''){
					alert('Confirme su contrasena!');
					form.RECONTRA.focus();
					ok = 0;
				}else{
					if(form.CONTRA.value!=form.RECONTRA.value ){
						alert('La contrasena y su confirmación no coinciden!');
						form.CONTRA.value='';
						form.RECONTRA.value='';
						form.CONTRA.focus();
						ok = 0;
					}
				}
			}
	
		}
	}else{
		if(form.EMPRESA.value == '' && ok == 1){
			alert('Digite el nombre de la empresa!');
			form.EMPRESA.focus();
			ok = 0;
		}
		if(form.DOCUMENTO.value == '' && ok == 1){
			alert('Digite el número de RUT!');
			form.DOCUMENTO.focus();
			ok = 0;
		}
		if(form.NOMBRES.value == '' && ok == 1){
			alert('Digite los nombres!');
			form.NOMBRES.focus();
			ok = 0;
		}
		
		if(form.APELLIDOS.value == '' && ok == 1){
			alert('Digite los apellidos!');
			form.APELLIDOS.focus();
			ok = 0;
		}
		if(form.CARGO.value == '' && ok == 1){
			alert('Digite el cargo!');
			form.CARGO.focus();
			ok = 0;
		}
		if(form.EMAIL.value == '' && ok == 1){
			alert('Digite su correo electrónico de la empresa!');
			form.EMAIL.focus();
			ok = 0;
		}
		if (!er_email.test(form.EMAIL.value)&& ok == 1){
			alert('El correo electrónico debe tener un formato válido');
			form.EMAIL.focus();
			ok = 0;
		}
		if(form.CONTRA.value != '' && ok == 1){
				if(form.RECONTRA.value == ''){
					alert('Confirme su contrasena!');
					form.RECONTRA.focus();
					ok = 0;
				}else{
					if(form.CONTRA.value!=form.RECONTRA.value ){
						alert('La contrasena y su confirmación no coinciden!');
						form.CONTRA.value='';
						form.RECONTRA.value='';
						form.CONTRA.focus();
						ok = 0;
					}
				}
		}
		
	}
	
	if(form.TELEFONO.value == '' && ok == 1){
			alert('Digite el Teléfono!');
			form.TELEFONO.focus();
			ok = 0;
	}
	
	if(form.DIRECCION1.value == '' && ok == 1){
			alert('Digite la dirección de correspondencia!');
			form.DIRECCION1.focus();
			ok = 0;
	}
	
	if(form.CIUDAD.value == '' && ok == 1){
			alert('Digite la ciudad/pais!');
			form.CIUDAD.focus();
			ok = 0;
	}
	
	if(form.FAX.value == '' && ok == 1){
			alert('Digite el número de fax');
			form.FAX.focus();
			ok = 0;
	}
	
	if(form.CONTACTO1.value == '' && ok == 1){
			alert('Digite el nombre del contacto principal!');
			form.CONTACTO1.focus();
			ok = 0;
	}
	
	if(form.CARGO_CONTACTO1.value == '' && ok == 1){
			alert('Digite el cargo del contacto principal!');
			form.CARGO_CONTACTO1.focus();
			ok = 0;
	}
	
	if(form.EMAIL_CONTACTO1.value == '' && ok == 1){
			alert('Digite su correo electrónico del contacto principal!');
			form.EMAIL_CONTACTO1.focus();
			ok = 0;
	}
		
	if (!er_email.test(form.EMAIL_CONTACTO1.value)&& ok == 1){
		alert('El correo electrónico debe tener un formato válido');
		form.EMAIL_CONTACTO1.focus();
		ok = 0;
	}
	
	if(form.TEL_CONTACTO1.value == '' && ok == 1){
			alert('Digite el teléfono del contacto principal!');
			form.TEL_CONTACTO1.focus();
			ok = 0;
	}
	
	if(form.EMAIL_CONTACTO2.value != '' && ok == 1){
		if (!er_email.test(form.EMAIL_CONTACTO2.value)&& ok == 1){
			alert('El correo electrónico del segundo contacto, debe tener un formato válido');
			form.EMAIL_CONTACTO2.focus();
			ok = 0;
		}
	}
	
	if(form.EMAIL_CONTACTO_TESORERIA.value != '' && ok == 1){
		if (!er_email.test(form.EMAIL_CONTACTO_TESORERIA.value)&& ok == 1){
			alert('El correo electrónico del contacto de tesorería, debe tener un formato válido');
			form.EMAIL_CONTACTO_TESORERIA.focus();
			ok = 0;
		}
	}
	
	if(form.EMAIL_CONTACTO_DESPACHOS.value != '' && ok == 1){
		if (!er_email.test(form.EMAIL_CONTACTO_DESPACHOS.value)&& ok == 1){
			alert('El correo electrónico del contacto de despachos, debe tener un formato válido');
			form.EMAIL_CONTACTO_DESPACHOS.focus();
			ok = 0;
		}
	}
	
	if(form.PROVEEDORES.value == '' && ok == 1){
			alert('Digite los proveedores!');
			form.PROVEEDORES.focus();
			ok = 0;
	}
	
	if(form.DIA_FACTURACION.value == -1 && ok == 1){
			alert('Seleccione el día de corte en la facturación!');
			form.DIA_FACTURACION.focus();
			ok = 0;
	}
	
	if(form.HORARIO_RADICACION.value == '' && ok == 1){
			alert('Digite el horario de radicación!');
			form.HORARIO_RADICACION.focus();
			ok = 0;
	}

	if(ok == 1){
			form.submit();
	}
}

function validarfrmLogin(){
	var form = document.getElementById('frmLogin');
	var ok = 1;
	var er_email = /^([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(@)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(.)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(.)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)$/

	if(form.LOGIN.value == '' && ok == 1){
		alert('Digite su correo electrónico!');
		form.LOGIN.focus();
		ok = 0;
	}
	
	if (!er_email.test(form.LOGIN.value)&& ok == 1){
		alert('El correo electrónico debe tener un formato válido');
		form.LOGIN.focus();
		ok = 0;
	}
	
	if(form.CONTRA.value == '' && ok == 1){
		alert('Digite su correo Contrasena!');
		form.CONTRA.focus();
		ok = 0;
	}
	
	if(ok == 1){
			form.submit();
	}
}

function validarfrmContra(){
	var form = document.getElementById('frmContra');
	var ok = 1;
	var er_email = /^([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(@)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(.)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)+(.)+([A-Z]|[a-z]|[0-9]|\_|\-|\.)$/


	if(form.EMAIL.value == '' && ok == 1){
		alert('Digite su correo electrónico!');
		form.EMAIL.focus();
		ok = 0;
	}
	
	if (!er_email.test(form.EMAIL.value)&& ok == 1){
		alert('El correo electrónico debe tener un formato válido');
		form.EMAIL.focus();
		ok = 0;
	}
	
	if(form.DOC.value == '' && ok == 1){
		alert('Digite su Documento!');
		form.DOC.focus();
		ok = 0;
	}
		
	if(ok == 1){
			form.submit();
	}
}

function validarfrmCotizador(){
	var form = document.getElementById('frmCotizador');
	var ok = 1;

	if(form.PERSONALIZACION.value == -1 && ok == 1){
		alert('Seleccione la opcion de personalización!');
		form.PERSONALIZACION.focus();
		ok = 0;
	}
	
	if((form.PERSONALIZACION.value == 2 || form.PERSONALIZACION.value == 3) && ok == 1){
		if(form.TINTAS.value == -1){
			alert('Seleccione el número de tintas!');
			form.TINTAS.focus();
			ok = 0;
		}
	}

	if(form.CANTIDAD.value == '' && ok == 1){
		alert('Digite la cantidad!');
		form.CANTIDAD.focus();
		ok = 0;
	}
	
	
	if(ok == 1){
			form.submit();
	}
}

function validarfrmBuscar(){
	var form = document.getElementById('frmBuscar');
	var ok = 1;

	if(form.BUSCAR.value == "" && ok == 1){
		alert('Digite la búsqueda!');
		form.BUSCAR.focus();
		ok = 0;
	}
	
	if(ok == 1){
			form.submit();
	}
}

function acepta_numero(campo){
        if (isNaN(campo.value)){
			alert("Esto no es un número!");
			campo.value='';
			//campo.value= campo.value.slice(0, -1);
        }
		else{
			
		}

}


