﻿// Javascript copied from Tandem / MasterPages/BookstoreMasterPage.master


function GoBack() {
    history.back();
    return false;
}

function Confirm(message) {
    //This is used to make sure they really want to delete the record
    //this function gets assigned in the code behind
    return window.confirm(message)

}

function doClick(buttonName, e) {
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox
    //the purpose of this function is to allow the enter key to point to the correct button to click.
    if (key == 13) {
        var btn = document.getElementById(buttonName);
        if (btn != null) {
            btn.click();
            event.keyCode = 0
        }
    }

}

function keypressNumOnly(buttonName, e) {
    //This function causes the textboxs to only allow numbers

    var tmpstr = ""
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    tmpstr = String.fromCharCode(key)

    if ((tmpstr == "0") ||
     tmpstr == "1" ||
     tmpstr == "2" ||
     tmpstr == "3" ||
     tmpstr == "4" ||
     tmpstr == "5" ||
     tmpstr == "6" ||
     tmpstr == "7" ||
     tmpstr == "8" ||
     tmpstr == "9" ||
     key == 8 ||
     key == 0) {
        //do nothing these are valid keys
        return true;
    }
    else if (key == 13) {
        var btn = document.getElementById(buttonName);
        if (btn != null) {
            btn.click();
        }
        return false;
    }

    //Not a key we want
    return false;
}

function keypressNumOnlyChangeFocus(buttonName, e) {
    //This function causes the textboxs to only allow numbers

    var tmpstr = ""
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    tmpstr = String.fromCharCode(key)

    if ((tmpstr == "0") ||
     tmpstr == "1" ||
     tmpstr == "2" ||
     tmpstr == "3" ||
     tmpstr == "4" ||
     tmpstr == "5" ||
     tmpstr == "6" ||
     tmpstr == "7" ||
     tmpstr == "8" ||
     tmpstr == "9" ||
     key == 8 ||
     key == 0) {
        //do nothing these are valid keys
        return true;
    }
    else if (key == 13) {
        var btn = document.getElementById(buttonName);
        if (btn != null) {
            btn.focus();
        }
        return false;
    }

    //Not a key we want
    return false;
}

// DLB : 3/11/09 : WebServices call to see if the List Name already exists

var _buttonId;

function DoesListExist(mUserID, listNameId, buttonId) {
    _buttonId = buttonId;
    MackinWebServices.DoesListExist(mUserID, $get(listNameId).value, DoesListExistAnswer)
}

function DoesListExistAnswer(arg) {
    if (arg) {
        $get('duplicateListNameMessageHolder').innerHTML = 'Duplicate List Name! Please enter a unique name.';
        $get('duplicateListNameMessageHolder').style.display = 'block';
        $get(_buttonId).disabled = true;
        //alert(arg);
    } else {
        $get('duplicateListNameMessageHolder').innerHTML = '';
        $get('duplicateListNameMessageHolder').style.display = 'none';
        $get(_buttonId).disabled = false;
    }
}
// DLB : 3/11/09 : End

// DLB : 3/13/09 : Moved this function from indivual pages to this Jar
// Function to trap the enter key in the dialog and prevent closing.
function dontclosedialog(dialog, arg) {
    // DLB : 3/12/09 : Added TEXTAREA to the if statement.  On create New List when you pressed enter
    //                 after entering the list name the dialog would close and the form would process
    //                 so I think we need to return false on enters coming from other areas.
    //if (arg.keyCode == 13) {
    //alert(arg.cancelBubble);
    var srcEl = arg.srcElement ? arg.srcElement : arg.target;
    if ((srcEl.nodeName == 'TEXTAREA') && (arg.keyCode == 13)) {
        return 0;
    } else if ((srcEl.nodeName == 'INPUT') && (arg.keyCode == 13) && (srcEl.type != 'submit')) {
        try {
            arg.keyCode = 9;
        }
        catch (err) {

        }
        //alert('Input Text');
        return false;
    } else if ((srcEl.nodeName == 'INPUT') && (arg.keyCode == 13) && (srcEl.type == 'submit')) {
        return true;
    }
    return false;
}
// DLB : 3/13/09 : End

// DLB : 04/02/2009 : added function for confirm box
function ConfirmAction(question, redirectTo) {
    var answer = confirm(question);
    if (!answer) {
        eo_CancelEvent();
        if ((navigator.userAgent.indexOf('Safari') != -1) || (navigator.userAgent.indexOf('Chrome') != -1)) {
            window.event.cancelBubble = true;
        }
        return false;
    }
}

// DLB : 04/23/2009 :   Functions for dynamically position a div message at the mouse pointer position

// Fill the div message
function divMsg(WinMsg, DivID) {
    if (document.getElementById(DivID)) {
        myElement = document.getElementById(DivID);
        myElement.innerHTML = WinMsg;
        //richToolTip(e);
    }
}

function positionShowDiv(DivID, e) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX + 10;
        posy = e.pageY + 10;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft
			            + document.documentElement.scrollLeft + 10;
        posy = e.clientY + document.body.scrollTop
			            + document.documentElement.scrollTop + 10;
    }
    // posx and posy contain the mouse position relative to the document
    // Do something with this information
    myElement = document.getElementById(DivID);
    myElement.style.top = posy + 'px';
    myElement.style.left = posx + 'px';
    myElement.style.visibility = 'visible';
    _noteVisible = true;  // DDL  : 03/22/2010 : Set variable to track visibility of note message popup.
}

