function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { 
	  	if(validateEmail(val, true, false) != true) errors+='- '+nm+' debe ser un e-mail.\n';		
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe ser un número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' debe ser un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
  } if (errors) alert('El formulario no es correcto:\n'+errors);
  document.form_returnValue = (errors == '');
}

function borracampo(campo, texto) {

	if(campo.value == texto) {
		campo.value = '';
		campo.focus();
	}

}

function volvercampo(campo, texto) {

	if(campo.value == '') {
		campo.value = texto;
	}

}

function enablear(campo) {

	eval("document.getElementById['" + campo + "']").disabled = false;
}

function disablear(campo) {
	eval("document.getElementById['" + campo + "']").disabled = true;
}

function colorear(campo) {
	eval("document.getElementById['" + campo + "']").style.background='#A4D4F4';
}

function decolorear(campo) {
	eval("document.getElementById['" + campo + "']").style.background='#FFFFFF';
}

function parpadear(campo) {

	setTimeout(eval("colorear('"+campo+"');"), 1000);
	setTimeout(eval("decolorear('"+campo+"');"), 1000);
	setTimeout(eval("colorear('"+campo+"');"), 1000);
	setTimeout(eval("decolorear('"+campo+"');"), 1000);

}


// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {

	if (addr == '' && man) {
	   if (db) alert('debe introducir un e-mail');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('El e-mail contiene caracteres inválidos');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("El e-mail contiene caracteres inválidos (no ASCII)");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('El e-mail debe contener una @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('El e-mail no debe empezar por una @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('El e-mail sólo debe contener una @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('El e-mail debe contener un punto en el dominio');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('No puede haber un punto justo después de la @');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('No puede haber un punto justo antes de la @');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('No puede haber dos puntos juntos en la arroba');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('Dominio de primer nivel incorrecto: .com, .es ...');
	   return false;
	}
	return true;
}