	/* ********************************************************
		FILE: checkfields.js 
		AUTHOR: Latinvia
		DATE:04/07/2000
		DESCRIPTION:Chequeo de variables en el formulario de 
					alta de usuarios y libreria de funciones
	******************************************************** */

	/*
		********************************************************
		LIBRERIA
		isEmpty()
		isPosInteger()
	   	******************************************************** 
	*/
	
	/* Esta funcion devuelve true si el string pasado es nulo o vacio */
	function isEmpty(inputStr){	
		if(inputStr == null || inputStr == "") {
			return true
		}
		return false
	}
	
	/* 
		Esta funcion devuelve true si todos los caracteres que la componen
	   	son enteros positivos
	*/
	function isPosInteger(inputVal){
		inputStr = inputVal.toString()
		for(var i=0;i<inputStr.length;i++){
			var oneChar = inputStr.charAt(i)
			if(oneChar < "0" || oneChar > "9") {
				return false
			}
		}
		return true
	}
	
	/*
		Esta funcion devuelve true si todos los caracteres que la componen son enteros
	*/
	function isInteger(inputVal){
		inputStr = inputVal.toString()
		for(var i=0;i<inputStr.length;i++){
			var oneChar = nputStr.charAt(i)
			// para el signo negativo
			if(i == 0 && oneChar == "-"){
				continue
			}
			if(oneChar < "0" || oneChar > "9"){
				return false
			}
		}
		return true
	}
	
	/* Hacer las comprobaciones del lado del cliente */	
	var strMsgError=""
	var retorno = true
	
	/* Estas variables identifican al browser usado*/
	var isNAV,isIE
	
	/* Estas variables toman distintos valores de acuerdo a las versines de IE o Nav */
	var range = ""
	var styleObj = ""
	
	/* Resolver que tipo de navegador se esta usando */
	if (navigator.appName == "Netscape"){
		isNAV = true
		range = ""
		styleObj = ""
	}
	else if(navigator.appVersion.indexOf("MSIE") != -1){
		isIE = true
		range = "all."
		styleObj = ".style"
	}
		
	/* Esta funcion solo facilita las cosas */
	function Error(msg){
		strMsgError = strMsgError + msg
		retorno = false
	}
	
	/* Esta funcion chequea la consistencia de los valores ingresados */
	function CheckFormData(codalianza){
		
		/* Se debe poner este valor en true*/
		retorno = true;

		/* Un par de strings */
		var str1 = new String("")
		var str2 = new String("")
		
		/* ### NOMBRE DE USUARIO ### */	
		/* Verificar que el campo no este vacio */
		if(document.all)
			str1 = document.all.vch2User_ID.value
		else
			str1 = document.frmUsrData.vch2User_ID.value
			
		if(isEmpty(str1)){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a USER NAME. This field is required to complete the registration process.\n")
				
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo Nome de Usuário não pode ficar vazio\n")
				else
					("El campo Nombre de usuario no puede estar vacio\n")
		}
		
		if(str1.indexOf(" ") != -1){
			if(document.all.TipoIdioma.value == 2)
				Error("Field USER NAME cannot contain blank spaces\n")
			else
				if(document.all.TipoIdioma.value == 3)	
				Error("O campo Nome de Usuário não pode conter espaços em branco\n")
			else
				Error("El campo Nombre de Usuario no puede contener espacios en blanco\n")
		}
	
		/* Verificar que la longitud de los datos ingresados este entre 4-20 */
		if(document.all)
			str1 = document.all.vch2User_ID.value
		else
			str1 = document.frmUsrData.vch2User_ID.value

		if(str1.length < 4 || str1.length > 20) {
			if(document.all.TipoIdioma.value == 2)
				Error("Please provide a USER NAME with 4-20 characters\n")
			else
				if(document.all.TipoIdioma.value == 3)	
					Error("O campo Nome de Usuário deve conter mínimo 4 caractéres e máximo 20\n")
				else
					Error("La longitud del nombre de usuario no debe ser menor que 4 caracteres ni mayor de 20\n")
		}

		/* ### CONTRASEÑA ### */
		/* Verificar que la contraseña no este vacia ni contenga caracteres especiales */
		if(document.all)
			str1 = document.all.vch2Password.value
		else
			str1 = document.frmUsrData.vch2Password.value
			
		if(isEmpty(str1)){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a PASSWORD. This field is required to complete the registration process.\n")
			else
				if(document.all.TipoIdioma.value == 3)		
					Error("O campo senha não pode ficar vazio\n")
				else
					Error("El campo contraseña no puede estar vacio\n")
		}
			
		/* Verificar que la longitud de la contraseña este entre 4 y 12 caracteres */
		if(document.all)
			str1 = document.all.vch2Password.value
		else
			str1 = document.frmUsrData.vch2Password.value
			
		if(str1.length <4 || str1.length > 20){
			if(document.all.TipoIdioma.value == 2)
				Error("Please provide a PASSWORD with 4-20 characters\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo Senha deve conter mínimo 4 caractéres e máximo 20\n")
				else
					Error("La longitud de la contraseña no debe ser menor que 4 caracteres ni mayor de 20\n")
				
		}
		
		/* ### CONTRASEÑAS IGUALES ### */
		/* Cargar la confirmacion de la password */
		if(document.all){
			str2 = document.all.vch2ConfirmPassword.value
		}
		else{
			str2 = document.frmUsrData.vch2ConfirmPassword.value
		}
		
		if(str1 != str2){
			if(document.all.TipoIdioma.value == 2)
				Error("Incorrect password\n")
			else
				if(document.all.TipoIdioma.value == 3)	
					Error("As senhas não podem se confirmar\n")
				else
					Error("Las contraseñas no coinciden\n")
		}

		
		/* ### TERMINOS Y CONDICIONES ### */
		if(document.all){
			if(document.all.chkbxTerminosAceptadosID.checked == false){
				if(document.all.TipoIdioma.value == 2)
					Error("Sorry, you can not continue if you do not accept or confirm\n")
				else
					if(document.all.TipoIdioma.value == 3)
						Error("Não pode continuar. Aceptar\n")
					else	
						Error("Lo siento, no puede continuar sin aceptar o confirmar\n")
				}	
			else
				if(document.frmUsrData.chkbxTerminosAceptadosID.checked == false){
					if(document.all.TipoIdioma.value == 2)
						Error("Sorry, you can not continue if you do not accept or confirm\n")
					else
						if(document.all.TipoIdioma.value == 3)
							Error("Não pode continuar. Aceptar\n")
						else	
							Error("Lo siento, no puede continuar sin aceptar o confirmar\n")
				}			
		}
		
		/* ###  EMAIL ### */
		/* Deuda pendiente */
		/* ******************************************************** */
		if(document.all)
			str1 = document.all.vch2EMail.value;
		else
			str1 = document.frmUsrData.vch2EMail.value;
					
		if(str1.length <= 0){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter an E-MAIL Account. This field is required to complete the registration process\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo E-mail não pode ficar vazio\n")	
				else
					Error("Debe completar el campo E-mail\n")
		}			

		/* ### NOMBRE ###  */
		if(document.all)
			str1 = document.all.vch2FirstName.value
		else
			str1 = document.frmUsrData.vch2FirstName.value
			
		if(str1.length <= 0){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a First Name. This field is required to complete the registration process\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo Nome não pode ficar vazio\n")	
				else
					Error("Debe completar el campo Nombre\n")
		}			
				
				
		/* ### APELLIDO ### */
		if(document.all)
			str1 = document.all.vch2LastName.value
		else
			str1 = document.frmUsrData.vch2LastName.value
			
		if(str1.length <= 0){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a Last Name. This field is required to complete the registration process\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo Sobrenome não pode ficar vazio\n")
				else
					Error("Debe completar el campo Apellido\n")
		}			
				

		/* ### DIRECCION ### */		
		if(document.all)
			str1 = document.all.vch2Address1.value
		else
			str1 = document.frmUsrData.vch2Address1.value
			
		if(str1.length <= 0){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a Address. This field is required to complete the registration process\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo Endereço não pode ficar vazio\n")
				else
					Error("Debe completar el campo Direccion\n")
		}
		
		/* ### ZIP ### */
		if(document.all)
			str1 = document.all.vch2Zip.value
		else
			str1 = document.frmUsrData.vch2Zip.value
		
		if(str1.length <= 0){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a Zip/Postal Code. This field is required to complete the registration process\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo C.P.F. não pode ficar vazio\n")	
				else
					Error("Debe completar el campo Codigo Postal\n")
		}			
			
		/* ### CIUDAD ### */
		if(document.all)
			str1 = document.all.vch2City.value
		else
			str1 = document.frmUsrData.vch2City.value
		
		if(str1.length <= 0){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a City. This field is required to complete the registration process\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo Cidade não pode ficar vazio\n")	
				else
					Error("Debe completar el campo Ciudad\n")
		}
		
		/* ### ESPECIALIDAD PARA NANOTEC LATINA ### */
		if(document.all){
		
			str1 = document.all.vch2Especialidad.value
			if(str1 == 'Otros'){
				str2 = document.all.vch2Cargo.value
				if(str2.length <= 0){
					Error("Debe completar rubro\n")
				}
			}	
		}		
		else
			{
			str1 = document.frmUsrData.vch2Especialidad.value
			if(str1 == 'Otros'){
				str2 = document.frmUsrData.vch2Cargo.value
				if(str2.length <= 0){
					Error("Debe completar rubro\n")
				}
			}	
		}	
		
		
		/* ### PROVINCIA/ESTADO ### */
		if(document.all)
			str1 = document.all.vch2State.value
		else
			str1 = document.frmUsrData.vch2State.value

		if(str1.length <= 0){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a State/Province. This field is required to complete the registration process\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo Estado não pode ficar vazio\n")	
				else
					Error("Debe completar el campo Provincia/Estado\n")
		}	
			
		if(str1.length <= 0){
			if(document.all.TipoIdioma.value == 2)
				Error("You did not enter a State/Province. This field is required to complete the registration process\n")
			else
				if(document.all.TipoIdioma.value == 3)
					Error("O campo Estado não pode ficar vazio\n")	
				else
					Error("Debe completar el campo Provincia/Estado\n")
		}	

		
		/* ### DETERMINADOS CODALIALINZA PIDEN TELEFONO ### */
		
		if(document.all)
			str1 = document.all.vch2Phone.value
		else
			str1 = document.frmUsrData.vch2Phone.value
			
		if(codalianza == 4090  || codalianza == 4032)
				if(str1.length <= 0){
					Error("Debe completar el campo Telefono\n")
			}			
		
				
		/* ### persona juridica con empresa/razon legal ### */
		
		if(document.all.vch2TipoPersona)
		{
 
			if(document.all)
				if(document.all.vch2TipoPersona.value)
					str1 = document.all.vch2TipoPersona.value
				else
					str1 = document.all.vch2TipoPersona[document.all.vch2TipoPersona.selectedIndex].value	
			else
				if(document.frmUsrData.vch2TipoPersona.value)
					str1 = document.frmUsrData.vch2TipoPersona.value
				else
					str1 = document.frmUsrData.vch2TipoPersona[document.all.vch2TipoPersona.selectedIndex].value
		
			if(document.all)
				str2 = document.all.vch2Company.value
			else
				str2 = document.frmUsrData.vch2Company.value
			
			if(document.all)
				str3 = document.all.vch2RazonSocial.value
			else
				str3 = document.frmUsrData.vch2RazonSocial.value
			
			
			/* condicion */
		
			if(str1 == 2){
				if(str2.length <=0){
					if(document.all.TipoIdioma.value == 2)
						Error("You must inform your Company\n")
					else
						if(document.all.TipoIdioma.value == 3)
							Error("O campo Empresa não pode ficar vazio\n")	
						else
							Error("Si es Persona Juridica, ingrese Empresa\n")
				}
			}		
			
			if(str1 == 2){
				if(str3.length <=0){
					if(document.all.TipoIdioma.value == 2)
						Error("You must inform your Legal Name\n")
					else
						if(document.all.TipoIdioma.value == 3)
							Error("O campo Razão Social não pode ficar vazio\n")	
						else
							Error("Si es Persona Juridica, ingrese Razon Social\n")
				}
			}	
		}
		
		
		/* Al finalizar, se comprueba el valor del flag retorno */
		
		if(!retorno){
			if(document.all.TipoIdioma.value == 2)
				alert("The following errors have occurred:\n" + strMsgError)
			else
				if(document.all.TipoIdioma.value == 3)
					alert("Aconteceram os seguintes erros:\n" + strMsgError)
				else
					alert("Se produjeron los siguientes errores:\n" + strMsgError)
		}
		
		strMsgError = ""
		str1 = ""
		str2 = ""
		
		return retorno
		
	}

	/* 
		Esta funcion actualiza el texto del mail, para mostrar al usuario 
		como quedaria su nombre de cuenta
		La variable mode identifica el modo de comportamiento. 
		Si tiene el valor ALL se actualizan tanto el div como el campo "cuenta con la que quiere operar"
		Si vale STORE se actualiza solo el valor del campo "cuenta con la que quiere operar"
	*/
	function ActualizaEMail(accion){
		var str1;

			
		if(document.all){
			/* mostrar solo si no es una alianza */
			if(accion=="ALL"){
				divSpanMail.innerHTML = document.all.vch2User_ID.value + "@latinvia.com";
				
				/* actualizar el campo Cuenta con la que va a operar */
				str1 = document.all.vch2User_ID.value + "@latinvia.com";
				document.all.vch2EMail_ID.value = str1;
			}
		}
		else if(document.layers){
			/* mostrar solo si no es una alianza */
			if(accion=="ALL"){
				document.layers["layerSpanMail"].document.open();
				document.layers["layerSpanMail"].document.write("<p class='azulbold-tit14'>" + document.frmUsrData.vch2User_ID.value + "@latinvia.com</p>");
				document.layers["layerSpanMail"].document.close();
				/* actualizar el campo Cuenta con la que va a operar */
				str1 = document.frmUsrData.vch2User_ID.value + "@latinvia.com";
				document.frmUsrData.vch2EMail.value = str1;
			}
		}
		else{
			alert("Su cuenta de email sera:" + document.frmUsrData.vch2User_ID.value + "@latinvia.com");
		}
	}
	
	/* Limpiar: Ejecuta reset del formulario */
	function Limpiar(){
		if(document.all){ /* MS Explorer */
			document.all.frmUsrData.reset()
		}
		else if(document.layers){ /* Netscape 4.x */
			document.frmUsrData.reset()
		}
		else{ /* Otro */
			document.all.frmUsrData.reset()
		}
	}
	
	/* Enviar: Ejecuta submit del formulario */
	function Enviar(codalianza){
		/*Solamente habilita el campo cfinput del mail
		para que el otro conozca el valor*/
		document.all.vch2EMail.disabled = false;
	
		if(document.all){ /* MS Explorer */
			if(CheckFormData(codalianza))
				document.all.frmUsrData.submit()
				/*Solamente habilita el campo cfinput del mail
				para que el otro conozca el valor*/
				document.all.vch2EMail.disabled = false;
		}
		else if(document.layers){ /* Netscape 4.x */
			if(CheckFormData())
				document.frmUsrData.submit()
				document.all.vch2EMail.disabled = false;
		}
		else{ /* Otro */
			if(CheckFormData(codalianza))
				document.all.frmUsrData.submit()
				/*Solamente habilita el campo cfinput del mail
				para que el otro conozca el valor*/
				document.all.vch2EMail.disabled = false;
		}
	}

	/* Mostrar en un ventana, informacion sobre la cookie */
	function MostrarInfoCookie()
	{
		var newWindow
		
		newWindow = window.open("info/cookie.html","windowInfoCookie","width=350,height=350,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,dependent=yes")
		
	}
	
	/* Mostrar ventana con Terminos y condiciones */
	function Terminos()
	{
		VentanaTermino = window.open("../organizador/info/ayudas/dsp_terminos_condiciones.cfm","TerminosLatinvia","top=10,left=255,width=518=,height=300,location=no,toolbar=no,directories=no,status=no,menubar=no,resizeable=yes,scrollbars=yes");
	}
		
