/*Funcion para crear el objeto de AJAX*/
function _creaXML(){
    var xmlhttp=false;
    if (window.XMLHttpRequest)  {// code for all new browsers
        xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject) {// code for IE5 and IE6
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlhttp;
}
function isset(variable_name) {
    try {
        if (typeof(eval(variable_name)) != 'undefined')
            if (eval(variable_name) != null)
                return true;
    } catch(e) { }
    return false;
}

function destruye_ajax(){
    document.body.removeChild(document.getElementById('negra'));
    document.getElementById('pop').parentNode.removeChild(document.getElementById('pop'));
}

function muestra_ajax(o,u,metodo,sincapas,muestrafinal,capaPrioritaria){
   
    cposcura=document.createElement('div');
    cposcura.id='negra';
    cpmensaje=document.createElement('div');
    cpmensaje.id='pop';
    cposcura.onclick=destruye_ajax;
    if(sincapas){
        if(capaPrioritaria){
            cpmensaje=capaPrioritaria;
        }
        else{
            cpmensaje=o;
        }
    }
	
	
    var xmlhttpa=_creaXML();
    pgsol=u;
    if(metodo){
        xmlhttpa.open(metodo,pgsol,true);
        valores='video='+document.getElementById("name_video").value;
        var i=0;
    /*	for(i=0;i<o.elements.length;i++){
			if(o.elements[i].name){
				valores+='&'+o.elements[i].name+'='+o.elements[i].value;
			}
		}*/
				
    }
    else{
        xmlhttpa.open("get",pgsol,true);
    }
    xmlhttpa.onreadystatechange=function(){
        if(xmlhttpa.readyState==4){
            txtres=xmlhttpa.responseText;
            cpmensaje.innerHTML=txtres;
            if(muestrafinal && txtres && txtres.indexOf('centradito')==-1){
                muestrafinal.style.display='';
            }
        }
    }
	
    if(metodo){
        xmlhttpa.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttpa.send(valores);
    }
    else{
        xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
        xmlhttpa.send(null);	
				
    }
    if(!sincapas){
        cpmensaje.style.top='0px';
        //o.appendChild(cpmensaje);
        cpmensaje.style.left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
        cpmensaje.style.top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
        document.body.appendChild(cposcura);
        document.body.appendChild(cpmensaje);
		
		
		
    }
    return false;
}
/*
if(window.addEventListener){
	window.addEventListener('load',setfunctional,false);
}
else if(window.attachEvent){
	window.attachEvent('onload',setfunctional);
}
*/




function send_video()
{
    var enviar="ok";
    document.getElementById("error_campo1").innerHTML="";
    document.getElementById("error_campo2").innerHTML="";
    if(document.getElementById("urlyoutube").value=="")
    {
        document.getElementById("error_campo1").innerHTML='<p class="info_panel error">El campo Url del vídeo es obligatorio.</p>';
        enviar="ko";
    }
    if(document.getElementById("titulo_video").value=="")
    {
        document.getElementById("error_campo2").innerHTML='<p class="info_panel error">El campo título del vídeo es obligatorio.</p>';
        enviar="ko";
    }
    if(enviar=="ok")
    {
        document.enviovideo_form.submit();
    }
}

function setfunctional(){
	
    /* Capas ajax*/
    if(document.getElementById("masinfoLnk")){
        var domdiv = document.getElementById("divpop");
        document.getElementById("masinfoLnk").onclick=function(){
            return muestra_ajax(domdiv,this.href);
        }
    }
	
    if(document.getElementById("masinfoLnk2")){
        var domdiv = document.getElementById("divpop");
        document.getElementById("masinfoLnk2").onclick=function(){
            return muestra_ajax(domdiv,document.getElementById("masinfoLnk").href);
        }
    }
	
    if(document.getElementById("enviovideoLnk")){
        var domdiv = document.getElementById("divpop");
        document.getElementById("enviovideoLnk").onclick=function(){
            return muestra_ajax(domdiv,this.href,"post");
        }
    }	
	
    if(document.getElementById("subevideo")){
        var domdiv = document.getElementById("divpop");		
        document.getElementById("subevideo").onclick=function(){
            return muestra_ajax(domdiv,document.getElementById("masinfoLnk").href);
        }
    }
	
    /*$("#menucontacto").click(function() {
        var domdiv = document.getElementById("divpop");
        return muestra_ajax_contacto(domdiv,document.getElementById("menucontacto").href);
    });*/

    $("#olvido_usuario").click(function() {
        var domdiv = document.getElementById("divpop");
        return muestra_ajax(domdiv,this.href);
    });
	
    $("#olvido_password").click(function() {
        var domdiv = document.getElementById("divpop");
        return muestra_ajax(domdiv,this.href);
    });
	
    $(".denunciar_video").click(function() {
        var domdiv = document.getElementById("divpop");
        return muestra_ajax(domdiv,this.href);
    });	
	
    $("#denunciar_video").click(function() {
        var domdiv = document.getElementById("divpop");
        return muestra_ajax(domdiv,this.href);
    });	
	
    //Enlace a bases legales en todos los banners
    $(".promo_promovideos").append('<span class="consultabases">* Consultar características en estas <a href="/index.php/danet/bases_legales/basescomoconseguir" target="_blank">Bases Legales videos</a> y estas <a href="/index.php/danet/bases_legales/promovideos" target="_blank">Bases Legales votos y comentarios</a></span>');
    $(".promo_promoyoutube").append('<span class="consultabases">* Consultar características en <a href="/index.php/danet/bases_legales/basescomoconseguir" target="_blank">Bases Legales</a></span>');
    $(".promo_quieroganarhoy").append('<span class="consultabases">* Consultar características en <a href="/index.php/danet/bases_legales/quieroganarhoy" target="_blank">Bases Legales</a></span>');

}

function _Llamada_Ajax(url,IdForm,divResp)
{ 
 
    var id=IdForm;
    var txt=$(id).serialize();
    // var txt=$("#form_olvido_password").serialize();
    // alert(txt);

    /// Invocamos a nuestro script PHP
    $.post(url, txt, function(data){
        $(divResp).html(data);
    }); 
	
}


function _Llamada_Ajax_nova(url,IdForm,divResp)
{ 
 
    var id=IdForm;
    var txt=$(id).serialize();
    // var txt=$("#form_olvido_password").serialize();
    // alert(txt);

    /// Invocamos a nuestro script PHP
   /* $.ajax(url, txt, function(data){
        $(divResp).html(data);
    }); */
    
    $.ajax({
          type: "POST",
          url: url,
          data: txt,
        success: function(data){
            
           $(divResp).html(data);
             }
        });
        
 
	
}

function muestra_ajax_contacto(url1)
{
   var domdiv = document.getElementById("divpop");
       return muestra_ajax_cont(domdiv,url1);

    var left=parseInt((document.documentElement.clientWidth/2)-250)+'px';
    var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/10)+'px';

	 $.ajax({
        type: "GET",
        url: url1,
        data: "",
        success: function(datos){
		
        document.getElementById("mensaje_logeado_pin"). innerHTML='<div id="negra" onclick="javascript:delete_ajax();"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';">'+datos+'</div></div>';	
      		
        }
    });			
    
        		

}
function _Llamada_Ajax_re(url,IdForm,divResp)
{ 
 
    var id=IdForm;
    var txt="enviar=ok";
    // var txt=$("#form_olvido_password").serialize();
    // alert(txt);

    /// Invocamos a nuestro script PHP
    $.post(url, txt, function(data){
        $(divResp).html(data);
    }); 
	
}




