﻿<!-- // Required to be compliant with XHTML-->
var diaWeek;


function inicioAjax(bloque)
{
         var xmlHttp = null;
        
         try {
            // Firefox, Opera 8.0+, Safari, IE7+
            xmlHttp = new XMLHttpRequest(); // xmlHttp is now a XMLHttpRequest.
         } catch (e) {
            // Internet Explorer
            try {
               xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
         }
    		xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)
           try { 

              if (xmlHttp.status == 200) {
               
                 document.getElementById(bloque).innerHTML = xmlHttp.responseText;
              }
           } catch (e) {
              document.getElementById(bloque).innerHTML 
                 = "Error en la llamada de retorno Ajax : " + e.description;
           }
    		}
    		 
 return xmlHttp;
} 

function insertaPartida(fecha,user,ID,dia) 
{
   xmlHttp = inicioAjax('calendario');
   xmlHttp.open("POST","calendario.asp"); 
	 //alert(dia);
	 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	 xmlHttp.send('fecha='+fecha+'&user='+user.replace(/ /g,'%20')+'&ID='+ID+'&partida='+dia);
}

function eliminaPartida(fecha,user,ID,dia) 
{
   xmlHttp = inicioAjax('calendario');
   xmlHttp.open("POST","calendario.asp"); 
	 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	 xmlHttp.send('fecha='+fecha+'&user='+user.replace(/ /g,'%20')+'&ID='+ID+'&nopartida='+dia);
}

function AsistirPartida(fecha,user,ID,dia) 
{
   xmlHttp = inicioAjax('calendario');
   xmlHttp.open("POST","calendario.asp"); 
	 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	 xmlHttp.send('fecha='+fecha+'&user='+user.replace(/ /g,'%20')+'&ID='+ID+'&jugador='+dia);
}

function noAsistirPartida(fecha,user,ID,dia) 
{
   xmlHttp = inicioAjax('calendario');
   xmlHttp.open("POST","calendario.asp"); 
	 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	 xmlHttp.send('fecha='+fecha+'&user='+user.replace(/ /g,'%20')+'&ID='+ID+'&nojugador='+dia);
}

function statusPartida(fecha,user,ID,dia) 
{
   var ancho;
	 var fechatotal;
	 fechatotal = fecha.substr(0,fecha.indexOf("-",6)+1)+dia;
	// alert(dia);
if( typeof( window.innerWidth ) == 'number' ) {
   ancho = window.innerWidth;
} else if (document.documentElement &&  document.documentElement.clientWidth ) {
   ancho = document.documentElement.clientWidth;
} else  {
   ancho = document.body.clientWidth;	
}

   document.getElementById('ventana').style.left =  ((ancho - 900) / 2) +'px'
   document.getElementById('ventana').style.display='';
  	 
   xmlHttp = inicioAjax('ventana');
   xmlHttp.open("POST","statusPartida.asp"); 
	 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	 xmlHttp.send('fecha='+fechatotal+'&user='+user.replace(/ /g,'%20')+'&ID='+ID);
	 
}

function nuevoJugador(paginaWeb)
{
   var ancho;
	 /* mostrem finestra registre */
    if( typeof( window.innerWidth ) == 'number' ) {
       ancho = window.innerWidth;
    } else if (document.documentElement &&  document.documentElement.clientWidth ) {
       ancho = document.documentElement.clientWidth;
    } else  {
       ancho = document.body.clientWidth;	
    }
    document.getElementById('ventana').style.left =  ((ancho - 900) / 2) +'px'
    xmlHttp = inicioAjax('ventana');
    xmlHttp.open("GET",paginaWeb); 
	  xmlHttp.send("ok");
    document.getElementById('ventana').style.display='';

}




