﻿function currencyFormat(fld, milSep, decSep, e,decimales)
		 { 
			
			var sep = 0; 
			var key = ''; 
			var i = j = 0; 
			var len = len2 = 0; 
			var strCheck = '0123456789'; 
			var aux = aux2 = ''; 
                        var limite = 8;
			var whichCode = e.keyCode; // (window.Event) ? e.which : e.keyCode;
			
			if (whichCode==0)
			    whichCode = e.which;
						
			if (whichCode == 13) return true; // Enter 
			if (whichCode == 8) return true; //Delete
			
			if (fld.value.length>limite)
				return false;
			milSep='';
			key = String.fromCharCode(whichCode); // Get key value from key code 
			if (strCheck.indexOf(key) == -1) return false; // Not a valid key 
			len = fld.value.length; 
			for(i = 0; i < len; i++) 
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; 
			aux = ''; 
			for(; i < len; i++) 
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); 
			aux += key; 
			len = aux.length; 
			if(decimales==2)
			{
				if (len == 0) fld.value = ''; 
				if (len == 1) fld.value = '0'+ decSep + '0' + aux; 
				if (len == 2) fld.value = '0'+ decSep + aux; 
				if (len > 2) 
				{ 
					aux2 = ''; 
					for (j = 0, i = len - 3; i >= 0; i--) { 
						if (j == 3) { 
							aux2 += milSep; 
							j = 0; 
						} 
						aux2 += aux.charAt(i); 
						j++; 
					} 
					fld.value = ''; 
					len2 = aux2.length; 
					for (i = len2 - 1; i >= 0; i--) 
					fld.value += aux2.charAt(i); 
					fld.value += decSep + aux.substr(len - 2, len); 
				}
			} 
			else
			{
				if (len == 0) fld.value = ''; 
				if (len == 1) fld.value = '0'+ decSep + '000' + aux; 
				if (len == 2) fld.value = '0'+ decSep + '00' + aux; 
				if (len == 3) fld.value = '0'+ decSep + '0' + aux; 
				if (len == 4) fld.value = '0'+ decSep + aux;
				if (len > 4) {
					aux2 = ''; 
					for (j = 0, i = len - 5; i >= 0; i--) { 
						if (j == 3) { 
							aux2 += milSep; 
							j = 0; 
						} 
						aux2 += aux.charAt(i); 
						j++; 
					} 
					fld.value = ''; 
					len2 = aux2.length; 
					for (i = len2 - 1; i >= 0; i--) 
					fld.value += aux2.charAt(i); 
					fld.value += decSep + aux.substr(len - 4, len); 
				}
			}
			return false; 
		}
// 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 redondear(cantidad, decimales) {
            var cantidad = parseFloat(cantidad);
                var decimales = parseFloat(decimales);
        decimales = (!decimales ? 2 : decimales);
        return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
    }

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 OpenBancaEnlinea()
{
  window.open('/BancaEnlinea','BancaEnLinea','width=860,height=610,scrollbars=yes,status=yes,resizable=yes,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');
}


