$(function(){

      $("#registro").hide('fast');
      $("#OlClave").hide('fast');

        var ab =0;
        var oc =0;
        $("#registrate").click(function(){

           if(ab ==0)
             {
              $("#registro").show("slow");
              ab=1
             }else
                 {
                  $("#registro").hide('slow');
                  ab=0;
                 }
        });


        $("#mclave").click(function(){

           if(oc ==0)
             {
              $("#OlClave").show("slow");
              oc=1
             }else
                 {
                  $("#OlClave").hide('slow');
                  oc=0;
                 }
        });

/*        $('#slider1').bxSlider({
          auto: true,
          autoControls: true,
          autoHover: true,
          pager: false,
          controls: false
        });*/

        $("#RePass").focus(function(){
           $("#RePass").val("");
        });

        $("#RecuCuenta").click(function(a){
          a.preventDefault();

          if( $("#RePass").val() != "" )
           {

            if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test($("#RePass").attr("value")))
               {
                 $("#CargandoRcuenta").css("display", "inline");
                 $("#RecuCuenta").css("display", "none");
                 $.post("Class/Usuarios/RecuperarCuenta.php", { email: $("#RePass").attr('value') },
                               function(data){

                                                 $("#CargandoRcuenta").css("display", "none");
                                                 if(data.length == 17)
                                                   {
                                                     $("#RcuentaExitosa").html(data).show('slow');

                                                     setTimeout(function(){
                                                       $('form')[0].reset();
                                                       $("#RePass").removeClass();
                                                       $("#RePass").addClass("box");
                                                       $("#RcuentaExitosa").hide('slow');
                                                       $("#OlClave").hide('slow');
                                                       $("#RecuCuenta").css("display", "inline");
                                                     },3000);

                                                   }
                                                   else
                                                       {
                                                       $("#RcuentaExitosa").html(data).show('slow');
                                                       setTimeout(function(){
                                                       $("#RcuentaExitosa").hide('slow');
                                                       $("#RePass").val("");
                                                       $("#RecuCuenta").css("display", "inline");
                                                        },3000);
                                                       }


                                            });

               }
               else
                   {
                     $("#RcuentaExitosa").html("Email No valido.").show('slow');
                      setTimeout(function(){
                                           $("#RePass").removeClass();
                                           $("#RePass").addClass("box");
                                           $("#RcuentaExitosa").hide('slow');
                                           },4000);
                   }


           }
           else
               {
                 $("#RePass").addClass("Requerido");
               }

        });





	$('#show-options').click(function() {
		$('#options').slideToggle();
		$(this).toggleClass('open');
		return false;
	});


    var sesionU = 0;
    var sesionC = 0;

    $("#SeUsuario").focus(function(){
        if(sesionU == 0)
         {
           $("#SeUsuario").val("");
           $("#SeUsuario").select();
           sesionU = 1;
         }
    });

    $("#SeClave").focus(function(){
       if(sesionC == 0)
         {
           $("#SeClave").val("");
           $("#SeClave").select();
           sesionC = 1;
         }
    });

    $("#InicioSesion").click(function(a){

      a.preventDefault();

      if( $("#SeUsuario").val() != "" )
        {
         $("#SeUsuario").removeClass();
         $("#SeUsuario").addClass("box");
        }
        else
           {
            $("#SeUsuario").addClass("Requerido");
            $("#SeUsuario").select();
           }

          if( $("#SeClave").val() != "" )
            {
             $("#SeClave").removeClass();
             $("#SeClave").addClass("box");
            }
            else
                {
                 $("#SeClave").addClass("Requerido");
                 $("#SeClave").select();
                }

          if( $("#SeClave").val() != "" && $("#SeUsuario").val() != "" )
            {
             $("#CargandoSession").css("display", "inline");
             $("#InicioSesion").css('display','none');
             $.post("Class/Usuarios/InicioSesion.php", { usu: $("#SeUsuario").attr('value'), pass: $("#SeClave").attr('value') },
             function(data){
                                   $("#CargandoSession").css("display", "none");

                                   if(data.length == 12)
                                     {
                                       $("#SesionExitosa").html(data).show('slow');
                                       setTimeout(function(){
                                       window.location.reload();
                                       },2000);
                                     }
                                     else
                                         {
                                          $("#SesionExitosa").html(data).show('slow');
                                           setTimeout(function(){
                                           $("#SesionExitosa").hide('slow');
                                           $("#SeClave").val("");
                                           $("#SeUsuario").val("");
                                           $("#InicioSesion").css('display','inline');
                                            },2000);
                                         }
                          });
            }

    });


      var ContacNombre = 0;
      var ContacEmail = 0;
      var ContacTelefono = 0;
      var ContacAsunto = 0;
      var ContacMensaje = 0;

      $("#ContaNombre").click(function(){
          if(ContacNombre == 0)
           {
             $("#ContaNombre").val("");
             ContacNombre = 1;
           }
      });

      $("#ContaNombre").focus(function(){
          if(ContacNombre == 0)
           {
             $("#ContaNombre").val("");
             ContacNombre = 1;
           }
      });

      $("#Ctelefono").click(function(){
         if(ContacTelefono == 0)
           {
             $("#Ctelefono").val("");
             ContacTelefono = 1;
           }
      });

      $("#Ctelefono").focus(function(){
         if(ContacTelefono == 0)
           {
             $("#Ctelefono").val("");
             ContacTelefono = 1;
           }
      });

      $("#emailContactenos").click(function(){
         if(ContacEmail == 0)
           {
             $("#emailContactenos").val("");
             ContacEmail = 1;
           }
      });


      $("#emailContactenos").focus(function(){
         if(ContacEmail == 0)
           {
             $("#emailContactenos").val("");
             ContacEmail = 1;
           }
      });


      $("#asunto").click(function(){
         if(ContacAsunto == 0)
           {
             $("#asunto").val("");
             ContacAsunto = 1;
           }
      });

      $("#asunto").focus(function(){
         if(ContacAsunto == 0)
           {
             $("#asunto").val("");
             ContacAsunto = 1;
           }
      });


      $("#mensaje").click(function(){
         if(ContacMensaje == 0)
           {
             $("#mensaje").val("");
             ContacMensaje = 1;
           }
      });

      $("#mensaje").focus(function(){
         if(ContacMensaje == 0)
           {
             $("#mensaje").val("");
             ContacMensaje = 1;
           }
      });


    $("#EnviarContactenos").click(function(a){

      a.preventDefault();


          if( $("#ContaNombre").attr("value") != "" && $("#Ctelefono").attr("value") != "" && $("#emailContactenos").attr("value") != ""  && $("#asunto").attr("value") != "" && $("#mensaje").attr("value") != "" &&  ContacNombre ==1 && ContacEmail ==1 && ContacTelefono == 1 && ContacAsunto ==1 && ContacMensaje ==1 )
            {
             if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test($("#emailContactenos").attr("value")))
                  {
                   $("#CargaContactenosExitoso").css("display", "inline");
                   $.post("Class/Usuarios/Contactenos.php", { nombre: $("#ContaNombre").attr('value'), telefono: $("#Ctelefono").attr('value'), email: $("#emailContactenos").attr('value'), asunto: $("#asunto").attr('value'), mensaje: $("#mensaje").attr('value') },
                   function(data){
                                         $("#CargaContactenosExitoso").css("display", "none");

                                         $("#ContaNombre").removeClass();
                                         $("#ContaNombre").addClass("box");
                                         $("#Ctelefono").removeClass();
                                         $("#Ctelefono").addClass("box");
                                         $("#emailContactenos").removeClass();
                                         $("#emailContactenos").addClass("box");
                                         $("#asunto").removeClass();
                                         $("#asunto").addClass("box");

                                         $("#FormuContactenos")[0].reset();

                                         $("#mensaje").removeClass();
                                         $("#mensaje").addClass("box2");
                                         $("#ContactenosExitoso").html("Mensaje Enviado Correctamente").show('slow');
                                         setTimeout(function(){
                                             $("#ContactenosExitoso").hide('slow');
                                            },2000);

                                         ContacNombre = 0;
                                         ContacEmail = 0;
                                         ContacTelefono = 0;
                                         ContacAsunto = 0;
                                         ContacMensaje = 0;

                                });
                   }
                   else
                       {
                        $("#ContactenosExitoso").html("Email No valido.").show('slow');
                        setTimeout(function(){
                                           $("#ContactenosExitoso").hide('slow');
                                          },2000);
                        VeriContac();
                        $("#emailContactenos").addClass("Requerido");
                        $("#emailContactenos").select();
                       }

            }
            else
               {

                VeriContac();
                $("#ContactenosExitoso").html("Datos Incompletos").show('slow');
                 setTimeout(function(){
                                       $("#ContactenosExitoso").hide('slow');
                                      },2000);
               }


    });


    function VeriContac()
           {
                if( ContacNombre == 1 && $("#ContaNombre").attr("value") != "")
                  {
                   $("#ContaNombre").removeClass();
                   $("#ContaNombre").addClass("box");
                  }
                  else
                     {
                      $("#ContaNombre").addClass("Requerido");
                      ContacNombre = 0;
                     }

                    if( ContacTelefono == 1 && $("#Ctelefono").attr("value") != "")
                      {
                       $("#Ctelefono").removeClass();
                       $("#Ctelefono").addClass("box");
                      }
                      else
                          {
                           $("#Ctelefono").addClass("Requerido");
                           ContacTelefono = 0;
                          }

                  if( ContacEmail == 1 && $("#emailContactenos").attr("value") != "")
                    {
                     $("#emailContactenos").removeClass();
                     $("#emailContactenos").addClass("box");
                    }
                    else
                       {
                        $("#emailContactenos").addClass("Requerido");
                        ContacEmail = 0;
                       }

                      if( ContacAsunto == 1 && $("#asunto").attr("value") != "")
                        {
                         $("#asunto").removeClass();
                         $("#asunto").addClass("box");
                        }
                        else
                            {
                             $("#asunto").addClass("Requerido");
                             ContacAsunto = 0;
                            }

                    if( ContacMensaje == 1 && $("#mensaje").attr("value") != "")
                        {
                         $("#mensaje").removeClass();
                         $("#mensaje").addClass("box2");
                        }
                        else
                            {
                             $("#mensaje").addClass("Requerido");
                             ContacMensaje = 0;
                            }
           }

    $("#buscador").click(function(){
       $("#buscador").val("")
       $("#buscador").css({'color':'#38171E ','text-align':'left'});
       $("#buscador").addClass("box3X22");
    });

    $("#BuscarPost").click(function(e){

      if($("#buscador").val() != "")
        {
         $("#Fbuscar").submit( function (){

         });
        }
        else
            {
              $("#buscador").val("Datos Incompletos").css({'color':'red','text-align':'center'}).show(4000);
              e.preventDefault ();
            }

    })


});

function ventanaSecundaria (URL)
       {
        window.open(URL,"ventana1","width=550,height=425,scrollbars=NO")
       }

function emoticonos(tag) {
    var myField;
    if (document.getElementById('content') && document.getElementById('content').type == 'textarea') {
        myField = document.getElementById('content');
    }
    else if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {
        myField = document.getElementById('comment');
    }
    else {
        return false;
    }
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = tag;
        myField.focus();
    }
    else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        var cursorPos = endPos;
        myField.value = myField.value.substring(0, startPos)
                      + tag
                      + myField.value.substring(endPos, myField.value.length);
        cursorPos += tag.length;
        myField.focus();
        myField.selectionStart = cursorPos;
        myField.selectionEnd = cursorPos;
    }
    else {
        myField.value += tag;
        myField.focus();
    }
}       

