//Contenido
var http_request = false;

function obtenerRequest() {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }
    }
    else if (window.ActiveXObject) { // IE
        try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) {}
        }
    }
    if (!http_request) {
        alert('Se ha producido un error. (objeto XMLHTTP)');
        return false;
    }
    return http_request;
}

function addContent() {
    if (http_request.readyState == 4) {
        var contenido       = document.getElementById('contenido');
        texto               = unescape(http_request.responseText);
        texto2              = texto.replace(/\+/gi," ");
        contenido.innerHTML = texto2;
    }
}

function cargar_contenido(url) {
    document.getElementById('contenido').innerHTML = '<br><br><br><br><br><center><img src="img/processbar.gif"><br><b>Cargando...</b></center><br><br><br><br><br>';
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addContent;
    http_request.open('GET', url, true);
    http_request.send(null);
}

function addPopupContent() {
    if (http_request.readyState == 4) {
        var popup = document.createElement("div");
        popup.id        = 'popup_id';
        popup.className = 'popup_amarillo';
        popup.innerHTML = http_request.responseText;
        var contenido = document.getElementById('contenido');
        contenido.appendChild(popup);
        if (document.forms[0]) document.forms[0].elements[0].focus();
        var thePopup   = document.getElementById('popup_id');
	Drag.init(thePopup);
    }
}

function popup(url) {
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addPopupContent;
    http_request.open('GET', url, true);
    http_request.send(null);
}

function validar_login_srv(user, pass) {
    if (user == "") return "Introduzca un usuario";
    if (pass == "") return "La contraseña es incorrecta";
    //Llamar a login.php
    if (user == "q") return "ok";
    else             return "Los datos son incorrectos";
}

//Funciones de estilo

function changeclass(tema,estilo) { e = document.getElementById(tema).className = estilo; }

function campo_erroneo(obj,img) {
    obj.style.borderColor = "red";
    obj.style.background  = "#ffdddd";
    document.getElementById(img).src = "img/cross.gif";
}

function campo_correcto(obj,img) {
    obj.style.borderColor = "#bbbbbb";
    obj.style.background  = "white";
    document.getElementById(img).src = "img/blanco.gif";
}

//Validaci¾n campos de formularios

function validar_campo_texto(obj,img) {
    var valor = obj.value;
    if (valor == "") { campo_erroneo(obj,img);  }
    else             { campo_correcto(obj,img); }
}

function validar_campo_email(obj,img) {
    var valor = obj.value;
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) { campo_correcto(obj,img);}
    else { campo_erroneo(obj,img);}
}

function validar_campo_email(obj) {
    var valor = obj.value;
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) { return true;}
    else { return false;}
}

function validar_fecha(obj,img) {
    var valor = obj.value;
}

function cargar_vista_previa(valor) {
    var img = document.getElementById('vista_previa');
    img.src = valor;
}

function ver_video(direccion) {
    var video = document.getElementById('cont_videos');
    video.innerHTML = '<object width="425" height="355"><param name="movie" value="' + direccion + '&rel=1"></param><param name="wmode" value="transparent"></param><embed src="' + direccion + '&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
}

function cargar_galeria(numero){
    var galeria = document.getElementById('galeria');
    galeria.innerHTML = '<center><br><br><b>Galería '+ numero +'</b><br><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7" width="600" height="400"><param name="movie" value="FotosFase'+ numero +'/fotos.swf?xml=FotosFase'+ numero +'/gallery.xml" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="FotosFase'+ numero +'/fotos.swf?xml=FotosFase'+ numero +'/gallery.xml" wmode="transparent" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="600" height="400"></embed></Object></center>';

}


function partido(categoria, equipos, hora, lugar) {
   return '<tr><td align="center">' + categoria + '</td><td align="center">' + equipos + '</td><td align="center">' + hora + '</td><td align="center">' + lugar + '</td></tr>';
}

