
function siguiente(num,total,cat,t){
if (num >= (total-1)){
alert("Esta visualizando el ultimo registro del listado, realice otra busqueda si desea ver mas documentos");
}else{
num_pedido=num+1;
location="/Index/siguiente/id/"+num_pedido+"/total/"+total+"/cat/"+cat+"/t/"+t;
}
}
function anterior(num,total,cat,t){
if (num <=0){
alert("Esta visualizando el primer registro del listado, realice otra busqueda si desea ver mas documentos");
}else{
num_pedido=num-1;
location="/Index/siguiente/id/"+num_pedido+"/total/"+total+"/cat/"+cat+"/t/"+t;
}
}






function buscar(formu){
puntos=formu.puntos.value;
if (!esNumerico(puntos)){
alert ("El campo puntos no es numérico, tecleelo de nuevo");
formu.puntos.value="";
}else{
formu.submit();
}

}




function cambiaImagenFicha(ruta){
$("#imagen_ficha").attr("src",ruta);
}




function abreMasInfo(id){
label1="M&aacute;s informaci&oacute;n";
width1=651;
height1=416;
close1=1;
resize1=1;
pagina1="/Index/vermasinfo/id/"+id;

  				$().newPopup({
				id:'popup_info',
				label:label1,
				width:width1,
				height:height1,
				close:close1,
				resize:resize1,
				iframe:pagina1
			});             



}


function abreCanjealo(id){
label1="Canjear";
width1=651;
height1=416;
close1=1;
resize1=1;
pagina1="/Index/vercanjealo/id/"+id;

  				$().newPopup({
				id:'popup_info',
				label:label1,
				width:width1,
				height:height1,
				close:close1,
				resize:resize1,
				iframe:pagina1
			});             



}

function abreMasPuntos(id){
label1="C&oacute;mo conseguir puntos";
width1=651;
height1=416;
close1=1;
resize1=1;
pagina1="/Index/vermaspuntos/id/"+id;

  				$().newPopup({
				id:'popup_info',
				label:label1,
				width:width1,
				height:height1,
				close:close1,
				resize:resize1,
				iframe:pagina1
			});             



}





////////////////////////VALIDACION ESTANDAR

function esEmail(email){
 var sLen = email.length; var i=0; var pasaPrimero= true;
 var chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-@';
 while (i < sLen && pasaPrimero) {
   c=email.charAt(i);
   if (!(chrs.indexOf(c)>=0 || (c=='_' && i>0))) pasaPrimero=false; i++;
 }
 var emailFilter=/^.+@.+\..{2,4}$/;
 if (!(emailFilter.test(email)) || !pasaPrimero) {
   return false;
 }
 return true;
}

function esEntero(dato){
if (esNumerico(dato) && parseInt(dato)==dato){
	return true;
}else{
	return false;
}
}

function esNumerico(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function esNIF(nif){
nif=nif.toUpperCase() ;
  var check = true,longitud,numero,letra,index;
  var letrasNIF = new Array('T','R','W','A','G','M','Y','F','P','D','X','B','N','J','Z','S','Q','V','H','L','C','K','E','T');
  longitud=nif.length;
  numero = nif.substring(0,longitud-1);
  letra = nif.substring(longitud-1,longitud);
  numero=TrimLeft(numero,"0");
	if (parseInt(numero) == 0)
	  check = false;
	index = (parseInt(numero)) % 23;
	if (letra.toUpperCase() != letrasNIF[index])
	  check = false;
	return check;
}

function TrimLeft( str,caracter ) {
var resultStr = "";
var i = len = 0;
// Return immediately if an invalid value was passed in
if (str+"" == "undefined" || str == null) 
return null;
// Make sure the argument is a string
str += "";
if (str.length == 0) 
resultStr = "";
else { 
// Loop through string starting at the beginning as long as there
// are spaces.
// len = str.length - 1;
len = str.length;

while ((i <= len) && (str.charAt(i) == caracter))
i++;
// When the loop is done, we're sitting at the first non-space char,
// so return that char plus the remaining chars of the string.
resultStr = str.substring(i, len);
}
return resultStr;
}


function esDocumento(documento,tipo){
		switch (tipo){
			case 'NIF': return esNIF(documento);
										break;
			case 'NIE': return esNIE(documento);
										break;
			case 'CIF': return esCIF(documento);
										break;
			case 'Pasaporte': return documento.length>0;
								break;
			default: return false;
			                   break;					
		}

}

function esCIF(texto){
        var pares = 0;
        var impares = 0;
        var suma;
        var ultima;
        var unumero;
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
        var xxx;
        texto = texto.toUpperCase();
        var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g);
         if (!regular.exec(texto)) return false;
         ultima = texto.substr(8,1);
         for (var cont = 1 ; cont < 7 ; cont ++){
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
             pares += parseInt(texto.substr(cont,1));
         }
         xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
         impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
         suma = (pares + impares).toString();
         unumero = parseInt(suma.substr(suma.length - 1, 1));
         unumero = (10 - unumero).toString();
         if(unumero == 10) unumero = 0;
         if ((ultima == unumero) || (ultima == uletra[unumero]))
             return true;
         else
             return false;
}

