
function formulario_tipo_registro(tipo_registro){
    if(tipo_registro=='persona'){
      $("#persona").show();
      $("#empresa").hide();
    }else{
      $("#empresa").show();
      $("#persona").hide();
    }
}

function validarFecha(dia_c,mes_c,anio_c){
var fecha=new Date();
var dia=fecha.getDate();
var mes=fecha.getMonth() +1 ;
var ano=fecha.getFullYear();

    if(anio_c >= ano)
    if( anio_c <= ano)
        if(mes_c <= mes )
           if(dia_c <= dia)
            return false;
            else
            return true;
         else
        return true;
    else
    return true;

}

function validar_compra_empresa_paso3(productos){
  if(productos > 0){
    if(getIdValue('medio')=='' )
		alert('Seleccione medio de pago ');
    else{

    if(getIdValue('medio')=='tarjeta'){
        $('#main_contenido').load('cgi-bin/pago.php',
        {medio:getIdValue('medio')})

    }else if(getIdValue('medio')=='entrega'){
            if(getIdValue('especificacion')=='')
		    alert('Ingrese alguna especificación');
            else
            $('#main_contenido').load('aplicaciones/productos/empresa_formulario_paso3_accion.php',
            {medio:getIdValue('medio'),especificacion: getIdValue('especificacion')})

    } else if(getIdValue('medio')=='banco'){
       elemento = document.getElementById("cuenta");
       if(!elemento.checked)
        alert('Debe seleccionar la opcion');
        else
        $('#main_contenido').load('aplicaciones/productos/empresa_formulario_paso3_accion.php',
        {medio:getIdValue('medio'),banco:getIdValue('banco')})

    } else if(getIdValue('medio')=='cheque'){
      elemento = document.getElementById("cheque");
      if(!elemento.checked)
        alert('Debe seleccionar la opcion');
        else
        $('#main_contenido').load('aplicaciones/productos/empresa_formulario_paso3_accion.php',
        {observacion:getIdValue('observacion'),medio:getIdValue('medio'),cheque:getIdValue('cheque')})

    }

    }
   }else{alert('No tiene productos para cotizar');}
}
function validar_compra_empresa_paso3_cotizacion(productos){

    if(productos > 0){
        cargar_url_id2('aplicaciones/productos/empresa_formulario_paso3_accion.php','main_contenido');
    }
        else
        {
            alert('No tiene productos para cotizar');
        }
}


function validar_compra_empresa_paso2(){

    if(getIdValue('atencion_a')=='')
        alert('Ingrese atencion a');
    else if(getIdValue('direccion_envio')=='' )
		alert('Ingrese Dirección de Envio ');
    else if(getIdValue('numero_direccion')=='')
		alert('Ingrese Numero de Dirección ');
    else if(getIdValue('region')=='')
		alert('Ingrese Región');
    else if(getIdValue('provincia')=='')
		alert('Ingrese Ciudad');
	else if(getIdValue('comuna')=='')
		alert('Ingrese Comuna');


    else if(document.getElementById('opcion').checked){
        if(getIdValue('atencion_a2')=='')
        alert('Ingrese atencion a');
        else if(getIdValue('direccion2')=='')
		    alert('Ingrese la Direccion de Envio de Factura');
        else if(getIdValue('numero_direccion2')=='')
    		alert('Ingrese la Direccion de Envio de Factura');
        else if(getIdValue('region2')=='')
    		alert('Ingrese Región');
        else if(getIdValue('provincia2')=='')
    		alert('Ingrese Ciudad');
    	else if(getIdValue('comuna2')=='')
    		alert('Ingrese Comuna');
        else
        cargar_url_id2('aplicaciones/productos/empresa_formulario_paso2_accion.php?atencion_a='+URLEnc(document.getElementById('atencion_a').value)+'&direccion_envio='+URLEnc(document.getElementById('direccion_envio').value)+'&comprobante='+getNameValues('comprobante')+'&numero_direccion='+URLEnc(document.getElementById('numero_direccion').value)+'&region='+document.getElementById('region').value+'&provincia='+document.getElementById('provincia').value+'&comuna='+document.getElementById('comuna').value+'&codigo_postal='+URLEnc(document.getElementById('codigo_postal').value)+'&atencion_a2='+URLEnc(document.getElementById('atencion_a2').value)+'&direccion2='+URLEnc(document.getElementById('direccion2').value)+'&numero_direccion2='+URLEnc(document.getElementById('numero_direccion2').value)+'&region2='+document.getElementById('region2').value+'&provincia2='+document.getElementById('provincia2').value+'&comuna2='+document.getElementById('comuna2').value+'&codigo_postal2='+document.getElementById('codigo_postal2').value+'&opcion=si','main_contenido');

    }else
        cargar_url_id2('aplicaciones/productos/empresa_formulario_paso2_accion.php?atencion_a='+URLEnc(document.getElementById('atencion_a').value)+'&direccion_envio='+URLEnc(document.getElementById('direccion_envio').value)+'&comprobante='+getNameValues('comprobante')+'&numero_direccion='+URLEnc(document.getElementById('numero_direccion').value)+'&region='+document.getElementById('region').value+'&provincia='+document.getElementById('provincia').value+'&comuna='+document.getElementById('comuna').value+'&codigo_postal='+URLEnc(document.getElementById('codigo_postal').value),'main_contenido');
}