function positionShowDivFullRecord(DivID, e, offset) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX + 10;
        posy = e.pageY + 10;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft
			            + document.documentElement.scrollLeft + 10;
        posy = e.clientY + document.body.scrollTop
			            + document.documentElement.scrollTop + 10;
    }
    // posx and posy contain the mouse position relative to the document
    // Do something with this information
    myElement = document.getElementById(DivID);
    myElement.style.top = posy + 'px';
    myElement.style.left = (posx - offset) + 'px';
    myElement.style.visibility = 'visible';
    _noteVisible = true;  // DDL  : 03/22/2010 : Set variable to track visibility of note message popup.
}

function hideDiv(DivID) {
    document.getElementById(DivID).style.width = '0px';
    document.getElementById(DivID).style.height = '0px';
    document.getElementById(DivID).style.padding = '0px';
    document.getElementById(DivID).style.visibility = 'hidden';
    document.getElementById(DivID).innerHTML = '';
    _noteVisible = false; // DDL  : 03/22/2010 : Clear variable to track visibility of note message popup.
}

function markListInfoAsDirty(RefreshID) {
    document.getElementById("listinfo").className = "LegendTextDirty";
    if (RefreshID != "") {
        document.getElementById(RefreshID).disabled = false;
        document.getElementById(RefreshID).className = "UpdateTotalsEnabled"
        document.getElementById(RefreshID).title = "";
    }
    eo_CancelEvent();
}

function marcRecordSearchDev() {
    window.open('http://192.168.100.205/', 'MARCRecords');
}

function marcRecordSearch() {
    window.open('http://marcsearch.mackin.com', 'MARCRecords');
}

//function FullRecordPrint() {
//    var currentItemID = document.getElementById('<%= ui_hdn_CurrentID.ClientID %>');
//    window.open('print/FullRecordPrint.aspx', 'FullRecord');
//}

// DLB : 11/12/2009 : Script for opening a dialog box though script.
function OpenDialogPopUp(dialogName) {
    var eoPopup;
    while (eoPopup == null) {
        eoPopup = eo_GetObject(dialogName);
    }
    eoPopup.show(true);
    eo_CancelEvent();
}

function listmatch(orderid, linkID, qtyTextBox, PriorityDDL, dataRow, command) {
    var qty = document.getElementById(qtyTextBox).value;

    var priority;
    if (document.getElementById(PriorityDDL)) {
        priority = document.getElementById(PriorityDDL).value;
    }
    else {
        priority = "NotVisible";
    }

    stat = "NotVisible";

    switch (command) {
        case "qty":
            if (qty != 0) {
                document.getElementById(linkID).disabled = false;
            } else {
                document.getElementById(linkID).disabled = true;
            }
            break;
        case "priority":
            //            if ((!document.getElementById(selectID).checked) && (qty != 0)) {
            //                document.getElementById(selectID).checked = true;
            //                document.getElementById("listinfo").className = "LegendTextDirty";
            //            }
            //            else {
            //                RefreshID = '';
            //            }
            break;
        case "select":
            qty = 0;
            break;
    }

    if (qty == 0) {
        if (dataRow != -1) {
            document.getElementById("row" + dataRow).className = "GridViewZeroQtyRow";
            document.getElementById(qtyTextBox).value = qty;
            document.getElementById(linkID).disabled = true;
        }
    }
    else {
        if (dataRow % 2) {
            if (dataRow != -1) {
                document.getElementById("row" + dataRow).className = "GridViewAlternatingRow";
            }
        }
        else {
            if (dataRow != -1) {
                document.getElementById("row" + dataRow).className = "GridViewRowStyle";
            }
        }
    }
    //    if (document.getElementById(selectID).checked && qty == 0) {
    //        qty = 1;
    //    }

    //    document.getElementById(qtyID).value = qty;

    //CallServer("order|" + id + "|" + qty + "|" + priority + "|" + stat + "|" + sender + "|" + RecordNbr + "|" + ItemType + "|" + ListPrice + "|" + RowID); //);
    //    if (RefreshID != "") {
    //        document.getElementById(RefreshID).disabled = false;
    //        document.getElementById(RefreshID).className = "UpdateTotalsEnabled"
    //        document.getElementById(RefreshID).title = "";
    //    }
    //alert($get(NewOrderID).value)
    //    if (($get(NewOrderID).value == "") || ($get(NewOrderID).value == "0")) changeNoteGraphic(NotesImageID, 'NoNote.gif');
    //    MackinWebServices.selectSearchResults(id, qty, priority, stat, sender, RecordNbr, ItemType, ListPrice, RowID, RefreshID, M_User_ID, ConsidID, SessID, addNewOrderID)
    MackinWebServices.selectListDetail(orderid, qty, priority, stat, '')
    eo_CancelEvent();
}

var errorMsgID;
function isCouponValid(ConsidID, CouponID, ListTotal, M_User_ID, ErrorMsgID) {
    errorMsgID = ErrorMsgID;
    MackinWebServices.isCouponValid(ConsidID, CouponID, ListTotal, M_User_ID, CouponValidationMsg);
}

function CouponValidationMsg(args) {
    if (args != 'true') {
        $get(errorMsgID).innerHTML = args;
    } else {
        $get(errorMsgID).innerHTML = '';
    }
}