function almacenaUsuario(user) 
{
    var ancho;
	 /* mostrem finestra registre */
	 	document.getElementById('calendario').style.display='none';
    if( typeof( window.innerWidth ) == 'number' ) {
       ancho = window.innerWidth;
    } else if (document.documentElement &&  document.documentElement.clientWidth ) {
       ancho = document.documentElement.clientWidth;
    } else  {
       ancho = document.body.clientWidth;	
    }
    document.getElementById('ventana').style.left =  ((ancho - 900) / 2) +'px'
    xmlHttp = inicioAjax('ventana');
    xmlHttp.open("POST","almacenaUser.asp"); 
  	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  	user = user.replace(/ /g,'%20');
		xmlHttp.send('user='+user.replace(/ /g,'%20'));
    document.getElementById('ventana').style.display='';
}

function cargaPhoto(user)
{
    xmlHttp = inicioAjax('photo');
    xmlHttp.open("POST","showPhoto.asp"); 
  	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  	xmlHttp.send('user='+user.replace(/ /g,'%20') );
    document.getElementById('photo').style.display='';
}


function guardaUserAE()
{
    var ancho;
		
	 /* mostrem finestra registre */
    document.getElementById('ventana').style.display='none';
    if( typeof( window.innerWidth ) == 'number' ) {
       ancho = window.innerWidth;
    } else if (document.documentElement &&  document.documentElement.clientWidth ) {
       ancho = document.documentElement.clientWidth;
    } else  {
       ancho = document.body.clientWidth;	
    }
    document.getElementById('ventana').style.left =  ((ancho - 900) / 2) +'px'
    xmlHttp = inicioAjax('ventana');
    xmlHttp.open("POST","userRegistrado.asp"); 
  	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  	xmlHttp.send('user='+document.guardaUser.USER.value.replace(/ /g,'%20')+'&ID='+document.guardaUser.IDSOC.value+'&CLUB='+document.guardaUser.CLUB.value.replace(/ /g,'%20'));
    document.getElementById('ventana').style.display='';
}
			 
function calendarioInscripcion(fecha,user,ID)
{
    xmlHttp = inicioAjax('calendario');
    xmlHttp.open("POST","calendario.asp"); 
	  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	  xmlHttp.send('fecha='+fecha+'&user='+user.replace(/ /g,'%20')+'&ID='+ID);
} 		

function menuCalendario()
{
    xmlHttp = inicioAjax('menu');
    xmlHttp.open("POST","menuCalendario.asp"); 
	  xmlHttp.send();
} 
 
function registraUsuario()
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

	  if (document.registraSocio.Usuario.value =="")
		{
		  IsNumber = false;
		}
		
	  if (document.registraSocio.Password.value =="")
		{
		  IsNumber = false;
		}

	  if (document.registraSocio.ID.value =="")
		{
		  IsNumber = false;
		}
		
    for (i = 0; i < document.registraSocio.ID.value.length && IsNumber == true; i++) 
      { 
      Char = document.registraSocio.ID.value.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
		
   if (IsNumber)
	 {
	 
	  if (document.registraSocio.ID.value != 0 )
		{
    	  document.getElementById('calendario').style.display='none';
      	xmlHttp = inicioAjax('calendario');
        xmlHttp.open("POST","calendario.asp"); 
    	  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    	  xmlHttp.send('fecha=ahora&user='+document.registraSocio.Usuario.value.replace(/ /g,'%20')+'&ID='+document.registraSocio.ID.value);
        xmlHttp = inicioAjax('usuario');
        xmlHttp.open("POST","menuUsuario.asp"); 
    		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    		xmlHttp.send('usu='+document.registraSocio.Usuario.value.replace(/ /g,'%20')+'&ID='+document.registraSocio.ID.value+'&pass='+document.registraSocio.Password.value); 
    }else{
		    ReimprimeRegistroUsuario(document.registraSocio.Usuario.value.replace(/ /g,'%20'),document.registraSocio.Password.value);
		}   
	 
	 
	 } else {
	
	    document.registraSocio.Usuario.value="";
			document.registraSocio.ID.value="";
		  document.registraSocio.Password.value="";
	 }
	
}