function mas_info_ajax(url)
{
	
    _Llamada_Ajax_re(url,"","#respuesta")
	
}

function olvido_password()
{
    if ( (!document.getElementById('respuesta_olvidoCapa'))&&((document.getElementById('literalCid_olvido').value=='')))
    {
        document.getElementById('pregunta_olvido').innerHTML="<div class='info_panel error_msg'>Es necesario introducir un usuario</div>";
    }
    else
    {
        if((document.getElementById('literalCid_olvido').value!='')&&(!document.getElementById('respuesta_olvidoCapa'))){
            document.getElementById('pregunta_olvido').innerHTML="<div class='info_panel error'>Es necesario Recordar Pregunta Secreta</div>";
		
        }else
        {
            if (document.getElementById('respuesta_olvidoCapa').value == "") {
                document.getElementById('pregunta_olvido').innerHTML="<div class='info_panel error'>Es necesario introducir un Respuesta</div>";
            }
            else {
              
                _Llamada_Ajax_nova($("#form_olvido_password").attr("action"), '#form_olvido_password', '#respuesta');
			
            }
        }
    }
	
}


function contactar()
{
    $("#_nombre").css("display","none");
    $("#_mail").css("display","none");
    $("#_mensaje").css("display","none");
    $("#_condiciones").css("display","none");
    var envio="ok";

    if (document.getElementById('contacto_nombre').value == "") {
        document.getElementById('_nombre').innerHTML="<div class='info_panel error'>Es necesario añadir un"+(($(".nombre").text()).replace('>','')).replace(':','')+"</div>";
        $("#_nombre").css("display","block");
        envio="ko";
    }
    if (document.getElementById('contacto_mail').value == "") {
        $("#_mail").css("display","block");
        document.getElementById('_mail').innerHTML="<div class='info_panel error'>Es necesario añadir un "+(($(".mail").text()).replace('>','')).replace(':','')+"</div>";
        envio="ko";
    }
    if ($('#contacto_mensaje').val() == "") {
        $("#_mensaje").css("display","block");
        document.getElementById('_mensaje').innerHTML="<div class='info_panel error'>Es necesario escribir un "+(($(".mensaje").text()).replace('>','')).replace(':','')+"</div>";
        envio="ko";
    }
    if (document.getElementById('contacto_condiciones').checked == false) {
        $("#_condiciones").css("display","block");
        document.getElementById('_condiciones').innerHTML="<div class='info_panel error'>Es necesario aceptar el envío de datos personales.</div>";
        envio = "ko";
    }

    if (envio == "ok") {
        //_Llamada_Ajax('../danet/contacto_AJAX', '#contacto_form', '#respuesta');
        document.contacto.submit();
    }
}

