﻿// JScript File

function changeMenuIn(id)
{
  document.getElementById(id).setAttribute("src", "img/transMenuIn.gif");
}

function changeMenuOut(id)
{
  document.getElementById(id).setAttribute("src", "img/transMenu.gif");
}

function chkCheckAll(id, control)
{
  if(id == 'Todas' || id == 'Todos')
  {
    var formulario = eval(document.forms[0]); 
    for (var i=0, len=formulario.elements.length; i<len ; i++)  
    {  
      if (formulario.elements[i].type == "checkbox" )  
      {
        if(formulario.elements[i].name != control + '$0' && formulario.elements[i].name.indexOf(control) != -1)
        {
          formulario.elements[i].checked = formulario.elements[control + '$0'].checked;
        }
      }  
    }
  } 
}

function ChangeMoneda()
{
  var euro = 166.386;
  var valor = document.getElementById('txtPrecio').value.replace('.', '').replace('.','').replace('.','').replace('.','');
  var objeto;
  var textoFinal='';
  if(valor.indexOf('/mes') != -1)
  {
    textoFinal = '/mes';
  }
  if(valor.indexOf('euros') != -1)
  {
    objeto = Math.round(parseInt(valor) * euro);
    document.getElementById('txtPrecio').value = formatNmb(String(objeto)) + " ptas" + textoFinal;
    if(document.all)
    {
      document.getElementById('hlkVerPts').innerText = 'Ver euros';
    }
    else
    {
      document.getElementById('hlkVerPts').textContent  = 'Ver euros';
    }
  }
  else
  {
    objeto = Math.round(parseInt(valor) * 100 / euro / 100);
    document.getElementById('txtPrecio').value = formatNmb(String(objeto)) + " euros" + textoFinal;
    if(document.all)
    {
      document.getElementById('hlkVerPts').innerText = 'Ver ptas';
    }
    else
    {
      document.getElementById('hlkVerPts').textContent  = 'Ver ptas';
    }
  }
}

function formatNmb(nNmb)
{
    var sRes = "";
    for (var j, i = nNmb.length - 1, j = 0; i >= 0; i--, j++)
    {
      sRes = nNmb.charAt(i) + ((j > 0) && (j % 3 == 0)? ".": "") + sRes;
    }
    return sRes;
} 

