//
// Javascript used by the Henry's Heartlings Donation page
//

function displayOn(ident)
{
    document.getElementById(ident).style.display = 'block';
}

function displayOff(ident)
{
    document.getElementById(ident).style.display = 'none';
}

function setup()
{
    // hide things shown if no javascript
    displayOff('hradio');
    displayOff('kradio');
    displayOff('gradio');
    displayOff('jradio');
    displayOff('dradio');
    displayOff('rradio');
    displayOff('aradio');
    displayOff('honored');

    // load images to cache
    hgrey = new Image();
    kgrey = new Image();
    ggrey = new Image();
    jgrey = new Image();
    dgrey = new Image();
    rgrey = new Image();
    agrey = new Image();
    hgrey.src = "images/Henry-grey.png";
    kgrey.src = "images/Kath-grey.png";
    ggrey.src = "images/Greg-grey.png";
    jgrey.src = "images/Jason-grey.png";
    dgrey.src = "images/Danni-grey.png";
    rgrey.src = "images/Richard-grey.png";
    agrey.src = "images/Amy-grey.png";

}

function activateHenry()
{
    //    alert("Henry has already reached his fundraising goal.\nPlease choose another walker to help reach their goal.\nAll donations will help the AHA, no matter which walker you choose.");

    // check index on next line
    document.getElementById('donation').supId[0].checked = true;
    document.getElementById('henry').style.background = '#FFCCCC';
    document.getElementById('henry').style.border = '2px solid #981B1E';
    document.getElementById('hpict').src = 'images/Henry.png';
    document.getElementById('kath').style.background = '#CCCCCC';
    document.getElementById('kath').style.border = '2px solid #CCCCCC';
    document.getElementById('kpict').src = 'images/Kath-grey.png';
    document.getElementById('greg').style.background = '#CCCCCC';
    document.getElementById('greg').style.border = '2px solid #CCCCCC';
    document.getElementById('gpict').src = 'images/Greg-grey.png';
    document.getElementById('jason').style.background = '#CCCCCC';
    document.getElementById('jason').style.border = '2px solid #CCCCCC';
    document.getElementById('jpict').src = 'images/Jason-grey.png';
    document.getElementById('danni').style.background = '#CCCCCC';
    document.getElementById('danni').style.border = '2px solid #CCCCCC';
    document.getElementById('dpict').src = 'images/Danni-grey.png';
    document.getElementById('richard').style.background = '#CCCCCC';
    document.getElementById('richard').style.border = '2px solid #CCCCCC';
    document.getElementById('rpict').src = 'images/Richard-grey.png';
    document.getElementById('amy').style.background = '#CCCCCC';
    document.getElementById('amy').style.border = '2px solid #CCCCCC';
    document.getElementById('apict').src = 'images/Amy-grey.png';
}

function activateKath()
{
    //    alert("Kath has already reached her fundraising goal.\nPlease choose another walker to help reach their goal.\nAll donations will help the AHA, no matter which walker you choose.");

    // check index on next line
    document.getElementById('donation').supId[1].checked = true;
    document.getElementById('henry').style.background = '#CCCCCC';
    document.getElementById('henry').style.border = '2px solid #CCCCCC';
    document.getElementById('hpict').src = 'images/Henry-grey.png';
    document.getElementById('kath').style.background = '#FFCCCC';
    document.getElementById('kath').style.border = '2px solid #981B1E';
    document.getElementById('kpict').src = 'images/Kath.png';
    document.getElementById('greg').style.background = '#CCCCCC';
    document.getElementById('greg').style.border = '2px solid #CCCCCC';
    document.getElementById('gpict').src = 'images/Greg-grey.png';
    document.getElementById('jason').style.background = '#CCCCCC';
    document.getElementById('jason').style.border = '2px solid #CCCCCC';
    document.getElementById('jpict').src = 'images/Jason-grey.png';
    document.getElementById('danni').style.background = '#CCCCCC';
    document.getElementById('danni').style.border = '2px solid #CCCCCC';
    document.getElementById('dpict').src = 'images/Danni-grey.png';
    document.getElementById('richard').style.background = '#CCCCCC';
    document.getElementById('richard').style.border = '2px solid #CCCCCC';
    document.getElementById('rpict').src = 'images/Richard-grey.png';
    document.getElementById('amy').style.background = '#CCCCCC';
    document.getElementById('amy').style.border = '2px solid #CCCCCC';
    document.getElementById('apict').src = 'images/Amy-grey.png';
}