function preguntausuario(literalCid) {
    alert(literalCid);
    if (literalCid == "") {
        $("#errores").addClass("info_panel");
        $(".info_panel").html("mensaje error");
    } else {
        $(".info_panel").html("");
        $("#errores").removeClass("info_panel");
			
			
        //	$("#recuerda_pregunta").click(function(e) {
        var xmlhttpa=_creaXML();
        //		e.preventDefault();
        if(xmlhttpa) {
				 
            xmlhttpa.open("GET","http://localhost/danet/index.php/registro/check_pregunta/"+literalCid,true);
            xmlhttpa.onreadystatechange = function(){
                if (xmlhttpa.readyState == 4 && xmlhttpa.status == 200) {
                    document.getElementById("pregunta_olvido").innerHTML = xmlhttpa.responseText;
                }
            }
            xmlhttpa.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlhttpa.send();
				 
        } 	
    //	});
    }
}


jQuery(document).ready(function($) {
	
    setfunctional();
	
    /*$("a.validar_pincode_ajax_1").click(function (e) { 
		e.preventDefault();
		$("#mensaje_validacion_1").load($(this).attr("href"), { 
		'pincode': $("#pincode_1").val() } );
	
	});*/
	
	
	

    $("a.refrescar_captcha_ajax").click(function (e) { 
        document.getElementById("captcha").value="";
        e.preventDefault();
        $("#captcha_image").load($(this).attr("href"));
		
    });
// Interceptamos el evento submit
	
});


function delete_ajax(){

    document.getElementById('negra').parentNode.removeChild(document.getElementById('negra'));
    document.getElementById('pop').parentNode.removeChild(document.getElementById('pop'));
}

function delete_ajax_cont(){

    document.getElementById('negra').parentNode.removeChild(document.getElementById('negra'));
    document.getElementById('popcont').parentNode.removeChild(document.getElementById('popcont'));
}

function validar_pincode(url,id){
    pincode++;
    $.ajax({
        type: "POST",
        url: url+"index.php/pincodes/validar_pincode/",
        data: "pincode="+$("#pincode_"+id).val(),
        success: function(datos){
				
            //document.getElementById("mensaje_validacion_"+id).innerHTML=datos;
			
			
            if(datos.search('mensaje')!= -1) 
            {
                $(".x_cerrar").attr("src",url+"images/OK_Verde.png");
                //nueva_fila(pincode);
                document.getElementById("h_pincodes_"+id).value="true";
                document.getElementById("pincode_"+id).readOnly = true;
                document.getElementById("ok_pincode_1").innerHTML=datos;
			
                $("#ok_pincode_1").css("display","block");
                $("#ok_pincode_1").css("color","green");
                $("#ok_pincode_1").css("font-size","24px");
                $("#ok_pincode_1").css("padding-top","1px");
		
                $(".ok_cerrar").css("display","block");
			
            //$('.x_cerrar').removeAttr('onclick');
			
            //var original_onclick = $('.x_cerrar').attr('onclick');
            /*	$('.x_cerrar').removeAttr('onclick').click(function(){
				//showConfirm(original_onclick);
			});
			
			$('#error_pincode_1').removeAttr('onclick').click(function(){
				//showConfirm(original_onclick);
			});
			*/			
		
            /*	$('.x_cerrar').click(function() {
  					
				});
				$('#error_pincode_1').click(function() {
  					 
				});*/
		
            }
            if(datos.search('error')!= -1) 
            {	
                document.getElementById("h_pincodes_"+id).value="false";
                document.getElementById("pincode_"+id).readOnly = false;
                document.getElementById("pincode_"+id).value = "";
                //document.getElementById("pincode_1").value=datos;
		
                document.getElementById("error_pincode_1").innerHTML=datos;
                $("#error_pincode_1").css("display","block");
                $(".x_cerrar").css("display","block");
			
                $('.x_cerrar').click(function() {
                    borrador_capa();
                });
                $('#error_pincode_1').click(function() {
                    borrador_capa();
                });
			
            }
			
            if(datos.search('horario')!= -1) 
            {	
                var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
                var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
		
                document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p>'+datos+'</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';		
			
            }
			
        //document.getElementById("error_pincode_1").innerHTML="";
					
        }
    });
	
}