function mostrar_horarios() {
texto = '<br>';
texto += '<center><b><font face="Verdana">SABADO 31 DE MAYO 2008</font></b></center><br>';
texto += '<table align="center" width="96%" class="tabla_plantillas">';
texto += '<tr bgcolor="#75A3ED"><td align="center"><b>CATEGORIA<b></td><td align="center"><b>PARTIDO</b></td><td align="center"><b>HORA</b></td><td align="center"><b>LUGAR</b></td></tr>';
texto += partido('SENIOR MASCULINO', 'El Pilar Marianistas - Donibane', '17:30h.', 'Marianistas');
texto += '</table>';
texto += '<br><br>';


//texto += '<center><b><font face="Verdana">SABADO 12 DE ABRIL 2008</font></b></center><br>';
//texto += '<table align="center" width="96%" class="tabla_plantillas">';
//texto += '<tr bgcolor="#75A3ED"><td align="center"><b>CATEGORIA<b></td><td align="center"><b>PARTIDO</b></td><td align="center"><b>HORA</b></td><td align="center"><b>LUGAR</b></td></tr>';
//texto += partido('INFANTIL MASCULINO', 'Mendebaldea - El Pilar Marianistas', '09:00h.', 'Pol. Europa');
//texto += partido('', '', '', '');
//texto += partido('JUVENIL FEMENINO', 'Valle del Oja - El Pilar Marianistas', '10:15h.', 'Pol. Europa');
//texto += partido('', '', '', '');
//texto += partido('ALEVIN MASCULINO', 'Luis Elejalde - El Pilar Marianistas', '12:00h.', 'Pol. El Campillo');
//texto += partido('', '', '', '');
//texto += partido('CADETE MASCULINO', 'El Pilar Marianistas - Calvete A', '10:00h.', 'Marianistas');
//texto += partido('', '', '', '');
//texto += partido('JUVENIL MASCULINO', 'El Pilar Marianistas - El Pilar Marianistas(Senior)', '18:00h.', 'Marianistas');
//texto += partido('', '', '', '');
//texto += partido('SENIOR MASCULINO', 'El Pilar Marianistas(Juvenil) - El Pilar Marianistas', '18:00h.', 'Marianistas');

//texto += '</table>';
//texto += '<br><br>';

//texto += '<center><b><font face="Verdana">DOMINGO 11 DE MAYO 2008</font></b></center><br>';
//texto += '<table align="center" width="96%" class="tabla_plantillas">';
//texto += '<tr bgcolor="#75A3ED"><td align="center"><b>CATEGORIA<b></td><td align="center"><b>PARTIDO</b></td><td align="center"><b>HORA</b></td><td align="center"><b>LUGAR</b></td></tr>';
//texto += partido('SENIOR MASCULINO', 'El Pilar Marianistas - Romo', '11:00h.', 'Marianistas');
//texto += '</table>';
//texto += '<br><br>';

Dialog.alert(texto, {top:170, windowParameters: {className:"alphacube", width:600, height:240}, 
                            okLabel:     "Aceptar"
                            });

  //alert("Los horarios de la siguiente jornada todavía no están disponibles.");
}

//VENTANA DE LOGIN

function cambiar_enlaces() {
    var enlaces = document.getElementById('enlaces_cuerpo');
    enlaces.innerHTML = '<div id="enlaces_cuerpo"><img src="img/usuario.gif"><span style="cursor: pointer; text-decoration: underline" onclick="cargar_contenido(&quot;panel_control.php&quot;);">Panel de control</span></div>';
}

function login() {
    texto = '<div id="login_msg">&nbsp;</div><br>';
    texto += '<table align="center">';
    texto += '<tr><td><img src="img/usuario.gif"/></td><td>Usuario:</td><td><input type="text" id="usuario" name="usuario" value=""></td></tr>';
    texto += '<tr><td colspan="2"><br></td></tr>';
    texto += '<tr><td><img src="img/key.gif"/></td><td>Contraseña:</td><td><input type="password" id="pass" name="pass" value=""></td></tr>';
    texto += '</table>';
    Dialog.confirm(texto, {top:160, windowParameters: {className:"alphacube", width:300}, 
              okLabel:     "Aceptar",
              cancelLabel: "Cancelar",
              ok:function(win) {
                  if (($('usuario').value == "") || ($('pass').value == "")) {
                        $('login_msg').className = 'error';
                        $('login_msg').innerHTML = 'Usuario incorrecto';
                        new Effect.Shake(Windows.focusedWindow.getId());
                        return false;
                    }
                    else {
                        $('login_msg').className = 'mensaje';
                        $('login_msg').innerHTML = 'Comprobando usuario...';
                        var t1, t2;
                        t1   = document.getElementById('usuario').value;
                        t2   = document.getElementById('pass').value;
                        ajax = obtenerRequest();
                        ajax.open("POST", "validar_usuario.php", true);
                        ajax.onreadystatechange=function() {
                            if (ajax.readyState==4) {
                            	if (ajax.status == 200) {
                            	    var resp = ajax.responseText;
                                    if (resp == 11) {
                                    	cargar_contenido('panel_control.php');
                                    	crear_ventana_foro();
                                    	cambiar_enlaces();
                                        Dialog.cancelCallback();
                                        return true;
                                    }
                                    else {
                                        $('login_msg').className = 'error';
                                        $('login_msg').innerHTML = 'Usuario incorrecto';
                                        new Effect.Shake(Windows.focusedWindow.getId());
                                        return false;
                                    }
                                }
                            }
                        }
                        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                        ajax.send("user="+escape(t1)+"&pass="+escape(t2));
                    }
                  
              }
             });
}


