
function validarParametrosForm(idForm){
		res=false;
    gets= function(){
				if(this.id!=""&&this.value!=""){
					res=true;	
				}
    }
    $("#"+idForm+" select").each(gets);
    $("#"+idForm+" textarea").each(gets);
    $("#"+idForm+" :text").each(gets);
    $("#"+idForm+" :radio:checked").each(gets);
    $("#"+idForm+" :checkbox:checked").each(gets);
		return res;
}
rules_recargar_concurso={
  preguntas:function(){
    $("#enviarResp").click(rules_enviar_resp.ejecutar);
  }
}

rules_mostrar_preg = {
evento : function() {
             $("a.participa").click(rules_mostrar_preg.ejecutar);
         },
ejecutar : function() {
               p=parametros(this.href);
               if(!$(this).parents("form").find(".acepto").is(":checked")){
                   aviso("Debe aceptar las condiciones del concurso.");
                   return false;
               }
               var us = getUser();
               if(!us){
                   avisoLogin("Para participar en el concurso debes estar registrado o haber hecho login. Haz clic en aceptar para registrarte o hacer login.","/comunidad/index.html?url_back=/participa/concursos/");
                   return false;
               }
               fin = function (html){
                   if(validarErr(html)){
                       $("#modal").html(html).popUp();
                       $("#modal").each(rules_recargar_concurso.preguntas);
                   }
               }
               $.ajax({ url: "/modulo/comunidad.html", data: p, success: fin });
               return false;
           }
}
$(document).ready(rules_mostrar_preg.evento);

rules_enviar_resp = {
evento : function() {
             $("#enviarResp").click(rules_enviar_resp.ejecutar);
         },
ejecutar : function() {
               if(validarParametrosForm("formPreg")){
									 p=parametrosForm("formPreg");
									 fin = function (html){
											 if(validarErr(html)){
													 $("#modal").html(html).popUp();
											 }
									 }
									 $.ajax({ url: "/modulo/comunidad.html", data: p, success: fin });
							 }
							 else{
									 aviso("Debes rellenar el formulario","modal2","modal");
							 }
               return false;
           }
}
$(document).ready(rules_enviar_resp.evento);

rules_mostrar_bases = {
evento : function() {
             $("a.ajaxBases").click(rules_mostrar_bases.ejecutar);
         },
ejecutar : function() {
               p=parametros(this.href);
               fin = function (html){
                   $("#modal").html(html).popUp();
               }
               $.ajax({ url: "/modulo/index.html", data: p, success: fin });
               return false;
           }
}
$(document).ready(rules_mostrar_bases.evento);

rules_mostrar_ganadores={
	evento:function(){
 		$("a.ajaxGanadores").click(rules_mostrar_ganadores.ejecutar);
	},
	ejecutar:function(){
	 	p=parametros(this.href);
	 	fin=function(html){
			$("#modal").html(html).popUp();
	 	}
	 	$.ajax({url:"/modulo/index.html",data: p,success:fin});
    return false;
  }
}
$(document).ready(rules_mostrar_ganadores.evento);

rules_busqueda_concursos = {
    evento : function() {
             $("form#buscarConcurso").submit(rules_busqueda_concursos.ejecutar);
    },
    before: function() {
    	//$().pre_loading("#columna415",img_cargando);
    },
	ejecutar : function() { 
			   idForm = this.id;
			   p = parametrosForm(idForm);			  	
				 var ctn=p.split("ctn=")[1];
				 ctn=ctn.split("&")[0];
			   fin = function(html)
			   {
				  $().post_loading();
                  $("div#"+ctn).replaceWith(html);
                  $("div#"+ctn).each(rules_busqueda_concursos.evento);
                  $("div#"+ctn).each(rules_paginacion_concursos.evento);
               }
			   $.ajax({ 
			   url: "/modulo/index.html",
			   data: p,
			   beforeSend: rules_busqueda_concursos.before,
			   success: fin 
			   });
               return false;
           }
}
$(document).ready(rules_busqueda_concursos.evento);

rules_paginacion_concursos = {
    evento : function() {
                 $("a.aP").click(rules_paginacion_concursos.ejecutar);
             },
    ejecutar: function(){
                  var parametros = this.href.split("?")[1];
                  var url = this.href.split("?")[0];
                  var ctn = parametros.split("container=")[1];
                  var modulo = parametros.split("modulo=")[1];
                  var aP = "modulo="+modulo+"&"+parametros;
									ctn = ctn.split("&")[0];
                  var regla = function(){};
                  fin = function(html){
                       if(validarErr(html)){
                       $("#"+ctn).html(html);
                       $("#"+ctn).each(rules_paginacion_concursos.evento);
                       }
                  }
                  $.ajax({ url: "/modulo/index.html",data: aP, success: fin });
                  return false;
              }
}
$(document).ready(rules_paginacion_concursos.evento);
