function eliminar(){
	return confirm("¿Eliminar?");
}
			
function funcFormVacio(objeto, nombre){
	mensaje='Requírese o campo '+nombre+'.';		
	if(objeto.value==''){
		alert(mensaje);
		objeto.focus();
		return false;
	}
}

function funcFormNumerico(objeto, nombre, decimales, digMin, digMax){
	if(digMin==digMax || !digMax){
		mensaje='O campo \''+nombre+'\' debe ser un número de '+digMin+' díxitos.';
		digMax = digMin
	}else{
		mensaje='O campo \''+nombre+'\' debe ser un número de entre '+digMin+' e '+digMax+' díxitos.';
	}
	
	if(decimales=='no'){
		if (objeto.value.indexOf('.')!=-1){
			mensaje = mensaje +' (non pode conter decimais)';
			alert(mensaje);
			objeto.focus();
			return false;						
		}
	}
	
	if(objeto.value!=''){
		if (objeto.value.length<digMin || isNaN(objeto.value) || objeto.value.length>digMax){
			alert(mensaje);
			objeto.focus();
			return false;
		}
	}			
}

function funcFormTlf(objeto, nombre){	 		
	mensaje='O campo \''+nombre+'\' debe ser un número de entre 9 e 12 díxitos e non pode conter espacios.'
	if(objeto.value!=''){
		if (objeto.value.length<9 || isNaN(objeto.value) || objeto.value.length>12){
			alert(mensaje);
			objeto.focus();
			return false;
		}
	}
}

function funcFormEmail(objeto, nombre){
	mensaje="O campo '"+nombre+"' debe ter o formato correo@dominio.ext"
	if (objeto.value!='' && objeto.value){	
		var cadena=".@";
		var este;
		var contador=0;
		for(var i=0;i<objeto.value.length;i++){
			este=objeto.value.substring(i,i+1);
			if (cadena.indexOf(este)!=-1)
				contador++;
		}
		if (contador<2){	
			alert(mensaje);
			objeto.focus();
			return false;
		}
	}
}

function funcFormFecha(objDia, objMes, nombre){
	var valida=1;	
	var mensaje = "A '"+nombre+"' non é unha data correcta.";
	if(objDia.value==31 && (objMes.value==4 || objMes.value==6 || objMes.value==9 || objMes.value==11))
		valida = 0;

	if(objMes.value==2 && objDia.value>29)
		valida = 0;
		
	if (valida==0){	
			alert(mensaje);
			objDia.focus();
			return false;
		}
}

function funcFormCIF(objeto, nombre){
mensaje='O campo \''+nombre+'\' debe ter o formato A00000000 (letra seguida de 8 díxitos)';
var cifOK=1;
	if (objeto.value!=''){
		if (objeto.value.length!=9){
			cifOK=0;
		}else{
			for (i=1;i<9;i++){
				cif=objeto.value.charAt(i);
				if (isNaN(cif)){
					cifOK=0;
				}
			}	
		}
		if (cifOK!=0){
			cif=objeto.value.charAt(0);
				if (!isNaN(cif)){
					cifOK=0;
				}
		}
	}
	if (cifOK==0){
		alert(mensaje);
		objeto.focus();
		return false;				
	}
}


function funcFormNIF(objeto, nombre){
mensaje='O campo \''+nombre+'\' debe ter o formato 00000000X ou A0000000X';
var nifOK = 1;
	if (objeto.value!=''){
		if (objeto.value.length!=9){
			nifOK = 0;
		}else{
			for (i=1;i<8;i++){
				nif=objeto.value.charAt(i);
				if (isNaN(nif)){
					nifOK = 0;
				}
			}	
		}
		if (nifOK!=0){
			nif=objeto.value.charAt(8);
				if (!isNaN(nif)){
					nifOK = 0;
				}			
		}
	}
	if (nifOK==0){
		alert(mensaje);
		objeto.focus();
		return false;				
	}
}

function funcFormColor(objeto,nombre){
mensaje='El campo \''+nombre+'\' debe ser del tipo #XXXXXX';
var colorOK = 1;
	if(objeto.value.length!=7)
		colorOK = 0;
	else{
		if(objeto.value.charAt(0)!='#')
			colorOK = 0;
		for(i=1;i<7;i++){
			//if(!isAlphanumeric(objeto.value.charAt(i)))
				//colorOK = 0;
		}
	}
	
	if (colorOK==0){
		alert(mensaje);
		objeto.focus();
		return false;				
	}
}


function limitaTextArea(objeto,ncar,contador){
var texto = objeto.value
if(texto.length>ncar)
  objeto.value=texto.substring(0,ncar)
else
 if(contador)
 	contador.value=ncar-texto.length
}
function Reemplazar(objeto, el_que, por_esto) {
	temp = "" + objeto.value;

	while (temp.indexOf(el_que)>-1) {
		pos= temp.indexOf(el_que);
		temp = "" + (temp.substring(0, pos) + por_esto + temp.substring((pos + el_que.length), temp.length));
	}

	objeto.value=temp;
}

function borrarCampos(fo){
	if(confirm('¿Borrar os campos?'))
		fo.reset();
}

function confirma(txt_confirma,url_o_form, accion){
	if(confirm(txt_confirm)){
		if(accion==1) location.href=url_o_form;
		if(accion==2) url_o_form.submit();
	}
}

function alerta(txt_alert, txt_confirm, accion, url_o_form){
	alert(txt_alert);
	if(confirm(txt_confirm)){
		if(accion==1) location.href=url_o_form;
		if(accion==2) url_o_form.submit();
	}
}

function superalerta(txt_alert, txt_confirm1, txt_confirm2, accion, url_o_form){
	alert(txt_alert);
	if(confirm(txt_confirm1)){
		if(confirm(txt_confirm2)){
			if(accion==1) location.href=url_o_form;
			if(accion==2) url_o_form.submit();
		}
	}
}