//VENTANA DE REGISTRO

function mostrar_alerta() {
texto_registro = '<table align="center" width="100%">';
texto_registro += '<tr><td valign="top"><img src="img/info.gif"></td><td><b>El usuario ha sido creado correctamente.</b><br><br><br><center>Puedes realizar cualquier cambio en los datos de usuario en el Panel de Control que aparece cuando te conectas.</center><br></td></tr>';
texto_registro += '</table>';
Dialog.alert(texto_registro, {top:170, windowParameters: {className:"alphacube", width:400, height:150}, 
                              okLabel:     "Aceptar"
                              
                             });

}

function registro() {
    texto  = '<div id="registro1" name="registro1">Para poder registrarte, es necesario que introduzcas los siguientes datos personales. Ten en cuenta que los campos que tienen asterisco (*) son obligatorios.';
    texto += '<br><br><div id="registro_msg" height="300px">&nbsp;</div><br/>';
    texto += '<table>';
    texto += '<tr><td>* Nombre:  </td><td><input type="text" id="nombre"   name="nombre" onBlur="validar_campo_texto(this,&quot;reg_img1&quot;);">&nbsp;<img id="reg_img1" src="img/blanco.gif"></td></tr>';
    texto += '<tr><td>* Apellido:</td><td><input type="text" id="apellido" name="apellido" size="36" onBlur="validar_campo_texto(this,&quot;reg_img2&quot;);"/>&nbsp;<img id="reg_img2" src="img/blanco.gif"></td></tr>';
    texto += '<tr><td>* Fecha Nacimiento:</td>';
    texto += '<td><select id="dia" name="dia">';
    texto += '<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>';
    texto += '<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>';
    texto += '<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>';
    texto += '<option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option>';
    texto += '<option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option>';
    texto += '<option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>';
    texto += '</select>';
    texto += '<select id="mes" name="mes">';
    texto += '<option value="1">Enero</option><option value="2">Febrero</option><option value="3">Marzo</option><option value="4">Abril</option>';
    texto += '<option value="5">Mayo</option><option value="6">Junio</option><option value="7">Julio</option><option value="8">Agosto</option>';
    texto += '<option value="9">Septiembre</option><option value="10">Octubre</option><option value="11">Noviembre</option><option value="12">Diciembre</option>';
    texto += '</select>';
    texto += '<select id="anio" name="anio">';
    for (var i = 1900; i < 2008; i++) {
        texto += '<option value="' + i + '">' + i + '</option>';
    }
    texto += '</select>';
    texto += '</td></tr>';
    texto += '<tr><td>* E-mail: </td><td><input type="text" id="email" name="email" size="36" onBlur="validar_campo_email(this,&quot;reg_img3&quot;);"/>&nbsp;<img id="reg_img3" src="img/blanco.gif"></td></tr>';
    texto += '<tr><td>* Usuario: </td><td><input type="text"     id="reg_user" name="reg_user" onBlur="validar_campo_texto(this,&quot;reg_img4&quot;);"/>&nbsp;<img id="reg_img4" src="img/blanco.gif"></td></tr>';
    texto += '<tr><td>* Password:</td><td><input type="password" id="reg_pass" name="reg_pass" onBlur="validar_campo_pass(this,&quot;reg_img5&quot;);"/>&nbsp;<img id="reg_img5" src="img/blanco.gif"></td></tr>';
    texto += '</table>';
    Dialog.confirm(texto, {top:160, windowParameters: {className:"alphacube", width:400}, 
              okLabel:     "Aceptar",
              cancelLabel: "Cancelar",
              ok:function(win) {
              	  if (($('nombre').value == "") || ($('apellido').value == "") || (validar_campo_email($('email').value))
              	  	|| ($('reg_user').value == "") || ($('reg_pass').value == "")) {
                        $('registro_msg').className = 'error';
                        $('registro_msg').innerHTML = 'Los datos no son correctos';
                        new Effect.Shake(Windows.focusedWindow.getId());
                        return false;
                   }
                   else {
                   	$('registro_msg').className = 'mensaje';
                        $('registro_msg').innerHTML = 'Registrando usuario...';
                        var t1, t2, t3, t4, t5, t6, t7, t8;
                        t1   = document.getElementById('nombre').value;
                        t2   = document.getElementById('apellido').value;
                        t3   = document.getElementById('dia').value;
                        t4   = document.getElementById('mes').value;
                        t5   = document.getElementById('anio').value;
                        t6   = document.getElementById('email').value;
                        t7   = document.getElementById('reg_user').value;
                        t8   = document.getElementById('reg_pass').value;
                        ajax = obtenerRequest();
                        ajax.open("POST", "registro.php", true);
                        ajax.onreadystatechange=function() {
                            if (ajax.readyState==4) {
                            	if (ajax.status == 200) {
                            	    var resp = ajax.responseText;
                            	    if (resp == 11) {
                            	    	Dialog.cancelCallback();
                            	    	setTimeout ("mostrar_alerta();", 1000);
                                        return true;
                                    }
                                    if (resp == 22) {
                            	        $('registro_msg').innerHTML = 'El usuario seleccionado ya existe.';
                                        $('registro_msg').className = 'error';
                                        new Effect.Shake(Windows.focusedWindow.getId());
                                        return false;
                                    }
                                    if (resp == 33) {
                            	        $('registro_msg').innerHTML = 'Error registrando al usuario';
                                        $('registro_msg').className = 'error';
                                        new Effect.Shake(Windows.focusedWindow.getId());
                                        return false;
                                    }
                                }
                            }
                        }
                        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                        ajax.send("nombre="+escape(t1)+"&apellido="+escape(t2)+"&dia="+t3+"&mes="+t4+"&anio="+t5+"&email="+escape(t6)+"&usuario="+escape(t7)+"&pass="+escape(t8));
                   }
              }
             });
}


