function OpenCenterPop(link, nombre, ancho, alto){
  derecha=(screen.width-ancho)/2;
  arriba=(screen.height-alto)/2;
  string="toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+ancho+",height="+alto+",left="+derecha+",top="+arriba+"";
  fin=window.open(link,nombre,string);
}

function checkField(errorOut, nombrecampo, nombre, tipo, requerido){
//Llamada: if (checkField('idDelSpanDondeSeMuestraElError', 'NameDelCampo', 'TextoNombreDelCampo', 'Tipo', Requerido1o0)!="ok") return
//Atencion: si el tipo es radio se le pasa el nombre del campo no el id.

	var temp=""
	var obj=document.getElementById(nombrecampo)
	objError=document.getElementById(errorOut)
	objError.innerHTML=""
	//obj.style.backgroundColor="white"
	var min=6;
	valor=obj.value

	if (tipo!="radio"){
		//saca del valor las '
		for (i=0; i<valor.length ; i++){
			if (valor.charAt(i)!="'"){
				temp=temp + valor.charAt(i)
			}
		}
		valor=temp
	}
	
	if (requerido==1 && valor==""){
		objError.innerHTML="" + nombre + " no puede ser vacio."
		location.hash="href_" + errorOut;
		//obj.style.backgroundColor="#F9FF9D"
		obj.focus();
		return (false)
	}
	switch (tipo){
		case "numero":
			if (isNaN(valor)){
				objError.innerHTML="" + nombre + " debe ser un valor numerico."
				location.hash="href_" + errorOut;
				//obj.style.backgroundColor="#F9FF9D"
				obj.focus();
				return (false)
			}
			break
			
		case "email":
			if (valor.length>0){
				chequeoEmail=emailCheck(valor)
				if (chequeoEmail=="Dirección de mail inválida."){
					objError.innerHTML="" + chequeoEmail + ""
					location.hash="href_" + errorOut;
					//obj.style.backgroundColor="#F9FF9D"
					obj.focus();
					return (false)
				}
			}
			break
			
		case "radio":
			var obj=document.getElementsByName(nombrecampo)
			if (requerido==1){
				for (i=0;i<obj.length;i++) {
					if (obj[i].checked){
						sel=true;
						break;
					}
				}
				if (!sel){
					objError.innerHTML="Debe seleccionar "+nombre + ".";
					location.hash="href_" + errorOut;
					//obj.style.backgroundColor="#F9FF9D"
					obj.focus();
					return (false)
				}
			}
			break
		case "clave":
			if (valor.length < min){
				objError.innerHTML="" + nombre + " debe tener al menos " + min + " caracteres.";
				obj.focus();
				location.hash="#";
				return (false)
			}
			break
	}
	if (tipo!="radio"){
		obj.value=valor
	}
	

	return "ok"
		
}

function emailCheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return "Dirección de mail inválida."
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return "Dirección de mail inválida."
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   return "Dirección de mail inválida."
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return "Dirección de mail inválida."
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return "Dirección de mail inválida."
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return "Dirección de mail inválida."
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return "Dirección de mail inválida."
		 }

 		 return str					
}

function checkPass(ErrorSpan, pass1, pass2){
		
	var obj1=document.getElementById(pass1);
	var obj2=document.getElementById(pass2);
	objError=document.getElementById(ErrorSpam);
	
	var valor1;
	var valor2;
	
	valor1=obj1.value;
	valor2=obj2.value;
	
	if (valor1!=valor2){
		objError.innerHTML="Las claves no coinciden.";
		obj2.focus();
		location.hash="#";
		return (false)
	}else{
		return "ok"
	}	
}