function activateGreg()
{
    // check index on next line
    document.getElementById('donation').supId[2].checked = true;
    document.getElementById('henry').style.background = '#CCCCCC';
    document.getElementById('henry').style.border = '2px solid #CCCCCC';
    document.getElementById('hpict').src = 'images/Henry-grey.png';
    document.getElementById('kath').style.background = '#CCCCCC';
    document.getElementById('kath').style.border = '2px solid #CCCCCC';
    document.getElementById('kpict').src = 'images/Kath-grey.png';
    document.getElementById('greg').style.background = '#FFCCCC';
    document.getElementById('greg').style.border = '2px solid #981B1E';
    document.getElementById('gpict').src = 'images/Greg.png';
    document.getElementById('jason').style.background = '#CCCCCC';
    document.getElementById('jason').style.border = '2px solid #CCCCCC';
    document.getElementById('jpict').src = 'images/Jason-grey.png';
    document.getElementById('danni').style.background = '#CCCCCC';
    document.getElementById('danni').style.border = '2px solid #CCCCCC';
    document.getElementById('dpict').src = 'images/Danni-grey.png';
    document.getElementById('richard').style.background = '#CCCCCC';
    document.getElementById('richard').style.border = '2px solid #CCCCCC';
    document.getElementById('rpict').src = 'images/Richard-grey.png';
    document.getElementById('amy').style.background = '#CCCCCC';
    document.getElementById('amy').style.border = '2px solid #CCCCCC';
    document.getElementById('apict').src = 'images/Amy-grey.png';
}

function activateJason()
{
    // check index on next line
    document.getElementById('donation').supId[3].checked = true;
    document.getElementById('henry').style.background = '#CCCCCC';
    document.getElementById('henry').style.border = '2px solid #CCCCCC';
    document.getElementById('hpict').src = 'images/Henry-grey.png';
    document.getElementById('kath').style.background = '#CCCCCC';
    document.getElementById('kath').style.border = '2px solid #CCCCCC';
    document.getElementById('kpict').src = 'images/Kath-grey.png';
    document.getElementById('greg').style.background = '#CCCCCC';
    document.getElementById('greg').style.border = '2px solid #CCCCCC';
    document.getElementById('gpict').src = 'images/Greg-grey.png';
    document.getElementById('jason').style.background = '#FFCCCC';
    document.getElementById('jason').style.border = '2px solid #981B1E';
    document.getElementById('jpict').src = 'images/Jason.png';
    document.getElementById('danni').style.background = '#CCCCCC';
    document.getElementById('danni').style.border = '2px solid #CCCCCC';
    document.getElementById('dpict').src = 'images/Danni-grey.png';
    document.getElementById('richard').style.background = '#CCCCCC';
    document.getElementById('richard').style.border = '2px solid #CCCCCC';
    document.getElementById('rpict').src = 'images/Richard-grey.png';
    document.getElementById('amy').style.background = '#CCCCCC';
    document.getElementById('amy').style.border = '2px solid #CCCCCC';
    document.getElementById('apict').src = 'images/Amy-grey.png';
}

function activateDanni()
{
    // check index on next line
    document.getElementById('donation').supId[4].checked = true;
    document.getElementById('henry').style.background = '#CCCCCC';
    document.getElementById('henry').style.border = '2px solid #CCCCCC';
    document.getElementById('hpict').src = 'images/Henry-grey.png';
    document.getElementById('kath').style.background = '#CCCCCC';
    document.getElementById('kath').style.border = '2px solid #CCCCCC';
    document.getElementById('kpict').src = 'images/Kath-grey.png';
    document.getElementById('greg').style.background = '#CCCCCC';
    document.getElementById('greg').style.border = '2px solid #CCCCCC';
    document.getElementById('gpict').src = 'images/Greg-grey.png';
    document.getElementById('jason').style.background = '#CCCCCC';
    document.getElementById('jason').style.border = '2px solid #CCCCCC';
    document.getElementById('jpict').src = 'images/Jason-grey.png';
    document.getElementById('danni').style.background = '#FFCCCC';
    document.getElementById('danni').style.border = '2px solid #981B1E';
    document.getElementById('dpict').src = 'images/Danni.png';
    document.getElementById('richard').style.background = '#CCCCCC';
    document.getElementById('richard').style.border = '2px solid #CCCCCC';
    document.getElementById('rpict').src = 'images/Richard-grey.png';
    document.getElementById('amy').style.background = '#CCCCCC';
    document.getElementById('amy').style.border = '2px solid #CCCCCC';
    document.getElementById('apict').src = 'images/Amy-grey.png';
}