function validar_compra_persona_paso1(){
    if(getIdValue('atencion_a') == '')
        alert('Ingrese Atención a ');
    else if(getIdValue('direccion_envio')=='' )
		alert('Ingrese Dirección de Envio ');
    else if(getIdValue('numero_direccion')=='')
		alert('Ingrese Numero de Dirección ');
    else if(getIdValue('region')=='')
		alert('Ingrese la Región');
    else if(getIdValue('provincia')=='')
		alert('Ingrese Ciudad');
	else if(getIdValue('comuna')=='')
		alert('Ingrese la Comuna');

    else if(document.getElementById('opcion').checked){
    if(getIdValue('atencion_a2') == '')
        alert('Ingrese Atención a ');
    else if(getIdValue('direccion2')=='')
		alert('Ingrese la Direccion de Envio de Factura');
    else if(getIdValue('numero_direccion2')=='')
		alert('Ingrese la Direccion de Envio de Factura');
    else if(getIdValue('region2')=='')
		alert('Ingrese la Región');
    else if(getIdValue('provincia2')=='')
		alert('Ingrese Ciudad');
	else if(getIdValue('comuna2')=='')
		alert('Ingrese la Comuna');
    else
    cargar_url_id2('aplicaciones/productos/persona_formulario_paso1_accion.php?atencion_a='+URLEnc(document.getElementById('atencion_a').value)+'&direccion_envio='+URLEnc(document.getElementById('direccion_envio').value)+'&numero_direccion='+URLEnc(document.getElementById('numero_direccion').value)+'&region='+document.getElementById('region').value+'&provincia='+document.getElementById('provincia').value+'&comuna='+document.getElementById('comuna').value+'&codigo_postal='+URLEnc(document.getElementById('codigo_postal').value)+'&atencion_a2='+URLEnc(document.getElementById('atencion_a2').value)+'&direccion2='+URLEnc(document.getElementById('direccion2').value)+'&numero_direccion2='+URLEnc(document.getElementById('numero_direccion2').value)+'&region2='+document.getElementById('region2').value+'&provincia2='+document.getElementById('provincia2').value+'&comuna2='+document.getElementById('comuna2').value+'&codigo_postal2='+URLEnc(document.getElementById('codigo_postal2').value)+'&opcion=si','main_contenido');
    }else
    cargar_url_id2('aplicaciones/productos/persona_formulario_paso1_accion.php?atencion_a='+URLEnc(document.getElementById('atencion_a').value)+'&direccion_envio='+URLEnc(document.getElementById('direccion_envio').value)+'&numero_direccion='+URLEnc(document.getElementById('numero_direccion').value)+'&region='+document.getElementById('region').value+'&provincia='+document.getElementById('provincia').value+'&comuna='+document.getElementById('comuna').value+'&codigo_postal='+URLEnc(document.getElementById('codigo_postal').value)+'&opcion=no','main_contenido');

}