function addPlaylist(url,id_video){
	
    $.ajax({
        type: "POST",
        url: url+"index.php/danet/addPlaylist",
        data: "id_video="+id_video,
        success: function(datos){
				
            document.getElementById("mensaje_logeado").innerHTML='<div id="negra"></div><div id="pop" style="top: 25%; left: 394px;"><div class="msg_ajax">	<h6><small>&gt;</small> INFO</h6><p>'+datos+'</p><div class="ajax_botones centrado"> <img src="'+url+'/images/aceptar_img.gif" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';
			
        }
    });
	
}

function delPlaylist(url,id_video){
    var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
    var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
    $.ajax({
        type: "POST",
        url: url+"index.php/danet/delPlaylist",
        data: "id_video="+id_video,
        success: function(datos){
				
            document.getElementById("mensaje_logeado").innerHTML='<div id="negra"></div><div id="pop" style="top: '+top+'; left: '+left+'"><div class="msg_ajax">	<h6><small>&gt;</small> INFO</h6><p>'+datos+'</p><div class="ajax_botones centrado"> <img src="'+url+'/images/aceptar_img.gif" onclick="javascript:location.href=\''+url+'index.php/danet/playlist\';" class="boton_popup" style="cursor: pointer;"> </div></div></div>';
				
        }
    });
	
}



function men_logeado(url)
{
		
    var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
    var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
	
    document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p>¡Un momento!Antes de participar tienes que entrar con tu nombre de usuario y tu contraseña. Y si aún no tienes cuenta, regístrate en la página de Danet ¡es muy fácil!¡Suerte!</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';		
				
	
}

function men_promos(url)
{
		
    var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
    var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
	
    document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p style="font-size: 18px;">No hay promoción pincodes activa. Entérate pulsando en la imagen, como ganar 50.000 €</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';		
				
	
}



function men_logeado_codigos(url)
{
		
    var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
    var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
		
    document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p>¡Un momento!Antes de participar tienes que entrar con tu nombre de usuario y tu contraseña. Y si aún no tienes cuenta, regístrate en la página de Danet ¡es muy fácil!¡Suerte!</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';
	
}

function nueva_fila(id){
	
    if(document.getElementById("tpincodes").rows.length<6){

        var table = document.getElementById("tpincodes");

        var row = table.getElementsByTagName("TBODY")[0].cloneNode(true);

        table.appendChild(row);


        for(i=0;i<row.getElementsByTagName("input").length;i++)
        {
            row.getElementsByTagName("input")[0].setAttribute("name","pincode_"+id);
            row.getElementsByTagName("input")[0].setAttribute("id","pincode_"+id);
            document.getElementById("pincode_"+id).readOnly = false;
	
            row.getElementsByTagName("a")[0].setAttribute("name",id);
            row.getElementsByTagName("a")[0].className="validar_pincode_ajax_"+id;
	
            row.getElementsByTagName("div")[0].setAttribute("id","mensaje_validacion_"+id);

            row.getElementsByTagName("input")[0].value="";
	
            row.getElementsByTagName("input")[1].setAttribute("name","h_pincodes_"+id);
            row.getElementsByTagName("input")[1].setAttribute("id","h_pincodes_"+id);
            row.getElementsByTagName("input")[1].value="false";
	
            document.getElementById("mensaje_validacion_"+id).innerHTML="";	
	


        }


    }else
    {
// alert("no puedes añadir mas hijos");
}

}

