﻿var __agencyId = null;

var __lastMiniNavTimeoutId = 0;
function MasterMininav(id)
{
    clearInterval(__lastMiniNavTimeoutId);
    $("#mstr_customer").hide();
    $("#mstr_language").hide();
    switch (id)
    {
        case 0:
            $("#mstr_customer").slideDown();
            break;
        case 1:
            $("#mstr_language").slideDown();
            break;
        case 2:
            $("#mstr_agent").slideDown();
            break;
    }

    __lastMiniNavTimeoutId = setTimeout(function ()
    {
        $("#mstr_customer").slideUp();
        $("#mstr_language").slideUp();
        $("#mstr_agent").slideUp();
    }, 6000);
}

function findAnAgentBox(whichMod)
{
    $('#faa-arrow').slideUp('fast');
    switch (whichMod)
    {
        case 1:
            $('#faa-city').slideUp('fast');
            $('#faa-zip').slideDown('fast');
            $('#faa-txtZipCode').focus();
            break;
        case 2:
            $('#faa-zip').slideUp('fast');
            $('#faa-city').slideDown('fast');
            break;
        case 3:
            window.location.href = "/locations/zipcode/" + $("#faa-txtZipCode").val();
            break;
        default:
    }
}
function showLocationChoices(s,h)
{
    $('#' + h).slideUp('fast');
    $('#' + s).slideDown('fast');
}
function showLocationZipCode(e)
{
    window.location.href = "/locations/zipcode/" + $("#" + e).val();
}

function UnBlockUi()
{
    $.unblockUI();
}
function BlockUi(message)
{
    $.blockUI({ message: "<div class=\"BlockUiLoader\">" + message + "</div>" });
}
function BlockUiWithClose(message)
{
    $.blockUI({ message: "<div class=\"BlockUiLoader\">" + message + "<hr /><a href=\"#\" onclick=\"UnBlockUi()\">Close</a></div>" });
}
function BlockUiWithElement(elementId)
{
    $.blockUI({ message: $("#" + elementId) });
}
function FocusOn(elementId)
{
    $("#" + elementId)[0].focus();
}

function Round5(value)
{
    return Math.floor(value * 1e5) / 1e5;
}


function GetAllLocations(func)
{
    var data = "{}";
    var method = "GetAllLocations";
    jQueryJsonAjax(data, method, func,
    function (error)
    {

    });
}
function LocDetSms()
{
    $("#loc-SendSms").toggle();
    $("#loc-SendEmail").hide();
}
function LocDetEmail()
{
    $("#loc-SendSms").hide();
    $("#loc-SendEmail").toggle();
}
function LocGeneralSms(agencyId)
{
    BlockUiWithElement("loc-SendSms");
    __agencyId = agencyId;
}
function LocGeneralEmail(agencyId)
{
    BlockUiWithElement("loc-SendEmail");
    __agencyId = agencyId;
}
function SendContactInfoViaSms()
{
    var number = $("#txtSMSNumber").val();
    var carrier = $("#smsCarrier").val();
    BlockUi("Sending SMS");
    $.post("/locations/SendContactInfoViaSms", { 'agencyId': __agencyId, 'number': number, 'carrier': carrier })
        .success(function (result) { ResetSendContact(); BlockUiWithClose("<h3>SMS Sent</h3><p>The location contact information has been sent!</p>"); })
        .error(function (error) { BlockUiWithClose("<h3>Ran into a Problem</h3><p>Something went wrong while sending you location info.</p><p>Make sure that required fields are filled.</p><p>Try again, if this continues, contact support</p>"); });
}
function SendContactInfoViaEmail()
{
    var email = $("#txtsc-email").val();
    BlockUi("Sending Email");
    $.post("/locations/SendContactInfoViaEmail", { 'agencyId': __agencyId, 'email': email })
        .success(function (result) { ResetSendContact(); BlockUiWithClose("<h3>Email Sent</h3><p>The location contact information has been sent!</p>"); })
        .error(function (error) { BlockUiWithClose("<h3>Ran into a Problem</h3><p>Something went wrong while sending you location info.</p><p>Make sure that required fields are filled.</p><p>Try again, if this continues, contact support</p>"); });
    }
    function ResetSendContact()
    {
        $("#loc-SendSms").hide();
        $("#loc-SendEmail").hide();
        $("#txtSMSNumber").val("");
        $("#txtEmail").val("");
        UnBlockUi();
    }

/* formatting */

function FormatToTelephoneNumber(telephoneNumber)
{
    if (telephoneNumber.length === 7)
    {
        return telephoneNumber.substring(0,3) + "-" + telephoneNumber.substring(3, 4);
    }

    if (telephoneNumber.length === 10)
    {
        return "(" + telephoneNumber.substring(0,3) + ") " + telephoneNumber.substring(3, 6) + "-" + telephoneNumber.substring(6, 10);
    }

    return telephoneNumber;
}