function validar_compra_persona_paso2(productos,regalos){

    if(productos > 0){
    if(getIdValue('medio')=='' )
		alert('Seleccione medio de pago ');
    else{

    if(getIdValue('medio')=='tarjeta'){
        $('#main_contenido').load('cgi-bin/pago_personas.php',
        {regalo:regalos,envio:getNameValues('envio'),observacion:getIdValue('observacion'),
        medio:getIdValue('medio')})

    }else if(getIdValue('medio')=='entrega'){
            if(getIdValue('especificacion')=='')
		    alert('Ingrese alguna especificación');
            else
            $('#main_contenido').load('aplicaciones/productos/persona_formulario_paso2_accion.php',
            {observacion:getIdValue('observacion'),medio:getIdValue('medio'),especificacion: getIdValue('especificacion'),
            regalo:regalos,tot_reg:getIdValue('tot_reg'),envio:getNameValues('envio')})

    } else if(getIdValue('medio')=='banco'){
       elemento = document.getElementById("cuenta");
       if(!elemento.checked)
        alert('Debes seleccionar la opcion');
        else
        $('#main_contenido').load('aplicaciones/productos/persona_formulario_paso2_accion.php',
        {regalo:regalos,envio:getNameValues('envio'),observacion:getIdValue('observacion'),
        medio:getIdValue('medio'),banco:getIdValue('banco')})
        }
    }
    }
    else{alert('No tiene productos para cotizar');}

}

function comprueba_checkbox(idregalo)
{

   if(document.getElementById(idregalo).checked)
   {
       return "Si";
   }
          else
          {
            return "No";
          }


}



function validar_registro_cliente(){
var ficha_formulario_Email;
ficha_formulario_Email = getId( 'email' ).value.replace( /\s/g, '' );

	if(getIdValue('rut')=='' ||  getIdValue('dv')=='')
		alert('Ingrese un RUT');
	else if(!validarRut(getIdValue('rut'),getIdValue('dv')))
		return false;
    else if( ficha_formulario_Email.indexOf('@') < 1 ||
            ficha_formulario_Email.indexOf('.') < 1 ||
            ficha_formulario_Email.indexOf('@') > ficha_formulario_Email.length - 6 ||
            ficha_formulario_Email.indexOf('@') != ficha_formulario_Email.lastIndexOf('@') ||
            ficha_formulario_Email.lastIndexOf('.') == ficha_formulario_Email.length - 1 ||
            ficha_formulario_Email.lastIndexOf('.') < ficha_formulario_Email.indexOf('@') )
            alert('Ingrese un email válido');
    else if(getIdValue('region')=='')
		alert('Ingrese la Region');
	else if(getIdValue('provincia')=='')
		alert('Ingrese Ciudad');
	else if(getIdValue('comuna')=='')
		alert('Ingrese la Comuna');
	else if(getIdValue('telefono')=='')
		alert('Ingrese el Telefono');
	else if(getIdValue('direccion')=='')
		alert('Ingrese la Direccion');
	else if(getIdValue('password')=='' || getIdValue('re_password')=='' || getIdValue('re_password')!=getIdValue('password') )
		alert('Ingrese su Password y repita en Confirmar  Password');

	else if(getIdValue('tipo_registro')=='persona' && getIdValue('nombre')=='')
   		alert('Ingrese su Nombre');
   	else if(getIdValue('tipo_registro')=='persona' && getIdValue('apellidopaterno')=='')
   		alert('Ingrese su Apellido Paterno');
   	else if(getIdValue('tipo_registro')=='persona' && getIdValue('apellidomaterno')=='')
   		alert('Ingrese su Apellido Materno');

   	else if(getIdValue('tipo_registro')=='empresa' && getIdValue('razon_social')=='')
   		alert('Ingrese la Razon Social');
   	else if(getIdValue('tipo_registro')=='empresa' && getIdValue('giro')=='')
   		alert('Ingrese el Giro');
   	else if(getIdValue('tipo_registro')=='empresa' && getIdValue('contacto')=='')
   		alert('Ingrese la Persona de Contacto');

    else
		enviar_registro_cliente();
}

function enviar_registro_cliente(){
    $('#barracentro').load('aplicaciones/usuarios/registro_usuarios_accion.php',
    {
    tipo_registro:getIdValue('tipo_registro'),
    rut:getIdValue('rut'),
    dv:getIdValue('dv'),
    email:getIdValue('email'),
    nombre:getIdValue('nombre'),
    apellidopaterno:getIdValue('apellidopaterno'),
    apellidomaterno:getIdValue('apellidomaterno'),
    razon_social:getIdValue('razon_social'),
    giro:getIdValue('giro'),
    contacto:getIdValue('contacto'),
    region:getIdValue('region'),
    provincia:getIdValue('provincia'),
    comuna:getIdValue('comuna'),
    direccion:getIdValue('direccion'),
    telefono:getIdValue('telefono'),
    fax:getIdValue('fax'),
    celular:getIdValue('celular'),
    codigo_postal:getIdValue('codigo_postal'),
    password:getIdValue('password'),
    'intereses[]':getNameValues('intereses[]'),
    re_password:getIdValue('re_password')
    })

}

