/************************** SUBMITS **********************************/

function validateEndUser()
{
	//el array de flags comienza en 0 para cada posicion. La misma representa cada una de las validaciones, si ocurre algun error el indice cambia a 1
	//Al final se recorrer&aacute; la coleccion y si algun indice == 1 mostramos error, sino mostramos ok.
	var _flagArray = new Array('0','0','0','0','0','0');
	i = 0;
	
	var iPais = document.getElementById('hdnCountry').value;
		
	MensajeProvincia = "";
	MensajeCiudad = "";
	MensajeOtraUbicacion= "";
	switch (iPais)
	{
	case "7": 
		MensajeProvincia = "Selecciona tu provincia de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Introduce tu ciudad de residencia.";
		break;
	case "27": 
		MensajeProvincia = "Selecciona tu provincia de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "28": 
		MensajeProvincia = "Selecciona tu departamento de residencia."; 
		MensajeCiudad = "Selecciona tu distrito de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu distrito de residencia.";
		break;
	case "29": 
		MensajeProvincia = "Selecciona tu regi&oacute;n de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "33": 
		MensajeProvincia = "Selecciona tu estado de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "34": 
		MensajeProvincia = "Selecciona tu provincia de residencia.";
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";	
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";		
		break;
	case "39": 
		MensajeProvincia = "Selecciona tu departamento de residencia.";
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "46": 
		MensajeProvincia = "Selecciona tu estado de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	}
	
	//Provincia
	prov = document.getElementById('provinceId').value;
	if(validarSelect(prov,'divProvinceUS','err_command.provinceId',MensajeProvincia) == false)
			_flagArray[i] = '1';i++;
				
	//Localidad
	loc = document.getElementById('cityId').value;
	
	if(validarSelect(loc,'divCitiesUS','err_command.cityId','' + MensajeCiudad + 'Si no la encuentras en el listado, selecciona la opci&oacute;n "Otra Ubicaci&oacute;n" e ingr&eacute;sala.') == false)
		_flagArray[i] = '1';i++;

	//OtraUbicacion
		
		if(document.getElementById('divOtherLocationUS').className != "hide")
		{
			if(validarTexto('addressCustomCityName',1,30,'err_command.addressCustomCityName','La ubicacion debe hasta 30 caracteres.', MensajeOtraUbicacion ,'divOtherLocationUS') == false)
				_flagArray[i] = '1';i++;
		}
		else
		{			
			setErrorState('divOtherLocationUS','err_command.addressCustomCityName','hide','');
			document.getElementById("addressCustomCityName").value="";
		}	
	
	if(iPais == '39')
	{
		if (document.getElementById('documentValue1') != null)
		{
			//valido cada input separado, porque si uno esta vacio no seria un numero, entonces daria error.	
			if(document.getElementById('documentValue1').value != "")
			{
				documento = document.getElementById('documentValue1').value.trim();					
			
				if(!validarSoloNumeros(documento))
				{
					document.getElementById('err_command.documentNumber').innerHTML = "Ingresa s&oacute;lo n&uacute;meros.";
					setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
					_flagArray[i] = '1';
				}
				else 
				{
					setErrorState('divCuitCA','err_command.documentNumber','','none');
					document.getElementById('documentNumber').value= document.getElementById('documentValue1').value.trim();			
				}
			}
			else
			{
				document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el documento.";
				setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
				_flagArray[i] = '1';		
			}
		}
	}	
	//Verifico si hay errores en la pagina
	if(findErrors(_flagArray) == true)
	{
		clearErrors();
		document.getElementById('divError').className = "error hide";		
		document.formMydata.submit();	
	}
	else
	{
		document.getElementById('divError').className = "error";
		document.getElementById('divError').innerHTML = "Busca este &iacute;cono para encontrar los errores en la p&aacute;gina."
		location.href = "#focusError";
	}
}

function validateCarAgency()
{		
	//el array de flags comienza en 0 para cada posicion. La misma representa cada una de las validaciones, si ocurre algun error el indice cambia a 1
	//Al final se recorrera la coleccion y si algun indice == 1 mostramos error, sino mostramos ok.
	var _flagArray = new Array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	i = 0;
	
	var iPais = document.getElementById('hdnCountry').value;

	
		if(iPais == '7'){
		enterCodeArea="Introduce el c&oacute;digo de &aacute;rea.";
		enterPhone="Introduce el tel&eacute;fono.";
		reasonSocial="Introduce la raz&oacute;n social.";
	}else{
		enterCodeArea="Ingresa el c&oacute;digo de &aacute;rea.";
		enterPhone="Ingresa el tel&eacute;fono.";
		reasonSocial="Ingresa la raz&oacute;n social.";
	}
	
	
	
	MensajeConcesionaria = "";
	switch (iPais)
	{
	case "27": MensajeConcesionaria = "Ingresa el nombre de la concesionaria."; break;
	case "29": MensajeConcesionaria = "Ingresa el nombre de la automotora."; break;
	case "39": MensajeConcesionaria = "Ingresa el nombre de la concesionario."; break;
	case "46": MensajeConcesionaria = "Ingresa el nombre de la agencia."; break;
	case "28": MensajeConcesionaria = "Ingresa el nombre de la concesionario."; break;
	case "33": MensajeConcesionaria = "Ingresa el nombre de la concesionario."; break;
	case "34": MensajeConcesionaria = "Ingresa el nombre de la concesionario."; break;
	case "7": MensajeConcesionaria = "Introduce el nombre del concesionario."; break;
	}
	
	var mensajeError = "Ingresa el nombre de la concesionaria."
	if (iPais == 39){
		mensajeError = "Ingresa el nombre del concesionario."
	}
	else if(iPais == 46)
	{
		mensajeError = "Ingresa el nombre de la agencia."
	}
		
	if(iPais == '7'){
		enterBranch="Introduce el nombre de la sucursal.";
		onlyNumber="Puedes introducir s&oacute;lo letras y/o n&uacute;meros.";
	}else{
		enterBranch="Ingresa el nombre de la sucursal.";
		onlyNumber="Puedes ingresar s&oacute;lo letras y/o n&uacute;meros.";
	}	
		
	//Nombre Concesionaria
	if(validarTexto('fantasyName',1,50,'err_command.fantasyName',MensajeConcesionaria,MensajeConcesionaria,'divNameCA') == true)
	{
		if(!validarUsuario(document.getElementById('fantasyName').value,'1'))
		{
			_flagArray[i] = '1';i++;
			document.getElementById('err_command.fantasyName').innerHTML = onlyNumber;
			setErrorState('divNameCA','err_command.fantasyName','errorSmall','block');
		}	
		else
			setErrorState('divNameCA','err_command.fantasyName','','none');
	}
	else
		_flagArray[i] = '1';
	
	i++;	
		
		
		
	//Nombre Sucursal		
	
	if(document.getElementById('divSucursalCA'))
	{
		if(document.getElementById('divSucursalCA').className != "hide")
		{
			if(validarTexto('branchName',1,30,'err_command.branchName',enterBranch,enterBranch,'divSucursalCA') == true)
			{
				if(!validarUsuario(document.getElementById('branchName').value,'1'))
				{
					_flagArray[i] = '1';
					document.getElementById('err_command.branchName').innerHTML = onlyNumber;
					setErrorState('divSucursalCA','err_command.branchName','errorSmall','block');
				}	
				else
					setErrorState('divSucursalCA','err_command.branchName','','none');
			}
			else			
				_flagArray[i] = '1';							
		}
		else{			
			document.getElementById('err_command.branchName').innerHTML = "";
			document.getElementById('branchName').value="";
		}
	}		
	i++;
	
	MensajeTipoConcesionaria = "";
	switch (iPais)
	{
	case "7": MensajeTipoConcesionaria = "Selecciona el tipo de concesionario"; break;
	case "27": MensajeTipoConcesionaria = "Selecciona el tipo de concesionaria."; break;
	case "28": MensajeTipoConcesionaria = "Selecciona el tipo de concesionario."; break;
	case "29": MensajeTipoConcesionaria = "Selecciona el tipo de automotora."; break;
	case "33": MensajeTipoConcesionaria = "Selecciona el tipo de concesionario."; break;
	case "34": MensajeTipoConcesionaria = "Selecciona el tipo de concesionario."; break;
	case "39": MensajeTipoConcesionaria = "Selecciona el tipo de concesionario."; break;
	case "46": MensajeTipoConcesionaria = "Selecciona el tipo de agencia."; break;
	}
	
	//Tipo Concesionaria
	if(validarRadio('carAgencyTypeId') == true)
		setErrorState('divTypeCA','err_command.carAgencyTypeId','','none');
	else
	{
		setErrorState('divTypeCA','err_command.carAgencyTypeId','errorSmall','block');
		document.getElementById('err_command.carAgencyTypeId').innerHTML = MensajeTipoConcesionaria;
		_flagArray[i] = '1';
	}		
	i++;	
	
	MensajeProvincia = "";
	MensajeCiudad = "";
	MensajeOtraUbicacion = "";
	switch (iPais)
	{
	case "7": 
		MensajeProvincia = "Selecciona tu provincia de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Introduce tu ciudad de residencia.";
		break;
	case "27": 
		MensajeProvincia = "Selecciona tu provincia de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "28": 
		MensajeProvincia = "Selecciona tu departamento de residencia."; 
		MensajeCiudad = "Selecciona tu distrito de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu distrito de residencia.";
		break;
	case "29": 
		MensajeProvincia = "Selecciona tu regi&oacute;n de residencia.";
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "33": 
		MensajeProvincia = "Selecciona tu estado de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "34": 
		MensajeProvincia = "Selecciona tu provincia de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "39": 
		MensajeProvincia = "Selecciona tu departamento de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	case "46": 
		MensajeProvincia = "Selecciona tu estado de residencia."; 
		MensajeCiudad = "Selecciona tu ciudad de residencia. ";
		MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
		break;
	}
			
	//Provincia
	campo = document.getElementById('provinceId').value;
	if(validarSelect(campo,'divProvinceCA','err_command.provinceId', MensajeProvincia) == false)	
		_flagArray[i] = '1';
	i++;
	
				
	//Localidad
	campo = document.getElementById('cityId').value;
	if(validarSelect(campo,'divCitiesCA','err_command.cityId', '' + MensajeCiudad + ' Si no la encuentras en el listado, selecciona la opci&oacute;n "Otra Ubicaci&oacute;n" e ingr&eacute;sala.') == false)	
		_flagArray[i] = '1';
	i++;
	
	//OtraUbicacion		
	if(document.getElementById('divOtherLocation').className != "hide")
	{
		if(validarTexto('addressCustomCityName',1,30,'err_command.addressCustomCityName','La ubicacion debe hasta 30 caracteres.',MensajeOtraUbicacion,'divOtherLocation') == false)		
			_flagArray[i] = '1';		
	}				
	else
		document.getElementById('addressCustomCityName').value="";
		
	
	
	i++;
	//Direccion
	mensajeCalle = "Ingresa la calle."
	if(iPais == '28' || iPais == '33' || iPais == '34' || iPais == '39')
		mensajeCalle = "Ingresa la direcci&oacute;n."
			
		
	if(iPais == '7')
		mensajeCalle = "Introduce la calle."
	
	if(validarTexto('addressStreet',1,60,'err_command.addressStreet',mensajeCalle,mensajeCalle,'divStreet') == false)
	{
		_flagArray[i] = '1';
	}
	i++;
	
	//Mapa
	if(	document.getElementById("isValidMap").value!="true" ) {	
		_flagArray[i] = '1'; 
		document.getElementById('generarMapa').className = 'errorSmall';
	} else {
		document.getElementById('generarMapa').className = '';
	}
	i++;

	if(iPais == '7'){
		enterCodePostal="Introduce el c&oacute;digo postal.";
		enterNumber="Introduce el n&uacute;mero.";
		msgNumbersInNumber="Puedes introducir s&oacute;lo n&uacute;meros en el campo n&uacute;mero.";
		msgNumbersInFloor="Puedes introducir s&oacute;lo n&uacute;meros en el campo piso.";
		msgOnlyWordsInAppartment="Puedes introducir s&oacute;lo letras y/o n&uacute;meros en el campo depto.";
	}else{
		enterCodePostal="Ingresa el c&oacute;digo postal.";
		enterNumber="Ingresa el n&uacute;mero.";
		msgNumbersInNumber="Puedes ingresar s&oacute;lo n&uacute;meros en el campo n&uacute;mero.";
		msgNumbersInFloor="Puedes ingresar s&oacute;lo n&uacute;meros en el campo piso.";
		msgOnlyWordsInAppartment="Puedes ingresar s&oacute;lo letras y/o n&uacute;meros en el campo depto.";
	}	
	
	if(iPais != '39' && iPais != '33' && iPais != '34' && iPais != '28') //Colombia no tiene estos datos
	{	
		//Codigo Postal
		if(iPais == '27')
		{
		if(validarTexto('addressPostalCode',1,12,'err_command.addressPostalCode',enterCodePostal,enterCodePostal,'divZipCodeCA') == true)
		{
			if(validarLetrasNumeros(document.getElementById('addressPostalCode').value,"") == false)
			{
				setErrorState('divZipCodeCA','err_command.addressPostalCode','errorSmall','block');
				document.getElementById('err_command.addressPostalCode').innerHTML = onlyNumber;
				_flagArray[i] = '1';				
			}
		}
		else	
			_flagArray[i] = '1';
		}
		i++;
		
					
		//Numero
		if(validarTexto('addressNumber',1,7,'err_command.addressNumber,command.addressFloor,command.addressDepartment',enterNumber,enterNumber,'divStreetDataCA') == true)
		{
			if(isNaN(document.getElementById('addressNumber').value))
			{
				_flagArray[i] = '1';
				document.getElementById('err_command.addressNumber,command.addressFloor,command.addressDepartment').innerHTML = msgNumbersInNumber;
				setErrorState('divStreetDataCA','err_command.addressNumber,command.addressFloor,command.addressDepartment','errorSmall','block');
			}			
		}
		else
		{
			_flagArray[i] = '1';
		}
			
		// Piso 
		if(document.getElementById('addressFloor') != null){
		if(isNaN(document.getElementById('addressFloor').value))
		{
			_flagArray[i] = '1';
				document.getElementById('err_command.addressNumber,command.addressFloor,command.addressDepartment').innerHTML = msgNumbersInFloor;
			setErrorState('divStreetDataCA','err_command.addressNumber,command.addressFloor,command.addressDepartment','errorSmall','block');
		}		
		}
		else
			_flagArray[i] = '0';
			
		i++;
			
		// Depto
		if(document.getElementById('addressDepartment') != null){
		if(validarDepto(document.getElementById('addressDepartment').value) == false)
		{
			_flagArray[i] = '1';
				document.getElementById('err_command.addressNumber,command.addressFloor,command.addressDepartment').innerHTML = msgOnlyWordsInAppartment;
			setErrorState('divStreetDataCA','err_command.addressNumber,command.addressFloor,command.addressDepartment','errorSmall','block');
		}		
		i++;
	}
		else
			_flagArray[i] = '0';
	}
	
	
	
	
	
	
	// Razon Social
	if(validarRazonSocial('commercialName','err_command.commercialName',reasonSocial,'divCommercialNameCA') == false)	
		_flagArray[i] = '1';
	i++;
	
	if (iPais == 27 || iPais == 39)
	{		
		if (iPais == 27)
			mensaje = 'Selecciona una condici&oacute;n ante el IVA.';		
		if (iPais == 39)
			mensaje = 'Selecciona un tipo de r&eacute;gimen.';
	
		campo = document.getElementById('taxConditionId').value;
		if(validarSelect(campo,'divIVACA','err_command.taxConditionId', mensaje) == false)		
			_flagArray[i] = '1';
		i++;
	}
	
	//DOCUMENTO
	var documento;
	switch (iPais)
	{			
			case "27":		
			//valido cada input separado, porque si uno esta vacio no seria un numero, entonces daria error.			
			if (document.getElementById('divCuitCA').className != "hide")
			{
				if(document.getElementById('documentValue1').value != "" && document.getElementById('documentValue2').value != "" && document.getElementById('documentValue3').value != "")
				{
					documento = document.getElementById('documentValue1').value + document.getElementById('documentValue2').value + document.getElementById('documentValue3').value	
					if (isNaN(documento) || validarExpression("Documento",documento))
					{
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						document.getElementById('err_command.documentNumber').innerHTML = "Puedes ingresar s&oacute;lo n&uacute;meros.";
						_flagArray[i] = '1';
						break;
					}
					else
					{
						//Documento 1
						if(validarTexto('documentValue1',0,2,'err_command.documentNumber','Ingresa el CUIT.','Puedes ingresar s&oacute;lo n&uacute;meros.','divCuitCA') == false)
							_flagArray[i] = '1';
						//Documento 2
						if(validarTexto('documentValue2',0,8,'err_command.documentNumber','Ingresa el CUIT.','Puedes ingresar s&oacute;lo n&uacute;meros.') == false)
							_flagArray[i] = '1';
						//Documento 3
						if(validarTexto('documentValue3',0,1,'err_command.documentNumber','Ingresa el CUIT.','Puedes ingresar s&oacute;lo n&uacute;meros.') == false)
							_flagArray[i] = '1';
					}
				}
				else
				{
					document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el CUIT.";
					setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
					_flagArray[i] = '1';			
				}
			}			
			else
			{
				document.getElementById('documentValue1').value="";
				document.getElementById('documentValue2').value="";
				document.getElementById('documentValue3').value="";
			}
			if(_flagArray[i] == '0')
				documento = document.getElementById('documentValue1').value +"-"+ document.getElementById('documentValue2').value +"-"+ document.getElementById('documentValue3').value
			break;
			case "29":
								
				if(document.getElementById('documentValue1').value != "" && document.getElementById('documentValue2').value != "")
				{
					if(validarLetrasNumeros(document.getElementById('documentValue1').value,"") && validarLetrasNumeros(document.getElementById('documentValue2').value,"")) 
					{
						if(!validarRut(document.getElementById('documentValue1').value + document.getElementById('documentValue2').value))						
						{					
							document.getElementById('err_command.documentNumber').innerHTML = "Ingresa un RUT v&aacute;lido.";
							setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
							_flagArray[i] = '1';
						}
						else
						{
							setErrorState('divCuitCA','err_command.documentNumber','','none');
							documento = document.getElementById('documentValue1').value +"-"+ document.getElementById('documentValue2').value
						}
					}
					else
					{
						_flagArray[i] = '1';
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						document.getElementById('err_command.documentNumber').innerHTML = "Puedes ingresar s&oacute;lo letras y/o n&uacute;meros.";						
					}
				}
				else
				{	
					if ((document.getElementById('documentValue1').value != "" || document.getElementById('documentValue2').value != "") && !(document.getElementById('documentValue1').value != "" && document.getElementById('documentValue2').value != ""))
					{	//XOR
						document.getElementById('err_command.documentNumber').innerHTML = "Ingresa un RUT v&aacute;lido.";
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						_flagArray[i] = '1';
					}
					else
					{
						document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el RUT.";
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						_flagArray[i] = '1';
					}
				}
				
			break;
			case "39":
			if (document.getElementById('divCuitCA').className != "hide")
			{
				//valido cada input separado, porque si uno esta vacio no seria un numero, entonces daria error.	
				if(document.getElementById('documentValue1').value != "")
				{
					documento = document.getElementById('documentValue1').value.trim();					
				
					if(!validarSoloNumeros(documento))
					{
						document.getElementById('err_command.documentNumber').innerHTML = "Puedes ingresar s&oacute;lo n&uacute;meros.";
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						_flagArray[i] = '1';
					}
					else 
					{
						document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el NIT.";
						setErrorState('divCuitCA','err_command.documentNumber','','none');
						documento = document.getElementById('documentValue1').value.trim();			
					}
				}
				else
				{
					document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el NIT.";
					setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
					_flagArray[i] = '1';		
				}
			}
			break;
			case "46":
			if(document.getElementById('documentValue1').value != ""){
				if(!validarRFC(document.getElementById('documentValue1').value))
				{
					document.getElementById('err_command.documentNumber').innerHTML = "Puedes ingresar s&oacute;lo letras y/o n&uacute;meros.";
					setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
					_flagArray[i] = '1';		       
				}
				else
				{
					setErrorState('divCuitCA','err_command.documentNumber','','none');
					documento = document.getElementById('documentValue1').value.trim();			
				}
				break;		
			}
			else
			{
				document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el R.F.C.";
				setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
				_flagArray[i] = '1';		
			}
			break;
			/*case "28":
				if(document.getElementById('documentValue1').value != ""){
					if(!validarRFC(document.getElementById('documentValue1').value))
					{
						document.getElementById('err_command.documentNumber').innerHTML = "Puedes ingresar s&oacute;lo letras y/o n&uacute;meros.";
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						_flagArray[i] = '1';		       
					}
					else
					{
						setErrorState('divCuitCA','err_command.documentNumber','','none');
						documento = document.getElementById('documentValue1').value.trim();			
					}
					break;		
				}
				else
				{
					document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el R.F.C.";
					setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
					_flagArray[i] = '1';		
				}
				break;			
			case "33":
				if(document.getElementById('documentValue1').value != ""){
					if(!validarRFC(document.getElementById('documentValue1').value))
					{
						document.getElementById('err_command.documentNumber').innerHTML = "Puedes ingresar s&oacute;lo letras y/o n&uacute;meros.";
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						_flagArray[i] = '1';		       
					}
					else
					{
						setErrorState('divCuitCA','err_command.documentNumber','','none');
						documento = document.getElementById('documentValue1').value.trim();			
					}
					break;		
				}
				else
				{
					document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el R.F.C.";
					setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
					_flagArray[i] = '1';		
				}
				break;
			case "34":
				if(document.getElementById('documentValue1').value != ""){
					if(!validarRFC(document.getElementById('documentValue1').value))
					{
						document.getElementById('err_command.documentNumber').innerHTML = "Puedes ingresar s&oacute;lo letras y/o n&uacute;meros.";
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						_flagArray[i] = '1';		       
					}
					else
					{
						setErrorState('divCuitCA','err_command.documentNumber','','none');
						documento = document.getElementById('documentValue1').value.trim();			
					}
					break;		
				}
				else
				{
					document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el R.F.C.";
					setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
					_flagArray[i] = '1';		
				}
				break;
			case "7":
				if(document.getElementById('documentValue1').value != ""){
					if(!validarRFC(document.getElementById('documentValue1').value))
					{
						document.getElementById('err_command.documentNumber').innerHTML = "Puedes ingresar s�lo letras y/o n�meros.";
						setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
						_flagArray[i] = '1';		       
	}
					else
					{
						setErrorState('divCuitCA','err_command.documentNumber','','none');
						documento = document.getElementById('documentValue1').value.trim();			
					}
					break;		
				}
				else
				{
					document.getElementById('err_command.documentNumber').innerHTML = "Ingresa el R.F.C.";
					setErrorState('divCuitCA','err_command.documentNumber','errorSmall','block');
					_flagArray[i] = '1';		
				}
				break;*/
	}

	document.getElementById('documentNumber').value = documento;
	
	i++;	
	
	if(iPais == '27')
	{		
		//domicilio comercial
		if(validarRadio('fiscalResidence') == true)
			setErrorState('divTypeCA','err_command.fiscalResidence','','none');
		else
		{
			setErrorState('divTypeCA','err_command.fiscalResidence','errorSmall','block');
			document.getElementById('err_command.fiscalResidence').innerHTML = "Selecciona alguna de las opciones";
			_flagArray[i] = '1';
		}
		i++;
		
		if (document.getElementById('dibDatosFiscales').className != 'hide')
		{		
			//Provincia Fiscal
			campo = document.getElementById('fiscalProvinceId').value;
			if(validarSelect(campo,'divProvinceFistalCA','err_command.fiscalProvinceId', 'Selecciona tu provincia de residencia.') == false)		
				_flagArray[i] = '1';
			i++;
			
			//Localidad Fiscal
			campo = document.getElementById('fiscalCityId').value;
			if(validarSelect(campo,'divCitiesFiscalCA','err_command.fiscalCityId', 'Selecciona tu ciudad de residencia. Si no la encuentras en el listado, selecciona la opci&oacute;n "Otra Ubicaci&oacute;n" e ingr&eacute;sala.') == false)
				_flagArray[i] = '1';
			i++;		
		
			//OtraUbicacion		
			if(document.getElementById('divOtherFiscalLocation').className != "hide")
			{
				if(validarTexto('fiscalAddressCustomCityName',1,30,'err_command.fiscalAddressCustomCityName','La ubicacion debe hasta 30 caracteres.','Ingresa tu ciudad de residencia.','divOtherFiscalLocation') == false)
					_flagArray[i] = '1';			
			}				
			else
				document.getElementById('fiscalAddressCustomCityName').value="";
			i++;
			
			//Direccion Fiscal
			if(validarTexto('fiscalAddressStreet',1,60,'err_command.fiscalAddressStreet','Ingresa la calle.','Ingresa la calle.','divFiscalStreet') == false)
				_flagArray[i] = '1';
			i++;
			
			//Codigo Postal Fiscal
			if(validarTexto('fiscalAddressPostalCode',1,12,'err_command.fiscalAddressPostalCode','Ingresa el c&oacute;digo postal.','Ingresa el c&oacute;digo postal.','divFiscalZipCodeCA') == true)
			{
				if(validarLetrasNumeros(document.getElementById('fiscalAddressPostalCode').value,"") == false)
				{
					document.getElementById('err_command.fiscalAddressPostalCode').innerHTML = "Puedes ingresar s&oacute;lo letras y/o n&uacute;meros.";
					setErrorState('divFiscalZipCodeCA','err_command.fiscalAddressPostalCode','errorSmall','block');
					_flagArray[i] = '1';
				}
			}
			else		
				_flagArray[i] = '1';
			i++;							
			
			
			if(iPais == '7'){
				enterCodePostal="Introduce el c&oacute;digo postal.";
				enterNumber="Introduce el n&uacute;mero.";
				msgNumbersInNumber="Puedes introducir s&oacute;lo n&uacute;meros en el campo n&uacute;mero.";
			}else{
				enterCodePostal="Ingresa el c&oacute;digo postal.";
				enterNumber="Ingresa el n&uacute;mero.";
				msgNumbersInNumber="Puedes ingresar s&oacute;lo n&uacute;meros en el campo n&uacute;mero.";
			}	
			
			//Numero Fiscal
			if(validarTexto('fiscalAddressNumber',1,7,'err_command.fiscalAddressDepartment,command.fiscalAddressDepartment,command.fiscalAddressDepartment','Ingresa el n&uacute;mero.','Ingresa el n&uacute;mero.','divFiscalStreetDataCA') == true)
			{
				if(isNaN(document.getElementById('fiscalAddressNumber').value))
				{
					_flagArray[i] = '1';
					document.getElementById('err_command.fiscalAddressDepartment,command.fiscalAddressDepartment,command.fiscalAddressDepartment').innerHTML = msgNumbersInNumber;
					setErrorState('divFiscalStreetDataCA','err_command.fiscalAddressDepartment,command.fiscalAddressDepartment,command.fiscalAddressDepartment','errorSmall','block');
				}
				else
					setErrorState('divFiscalStreetDataCA','err_command.fiscalAddressDepartment,command.fiscalAddressDepartment,command.fiscalAddressDepartment','','none');
			}
			else	
				_flagArray[i] = '1';
			i++;
	
			// Piso Fiscal
			if(isNaN(document.getElementById('fiscalAddressFloor').value))
			{
				_flagArray[i] = '1';
				document.getElementById('err_command.fiscalAddressDepartment,command.fiscalAddressDepartment,command.fiscalAddressDepartment').innerHTML = msgNumbersInFloor;
				setErrorState('divFiscalStreetDataCA','err_command.fiscalAddressDepartment,command.fiscalAddressDepartment,command.fiscalAddressDepartment','errorSmall','block');
			}
			i++;
			
			// Depto Fiscal
			if(validarLetrasNumeros(document.getElementById('fiscalAddressDepartment').value,"") == false)
			{
				_flagArray[i] = '1';
				document.getElementById('err_command.fiscalAddressDepartment,command.fiscalAddressDepartment,command.fiscalAddressDepartment').innerHTML = "Puedes ingresar s&oacute;lo letras y/o n&uacute;meros en el campo depto.";
				setErrorState('divFiscalStreetDataCA','err_command.fiscalAddressDepartment,command.fiscalAddressDepartment,command.fiscalAddressDepartment','errorSmall','block');
			}
			i++;
		}
		else
		{
			document.getElementById('fiscalAddressStreet').value=""
			document.getElementById('fiscalAddressNumber').value=""
			document.getElementById('fiscalAddressFloor').value=""
			document.getElementById('fiscalAddressDepartment').value=""
			document.getElementById('fiscalAddressPostalCode').value=""
		}
	}	
		
	
	if(iPais == '7'){
		msgOnlyInNumber="Puedes introducir s&oacute;lo n&uacute;meros.";
	}else{
		
		msgOnlyInNumber="Puedes ingresar s&oacute;lo n&uacute;meros.";
	}	
	

	
	if (document.getElementById('commercialContactMainPhoneAreaCode').value != "")
	{
		if(validarSoloNumeros(document.getElementById('commercialContactMainPhoneAreaCode').value) == true)
		{
			if (document.getElementById('commercialContactMainPhoneNumber').value != "")
			{
				if(validarSoloNumeros(document.getElementById('commercialContactMainPhoneNumber').value) == false){		
					_flagArray[i] = '1';
					document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = msgOnlyInNumber;
					setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
				}
				else					
					setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','','none');
			}
			else
			{
				_flagArray[i] = '1';
				document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = enterPhone;
				setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
			}
				
		}
		else	{
			_flagArray[i] = '1';
			document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = msgOnlyInNumber;
			setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
			}
	}
	else
	{
		_flagArray[i] = '1';
		document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = enterCodeArea;
		setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
	}
	i++;
	
	if(document.getElementById('commercialContactMainPhoneExtension').value.length > 0)
		if(validarSoloNumeros(document.getElementById('commercialContactMainPhoneExtension').value) == false) {		
			_flagArray[i] = '1';
			document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = msgOnlyInNumber;
			setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
		}	
	
	if(document.getElementById('commercialContactAlternativePhoneAreaCode').value.length > 0 || document.getElementById('commercialContactAlternativePhoneNumber').value.length > 0 || document.getElementById('commercialContactAlternativePhoneExtension').value.length > 0)
	{
		if (document.getElementById('commercialContactAlternativePhoneAreaCode').value != "")
		{
			if(validarSoloNumeros(document.getElementById('commercialContactAlternativePhoneAreaCode').value) == true)
			{
				if (document.getElementById('commercialContactAlternativePhoneNumber').value != "")
				{
					if(validarSoloNumeros(document.getElementById('commercialContactAlternativePhoneNumber').value) == false){		
						_flagArray[i] = '1';
						document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = msgOnlyInNumber;
						setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');
					}
					else					
						setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','','none');
				}
				else
				{
					_flagArray[i] = '1';
					document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = enterPhone;
					setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');
				}
			}
			else{
				_flagArray[i] = '1';
				document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = msgOnlyInNumber;
				setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');				
			}
			i++;						
		}
		else
		{
			_flagArray[i] = '1';
			document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = enterCodeArea;
			setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');
		}
		if(document.getElementById('commercialContactAlternativePhoneExtension').value.length > 0)
			if(validarSoloNumeros(document.getElementById('commercialContactAlternativePhoneExtension').value) == false) {		
				_flagArray[i] = '1';
				document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = msgOnlyInNumber;
				setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');
			}
	}	
	else
		setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','','none');
	
	//Verifico si hay errores en la pagina	
	if(findErrors(_flagArray) == true)
	{		
		clearErrors();
		document.getElementById('divError').className = "error hide";		
		document.formMydata.submit();		
	}
	else
	{				
		document.getElementById('divError').className = "error";
		document.getElementById('divError').innerHTML = "Busca este &iacute;cono para encontrar los errores en la p&aacute;gina."
		location.href = "#focusError";
	}	
}

function validateBusiness()
{		
	//el array de flags comienza en 0 para cada posicion. La misma representa cada una de las validaciones, si ocurre algun error el indice cambia a 1
	//Al final se recorrer&aacute; la coleccion y si algun indice == 1 mostramos error, sino mostramos ok.
	var _flagArray = new Array('0','0','0','0','0','0','0','0','0','0','0','0','0');
	i = 0;
	var iPais = document.getElementById('hdnCountry').value;

	
	var mensajeError = "Ingresa el nombre de la concesionaria."

	if (iPais == 7){
		mensajeError = "Introduce el nombre del concesionario."
		MensajeOtraUbicacion = "introduce tu ciudad de residencia.";
		MensajeConcesionaria = "intrudce el nombre de la concesionaria.";
		enterCodePostal="Introduce el c&oacute;digo postal.";
	}
	else{
	MensajeOtraUbicacion = "Ingresa tu ciudad de residencia.";
	MensajeConcesionaria = "Ingresa el nombre de la concesionaria.";
	enterCodePostal="Ingresa el c&oacute;digo postal.";
	}
	

	MensajeProvincia = "Selecciona tu provincia de residencia."; 
	MensajeCiudad = "Selecciona tu ciudad de residencia. ";
			
			
	//Provincia
	campo = document.getElementById('provinceId').value;
	if(validarSelect(campo,'divProvinceCA','err_command.provinceId', MensajeProvincia) == false)	
		_flagArray[i] = '1';
	i++;
				
	//Localidad
	campo = document.getElementById('cityId').value;
	if(validarSelect(campo,'divCitiesCA','err_command.cityId', '' + MensajeCiudad + ' Si no la encuentras en el listado, selecciona la opci&oacute;n "Otra Ubicaci&oacute;n" e ingr&eacute;sala.') == false)	
		_flagArray[i] = '1';
	i++;
	
	//OtraUbicacion		
	if(document.getElementById('divOtherLocation').className != "hide")
	{
		if(validarTexto('addressCustomCityName',1,30,'err_command.addressCustomCityName','La ubicacion debe hasta 30 caracteres.',MensajeOtraUbicacion,'divOtherLocation') == false)		
			_flagArray[i] = '1';		
	}				
	else
		document.getElementById('addressCustomCityName').value="";
	
	i++;
	//Direccion
	mensajeCalle = "Ingresa la calle."

	if(validarTexto('addressStreet',1,60,'err_command.addressStreet',mensajeCalle,mensajeCalle,'divStreet') == false)
	{
		_flagArray[i] = '1';
	}
	i++;

	if(iPais == '7'){
	
		onlyNumber="Puedes introducir s&oacute;lo letras y/o n&uacute;meros.";
		varPiso="Introduce el n&uacute;mero.";
		varPisoNum="Puedes introducir s&oacute;lo n&uacute;meros en el campo n&uacute;mero.";
	}else{
		onlyNumber="Puedes ingresar s&oacute;lo letras y/o n&uacute;meros.";
		varPiso="Ingresa el n&uacute;mero.";
		varPisoNum="Puedes ingresar s&oacute;lo n&uacute;meros en el campo n&uacute;mero.";
	}	
	
	if(validarTexto('addressPostalCode',1,12,'err_command.addressPostalCode',enterCodePostal,enterCodePostal,'divZipCodeCA') == true)
	{
		if(validarLetrasNumeros(document.getElementById('addressPostalCode').value,"") == false)
		{
			setErrorState('divZipCodeCA','err_command.addressPostalCode','errorSmall','block');
			document.getElementById('err_command.addressPostalCode').innerHTML = onlyNumber;
			_flagArray[i] = '1';				
		}
	}
	else {	
		_flagArray[i] = '1';
	}
	i++;
		
					
	//Numero
	if(document.getElementById('addressNumber') != null){
		if(validarTexto('addressNumber',1,7,'err_command.addressNumber,command.addressFloor,command.addressDepartment',varPiso,varPiso,'divStreetDataCA') == true)
	{
		if(isNaN(document.getElementById('addressNumber').value))
		{
			_flagArray[i] = '1';
				document.getElementById('err_command.addressNumber,command.addressFloor,command.addressDepartment').innerHTML = varPisoNum;
			setErrorState('divStreetDataCA','err_command.addressNumber,command.addressFloor,command.addressDepartment','errorSmall','block');
		}			
	}
	else
	{
		_flagArray[i] = '1';
	}
	}
	else
	{
		_flagArray[i] = '1';
	}
	i++;
	
	
	//Mapa
	if(	document.getElementById("isValidMap").value!="true" ) {	
		_flagArray[i] = '1'; 
		document.getElementById('generarMapa').className = 'errorSmall';
	} else {
		document.getElementById('generarMapa').className = '';
	}
	i++;
			

	if(iPais == '7'){
		enterCodeArea="Introduce el c&oacute;digo de &aacute;rea.";
		enterPhone="Introduce el tel&eacute;fono.";
		msgNumbersInFloor="Puedes introducir s&oacute;lo n&uacute;meros en el campo piso.";
		msgOnlyWordsInAppartment="Puedes introducir s&oacute;lo letras y/o n&uacute;meros en el campo depto.";	
		msgOnlyInNumber="Puedes introducir s&oacute;lo n&uacute;meros.";		
	}else{
		enterCodeArea="Ingresa el c&oacute;digo de &aacute;rea.";
		enterPhone="Ingresa el tel&eacute;fono.";
		msgNumbersInFloor="Puedes ingresar s&oacute;lo n&uacute;meros en el campo piso.";
		msgOnlyWordsInAppartment="Puedes ingresar s&oacute;lo letras y/o n&uacute;meros en el campo depto.";
		msgOnlyInNumber="Puedes ingresar s&oacute;lo n&uacute;meros.";
	}	


	
	
	// Piso 
	if(document.getElementById('addressFloor') != null){
	if(isNaN(document.getElementById('addressFloor').value))
	{
		_flagArray[i] = '1';
			document.getElementById('err_command.addressNumber,command.addressFloor,command.addressDepartment').innerHTML = msgNumbersInFloor;
		setErrorState('divStreetDataCA','err_command.addressNumber,command.addressFloor,command.addressDepartment','errorSmall','block');
	}		
	}
	i++;
		
	// Depto
	if(validarDepto(document.getElementById('addressDepartment').value) == false)
	{
		_flagArray[i] = '1';
		document.getElementById('err_command.addressNumber,command.addressFloor,command.addressDepartment').innerHTML = msgOnlyWordsInAppartment;
		setErrorState('divStreetDataCA','err_command.addressNumber,command.addressFloor,command.addressDepartment','errorSmall','block');
	}		
	i++;
	
	
	

	
	if (document.getElementById('commercialContactMainPhoneAreaCode').value != "")
	{
		if(validarSoloNumeros(document.getElementById('commercialContactMainPhoneAreaCode').value) == true)
		{
			if (document.getElementById('commercialContactMainPhoneNumber').value != "")
			{
				if(validarSoloNumeros(document.getElementById('commercialContactMainPhoneNumber').value) == false){		
					_flagArray[i] = '1';
					document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = msgOnlyInNumber;
					setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
				}
				else					
					setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','','none');
			}
			else
			{
				_flagArray[i] = '1';
				document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = enterPhone;
				setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
			}
				
		}
		else	{
			_flagArray[i] = '1';
			document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = msgOnlyInNumber;
			setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
			}
	}
	else
	{
		_flagArray[i] = '1';
		document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = enterCodeArea;
		setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
	}
	i++;
	
	if(document.getElementById('commercialContactMainPhoneExtension').value.length > 0)
		if(validarSoloNumeros(document.getElementById('commercialContactMainPhoneExtension').value) == false) {		
			_flagArray[i] = '1';
			document.getElementById('err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension').innerHTML = msgOnlyInNumber;
			setErrorState('divPhoneCA','err_command.commercialContactMainPhoneAreaCode,command.commercialContactMainPhoneNumber,command.commercialContactMainPhoneExtension','errorSmall','block');
		}	
	
	if(document.getElementById('commercialContactAlternativePhoneAreaCode').value.length > 0 || document.getElementById('commercialContactAlternativePhoneNumber').value.length > 0 || document.getElementById('commercialContactAlternativePhoneExtension').value.length > 0)
	{
		if (document.getElementById('commercialContactAlternativePhoneAreaCode').value != "")
		{
			if(validarSoloNumeros(document.getElementById('commercialContactAlternativePhoneAreaCode').value) == true)
			{
				if (document.getElementById('commercialContactAlternativePhoneNumber').value != "")
				{
					if(validarSoloNumeros(document.getElementById('commercialContactAlternativePhoneNumber').value) == false){		
						_flagArray[i] = '1';
						document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = msgOnlyInNumber;
						setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');
					}
					else					
						setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','','none');
				}
				else
				{
					_flagArray[i] = '1';
					document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = enterPhone;
					setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');
				}
			}
			else{
				_flagArray[i] = '1';
				document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = msgOnlyInNumber;
				setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');				
			}
			i++;						
		}
		else
		{
			_flagArray[i] = '1';
			document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = enterCodeArea;
			setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');
		}
		if(document.getElementById('commercialContactAlternativePhoneExtension').value.length > 0)
			if(validarSoloNumeros(document.getElementById('commercialContactAlternativePhoneExtension').value) == false) {		
				_flagArray[i] = '1';
				document.getElementById('err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension').innerHTML = msgOnlyInNumber;
				setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','errorSmall','block');
			}
	}	
	else
		setErrorState('divPhoneAltCA','err_command.commercialContactAlternativePhoneAreaCode,command.commercialContactAlternativePhoneNumber,command.commercialContactAlternativePhoneExtension','','none');
	
	//Verifico si hay errores en la pagina	
	if(findErrors(_flagArray) == true)
	{		
		clearErrors();
		document.getElementById('divError').className = "error hide";		
		document.formMydata.submit();		
	}
	else
	{				
		document.getElementById('divError').className = "error";
		document.getElementById('divError').innerHTML = "Busca este &iacute;cono para encontrar los errores en la p&aacute;gina."
		location.href = "#focusError";
	}	
}


function clearErrors()
{
	f=document.getElementsByTagName('code');
	for(j=0;j<f.length;j++)
	{
			f[j].style.display = "none";
			//f[j].style.visibility = 'hidden';
	} 
	
	i=document.getElementsByTagName('div');
	for(j=0;j<i.length;j++)
	{
		if(i[j].className == 'errorSmall')
		{
			i[j].style.display = "none";
			//i[j].style.visibility = 'hidden';
		}
	} 
}

function validaSelectIva()
{	
	if (document.getElementById('taxConditionId').options[document.getElementById('taxConditionId').selectedIndex].value == '6' || document.getElementById('taxConditionId').options[document.getElementById('taxConditionId').selectedIndex].value == '0')
	{
		document.getElementById('divCuitCA').className = "hide";
		document.getElementById('err_command.documentNumber').innerHTML = ""
	}
	else
	{
		if (document.getElementById('divCuitCA').className == "hide")
			document.getElementById('divCuitCA').className = "";
		else
			document.getElementById('divCuitCA').className = document.getElementById('divCuitCA').className;
	}
}

function validarSubmitNewUser(tipoUsuario, obj)
{	
	if(validarTexto('newNickname',3,20,'err_command.newNickname','El nombre de usuario debe tener un m&iacute;nimo de 3 caracteres.','Ingresa un nombre de usuario.','divUser') == true)
	{
		cadena = document.getElementById('newNickname').value;

		if(validarUsuario(cadena,tipoUsuario))
		{		
			submitContent('formChangeUser','iframeChangeUser');
			loadingBar(obj);
		}
		else
		{
			 document.getElementById('err_command.newNickname').innerHTML = "Puedes ingresar s&oacute;lo letras, n&uacute;meros y los separadores (. , - _).";
			 setErrorState('divUser','err_command.newNickname','errorSmall','block');
		}
	}	
}

function loadingBar(obj)
{
	obj.parentNode.className = "centerPopUp pensando";
	$("div[class=close]:eq(0)").data("events").click=null;
	//obj.parent().attr("class")
	//obj.parent().css("")
}

function showDivSucursal(value)
{	
	if(document.getElementById('carAgencyTypeId').value == 1 && document.getElementById('divSucursalCA').className == "hide") //sucursal
		document.getElementById('divSucursalCA').className = "";
	else if (document.getElementById('carAgencyTypeId').value == 0 && document.getElementById('divSucursalCA').className == "")//casa central
		document.getElementById('divSucursalCA').className = "hide";
}

function validarSubmitNewPassword(obj)
{	
	var _flag = true;
	var _flag2 = true;
	var _flag3 = true;
	
	var iPais = document.getElementById('hdnCountry').value;
	
	if(iPais == '7'){
		enterPassword="Introduce tu contrase&ntilde;a.";
		reEnterPassword="Introduce tu nueva contrase&ntilde;a.";
		repeatPassword="Reintroduce tu nueva contrase&ntilde;a.";
		repeatPasswordBothField="Introduce la misma contrase&ntilde;a en ambos casilleros.";
	}else{
		enterPassword="Ingresa tu contrase&ntilde;a.";
		reEnterPassword="Ingresa tu nueva contrase&ntilde;a.";
		repeatPassword="Reingresa tu nueva contrase&ntilde;a.";
		repeatPasswordBothField="Ingresa la misma contrase&ntilde;a en ambos casilleros.";
	}

	_flag = validarTexto('presentPassword',6,20,'err_command.presentPassword','La contrase&ntilde;a debe tener un m&iacute;nimo de 6 caracteres.',enterPassword,'divOldPassword');
	_flag2 = validarTexto('newPassword',6,20,'err_command.newPassword','La contrase&ntilde;a debe tener un m&iacute;nimo de 6 caracteres.',reEnterPassword,'divNewPassword');
	_flag3 = validarTexto('confirmNewPassword',6,20,'err_command.confirmNewPassword','La contrase&ntilde;a debe tener un m&iacute;nimo de 6 caracteres.',repeatPassword,'divNewPassword2');
	

	if(_flag == true && _flag2 == true && _flag3 == true)
	{
		if(validarTextoIgual('newPassword','confirmNewPassword',repeatPasswordBothField,'err_command.confirmNewPassword','divNewPassword2') == true)
		{			
			//OK
			cadena = '';			
			for (i=0; i< document.getElementById('newPassword').value.length; i++)
			{
				cadena = cadena + '*';
			}		
			document.getElementById('userPassword').innerHTML = cadena;
			submitContent('formChangePasswordUser','iframeChangePasswordUser');
			loadingBar(obj);
		}
		else
		{
			//document.getElementById('err_command.confirmNewPassword').innerHTML = "No se permite utilizar caracteres especiales.";
			setErrorState('divNewPassword2','err_command.confirmNewPassword','errorSmall','block');
		}
	}	
}

function muestraDivSucursal(div1){
	document.getElementById('divSucursalCA').className = '';
}

function ocultaDivSucursal(div1){
	document.getElementById('divSucursalCA').className = 'hide';
	document.getElementById('err_command.branchName').innerHTML = '';
}

function validarSubmitNewEmail(obj)
{

	var iPais = document.getElementById('hdnCountry').value;
	var _flag = true;
	var _flag2 = true;
	var enterEmail="";
	var ReEnterEmail="";
	var emailNoValid="";
	
	if(iPais == '7'){
		enterEmail="Introduce tu nuevo e-mail.";
		ReEnterEmail="Reintroduce tu nuevo e-mail.";
		emailNoValid="El e-mail introducido no tiene un formato v&aacute;lido.";
		emailNoValidBothField="El e-mail introducido debe coincidir en ambos casilleros.";
	}else{
		enterEmail="Ingresa tu nuevo e-mail.";
		ReEnterEmail="Reingresa tu nuevo e-mail.";
		emailNoValid="El e-mail ingresado no tiene un formato v&aacute;lido.";
		emailNoValidBothField="El e-mail ingresado debe coincidir en ambos casilleros.";
	}
	_flag = validarEmail('newEmail','divNewEmail','err_command.newEmail',enterEmail, emailNoValid)
	_flag2 = validarEmail('confirmNewEmail','divConfirmEmail','err_command.confirmNewEmail',ReEnterEmail, emailNoValid)
	
	if(_flag == true && _flag2 == true)
	{
		if(validarTextoIgual('newEmail','confirmNewEmail',emailNoValidBothField,'err_command.confirmNewEmail','divConfirmEmail') == true)
		{
			//OK
			submitContent('formChangeEmailUser','iframeChangeEmailUser');
			loadingBar(obj);
		}
		else
		{
			//document.getElementById('err_command.confirmNewEmail').innerHTML = "No se permite utilizar caracteres especiales.";
			//setErrorState('divConfirmEmail','err_command.confirmNewEmail','errorSmall','block');
		}
	}
}

function validateSubmitContactInfo(obj)
{

	var iPais = document.getElementById('hdnCountry').value;
	
	
	if(iPais == '7'){
		enterCodeArea="Introduce el c&oacute;digo de &aacute;rea.";
		enterPhone="Introduce el tel&eacute;fono.";
		msgNumbersInFloor="Puedes introducir s&oacute;lo n&uacute;meros en el campo piso.";
		msgOnlyWordsInAppartment="Puedes introducir s&oacute;lo letras y/o n&uacute;meros en el campo depto.";	
		msgOnlyInNumber="Puedes introducir s&oacute;lo n&uacute;meros.";		
		enterPhoneContact='Introduce tu tel&eacute;fono.';
		enterName="Introduce tu nombre.";
		enterLastName="Introduce tu apellido.";
		enterEmail="Introduce tu e-mail.";
		enterValidEmail="Introduce un e-mail v&aacute;lido.";
		horarieAttention="Introduce un horario de atenci&oacute;n.";
		
		
	}else{
		enterCodeArea="Ingresa el c&oacute;digo de &aacute;rea.";
		enterPhone="Ingresa el tel&eacute;fono.";
		msgNumbersInFloor="Puedes ingresar s&oacute;lo n&uacute;meros en el campo piso.";
		msgOnlyWordsInAppartment="Puedes ingresar s&oacute;lo letras y/o n&uacute;meros en el campo depto.";
		msgOnlyInNumber="Puedes ingresar s&oacute;lo n&uacute;meros.";
		enterPhoneContact='Ingresa tu tel&eacute;fono.';
		enterName="Ingresa tu nombre.";
		enterLastName="Ingresa tu apellido.";
		enterEmail="Ingresa tu e-mail.";
		enterValidEmail="Ingresa un e-mail v&aacute;lido.";
		horarieAttention="Ingresa un horario de atenci&oacute;n.";
	}	



	var _flagArray = new Array(true,true,true,true,true,true,true,true,true);

	_flagArray[0] = validarTexto('name', 0, 50, 'err_command.name', 'El campo no puede tener m&aacute;s de 50 caracteres', enterName, 'divContactName');
	_flagArray[1] = validarTexto('surname', 0, 50, 'err_command.surname', 'El campo no puede tener m&aacute;s de 50 caracteres', enterLastName, 'divContactSurname');
	
	_flagArray[2] = validatePhone('primaryPhoneNumber', 'err_command.primaryPhoneLocalAreaNumber,command.primaryPhoneNumber,command.primaryPhoneExtension', 'divPrimaryPhone', false, msgOnlyInNumber, enterPhoneContact);
	
	
	
	
	if(!hasDivError('divPrimaryPhone'))
		_flagArray[3] = ValidateOnlyNumbersSetErrors('primaryPhoneLocalAreaNumber', 'err_command.primaryPhoneLocalAreaNumber,command.primaryPhoneNumber,command.primaryPhoneExtension', 'divPrimaryPhone', false ,msgOnlyInNumber, enterCodeArea);
	
	if(!hasDivError('divPrimaryPhone') && _flagArray[3] == true)
		_flagArray[4] = ValidateOnlyNumbersSetErrors('primaryPhoneExtension', 'err_command.primaryPhoneLocalAreaNumber,command.primaryPhoneNumber,command.primaryPhoneExtension', 'divPrimaryPhone', true ,msgOnlyInNumber, '');
		
	if (document.getElementById('secondaryPhoneNumber').value != "" || document.getElementById('secondaryPhoneLocalAreaNumber').value != "" || document.getElementById('secondaryPhoneExtension').value != "")	
	{
		_flagArray[5] = validatePhone('secondaryPhoneNumber', 'err_command.secondaryPhoneLocalAreaNumber,command.secondaryPhoneNumber,command.secondaryPhoneExtension', 'divSecondaryPhone', false ,msgOnlyInNumber, enterPhoneContact);
		
		if(!hasDivError('divSecondaryPhone'))
			_flagArray[6] = ValidateOnlyNumbersSetErrors('secondaryPhoneLocalAreaNumber', 'err_command.secondaryPhoneLocalAreaNumber,command.secondaryPhoneNumber,command.secondaryPhoneExtension', 'divSecondaryPhone', false ,msgOnlyInNumber, enterCodeArea);
		
		if(!hasDivError('divSecondaryPhone') && _flagArray[6] == true)
			_flagArray[7] = ValidateOnlyNumbersSetErrors('secondaryPhoneExtension', 'err_command.secondaryPhoneLocalAreaNumber,command.secondaryPhoneNumber,command.secondaryPhoneExtension', 'divSecondaryPhone', true ,msgOnlyInNumber, '');	
	}	
	_flagArray[8] = validarEmailContacto('emailAddress', 'divEmail', 1, 50, 'err_command.emailAddress', 'El campo no puede tener m&aacute;s de 50 caracteres.', enterEmail, enterValidEmail);
	
	_flagArray[9] = validarTexto('officeHours', 0, 50, 'err_command.officeHours', 'El campo no puede tener m&aacute;s de 50 caracteres', horarieAttention, 'divOfficeHours');
	
	if (findBooleansErrors(_flagArray)){
		document.getElementById('btnSave').disabled = true;
		document.getElementById('btnCancel').disabled = true;
		submitContent('formChangeUserInfo', 'iframeChangeContactInfo');
		loadingBar(obj);
	}
	
}	

/************************** END SUBMITS **********************************/


/************************** FUNCTIONS **********************************/

function validarTexto(campo,valorMinimo,valorMaximo,idCode,errorLimite,errorVacio, idDiv)
{	
	var iEstado = 0;
		if(document.getElementById(campo) == null)
			return false;
	
	 if(document.getElementById(campo).value.length == 0)
      {   
		 document.getElementById(idCode).innerHTML = errorVacio;
		 setErrorState(idDiv,idCode,'errorSmall','block');
		 iEstado = 1;
		 return false;
      }	  
	if(document.getElementById(campo).value.length < valorMinimo || document.getElementById(campo).value.length > valorMaximo)
    {
		document.getElementById(idCode).innerHTML = errorLimite;
	   	setErrorState(idDiv,idCode,'errorSmall','block');
	   	iEstado = 1;
    }                  
       
	
	if(iEstado == 0){
		setErrorState(idDiv,idCode,'','none');
		return true;
	}
	else
		return false;
	
}

function validarRazonSocial(campo,idCode,errorVacio, idDiv)
{	
	var iEstado = 0;
	razonSocial = document.getElementById(campo).value;
	
	if(razonSocial.length == 0)	
	{
		document.getElementById(idCode).innerHTML = errorVacio;
	   	setErrorState(idDiv,idCode,'errorSmall','block');
	   	iEstado = 1;
	}
	
	if(iEstado == 0){
		setErrorState(idDiv,idCode,'','none');
		return true;
	}
	else
		return false;	
}

function validarTextoIgual(campo1,campo2,errorNoIguales, idCode,idDiv)
{
	if(document.getElementById(campo1).value == document.getElementById(campo2).value)
	{
		//setErrorState(idDiv,idCode,'','none');
		return true;
	}
	else
	{
		document.getElementById(idCode).innerHTML = errorNoIguales;
		setErrorState(idDiv,idCode,'errorSmall','block');
   		return false;
	}	
}

function validarEmailContacto(mail,idDiv,valorMinimo,valorMaximo,idCode,errorLimite,errorVacio,errorFormato)
{
	var iEstado = 0;
	mail = document.getElementById(mail).value;
	
	if(mail.length != 0)
	{
		var filter = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/;  
		 if (!filter.test(mail))
		 {
			 document.getElementById(idCode).innerHTML = errorFormato;
			 setErrorState(idDiv,idCode,'errorSmall','block');
			 iEstado = 1;
	  		 //return false;
		 }
		 else if(mail.length > valorMaximo)
		 {
				document.getElementById(idCode).innerHTML = errorLimite;
			   	setErrorState(idDiv,idCode,'errorSmall','block');
			   	iEstado = 1;
		 }
	}else{
		document.getElementById(idCode).innerHTML = errorVacio;
	   	setErrorState(idDiv,idCode,'errorSmall','block');
	   	iEstado = 1;
	}
	
	if(iEstado == 0){
		setErrorState(idDiv,idCode,'','none');
		return true;
	}
	else
		return false;
	
}

function validateLogin(tagMail)
{
	var state = "none";
	if(validateEmail(tagMail))
	{
		viewDefaultTextLogin("block");		
		document.loginForm.submit();
	}
	else
	{
		viewDefaultTextLogin("none");
		document.getElementById('lbError').innerHTML = "El e-mail no tiene un formato válido."
		state = "block";
	}
	
	document.getElementById('errlog').style.display = state;	
}

function viewDefaultTextLogin(status)
{
	if(document.getElementById('ingpass') != null){document.getElementById('ingpass').style.display = status;}
}

function submitLoginToPressEnter(e) { 
  aKeyPress = (document.all) ? e.keyCode :e.which; 
  if(aKeyPress == 13) validateLogin('username');
}

function validateEmail(tagMail)
{	
	var mailToEvaluate = document.getElementById(tagMail).value;
	if(mailToEvaluate.length > 0)
	{
		var filter = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/;
		return filter.test(mailToEvaluate);
	}
	return true;
}

function validarEmail(mail,idDiv,idCode,errorVacio, errorFormato)
{	
	document.getElementById(mail).value = trimIE(document.getElementById(mail).value)
	mail = document.getElementById(mail).value;
	
	if(mail.length != 0)
	{
		var filter = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/;
		 if (!filter.test(mail))
		 {
			 document.getElementById(idCode).innerHTML = errorFormato;
			 setErrorState(idDiv,idCode,'errorSmall','block');
	  		 return false;
		 }
		 else
		 {
			 //el email es valido
			 setErrorState(idDiv,idCode,'','none');
	  		 return true;
		 }  
	}
	else
	{
		setErrorState(idDiv,idCode,'errorSmall','block');
		document.getElementById(idCode).innerHTML = errorVacio;
  		return false;
	}
}


function validarUsuario(cadena, tipoUsuario)
{
	/**Excepciones que la regular expression no limita MEJORAR!!!!**/
	cadena = replace(cadena," ","");
	cadena = replace(cadena,".","");
	cadena = replace(cadena,"-","");
	cadena = replace(cadena,"_","");
	
	if(cadena.indexOf("/") != -1)
	{
		return false;
	}	
	/**Fin Excepciones**/
	var caracteres = new Array("---","___","...","--_","-_-","__-","_-_","--.",".--","-.-","__.",".__","_._",".._","..-","._.",".-.");
	
	if(cadena.length == 3)
	{
		cadena.substring(0,3); //se buscan los primeros 3 caracteres y se lo busca en el array que la combinacion no se encuentre, si existe el usuario no es valido.

		for (i=0;i<caracteres.length;i++)
		{
			if(cadena.indexOf(caracteres[i]) != -1)
			{
				return false;
			}	
		}		
		cadenaCortada = cadena.substring(0,1); // no puede comenzar con estos 3 caracteres

		if(cadenaCortada == "-" || cadenaCortada == "_" || cadenaCortada == ".")
		{
			return false;
		}
	}
	var patron;
	if(tipoUsuario == '0')
		patron = "^[a-zA-Z0-9.\\-_áéíóúÁÉÍÓÚÑñ]+[.]*$";
	else
		patron = "^[a-zA-Z0-9.\\-_áéíóúÁÉÍÓÚÑñ'&]+[.]*$";

	var expreg = new RegExp(patron);

	if (expreg.test(cadena)) 
	{
		return true;
	}
	else
	{	
		return false;
	}
}


function validarSelect(campo,idDiv,idCode,texto)
{
	if(campo == '0' || campo == '-1')
	{
		document.getElementById(idCode).innerHTML = texto;
		setErrorState(idDiv,idCode,'errorSmall','block');
		return false;
	}
	else
	{
		setErrorState(idDiv,idCode,'','none');
		return true;
	}
}


function setErrorState(idDiv,idCode, className,display)
{
	/*if(document.getElementById(idCode) == null)
	alert(idCode);
	if(document.getElementById(idDiv) == null)
		alert(idDiv);*/
	document.getElementById(idDiv).className = className;
	document.getElementById(idCode).style.display = display;
}

function replace(texto,s1,s2){
	return texto.split(s1).join(s2);
}


function validarLetrasNumeros(cadena,tipo)
{
	if(tipo != "") //campo direccion
	{
		cadena = replace(cadena,"-","");
		cadena = replace(cadena,"ï¿½","");
		patron = "^[a-zA-Z0-9áéíóúÁÉÍÓÚÑñ'.]*$";
	}
	else //campo codigo postal
		patron = "^[a-zA-Z0-9áéíóúÁÉÍÓÚÑñ.]*$";
		
	var expreg = new RegExp(patron);

	if (expreg.test(cadena)) 
		return true;
	else
		return false;
}

function validarDepto(cadena)
{
	cadena = replace(cadena,"ñ","");
	cadena = replace(cadena,"Ñ","");
	patron = "^[a-zA-Z0-9������������.]*$";
		
	var expreg = new RegExp(patron);

	if (expreg.test(cadena)) 
		return true;
	else
		return false;
}

function noEnterAction(evt)
{	
	if(navigator.appName == 'Netscape')
	    var key = evt.which;
	else        
		var key = evt.keyCode;
		//var keyCtrl = evt.ctrlKEY; 
		   	 	    
	if(key == 13)
	    return false; //ticket 3871
	
}

function noSpacesEventValide(e) { // 1
    tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
    patron =/[\s]/; // 4
    te = String.fromCharCode(tecla); // 5
    return !patron.test(te); // 6
} 

function findErrors(flagArray)
{
	for(i=0;i < flagArray.length;i++)
	{
		
		if(flagArray[i] != '0')
		{
			/*alert(flagArray[i]);*/
			return false;
		}
	}	
	return true;
}

function findBooleansErrors(flagArray)
{
	for(i=0;i < flagArray.length;i++)
	{
		if(flagArray[i] == false)
			return false;
	}	
	return true;
}

function validarRadio(radioName)
{
		var allRadios = document.getElementsByName(radioName);
		for (var i=0; i<allRadios.length; i++)
		{
			if(allRadios[i].checked == true)
			return true;
		}
		return false;
} 

//Validar Expression Regular Fecha Nacimiento y Documento (letras y numeros)
function validarExpression(tipoExp,cadena)
{
	switch(tipoExp)
	{
		case "Fecha":
		{
			//si la expression tiene la barra invertida "\" se debe crear el string y en todas sus apariciones duplicar la barra quedando "\\"
			patron = "^([012][0-9]|3[01])(/|-)(0[1-9]|1[012])\\2(\\d{4})$";
			var expreg = new RegExp(patron);

			if (expreg.test(cadena)) 
				return true;
			else
				return false;
		}
			break;
		case "Documento":
		{
			//al contrario de la anterior no necesita ser un string pasado a RegExp no tiene barras invertidas
			patron = /^[a-z\d]{6,20}$/i;
			
			if (patron.test(cadena)) 
			    return false;
			else
				return true;
		}
		break;	
	}  
}

function validarRFC(cadena)
{
	patron = /^[a-z\d]{1,13}$/i;
			
			if (patron.test(cadena)) 
			{
			    return true;
			}
			else
			{
				return false;
			}
}

function validarRut(texto)
{	
	for ( j=0; j < texto.length ; j++ )	
	{		
		if (texto.charAt(j) == '-')
		{	
			return false;		
		}
		else if (isNaN(parseInt(texto.charAt(j)))) //solo se admiten numeros, salvo q sea una K o un k, ver if de adentro
		{	
			if(texto.charAt(j) != "K")
			{	
				if((texto.charAt(j) != "k"))
				{
					return false;
				}
			}
		}
	}

	var tmpstr = "";	
	for ( j=0; j < texto.length ; j++ )		
		if ( texto.charAt(j) != ' ' && texto.charAt(j) != '.' && texto.charAt(j) != '-' )
			tmpstr = tmpstr + texto.charAt(j);	
	texto = tmpstr;	
	largo = texto.length;	

	if ( largo < 2 )	
	{		
		return false;	
	}	

	for (j=0; j < largo ; j++ )	
	{			
		if ( texto.charAt(j) !="0" && texto.charAt(j) != "1" && texto.charAt(j) !="2" && texto.charAt(j) != "3" && texto.charAt(j) != "4" && texto.charAt(j) !="5" && texto.charAt(j) != "6" && texto.charAt(j) != "7" && texto.charAt(j) !="8" && texto.charAt(j) != "9" && texto.charAt(j) !="k" && texto.charAt(j) != "K" )
 		{			
			return false;		
		}	
	}	

	if ( revisarDigito2(texto) )		
		return true;	

	return false;
}

function revisarDigito( dvr )
{	
	dv = dvr + ""	
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')	
	{		
		return false;	
	}	
	return true;
}

function revisarDigito2( crut )
{	
	largo = crut.length;	
	if ( largo < 2 )	
	{		
		return false;	
	}	
	if ( largo > 2 )		
		rut = crut.substring(0, largo - 1);	
	else		
		rut = crut.charAt(0);	
	dv = crut.charAt(largo-1);	
	revisarDigito( dv );	

	if ( rut == null || dv == null )
		return 0	

	var dvr = '0'	
	suma = 0	
	mul  = 2	

	for (j= rut.length -1 ; j >= 0; j--)	
	{	
		suma = suma + rut.charAt(j) * mul		
		if (mul == 7)			
			mul = 2		
		else    			
			mul++	
	}	
	res = suma % 11	
	if (res==1)		
		dvr = 'k'	
	else if (res==0)		
		dvr = '0'	
	else	
	{		
		dvi = 11-res		
		dvr = dvi + ""	
	}
	if ( dvr != dv.toLowerCase() )	
	{		
		return false	
	}

	return true
}

function validarSoloNumeros(cadena)
{
	cadena = replace(cadena," ","");

	patron = "^[0-9]*$";
	var expreg = new RegExp(patron);

	if (cadena.length > 0 && expreg.test(cadena)) 
	{
		return true;
	}
	else
	{	
		return false;
	}
}

function validarNumerosYLetras(cadena)
{
	cadena = replace(cadena," ","");

	patron = "^[0-9a-zA-ZáéíóúÁÉÍÓÚÑñ]*$";
	var expreg = new RegExp(patron);

	if (cadena.length > 0 && expreg.test(cadena)) 
	{
		return true;
	}
	else
	{	
		return false;
	}
}

function ValidateOnlyNumbersSetErrors(field, idCode, idDiv, canBeEmpty ,errorWrongPhoneExp, errorEmptyField)
{
	stream = replace(document.getElementById(field).value," ","");

	patron = "^[0-9]*$";
	var expreg = new RegExp(patron);

	if ((canBeEmpty) || (stream.length > 0)) {
		if ((expreg.test(stream)) || stream.length == 0){
			setErrorState(idDiv,idCode,'','none');		
			return true;
		}
		else {		
			document.getElementById(idCode).innerHTML = errorWrongPhoneExp;
			setErrorState(idDiv,idCode,'errorSmall','block');
			return false;
		}
	}
	else {
		document.getElementById(idCode).innerHTML = errorEmptyField;
		setErrorState(idDiv,idCode,'errorSmall','block');
		return false;
	}
}
function isSucursal(idDiv, mostrar)
{
	if(mostrar)
		document.getElementById(idDiv).sttyle.display = "block";
	else
		document.getElementById(idDiv).sttyle.display = "none";
}

function validatePhone(field, idCode, idDiv, canBeEmpty, errorWrongPhoneExp, errorEmptyField)
{
	patron = "^[0-9]+$";
	var expreg = new RegExp(patron);
	
	if ((canBeEmpty) || (document.getElementById(field).value.length > 0)) {
		if (expreg.test(document.getElementById(field).value) || (document.getElementById(field).value.length == 0)){
			setErrorState(idDiv,idCode,'','none');		
			return true;
		}
		else {		
			document.getElementById(idCode).innerHTML = errorWrongPhoneExp;
			setErrorState(idDiv,idCode,'errorSmall','block');
			return false;
		}
	}
	else {
		document.getElementById(idCode).innerHTML = errorEmptyField;
		setErrorState(idDiv,idCode,'errorSmall','block');
		return false;
	}
}

function hasDivError(idDiv)
{
	if (document.getElementById(idDiv).className == "errorSmall")
		return true;
	else	
		return false;
}

function otraLocalidad(xsValor, xsCampo)
{	   	
	//mejorar!!!!!!!!!!!!!!!!!!
	if (xsCampo != null)
	{
		var valor = xsValor;
		var version = navigator.appVersion;

		
		if(valor.toLowerCase() == "otra ubicaci&oacute;n" ||  valor.toLowerCase() == "otra ubicaci\u00F3n" )
		{
			document.getElementById(xsCampo).style.display = "block";
		} 
		else
		{
			document.getElementById(xsCampo).style.display = "none";				
		}
   }
}//End function otraLocalidad

function trimIE (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

function AcceptOnlyNumbers(evt){	//Acepta solo Numeros.
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
	if(navigator.appName == 'Netscape')
		var key = evt.which;
    else        
		var key = evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));
}

