﻿//$(document).ready(loadShortcuts);

// disabled on 2/11 (see above)
/*
function loadShortcuts() {
$(document).bind('keydown', 'alt+k', doSearchBox);
$(document).bind('keydown', 'esc', killSearchBox);

$('#dialogSearchWord').keyup(function(e) {
//alert(e.keyCode);
if (e.keyCode == 13) {
//alert('Enter key was pressed.');
//document.location.href='http://google.com';
doSearch(document.getElementById('dialogSearchWord').value());
}
});
}
// was going to load the dialog box, but it's not active now
function doSearchBox() {
//alert($("#dialogSearch").dialog('isOpen'));
if (!$("#dialogSearch").dialog('isOpen')) {
//alert('creating')
$("#dialogSearch").dialog({
bgiframe: true,
height: 75,
modal: true
});
$("#dialogSearch").dialog("open");
$("#dialogSearchWord").val("").focus().css("background-color", "red");
}

}

function killSearchBox() {
//alert('escape');
$("#dialogSearch").dialog("close");
}
*/

function parseAutoCompleteValue(target) {
    var val = String(target.value)
    var whitespaceIndex = Number(val.indexOf(" "));

    if (whitespaceIndex > -1 && val.length > 0) {
        //alert("going to parse now");
        var newVal = val.substring(0, whitespaceIndex);
        //alert("new value will be " + newVal);
        target.value = newVal;
    }
    else {
        //alert("Error Parsing Auto-Complete Value - please contact 270net");
        return target;
    }
}

function doSearch() {
    var kw = $("#txtQuery").val();

    var memberTypeId = $(".lstMemberTypeId :selected").val();
    var userStatusId = $(".lstUserStatusId :selected").val();
    var memberRegionId = $(".lstMemberRegionId :selected").val();
    var billingStatusId = $(".lstBillingStatusId :selected").val();

    //alert(memTypeId);

    window.location.href = "default.aspx?q=" + kw + "&membertypeid=" + memberTypeId + "&userstatusid=" + userStatusId + "&memberregionid=" + memberRegionId + "&billingstatusid=" + billingStatusId;
}

/* profile update stuff */
function switchPostalContainer(src) {
    //src is the command div tag.  let's figure out which index he is of all the cmd containers

    // reset both command and postal containers to their normal css state
    $(".addrCmd").removeClass("addrCmdSelected");
    $(".addrContainer").removeClass("addrContainerHighlighted");

    // the element passed into the function add additionally gets the cmdSelected class
    $(src).addClass("addrCmdSelected");

    // postal section commands should always equal the number of postall address containers (e.g. 4 cmds on left, 4 containers on right w/ diff addrs)
    // find the index of selected element in our collection of commands, get a reference, then add the highlighted class to the correct postal container
    var clickedIndex = $(".addrCmd").index(src);
    var targEle = $(".addrContainer").get(clickedIndex);
    $(targEle).addClass("addrContainerHighlighted");
}

function toggleEnabledStatus(src, targetContainer) {

    //alert(src.id);
    var selector = "#" + src.id + ":checked";
    //alert(selector);
    //alert($(selector).hide());

    if ($(selector).val() == null) {
        // enable all (show form)
        //alert('not checked - id = ' + targetContainer);

        ////$("#" + targetContainer + " input").attr("disabled", "");
        ////$("#" + targetContainer + " select").attr("disabled", "");
        $("#" + targetContainer).css("visibility", "visible");
    }
    else {
        // disable all children (hide form)
        //alert('checked - id = ' + targetContainer);
        ////$("#" + targetContainer + " input").attr("disabled", "disabled");
        ////$("#" + targetContainer + " select").attr("disabled", "disabled");
        $("#" + targetContainer).css("visibility", "hidden");
    }
}

function setupScreenName(lname, fname, nickname) {
    if ($("#" + nickname).val() == "") {
        // auto fill
        $("#" + nickname).val($("#" + fname).val() + '.' + $("#" + lname).val());
    }
}

function copyToContacts() {
    $('.rel-company').val($('.top-company').val());
    $('.rel-title').val($('.top-title').val());
    $('.rel-first').val($('.top-first').val());
    $('.rel-middle').val($('.top-middle').val());
    $('.rel-last').val($('.top-last').val());
    $('.rel-suffix').val($('.top-suffix').val());
    $('.rel-jobtitle').val($('.top-jobtitle').val());
    $('.rel-email').val($('.top-email').val());

}
