function openWin() {
    var url, width = 500, height = 200, menu = "";
    args = arguments;
    url = args[0];
    if (args.length > 1) {
        width = args[1];
    }
    if (args.length > 2) {
        height = args[2];
    }
    if (args.length > 3) {
        if (args[3]) {
            menu = ",menubar=yes,toolbar=yes";
        }
    }
    var newwin = window.open(url, 'newWin' + Math.floor(Math.random() * 1000), 'width=' + width + ',height=' + height + ',scrollbars,resizable' + menu);
}

function showConfirmation(url) {
    targetUrl = url;
    window.open('/static/html/confirm_external_link.html', 'confirm', 'width=420,height=280,resizable=yes').focus();
}

/**
 * Tabbed Content for Contact Us Product Information
 */
function prodSupportSelectedItem(currProd) {
    //Global variable declaration
    var offClass = "contact-us-prod-support-item-off";
    var onClass = "contact-us-prod-support-item-on";
    var offClassTopCell = "contact-us-prod-support-item-off-for-top-cell";
    var offClassMdlCell = "contact-us-prod-support-item-off-for-middle-cell";

    //Array
    var prodArray = ['prd1','prd2'];
    var prodContentArray = ['prdContent1','prdContent2','prdContent3'];

    for (var i = 0; i < prodArray.length; i++) {
        if (currProd == prodArray[i]) {
            if (i == 1) {
                document.getElementById(prodArray[i - 1]).className = offClassTopCell;
            } else if (i == (prodArray.length - 1)) {
                document.getElementById(prodArray[0]).className = offClassTopCell;
                document.getElementById(prodArray[i - 1]).className = offClassMdlCell;
            }
            document.getElementById(prodArray[i]).className = onClass;
            document.getElementById(prodContentArray[i]).style.display = "block";
        }
        else {
            document.getElementById(prodArray[i]).className = offClass;
            document.getElementById(prodContentArray[i]).style.display = "none";
        }
    }
}

/**
 * Toggle main and print CSS styles
 */

function togglePrintStyle() {
    var mainStyle = document.getElementById("mainStyle");
    var printStyle = document.getElementById("printStyle");

    mainStyle.disabled = !mainStyle.disabled;
    printStyle.disabled = !printStyle.disabled;
}

function addConfirmation() {
    var links = document.getElementsByClassName("selected-row")[0].getElementsByTagName("a");
    for (var j = 0; j < links.length; j++) {
        if (links[j].title == "Insulin Pumps") {
            links[j].addEventListener("click", function(e) {confirmationAction(e, true);}, false);
        } else if (links[j].title == "Data Management Systems") {
            links[j].addEventListener("click", function(e) {confirmationAction(e, false);})
        }
    }
}

function confirmationAction(e, confirm) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) {
        targ = e.target;
    } else if (e.srcElement) {
        targ = e.srcElement;
    }
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;

    e.preventDefault();

    if (confirm) {
        showConfirmation("javascript:openWin('" + targ.toString() + "',800,600,true);");
    }
    else {
        window.open('/static/html/dms-popup.html','confirm','width=440,height=360,scrollbars=yes,resizable=no,location=no').focus();
    }
}
