﻿var forgot = "";
jQuery(document).ready(function()
{ 

   //if there is a querystring = e=1, they logged in incorrectly..show error message
   var url = window.location.toString();
   if (url.indexOf("e=") > -1){
        $("#logError").show();
   
   }
   
   if (url.indexOf("p=") > -1){
        $("#leftHeading").html("You Must Login or Register to Advertise!");
        
   }
   
   if (url.indexOf("u=") > -1){
       setTimeout("clickForgotUser()",500);
   }
   if (url.indexOf("f=") > -1){
        setTimeout("clickForgotPass()",500);
   }

   $("#logIn").click(function(){
        
   
   
   });

   $('#logRegister').bind('click',function() {
     
       showOverlay();

       $("#vistaIFrame")[0].src ="/Pages/Registration/registration.htm"   
        if($('#window').css('display') == 'none') {
           $("#windowTopContent").html("Register New Account With TapInko.com");
//           $(this).TransferTo(
//                {
//                    to:'window',
//                    className:'transferer2', 
//                    duration: 500,
//                    complete: function()
//                    {
//                        $('#window').show();
//                    }
//                }
//            );
            $('#window').show("slow");
        }
        this.blur();
        return false;
    }
  );

    $("#forgotUser").click(function(){
        forgot = "userid";
        $("#signInArea").hide();
        $("#forgotInfoArea").fadeIn("slow");
        $("#forgotTitle").html("<b>Forgot your username?</b>");
        $("#forgotInstructions").html("Enter your email below and we'll send your username.");
    
    });
    
    $("#forgotPass").click(function(){
        forgot = "password";
        $("#signInArea").hide();
        $("#forgotInfoArea").fadeIn("slow");
        $("#forgotTitle").html("<b>Forgot your password?</b>");
        $("#forgotInstructions").html("Enter your email below.  You will receive a link to reset your password.");
    });
    
    $("#sendForgot").click(function(){
        //ForgotInfo(string emailAddr, string forgottenInfo)ForgotInfo
        $("#forgotStatus").hide();
        if ($("#sendto").val() == ""){
            alert("Please enter your email address.");
        }
        else{
            $("#sendForgot").hide();
            $("#processing").fadeIn("slow");
            var theData = "{\"emailAddr\":\"" + $("#sendto").val() + "\",\"forgottenInfo\":\"" + forgot + "\"}";
            sendObject(theData,'ContactsController','ForgotInfo',showWhatHappened,'{}');
        }
    });

    // 


});

function clickForgotUser(){

      $("#forgotUser").trigger("click");   
}

function clickForgotPass(){
     $("#forgotPass").trigger("click");
}

function showWhatHappened(msg){

    var worked = eval(msg.d);
    $("#processing").hide();
    //$("#sendForgot").fadeIn("slow");

    if (worked){
       
        $("#forgotStatus").html("<br />Thanks.  You should receive an email with your requested information shortly.");
        $("#sendto").val("");
        $("#forgotStatus").fadeIn("slow");
    }   
    else{
        $("#forgotStatus").html("<br />Sorry, that email does not exist in our system.  <br />Please <a href='javascript:void(0)' onclick='parent.openContactForm()'>contact us</a>.");
        $("#forgotStatus").fadeIn("slow");
    }
    $("#sendForgot").show();


}


function sendObject(arg, toController, method, successCallback, failureCallback) {
  
    $.ajax({ type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/bll/" + toController + ".aspx/" + method,
        data: arg,
        dataType: "json",
        success: successCallback,
        error: function(a, b, c) { alert("Sorry!  An error occured.  Please contact us at support@tapinko.com");  }//alert(a.responseText);  }

    });

}