function workaround()
{
 		xmlHttp = inicioAjax('calendario');
    xmlHttp.open("GET","entrada.asp"); 
	  xmlHttp.send('error='+1);
    xmlHttp = null;
}

function desconectar(error)
{
		xmlHttp = inicioAjax('calendario');
    xmlHttp.open("GET","entrada.asp"); 
	  xmlHttp.send('error='+error);
    xmlHttp = null;
    xmlHttp = inicioAjax('usuario');
    xmlHttp.open("POST","conectar.asp"); 
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlHttp.send('error='+error); 

}	



document.onclick = new Function("show(null)")

function getPos(el,sProp) {
	var iPos = 0
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos

}

function show(el,m,dia) {
	if (m) {
		m.style.display='';
    var ie = (document.all) ? true:false 
		var n6 = (document.getElementById) ? true:false 
		if(ie == true) 
    {

 	    document.getElementById("menu").style.left =	 ( (document.body.clientWidth -400) / 2 )+'px';
    } 
		else 
		{
		  document.getElementById("menu").style.left =  ((window.innerWidth - 400 ) / 2) +'px';
			
		}
		document.getElementById("diaMes").innerHTML = '<FONT COLOR = #FFFFFF SIZE = "6">Dia ' + dia + '</FONT>'; 
		//m.style.left = getPos(el,"Left") - 30 + 'px';
		//m.style.top = getPos(el,"Top") + el.offsetHeight - 40+ 'px';
	}

}



function compruebaUsuario(tipo)
{
	
   var ValidChars = "0123456789";
   var IsNumber=true;
	 var parametros = "";
 
   if (document.registraNuevoSocio.Usuario.value =="")
		{
		alert('Debes introducir un nombre de Usuario.');
 	        	 return;

		}
   if (document.registraNuevoSocio.Password.value =="" )
		{
		 return;
		}
   if (document.registraNuevoSocio.Password2.value =="" )
		{
                  alert('Debes repetir el password');
	 return;
		}
   if (document.registraNuevoSocio.email.value =="" )
		{
                  alert('Falta el Email!');
	 return;
		}
   if (document.registraNuevoSocio.nombre.value =="" )
		{
                  alert('Por favor, escribe tu nombre.');
	 return;
		} 
	 if (document.registraNuevoSocio.apellidos.value =="" )
		{
                  alert('Por favor, escribe tus apellidos.');
	 return;
		} 

	 if (document.registraNuevoSocio.fecnac.value =="" )
		{
		              alert('Por favor, introduce tu fecha de nacimiento.');
	 return;
		}
		if (document.registraNuevoSocio.fecnac.value.length != 10) 
		{
	    		alert('Por favor, introduce correctamentetu fecha de nacimiento.');
//		  IsNumber = false;
	 return;
		
		}
		
		if (document.registraNuevoSocio.fecnac.value.charAt(2) != '/') 
		{
	    alert('Por favor, introduce correctamente tu fecha de nacimiento.');
	 return;
		
		}
		if (document.registraNuevoSocio.fecnac.value.charAt(5) != '/') 
		{
	    alert('Por favor, introduce correctamente tu fecha de nacimiento.');
	 return;
		
		}
      
	 if (document.registraNuevoSocio.telefono.value =="" )
		{
                  alert('Por favor, introduce un telf. de contacto.');
	 return;
		} 
	 if (document.registraNuevoSocio.city.value =="" )
		{
                  alert('Por favor, introduce tu ciudad de residencia.');
	 return;
		} 
		 if (document.registraNuevoSocio.address.value =="" )
		{
                  alert('Por favor, introduce tu dirección.');
	 return;
		} 
		
   		
   if (document.registraNuevoSocio.Password.value != document.registraNuevoSocio.Password2.value )
		{
		  alert('Los passwords no coinciden');
	 return;
		}



	 
	  xmlHttp = inicioAjax('ventana');
   	   xmlHttp.open("POST","nuevoJugador3.asp"); 
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		
		for  ( var i = 0;i<document.registraNuevoSocio.elements.length;i++)
		{
		  //alert(document.registraNuevoSocio.elements[i].value.replace(/ /g,'%20')+ "param " + parametros);
      		  if(  (document.registraNuevoSocio.elements[i].type == "text" || document.registraNuevoSocio.elements[i].type == "password") && document.registraNuevoSocio.elements[i].value != "" ) {
		   parametros = parametros + document.registraNuevoSocio.elements[i].name + '=' + document.registraNuevoSocio.elements[i].value.replace(/ /g,'%20');
			 if (i!= document.registraNuevoSocio.elements.length -1) parametros = parametros + '&';
		  }
		}
		if (tipo=='nuevo')
		{
		 	 parametros = parametros + 'ID=0';
		}else{
		  parametros = parametros.substr(0,parametros.length-1);
		}
		//alert (parametros);
		xmlHttp.send(parametros); 
   
	
}