function enviar_registro_detalle_cliente(){
    $('#main_contenido').load('aplicaciones/usuarios/editar_usuarios_accion.php',
    {
    tipo_registro:getIdValue('tipo_registro'),
    rut:getIdValue('rut'),
    dv:getIdValue('dv'),
    email:getIdValue('email'),
    nombre:getIdValue('nombre'),
    apellidopaterno:getIdValue('apellidopaterno'),
    apellidomaterno:getIdValue('apellidomaterno'),
    razon_social:getIdValue('razon_social'),
    giro:getIdValue('giro'),
    contacto:getIdValue('contacto'),
    region:getIdValue('region'),
    provincia:getIdValue('provincia'),
    comuna:getIdValue('comuna'),
    direccion:getIdValue('direccion'),
    telefono:getIdValue('telefono'),
    fax:getIdValue('fax'),
    celular:getIdValue('celular'),
    codigo_postal:getIdValue('codigo_postal'),
    password:getIdValue('password'),
    'intereses[]':getNameValues('intereses[]'),
    re_password:getIdValue('re_password')
    })

}



function validar_registro_personas(){
var ficha_formulario_Email_1;
var ficha_formulario_Email_2;
ficha_formulario_Email_1 = getId( 'email' ).value.replace( /\s/g, '' );
ficha_formulario_Email_2 = getId( 're_email' ).value.replace( /\s/g, '' );

  var p1 = document.getElementById("email").value;
  var p2 = document.getElementById("re_email").value;
  var p3 = document.getElementById("password").value;
  var p4 = document.getElementById("re_password").value;
  var rut = document.getElementById("rut").value;
  var dv = document.getElementById("dv").value;

    if(getIdValue('nombre')=='' )
		alert('Ingrese Nombre ');
    else if(getIdValue('apellidopaterno')=='')
		alert('Ingrese Apellido Paterno');
    else if(getIdValue('apellidomaterno')=='')
		alert('Ingrese Apellido Materno');
    else if(getIdValue('rut')=='' ||  getIdValue('dv')=='')
		alert('Ingrese un RUT');
	else if(!validarRut(getIdValue('rut'),getIdValue('dv')))
		return false;
    else if(getIdValue('region')=='')
		alert('Ingrese Región');
    else if(getIdValue('provincia')=='')
		alert('Ingrese Ciudad');
	else if(getIdValue('comuna')=='')
		alert('Ingrese Comuna');
    else if( ficha_formulario_Email_1.indexOf('@') < 1 ||
        ficha_formulario_Email_1.indexOf('.') < 1 ||
        ficha_formulario_Email_1.indexOf('@') > ficha_formulario_Email_1.length - 6 ||
        ficha_formulario_Email_1.indexOf('@') != ficha_formulario_Email_1.lastIndexOf('@') ||
        ficha_formulario_Email_1.lastIndexOf('.') == ficha_formulario_Email_1.length - 1 ||
        ficha_formulario_Email_1.lastIndexOf('.') < ficha_formulario_Email_1.indexOf('@') )
        alert('Ingrese un email válido');
    else if( ficha_formulario_Email_2.indexOf('@') < 1 ||
        ficha_formulario_Email_2.indexOf('.') < 1 ||
        ficha_formulario_Email_2.indexOf('@') > ficha_formulario_Email_2.length - 6 ||
        ficha_formulario_Email_2.indexOf('@') != ficha_formulario_Email_2.lastIndexOf('@') ||
        ficha_formulario_Email_2.lastIndexOf('.') == ficha_formulario_Email_2.length - 1 ||
        ficha_formulario_Email_2.lastIndexOf('.') < ficha_formulario_Email_2.indexOf('@') )
        alert('Repita el email válido');
    else if(getIdValue('password')=='')
		alert('Ingrese  Password');
    else if(getIdValue('re_password')=='')
		alert('Ingrese repita la Password ');
    else if(getIdValue('pregunta')=='')
		alert('Ingrese  Pregunta secreta');
    else if(getIdValue('respuesta')=='')
		alert('Ingrese Respuesta ');
    else if (p1 != p2)
      alert("Las Mails deben de coincidir");
    else if (p3 != p4)
      alert("Las Password deben de coincidir");
    else if(!document.getElementById("aceptar").checked)
      alert('Debe aceptar terminos y condiciones');
    else

    $('#mensaje').load('aplicaciones/usuarios/registro_personas_accion.php',
    {apellidopaterno:getIdValue('apellidopaterno'),apellidomaterno:getIdValue('apellidomaterno'),
    nombre:getIdValue('nombre'),tipo_registro:getIdValue('tipo_registro'),genero:getIdValue('genero'),
    estadocivil:getIdValue('estadocivil'),rut:getIdValue('rut'),dv:getIdValue('dv'),dia:getIdValue('dia'),
    mes:getIdValue('mes'),anno:getIdValue('anno'),direccion:getIdValue('direccion'),numero:getIdValue('numero'),
    depto:getIdValue('depto'),region:getIdValue('region'),provincia:getIdValue('provincia'),comuna:getIdValue('comuna'),
    codarea:getIdValue('codarea'),telefono:getIdValue('telefono'),codcel:getIdValue('codcel'),celular:getIdValue('celular'),
    codigo_postal:getIdValue('codigo_postal'),email:getIdValue('email'),re_email:getIdValue('re_email'),
    password:getIdValue('password'),re_password:getIdValue('re_password'),pregunta:getIdValue('pregunta'),
    respuesta:getIdValue('respuesta'),enviar:'Enviar'})


}