function borrar_filas_pin()
{
    document.getElementById("pincode_1").readOnly = false;
    document.getElementById("h_pincodes_1").value = "false";
	 
    var table = document.getElementById("tpincodes");
   
    for(var i = table.rows.length - 1; i > 0; i--)
   
    {
   
            table.deleteRow(i);
   
        }
	  
	  
}


/*
function validos(url)
{
	var txt=$('#asignar_pincode_form').serialize();
	var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
	var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
	$.ajax({
			type: "POST",
			url: url+"index.php/danet/validar_pincodes",
			data: txt,
			success: function(datos){
			
			if(datos.search("cambio_pantalla_3")!=-1){
			//document.getElementById("error_pincode").innerHTML="<div id='info_wrapper' class='info_wrapper'>"+datos+"</div>";		
			
			datos= datos.replace("cambio_pantalla_3","");
			
				
				document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p>'+datos+'</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';	
				$("#ok_pincode_1").css("display","none");
			$(".ok_cerrar").css("display","none");
					
			
			}else{	if(datos.search("cambio_pantalla_2")!=-1){
				datos= datos.replace("cambio_pantalla_2","");
			//document.getElementById("error_pincode").innerHTML="<div id='info_wrapper' class='info_wrapper'>"+datos+"</div>";		
			
		
				document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p>'+datos+'</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';	
				
			
			$("#ok_pincode_1").css("display","none");
			$(".ok_cerrar").css("display","none");
				}else{
					
//				document.getElementById("error_pincode").innerHTML="<div id='info_wrapper' class='info_wrapper'>"+datos+"</div>";			

				document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p>'+datos+'</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';		
				
				
				$("#ok_pincode_1").css("display","none");
			$(".ok_cerrar").css("display","none");	
				}
			}
					
			//document.getElementById("validados").value="false";
			if (datos.search("error")==-1){
				for(i=1;i<7;i++){
					var obj = document.getElementById("pincode_"+i); 
					var obj1 = document.getElementById("mensaje_validacion_"+i); 
					
				/*	if (isset(obj)) 
					{
						obj.value="";
						obj.readOnly = "false";
					}
					
					if (isset(obj1)) 
					{
						obj1.innerHTML="";
					}
				}
				
				//borrar_filas_pin();	
				pincode=1;
			//	actualizar_puntos(url);
				refesco_cap(url);
				document.getElementById("captcha").value=""; 
				document.getElementById("pincode_1").value=""; 
				document.getElementById("pincode_1").readOnly = false;
				$(".x_cerrar").attr("src",url+"images/x_cerrar.png");
				$("#error_pincode_1").css("display","none");
				$(".x_cerrar").css("display","none");
				$('.x_cerrar').click(function() {
  					 borrador_capa();
				});
				$('#error_pincode_1').click(function() {
  					 borrador_capa();
				});
				$("#error_pincode_1").css("color","red");
			$("#error_pincode_1").css("font-size","13px");
			$("#error_pincode_1").css("padding-top","6px");
			$("#ok_pincode_1").css("display","none");
			$(".ok_cerrar").css("display","none");
				
				
					
			  }
		}
	});
} */

function validos(url)
{
    var txt=$('#asignar_pincode_form').serialize();
    var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
    var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
    if($("#h_pincodes_1").val()=="true"){
        $.ajax({
            type: "POST",
            url: url+"index.php/danet/validar_pincodes",
            data: txt,
            success: function(datos){
			
				
                document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p>'+datos+'</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';	
				
		if(datos.indexOf("CARACTERES INCORRECTOS")!= -1 ){
                   
                }else{
                    
                     document.getElementById("pincode_1").value=""; 
                     document.getElementById("pincode_1").readOnly = false;
                      $("#ok_pincode_1").css("display","none");
                        $(".ok_cerrar").css("display","none");
                          $("#ok_pincode_1").css("display","none");
                        $(".ok_cerrar").css("display","none");
                        $("#h_pincodes_1").val("false");
                }	
             
                //borrar_filas_pin();	
                pincode=1;
                //	actualizar_puntos(url);
                refesco_cap(url);
                
                document.getElementById("captcha").value=""; 
                 
                $(".x_cerrar").attr("src",url+"images/x_cerrar.png");
                 
                $("#error_pincode_1").css("display","none");
                 
                $(".x_cerrar").css("display","none");
                 
                $('.x_cerrar').click(function() {
                    borrador_capa();
                });
               
                $('#error_pincode_1').click(function() {
                    borrador_capa();
                });
               
                $("#error_pincode_1").css("color","red");
                 
                $("#error_pincode_1").css("font-size","13px");
                 
                $("#error_pincode_1").css("padding-top","6px");
              
		
            }
        });
	
    }else{
        document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p style="font-size:18px;">Necesitas validar primero los codigos pin.</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';	
				
    }
}



