﻿/*******************************************************/
/*Function: CalculateTotal                             */
/**Purpose: Calculate subtotal + shipping + tax        */
/*******************************************************/
function CalculateTotalxxx() {
    var divSubtotal = document.getElementById('divSubtotal');
    var divTax = document.getElementById('divTax');
    var divShipping = document.getElementById('divShipping');
    var divTotal = document.getElementById('divTotal');
    var cboShipping = document.getElementById('cboShipVia');
    var txtSubtotal = document.getElementById('txtSubtotal');
    var txtTax = document.getElementById('txtTax');

    divSubtotal.innerHTML = txtSubtotal.value;
    divTax.innerHTML = txtTax.value;
    divShipping.innerHTML = cboShipping.options[cboShipping.selectedIndex].value;
    divTotal.innerHTML = txtSubtotal.value + txtTax.value + cboShipping.options[cboShipping.selectedIndex].value;
}


/*******************************************************/
/*Function: DisplayCart                                */
/**Purpose: Display Cart (or message) - ViewCart.aspx  */
/*******************************************************/
function DisplayCart(Num) {
    var divCart = document.getElementById('divCart');
    var divMessage = document.getElementById('divMessage');

    if (Num == 0) {
        //No items in cart (or cart not started)
        divCart.style.display = "none";
        divMessage.style.display = "block";
    }
    else {
        //Cart started and has items
        divCart.style.display = "block";
        divMessage.style.display = "none";

    }
}
/*******************************************************/
/*Function: DivToggle                                  */
/**Purpose: Toggle div display styles - Account.aspx   */
/*******************************************************/
function DivToggle(ID) {
    var divProfile, divHistory;

    var txt = document.getElementById('ctl00_ContentPlaceHolder1_txtUserID');
    var divMessage = document.getElementById('divMessage');
    var divProfile = document.getElementById('divProfile');
    var divHistory = document.getElementById('divHistory');

    //User has not logged in
    if (isNaN(txt.value)) {
        alert('Please login to the store to view your ' + ID);
        return;
    }

    if (ID == "Profile") {
        divMessage.style.display = 'none';
        divProfile.style.display = 'block';
        divHistory.style.display = 'none';
    }
    else if (ID == "History") {
        divMessage.style.display = 'none';
        divProfile.style.display = 'none';
        divHistory.style.display = 'block';
    }
}
/*****************************************/
/*Function: HideImageBox()               */
/**Purpose: Hide the image popup         */
/*****************************************/
function HideImageBox() {
    var divImageBox = document.getElementById('divImageBox');
    var fraShim = document.getElementById('fraShim');

    fraShim.style.display = "none";
    fraShim.style.left = "-500px";
    fraShim.style.top = "-500px";

    divImageBox.style.left = "-200px";
    divImageBox.style.top = "-1000px";
}
/*****************************************/
/*Function: HideMsgBox()                 */
/**Purpose: Hide the message popup       */
/*****************************************/
function HideMsgBox() {
    var divMsgBox = document.getElementById('divMsgBox');
    var fraShim = document.getElementById('fraShim');

    fraShim.style.display = "none";
    fraShim.style.left = "-500px";
    fraShim.style.top = "-500px";

    divMsgBox.style.left = "-200px";
    divMsgBox.style.top = "-1000px";
}
/*******************************************************/
/*Function: InitItemsPage                              */
/**Purpose: Initialize images on items.aspx            */
/*******************************************************/
function InitItemsPage() {
    var imgUpper = document.getElementById('imgUpper');
    var imgLower = document.getElementById('imgLower');
 
    imgUpper.src = "imgs/general/spacer.gif";
    imgLower.src = "imgs/general/spacer.gif";
}
/*****************************************/
/*Function: LoginNewUser()               */
/**Purpose: Go to login for new user     */
/*****************************************/
function LoginNewUser() {
    var msg;

    msg = "Your account was created successfully, do you wish to login now?";

    if (confirm(msg)) {
        window.location.href = "Default.aspx";
    }
}
/*******************************************************/
/*Function: MemberOption()                             */
/**Purpose: Toggle txtMemberID properties              */
/*******************************************************/
function MemberOption() {
    var txt, opt;

    txt = document.getElementById('ctl00_ContentPlaceHolder1_txtMemberID');
    opt = document.getElementById('ctl00_ContentPlaceHolder1_rbtnMember_0');

    if (opt.checked) {
        //Yes - user states they are a member
        txt.disabled = false;
        txt.style.backgroundColor = "#FFFFFF";
    }
    else {
        //No - user states they are not a member
        txt.disabled = true;
        txt.style.backgroundColor = "#CCCCCC";
        txt.value = "";
    }
}
/*******************************************************/
/*Function: Messagebox                                 */
/**Purpose: Messagebox                                 */
/*******************************************************/
function Messagebox(msg) {
    var spn = document.getElementById('spnMessage');

    spn.innerHTML = msg;

    ShowMsgBox();
}
/*******************************************************/
/*Function: onImage Error(source)                      */
/**Purpose: Display default image upon error           */
/*******************************************************/
function onImageError(source) {
    source.src = "imgs/items/aloa.gif";

    // disable onerror to prevent endless loop
    source.onerror = "";

    return true;
}
/*****************************************/
/*Function: SetFocus()                   */
/**Purpose: Set control focus            */
/*****************************************/
function SetFocus(id) {
    var ctrl;

    ctrl = document.getElementById(id);
    ctrl.focus();
}
/*****************************************/
/*Function: ShowImageBox()               */
/**Purpose: Show the image popup         */
/*****************************************/
function ShowImageBox() {
    var divImageBox = document.getElementById('divImageBox');
    var fraShim = document.getElementById('fraShim');
    var xpos, ypos;

    xpos = (screen.width / 2) - 200;
    ypos = (screen.height / 2) - 200;

    divImageBox.style.left = xpos + 'px';
    divImageBox.style.top = ypos + 'px';

    fraShim.style.width = divImageBox.offsetWidth;
    fraShim.style.height = divImageBox.offsetHeight;

    fraShim.style.left = xpos + 'px';
    fraShim.style.top = ypos + 'px';
    fraShim.style.zIndex = divImageBox.style.zIndex - 1;
    fraShim.style.display = "block";
    fraShim.style.backgroundColor = "black";
}
/*****************************************/
/*Function: ShowMsgBox()                 */
/**Purpose: Show the message popup       */
/*****************************************/
function ShowMsgBox() {
    var divMsgBox = document.getElementById('divMsgBox');
    var fraShim = document.getElementById('fraShim');
    var xpos, ypos;

    xpos = (screen.width / 2) - 200;
    ypos = (screen.height / 2) - 200;

    divMsgBox.style.left = xpos + 'px';
    divMsgBox.style.top = ypos + 'px';

    fraShim.style.width = divMsgBox.offsetWidth;
    fraShim.style.height = divMsgBox.offsetHeight;

    fraShim.style.left = xpos + 'px';
    fraShim.style.top = ypos + 'px';
    fraShim.style.zIndex = divMsgBox.style.zIndex - 1;
    fraShim.style.display = "block";
    fraShim.style.backgroundColor = "black";
}
/*******************************************************/
/*Function: ToggleList                                 */
/**Purpose: Toggle div display for items.aspx          */
/*******************************************************/
function ToggleList() {
    var imgUpper = document.getElementById('imgUpper');
    var imgLower = document.getElementById('imgLower');
    var div = document.getElementById('divItemsList');
    
    if (imgUpper.src.indexOf('plus', 0) > 0) {
        imgUpper.src = "imgs/buttons/minus.gif";
        imgLower.src = "imgs/buttons/minus.gif";

        div.style.height = "100%";
    }
    else {
        imgUpper.src = "imgs/buttons/plus.gif";
        imgLower.src = "imgs/buttons/plus.gif";

        div.style.height = "365px";
    }
}
/*******************************************************/
/*Function: TrapBtnClick                               */
/**Purpose: Trap {Enter} key - Default.aspx            */
/*******************************************************/
function TrapBtnClick(id, event) {

    var btn = document.getElementById(id);

    if (document.all) 
    {
        if (event.keyCode == 13) 
        {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
    else if (document.getElementById) 
    {
        if (event.which == 13) 
        {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
    else if (document.layers) 
    {
        if (event.which == 13) 
        {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
}
/*******************************************************/
/*Function: IFDIARedirect                              */
/**Purpose: Redirect to IFDIA                          */
/*******************************************************/
function IFDIARedirect(ID) {
    var divBtn;
    var divMsg  ; 

    divBtn = document.getElementById('divButton');
    divMsg = document.getElementById('divMessage');
    
    divBtn.style.display="none";
    divMsg.style.display = "block";

    window.location.href = "http://ifdia.org/elearning/login/index.php?id=" + ID + 
                           "&aloa=yes&courseid=3&returnurl=aloastore.com/IFDIAGrade.aspx";
}
/*******************************************************/
/*Function: ItemMessage                                */
/**Purpose: Add to cart message - Items.aspx           */
/*******************************************************/
function ItemMessage(ID) {

    if (ID == 241)
        return confirm('Adding this item will start the IFDIA registration process. Are you ready to take the pre-qual test?');
    else
        return confirm('Are you sure you wish to add this item to your cart?');
}
/*******************************************************/
/*Function: ItemMessageByCtrl                          */
/**Purpose: Add to cart message - Items.aspx           */
/*******************************************************/
function ItemMessageByCtrl() {

    var txt = document.getElementById('ctl00_ContentPlaceHolder1_txtItemID');

    if (txt) {
        if (txt.value == 241)
            return confirm('Adding this item will start the IFDIA registration process. Are you ready to take the pre-qual test?');
        else
            return confirm('Are you sure you wish to add this item to your cart?');
    }
    else
        return confirm('Are you sure you wish to add this item to your cart?');
}

