var ultimoNombreBuscado;
var req;
var sImagenError = '<img src="../../Includes/images/RNP/Icons/ic_error.gif" width="14" height="14" border=0/> ';
var sImagenAdvertencia =  '<img src="../../Includes/images/RNP/Icons/ic_advertencia.gif" width="16" height="14"/>'
var sImagenCargando = '<img src="../../Includes/images/RNP/Icons/ic_ani_cargando.gif" width="20" height="20" />'

var MSG_VACIO_NOMBREUSUARIO = 'Por favor ingrese un Nombre de Usuario.'
var MSG_FORMATO_NOMBREUSUARIO = 'Formato incorrecto, por favor no incluya espacios en blanco, puntos, guiones, ni caracteres especiales como: *, ñ, &, u otros.'

var MSG_VACIO_NOMBREORGANIZACION = 'Por favor ingrese un Nombre de Organizaci\u00F3n.'
var MSG_FORMATO_NOMBREORGANIZACION = 'Formato incorrecto, no incluya espacios en blanco, puntos, guiones, ni caracteres especiales como: *, ñ, &, u otros.'

var MSG_VACIO_CLAVE = 'Por favor ingrese una Clave.'
var MSG_FORMATO_CLAVE = 'Formato incorrecto, por favor ingrese un m\u00EDnimo 6 y un máximo 8 caracteres.\nNo incluya espacios en blanco, puntos, guiones, ni caracteres especiales como: *, ñ, &, u otros.'

var MSG_VACIO_CLAVECONFIRMACION = 'Por favor ingrese nuevamente su Clave.'
var MSG_FORMATO_CLAVECONFIRMACION = 'La confirmaci\u00F3n de la clave debe ser igual a la clave ingresada en el campo anterior. Por favor ingrese ambas claves nuevamente.'

var MSG_VACIO_EMAILDATOS = 'Por favor ingrese un E-mail para recibir los datos de ingreso al sistema.'
var MSG_FORMATO_EMAILDATOS = 'Formato incorrecto, por favor verifique su E-mail e ingréselo correctamente.'

var MSG_VACIO_TIPOPROVEEDOR = 'Por favor seleccione un Tipo de Proveedor.'

var MSG_VACIO_RUT = 'Por favor ingrese el N\u00FAmero. de RUT de su empresa.'
var MSG_FORMATO_RUT = 'Formato incorrecto, no incluya espacios en blanco, puntos ni guiones.'
var MSG_VACIO_RUTDV = 'Por favor ingrese el Nro. de RUT de su empresa.'
var MSG_FORMATO_RUTDV = 'Formato incorrecto, no incluya espacios en blanco, puntos ni guiones.'

var MSG_VACIO_NUMDOC = 'Debe ingresar un n\u00FAmero de Documento de Identidad.'

var MSG_VACIO_RAZONSOCIAL = 'Por favor ingrese la Raz\u00F3n Social de su Empresa.'
var MSG_VACIO_NOMBRECOMPLETO = 'Por favor ingrese su Nombre Completo.'

var MSG_VACIO_NOMBREFANTASIA = 'Por favor ingrese el Nombre Fantas\u00EDa de su empresa.'

var MSG_VACIO_GIRO = 'Por favor seleccione el Giro de su empresa.'

var MSG_VACIO_NIVELFACTURACION = 'Por favor seleccione su Nivel de Facturaci\u00F3n Anual.'

var MSG_VACIO_NUMTRABAJADORES = 'Por favor seleccione el N\u00FAmero Total de Trabajadores de su empresa.'

var MSG_VACIO_DIRECCIONCASAMATRIZ = 'Por favor ingrese la Direcci\u00F3n de la Casa Matriz de su empresa'
var MSG_VACIO_DIRECCIONPERSONA = 'Por favor ingrese su Direcci\u00F3n.'

var MSG_VACIO_PAIS = 'Por favor ingrese el País de la Raz\u00F3n Social ingresada anteriormente.'
var MSG_VACIO_REGION = 'Por favor seleccione una Regi\u00F3n.'
var MSG_VACIO_COMUNA = 'Por favor seleccione una Comuna.'

var MSG_VACIO_NOMBRECONTACTO = 'Por favor ingrese su Nombre.'
var MSG_VACIO_CARGO = 'Por favor ingrese su Cargo dentro de la empresa.'

var MSG_VACIO_TELEFONO = 'Por favor ingrese su n\u00FAmero de Tel\u00E9fono.'
var MSG_VACIO_FAX = 'Por favor ingrese su n\u00FAmero de Fax.'
var MSG_VACIO_TELEFONOCODPAIS = 'Por favor ingrese su n\u00FAmero de Tel\u00E9fono.'

var MSG_VACIO_ANEXO = 'Por favor ingrese su n\u00FAmero de Anexo.'

var MSG_VACIO_TELEFONOCODREGION = 'Por favor ingrese su n\u00FAmero de Tel\u00E9fono.'
var MSG_FORMATO_TELEFONO = 'Formato incorrecto, no incluya espacios en blanco, puntos ni guiones.'

var MSG_FORMATO_CELULAR = 'Formato incorrecto, no incluya espacios en blanco, puntos ni guiones.'

var MSG_FORMATO_CELULARCODPAIS = 'Formato incorrecto, ingrese codigo pais.'

var MSG_FORMATO_CELULARCODIGO = 'Formato incorrecto, ingrese codigo.'

var MSG_FORMATO_FAX = 'Formato incorrecto, no incluya espacios en blanco, puntos ni guiones.'

var MSG_VACIO_EMAIL = 'Por favor ingrese su E-mail.'
var MSG_FORMATO_EMAIL = 'Formato incorrecto, por favor verifique su E-mail e ingr\u00E9selo correctamente.'
var MSG_VACIO_SUSCRIPCION='Por favor Seleccione un tipo de aviso a recibir.'

var MSG_DOCUMENTO_AYUDA = 'N\u00FAmero de Documento de su empresa a ser registrada.'
var MSG_RUT_AYUDA = 'N\u00FAmero de RUT de su empresa / N\u00FAmero de RUT de la Persona a ser registrada como Proveedor.'

var MSG_RAZONSOCIAL_AYUDA = 'Ejemplo: Techor S.A.'
var MSG_NOMBREPERSONA_AYUDA = 'Ejemplo: Manuel Rodriguez'

// 22/11/2005 - DMF - Variables de error de la seccion de Datos Bancarios
var MSG_NOMBRE_DEL_BANCO = 'Por Favor Seleccione un Banco.'
var MSG_TIPO_CTA = 'Por favor Seleccione un tipo de cuenta bancaria.'
var MSG_VACIO_NRO_CTA = 'Por favor ingrese su n\u00FAmero de cuenta bancaria.'
var MSG_FORMATO_NRO_CTA = 'El formato de su n\u00FAmero de cuenta bancaria, s\u00F3lo debe ingresar numeros.'
var MSG_FORMATO_TELEFONOCODREGION ='EL formato de alguno de sus n\u00FAmeros de Conctacto no es correcto.' 
var MSG_FORMATO_FILTROS ='Debe seleccionar al menos un Filtro.'
// 22/11/2005 - DMF - Fin

