
function irapag(pagina, url, regs, param)
{
	var goto = url+"?inicio="+(parseInt(regs)*parseInt(pagina))+"&pag="+(parseInt(pagina) + 1)+param;
	
	//alert(goto);
	document.location=goto;
}

// whitespace characters
var whitespace = " \t\n\r";
var defaultEmptyOK = false;


//FUNCIONES VARIAS DE VALIDACION DE FORMULARIOS

/* EXPRESIONES REGULARES COMUNES
* D.N.I.: ^\d{1,8}$
* Entero: ^(?:\+|-)?\d+$
* Real: ^(?:\+|-)?\d+\.\d*$
* Hora: ^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?$
* Fecha: ^([012][1-9]|3[01])(/|-)(0[1-9]|1[012])\2(\d{4})$
* Email: (^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@ ([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$
*/

function validateValue( strValue, strMatchPattern ) {
/************************************************
DESCRIPTION: Validates that a string a matches
  a valid regular expression value.

PARAMETERS:
   strValue - String to be tested for validity
   strMatchPattern - String containing a valid
      regular expression match pattern.

RETURNS:
   True if valid, otherwise false.
*************************************************/
var objRegExp = new RegExp( strMatchPattern);

 //check if string matches pattern
 return objRegExp.test(strValue);
}

function Vacio(s)
{   return ((s == null) || (s.length == 0))
}

function FechaStrToDate(dateStr)
{
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
var matchArray = dateStr.match(datePat);
		
if (matchArray == null)
	return false;
else{
	var month = matchArray[3]; // parse date into variables
	var day = matchArray[1];
	var year = matchArray[4];
	
	var fecha = new Date(year,month-1,day);
	return fecha;
	}
}

function Hora( strHora )
{
	
	return validateValue( strHora, "^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?$");
}

function Fecha(dateStr)
{
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
//alert("La fecha no está en un formato válido.")
return false;
}
month = matchArray[3]; // parse date into variables
day = matchArray[1];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
//alert("El mes debe estar entre 1 y 12.");
return false;
}
if (day < 1 || day > 31) {
//alert("El día debe estar entre 1 y 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("El mes "+month+" no tiene 31 dias!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
//alert("Febrero de " + year + " no tiene " + day + " dias!");
return false;
   }
}
return true;  // date is valid
}


/****************************************************************/

// Returns true if string s is empty or 
// whitespace characters only.

function EnBlanco(s)