function validar_rut_empresa(){

var rut_completo =document.getElementById("rut_empresa").value;
var rut_dv =document.getElementById("rut_dv_empresa").value;

var rut=rut_completo[0]+rut_completo[1]+rut_completo[2]+rut_completo[3]+rut_completo[4]+rut_completo[5]+rut_completo[6]+rut_completo[7];
var dv = rut_dv;

//var largo = rut_completo;

    if(getIdValue('rut_empresa')=='' )
    alert('Rut Invalido');
    else if(rut_dv == '')
    alert('Rut Invalido');
	else if(validarRut(rut,dv))
        return true;



}

function validar_registro_empresa(){

var ficha_formulario_Email_1;
var ficha_formulario_Email_2;
var p1 = document.getElementById("mail_contacto").value;
var p2 = document.getElementById("re_mail_contacto").value;
var p3 = document.getElementById("pass").value;
var p4 = document.getElementById("re_pass").value;
var rut =document.getElementById("rut_empresa").value;
var dv = rut.length;
ficha_formulario_Email_1 = getId( 'mail_contacto' ).value.replace( /\s/g, '' );
ficha_formulario_Email_2 = getId( 're_mail_contacto' ).value.replace( /\s/g, '' );


    if(getIdValue('nombre_contacto')=='' )
		alert('Ingrese Nombre ');
    else if(getIdValue('apellido_contacto')=='' )
		alert('Ingrese Apellido ');
    else if(getIdValue('cargo')=='' )
		alert('Ingrese  Cargo');
    else if(getIdValue('nombre_empresa')=='' )
		alert('Ingrese Nombre de la Empresa ');
    else if(!validar_rut_empresa())
	     return false;
    else if(getIdValue('razon_social')=='' )
		alert('Ingrese Razon Social ');
    else if(getIdValue('giro')=='' )
		alert('Ingrese Giro ');
    else if(getIdValue('num_empleados')=='' )
		alert('Ingrese Tamañao de Empresa ');
    else if(getIdValue('region')=='')
		alert('Ingrese Región');
    else if(getIdValue('provincia')=='')
		alert('Ingrese Ciudad');
	else if(getIdValue('comuna')=='')
		alert('Ingrese Comuna');
    else if( ficha_formulario_Email_1.indexOf('@') < 1 ||
        ficha_formulario_Email_1.indexOf('.') < 1 ||
        ficha_formulario_Email_1.indexOf('@') > ficha_formulario_Email_1.length - 6 ||
        ficha_formulario_Email_1.indexOf('@') != ficha_formulario_Email_1.lastIndexOf('@') ||
        ficha_formulario_Email_1.lastIndexOf('.') == ficha_formulario_Email_1.length - 1 ||
        ficha_formulario_Email_1.lastIndexOf('.') < ficha_formulario_Email_1.indexOf('@') )
        alert('Ingrese un email válido');
    else if( ficha_formulario_Email_2.indexOf('@') < 1 ||
        ficha_formulario_Email_2.indexOf('.') < 1 ||
        ficha_formulario_Email_2.indexOf('@') > ficha_formulario_Email_2.length - 6 ||
        ficha_formulario_Email_2.indexOf('@') != ficha_formulario_Email_2.lastIndexOf('@') ||
        ficha_formulario_Email_2.lastIndexOf('.') == ficha_formulario_Email_2.length - 1 ||
        ficha_formulario_Email_2.lastIndexOf('.') < ficha_formulario_Email_2.indexOf('@') )
        alert('Repita el email válido');
    else if(getIdValue('pass')=='')
		alert('Ingrese  Password');
    else if(getIdValue('re_pass')=='')
		alert('Ingrese repita la Password ');
    else if(getIdValue('pregunta_secreta')=='')
		alert('Ingrese  Pregunta secreta');
    else if(getIdValue('respuesta_secreta')=='')
		alert('Ingrese Respuesta ');
    else if (p1 != p2)
      alert("Las Mails deben de coincidir");
    else if (p3 != p4)
      alert("Las Password deben de coincidir");
    else if(!document.getElementById("aceptar").checked)
      alert('Debe aceptar terminos y condiciones');
    else
    $('#mensaje').load('aplicaciones/usuarios/registro_empresas_accion.php',
    {nombre_contacto:getIdValue('nombre_contacto'),apellido_contacto:getIdValue('apellido_contacto'),
    cargo:getIdValue('cargo'),cod1:getIdValue('cod1'),telefono1:getIdValue('telefono1'),cod2:getIdValue('cod2'),
    telefono2:getIdValue('telefono2'),cellcod1:getIdValue('cellcod1'),cell1:getIdValue('cell1'),cellcod2:getIdValue('cellcod2'),
    cell2:getIdValue('cell2'),nombre_empresa:getIdValue('nombre_empresa'),rut_empresa:getIdValue('rut_empresa'),rut_dv_empresa:getIdValue('rut_dv_empresa'),
    razon_social:getIdValue('razon_social'),region:getIdValue('region'),provincia:getIdValue('provincia'),comuna:getIdValue('comuna'),
    giro:getIdValue('giro'),num_empleados:getIdValue('num_empleados'),direccion_comercial:getIdValue('direccion_comercial'),numero_direccion:getIdValue('numero_direccion'),
    mail_contacto:getIdValue('mail_contacto'),re_mail_contacto:getIdValue('re_mail_contacto'),pass:getIdValue('pass'),
    re_pass:getIdValue('re_pass'),solicitud_credito:getIdValue('solicitud_credito'),bancos:getIdValue('bancos'),
    cuenta_corriente:getIdValue('cuenta_corriente'),dias:getIdValue('dias'),mes:getIdValue('mes'),anno:getIdValue('anno'),
    monto_solicitado:getIdValue('monto_solicitado'),rut_autorizado:getIdValue('rut_autorizado'),nombre_autorizado:getIdValue('nombre'),
    apellido_autorizado:getIdValue('apellido_autorizado'),telefono_autorizado:getIdValue('telefono_autorizado'),archivo_firma:getIdValue('archivo_firma'),
    archivo_balance:getIdValue('archivo_balance'),archivo_iva:getIdValue('archivo_iva'),renta:getIdValue('renta'),
    archivo_renta:getIdValue('archivo_renta'),comentarios:getIdValue('comentarios'),pregunta_secreta:getIdValue('pregunta_secreta'),
    respuesta_secreta:getIdValue('respuesta_secreta'),enviar:'Enviar'})
}