function imprimirError(texto,ancla){
	//var error = '<a href="javascript:enviarAAncla(\'' + ancla + '\')" onmouseover="window.status=\'Ir al Error\';return true" onmouseout="window.status=\'\';return true">' +  sImagenError 	
	//error = error + texto + '</a><br/>';
	//document.getElementById('errorGeneral').innerHTML =  text;	
	document.getElementById('errorGeneral').innerHTML =  sImagenError + ' Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.';
	document.getElementById('errorGeneral').style.display = '';
}
function imprimirErrorRut(texto,ancla){
	//var error = '<a href="javascript:enviarAAncla(\'' + ancla + '\')" onmouseover="window.status=\'Ir al Error\';return true" onmouseout="window.status=\'\';return true">' +  sImagenError 	
	//error = error + texto + '</a><br/>';
	//document.getElementById('errorGeneral').innerHTML =  text;	
	document.getElementById('errorGeneral').innerHTML =  sImagenError + ' El Rut ingresado ya se encuentra registrado. Por favor verifique los datos indicados en rojo.';
	document.getElementById('errorGeneral').style.display = '';
}

function imprimirErrorUsuario(texto,ancla){
	//var error = '<a href="javascript:enviarAAncla(\'' + ancla + '\')" onmouseover="window.status=\'Ir al Error\';return true" onmouseout="window.status=\'\';return true">' +  sImagenError 	
	//error = error + texto + '</a><br/>';
	//document.getElementById('errorGeneral').innerHTML =  text;	
	document.getElementById('errorGeneral').innerHTML =  sImagenError + ' El nombre de usuario ingresado ya se encuentra registrado. Por favor verifique los datos indicados en rojo.';
	document.getElementById('errorGeneral').style.display = '';
}

function imprimirErrorProceso(texto,ancla){
	//var error = '<a href="javascript:enviarAAncla(\'' + ancla + '\')" onmouseover="window.status=\'Ir al Error\';return true" onmouseout="window.status=\'\';return true">' +  sImagenError 	
	//error = error + texto + '</a><br/>';
	//document.getElementById('errorGeneral').innerHTML =  text;	
	document.getElementById('errorGeneral').innerHTML =  sImagenError + ' Ha ocurrido un error en el proceso de Registro. Intentelo Nuevamente.';
	document.getElementById('errorGeneral').style.display = '';
}

function crearStrAdvertencia(msg){
	return sImagenAdvertencia + '<span class="formCamposError"" id=""error""> ' + msg +  ' </span><br>'
}


function validarNombreOrg(txtNombreOrg){
	var NombreOrg = trim(txtNombreOrg.value);
	mostrarItem('div' + txtNombreOrg.id)
	if (ultimoNombreBuscado != NombreOrg){
		if (NombreOrg ==''){			
			document.getElementById('div' + txtNombreOrg.id).innerHTML = crearStrAdvertencia(MSG_VACIO_NOMBREORGANIZACION)
			return false;	
		}
		if (!(/^[a-zA-Z0-9]+$/.test(NombreOrg))){
			document.getElementById('div' + txtNombreOrg.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_NOMBREORGANIZACION)
			return false;		
		}	/*		
		else{		
		ultimoNombreBuscado = NombreOrg;
		document.getElementById('div' + txtNombreOrg.id).style.display = ''
		var sUrl = 'Validaciones.aspx?d=' + (new Date()) + '&o=' + NombreOrg	+ '&op=1'	
		//not IE
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = pReqValidarNombreOrgV;			
			req.open("GET",sUrl , true);	
			req.send(null);
			// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {	
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {				
				req.onreadystatechange = pReqValidarNombreOrgV;							
				req.open("GET",sUrl , true);	
				req.send();
			}
		}		
		window.clearTimeout() 		
		}	*/
	}
	ocultarItem('div' + txtNombreOrg.id)
	return true
}


function operarRubros(idRubro,operacion) {		
	var sUrl = 'FuncionesRubros.aspx?d=' + (new Date()) 
	if(idRubro != null) sUrl = sUrl + '&idRubro=' + idRubro 
	if(operacion != null) sUrl = sUrl + '&op=' + operacion
	
	var strLocation = new String(window.location)	
	var sUrl = strLocation.split(strLocation.split("/")[strLocation.split("/").length -1])[0] + sUrl
	
	if (window.XMLHttpRequest) {	
		req = new XMLHttpRequest();
		req.onreadystatechange = pReqRefrescarRubros;
		
		req.open("GET",sUrl , true);	
		req.send(null);		
		// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {	
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = pReqRefrescarRubros;					
			req.open("GET",sUrl , true);	
			req.send();
		}
	}		
	window.clearTimeout() 	
	return
}
function pReqRefrescarRubros() {		
	if (req.readyState == 4) {		
		document.onmousedown= ''
		document.body.style.cursor = 'default'	
		if (req.status == 200) {							
			document.getElementById('divRubros').innerHTML = req.responseText										
		}
		else{			
			document.getElementById('divRubros').innerText = 'Por favor intenta nuevamente.'		
		}		
		req = null				
	}else{
		document.body.style.cursor = 'wait'
		document.onmousedown=mensajeOperandoRubros
		//document.getElementById('divRubros').innerHTML = '<table width="100%"  border="0" cellpadding="0" cellspacing="0" class="registroTabla"><caption>' + sImagenCargando + ' Cargando...</caption></table>'		
	}
}
function mensajeOperandoRubros(){
alert('Se están cargando los rubros, por favor espere hasta que el proceso se complete.')
}
function abrirVentanaRubros(){
	s = "PageGoodandServices.aspx"
	open(s , "RubrosProveedor", "width=700, height=410, status=yes, scrollbars=yes, left=0, top=0 , resizable=yes");
}

function habilitarRegiones(idPais){

var ddRegion = document.getElementById('ddRegion');
var ddComuna = document.getElementById('ddComuna');
cambia_ddpais();
if(idPais == 'CL'){
	ddRegion.disabled = false;	
}
else{	
	ddRegion.disabled = true;
	ddComuna.disabled = true;
	ddComuna
	ddComuna.selectedIndex = 0;
	ddRegion.selectedIndex = 0;	
}
}

function listarComunaPorRegion(idRegion){
var ddComuna = document.getElementById('ddComuna');	
var ddRegion = document.getElementById('ddRegion');	

if(idRegion != 0){	
	ddComuna.options.length = 0;	
	ddComuna.options[0] = new Option('Seleccionar...','0');		 
	
	//alert("Id: " + idRegion +"  Largo: " + arrRegion[idRegion].length );
	//alert(arrRegion[idRegion]);
	
	if (arrRegion[idRegion] != undefined)
	{
	    if (arrRegion[idRegion].length >0)
	    {
	        for (i=0;i<arrRegion[idRegion].length;i++){
		        //if(arrRegion[idRegion][i][1] != '')
			        ddComuna.options[i] = new Option(arrRegion[idRegion][i][1],arrRegion[idRegion][i][0]);
	        }	
	    }    
	    ddComuna.disabled = false;
	}
	 
  }
  else{
        ddComuna.disabled = true;
       }
    document.Form1.hidIdRegion.value=ddRegion.value;           
	document.Form1.hidIdComuna.value=ddComuna.value;  
}
function eliminarRubro(idRubro){			
	if (confirm("¿Está Seguro que desea Eliminar este Rubro?")){
		operarRubros(idRubro,1)
	}
}
function enviarAAncla(ancla) {

    strLocation = new String(window.location)
    window.location = strLocation.split("#")[0] + '#' + ancla
    
}

