function muestra(tld){
    var obj = document.getElementById(tld);
    obj.style.display = "block";
}
function oculta(tld){
    var obj = document.getElementById(tld);
    obj.style.display ="none";
}

function RestaValorOculto(chk,ext)
{
   if(chk.checked==false)
   {
          b1 = document.getElementById("Periodo_Mirror_"+ext);
          b5 = document.getElementById("ValorTotalIva");
          b  = eval('PrecioMirror['+ b1.value +']')* b1.value;
          ValorTotalIvaFinal = ValorTotalIvaFinal - b;
          b5.value = FormatoPesos(ValorTotalIvaFinal);
    }
}


function CalcularTotales(Total)
{
        Suma = 0;
        for (i in PreciosDominioPeriodo)
        {
                Suma = Suma + (eval('PreciosDominioPeriodo[\''+i+'\']'));
        }
        ValorTotalIvaFinal = Suma;
        if (Total)
                Total.value = FormatoPesos(Suma);
}


function EscondeCajaURL(chk,ext)
{
  //capturamos los div
  a1 = document.getElementById('CajaURL_'+ext);
  a2 = document.getElementById('CajaMasking_'+ext);
  a3 = document.getElementById('CajaPeriodoRedir_'+ext);
  a4 = document.getElementById('CajaValorRedir_'+ext);
  a5 = document.getElementById('CajaValorFinalMirror_'+ext);
  for(i=1;i<=5;i++)
  {
          r=eval('a'+i);
          if(chk.checked==true)
          {
                if((eval('a'+i)!=a4)&&(eval('a'+i)!=a3))
                r.style.display='block';
          }
          else
          {
                if((eval('a'+i)!=a4)&&(eval('a'+i)!=a3))
                r.style.display='none';
          }
  }
  if(chk.checked==true)
  CalculaValorAnio(ext)
}


function CalculaValorAnio(ext)
{
  //capuramos los objetos del form
  b1 = document.getElementById("Periodo_Mirror_"+ext);
  b2 = document.getElementById("ValorMirrorPorAnio_"+ext);
  b3 = document.getElementById("ValorFinalMirror_"+ext);
  b4 = document.getElementById("periodo_"+ext);
  b5 = document.getElementById("ValorTotalIva");
  b2.value = FormatoPesos(PrecioMirror[b1.value]);
  b3.value = FormatoPesos(PrecioMirror[b1.value] * b1.value);

  a = eval('Precios_'+ ext +'['+ b4.value +']')* b4.value;
  b = eval('PrecioMirror['+ b1.value +']')* b1.value;
  PreciosDominioPeriodo[ext] = a + b;
  CalcularTotales(b5);
}


function AgregarDominio(chk,sel,txt,valor)
{
        b3 = document.getElementById('ValorDominio_'+chk.value+'_PorAnio');
        b4 = document.getElementById("CLP"+chk.value);
        ahorro = document.getElementById('Ahorro_'+chk.value);
        if (chk.checked)
        {       //se acaba de marcar
                b3.style.color='#000000';
                b4.style.color='#000000';
                sel.disabled=false;
                txt.value=FormatoPesos(eval('Precios_'+chk.value+'['+sel.value+'] * sel.value ;'));
                eval('PreciosDominioPeriodo[\''+chk.value+'\']='+'Precios_'+chk.value+'['+sel.value+'] * sel.value ;');
                r = FormatoPesos(eval('Precios_'+chk.value+'['+sel.value+'];'));
                valor.value = r;
                ahorro.value = FormatoPesos(eval('Precios_'+chk.value+'[1] * sel.value ;')-eval('Precios_'+chk.value+'['+sel.value+'] * sel.value ;'))
                if((chk.value=='info')||(chk.value=='org'))
                ahorro.value = FormatoPesos(eval('12000 * sel.value ;')-eval('Precios_'+chk.value+'['+sel.value+'] * sel.value ;'))

        }
        else
        {
                b3.style.color='#b0d6ff';
                b4.style.color='#ffffff';
                sel.disabled=true;
                txt.value='';
                ahorro.value = '';
                eval('PreciosDominioPeriodo[\''+chk.value+'\']=0;');
        }
        CalcularTotales(document.dominios.total_iva);
}


function FormatoPesos(num)
{
        separador_miles='.';
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
                num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
                cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        {
                num = num.substring(0,num.length-(4*i+3))+separador_miles+
                num.substring(num.length-(4*i+3));
        }
        return (((sign)?'':'-') + num );
}


function ValidaDatos(total)
{
        if (total==0)
        {
                return false;
        }
        else
        {
                return true;
        }
}


function VerificarCondiciones(chk_condiciones)
{
        if (!chk_condiciones.checked)
        {
                alert('Para realizar el pago debe aceptar los términos legales.');
                return false;
        }
        else
        {
                return true;
        }
}
