// JavaScript Document
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


// JavaScript Document

//VALIDACION DE FORMULARIOS
var checkObjects	= new Array();
var errors		= "";
var returnVal		= false;
var language		= new Array();
language["header"]	= "Hurrengo erroreak aurkitu dira / Se han encontrado los siguientes errores: "
language["start"]	= "->";
language["field"]	= " ";
language["require"]	= " beharrezkoa da / es necesario ";
language["min"]		= " / y consiste en al menos ";
language["max"]		= " / y no debe contener más de ";
language["minmax"]	= " / y no más de ";
language["chars"]	= " karaktereak / caracteres ";
language["num"]		= " eta zenbakia izan behar da  / y tiene que ser númerico ";
language["email"]	= " posta-elektroniko balioduna izan behar du / debe contener una dirección de e-mail válida ";
// -----------------------------------------------------------------------------
// define - Call this function in the beginning of the page. I.e. onLoad.
// n = name of the input field (requerido)
// type= string, num, email (requerido)
// min = the value must have at least [min] caracteres (Optional)
// max = the value must have maximum [max] caracteres (Optional)
// d = (Optional)
// -----------------------------------------------------------------------------
function define(n, type, HTMLname, min, max, d) {
var p;
var i;
var 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 = define(n, type, HTMLname, min, max, d.layers[i].document);
return x;       

}
eval("V_"+n+" = new formResult(x, type, HTMLname, min, max);");
checkObjects[eval(checkObjects.length)] = eval("V_"+n);
}
function formResult(form, type, HTMLname, min, max) {
this.form = form;
this.type = type;
this.HTMLname = HTMLname;
this.min  = min;
this.max  = max;
}
function validate() {
if (checkObjects.length > 0) {
errorObject = "";
for (i = 0; i < checkObjects.length; i++) {
validateObject = new Object();
validateObject.form = checkObjects[i].form;
validateObject.HTMLname = checkObjects[i].HTMLname;
validateObject.val = checkObjects[i].form.value;
validateObject.len = checkObjects[i].form.value.length;
validateObject.min = checkObjects[i].min;
validateObject.max = checkObjects[i].max;
validateObject.type = checkObjects[i].type;
if (validateObject.type == "num" || validateObject.type == "string") {
if ((validateObject.type == "num" && validateObject.len <= 0) || (validateObject.type == "num" && isNaN(validateObject.val))) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['num'] + "\n";
} else if (validateObject.min && validateObject.max && (validateObject.len < validateObject.min || validateObject.len > validateObject.max)) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['min'] + validateObject.min + language['minmax'] + validateObject.max+language['chars'] + "\n";
} else if (validateObject.min && !validateObject.max && (validateObject.len < validateObject.min)) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['min'] + validateObject.min + language['chars'] + "\n";
} else if (validateObject.max && !validateObject.min &&(validateObject.len > validateObject.max)) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['max'] + validateObject.max + language['chars'] + "\n";
} else if (!validateObject.min && !validateObject.max && validateObject.len <= 0) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + "\n";
   }
} else if(validateObject.type == "email") {
// Checking existense of "@" and ".". 
// Length of must >= 5 and the "." must 
// not directly precede or follow the "@"
if ((validateObject.val.indexOf("@") == -1) || (validateObject.val.charAt(0) == ".") || (validateObject.val.charAt(0) == "@") || (validateObject.len < 6) || (validateObject.val.indexOf(".") == -1) || (validateObject.val.charAt(validateObject.val.indexOf("@")+1) == ".") || (validateObject.val.charAt(validateObject.val.indexOf("@")-1) == ".")) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['email'] + "\n"; }
      }
   }
}
if (errors) {
alert(language["header"].concat("\n" + errors));
errors = "";
returnVal = false;
} else {
returnVal = true;
   }
}

function MM_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=MM_findObj(n, d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateFormE() { //v4.0
  var titulo,i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormE.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    titulo=args[i+1]; 
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+titulo+' posta elektronikoko helbide bat behar da.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+titulo+' ez duzu telefono zenbakirik sartu.\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+='- '+titulo+' zenbaki hauen arteko bat behar da '+min+' eta '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+titulo+' sartu beharrezko datua da.\n'; }
  } if (errors) alert('Honako oker hauek izan dira:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_validateFormIn() { //v4.0
var titulo,i, p, q, nm, test, num, min, max, errors='', args=MM_validateFormIn.arguments;
for (i=0; i<(args.length-2); i+=3) { 
test=args[i+2]; 
val=MM_findObj(args[i]);
titulo=args[i+1]; 
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+titulo+' it must contain an email direction.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+titulo+' it must contain numbers.\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+='- '+titulo+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+titulo+' it is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}

function MM_validateFormC() { //v4.0
  var titulo,i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormC.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  { test=args[i+2]; 
	val=MM_findObj(args[i]);
	titulo=args[i+1];
    if (val) 
		{nm=val.name; 
		 if ((val=val.value)!="") 
			{if (test.indexOf('isEmail')!=-1)
			   { p=val.indexOf('@');
        		if (p<1 || p==(val.length-1)) errors+='- '+titulo+' debe contener una direccion de e-mail.\n';
      			} else if (test!='R') 
					{ num = parseFloat(val);
			        if (isNaN(val)) errors+='- '+titulo+' debe contener números.\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+='- '+titulo+' debe contener un numero entre '+min+' y '+max+'.\n';
					    } 
					} 
				} else if (test.charAt(0) == 'R') errors += '- '+titulo+' es obligatorio.\n'; }
	           } 
			   if (errors) alert('Se detectaron los siguientes errores:\n'+errors);
		       document.MM_returnValue = (errors == '');
		}
	
function abrirpopup(nombre,ancho,alto) {
  dat = 'width=' + ancho + ',height=' + alto + ',left=0,top=0,scrollbars=no,resize=yes';
  window.open(nombre,'',dat)
}

function registros(obj){
var p;
p=(obj.value-1)*8;
document.forms.form2.offset.value=p
}

function textCounter(field, maxlimit)
{
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
}

//------------------------------------------------------------------------------------------------------------------------