function verRubro(idRubro){
	open("../RegistroProveedor/ver_producto_rubro.aspx?idrubro=" + idRubro, "ConsultaProducto","width=450, height=350, status=yes, scrollbars=yes, left=50, top=50");
}
function setearNacionalidad(idNacionalidad){
	var ddPais = document.getElementById('ddPais');
	var ddRegion = document.getElementById('ddRegion');
	var ddComuna = document.getElementById('ddComuna');

	
	//1:Extranjera, 0:Chilena
	if (idNacionalidad==1){
	ddRegion.disabled = true;
	ddComuna.disabled = true;
	ddPais.disabled = false;
	ddComuna.selectedIndex = 0;
	ddRegion.selectedIndex = 0;	
	//ddPais.selectedIndex = ddPais.options.length-1;
	if ( document.Form1.hidIdCountry.value=="" )
	{
	    seleccionarPais('AF');
	}
	document.getElementById('divIdentificador').style.display = '';
	document.getElementById('divRut').style.display = 'none';
	document.getElementById('divTextoRut').innerHTML ='<span class="formObliga">*</span>Documento';
	document.getElementById('divRutAyuda').innerHTML =	MSG_DOCUMENTO_AYUDA;
	document.getElementById('rutAyuda').innerHTML= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	//  Fhurtado 20070410, sin obligación en  documento, OT 2494
	
    document.getElementById('divnombrefantasia').innerHTML = 'Nombre de Fantas&iacute;a';
	document.getElementById('divniveldefacturacion').innerHTML = 'Nivel de Facturaci&oacute;n';
    document.getElementById('div_numerodetrabajadores').innerHTML= 'N&uacute;mero de Trabajadores';
	document.getElementById('divtipo_cuenta').innerHTML= 'Tipo Cuenta';
	document.getElementById('dvdnro_cuenta').innerHTML= 'N&uacute;mero Cuenta';
	document.getElementById('divregion').innerHTML= 'Regi&oacute;n';
	document.getElementById('dvdcomuna').innerHTML='Comuna';
	document.getElementById('divcargo').innerHTML='Cargo';
	//document.getElementById('divtxtciudad').innerHTML='Ciudad';

	}else{
	for(i=0;i<ddPais.options.length-1;i++){
		if (ddPais.options[i].value == 'CL'){ddPais.selectedIndex = i}
	}
	ddRegion.disabled = false;
	ddComuna.disabled = true;
	ddPais.disabled = true;	
	document.getElementById('divRut').style.display = ''
	document.getElementById('divIdentificador').style.display = 'none';
	document.getElementById('divTextoRut').innerHTML = '<span class="formObliga">*</span>R.U.T.';
	document.getElementById('divRutAyuda').innerHTML =	MSG_RUT_AYUDA;
	document.getElementById('rutAyuda').innerHTML = 'Este dato debe corresponder al de su Inicio de Actividades en el S.I.I';
	
	
    document.getElementById('divnombrefantasia').innerHTML = '<span class="formObliga">*</span>Nombre de Fantas&iacute;a';
	document.getElementById('divniveldefacturacion').innerHTML = '<span class="formObliga">*</span>Nivel de Facturaci&oacute;n';
	document.getElementById('div_numerodetrabajadores').innerHTML= '<span class="formObliga">*</span>N&uacute;mero de Trabajadores';
	document.getElementById('divtipo_cuenta').innerHTML= '<span class="formObliga">*</span>Tipo Cuenta';
	document.getElementById('dvdnro_cuenta').innerHTML= '<span class="formObliga">*</span>N&uacute;mero Cuenta';
	document.getElementById('divregion').innerHTML= '<span class="formObliga">*</span>Regi&oacute;n';
	document.getElementById('dvdcomuna').innerHTML='<span class="formObliga">*</span>Comuna';
	document.getElementById('divcargo').innerHTML='<span class="formObliga">*</span>Cargo';
//	
	}
	
}
function setearTipoEmpresa(idTipo){
	//Limpia Error de No haber seleccionado un Tipo de empresa
	document.getElementById('divagrpTipoProveedor').innerHTML = ''
	//1:Empresa, 0:Persona
	if(idTipo == 1){
		document.getElementById('divRazonSocialAyuda').innerHTML =	MSG_RAZONSOCIAL_AYUDA
		document.getElementById('descTipoEmpresa').innerHTML = '<span class="formObliga">*</span>Raz&oacute;n Social';
								
	}else{
		document.getElementById('divRazonSocialAyuda').innerHTML =	MSG_NOMBREPERSONA_AYUDA
		document.getElementById('descTipoEmpresa').innerHTML = '<span class="formObliga">*</span>Nombre de la Persona';
	}
}

function validarNombreUsuario(txtNombreUsuario) {
    
	mostrarItem('div' + txtNombreUsuario.id)
	//Validando que sean sólo letras y números
	if(trim(txtNombreUsuario.value) == ''){
	    //alert(MSG_VACIO_NOMBREUSUARIO)
	    document.getElementById('div' + txtNombreUsuario.id).innerHTML = crearStrAdvertencia(MSG_VACIO_NOMBREUSUARIO) //sImagenAdvertencia + ' <span class=formCamposError>El formato del "Nombre de Usuario" no es válido.</span>'
		//document.getElementById('txtNombreUsuario').innerHTML = sImagenAdvertencia;
	
		//window.event.returnValue = false;
		//alert("Muchoantes");
		return false;
}
	
	if (!(/^[a-zA-Z0-9-]+$/.test(txtNombreUsuario.value))) {
		document.getElementById('div' + txtNombreUsuario.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_NOMBREUSUARIO) //sImagenAdvertencia + ' <span class=formCamposError>El formato del "Nombre de Usuario" no es válido.</span>'
		//window.event.returnValue = false;
		//alert("paso");
		return false;		
	}	
	ocultarItem('div' + txtNombreUsuario.id)
	
	return true;	
}
function validarClave(txtClave){	

	mostrarItem('div' + txtClave.id)
	if(trim(txtClave.value) == ''){
	document.getElementById('div' + txtClave.id).innerHTML = crearStrAdvertencia(MSG_VACIO_CLAVE) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar "Una Clave"</span>'	
	//window.event.returnValue = false;
	return false;
	}	
	if(!(/^[a-zA-Z0-9]{6,8}$/.test(txtClave.value))){
	document.getElementById('div' + txtClave.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_CLAVE) //sImagenAdvertencia + ' <span class=formCamposError>El formato de la "Clave" ingresada no es válido</span>'	
	//window.event.returnValue = false;
	return false;
	}
	if(txtClave.id == 'txtClaveConfirmacion' && txtClave.value != document.getElementById('txtClave').value){
	document.getElementById('div' + txtClave.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_CLAVECONFIRMACION) //sImagenAdvertencia + ' <span class=formCamposError>La clave de confirmación no coincide con la clave ingresada</span>'	
	//window.event.returnValue = false;
	return false;	
	}
	ocultarItem('div' + txtClave.id)
	return true;
}
function validarEmailRecibirDatos(txtEmail){	
	mostrarItem('div' + txtEmail.id)	
	txtEmail.value = trim(txtEmail.value)
	if(txtEmail.value == ''){
	document.getElementById('div' + txtEmail.id).innerHTML = crearStrAdvertencia(MSG_VACIO_EMAIL) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar el "E-mail para Recibir Datos"</span>'	
	
	//window.event.returnValue = false;
	return false;
	}
	if (!(/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/.test(txtEmail.value))) {
	document.getElementById('div' + txtEmail.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_EMAIL) //sImagenAdvertencia + ' <span class=formCamposError>El formato de "E-mail para Recibir Datos" ingresado no es válido</span>'	
	//window.event.returnValue = false;
	return false;
	}
	ocultarItem('div' + txtEmail.id)
	return true;
}
function validarEmailRecibirOC(txtEmail){	
	mostrarItem('div' + txtEmail.id)	
	txtEmail.value = trim(txtEmail.value)
	if(txtEmail.value == ''){
	document.getElementById('div' + txtEmail.id).innerHTML = crearStrAdvertencia(MSG_VACIO_EMAIL) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar el "E-mail para Recibir Ordenes de Compra"</span>'	
	//window.event.returnValue = false;
	return false;
	}
	if (!(/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/.test(txtEmail.value))) {
	document.getElementById('div' + txtEmail.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_EMAIL) //sImagenAdvertencia + ' <span class=formCamposError>El formato de "E-mail para Recibir Ordenes de Compra" ingresado no es válido</span>'	
	//window.event.returnValue = false;
	return false;
	}
	ocultarItem('div' + txtEmail.id)
	return true;
}


