
function Borrar()
{
	return confirm("Se realizará un borrado en \"cascada\" de toda la información dependiente de dicho registro\r\r¿Desea borrar el registro?");
}

//busca coincidencia en un combo.
function searchSelect(txt, selectObject, caseinsensitive)  {
     
         if(caseinsensitive) txt = txt.toUpperCase();
         for(var i=0;i<selectObject.length;i++) {              
              tmpTxt = selectObject[i].text;
              tmpTxt = (caseinsensitive)?tmpTxt.toUpperCase():tmpTxt;
              if(tmpTxt.indexOf(txt)==0) {
                   selectObject.selectedIndex=i;
                   return;
              }
         }
  }

function abreVentana(theURL,Wname,W,H,scrollbars) {
		MM_openBrWindow(theURL,Wname,W,H,"scrollbars="+scrollbars+",");
    //return top.window.open(theURL,Wname,"width="+W+",height="+H+",status=yes,toolbar=no,location=no,directories=no,menubar=no,scrollbars="+scrollbars+",resizable=no,copyhistory=no");
}

function borrarItemLista(i,lst) {
  if ( i != -1) {
	lst.options[i].removeNode();
  }
}

//Una ventana hija envia datos a la padre.
function EnviarDatos(strValor,ID,Campo){	
		if(window.opener != null){			
		 	var strval = eval(window.opener.main)+"";		 	
		 	if(strval=='undefined'){		 		
		 		window.opener.RecogerDatos(strValor,ID,Campo);
		 	}
		 	else {		 	
		 		window.opener.main.RecogerDatos(strValor,ID,Campo);
		 	}
		}
		window.focus();
		if(Campo!='Beneficiario'){
			window.close();			
		}
}

//Una ventana hija ejecuta el click de Aceptar de la padre.
function AceptarPadre(){	
	if(window.opener != null){			
		window.opener.main.Actualizar();
		//if (window.opener.document.all.btnAceptar != null) {		
		//	window.opener.document.all.btnAceptar.click();
		//}
	}
	window.focus();	
	window.close();			
}



//Funciones de validación de formularios
function ValidarNIF(obj,strCampo){
	if(obj.value!=""){				
		if(!NIF(obj.value)){
			alert ('Compruebe que el NIF del '+strCampo+' es correcto');		
			obj.focus();		
		}	
	}
}



function ValidarNIE(obj,strCampo){
	if(obj.value!=""){				
		if(!NIE(obj.value)){
			alert ('Compruebe que el NIE del '+strCampo+' es correcto');		
			obj.focus();
		}	
	}
}

function ValidarEmail(obj,strCampo){
	if(obj.value!=""){				
		if(!Email(obj.value)){
			alert ('Compruebe que la dirección de correo electrónica del '+strCampo+' es correcta');		
			obj.focus();		
		}	
	}
}


function ValidarFecha(obj,strCampo){	
	if(obj.value!=""){					
		if(!Fecha(obj.value)){
			alert ('Compruebe que la fecha de '+strCampo+' es correcta');		
			obj.focus();		
		}	
	}
}
//fin funciones validación.

//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)
{
	var x = strNie.substring(0,1);
	if (x != 'X') return false;
	var nif = strNie.substring(1,strNie.length);
	if(nif.length!=9)	nif="0"+nif;
	return NIF(nif);		
}		

//Comprueba que who es un e-mail valido
function Email(who) {	
	var email=/^[A-Za-z0-9][\w-.]+@[A-Za-z0-9]([\w-.]+[A-Za-z0-9]\.)+([A-Za-z]){2,4}$/i;
	return(email.test(who));
}

//Comprueba que el formato de una fecha sea correcto. DD/MM/YYYY
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) {
		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
}

function parseFecha(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) {
		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 new Date(year,month-1,day);  // date is valid
}


// whitespace characters
var whitespace = " \t\n\r";
var defaultEmptyOK = false;

function Vacio(s)
{   return ((s == null) || (s.length == 0))
}

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;
}

function numerodecimal(valor){
	valor = valor.replace(",",".");
	num = parseFloat(valor)
	if (num!=valor){
		return(false)
	} else {
		return(true)
	}
}


function numdecsinpunt(valor){
	//alert(valor);	
	valor = valor.replace(/\./g,"");
	valor = valor.replace(/\,/g,".");	
	//alert('valor sin puntos ni nada '+valor);
	num = parseFloat(valor);
	//alert(num+','+valor);
	if (num!=valor){
		return(false)
	} else {
		return(true)
	}
}

function parseImporte(valor){
	//alert(valor);	
	valor = valor.replace(/\./g,"");
	valor = valor.replace(/\,/g,".");	
	//alert('valor sin puntos ni nada '+valor);
	num = parseFloat(valor);
	//numtxt = num.toString();	
	
	//if(numtxt.indexOf(".")!=-1){
	//	numtxt = numtxt.substring(0,numtxt.indexOf(".")+3);	
	//}
	//alert(num+','+valor);

	return num;
}

