﻿// JavaScript Document
// VALIDACIONES DE LOS FORMULARIOS DE PMU
var validaFormato	= new RegExp("^([0-9](?:.[0-9]{3})*)+(?:,[0-9]{1}){0,1}$");
var validaEntero 	= new RegExp("^[0-9]+$");
var validaAnio 		= new RegExp("^[0-9]{4}$");
var validaNumero 	= new RegExp("^[0-9]{4}$");
var validaMes 		= new RegExp("^0[0-9]|1[012]$");
var validaDia 		= new RegExp("^0[1-9]|[12][0-9]|3[01]$");
//var validaReal	= new RegExp("^[0-9]+(?:.[0-9]){0,1}$"); 
//var validaReal	= new RegExp("^[0-9]+((?:.[0-9]){0,1}|(?:,[0-9]){0,1})$");
var validaRealDosDecimales	= new RegExp("^[0-9]+((?:.([0-9]{2})){0,1}|(?:,([0-9]{2})){0,1})$");
var validaRealDos	= new RegExp("^[0-9]+((?:.([0-9]{1,2})){0,1}|(?:,([0-9]{1,2})){0,1})$");
var validaReal = new RegExp("^[0-9]+((?:.([0-9])){0,1}|(?:,([0-9])){0,1})$");
var validaCaracter 	= new RegExp("^[a-zA-Z]{1}$");