{   var i;

    // Is s empty?
    if (Vacio(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

/****************************************************************/

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function Email(s)
{
    // is s whitespace?
    if (EnBlanco(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function LongMax(objField, nLength, strWarning)
{
	var strField = new String(objField.value);

	if (strField.length > nLength) {
		alert(strWarning);
		return false;
	} else
		return true;
}

function Digito(valor){
   numero=parseInt(valor);
   if (!(numero>=0 && numero<=9)){
	alert("Introduzca un número entre 0 y 9");
	return(false);
   }
   return(true);
}
function Rango(valor,min,min){
   numero=parseInt(valor);
   if (!(numero>=min && numero<=min)){
	alert("Introduzca un número entre " + min+ " y " + max);
	return(false);
   }
   return(true);
}
function Numero(valor){
   nume=parseInt(valor);
   if ((nume != valor)){
	//alert("Introduzca un número");
	return(false);
   }
   return(true);
}

function Decimal(valor){
	valor = valor.replace(",",".");
	num = parseFloat(valor)
	if (num!=valor){
		return(false)
	} else {
		return(true)
	}
}

function SonDigitos(cadena){
	var longitud = cadena.length
	var i
	var numero
	var ok=true
	i=0
	while ((i<longitud)&& (OK=true)) {
		numero=parseInt(cadena.charAt(i));		
		if (!(numero>=0 && numero<=9)){
			ok=false	
		}   
		i++;
	}
	return(ok)
}


function Requerido(objField, FieldName)
{
	var strField = new String(objField.value);
	if (EnBlanco(strField)) {
		alert("Debe introducir " + FieldName);
		objField.focus();
		//objField.select();
		return false;
	}

	return true;
}

function esFichero()
/*	Devuelve true si el Fichero tiene la extensión que se pasa como parámetro
	 Devuelve false en cualquier otro caso */
{
	var cadena,res,extensiones,i;
	
	extensiones = esFichero.arguments;
	cadena = extensiones[0];
	cadena = cadena.toUpperCase();
	res = false;
	for (i=1;i < extensiones.length; i++)
	{ 
		if (cadena.indexOf("."+ extensiones[i]) != -1 )
		{
			res = true;		
		}
	}
	return (res);
}

function formatNum(num, numDecs) {
var valor
	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));
	
	valor=((sign)?'':'-') + num
	if (numDecs > 0)
		valor = valor + ',' + cents
		
	return (valor);
}

function StrReplace( str1, str2, str3) {
  return str1.toString().replace(str2, str3);
}

//Comprueba que un NIF sea correcto.
function NIF(strNif)
{
	var arrLetra = 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');

	if (strNif.length < 9) return false;
	
	
	var n = strNif.substring(0, 8);
	if (isNaN(Number(n))) return false;
		 
	var l = strNif.substring(8, 9);
	var letra = l.charCodeAt(0);
	if (!(letra >= 65 && letra <= 90)) return false;
	var position =Number(n)%23;
	if (arrLetra[position] != l) return false;
	
	return true;
}	
	
//Comprueba que un NIE sea correcto.
function NIE(strNie)
{
	if (strNie.length < 9) return false;
	var x = strNie.substring(0,1);
	if (x != 'X') return false;
	var nif = "0" + strNie.substring(1,strNie.length);
	return NIF(nif);
}

function FCKEditorVacio(nombreControl)
{
	if(FCKeditorAPI.GetInstance(nombreControl).GetXHTML() == "") 
		return true;
	else
		return false;
}

/* EXPRESIONES REGULARES COMUNES
* D.N.I.: ^\d{1,8}$
* Entero: ^(?:\+|-)?\d+$
* Real: ^(?:\+|-)?\d+\.\d*$
* Hora: ^(0[1-9]|1\d|2[0-3]):([0-5]\d):([0-5]\d)$
* Fecha: ^([012][1-9]|3[01])(/|-)(0[1-9]|1[012])\2(\d{4})$
* Email: (^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@ ([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$
*/

function client_data(info)
{
	if (info == 'width')
	{
		width_height_html = '<h4  class="right-bar">Current Screen Resolution</h4>';
		width = (screen.width) ? screen.width:'';
		height = (screen.height) ? screen.height:'';
		width_height_html += '<p class="right-bar">' + width + " x " +
			height + " pixels</p>";
		return (width && height) ? width_height_html:''; //document.write(width_height_html):'';
	}
	else if (info == 'js')
	{
		//document.write('<p class="right-bar">JavaScript is enabled.</p>');
		return 'enabled';
	}
	else if (info == 'cookies')
	{
		var cookieEnabled=(navigator.cookieEnabled)? true : false

		//if not IE4+ nor NS6+
		if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
			document.cookie="testcookie"
			cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
		}

		//if cookies are enabled on client's browser
		if (cookieEnabled) {
			return 'enabled';
		} else {
			return 'disabled';
		}

		/*var tmpcookie = new Date();
		chkcookie = (tmpcookie.getTime() + '');
		document.cookie = "chkcookie=" + chkcookie + "; path=/";
		if (document.cookie.indexOf(chkcookie,0) < 0) {
		  return 'disabled';
		} else {
		  return 'enabled';
		}*/

		/*expires ='';
		Set_Cookie('cookie_test', 'funciona!', expires, '/', '', '');
		string = '<h4  class="right-bar">Cookies</h4><p class="right-bar">';
		if (Get_Cookie('cookie_test'))
		{
			string += 'enabled</p>';
			return 'enabled';
		}
		else
		{
			string += 'disabled</p>';
			return 'disabled';
		}*/
		//document.write( string );
	}
}