function validar_formulario_distribuidores(){
var ficha_formulario_Email;
ficha_formulario_Email = getId( 'email' ).value.replace( /\s/g, '' );

    if(getIdValue('rut')=='' ||  getIdValue('dv')=='')
		alert('Ingrese un RUT');
	else if(!validarRut(getIdValue('rut'),getIdValue('dv')))
		return false;
    else if(getIdValue('razon_social')=='' )
		alert('Ingrese Razón Social ');
    else if(getIdValue('contacto')=='' )
		alert('Ingrese Contacto ');
    else if(getIdValue('region')=='' )
		alert('Ingrese Región ');
    else if( ficha_formulario_Email.indexOf('@') < 1 ||
        ficha_formulario_Email.indexOf('.') < 1 ||
        ficha_formulario_Email.indexOf('@') > ficha_formulario_Email.length - 6 ||
        ficha_formulario_Email.indexOf('@') != ficha_formulario_Email.lastIndexOf('@') ||
        ficha_formulario_Email.lastIndexOf('.') == ficha_formulario_Email.length - 1 ||
        ficha_formulario_Email.lastIndexOf('.') < ficha_formulario_Email.indexOf('@') )
        alert('Ingrese un email válido');
    else if(getIdValue('telefono')=='' )
		alert('Ingrese Telefono ');
    else

    $('#main_contenido').load('aplicaciones/usuarios/registro_distribuidores_accion.php',
    {razon_social:getIdValue('razon_social'),rut:getIdValue('rut'),dv:getIdValue('dv'),
    contacto:getIdValue('contacto'),region:getIdValue('region'),email:getIdValue('email'),
    telefono:getIdValue('telefono'),comentarios:getIdValue('comentarios'),enviar:'Enviar'})

}