//formatea el numero con puntos recibe un numero float 
//(en lugar de una cadena con formato español como ponerpuntos())
function ponerpuntos2(num,dec){
	// Se pasa el numero a formato español
	var strNum = num+"";
	strNum = strNum.replace(/\./g,",");
	// y se utiliza ponerpuntos()
	return ponerpuntos(strNum,dec);
}

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);
}


//pone los puntos a las cifras. Dec es el número de
//decimales que tiene. Cambia el . del decimal
//por la ,. Sino tiene que poner 00, y
//si es sólo ,88 poner el 0 delante
function ponerpuntos(num,dec){	
	var val = num+"";	
	val = val.replace(/\./g,"");	
	val = val.replace(/\,/g,".");		
	var cm = 0;
	var con=0;
	var temp;
	if(dec>0){
		var tt = val + ".a";
		var r = tt.split(".");
		if(r[1]=="a"){
			temp = ",00";
			con = 0;
		}
		else{
			temp = "," + r[1]; 
			var gt = r[1];
			con = gt.length+1;
			if(temp.length != 3)
				temp = temp + "0";
		}
		if(val.length < con+1)
			temp = "0" + temp;
	}
	else temp = "";
	con = con+1;
	for (var i = val.length - con ; i >=0 ; i--) {
		if(++cm == 4){
			temp = "." + temp;
			cm = 1;
		}
        temp = val.charAt(i) + temp;		
    }
    return temp;   
}

function numero(valor){

	if (EnBlanco(valor))
	{	
		return(false);
	}
	else
		if (isNaN (Number(valor)))
		{
			return(false);
		}

	return(true);
}


// Funciones preparadas para CustomValidators

// Valida un importe y formatea el valor con 
// dos decimales y separadores de miles
function NETValidate_Importe(Source, Args){		
	var strVal = Args.Value;					
	if(numdecsinpunt(strVal)){
		Args.IsValid=true;			
		Args.Value = ponerpuntos(strVal,2);
	} else { Args.IsValid=false; }
}

function NETValidate_ImportePositivo(Source, Args){		
	var strVal = Args.Value;
	Args.IsValid = true;		
	if(strVal.indexOf("-")!=-1){		
		Args.IsValid=false;
		return;
	}
					
	if(numdecsinpunt(strVal)){
		Args.IsValid=true;			
		Args.Value = ponerpuntos(strVal,2);
	} else { Args.IsValid=false; }
	

}

// Valida una fecha
function NETValidate_Fecha(Source, Args) {	
	Args.IsValid = Fecha(Args.Value);
}

// Valida un número entero
function NETValidate_Numero(Source, Args){
	Args.IsValid = numero(Args.Value);	
}
function FechaMayorque(datIni,datFin)
/*	Compara dos fechas
	datIni : Fecha Inicial
	datFin : Fecha Final
	Devuelve:
		True si datFin > datIni
		False en cualquier otro caso
*/
{
	var ok = true;
	var fechaini = str2Date(datIni);
	var fechafin = str2Date(datFin);
	
	if (fechafin<fechaini)
		ok=false;
	
	return ok;	
}
// Convierte una cadena(con Formato Fecha) a Fecha
function str2Date(strFecha)

/* Admite fechas en formato dd/mm/yy d/mm/yy dd/m/yy d/m/yy dd/mm/yyyy d/mm/yyyy dd/m/yyyy d/m/yyyy 
   dd-mm-yy d-mm-yy dd-m-yy d-m-yy dd-mm-yyyy d-mm-yyyy dd-m-yyyy d-m-yyyy 
*/
{
	var posdia,posmes,dia,mes,ano;
	
	if (strFecha.indexOf("/") != - 1)
	{
		posdia = strFecha.indexOf("/");
		dia =  strFecha.substring(0,posdia);
		posmes = strFecha.indexOf("/",posdia+1);
		mes	= strFecha.substring(posdia+1,posmes);
		ano = strFecha.substring(posmes+1,strFecha.length);	
		if (ano < 100)
		{
			ano = parseInt(ano) + 2000;
		}
		return new Date(ano,mes-1,dia);
	}
	
	if (strFecha.indexOf("-") != - 1)
	{
		posdia = strFecha.indexOf("-");
		dia =  strFecha.substring(0,posdia);
		posmes = strFecha.indexOf("-",posdia+1);
		mes	= strFecha.substring(posdia+1,posmes);
		ano = strFecha.substring(posmes+1,strFecha.length);	
		if (ano < 100)
		{
			ano = parseInt(ano) + 2000;
		}
		return new Date(ano,mes-1,dia);	
	}
	
	dia = strFecha.substring(0,2);
	mes = strFecha.substring(2,4);
	ano = strFecha.substring(4,strFecha.length);
	if (ano < 100)
		{
			ano = parseInt(ano) + 2000;
		}
	return new Date(ano,mes-1,dia);
	
}
function FechaMayorqueHoy(fecha){
	var fechaini = str2Date(fecha);
	var fechahoy = new Date();
	if(fechahoy<fechaini)
		return true;
	else
		return false;
}