//CAMBIAR DATOS

function quitar_imagen() {
    imagen_foro = document.getElementById('imagen_foro');
    imagen_foro.innerHTML = '<div id="main"><iframe src="upload.php" frameborder="0"></iframe></div>';
    document.getElementById('imagen').innerHTML = '';
}

function cambiar_foto(imagen,anchura,altura) {
//SIN ACABAR
    texto = '<div id="foto_msg">&nbsp;</div><br>';
    texto += '<table align="center">';
    texto += '<tr><td valign="top"><b>Imagen foro</b></td></tr><tr><td>';
    texto += '<div id="imagen" name="imagen"><img src="foro/imagenes/';
    texto += imagen;
    texto += '" border="0">';
    texto += '</div></td></tr>';
    texto += '<tr><td>&nbsp;</td></tr>';
    texto += '<tr><td><div id="imagen_foro" name="imagen_foro"><a href="javascript:quitar_imagen();">Quitar imagen</a></div></td></tr>';
    texto += '</table>';
    Dialog.confirm(texto, {top:160, windowParameters: {className:"alphacube", width:400, height:260}, 
              okLabel:     "Aceptar",
              cancelLabel: "Cancelar",
              ok:function(win) {
                  
	                    $('datos_msg').className = 'mensaje';
	                    $('datos_msg').innerHTML = 'Cambiando datos del usuario...';
	                    var t1, t2, t3, t4, t5, t6, t7;
	                    t1   = document.getElementById('nombre').value;
	                    t2   = document.getElementById('apellido').value;
	                    t3   = document.getElementById('dia').value;
	                    t4   = document.getElementById('mes').value;
	                    t5   = document.getElementById('anio').value;
	                    t6   = document.getElementById('email').value;
	                    ajax = obtenerRequest();
	                    ajax.open("POST", "cambiar_datos.php", true);
	                    ajax.onreadystatechange=function() {
	                        if (ajax.readyState==4) {
	                    	    if (ajax.status == 200) {
	                        	var resp = ajax.responseText;
	                                if (resp == 11) {
	                                    cargar_contenido('panel_control.php');
	                                    Dialog.cancelCallback();
	                                    return true;
	                                }
	                                else {
	                                    $('datos_msg').className = 'error';
	                                    $('datos_msg').innerHTML = resp;
	                                    new Effect.Shake(Windows.focusedWindow.getId());
	                                    return false;
	                                }
	                            }
	                        }
	                    }
	                ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	                ajax.send("nombre="+escape(t1)+"&apellido="+escape(t2)+"&dia="+t3+"&mes="+t4+"&anio="+t5+"&email="+escape(t6));
                    }
                  
             });
}