function activateRichard()
{
    // check index on next line
    document.getElementById('donation').supId[5].checked = true;
    document.getElementById('henry').style.background = '#CCCCCC';
    document.getElementById('henry').style.border = '2px solid #CCCCCC';
    document.getElementById('hpict').src = 'images/Henry-grey.png';
    document.getElementById('kath').style.background = '#CCCCCC';
    document.getElementById('kath').style.border = '2px solid #CCCCCC';
    document.getElementById('kpict').src = 'images/Kath-grey.png';
    document.getElementById('greg').style.background = '#CCCCCC';
    document.getElementById('greg').style.border = '2px solid #CCCCCC';
    document.getElementById('gpict').src = 'images/Greg-grey.png';
    document.getElementById('jason').style.background = '#CCCCCC';
    document.getElementById('jason').style.border = '2px solid #CCCCCC';
    document.getElementById('jpict').src = 'images/Jason-grey.png';
    document.getElementById('danni').style.background = '#CCCCCC';
    document.getElementById('danni').style.border = '2px solid #CCCCCC';
    document.getElementById('dpict').src = 'images/Danni-grey.png';
    document.getElementById('richard').style.background = '#FFCCCC';
    document.getElementById('richard').style.border = '2px solid #981B1E';
    document.getElementById('rpict').src = 'images/Richard.png';
    document.getElementById('amy').style.background = '#CCCCCC';
    document.getElementById('amy').style.border = '2px solid #CCCCCC';
    document.getElementById('apict').src = 'images/Amy-grey.png';
}

function activateAmy()
{
    // check index on next line
    document.getElementById('donation').supId[6].checked = true;
    document.getElementById('henry').style.background = '#CCCCCC';
    document.getElementById('henry').style.border = '2px solid #CCCCCC';
    document.getElementById('hpict').src = 'images/Henry-grey.png';
    document.getElementById('kath').style.background = '#CCCCCC';
    document.getElementById('kath').style.border = '2px solid #CCCCCC';
    document.getElementById('kpict').src = 'images/Kath-grey.png';
    document.getElementById('greg').style.background = '#CCCCCC';
    document.getElementById('greg').style.border = '2px solid #CCCCCC';
    document.getElementById('gpict').src = 'images/Greg-grey.png';
    document.getElementById('jason').style.background = '#CCCCCC';
    document.getElementById('jason').style.border = '2px solid #CCCCCC';
    document.getElementById('jpict').src = 'images/Jason-grey.png';
    document.getElementById('danni').style.background = '#CCCCCC';
    document.getElementById('danni').style.border = '2px solid #CCCCCC';
    document.getElementById('dpict').src = 'images/Danni-grey.png';
    document.getElementById('richard').style.background = '#CCCCCC';
    document.getElementById('richard').style.border = '2px solid #CCCCCC';
    document.getElementById('rpict').src = 'images/Richard-grey.png';
    document.getElementById('amy').style.background = '#FFCCCC';
    document.getElementById('amy').style.border = '2px solid #981B1E';
    document.getElementById('apict').src = 'images/Amy.png';
}

function checkHonored()
{
    if (document.donation.honor.checked == true)
	{
	    displayOn('honored');
	}
    else
	{
	    displayOff('honored');
	}
}

function checkMemorial()
{
    if (document.donation.memorial.checked == true)
	{
	    displayOff('address');
	}
    else
	{
	    displayOn('address');
	}
}

// Following function borrowed from: http://www.somacon.com/p143.php
//	return the value of the radio button that is checked return an
//	empty string if none are checked, or there are no radio
//	buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function validate()
{
    var errMsg = "Please be sure to enter the following:\n";
    var retval = true;
    var walkerId = 0;
    
    if (document.donation.donor.value == "")
	{
	    errMsg += "* donor name\n";
	    retval = false;
	}
    
    if (getCheckedValue(document.donation.kind) == "")
	{
	    errMsg += "* a donation method\n";
	    retval = false;
	}

    walkerId = getCheckedValue(document.donation.supId);
    if (walkerId == 0)
	{
	    errMsg += "* a Walker\n";
	    retval = false;
	}

    // Load the walker's name input for offline donation
    switch (walkerId)
	{
	case "139144318":
	    document.donation.walker.value = "Henry Schmitt";
	    break;
	case "146064011":
	    document.donation.walker.value = "Katherine Schmitt";
	    break;
	case "209299844":
	    document.donation.walker.value = "Greg Schmitt";
	    break;
	case "209299878":
	    document.donation.walker.value = "Jason Schmitt";
	    break;
	case "320443095":
	    document.donation.walker.value = "Danni Jones";
	    break;
	case "333375436":
	    document.donation.walker.value = "Richard McIntyre";
	    break;
	default:
	    document.donation.walker.value = "Team Donation";
	}
    
    if (document.donation.honor.checked)
	{
	    if (document.donation.honoree.value == "")
		{
		    errMsg += "* a name for your Honored Heartling\n";
		    retval = false;
		}
	    if (!document.donation.memorial.checked &&
		(document.donation.addr1.value == "" ||
		 document.donation.city.value == "" ||
		 document.donation.state.value == "" ||
		 document.donation.zip.value == ""))
		{
		    errMsg += "* a complete address for the Heartling Card\n";
		    retval = false;
		}
	}

    if (!retval)
	{
	    alert(errMsg);
	}

    return retval;
}

