﻿function GetEmailAddress() {
    var emailBox = document.getElementById("customerEmailLocation");
    if (emailBox != null)
        emailBox.style.display = "inline";
    var sendButton = document.getElementById("sendButtonLocation");
    if (sendButton != null)
        sendButton.style.display = "inline";
    var emailNotice = document.getElementById("emailNotice");
    if (emailNotice != null)
        emailNotice.style.display = "none";
    return false;
}
function ShowEmailPrompt(target) {
    if (target.value == null || target.value.length == 0) {
        if (target.name.toLowerCase() == "customeremail")
            target.value = "To Email Address";
        else if (target.name.toLowerCase() == "retaileremail")
            target.value = "From Email Address";
        else
            target.value = "Email Address";
    }
}
function HideEmailPrompt(target) {
    if (target.value != null && target.value.length > 0 && (target.value.toLowerCase() == "email address" || target.value.toLowerCase() == "from email address" || target.value.toLowerCase() == "to email address"))
        target.value = "";
}
function ShowPrintDialog() {
    window.print();
    return false;
}
function SendDetailsEmail() {
    var customerEmailAddress = m020_GetTextFromBox("customerEmail");
    var retailerEmailAddress = m020_GetTextFromBox("retailerEmail");
    
    if (customerEmailAddress.length > 0) {
        var currentLocation = document.location + '';
        var emailIdentifier = "email=";
        var indexOfEmail = currentLocation.indexOf(emailIdentifier);
        if (indexOfEmail > 0)
            currentLocation = currentLocation.substring(0, indexOfEmail - 1);
        var emailJoin = "?";
        if (currentLocation.indexOf("?") > 0)
            emailJoin = "&";
        
        var newLocation = currentLocation + emailJoin + emailIdentifier + customerEmailAddress
        
        if(retailerEmailAddress.length > 0) {
            var fromIdentifier = "from=";
            indexOfEmail = newLocation.indexOf(fromIdentifier);
            if (indexOfEmail > 0)
                newLocation = newLocation.substring(0, indexOfEmail - 1);
            var fromJoin = "?";
            if (newLocation.indexOf("?") > 0)
                fromJoin = "&";
            newLocation = newLocation+ fromJoin + fromIdentifier + retailerEmailAddress;
        }
        document.location = newLocation;
    }
}

function m020_GetTextFromBox(id) {
    var text = '';
    var textBox = document.getElementById(id);
    if (textBox != null) {
        text = textBox.value;
    }
    return text;
}

function m020_ToggleSpecs(id) {
    var area = document.getElementById(id);
    if (area != null) {
        var isHidden = true;
        if (area.style != null && area.style.display != null && area.style.display == 'block') {
            isHidden = false;
        }
        if (isHidden) {
            area.style.display = 'block';
        } else {
            area.style.display = 'none';
        }
        var status = document.getElementById(id + '-status');
        if (status != null) {
            if (isHidden) {
                status.innerHTML = 'Hide';
            } else {
                status.innerHTML = 'Show';
            }
        }
    }
}
