﻿//***********************
//Button Focus
function UniversalButtonFocus(buttonFocus, ee) {
    if (ee.keyCode == 13) { $(buttonFocus).focus(); }
}

function setSearchFocus() {
   //Get rid of after next master page update
}




//Watermark
function setTextMask(incControl, textToShow)//OnClick
{
    var textBoxControl = incControl;
    var textBoxText = incControl.value;

    if (textBoxText == textToShow) {
        textBoxControl.style.color = "black";
        textBoxControl.style.backgroundColor = "white";
        textBoxControl.style.textAlign = "left";
        textBoxControl.style.fontStyle = "normal";

        textBoxControl.value = "";
        textBoxControl.focus();
    }
}
function resetTextMask(incControl, textToShow, textPosition)//OnBlur
{
    var textBoxControl = incControl;
    var textBoxText = incControl.value;

    if (textBoxText == "") {
        textBoxControl.style.color = "#606060";
        textBoxControl.style.backgroundColor = "#F0F8FF";
        textBoxControl.style.fontStyle = "italic";
        textBoxControl.value = textToShow;
        if (textPosition == "c") textBoxControl.style.textAlign = "center";
        if (textPosition == "l") textBoxControl.style.textAlign = "left";
    }
}

function enableLogIn() { if ($("#ctl00_logInMasterDiv").is(":visible") == true) $("#ctl00_logIn_UserName").focus(); }

//Send To Friend Expansion
$(document).ready(function() {

//Log In Focus
$('#ctl00_logIn_Password').keydown(function(e) {
    UniversalButtonFocus('#ctl00_logIn_LoginButton', e);
});
//Search Focus
$('#ctl00_txtMasterSearch').keydown(function(e) {
    UniversalButtonFocus('#ctl00_btnMasterSearch', e);
});

    $(".clickMeEmailShare").click(function() {
        $(".sendToFriendDiv").slideToggle("fast");
    });
    $(".clickMeLogIn").click(function() {
        $(".logInDiv").slideToggle("fast");
        $(this).toggleClass("active");
        setTimeout("enableLogIn()", 500);
    });
    //*******************************
    //Send To Friend AJAX
    //*******************************
    $("#btnEmailFriend").click(function() {
        $("#emailFriendError").css('display', 'none').end(); //Reset
        $("#successFriendMail").css('display', 'none').end(); //Reset
        $("#ctl00_EmailLoadingImage").css('display', 'block').end()//SHOW LOADING IMAGE
        
        //Special, just for pages that have quotation "rohrmr's profile"
        var title = document.title;
        title = title.replace("'", "\\'");
        
        $.ajax({
            type: "POST", //GET or POST
            url: "http://www.matthewscaloriecounter.com/ajax/ajax_methods.asmx/SendFriendEmails", //****Must Be Changed upon Server Deployment
            //url: "../ajax/ajax_methods.asmx/SendFriendEmails", //for local testing
            contentType: "application/json; charset=utf-8",
            dataType: "json", //script, json, xml
            data: "{'emails': '" + $("#txtEmailInvites").val() +
                    "', 'fromEmail': '" + $("#txtYourEmail").val() +
                     "', 'name': '" + $("#txtYourName").val() +
                      "', 'message': '" + $("#txtMessage").val() +
                      "', 'url': '" + window.location +
                      "', 'title': '" + title + "'}",
            success: handleData,
            error: ajaxFailed
        });

        function handleData(data, status) { //THIS IS DATA RETURNED TO CLIENT COMPUTER
            $("#ctl00_EmailLoadingImage").css('display', 'none').end(); //HIDE LOADING IMAGE
            if (data.d == "a") {//Sent Successfully
                $("#successFriendMail").css('display', 'block').end(); //Show Success
                $("#friendMailTable").css('display', 'none').end(); //Hide Table, to help prevent spam
                $("#btnCloseEmailFriend_2").css('display', 'block').end(); //Show Close Button_2 
            }
            else {//Else problem
                $("#emailFriendError").css('display', 'block').end(); //Show Error
                $("#emailFriendError").html(data.d); //Assign Error Message
            }
        }
        function ajaxFailed(xmlRequest)
        { alert("Error In General \n\r\n\r" + xmlRequest.status + ' \n\r ' + xmlRequest.statusText + '\n\r' + xmlRequest.responseText); }

    });
});