function datos_usuario(usuario,nombre,apellido,dia,mes,anio,email) {
    texto = '<div id="datos_msg">&nbsp;</div><br>';
    texto += '<table align="center">';
    texto += '<tr><td>Usuario:</td><td>';
    texto += usuario;
    texto += '</td></tr>';
    texto += '<tr><td colspan="2"><br></td></tr>';
    texto += '<tr><td>Nombre:</td><td><input type="text" id="nombre" name="nombre" size="40" value="';
    texto += nombre;
    texto += '" onBlur="validar_campo_texto(this,&quot;datos_img1&quot;);">&nbsp;<img id="datos_img1" src="img/blanco.gif"></td></tr>';
    texto += '<tr><td colspan="2"><br></td></tr>';
    texto += '<tr><td>Apellido:</td><td><input type="text" id="apellido" name="apellido" size="40" value="';
    texto += apellido;
    texto += '" onBlur="validar_campo_texto(this,&quot;datos_img2&quot;);">&nbsp;<img id="datos_img2" src="img/blanco.gif"></td></tr>';
    texto += '<tr><td colspan="2"><br></td></tr>';
    texto += '<tr><td>Fecha nacimiento:</td>';
    texto += '<td><select id="dia" name="dia">';
    texto += '<option value="1"'
    if (dia == 1) texto += 'selected';
    texto += '>1</option>';
    texto += '<option value="2"'
    if (dia == 2) texto += 'selected';
    texto += '>2</option>';
    texto += '<option value="3"'
    if (dia == 3) texto += 'selected';
    texto += '>3</option>';
    texto += '<option value="4"'
    if (dia == 4) texto += 'selected';
    texto += '>4</option>';
    texto += '<option value="5"'
    if (dia == 5) texto += 'selected';
    texto += '>5</option>';
    texto += '<option value="6"'
    if (dia == 6) texto += 'selected';
    texto += '>6</option>';
    texto += '<option value="7"'
    if (dia == 7) texto += 'selected';
    texto += '>7</option>';
    texto += '<option value="8"'
    if (dia == 8) texto += 'selected';
    texto += '>8</option>';
    texto += '<option value="9"'
    if (dia == 9) texto += 'selected';
    texto += '>9</option>';
    texto += '<option value="10"'
    if (dia == 10) texto += 'selected';
    texto += '>10</option>';
    texto += '<option value="11"'
    if (dia == 11) texto += 'selected';
    texto += '>11</option>';
    texto += '<option value="12"'
    if (dia == 12) texto += 'selected';
    texto += '>12</option>';
    texto += '<option value="13"'
    if (dia == 13) texto += 'selected';
    texto += '>13</option>';
    texto += '<option value="14"'
    if (dia == 14) texto += 'selected';
    texto += '>14</option>';
    texto += '<option value="15"'
    if (dia == 15) texto += 'selected';
    texto += '>15</option>';
    texto += '<option value="16"'
    if (dia == 16) texto += 'selected';
    texto += '>16</option>';
    texto += '<option value="17"'
    if (dia == 17) texto += 'selected';
    texto += '>17</option>';
    texto += '<option value="18"'
    if (dia == 18) texto += 'selected';
    texto += '>18</option>';
    texto += '<option value="19"'
    if (dia == 19) texto += 'selected';
    texto += '>19</option>';
    texto += '<option value="20"'
    if (dia == 20) texto += 'selected';
    texto += '>20</option>';
    texto += '<option value="21"'
    if (dia == 21) texto += 'selected';
    texto += '>21</option>';
    texto += '<option value="22"'
    if (dia == 22) texto += 'selected';
    texto += '>22</option>';
    texto += '<option value="23"'
    if (dia == 23) texto += 'selected';
    texto += '>23</option>';
    texto += '<option value="24"'
    if (dia == 24) texto += 'selected';
    texto += '>24</option>';
    texto += '<option value="25"'
    if (dia == 25) texto += 'selected';
    texto += '>25</option>';
    texto += '<option value="26"'
    if (dia == 26) texto += 'selected';
    texto += '>26</option>';
    texto += '<option value="27"'
    if (dia == 27) texto += 'selected';
    texto += '>27</option>';
    texto += '<option value="28"'
    if (dia == 28) texto += 'selected';
    texto += '>28</option>';
    texto += '<option value="29"'
    if (dia == 29) texto += 'selected';
    texto += '>29</option>';
    texto += '<option value="30"'
    if (dia == 30) texto += 'selected';
    texto += '>30</option>';
    texto += '<option value="31"'
    if (dia == 31) texto += 'selected';
    texto += '>31</option>';
    texto += '</select>';
    texto += '<select id="mes" name="mes">';
    if (mes == '01') texto += '<option value="01" selected>Enero</option>';
    else             texto += '<option value="01">Enero</option>';
    if (mes == '02') texto += '<option value="02" selected>Febrero</option>';
    else             texto += '<option value="02">Febrero</option>';
    if (mes == '03') texto += '<option value="03" selected>Marzo</option>';
    else             texto += '<option value="03">Marzo</option>';
    if (mes == '04') texto += '<option value="04" selected>Abril</option>';
    else             texto += '<option value="04">Abril</option>';
    if (mes == '05') texto += '<option value="05" selected>Mayo</option>';
    else             texto += '<option value="05">Mayo</option>';
    if (mes == '06') texto += '<option value="06" selected>Junio</option>';
    else             texto += '<option value="06">Junio</option>';
    if (mes == '07') texto += '<option value="07" selected>Julio</option>';
    else             texto += '<option value="07">Julio</option>';
    if (mes == '08') texto += '<option value="08" selected>Agosto</option>';
    else             texto += '<option value="08">Agosto</option>';
    if (mes == '09') texto += '<option value="09" selected>Septiembre</option>';
    else             texto += '<option value="09">Septiembre</option>';
    if (mes == '10') texto += '<option value="10" selected>Octubre</option>';
    else             texto += '<option value="10">Octubre</option>';
    if (mes == '11') texto += '<option value="11" selected>Noviembre</option>';
    else             texto += '<option value="11">Noviembre</option>';
    if (mes == '12') texto += '<option value="12" selected>Diciembre</option>';
    else             texto += '<option value="12">Diciembre</option>';
    texto += '</select>';
    texto += '<select id="anio" name="anio">';
    for (var i = 1900; i < 2008; i++) {
	if (anio == i) texto += '<option value="' + i + '" selected>' + i + '</option>';
        else           texto += '<option value="' + i + '">' + i + '</option>';
    }
    texto += '</select>';
    texto += '</td>';
    texto += '</tr>';
    texto += '<tr><td colspan="2"><br></td></tr>';
    texto += '<tr><td>E-mail:</td><td><input type="text" id="email" name="email" size="40" value="';
    texto += email;
    texto += '" onBlur="validar_campo_email(this,&quot;datos_img3&quot;);"/>&nbsp;<img id="datos_img3" src="img/blanco.gif"></td></tr>';
    texto += '<tr><td colspan="2"><br></td></tr>';
    texto += '</table>';
    Dialog.confirm(texto, {top:160, windowParameters: {className:"alphacube", width:450, height:300}, 
              okLabel:     "Aceptar",
              cancelLabel: "Cancelar",
              ok:function(win) {
                  if (($('nombre').value == "") || ($('apellido').value == "") || (validar_campo_email($('email').value))) {
                        $('datos_msg').className = 'error';
                        $('datos_msg').innerHTML = 'Los datos no son correctos';
                        new Effect.Shake(Windows.focusedWindow.getId());
                        return false;
                    }
                    else {
	                    $('datos_msg').className = 'mensaje';
	                    $('datos_msg').innerHTML = 'Cambiando datos del usuario...';
	                    var t1, t2, t3, t4, t5, t6, t7;
	                    t1   = document.getElementById('nombre').value;
	                    t2   = document.getElementById('apellido').value;
	                    t3   = document.getElementById('dia').value;
	                    t4   = document.getElementById('mes').value;
	                    t5   = document.getElementById('anio').value;
	                    t6   = document.getElementById('email').value;
	                    ajax = obtenerRequest();
	                    ajax.open("POST", "cambiar_datos.php", true);
	                    ajax.onreadystatechange=function() {
	                        if (ajax.readyState==4) {
	                    	    if (ajax.status == 200) {
	                        	var resp = ajax.responseText;
	                                if (resp == 11) {
	                                    cargar_contenido('panel_control.php');
	                                    Dialog.cancelCallback();
	                                    return true;
	                                }
	                                else {
	                                    $('datos_msg').className = 'error';
	                                    $('datos_msg').innerHTML = resp;
	                                    new Effect.Shake(Windows.focusedWindow.getId());
	                                    return false;
	                                }
	                            }
	                        }
	                    }
	                ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	                ajax.send("nombre="+escape(t1)+"&apellido="+escape(t2)+"&dia="+t3+"&mes="+t4+"&anio="+t5+"&email="+escape(t6));
                    }
                  
              }
             });

}

