﻿// JScript File
function mostrarOcultarTabla(nomCheck, nomTabla)
{
    check = document.getElementById(nomCheck);
    tabla=document.getElementById(nomTabla);
    if (check.checked)
    {
        tabla.style.display="";    
    }
    else
    {   
        tabla.style.display="none";
    }
}

function contarCaracteres(nomTexto, nomCantidad, maximo)
{
    texto=document.getElementById(nomTexto);
    cantidad=document.getElementById(nomCantidad);

    longitudTexto = texto.value.length;
    cantidad.value=(longitudTexto).toString();
   
    
}

function contarPalabras(nomTexto, nomCantidad, nomPreview, maximo) {
    texto=document.getElementById(nomTexto);
    cantidad=document.getElementById(nomCantidad);
    preview = document.getElementById(nomPreview);
    inicioBlanco = /^ /;
    finBlanco = / $/;
    variosBlancos = /[ ]+/g;
    
    textoPalabras = texto.value;
    
    textoPalabras = textoPalabras.replace(variosBlancos," ");    
    textoPalabras = textoPalabras.replace(inicioBlanco,"");
    textoPalabras = textoPalabras.replace(finBlanco,"");

    textoPalabrasDividido = textoPalabras.split(" ");
    if (textoPalabrasDividido.length>=parseInt(maximo))
    {
        textoPalabras="";
        //procesar el texto para eliminar las palabras de más
        for(i = 0; i<parseInt(maximo); i++)
        {
            textoPalabras +=  textoPalabrasDividido[i] + " ";
        }
        textoPalabras = textoPalabras.replace(finBlanco,"");
    }
    
    textoPalabrasDividido = textoPalabras.split(" ");
    
    if (textoPalabrasDividido.length>0)
    {
        cantidad.innerHTML = textoPalabrasDividido.length;
    }else
    {
        cantidad.innerHTML="0";
    }
    //Actualizar el valor para la previsualizacion
    if (textoPalabrasDividido.length>=parseInt(maximo))
    {
        texto.value = textoPalabras;    
    }

    preview.innerHTML=texto.value;
 }

function validarCampoTextoInfoAdicional(source, arguments){
    arguments.IsValid=true;
 	if((document.getElementById("ctl00_ContentPlaceHolder1_chk_InfoAdicional").checked) && (arguments.Value=="")){
	    arguments.IsValid=false;
    }
}

function validarCampoDropInfoAdicional(source, arguments){
    arguments.IsValid=true;
 	if((document.getElementById("ctl00_ContentPlaceHolder1_chk_InfoAdicional").checked) && (arguments.Value=="0")){
	    arguments.IsValid=false;
    }
}


function validarMinimoCaracteres(source, arguments){
    arguments.IsValid=true;
    minimo=document.getElementById("ctl00_ContentPlaceHolder1_hdd_MinimoCaracteres").value;
 	if(parseInt(arguments.Value) < parseInt(minimo)){
	    arguments.IsValid=false;
    }
}

function validarRangoSalario(source, arguments){
    arguments.IsValid=true;
    rangoSalario=document.getElementById("ctl00_ContentPlaceHolder1_ddl_PeriodoPago");
    maxSalario = document.getElementById("ctl00_ContentPlaceHolder1_ddl_RangoMaximo");
    if (rangoSalario)
    {
        if (rangoSalario.value=="0")
        {
            arguments.IsValid=false;
        }
    }
    if(arguments.Value=="0"){
	    arguments.IsValid=false;
    }
    else if(maxSalario.disabled==false)
    {
        if (maxSalario.value=="0")
        {
            arguments.IsValid=false;
        }
    }
}

function validarDiasTrabajoOferta(source, arguments)
{  
    arguments.IsValid=true;
    chk0= document.getElementById("ctl00_ContentPlaceHolder1_chbDias_0");
    chk1= document.getElementById("ctl00_ContentPlaceHolder1_chbDias_1");
    chk2= document.getElementById("ctl00_ContentPlaceHolder1_chbDias_2");
    chk3= document.getElementById("ctl00_ContentPlaceHolder1_chbDias_3");
    
    if (!chk0.checked && !chk1.checked && !chk2.checked && !chk3.checked)
        arguments.IsValid=false;
}

function validarTurnosOferta(source, arguments)
{  
    arguments.IsValid=true;
    chk0= document.getElementById("ctl00_ContentPlaceHolder1_chbTurnos_0");
    chk1= document.getElementById("ctl00_ContentPlaceHolder1_chbTurnos_1");
    chk2= document.getElementById("ctl00_ContentPlaceHolder1_chbTurnos_2");
    rbl0=document.getElementById("ctl00_ContentPlaceHolder1_rblTurnoRotativo_0");    
    
    if (!chk0.checked && !chk1.checked && !chk2.checked && rbl0.checked)
        arguments.IsValid=false;
}

function validarTelefonoPrincipal(source, arguments){
    arguments.IsValid=true;
 	if(arguments.Value=="" || document.getElementById("ctl00_ContentPlaceHolder1_ddl_TipoTelefonoPrincipal").value=="0"){
	    arguments.IsValid=false;
    }
}

function cambiarEstadoBotonRegistro(nomCheck, nomBoton)
{
    check=document.getElementById(nomCheck);
    boton=document.getElementById(nomBoton);
    boton.disabled=!check.checked;    
}

function validarImpresos(source, arguments)
{
    arguments.IsValid=false;
    if (document.getElementById("ctl00_ContentPlaceHolder1_PrevImpresos1_div_NoImpresos"))
    {
 	    if(document.getElementById("ctl00_ContentPlaceHolder1_PrevImpresos1_div_NoImpresos").style.display=="none"){
	        arguments.IsValid=true;
        }
    }else
    {
        arguments.IsValid=true;
    }
}
function checkExcluyente(chk1, chk2)
{
    principal = document.getElementById(chk1);
    secundario = document.getElementById(chk2);
    
    if(principal.checked)
    {
        secundario.checked=false;
    }
}
function checkExcluyente3(chk1, chk2,chk3)
{
    principal = document.getElementById(chk1);
    secundario = document.getElementById(chk2);
    tercero = document.getElementById(chk3);
    
    if(principal.checked)
    {
        secundario.checked=false;
        tercero.checked=false;
    }
}