function mostrar_div(div) {
div = document.getElementById(div);
div.style.display = "block";
}

function ocultar_div(div) {
div = document.getElementById(div);
div.style.display="none";
}

function centrar_div(div) {
div = document.getElementById(div);
div.style.marginLeft="200px";
}

function quitar_centrado_div(div) {
div = document.getElementById(div);
div.style.marginLeft="25px";
}


function muestra_oculta_div(checkbox)
{

    if(document.getElementById(checkbox).checked)
        mostrar_div('facturacion');
        else
        ocultar_div('facturacion');

}

function mostrar_ocultar_div(nombre_div,nombre_hidden)
{

    if(document.getElementById(nombre_hidden).value == 0){
       mostrar_div(nombre_div);
       document.getElementById(nombre_hidden).value = 1;
        }
        else{
         ocultar_div(nombre_div);
          document.getElementById(nombre_hidden).value =0;
        }

}

function isNumberKey(evt)
{
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
}

function mensaje(msg, numero)
{

    if(numero == 0)
    {
      alert(msg);
      location.href = "";
    }
    else if(numero == 1)
    {
      alert(msg);
    }
    else if(numero == 2)
    {
      if(confirm(msg))
      {
        location.href = "#aplicaciones/usuarios/recuperar_contrasena.php";
        //cargar_url_id2('aplicaciones/usuarios/recuperar_contrasena.php','main_contenido');
      }
    }
}

function validar_envio_producto(){

    if(getIdValue('atencion_a')=='')
        alert('Ingrese atencion a');
    else if(getIdValue('direccion_envio')=='' )
		alert('Ingrese Dirección de Envio ');
    else if(getIdValue('numero_direccion')=='')
		alert('Ingrese Numero de Dirección ');
    else if(getIdValue('region')=='')
		alert('Ingrese Región');
    else if(getIdValue('provincia')=='')
		alert('Ingrese Ciudad');
	else if(getIdValue('comuna')=='')
		alert('Ingrese Comuna');
    else {
        cargar_url_id2('aplicaciones/productos/envio_producto_accion.php?direccion_simple=si&atencion_a='+URLEnc(document.getElementById('atencion_a').value)+'&direccion_nueva='+URLEnc(document.getElementById('direccion_envio').value)+'&numero_nuevo='+URLEnc(document.getElementById('numero_direccion').value)+'&region_nueva='+document.getElementById('region').value+'&provincia_nueva='+document.getElementById('provincia').value+'&comuna_nueva='+document.getElementById('comuna').value+'&codigo_postal_nuevo='+URLEnc(document.getElementById('codigo_postal').value)+'&id_producto='+URLEnc(document.getElementById('id_producto').value)+'&id_moneda='+URLEnc(document.getElementById('moneda').value),'main_contenido');
    }

}