function cambiar_pass() {
    texto = '<div id="pass_msg">&nbsp;</div><br>';
    texto += '<table align="center">';
    texto += '<tr><td>Contraseña anterior:</td><td><input type="password" id="pass_anterior" name="pass_anterior" value=""></td></tr>';
    texto += '<tr><td colspan="2"><br></td></tr>';
    texto += '<tr><td>Contraseña nueva:</td><td><input type="password" id="pass_nueva" name="pass_nueva" value=""></td></tr>';
    texto += '<tr><td colspan="2"><br></td></tr>';
    texto += '<tr><td>Repetir contraseña nueva:</td><td><input type="password" id="pass_nueva2" name="pass_nueva2" value=""></td></tr>';
    texto += '</table>';
    Dialog.confirm(texto, {top:160, windowParameters: {className:"alphacube", width:300}, 
              okLabel:     "Aceptar",
              cancelLabel: "Cancelar",
              ok:function(win) {
                  if (($('pass_anterior').value == "") || ($('pass_nueva').value == "") || ($('pass_nueva2').value == "")) {
                        $('pass_msg').className = 'error';
                        $('pass_msg').innerHTML = 'Los datos no son correctos';
                        new Effect.Shake(Windows.focusedWindow.getId());
                        return false;
                    }
                    else {
                    	if ($('pass_nueva').value != $('pass_nueva2').value) {
                    	    $('pass_msg').className = 'error';
                            $('pass_msg').innerHTML = 'Los datos no son correctos';
                            new Effect.Shake(Windows.focusedWindow.getId());
                            return false;
                    	}
                        else {
                            $('pass_msg').className = 'mensaje';
                            $('pass_msg').innerHTML = 'Cambiando contraseña...';
                            var t1, t2, t3;
                            t1   = document.getElementById('pass_anterior').value;
                            t2   = document.getElementById('pass_nueva').value;
                            t2   = document.getElementById('pass_nueva2').value;
                            ajax = obtenerRequest();
                            ajax.open("POST", "cambiar_pass.php", true);
                            ajax.onreadystatechange=function() {
                                if (ajax.readyState==4) {
                            	    if (ajax.status == 200) {
                                	var resp = ajax.responseText;
                                        if (resp == 11) {
                                            Dialog.cancelCallback();
                                            return true;
                                        }
                                        else {
                                            $('pass_msg').className = 'error';
                                            $('pass_msg').innerHTML = resp;
                                            new Effect.Shake(Windows.focusedWindow.getId());
                                            return false;
                                        }
                                    }
                                }
                            }
                        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                        ajax.send("pass_anterior="+escape(t1)+"&pass_nueva="+escape(t2));
                      }
                    }
                  
              }
             });

}

