﻿// JScript File
// IE6 Validation and if it is true must show the upgrade message.
$(document).ready(function() {
    var useragent = navigator.userAgent.toLowerCase();
    var isMsIe6 = /msie 6./.test(useragent) && !/opera/.test(useragent);
    if (isMsIe6) { window.onload = function() { e("/common/images/") } }
});


function GetValueFromRadioButton(element)
{
   var returnValue;
   var rbl = document.getElementById(element);
   var options = rbl.getElementsByTagName('input');
    
    for (var i=0; i < options.length; i++)
    {
        if (options[i].checked)
        {
         
            returnValue = options[i].value;
            break;
        }
    }

    return returnValue;
}

function fixMoney(fld,sep)
{ // monetary field check
  if(!fld.value.length||fld.disabled) return true; // blank fields are the domain of requireValue 
  var val= fld.value;
  if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
  if(val.indexOf('$') == 0)
    val= parseFloat(val.substring(1,40));
  else
    val= parseFloat(val);
  if(isNaN(val))
  { // parse error 
   alert("El campo '" + fieldname(fld) +  "' debe ser un valor monetario.");
    return false;
  }
  var sign= ( val < 0 ? '-': '' );
  val= Number(Math.round(Math.abs(val)*100)).toString();
  while(val.length < 2) val= '0'+val;
  var len= val.length;
  val= sign + ( len == 2 ? '0' : val.substring(0,len-2) ) + '.' + val.substring(len-2,len+1);
  fld.value= val;
  return true;
}

function fixInt(fld,sep)
{ // integer check/complainer 
  if(!fld.value.length||fld.disabled) return true; // blank fields are the domain of requireValue 
  var val= fld.value;
  if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
  val= parseInt(val);
  if(isNaN(val))
  { // parse error 
     alert("El campo '" + fieldname(fld) +  "' debe ser un valor numérico.");
    return false;
  }
  fld.value= val;
  return true;
}

function fieldname(fld)
{ // get the field label text or name
  if(fld.id && document.getElementsByTagName)
  {
    for(var i= 0, lbl= document.getElementsByTagName('LABEL'); i < lbl.length; i++)
      if(lbl[i].htmlFor==fld.id) return lbl[i].nodeValue||lbl[i].textContent||lbl[i].innerText;
    for(var i= 0, lbl= document.getElementsByTagName('label'); i < lbl.length; i++)
      if(lbl[i].htmlFor==fld.id) return lbl[i].nodeValue||lbl[i].textContent||lbl[i].innerText;
  }
  return fld.name;
}

function OpenIMC()
{
  window.open('/Common/Themes/Tonisa/html/calculadoraImc.html','CalculadoraIMC','width=605,height=555,scrollbars=no,status=yes,resizable=no,titlebar=yes,toolbar=no');
}

function SendToFriend(pageId)
{
     window.open('/utility/sendtofriend.aspx?p='+ pageId,'BancaEnLinea','width=540,height=550,scrollbars=yes,status=yes,resizable=yes,titlebar=yes,toolbar=no');
 }

 function PopulateDaysCombo(sourceYear, month, target) {
     var elem = document.getElementById(sourceYear);
     var year = elem.options[elem.selectedIndex].value;
     var days = 0;
     if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
        days = 31;
     }
     else {
         if (month != 2)
            days = 30;
         else {
            if (isLeapYear(year)) 
                days = 29; 
            else days = 28;
         }
     }
     elem = document.getElementById(target);
     elem.options.length = 0;
     for (i = 0; i < days; i++) {
         elem.options[i] = new Option(i + 1, i + 1);
     }
     
 }

 function isLeapYear(Year) {
     if (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0)) {
         return (true);
     } else { return (false); }
 }

 function characters() {
     if (event.keyCode > 45 && event.keyCode < 58) event.returnValue = false;
 }

 function number() {
     tecla = (document.all) ? e.keyCode : e.which;
     if (tecla < 45 || tecla > 57) event.returnValue = false;
 }

 function validar(e) {
     tecla = (document.all) ? e.keyCode : e.which;
     if (tecla == 8 || tecla == 0) return true;
     patron = /[A-Za-zñÑ\s]/;
     return patron.test(String.fromCharCode(tecla));
 }
  
 function OpenTermsConditions(pageId) {
     window.open('/utility/Terms.aspx?p=' + pageId, 'CerveceriaNacional', 'width=650,height=500,scrollbars=yes,status=yes,resizable=no,titlebar=yes,toolbar=no');
 }

 var letters = 'ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyz ';
 var numbers = '1234567890';
 var email = ' ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyz1234567890@_-.';
 var address = ' ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyz1234567890';
 var alfa = 'ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyz1234567890';


 function alpha(e, allow) {
     var k;
     k = document.all ? parseInt(e.keyCode) : parseInt(e.which);

     if (k == 8 || k == 0 || k == 13)
         return (true)
     else {
         return (allow.indexOf(String.fromCharCode(k)) != -1);
     }
 }