function validarEmailAvisos(txtEmail){
   //document.getElementById('txtEmailRecibirAvisos').disabled = true;
   
	mostrarItem('div' + txtEmail.id)	
	if(!document.getElementById('radSuscripcion3').checked && !document.getElementById('radSuscripcion21').checked && !document.getElementById('radSuscripcion22').checked && !document.getElementById('radSuscripcion11').checked && !document.getElementById('radSuscripcion12').checked){
		document.getElementById('div' + txtEmail.id).innerHTML = crearStrAdvertencia('Debe seleccionar un Tipo de Aviso')
		document.getElementById('txtEmailRecibirAvisos').disabled=true;	
		//window.event.returnValue = false;
		return false
        
	}	

			
	//Muestra la tabla de Filtros sólo para las opciones 12 y 22
	if(document.getElementById('radSuscripcion12').checked || document.getElementById('radSuscripcion22').checked){
		document.getElementById('divTablaFiltros').style.display = 'block'
		
	}else{		
		document.getElementById('divTablaFiltros').style.display = 'none'
		
	}
	
	
	if(!document.getElementById('radSuscripcion3').checked)
	{

		txtEmail.value = trim(txtEmail.value)
		if(txtEmail.value == ''){
			document.getElementById('div' + txtEmail.id).innerHTML = crearStrAdvertencia(MSG_VACIO_EMAIL) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar el "E-mail para Recibir Avisos"</span>'	
			
			document.getElementById('divEmailRecibirAvisos').innerHTML= '<span class="formObliga">*</span>E-mail para recibir Avisos';
			//window.event.returnValue = false;
			return false;
			
		}			
		if (!(/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/.test(txtEmail.value))) {
			document.getElementById('div' + txtEmail.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_EMAIL) //sImagenAdvertencia + ' <span class=formCamposError>El formato de "E-mail para Recibir Avisos" ingresado no es válido</span>'	
			//window.event.returnValue = false;	
			
			return false;
		}		
        if (	(document.getElementById('radSuscripcion12').onchecked) || (document.getElementById('radSuscripcion22').onchecked) )
        {	
	             if ( document.getElementById('lblnotificaciones') == null )
	             {
	                    document.getElementById('div' + txtEmail.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_FILTROS) //sImagenAdvertencia + ' <span class=formCamposError>El formato de "E-mail para Recibir Avisos" ingresado no es válido</span>'	
			            //window.event.returnValue = false;	
            			document.getElementById('txtEmailRecibirAvisos').disabled=false;	
			            return false;
	             }
        }	 
	}
	
		
	ocultarItem('div' + txtEmail.id)	
    return true;
}

function validarRut(){	
	mostrarItem('divtxtRut')
	var sRut = document.getElementById('txtRut').value;
	var sDV = document.getElementById('txtRutDV').value;
	if(trim(sRut) ==''){
		document.getElementById('divtxtRut').innerHTML = crearStrAdvertencia(MSG_VACIO_RUT) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar el "R.U.T."</span>'	
		//window.event.returnValue = false;
		return false;
	}
	if(trim(sDV) ==''){
		document.getElementById('divtxtRut').innerHTML = crearStrAdvertencia(MSG_VACIO_RUTDV) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar el "Dígito Verificador"</span>'	
		//window.event.returnValue = false;
		return false;
	}
	if(!(/^[0-9]+$/.test(sRut))){
		document.getElementById('divtxtRut').innerHTML = crearStrAdvertencia(MSG_FORMATO_RUT) //sImagenAdvertencia + ' <span class=formCamposError>El "R.U.T." ingresado no es válido, ingrese sólo números</span>'	
		//window.event.returnValue = false;
		return false;
	}
	if(!checkDV(sRut + sDV)){
		document.getElementById('divtxtRut').innerHTML = crearStrAdvertencia(MSG_FORMATO_RUTDV) //sImagenAdvertencia + ' <span class=formCamposError>El "R.U.T." ingresado no es válido</span>'	
		//window.event.returnValue = false;
		return false;
	}	
	ocultarItem('divtxtRut')
	return true
}

function mostrarItem(item){
document.getElementById(item).style.display = ''
}
function ocultarItem(item){	
	document.getElementById(item).innerHTML = ''
	document.getElementById(item).style.display = 'none'		
}



function validarFono(blnEsFono){	
	var codPais		
	var codRegion
	var txtFono
	var txtAnexo
	
	if(blnEsFono){
		codPais = trim(document.getElementById('txtFonoPais').value)		
		codRegion = trim(document.getElementById('txtFonoRegion').value)
		txtFono = document.getElementById('txtFono')
	//	txtAnexo = trim(document.getElementById('txtFonoAnexo').value)
		
	}else{
		codPais = trim(document.getElementById('txtFaxPais').value)
		codRegion = trim(document.getElementById('txtFaxRegion').value)
		txtFono = document.getElementById('txtFax')
	}		
	mostrarItem('div' + txtFono.id)
	
		
	if(codPais == ''){
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_TELEFONOCODPAIS) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar "Código de País"</span>'	
		//window.event.returnValue = false;
		return false;
	}
	if (!(/^[0-9]+$/.test(codPais))) {
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_TELEFONOCODPAIS) //sImagenAdvertencia + ' <span class=formCamposError>El "Código de País" no es válido, ingrese sólo números</span>'	
		//window.event.returnValue = false;
		return false;
	}
	if(codRegion == ''){
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_TELEFONOCODREGION) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar "Código de Región"</span>'
		//window.event.returnValue = false;
		return false;
	}
	if (!(/^[0-9]+$/.test(codRegion))) {
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_TELEFONOCODREGION) //sImagenAdvertencia + ' <span class=formCamposError>El "Código de Región" no es válido, ingrese sólo números</span>'
		//window.event.returnValue = false;
		return false;
	}
	if(blnEsFono && txtFono.value == ''){
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_TELEFONO) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar el "Número de Teléfono"</span>'
		//window.event.returnValue = false;
		return false;
	}
	if (!(/^[0-9]{6,8}$/.test(txtFono.value))) {		
		if(blnEsFono){
			document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_TELEFONO) //sImagenAdvertencia + ' <span class=formCamposError>El Formato del "Télefono" no es válido, ingrese sólo números y con un largo de 6 a 8 caracteres</span>'	
		}else{
			document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_FAX) //sImagenAdvertencia + ' <span class=formCamposError>El Formato del "Fax" no es válido, ingrese sólo números y con un largo de 6 a 8 caracteres</span>'	
		}
		//window.event.returnValue = false;
		return false;
	}	
	