//VENTANAS FORO


function addForumContent() {
    if (http_request.readyState == 4) {
        texto  = unescape(http_request.responseText);
        texto2 = texto.replace(/\+/gi," ");
        foro.getContent().innerHTML = texto2;
    }
}

function crear_ventana_foro() {
    foro = new Window('1', {className: "alphacube", title: "Foro", draggable:true, width:850, height:600, top:180, left:200});
}

function abrir_foro() {
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addForumContent;
    http_request.open('GET', 'foro_temas.php', true);
    http_request.send(null);
    foro.show();
}

function ver_respuestas(tema,pagina) {
    foro.getContent().innerHTML = '<br><br><br><br><br><br><br><br><center><img src="img/processbar.gif"><br><b>Cargando...</b></center>';
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addForumContent;
    http_request.open('GET', 'foro_respuestas.php?tema=' + tema + '&pag=' + pagina, true);
    http_request.send(null);
}

function ver_temas(pagina) {
    foro.getContent().innerHTML = '<br><br><br><br><br><br><br><br><center><img src="img/processbar.gif"><br><b>Cargando...</b></center>';
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addForumContent;
    http_request.open('GET', 'foro_temas.php?pag=' + pagina, true);
    http_request.send(null);
}

function ver_estadisticas() {
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addForumContent;
    http_request.open('GET', 'foro_estadisticas.php', true);
    http_request.send(null);
}


function addPerfilContent() {
    if (http_request.readyState == 4) {
        texto  = unescape(http_request.responseText);
        texto2 = texto.replace(/\+/gi," ");
        Dialog.alert(texto2, {top:170, windowParameters: {className:"alphacube", width:350, height:300}, 
              okLabel:     "Aceptar"
             });
    }
}

function ver_perfil(usuario) {
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addPerfilContent;
    http_request.open('GET', 'foro_perfil_usuario.php?usuario=' + usuario, true);
    http_request.send(null);    
}