function administraNovatos()
{
   var ancho;
	
	if( typeof( window.innerWidth ) == 'number' ) {
   	ancho = window.innerWidth;
	} else if (document.documentElement &&  document.documentElement.clientWidth ) {
	   ancho = document.documentElement.clientWidth;
	} else  {
	   ancho = document.body.clientWidth;	
	}

    xmlHttp = inicioAjax('ventana');
    xmlHttp.open("POST","listaNovatos.asp"); 
    xmlHttp.send("ID=0");
    document.getElementById('ventana').style.left =  ((ancho - 900) / 2) +'px'
    document.getElementById('ventana').style.display='';
  	 
}


function asignaIDNovato(IDAnt,IDNew)
{

		//document.getElementById('ventana').style.display='';
    xmlHttp = inicioAjax('ventana');
    xmlHttp.open("POST","listaNovatos.asp"); 
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send('ID='+IDAnt+'&IDNew='+IDNew);
 
}





function sinAsistencia(IDAnt)
{

		//document.getElementById('ventana').style.display='';
    xmlHttp = inicioAjax('ventana');
    xmlHttp.open("POST","listaNovatos.asp"); 
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send('IDOld='+IDAnt);
 
}


function reAsistencia(IDAnt)
{
		//document.getElementById('ventana').style.display='';
    xmlHttp = inicioAjax('ventana');
    xmlHttp.open("POST","listaNovatos.asp"); 
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send('IDrea='+IDAnt);
}


function confirmaRegistroUsuario(ID,usu,pas,mail,firma,nom,cognom,NIF,fecnac,tele,addr,city,club,photo)
{
    parametros= 'ID='+ID+'&usu='+usu+'&pas='+pas+'&mail='+mail+'&firma='+firma+'&nom='+nom+'&cognom='+cognom+'&NIF='+NIF+'&fecnac='+fecnac+'&tele='+tele+'&addr='+addr+'&city='+city+'&club='+club+'&photo='+photo;
    //alert(parametros);
 
    xmlHttp = inicioAjax('ventana');
    xmlHttp.open("POST","registroDB.asp"); 
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send(parametros); 
}




function imprimeRegistroUsuario(numeroID)
{
 //alert('voy');
 window.open('impresionFicha.asp?ID=numeroID','nuevaVentana','width=400,height=400,menubar=no,status=no,toolbar=no,location=no,resizable=no');
// window.location.href = 'impresionFicha.asp?ID='+numeroID;
}

function ReimprimeRegistroUsuario(user,pass)
{
 //alert('voy');
 window.open('impresionFicha.asp?USU='+user+'&PAS='+pass,'nuevaVentana','width=400,height=400,menubar=no,status=no,toolbar=no,location=no,resizable=no');
// window.location.href = 'impresionFicha.asp?ID='+numeroID;
}