//	if(txtAnexo == ''){
//		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_ANEXO) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar "Código de País"</span>'	
//		window.event.returnValue = false;
//		return false;
//	}
	
	ocultarItem('div' + txtFono.id)
	return true
}
function validarFax(){	
	var codPais		
	var codRegion
	var txtFono
	
	
		codPais = trim(document.getElementById('txtFaxPais').value)
		codRegion = trim(document.getElementById('txtFaxRegion').value)
		txtFono = document.getElementById('txtFax')
			
	mostrarItem('div' + txtFono.id)
	if(codPais=='' && codRegion=='' && txtFono==''){
		ocultarItem('div' + txtFono.id)
		//window.event.returnValue = false;
		return true;
	}
	if(codPais == ''){
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_FAX) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar "Código de País"</span>'
		//window.event.returnValue = false;
		return false;
	}
	if (!(/^[0-9]+$/.test(codPais))) {
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_FAX) //sImagenAdvertencia + ' <span class=formCamposError>El "Código de País" no es válido, ingrese sólo números</span>'
		//window.event.returnValue = false;
		return false;
	}
	if(codRegion == ''){
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_FAX) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar "Código de Región"</span>'
		//window.event.returnValue = false;
		return false;
	}
	if (!(/^[0-9]+$/.test(codRegion))) {
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_TELEFONOCODREGION) //sImagenAdvertencia + ' <span class=formCamposError>El "Código de Región" no es válido, ingrese sólo números</span>'
		//window.event.returnValue = false;
		return false;
	}
	if(txtFono.value == ''){
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_VACIO_FAX) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar el "Número de Teléfono"</span>'
		//window.event.returnValue = false;
		return false;
	}
	if (!(/^[0-9]{6,8}$/.test(txtFono.value))) {
		document.getElementById('div' + txtFono.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_FAX) //sImagenAdvertencia + ' <span class=formCamposError>El Formato del "Fax" no es válido, ingrese sólo números y con un largo de 6 a 8 caracteres</span>'
		//window.event.returnValue = false;
		return false;
	}	
	ocultarItem('div' + txtFono.id)
	return true
}

function validarCelular(txtCelular){
	
	var codPais		
	var codCodigo
	var txtFono
		
	codPais = trim(document.getElementById('txtCelularPais').value)
	codCodigo = trim(document.getElementById('txtCelularCodigo').value)
	txtCelular = document.getElementById('txtCelular')
	
	mostrarItem('div' + txtCelular.id)
	
	if (txtCelular.value != ''){
		if (!(/^[0-9]{6,8}$/.test(txtCelular.value))) {			
			document.getElementById('div' + txtCelular.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_CELULAR) //sImagenAdvertencia + ' <span class=formCamposError>El Formato del "Celular" no es válido, ingrese sólo números y con un largo de 7 a 8 caracteres</span>'
			//window.event.returnValue = false;
			return false
		}
		
		if (!(/^[0-9]+$/.test(codPais))) {		
			document.getElementById('div' + txtCelular.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_CELULARCODPAIS) //sImagenAdvertencia + ' <span class=formCamposError>El Formato del "Celular" no es válido, ingrese sólo números y con un largo de 7 a 8 caracteres</span>'
			//window.event.returnValue = false;
			return false
		}
		
		if (!(/^[0-9]+$/.test(codCodigo))) {		
			document.getElementById('div' + txtCelular.id).innerHTML = crearStrAdvertencia(MSG_FORMATO_CELULARCODIGO) //sImagenAdvertencia + ' <span class=formCamposError>El Formato del "Celular" no es válido, ingrese sólo números y con un largo de 7 a 8 caracteres</span>'
			//window.event.returnValue = false;
			return false
		}
		
	}
	
	
	ocultarItem('div' + txtCelular.id)
	return true
}

function validarRubros(msg){
	mostrarItem('divValRubros')
	document.getElementById('divValRubros').innerHTML = crearStrAdvertencia(msg)
}