//INSERTAR TEMA Y RESPUESTA



function insertar_tema(pag) {
    texto = '<div id="ins_tema_msg">&nbsp;</div><br>';
    texto += '<table border="0" width="90%" align="center">';
    texto += '<tr><td style="width:10px;"><b>Tema:</b></td><td align="left"><input type="text" size="50" id="tema" name="tema" onBlur="validar_campo_texto(this,&quot;tema_img1&quot;);"/>&nbsp;<img id="tema_img1" src="img/blanco.gif"></td></tr>';
    texto += '</table>';
    texto += '<iframe name="frame_tema" id="frame_tema" src="foro_insertar_tema.php" width="500px" height="260px" frameborder="0"></iframe>';
    Dialog.confirm(texto, {windowParameters: {className:"alphacube", width:500, Height:260 }, 
             okLabel: "Aceptar",
             cancelLabel: "Cancelar",
             ok:function(win){
             	 if ($('tema').value == "") {
                       $('ins_tema_msg').className = 'error';
                       $('ins_tema_msg').innerHTML = 'El tema no puede estar vacío.';
                       new Effect.Shake(Windows.focusedWindow.getId());
                       return false;
             	 }
             	else{
             	   t1 = window.parent.frames[0].document.getElementById('tema');
             	   t1.value = $('tema').value;
             	   t2 = window.parent.frames[0].document.getElementById('formu');
             	   t2.submit();
             	   alert("El tema ha sido introducido correctamente");
             	   ver_temas(pag);
             	   return true;
             	}
             }
            });
}



function insertar_resp(tema,pag) {
    texto = '<iframe name="frame_resp" id="frame_resp" src="foro_insertar_respuesta.php?tema=' + tema + '" width="500px" height="260px" frameborder="0"></iframe>';
    Dialog.confirm(texto, {windowParameters: {className:"alphacube", width:500, Height:260 }, 
             okLabel: "Aceptar",
             cancelLabel: "Cancelar",
             ok:function(win){ 
             	   t1 = window.parent.frames[0].document.getElementById('formu');
             	   t1.submit();
             	   alert("La respuesta ha sido introducida correctamente");
             	   ver_respuestas(tema,pag);
             	   return true;
             }
            });
}


//VER PLANTILLAS


function addTeamsContent() {
    if (http_request.readyState == 4) {
        texto  = unescape(http_request.responseText);
        texto2 = texto.replace(/\+/gi," ");
        plantillas.getContent().innerHTML = texto2;
    }
}

function crear_ventana_plantillas() {
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addTeamsContent;
    http_request.open('GET', 'plantillas.php', true);
    http_request.send(null);
    plantillas = new Window('2', {className: "alphacube", title: "Plantillas", draggable:true, width:850, height:600, top:180, left:200});
}




function addTeamsRightContent() {
    if (http_request.readyState == 4) {
        texto  = unescape(http_request.responseText);
        texto2 = texto.replace(/\+/gi," ");
        contenido_plantillas.innerHTML = texto2;
    }
}


function plantilla_foto(categoria) {
    contenido_plantillas.innerHTML  = "<br><br><br><br><br><table align='center' width='100%'><tr><td><img src='img/processbar.gif'><br><b>Cargando...</b></td></tr></table>";
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addTeamsRightContent;
    http_request.open('GET', 'plantillas_foto.php?categoria=' + categoria, true);
    http_request.send(null);    
}


function plantilla_fichas(categoria) {
    contenido_plantillas.innerHTML  = "<br><br><br><br><br><table align='center' width='100%'><tr><td><img src='img/processbar.gif'><br><b>Cargando...</b></td></tr></table>";
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addTeamsRightContent;
    http_request.open('GET', 'plantillas_fichas.php?categoria=' + categoria, true);
    http_request.send(null);    
}

function plantilla_calendario(categoria) {
    contenido_plantillas.innerHTML  = "<br><br><br><br><br><table align='center' width='100%'><tr><td><img src='img/processbar.gif'><br><b>Cargando...</b></td></tr></table>";
    http_request                    = obtenerRequest();
    http_request.onreadystatechange = addTeamsRightContent;
    http_request.open('GET', categoria, true);
    http_request.send(null);    
}

//Apertura de las ventanas

function mostrar_emoticons() {
    var emo = document.getElementById('emoticons');
    if (emo.style.display == "none") {
    	emo.style.display = "block";
    }
    else emo.style.display = "none";
}





//WindowCloseKey.init();                