// JavaScript Document
function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}


function usuario(funcion){

	//donde se mostrará el resultado
	divResultado = document.getElementById('resultado');
	//instanciamos el objetoAjax
	ajax=objetoAjax();
  if(funcion==2){
    usuarios=document.forma_usuario.usuario.value;
    claves=document.forma_usuario.clave.value;

  }
	//usamos el medoto POST
	//archivo que realizará la operacion
    
	ajax.open("POST", "usuario.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//mostrar resultados en esta capa
			divResultado.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores

   if(funcion==2)ajax.send("funcion="+funcion+"&usuario="+usuarios+"&clave="+claves);
   if(funcion==1)ajax.send("funcion="+funcion);

}





/** funciones de validacion  **/


function validarDatos(){
	
	if(document.forma_usuario.usuario.value==""){
		alert("Inserte Datos");
		return ;
	}
	
	if(document.forma_usuario.clave.value==""){
		alert("Inserte Datos");
		return;
	}
	

   usuario(2);//validar datos

}


function lanzarurl(url,ancho,alto) {
window.open(url,"laventana","directories=no,location=no,toolbar=no,resizable=no,scrollbars=yes,width=" + ancho + ",height=" + alto + ",menubar=no");
} 

function abrir_flash(url,ancho,alto){
	  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ancho+'" height="'+alto+'">');
      document.write('<param name="movie" value="'+url+'" />');
      document.write('<param name="quality" value="high" />');
      document.write('<embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ancho+'" height="'+alto+'"></embed></object>');

}

function limpiar_miembro(){

  document.forma.nombre.value="";
  document.forma.apellidos.value="";
  document.forma.fechanacimiento.value="";
  document.forma.email.value="";
  document.forma.direccion.value="";
  document.forma.telefono.value="";
  return;

}

function val_email(elemento_forma)

{

    if ((elemento_forma.value.indexOf("@") == -1)||(elemento_forma.value.indexOf(".") == -1)) return false;

    else return true;

}



function validar_miembro(){

  if(document.forma.nombre.value==""){
    alert("Complete los datos");
    return;
  }
   if(document.forma.apellidos.value==""){
    alert("Complete los datos");
    return;

  }
  if(document.forma.fechanacimiento.value==""){
    alert("Complete los datos");
    return;

  }
  if(document.forma.direccion.value==""){
    alert("Complete los datos");
    return;

  }
 if(document.forma.telefono.value==""){
    alert("Complete los datos");
    return;

  }

 if(document.forma.email.value==""){
    alert("Complete los datos");
    return;

  }else{
          if(!(val_email(forma.email))){

              alert("Email incorrecto");
              return;
 
           }

   }

  if(document.forma.clave.value==""){
    alert("Complete los datos");
    return;
  }else{
        if(document.forma.clave.value!=document.forma.clave2.value){
               alert("Confirmación de clave incorrecta");
              return;

        }

  }

  if(document.forma.membresia.value==""){
     alert("Confirmación de clave incorrecta");
     return;
  }
 

   forma.submit();

}


function validar_contacto(){
  if(document.forma.nombre.value==""){
    alert("Complete los datos");
    return;
  }


   if(document.forma.email.value==""){
    alert("Complete los datos");
    return;
  }else{
       if(!(val_email(forma.email))){

              alert("Email incorrecto");
              return;
 
           }
  }

 
 if(document.forma.mensaje.value==""){
    alert("Complete los datos");
    return;

  }
    
  
  forma.submit();
}


function limpiar_contacto(){
  document.forma.nombre.value="";
  document.forma.email.value="";
  document.forma.mensaje.value="";
 
  return;
    

}

function mostrar_capa(capa){

   document.getElementById(capa).style.display="block";

}

function ocultar_capa(capa){

   document.getElementById(capa).style.display="none";

}