function actualizar_puntos(url)
{
	
    $.ajax({
        type: "POST",
        url: url+"index.php/danet/refrescar_contador",
        data: "",
        success: function(datos){
            document.getElementById("participaciones").innerHTML=datos;
        }
    });
}

function mas_1000(url)
{
		
    var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
    var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
		
    document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style="top:'+top+'; left: '+left+';"><div class="msg_ajax">	<h6><small>&gt;</small> Atención</h6><p>Has sobrepasado los 1.000 puntos permitidos en Gananones. <br/> Hasta el día 1 del próximo mes no podrás seguir introduciendo tus puntos.<br/> <br/>  Equipo Gananones.</p><div class="ajax_botones centrado"> <img src="'+url+'/images/aceptar_img.gif" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';
	
}

function refesco_cap(url)
{
	
    $.ajax({
        type: "POST",
        url: url+"index.php/danet/refrescar_captcha",
        data: "",
        success: function(datos){
            document.getElementById("captcha_image").innerHTML=datos;
			
        }
    });
}


function men_puesto(url)
{
		
    var left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
    var top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/4)+'px';
    $.ajax({
        type: "POST",
        url: url+"index.php/danet/puesto",
        data: "",
        success: function(datos){
            document.getElementById("mensaje_logeado_pin").innerHTML='<div id="negra"></div><div id="pop" style=" background-color: transparent;top:'+top+'; left: '+left+';"><div class="msg_ajax_new"><p>'+datos+'</p><div class="ajax_botones centrado"> <img src="'+url+'/images/new_aceptar.png" onclick="javascript:delete_ajax();" class="boton_popup" style="cursor: pointer;"> </div></div></div>';		
				
        }
    });	
	
	
}

function borrador_capa()
{
    $("#error_pincode_1").css("display","none");
    $(".x_cerrar").css("display","none");
}

function ga_ant()
{
    var total=$(".icarrusel").css("width");
    total=total.replace("px","");
    var recorrido=$(".icarrusel").css("margin-left");
    recorrido = recorrido.replace("px","");
    recorrido=recorrido-(-77);
    if(recorrido <= 0){
        $(".icarrusel").css("margin-left",recorrido+"px");
    }
	
	
}

function ga_sig()
{
	
    var total=$(".icarrusel").css("width");
    total=total.replace("px","");
    var recorrido=$(".icarrusel").css("margin-left");
    recorrido = recorrido.replace("px","");
    recorrido=recorrido-77;
	
    if(Math.abs(recorrido) <= total-460){
		
        $(".icarrusel").css("margin-left",recorrido+"px");
    }
}

function c_foto(obj,id,url)
{
    id_foto=id;
    valor=obj.src;
    valor=valor.replace("thumb/","");
	
    $.ajax({
        type: "POST",
        url: url+"index.php/danet/dato_ganador",
        data: "idfoto="+id,
        success: function(msg){
		
            $(".texo_img_gan").html(msg);
        }
    });
	
	
    $("#imagen_ganador").attr("src",valor);
}

function bajar_img(url)
{	

    if(id_foto>=2){

        id_foto--;
        $.ajax({
            type: "POST",
            url: url+"index.php/danet/dato_ganador",
            data: "idfoto="+id_foto,
            success: function(msg){
		
                $(".texo_img_gan").html(msg);
            }
        });
	
        $("#imagen_ganador").attr("src",url+"images/ganadores/"+id_foto+".jpg");

    }
}

function subir_img(url)
{
    if(id_foto<=9){
	
        id_foto++;
        $.ajax({
            type: "POST",
            url: url+"index.php/danet/dato_ganador",
            data: "idfoto="+id_foto,
            success: function(msg){
		
                $(".texo_img_gan").html(msg);
            }
        });
	
        $("#imagen_ganador").attr("src",url+"images/ganadores/"+id_foto+".jpg");
    }
}

$(document).ready( function(){
    $('#aceptar_boton').live('click', function(){
        olvido_password();
    });
});