var Holding = {
	formateaDecimal : function ( campo, cantDecimales, mensaje ) {
		var tieneComas = false;
		if ( campo.value.indexOf( "," ) != -1 ) {
			reComa = /,/gi
			rePunto = /\./gi
			tieneComas = true;
			campo.value = campo.value.replace( reComa, "." );
		}
		if ( isNaN( parseFloat( campo.value ) ) ) {
			return fnG.alerta( mensaje, campo );
		} else {
			campo.focus();
			campo.value = parseFloat( campo.value );
			var numFormatear = new NumberFormat( campo.value );
			numFormatear.setCurrency( false );
			numFormatear.setCommas( false );
			numFormatear.setPlaces( cantDecimales );
			campo.value = numFormatear.toFormatted();
			if ( tieneComas ) {
				campo.value = campo.value.replace( rePunto, "," );
			}
		}
		return true;
	},
	
	validaLogin : function () {
		if (fnG.trim(fnG.obtElem("usuario").value) == "")
			return fnG.alerta("Favor ingrese su Cuenta de Usuario.",fnG.obtElem("usuario"));
		if (fnG.trim(fnG.obtElem("password").value) == "")
			return fnG.alerta("Favor ingrese su Password.",fnG.obtElem("password"));
			return true;
	},

	limpiaTextoClick: function(obj) {
		obj.value = "";
	},
	validaContactoCentroAcero: function() {

		if ( fnG.trim(fnG.obtElem('txtNombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido (Solo Letras y Numeros).", fnG.obtElem('txtNombre') );
		}
		if ( fnG.trim(fnG.obtElem('txtApellido').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Apellido Valido (Solo Letras y Numeros).", fnG.obtElem('txtApellido') );
		}
		if ( fnG.trim(fnG.obtElem('txtEmpresa').value ) == "" ) {
			return fnG.alerta( "Debe ingresar una empresa Valida (Solo Letras y Numeros).", fnG.obtElem('txtEmpresa') );
		}
		if ( fnG.trim(fnG.obtElem('txtTelefono').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Telefono Valido (Solo Letras y Numeros).", fnG.obtElem('txtTelefono') );
		}
		if ( fnG.trim( fnG.obtElem('txtEmail').value ) == "" ) {
				return fnG.alerta( "Debe ingresar un e-mail Valido.", fnG.obtElem('txtEmail') );
		}
		if ( !fnG.esEmail(fnG.obtElem('txtEmail').value )) {
			return fnG.alerta( "Debe ingresar un e-mail Valido", fnG.obtElem('txtEmail') );
		}
		if ( fnG.trim(fnG.obtElem('txtConsulta').value ) == "" ) {
			return fnG.alerta( "Debe ingresar la consulta.", fnG.obtElem('txtConsulta') );
		}
		return true;
	} ,
	validaContactoInstapanel: function() {

		if ( fnG.trim(fnG.obtElem('txtNombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido (Solo Letras y Numeros).", fnG.obtElem('txtNombre') );
		}
		if ( fnG.trim(fnG.obtElem('txtApellido').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Apellido Valido (Solo Letras y Numeros).", fnG.obtElem('txtApellido') );
		}
		if ( fnG.trim(fnG.obtElem('txtTelefono').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Telefono Valido (Solo Letras y Numeros).", fnG.obtElem('txtTelefono') );
		}
		if ( fnG.trim( fnG.obtElem('txtEmail').value ) == "" ) {
				return fnG.alerta( "Debe ingresar un e-mail Valido.", fnG.obtElem('txtEmail') );
		}
		if ( !fnG.esEmail(fnG.obtElem('txtEmail').value )) {
			return fnG.alerta( "Debe ingresar un e-mail Valido", fnG.obtElem('txtEmail') );
		}
		if ( fnG.trim(fnG.obtElem('txtConsulta').value ) == "" ) {
			return fnG.alerta( "Debe ingresar la consulta.", fnG.obtElem('txtConsulta') );
		}
		return true;
	},
	validaContactoVarcopruden: function() {

		if ( fnG.trim(fnG.obtElem('txtNombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido (Solo Letras y Numeros).", fnG.obtElem('txtNombre') );
		}
		if ( fnG.trim(fnG.obtElem('txtApellido').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Apellido Valido (Solo Letras y Numeros).", fnG.obtElem('txtApellido') );
		}
		if ( fnG.trim(fnG.obtElem('txtTelefono').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Telefono Valido (Solo Letras y Numeros).", fnG.obtElem('txtTelefono') );
		}
		if ( fnG.trim( fnG.obtElem('txtEmail').value ) == "" ) {
				return fnG.alerta( "Debe ingresar un e-mail Valido.", fnG.obtElem('txtEmail') );
		}
		if ( !fnG.esEmail(fnG.obtElem('txtEmail').value )) {
			return fnG.alerta( "Debe ingresar un e-mail Valido", fnG.obtElem('txtEmail') );
		}
		if ( fnG.trim(fnG.obtElem('txtConsulta').value ) == "" ) {
			return fnG.alerta( "Debe ingresar la consulta.", fnG.obtElem('txtConsulta') );
		}
		return true;
	},
	
	validaCotizacionInstapanel: function() {

		if ( fnG.trim(fnG.obtElem('txtNombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido (Solo Letras y Numeros).", fnG.obtElem('txtNombre') );
		}
		if ( fnG.trim(fnG.obtElem('txtEmpresa').value ) == "" ) {
			return fnG.alerta( "Debe ingresar una empresa (Solo Letras y Numeros).", fnG.obtElem('txtEmpresa') );
		}
		if ( fnG.trim( fnG.obtElem('txtEmail').value ) == "" ) {
				return fnG.alerta( "Debe ingresar un e-mail Valido.", fnG.obtElem('txtEmail') );
		}
		if ( !fnG.esEmail(fnG.obtElem('txtEmail').value )) {
			return fnG.alerta( "Debe ingresar un e-mail Valido", fnG.obtElem('txtEmail') );
		}
		if ( fnG.trim(fnG.obtElem('txtTelefono').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Telefono Valido (Solo Letras y Numeros).", fnG.obtElem('txtTelefono') );
		}
		
		if ( fnG.trim(fnG.obtElem('ddlProductos').value ) == "" ) {
			return fnG.alerta( "Debe seleccionar Producto.", fnG.obtElem('ddlProductos') );
		}
		if ( fnG.trim(fnG.obtElem('ddlDistribuidor').value ) == "" ) {
			return fnG.alerta( "Debe seleccionar Distribuidor.", fnG.obtElem('ddlDistribuidor') );
		}
		if ( fnG.trim(fnG.obtElem('ddlRegion').value ) == "" ) {
			return fnG.alerta( "Debe seleccionar Region.", fnG.obtElem('ddlRegion') );
		}
		
		if ( fnG.trim(fnG.obtElem('txtConsulta').value ) == "" ) {
			return fnG.alerta( "Debe ingresar la consulta.", fnG.obtElem('txtConsulta') );
		}
		return true;
	}

}