// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popup(url, name, height, width, scrollbars) {
	var popwin;
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=no";
	opts += ",height=" + height + ",width=" + width + ",scrollbars=" + scrollbars;
	popwin = window.open("", name, opts);
	popwin.focus();
	popwin.location = url;
}

function cambiarradio() {
	document.ident.socio[1].checked = true
}

function ident_submit() {
	var resp = true;
	var mens = 'Es necesario introducir ';
	
	if (resp) {
		if (document.ident.socio[1].checked) {
			if ((document.ident.clave.value == "") || (document.ident.email.value == ""))
			{
				alert("El E-Mail y la contraseña son obligatorios");
				resp = false
			} 
		} else {
			if (document.ident.email.value == "") {
				alert("Es necesario introducir el E-mail");
				resp = false
			} else {
				resp = validarEmail(document.ident.email);
			}
		}
	}
	
	if (resp) {
		document.ident.submit();
	}
}

function cambiarradio1() {
	document.ident1.socio[1].checked = true
}

function ident_submit1() {
	var resp = true;
	var mens = 'Es necesario introducir ';
	
	if (resp) {
		if (document.ident1.socio[1].checked) {
			if ((document.ident1.clave.value == "") || (document.ident1.email.value == ""))
			{
				alert("El E-Mail y la contraseña son obligatorios");
				resp = false
			} 
		} else {
			if (document.ident1.email.value == "") {
				alert("Es necesario introducir el E-mail");
				resp = false
			} else {
				resp = validarEmail(document.ident1.email);
			}
		}
	}
	
	if (resp) {
		document.ident1.submit();
	}
}

function validarEmail(campo) {
	e = trim(campo.value);
	if (isEmail(e))
		return true;
	alert('La dirección de Email no es correcta');
	campo.focus();
	return false;
}
//función que indica si la dirección de email tiene la sintaxis correcta
function isEmail(argvalue) {
  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  //si hay más de una @	
  if (argvalue.indexOf("@") != argvalue.lastIndexOf("@"))
	return false;
  // arrayString = argvalue.split("@"); (works only in netscape3 and above.)
  var retSize = customSplit(argvalue, "@", "arrayString");

  if (arrayString[1].indexOf(".") == -1)
    return false;
  else if (arrayString[1].indexOf(".") == 0)
    return false;
  else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
    return false;
  }
  return true;
}

function trim(argvalue) {
  var tmpstr = ltrim(argvalue);

  return rtrim(tmpstr);
}

function customSplit(strvalue, separator, arrayName) {
  var n = 0;

  if (separator.length != 0) {
    while (strvalue.indexOf(separator) != -1) {
      eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));");
      strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
          strvalue.length+1);
      n++;
    }
    eval("arr" + n + " = strvalue;");
    arraySize = n+1;
  }
  else {
    for (var x = 0; x < strvalue.length; x++) {
      eval("arr"+n+" = \"" + strvalue.substring(x, x+1) + "\";");
      n++;
    }
    arraySize = n;
  }

  eval(arrayName + " = new makeArray(arraySize);");

  for (var i = 0; i < arraySize; i++)
    eval(arrayName + "[" + i + "] = arr" + i + ";");

  return arraySize;
}
//función que ejecuta un trim por la izquierda a un string
function ltrim(argvalue) {

  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }

  return argvalue;
}
//función que ejecuta un trim por la derecha a un string
function rtrim(argvalue) {

  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }
  return argvalue;
}

function makeArray(IntarrSize) {
  for (var n = 0; n < IntarrSize; n++)
    this[n] = "";

  return this;
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=350,left = 440,top = 337');");
}