function esNIF(nif){
nif=nif.toUpperCase() ;
  var check = true,longitud,numero,letra,index;
  var letrasNIF = new Array('T','R','W','A','G','M','Y','F','P','D','X','B','N','J','Z','S','Q','V','H','L','C','K','E','T');
  longitud=nif.length;
  numero = nif.substring(0,longitud-1);
  letra = nif.substring(longitud-1,longitud);
  numero=TrimLeft(numero,"0");
	if (parseInt(numero) == 0)
	  check = false;
	index = (parseInt(numero)) % 23;
	if (letra.toUpperCase() != letrasNIF[index])
	  check = false;
	return check;
}

function esNIE(nie){
	var check = true,longitud,numero,letra,index;
	var letrasNIF = new Array('T','R','W','A','G','M','Y','F','P','D','X','B','N','J','Z','S','Q','V','H','L','C','K','E','T');
	longitud=nie.length;
	equis=nie.substring(0,1);
	nie = nie.substring(1,longitud);
	longitud--;
	numero = nie.substring(0,longitud-1);
	letra = nie.substring(longitud-1,longitud);
	if (parseInt(numero) == 0)
	  check = false;
	index = (parseInt(numero)) % 23;
	if (letra.toUpperCase() != letrasNIF[index])
	  check = false;
	if (equis.toUpperCase() != "X")
	  check=false;

	return check;
}


/////////////formatos

function oNumero(numero)
{
//Propiedades
this.valor = numero || 0
this.dec = -1;
//Métodos
this.formato = numFormat;
this.ponValor = ponValor;
this.caracterDecimal='.';
this.caracterMiles=',';
//Definición de los métodos
function ponValor(cad)
{

if (cad =='-' || cad=='+') return
if (cad.length ==0) return
if (cad.indexOf(this.caracterDecimal) >=0)
    this.valor = parseFloat(cad);
else
    this.valor = parseInt(cad);
}

function numFormat(dec, miles)
{
var num = this.valor, signo=3, expr;
var cad = ""+this.valor;
var ceros = "", pos, pdec, i;
for (i=0; i < dec; i++)
ceros += '0';
pos = cad.indexOf(this.caracterDecimal)
if (pos < 0)
    cad = cad+this.caracterDecimal+ceros;
else
    {
    pdec = cad.length - pos -1;
    if (pdec <= dec)
        {
        for (i=0; i< (dec-pdec); i++)
            cad += '0';
        }
    else
        {
        num = num*Math.pow(10, dec);
        num = Math.round(num);
        num = num/Math.pow(10, dec);
        cad = new String(num);
        }
    }
pos = cad.indexOf(this.caracterDecimal)
if (pos < 0) pos = cad.lentgh
if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+')
       signo = 4;
if (miles && pos > signo)
    do{
        expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
        cad.match(expr)
        cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
        }
while (cad.indexOf(',') > signo)
    if (dec<0) cad = cad.replace(/\./,'')
        return cad;
}
}//Fin del objeto oNumero:
