﻿// JScript File

function GetCheckedItems(grid, columNumber)
    {
     
      var checkedItems = new Array();
      var gridItem;
      var itemIndex = 0;
      while(gridItem = grid.get_table().getRow(itemIndex))
      {
        if(gridItem.get_cells()[0].get_value())
        {
          checkedItems[checkedItems.length] = gridItem;
        
        }
        
        itemIndex++;
      }
      
      return checkedItems;
     
      
    }
function citiesDiv(id){
if (id !="0"){document.getElementById('guayaquilDiv').style.display="none";document.getElementById('quitoDiv').style.display="none";document.getElementById('mantaDiv').style.display="none";document.getElementById('portoviejoDiv').style.display="none";document.getElementById('cuencaDiv').style.display="none";document.getElementById('libertadDiv').style.display="none";document.getElementById('ibarraDiv').style.display="none";document.getElementById('milagroDiv').style.display="none";document.getElementById('bahiaDiv').style.display="none";document.getElementById('ambatoDiv').style.display="none";document.getElementById('lojadiv').style.display="none";document.getElementById(id).style.display="block";	}}
function GetValueFromCheckBoxList(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].getAttribute('projectId') + ",";
        }
    }
    if (returnValue.lenght > 0)
        returnValue = returnValue.substring(returnValue.lenght - 1, 1);
    return returnValue;
}


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 ValidateInt(field, qty)
{
     if(!field.value.length||field.disabled) return true;
     var val = field.value;
     var valArray= val.split(",");
     var reg= new RegExp("^\\d{"+ qty + "," + qty +"}$");
     
     var errorsArray =[];
     for (var i=0; i<valArray.length; i++) 
     {
        if(!reg.test(valArray[i]))
            errorsArray.push(false);
        else
          errorsArray.push(true);
     }
     
     if(errorsArray.indexOf(false) > -1)
        alert("Todos los boletos deben tener " + qty + " números exactamente");
     
}

function requireValue(fld)
{ // disallow a blank field
  if(fld.disabled) return true;
  if(!fld.value.length)
  { alert("El campo "+fieldname(fld)+" es requerido."); 
  return false; }
  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 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 currencyFormat(fld, milSep, decSep, e,limite,decimales)
		 { 
			if (fld.value.length>limite)
				return false;
			var sep = 0; 
			var key = ''; 
			var i = j = 0; 
			var len = len2 = 0; 
			var strCheck = '0123456789'; 
			var aux = aux2 = ''; 
			var whichCode = e.keyCode; // (window.Event) ? e.which : e.keyCode;
			
			if (whichCode==0)
			    whichCode = e.which;
						
			if (whichCode == 13) return true; // Enter 
			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; 
		}

function formatCurrency(num) {
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))+'.'+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$ ' + num + ',' + cents);
}

function validar(e) {

  /*  if(document.all) {
        alert("document.all");
        if(e.keyCode == 8) {return true;}
           // e.returnValue=true;
          
           // e.cancel=false;
            patron = /\d/;
            return patron.test(String.fromCharCode(e.keyCode));
        
    }

    else if(document.getElementById) {
        alert("document.getElementById");
        if(e.wich==8) {  alert("true"); return true;}
            //e.returnValue=true;
            //e.cancel=false;
            
            patron = /\d/;
            alert(patron.test(String.fromCharCode(e.wich)));
            return patron.test(String.fromCharCode(e.wich));
        
    }

    else if (document.layers){
         alert("document.layers");
        if(e.wich ==8){return true;}
            //e.returnValue=true;
             
            //e.cancel=false;
            patron = /\d/;
            return patron.test(String.fromCharCode(e.wich));
        
        
    }
    */
    
         tecla = (document.all)?e.keyCode:e.which;
        if (tecla==8) return true;
        patron = /\d/;
        return patron.test(String.fromCharCode(tecla));
}