function validar_cantidad_minima(valor, cant_min, moneda, id_prod, cant_actual,cliente)
{
  var agregar = parseInt(getIdValue(valor));
  var total =  parseInt(agregar) + parseInt(cant_actual);
  var valor_hidden= 'h_'+valor;
  var error = 0;



  if(parseInt(cant_min) > total && error !=1){
      alert('La cantidad minima es '+cant_min );
      document.getElementById(valor).value = getIdValue(valor_hidden);
      error = 1;
    }


   if(error != 1)
     cargar_url_id2('aplicaciones/cotizacion/agregar_producto.php?cliente='+cliente+'&moneda='+moneda+'&id='+id_prod+'&n_agregar='+getIdValue(valor),'main_contenido');


}


function validar_cantidad_minima2(valor, cant_min, moneda, id_prod,cliente)
{
  var agregar = parseInt(getIdValue(valor));
  var total =  parseInt(agregar);
  var valor_hidden= 'h_'+valor;
  var error = 0;



  if(parseInt(cant_min) > total && error !=1){
      alert('La cantidad minima es '+cant_min );
      document.getElementById(valor).value = getIdValue(valor_hidden);
      error = 1;
    }


   if(error != 1){
     cargar_url_id2('aplicaciones/cotizacion/modificar_carro.php?cliente='+cliente+'&moneda='+moneda+'&id='+id_prod+'&n_total='+getIdValue(valor),'main_contenido');
   }
   else{
       document.getElementById(valor) = cant_max;
       cargar_url_id2('aplicaciones/cotizacion/modificar_carro.php?cliente='+cliente+'&moneda='+moneda+'&id='+id_prod+'&n_total='+cant_max,'main_contenido');
   }

}

function validar_cantidad_minima3(valor, cant_min, moneda, id_prod, cant_actual,idcliente)
{
  var agregar = parseInt(getIdValue(valor));
  var total =  parseInt(agregar) + parseInt(cant_actual);
  var valor_hidden= 'h_'+valor;
  var error = 0;


  if(parseInt(cant_min) > total && error !=1){
      alert('La cantidad minima es '+cant_min );
      document.getElementById(valor).value = getIdValue(valor_hidden);
      error = 1;
    }


   if(error != 1){
     cargar_url_id2('aplicaciones/cotizacion/agregar_producto.php?cliente='+idcliente+'&moneda='+moneda+'&id='+id_prod+'&n_agregar='+getIdValue(valor),'main_contenido');
     cargar_url_id2('aplicaciones/productos/'+idcliente+'_formulario_paso1.php','main_contenido');
   }

}

function validar_cantidad_minima4(valor, moneda, id_prod, cant_actual,idcliente)
{
  var agregar = parseInt(getIdValue(valor));
  var total =  parseInt(agregar) + parseInt(cant_actual);
  var valor_hidden= 'h_'+valor;
  var error = 0;

  cargar_url_id2('aplicaciones/cotizacion/agregar_producto.php?cliente='+idcliente+'&moneda='+moneda+'&id='+id_prod+'&n_agregar='+getIdValue(valor),'main_contenido');
  cargar_url_id2('aplicaciones/productos/'+idcliente+'_formulario_paso1.php','main_contenido');

}


function validar_newsletter(){
var ficha_formulario_Email;
ficha_formulario_Email = getId( 'correo_distribuidores' ).value.replace( /\s/g, '' );


    if(getIdValue('nombre_distribuidor')=='')
        alert('Ingrese Nombre');
    else if( ficha_formulario_Email.indexOf('@') < 1 ||
            ficha_formulario_Email.indexOf('.') < 1 ||
            ficha_formulario_Email.indexOf('@') > ficha_formulario_Email.length - 6 ||
            ficha_formulario_Email.indexOf('@') != ficha_formulario_Email.lastIndexOf('@') ||
            ficha_formulario_Email.lastIndexOf('.') == ficha_formulario_Email.length - 1 ||
            ficha_formulario_Email.lastIndexOf('.') < ficha_formulario_Email.indexOf('@') )
            alert('Ingrese un email válido');
    else if(!document.getElementById('confirmacion').checked)
		alert('Debe aceptar recibir noticias');
    else{
    $('#respuesta_registro_distribuidores').load('aplicaciones/productos/correo_newsletter_accion.php',
    {correo:getIdValue('correo_distribuidores'),nombre_distribuidor:getIdValue('nombre_distribuidor'),enviar:'Enviar'});
    }

}