function validar(idiomas){
	idioma=idiomas;
	fr = document.registro;
			

	if (!fr.aviso.checked){
		if(idioma=='ca'){alert("Has d'acceptar l'avís legal");}
		else{alert("Debes aceptar el aviso legal");}
		return;
	}
	
	if (!fr.nombre.value){
		if(idioma=='ca'){alert("Introdueix el nom");}
		else{alert("Introduce un nombre");}
		fr.nombre.focus();
		return;
	}
	if (!fr.apellido.value){
		if(idioma=='ca'){alert("Introdueix el primer cognom");}
		else{alert("Introduce el primer apellido");}
		fr.apellido.focus();
		return;
	}

	if (fr.provincia.value==0){
		if(idioma=='ca'){alert("Introdueix una província");}
		else{alert("Introduce una provincia");}
		return;
	}
	
	if (!fr.telf.value){
		//fr.telf.value = "000000000";
		alert("Debes introducir al menos el primer número de teléfono");
		return;
	} else {
		if (fr.telf.value.length<9){
			if(idioma=='ca'){alert("El telèfon ha de tenir 9 números");}
			else{alert("El teléfono debe tener 9 números");}
			fr.telf.focus();
			return;
		} else {
			if (isNaN(fr.telf.value)){
				if(idioma=='ca'){alert("El telèfon ha de ser un número");}
				else{alert("El teléfono debe ser un número");}
				fr.telf.focus();
				return;
			}
		}
	}
	
	if (!fr.telfm.value){
		//fr.telfm.value = "000000000";
		
	} else {
		if (fr.telfm.value.length<9){
			if(idioma=='ca'){alert("El telèfon ha de tenir 9 números");}
			else{alert("El teléfono debe tener 9 números");}
			fr.telfm.focus();
			return;
		} else {
			if (isNaN(fr.telfm.value)){
				if(idioma=='ca'){alert("El telèfon móvil debe ser un numéric");}
				else{alert("El teléfono mòvil debe ser un número");}
				fr.telfm.focus();
				return;
			}
		}
	}
	
	if (!fr.email.value){
		if(idioma=='ca'){alert("Introdueix una direcció de correu electrònic");}
		else{alert("Introduce una dirección de correo electrónico");}
		fr.email.focus();
		return;
	} else {
		if (!validarMail(fr.email)){
			fr.email.focus();
			return;
		}
	}
	

								
	/*fr.nombre.value = ConvertString(fr.nombre.value);
	fr.apellido.value = ConvertString(fr.apellido.value);
	fr.apellido2.value = ConvertString(fr.apellido2.value);
	fr.calle.value = ConvertString(fr.calle.value);
	fr.numero.value = ConvertString(fr.numero.value);
	fr.escalera.value = ConvertString(fr.escalera.value);
	fr.piso.value = ConvertString(fr.piso.value);
	fr.puerta.value = ConvertString(fr.puerta.value);
	fr.resto.value = ConvertString(fr.resto.value);
	fr.poblacion.value = ConvertString(fr.poblacion.value);
	fr.respuesta.value = ConvertString(fr.respuesta.value);
	*/
	fr.nombre.value = ConvertString(fr.nombre.value);
	fr.apellido.value = ConvertString(fr.apellido.value);
	fr.apellido2.value = ConvertString(fr.apellido2.value);
	//fr.poblacion.value = ConvertString(fr.poblacion.value);
	//fr.respuesta.value = ConvertString(fr.respuesta.value);
	
	var str=jQuery(".formcontacto").serialize();
        
	//fr.submit();
	$.ajax({
	   type: "POST",
	   url: "http://www.danet.es/intermedia.php",
	   data: str+"&language="+idioma,
	   success: function(msg){
		
		 document.registro.reset();
		  
                 $("#rcont").html(msg);
	   }
	 });
	
}
	
	function validarMail(input){
		   var supported = 0;
		  if (window.RegExp) {
		    var tempStr = "a";
		    var tempReg = new RegExp(tempStr);
		    if (tempReg.test(tempStr)) supported = 1;
		  }
		  if (!supported)
		    return (input.value.indexOf(".") > 2) && (input.value.indexOf("@") > 0);
		  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
		  if ((!r1.test(input.value) && r2.test(input.value))){
			return true;
		  }else{
		  	if(idioma=='ca'){alert("El mail ha de tenir el format correcte");}
			else{alert("El mail debe tener el formato correcto");}
		  	return false;
		  }
	}
	
	function calcular_edad(fecha){ 

	    //calculo la fecha de hoy 
	    hoy=new Date() 
	    //alert(hoy) 


	    //calculo la fecha que recibo 
	    //La descompongo en un array 
	    var array_fecha = fecha.split("/") 
	    //si el array no tiene tres partes, la fecha es incorrecta 
	    if (array_fecha.length!=3) 
	       return false 

	
	    //compruebo que los ano, mes, dia son correctos 
	    var ano 
	    ano = parseInt(array_fecha[2]); 

	    if (isNaN(ano)) 
	       return false 

	    var mes 
	    mes = parseInt(array_fecha[1]); 

	    if (isNaN(mes)) 
	       return false 
	       
	    var dia 
	    dia = parseInt(array_fecha[0]); 

	    if (isNaN(dia)) 
	       return false 

	    //si el año de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4 

	    if (ano<=99) 
	       ano +=1900 


	    //resto los años de las dos fechas 
	     if (is.ns){
		    edad=(hoy.getYear()+1900)- ano - 1; //-1 porque no se si ha cumplido años ya este año 
		} else {
			edad=hoy.getYear()- ano - 1;
		}
	
	    //si resto los meses y me da menor que 0 entonces no ha cumplido años. Si da mayor si ha cumplido 

	    if (hoy.getMonth() + 1 - mes < 0) //+ 1 porque los meses empiezan en 0 
	       return edad 

	    if (hoy.getMonth() + 1 - mes > 0) 
	       return edad+1 


	    //entonces es que eran iguales. miro los dias 
	    //si resto los dias y me da menor que 0 entonces no ha cumplido años. Si da mayor o igual si ha cumplido 

	    if (hoy.getUTCDate() - dia >= 0) 
	       return edad + 1 

	    return edad 
	} 