function nextTab(tecla, elem, clase) {
        var index = elem.tabIndex;
        for (i=0;i<document.forms[0].elements.length;i++)
            {
                if (document.forms[0].elements[i].tabIndex == index + 1)
                    document.forms[0].elements[i].focus();
            }
        elem.value = String.fromCharCode(tecla);
}
function vermas(cod) {
    document.getElementById('contenedor1').style.display = 'none'; document.getElementById('contenedor2').style.display = 'none'; document.getElementById('contenedor3').style.display = 'none'; document.getElementById('contenedor4').style.display = 'none'; document.getElementById('contenedor5').style.display = 'none'; document.getElementById('contenedor6').style.display = 'none'; document.getElementById('contenedor7').style.display = 'none'; document.getElementById('contenedor8').style.display = 'none'; document.getElementById('contenedor9').style.display = 'none'; if (cod == 1) { document.getElementById('contenedor1').style.display = 'block'; }
    if (cod == 2) { document.getElementById('contenedor2').style.display = 'block'; }
    if (cod == 3) { document.getElementById('contenedor3').style.display = 'block'; }
    if (cod == 4) { document.getElementById('contenedor4').style.display = 'block'; }
    if (cod == 5) { document.getElementById('contenedor5').style.display = 'block'; }
    if (cod == 6) { document.getElementById('contenedor6').style.display = 'block'; }
    if (cod == 7) { document.getElementById('contenedor7').style.display = 'block'; }
    if (cod == 8) { document.getElementById('contenedor8').style.display = 'block'; }
    if (cod == 9) { document.getElementById('contenedor9').style.display = 'block'; } 
}
function ganadoresganaganaVER(cod) {
    if (cod == 1) { document.getElementById('titulocontenedor1A').style.display = 'none'; document.getElementById('titulocontenedor1B').style.display = 'block'; document.getElementById('contenedor1').style.display = 'block'; }
    if (cod == 2) { document.getElementById('titulocontenedor2A').style.display = 'none'; document.getElementById('titulocontenedor2B').style.display = 'block'; document.getElementById('contenedor2').style.display = 'block'; }
    if (cod == 3) { document.getElementById('titulocontenedor3A').style.display = 'none'; document.getElementById('titulocontenedor3B').style.display = 'block'; document.getElementById('contenedor3').style.display = 'block'; }
    if (cod == 4) { document.getElementById('titulocontenedor4A').style.display = 'none'; document.getElementById('titulocontenedor4B').style.display = 'block'; document.getElementById('contenedor4').style.display = 'block'; } 
}
function ganadoresganaganaOCULTAR(id) {
    if (id == 1) { document.getElementById('titulocontenedor1A').style.display = 'block'; document.getElementById('titulocontenedor1B').style.display = 'none'; document.getElementById('contenedor1').style.display = 'none'; }
    if (id == 2) { document.getElementById('titulocontenedor2A').style.display = 'block'; document.getElementById('titulocontenedor2B').style.display = 'none'; document.getElementById('contenedor2').style.display = 'none'; }
    if (id == 3) { document.getElementById('titulocontenedor3A').style.display = 'block'; document.getElementById('titulocontenedor3B').style.display = 'none'; document.getElementById('contenedor3').style.display = 'none'; }
    if (id == 4) { document.getElementById('titulocontenedor4A').style.display = 'block'; document.getElementById('titulocontenedor4B').style.display = 'none'; document.getElementById('contenedor4').style.display = 'none'; } 
}

dn = "WWW.LOTERIA.COM.EC";
lang = "es";
aff = "ESignSAWSCSecureServer";
tpt = "transparent";
vrsn_style = "WW";
splash_url = "https://seal.verisign.com";
seal_url = "https://seal.verisign.com";
u1 = splash_url + "/splash?form_file=fdf/splash.fdf&dn=" + dn + "&lang=" + lang;
u2 = seal_url + "/getseal?at=0&&sealid=2&dn=" + dn + "&aff=" + aff + "&lang=" + lang;
u3 = seal_url + "/getseal?at=1&&sealid=2&dn=" + dn + "&aff=" + aff + "&lang=" + lang;
function vrsn_splash() {
    tbar = "location=yes,status=yes,resizable=yes,scrollbars=yes,width=560,height=500";
    sw = window.open(u1, 'VRSN_Splash', tbar);
    sw.focus();
}


function ShowBlock(id) {
    jQuery("#" + id).slideToggle(300);
}