﻿// JScript File

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 valCI(source, args) {
     if (validaCedula(args.Value) == true)
     { args.IsValid = true; }
     else
     { args.IsValid = false; }
 }

 function validaCedula(cedula) {
     lv_prov = Number(cedula.substring(0, 2));

     if (lv_prov >= 1 && lv_prov <= 22) {
         lv_numced = cedula;
         ll_TenDig = Number(cedula.substring(9));
         ll_sum = 0;

         ll_Cnt = 0;
         ll_CntPos = 0;
         while (ll_CntPos < 9) {
             ll_CntPos = 2 * ll_Cnt + 1;
             lv_StrNum = lv_numced.substring(ll_CntPos - 1, ll_CntPos);
             ll_multi = Number(lv_StrNum) * 2;
             if (ll_multi >= 10)
                 ll_multi = 1 + (ll_multi % 10);
             ll_sum += ll_multi;
             ll_Cnt += 1;
         }

         ll_Cnt = 1;
         ll_CntPos = 1;
         while (ll_CntPos < 8) {
             ll_CntPos = 2 * ll_Cnt;
             lv_StrNum = lv_numced.substring(ll_CntPos - 1, ll_CntPos);
             ll_sum += Number(lv_StrNum);
             ll_Cnt += 1;
         }

         ll_cociente = Math.floor(ll_sum / 10);
         ll_decena = (ll_cociente + 1) * 10;
         ll_verificador = ll_decena - ll_sum;

         if (ll_verificador == 10)
             ll_verificador = 0;
         if (ll_verificador == ll_TenDig)
             return true;
         else

             return false;
     } else {

         return false;
     }
 }

 function soloLetras(e) {
     tecla = (document.all) ? e.keyCode : e.which;
     if (tecla >= 65 && tecla <= 90) return true;
     if (tecla >= 97 && tecla <= 122) return true;
     if (tecla == 164 || tecla == 165 || tecla == 32 || tecla == 0 || tecla == 8 || tecla==241) return true;
     return false;
 }
 function soloNumeros(e) {
     tecla = (document.all) ? e.keyCode : e.which;
     if (tecla == 8) return true;
     patron = /\d/;
     return patron.test(String.fromCharCode(tecla));
 }


 function textCounter(maxLength, textBox, txtLimitCounter) {
     var maxlimit = maxLength;
     var content = document.getElementById(textBox);
     if (content.value.length > maxlimit) // if too long...trim it!
         content.value = content.value.substring(0, maxlimit);
     // otherwise, update 'characters left' counter
     else
         document.getElementById(txtLimitCounter).value = maxlimit - content.value.length;

 }

 function textCounterLimitOnly(maxLength, textBox) {
     var maxlimit = maxLength;
     var content = document.getElementById(textBox);
     if (content.value.length > maxlimit) // if too long...trim it!
     {
         content.value = content.value.substring(0, maxlimit);
         /*alert(maxlimit);
         alert(content.value.length);*/
     }

     alert('test');
         
     // otherwise, update 'characters left' counter
     /*else
         document.getElementById(txtLimitCounter).value = maxlimit - content.value.length;*/

 }
 
 
 
 
 function verporprovinciapreseleccionados(cod)
{
	document.getElementById('provincia1').style.display='none';
	document.getElementById('provincia2').style.display='none';
	document.getElementById('provincia3').style.display='none';
	document.getElementById('provincia4').style.display='none';
	document.getElementById('provincia5').style.display='none';
	document.getElementById('provincia6').style.display='none';
	document.getElementById('provincia7').style.display='none';
	document.getElementById('provincia8').style.display='none';
	document.getElementById('provincia9').style.display='none';
	document.getElementById('provincia10').style.display='none';
	document.getElementById('provincia11').style.display='none';
	document.getElementById('provincia12').style.display='none';
	document.getElementById('provincia13').style.display='none';
	document.getElementById('provincia14').style.display='none';
	document.getElementById('provincia15').style.display='none';
	document.getElementById('provincia16').style.display='none';
	document.getElementById('provincia17').style.display='none';
	document.getElementById('provincia18').style.display='none';
	document.getElementById('provincia19').style.display='none';
	document.getElementById('provincia20').style.display='none';
	document.getElementById('provincia21').style.display='none';
	document.getElementById('provincia22').style.display='none';
	document.getElementById('provincia23').style.display='none';
	document.getElementById('provincia24').style.display='none';
if(cod==1){document.getElementById('provincia1').style.display='block';}
if(cod==2){document.getElementById('provincia2').style.display='block';}
if(cod==3){document.getElementById('provincia3').style.display='block';}
if(cod==4){document.getElementById('provincia4').style.display='block';}
if(cod==5){document.getElementById('provincia5').style.display='block';}
if(cod==6){document.getElementById('provincia6').style.display='block';}
if(cod==7){document.getElementById('provincia7').style.display='block';}
if(cod==8){document.getElementById('provincia8').style.display='block';}
if(cod==9){document.getElementById('provincia9').style.display='block';}
if(cod==10){document.getElementById('provincia10').style.display='block';}
if(cod==11){document.getElementById('provincia11').style.display='block';}
if(cod==12){document.getElementById('provincia12').style.display='block';}
if(cod==13){document.getElementById('provincia13').style.display='block';}
if(cod==14){document.getElementById('provincia14').style.display='block';}
if(cod==15){document.getElementById('provincia15').style.display='block';}
if(cod==16){document.getElementById('provincia16').style.display='block';}
if(cod==17){document.getElementById('provincia17').style.display='block';}
if(cod==18){document.getElementById('provincia18').style.display='block';}
if(cod==19){document.getElementById('provincia19').style.display='block';}
if(cod==20){document.getElementById('provincia20').style.display='block';}
if(cod==21){document.getElementById('provincia21').style.display='block';}
if(cod==22){document.getElementById('provincia22').style.display='block';}
if(cod==23){document.getElementById('provincia23').style.display='block';}
if(cod==24){document.getElementById('provincia24').style.display='block';}
}
 
 
 