function ConvertString(input) {
    var output = "";
    var si = 0;
    for (var i = 0; i < input.length; i++) {
        si = 0;
        if (input.charCodeAt(i) == 13 && input.charCodeAt(i + 1) == 10) {
            si = 1;
            i++;
            output += "<BR>";
        }
        if (input.charCodeAt(i) == 32) {
            si = 1;
            output += "%20";
        }
        if (input.charCodeAt(i) == 225 || input.charCodeAt(i) == 224) {
            si = 1;
            output += "a";
        }
        if (input.charCodeAt(i) == 233 || input.charCodeAt(i) == 232) {
            si = 1;
            output += "e";
        }
        if (input.charCodeAt(i) == 237 || input.charCodeAt(i) == 236) {
            si = 1;
            output += "i";
        }
        if (input.charCodeAt(i) == 243 || input.charCodeAt(i) == 242) {
            si = 1;
            output += "o";
        }
        if (input.charCodeAt(i) == 250 || input.charCodeAt(i) == 249) {
            si = 1;
            output += "u";
        }
        if (input.charCodeAt(i) == 39) {
            si = 1;
            output += "%20";
        }
        if (input.charCodeAt(i) == 38) {
            si = 1;
            output += "%20";
        }
        if (si == 0) {
            output += input.charAt(i);
        }
    }
    return output;
}

function muestra_ajax_cont(o,u,metodo,sincapas,muestrafinal,capaPrioritaria){
    cposcura=document.createElement('div');
    cposcura.id='negra';
    cpmensaje=document.createElement('div');
    cpmensaje.id='popcont';
    cposcura.onclick=delete_ajax_cont;
    if(sincapas){
        if(capaPrioritaria){
            cpmensaje=capaPrioritaria;
        }
        else{
            cpmensaje=o;
        }
    }
	
	
    var xmlhttpa=_creaXML();
    pgsol=u;
    if(metodo){
        xmlhttpa.open(metodo,pgsol,true);
        valores='video='+document.getElementById("name_video").value;
        var i=0;
 
				
    }
    else{
        xmlhttpa.open("get",pgsol,true);
    }
    xmlhttpa.onreadystatechange=function(){
        if(xmlhttpa.readyState==4){
            txtres=xmlhttpa.responseText;
            cpmensaje.innerHTML=txtres;
            if(muestrafinal && txtres && txtres.indexOf('centradito')==-1){
                muestrafinal.style.display='';
            }
        }
    }
	
    if(metodo){
        xmlhttpa.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttpa.send(valores);
    }
    else{
        xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
        xmlhttpa.send(null);	
				
    }
    if(!sincapas){
        cpmensaje.style.top='0px';
        //o.appendChild(cpmensaje);
        cpmensaje.style.left=parseInt((document.documentElement.clientWidth/2)-237.5)+'px';
        cpmensaje.style.top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight/10)+'px';
        document.body.appendChild(cposcura);
        document.body.appendChild(cpmensaje);
		
		
		
    }
    return false;
}
function popavis(enl){
	window.open(enl,'legal','width=800,height=600,scrollbars=1');
	return false;
}