function val(e) {
    tecla = (document.all) ? e.keyCode : e.which;
    //alert(String.fromCharCode(tecla) + " - " + e.keyCode);

    if ((e.keyCode == 8 || e.keyCode == 39 || e.keyCode == 46) || (e.keyCode == 37 && String.fromCharCode(tecla) != "%")) //  && (String.fromCharCode(tecla) == "") || String.fromCharCode(tecla) == "undefined"
        return true;
    patron = /(^[a-zA-Z0-9-]$)/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

function validarFormulario()
{
	var blnResultado = true;

	//Limpia Error General
	document.getElementById('errorGeneral').innerHTML = ''
	document.getElementById('divtxtNombreUsuario').style.display = 'none'
//	document.getElementById('divtxtNombreOrganizacion').style.display = 'none'
	document.getElementById('divtxtClave').style.display = 'none'
	document.getElementById('divtxtClaveConfirmacion').style.display = 'none'
	document.getElementById('divtxtEmailRecepcionDatos').style.display = 'none'
	document.getElementById('divagrpTipoProveedor').style.display = 'none'
	document.getElementById('divtxtRut').style.display = 'none'
	document.getElementById('divtxtRazonSocial').style.display = 'none'
	document.getElementById('divNombreFantasia').style.display = 'none'
	document.getElementById('divtxtGiro').style.display = 'none'
	document.getElementById('divddNivelFacturacion').style.display = 'none'
	document.getElementById('divddNumeroTrabajadores').style.display = 'none'
	document.getElementById('divtxtDireccionCasaMatriz').style.display = 'none'
	document.getElementById('divddPais').style.display = 'none'
	document.getElementById('divddRegion').style.display = 'none'
	document.getElementById('divddComuna').style.display = 'none'
	//document.getElementById('divtxtCiudad').style.display = 'none'
	document.getElementById('divtxtContactoNombre').style.display = 'none'
	document.getElementById('divtxtContactoApellido').style.display = 'none'
	document.getElementById('divtxtContactoCargo').style.display = 'none'
	document.getElementById('divtxtFono').style.display = 'none'
	document.getElementById('divtxtFax').style.display = 'none'
	document.getElementById('divtxtCelular').style.display = 'none'
	document.getElementById('divtxtDireccionCasaMatriz').style.display = 'none'
//	document.getElementById('divtxtEmailOC').style.display = 'none'
	document.getElementById('divtxtEmailRecibirAvisos').style.display = 'none'

//	// 22/11/2005 - DMF - Limpiamos la seccion de Datos Bancarios
	document.getElementById('divCboBancos').style.display = 'none'
	document.getElementById('divaGrpTipoCta').style.display = 'none'
	document.getElementById('divTxtNumeroCta').style.display = 'none'
//	// 22/11/2005 - DMF - Fin modificacion
//	
	//Valida Nombre Usuario
		if (!validarNombreUsuario(document.getElementById('txtNombreUsuario'))) {
	    imprimirError('El "Nombre de Usuario" no es correcto', 'atxtNombreUsuario')
	    blnResultado = false;
	    //window.event.returnValue = false;
	     return false;
	}
	
//	//Nombre Org
//	if (!validarNombreOrg(document.getElementById('txtNombreOrganizacion'))){
//		//imprimirError('Debe ingresar correctamente el "Nombre de Organización" ','atxtNombreOrganizacion')
//		imprimirError()
//		blnResultado = false;
//		window.event.returnValue = false;
//	}
	
	//valida Clave

	if (!validarClave(document.getElementById('txtClave'))){
		//imprimirError('El formato de la "Clave" no es correcta','atxtClave')
		imprimirError()
		blnResultado = false;
		//window.event.returnValue = false;
		return false;
	}
	
	if (!validarClave(document.getElementById('txtClaveConfirmacion'))){
		//imprimirError('El formato de la "Clave" no es correcta','atxtClave')
		imprimirError()
		blnResultado = false;
		//window.event.returnValue = false;
		return false;
	}

//	//valida Email Recibir Datos
	if (!validarEmailRecibirDatos(document.getElementById('txtEmailRecepcionDatos'))){
		//imprimirError('El "Email para Recepción de Datos" no es correcto','atxtEmailRecepcionDatos')
		imprimirError()
		blnResultado = false;
		//window.event.returnValue = false;
		
		return false;
	}
//	
	// valida que se seleccione un Tipo de Empresa
	if (!document.getElementById('radPersona').checked && ! document.getElementById('radEmpresa').checked){
		document.getElementById('divagrpTipoProveedor').style.display = ''
		document.getElementById('divagrpTipoProveedor').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe seleccionar un "Tipo de Proveedor"'
		//imprimirError('Debe seleccionar un "Tipo de Proveedor"','agrpTipoProveedor')
		imprimirError()
		blnResultado = false;
		//window.event.returnValue = false;
		return false;
	}
//	
	//Nacional:valida RUT, Extranjero: Valida Documento
	if (document.getElementById('radNacional').checked ){	
		if(!validarRut()){
			//imprimirError('El "RUT" ingresado no es válido','aTxtRut')
			imprimirError()
			blnResultado = false;
			//window.event.returnValue = false;
			return false;
		}
	}else{
		if(document.getElementById('txtIdenficador').value == ''){
		//imprimirError('Debe ingresar código de "Documento"','aTxtRut')
		
		document.getElementById('divtxtIdentificado').style.display = ''
		document.getElementById('divtxtIdentificado').innerHTML = crearStrAdvertencia(MSG_VACIO_NUMDOC) //sImagenAdvertencia + ' <span class=formCamposError>Debe ingresar el "R.U.T."</span>'	
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
		}
	}

	//Valida Razón Social
	if(document.getElementById('txtRazonSocial').value == ''){
		document.getElementById('divtxtRazonSocial').style.display = ''
		
		document.getElementById('divtxtRazonSocial').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe ingresar la "Raz&oacute;n Social"'
							
		//imprimirError('Debe ingresar la "Razón Social"','atxtRazonSocial')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

	//Valida Nombre de Fantasía
	//Fhurtado Validación con usuario nacional, OT2494
	if((document.getElementById('radNacional').checked )&& (document.getElementById('txtNombreFantasia').value == '')){
		document.getElementById('divNombreFantasia').style.display = ''
		document.getElementById('divNombreFantasia').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe ingresar el "Nombre de Fantas&iacute;a"'
		//imprimirError('Debe ingresar el "Nombre de Fantasía"','atxtNombreFantasia')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}
	
	//Valida Giro
	if(document.getElementById('txtGiro').value == ''){
		document.getElementById('divtxtGiro').style.display = ''
		document.getElementById('divtxtGiro').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe ingresar el "Giro" de la Empresa'
		//imprimirError('Debe ingresar el "Giro" de la Empresa','atxtGiro')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

	//Valida Nivel Facturación
	//Fhurtado Validación con usuario nacional, OT2494
	if((document.getElementById('radNacional').checked )&& (document.getElementById('lstNivelFacturacion').options[document.getElementById('lstNivelFacturacion').selectedIndex].value == '')){
		
		document.getElementById('divddNivelFacturacion').style.display = ''
		document.getElementById('divddNivelFacturacion').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe seleccionar un "Nivel de Facturaci&oacute;n"'
		//imprimirError('Debe seleccionar un "Nivel de Facturación"','addNivelFacturacion')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}
	
	// DATOS BANCARIOS	
	// Valida tipo de Cuenta Solo si se ha Marcado un Banco
	//Fhurtado Validación con usuario nacional, OT2494
	if((document.getElementById('radNacional').checked )&& (document.getElementById('CboBancos').options[document.getElementById('CboBancos').selectedIndex].value != '0'))
	{
		
		if (!document.getElementById('radCtaCte').checked && ! document.getElementById('radCtaVista').checked && !document.getElementById('radCajaAhorro').checked ){
			document.getElementById('divaGrpTipoCta').style.display = ''
			document.getElementById('divaGrpTipoCta').innerHTML = crearStrAdvertencia(MSG_TIPO_CTA)
			imprimirError()
			blnResultado = false;
			//window.event.returnValue = false;
			return false;
		}
	}
	
	// Validacion del numero de cuenta solo si se marca BANCO
	if(document.getElementById('CboBancos').options[document.getElementById('CboBancos').selectedIndex].value != '0')
	{
		if (document.getElementById('txtNumeroCta').value == "")
		{
			document.getElementById('divTxtNumeroCta').style.display = ''
			document.getElementById('divTxtNumeroCta').innerHTML = crearStrAdvertencia(MSG_VACIO_NRO_CTA)
			
			imprimirError()
			blnResultado = false;
			//window.event.returnValue = false;
			return false;
		}
	}

	if(document.getElementById('CboBancos').options[document.getElementById('CboBancos').selectedIndex].value != '0')
	{
		if(!(/^[0-9]+$/.test(document.getElementById('txtNumeroCta').value)))
		{
			document.getElementById('divTxtNumeroCta').style.display = ''
			document.getElementById('divtxtNumeroCta').innerHTML = crearStrAdvertencia(MSG_FORMATO_NRO_CTA) 
			imprimirError()
			blnResultado = false;
			//window.event.returnValue = false;
			return false;
		}
	}
	
	//Valida Número de Trabajadores
	//Fhurtado Validación con usuario nacional, OT2494
	if((document.getElementById('radNacional').checked )&& (document.getElementById('ddNumeroTrabajadores').options[document.getElementById('ddNumeroTrabajadores').selectedIndex].value == '0')){
		document.getElementById('divddNumeroTrabajadores').style.display = ''
		document.getElementById('divddNumeroTrabajadores').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe seleccionar un "N&uacute;mero de Trabajadores"'
		//imprimirError('Debe seleccionar un "Número de Trabajadores"','addNumeroTrabajadores')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

	//Valida Dirección de Casa matriz
	if(document.getElementById('txtDireccionCasaMatriz').value == ''){
		document.getElementById('divtxtDireccionCasaMatriz').style.display = ''
		document.getElementById('divtxtDireccionCasaMatriz').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe ingresar la "Direcci&oacute;n de la Casa Matriz"'
		//imprimirError('Debe ingresar la "Dirección de la Casa matriz"','atxtDireccionCasaMatriz')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

	//Valida que se seleccione una Región y Comuna
	var ddPais = document.getElementById('ddPais');
	var ddRegion = document.getElementById('ddRegion');
	var ddComuna = document.getElementById('ddComuna');
	var txtCiudad =document.getElementById('txtCiudad');
    cambia_ddpais();
    if(ddPais.options[ddPais.selectedIndex].text == 'Chile')
	{
	    ddPais.options[ddPais.selectedIndex].value="CL"
        if(ddRegion.options[ddRegion.selectedIndex].value == '0')
        {
			document.getElementById('divddRegion').style.display = ''
			document.getElementById('divddRegion').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe seleccionar una Regi&oacute;n'
			//imprimirError('Debe seleccionar una "Región"','addRegion')	
			imprimirError()
			blnResultado = false
			//window.event.returnValue = false;
			return false;
		}
        
        if  (document.getElementById('ddComuna').disabled == false)
        {

            if(ddComuna.options[ddComuna.selectedIndex].value == '0'){	
		        document.getElementById('divddComuna').style.display = ''
		        document.getElementById('divddComuna').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe seleccionar una Comuna'
		        //imprimirError('Debe seleccionar una "Comuna"','addComuna')	
		        imprimirError()
		        blnResultado = false
		        //window.event.returnValue = false;
		        return false;
		        }
        }
	}
	
	
	//siempre ciudad

	    if(txtCiudad.value == ''){	
		        document.getElementById('divtxtCiudad').style.display = ''
		        document.getElementById('divtxtCiudad').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe ingresar una Ciudad'
		        //imprimirError('Debe seleccionar una "Comuna"','addComuna')	
		        imprimirError()
		        blnResultado = false
		        //window.event.returnValue = false;
		        return false;
		        }
	//Valida Pais
    if  (document.getElementById('ddPais').disabled ==false)
	{
	    if(ddPais.options[ddPais.selectedIndex].value == '0'){
		        document.getElementById('divddPais').style.display = ''
			    
			    document.getElementById('divddPais').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe seleccionar un Pa&iacute;s'		
			    imprimirError()
			    blnResultado = false
			    //window.event.returnValue = false;
			    return false;
	    }
    }
//	//CONTACTO

	//Valida Nombre
	if(document.getElementById('txtContactoNombre').value == ''){
		document.getElementById('divtxtContactoNombre').style.display = ''
		document.getElementById('divtxtContactoNombre').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe ingresar el "Nombre del Contacto"'
		//imprimirError('Debe ingresar el "Nombre del Contacto"','atxtContactoNombre')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

//	//Valida Apellido
	if(document.getElementById('txtContactoApellido').value == ''){
		document.getElementById('divtxtContactoApellido').style.display = ''
		document.getElementById('divtxtContactoApellido').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe ingresar el "Apellido del Contacto"'
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

	//Valida el Cargo del Contacto
	//Fhurtado Validación con usuario nacional, OT2494
	if((document.getElementById('radNacional').checked )&& (document.getElementById('txtContactoCargo').value == '')){
		document.getElementById('divtxtContactoCargo').style.display = ''
		document.getElementById('divtxtContactoCargo').innerHTML = sImagenAdvertencia + ' <span class=formCamposError> Debe ingresar el "Cargo del Contacto"'
		//imprimirError('Debe ingresar el "Cargo del Contacto"','atxtContactoCargo')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

//	//Valida Fono Contacto
	if(!validarFono(true)){	
		//imprimirError('Debe ingresar el "Teléfono de contacto" correctamente','atxtFono')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

	//Valida Celular
	//Fhurtado Validación con usuario nacional, OT2494
	if ((document.getElementById('radNacional').checked )&&(!validarCelular(document.getElementById('txtCelular')))){	
		//imprimirError('Debe ingresar el "Celular de contacto" correctamente','atxtCelular')
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}

//	//Valida fax si es ingresado
	var	codPaisFax = trim(document.getElementById('txtFaxPais').value)
	var	codRegionFax = trim(document.getElementById('txtFaxRegion').value)
	var txtFonoFax = trim(document.getElementById('txtFax').value)
	
	if (codPaisFax != '' || codRegionFax != '' || txtFonoFax != ''){
	  	if(!validarFax()){
			//imprimirError('Debe ingresar el "Fax de contacto" correctamente','atxtFax')
			imprimirError()
			blnResultado = false
			//window.event.returnValue = false;
			return false;
		}
	}
	
	//Valida Mail para recibir OC
//	if(!validarEmailRecibirOC(document.getElementById('txtEmailOC'))){	
//		document.getElementById('txtEmailOC').style.display = ''
//		//imprimirError('El "Mail para recibir Ordenes de Compra" no es válido','atxtEmailOC')
//		imprimirError()
//		blnResultado = false
//		//window.event.returnValue = false;
//		return false;
//	}


	//Valida Mail para recibir Avisos
	if(!validarEmailAvisos(document.getElementById('txtEmailRecibirAvisos')))
	{	
		document.getElementById('divtxtEmailRecibirAvisos').style.display = ''
		imprimirError()
		blnResultado = false
		//window.event.returnValue = false;
		return false;
	}
	else
	{
//	alert('2'); aqui
    
	}
	var rubros= document.getElementById('dgrGoodandServices')
	if (rubros == null) {
	    imprimirError();
	    validarRubros('Debe Asociar al Menos un Rubro a su Empresa');
	    blnResultado = false
	    //window.event.returnValue = false;
	    alert("rubros");
	    return false;
	} 
	return true;
	
}


function cambia_ddpais()
{
    var ddPais = document.getElementById('ddPais');
    document.Form1.hidIdCountry.value =ddPais.options[ddPais.selectedIndex].value;
    //alert(document.Form1.hidIdCountry.value);
}

function finalizarRegistro() {
    
    var blnCondicionesAceptadas = true
    
	//Verificar CONDICIONES
	if (!document.getElementById('radCondicionesSI').checked){
		/*alert('Para operar en el Sistema de Compras y Contratación Pública,  usted debe Aceptar las Condiciones Generales de Uso')*/
		alert('Para operar en el Sistema de Compras y Contrataci\u00F3n P\u00FAblica,  usted debe Aceptar las Condiciones Generales de Uso')
		blnCondicionesAceptadas = false;
		
		enviarAAncla('aCond')
		//window.event.returnValue = false;
		return false;
	}
	//__doPostBack('btnFinalizarRegistro','')
	
	if (validarFormulario() && blnCondicionesAceptadas) {
	    
	  //debugger
	    __doPostBack('imbSiguiente', '')
    } else {

	enviarAAncla('aerrorGeneral')
	}
		
}
function validarNoBlanco(obj){
	if(obj.value != ''){ocultarItem('div' + obj.id)}
}
function validarNoSeleccionado(obj){
	if(obj.value != '0'){ocultarItem('div' + obj.id)}	
}

function seleccionarComuna(idComuna){
	var i,index;	
	var ddComuna = document.getElementById('ddComuna')
	for (i=0;i<ddComuna.options.length;i++){
		if (ddComuna.options[i].value == idComuna){
			index = i;
			break;
		}
	}
	ddComuna.selectedIndex = index		
}

function seleccionarPais(idPais){
	var i,index;	
	var ddPais = document.getElementById('ddPais')
	for (i=0;i<ddPais.options.length;i++){
		if (ddPais.options[i].value == idPais){
			index = i;
			break;
		}
	}
	ddPais.selectedIndex = index	
	document.Form1.hidIdCountry.value=ddPais.value;  	
	
}
function cargarInicial(){		
//	operarRubros();	

      var ddPais = document.getElementById('ddPais') 
      var ddComuna = document.getElementById('ddComuna');
	  var ddRegion = document.getElementById('ddRegion');  

        if (document.Form1.hidIdCountry.value == "")
      {
             seleccionarPais('CL');
        	listarComunaPorRegion(document.getElementById('hidIdRegion').value)
	        seleccionarComuna(document.getElementById('hidIdComuna').value)
      }  
      else
      {
          ddPais.options[ddPais.selectedIndex].value=document.Form1.hidIdCountry.value;
          listarComunaPorRegion(document.getElementById('hidIdRegion').value)
	      seleccionarComuna(document.getElementById('hidIdComuna').value)
          
        //alert(document.Form1.hidIdCountry.value);
//        if( (ddPais.options[ddPais.selectedIndex].value &= 'CL') && (document.Form1.hidIdCountry.value &= '0' ))
//        {
//            ddPais.options[ddPais.selectedIndex].value=document.Form1.hidIdCountry.value;
//        }    
      
      }

	if(document.getElementById('radNacional').checked){
		setearNacionalidad(0)	
			
	}else{		
		setearNacionalidad(1)
	}
	if(document.getElementById('radPersona').checked){
		setearTipoEmpresa(0)
	}
	else{
		setearTipoEmpresa(1)
	}

	
	if (ddRegion.options[ddRegion.selectedIndex].text == 'Seleccionar...')
	{
		ddComuna.disabled = true;	
	}
	else
	{
		ddComuna.disabled = false;	
	}
  //  alert("valor:" + document.getElementById('hidClave').value );
	document.getElementById('txtClave').value = document.getElementById('hidClave').value	
	document.getElementById('txtClaveConfirmacion').value = document.getElementById('hidClave').value		
	
	if ( (document.getElementById('radSuscripcion11').checked) || (document.getElementById('radSuscripcion21').checked) || (document.getElementById('radSuscripcion12').checked) || (document.getElementById('radSuscripcion22').checked) )
	{
	   document.getElementById('txtEmailRecibirAvisos').disabled = false;
	}

	
	
}


function irAPrincipal(){
	if((confirm('\u00BFEst\u00E1 seguro que desea borrar y volver a la P\u00E1gina Principal?'))){
		window.location.href='../../Login.aspx'
	}
}

		function VentanaTarifas(){
		window.open("http://www.chileproveedores.cl/Default.aspx?tabid=2282","Tarifas"," width=740, heigth=500, scrollbars=yes, menubar=no")
		}
function Rnp(x){
		s = window.location.href("bienvenidaRNP.aspx?r=" + x )
		/*if (s != null){
			window.setTimeout('window.location.replace("bienvenidaRNP.aspx?qs=1&r=' + x + '")',10)
		}*/
}

var sImagenError = '<img src="../../Includes/images/RNP/Icons/ic_error.gif" width="14" height="14" border=0/> ';	
		
	function cargarFiltrosEmail(){
		__doPostBack('btnFiltrosEmail','')
	}	
		
	function errorPagina(mensaje){
		document.getElementById('errorGeneral').innerHTML=  sImagenError + ' ' + mensaje;
		document.getElementById('errorGeneral').style.display = '';		
    }	

	function verTerminosDeUso(url){
		var s = 'pages/Terminos_Condiciones.htm'
		open(s , "CondicioneDeUso", "width=600, height=305, status=yes, scrollbars=yes, left=0, top=0 , resizable=yes");				
	}
	function mostrarAyuda(url){
	    
		var s = 'pages/AyudaDinamica.aspx?a=' + url
		open(s , "PaginaAyuda", "width=600, height=410, status=no, scrollbars=no, left=0, top=0 , resizable=no");				
	}
	function VentanaTarifas(){
		window.open("http://www.chileproveedores.cl/Default.aspx?tabid=2282","Tarifas"," width=740, heigth=500, scrollbars=yes, menubar=no")
	}
	function Rnp(x){
			s = window.location.href("bienvenidaRNP.aspx?r=" + x )
			/*if (s != null){
				window.setTimeout('window.location.replace("bienvenidaRNP.aspx?qs=1&r=' + x + '")',10)
			}*/
	}
	function ventana_filtros(){
		window.open("NotifyFilters.aspx","Filtros"," width=780, heigth=250, scrollbars=yes, status=yes,menubar=no,resizable=yes");
	}

	onload = function(){
		cargarInicial();
	}
	
	function validarBanco() {	
	if (document.Form1.CboBancos.value!=0 && document.Form1.radExtranjero.value==0)
	
		{
			document.getElementById('divtipo_cuenta').innerHTML= '<span class="formObliga">*</span>Tipo Cuenta';
			document.getElementById('dvdnro_cuenta').innerHTML= '<span class="formObliga">*</span>N&uacute;mero Cuenta';
		}	
		else
		{
			
			document.getElementById('divtipo_cuenta').innerHTML= '<span class="formObliga"></span>Tipo Cuenta';
			document.getElementById('dvdnro_cuenta').innerHTML= '<span class="formObliga"></span>N&uacute;mero Cuenta';
		}
		
	}
	
		function validarNorecibirEmail()
	{
		if (document.Form1.radSuscripcion3.checked)
		{
			document.getElementById('divEmailRecibirAvisos').innerHTML= '<span class="formObliga"></span>E-mail para recibir Avisos';
			document.getElementById('txtEmailRecibirAvisos').disabled = true;
			document.getElementById('divtxtEmailRecibirAvisos').style.display = 'none';
			document.getElementById('divTablaFiltros').style.display = 'none';
		}
	}
	    function FnSeleccionarRubrosProv(x){
	
	
	}
	function fnRecargarRubros(x){
	   	__doPostBack('btnAgregarRubros','')
	   	
	}
	
	function oculta_msj(tipo)
	{
	    switch(tipo)
            {
            case 0:
                document.getElementById('divtxtNombreUsuario').style.display = 'none';
                break;    
            
            case 1:
                document.getElementById('divtxtClave').style.display = 'none';
                break;    
            case 2:
                document.getElementById('divtxtClaveConfirmacion').style.display = 'none';
                break;
            case 3:
                document.getElementById('divtxtEmailRecepcionDatos').style.display = 'none';
                break;  
            case 4:
                document.getElementById('divtxtRut').style.display = 'none';
                break;
            case 5:
                document.getElementById('divtxtRazonSocial').style.display = 'none';
                break;                  
            case 6:
                document.getElementById('divNombreFantasia').style.display = 'none';
                break;
            case 7:
                document.getElementById('divtxtGiro').style.display = 'none';
                break;
            case 8:
                document.getElementById('divddNivelFacturacion').style.display = 'none';
                break;
            case 9:
                document.getElementById('divddNumeroTrabajadores').style.display = 'none';
                break;
            case 10:
                document.getElementById('divTxtNumeroCta').style.display = 'none';
                break;
            case 11:
                document.getElementById('divtxtDireccionCasaMatriz').style.display = 'none';
                break;                
                
            case 12:
                document.getElementById('divtxtCiudad').style.display = 'none';
                break;    
            case 13:
                document.getElementById('divtxtContactoNombre').style.display = 'none';
                break;    
            case 14:
                document.getElementById('divtxtContactoCargo').style.display = 'none';
                break;                                                    
            case 15:
               // document.getElementById('divtxtEmailOC').style.display = 'none';
                break;                    
            case 16:
                document.getElementById('divtxtContactoApellido').style.display = 'none';
                break;     
            case 17:
                document.getElementById('divtxtFono').style.display = 'none';
                break;                                     
            case 18:
                document.getElementById('divtxtFax').style.display = 'none';
                break;                                     
            case 19:
                document.getElementById('divtxtCelular').style.display = 'none';
                break;           
            case 20:
                document.getElementById('divtxtIdentificado').style.display = 'none';
                break;  
            default:


            } 

	     
	}
	
function borrarFila(valor) 
{
         
         document.Form1.hdnValor.value=valor;
         if (confirm("\u00BFEst\u00E1 Seguro que desea Eliminar este Giro?"))
         {
	            __doPostBack('btnEliminar','')
	     }
        else
        {
               return false;
        }	                 

}	

function textooculto()
{

if (document.getElementById('txtClave').value == document.getElementById('txtClaveConfirmacion').value )
{
        document.getElementById('hidClave').value = document.getElementById('txtClaveConfirmacion').value	
     //   alert(document.getElementById('hidClave').value);
}
else
{
    document.getElementById('divtxtClaveConfirmacion').innerHTML = crearStrAdvertencia(MSG_FORMATO_CLAVECONFIRMACION) //sImagenAdvertencia + ' <span class=formCamposError>La clave de confirmación no coincide con la clave ingresada</span>'	
	//window.event.returnValue = false;
	return false;	
}

}