function aceptarLetra(evt){
	if(navigator.appName == 'Netscape')
		var key = evt.which;
    else        
		var key = evt.keyCode;
	
	var iRetorno= true;
	//Permite ingresar acentos y la letra &ntilde; con sus respectivas mayusculas
	if((iRetorno)){
		switch (key) {
		    case 13://Enter
			case 48://1
			case 49://2
			case 50://3
			case 51://4
			case 52://5
			case 53://6
			case 54://7
			case 55://8
			case 56://9
			case 57://10
			case 64://@
			case 92://\
            case 37://%
            case 43://+
			case 38://&
			case 37://% 
			case 33://!
			case 36://$
			case 40://(
			case 41://)
			case 47:///
			case 42://*	
			case 45://-
			case 44://,
			case 58://:
			case 59://,;
			case 60://<
			case 61://=
			case 62://>
			case 63://?
				
			iRetorno=false;
			break;					
		} 
	}
	return iRetorno;
 }

function aceptarLetraApellido(evt){
	if(navigator.appName == 'Netscape')
		var key = evt.which;
    else        
		var key = evt.keyCode;
	var iRetorno= ((key >= 65 && key <= 90) ||(key >= 97 && key <= 122) || (key == 0) || (key == 8) || (key <= 32));
	//Permite ingresar acentos y la letra &ntilde; con sus respectivas mayusculas
	if(!(iRetorno)){
		switch (key) {
			case 241:
				iRetorno=true;
				break;
			case 209:
				iRetorno=true;
				break;
			case 225://&aacute;
				iRetorno=true;
				break;
			case 193://&aacute;
				iRetorno=true;
				break;
			case 233://&eacute;
				iRetorno=true;
				break;
			case 201://&eacute;
				iRetorno=true;
				break;
			case 237://&iacute;
				iRetorno=true;
				break;
			case 205://&iacute;
				iRetorno=true;
				break;
			case 243://&oacute;
				iRetorno=true;
				break;
			case 211://&oacute;
				iRetorno=true;
				break;
			case 250://&uacute;
				iRetorno=true;
				break;
			case 218://&uacute;
				iRetorno=true;
				break;	
			case 39://'
				iRetorno=true;
				break;	
			case 164://&ntilde;
				iRetorno=true;
				break;	
			case 165://&ntilde;
				iRetorno=true;
				break;	
		} 
	}
	return iRetorno;
 }

function updateUserData() {
	 var nuevaClave = '';
	 if (document.getElementById("userNickNameDialogHidden")) {
		 document.getElementById('userNickName').innerHTML = document.getElementById("userNickNameDialogHidden").value;
	 }
	 if (document.getElementById("userMailDialogHidden")) {
		 document.getElementById('userEmail').innerHTML = document.getElementById("userMailDialogHidden").value;
	 }
	 if (document.getElementById("userPasswordDialogHidden")) {
		for (i=0; i< document.getElementById('userPasswordDialogHidden').value.length; i++)
		{
			nuevaClave = nuevaClave + '*';
		}
		document.getElementById('userPassword').innerHTML = nuevaClave;
	 }
}

/************************** END FUNCTIONS **********************************/

