﻿
var prfx = "";

function hide(element) { if (element) { element.style.visibility = "hidden" }; if (element) { element.style.display = "none" }; }
function show(element) { element.style.visibility = "visible"; element.style.display = ""; }
function toggle_Country() {
    Country_Switch(document.getElementById(prfx + "Country"));
}
function selectFocus(obj) {
    obj.select();
}
function amountChange(obj) {
    document.getElementById(prfx + "Amount").value = obj.value
    var elem = document.getElementById('donate_errorloc');
    elem.innerHTML = "Donation amount: <b><span style='font-size: larger'>$" + obj.value + "</span></b>";
    
    amountRadioCheck(obj);
}
function amountRadioCheck(obj) {
    if (obj.value == "250.00") {
        document.getElementById("donation_250").checked = true;
    } else if (obj.value == "100.00") {
        document.getElementById("donation_100").checked = true;
    } else if (obj.value == "50.00") {
        document.getElementById("donation_050").checked = true;
    } else if (obj.value == "25.00") {
        document.getElementById("donation_025").checked = true;
    } else {
        document.getElementById("donation_025").checked = true;
        document.getElementById("donation_025").checked = false;
    }
}

function Country_Switch(element) {
    if (element.value == "US") {
        show(document.getElementById(prfx + "StateUS"));
        hide(document.getElementById(prfx + "StateCA"));
        hide(document.getElementById(prfx + "StateOther"));
    } else if (element.value == "CA") {
        hide(document.getElementById(prfx + "StateUS"));
        show(document.getElementById(prfx + "StateCA"));
        hide(document.getElementById(prfx + "StateOther"));
    } else {
        hide(document.getElementById(prfx + "StateUS"));
        hide(document.getElementById(prfx + "StateCA"));
        show(document.getElementById(prfx + "StateOther"));
    }
}
function donamtChange(obj, chk) {
    num = obj.value
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num)) num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    //num = Math.floor(num*100+0.0);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    dollar = num
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
        num.substring(num.length - (4 * i + 3));
    num = (((sign) ? '' : '-') + '$' + num + '.' + cents);

    obj.value = num.replace(/\$|\,/g, '');
    amountChange(obj);
}
function menuOver(img) {
    img.src = img.src.replace('_off', '_on');
    var childs = img.parentNode.parentNode.parentNode.getElementsByTagName("ul");
    if (childs != null && childs.length > 0)
        childs[0].onmouseover = function() { img.src = img.src.replace('_off', '_on') };

}
function menuOut(img) {
    if (img.title == 'Selected') {
        return;
    }
    img.src = img.src.replace('_on', '_off');
    var childs = img.parentNode.parentNode.parentNode.getElementsByTagName("ul");
    if (childs != null && childs.length > 0)
        childs[0].onmouseout = function() { img.src = img.src.replace('_on', '_off') };
}
function captInfo() {
    window.open('capinfo.htm', 'capinfo', 'width=500,height=200')
}
function cardInfo() {
    window.open('cardinfo.htm', 'cardinfo', 'width=500,height=450')
}
function donateSecure() {
    window.open('donsecure.html', 'donsecure', 'width=500,height=300')
}
function captReload(id) {
    var date = new Date();
    document.getElementById(id).src = document.getElementById(id).src + '?key=' + date.getTime();
    return false;
}
