function verifyPage1(theForm)
{
    var why = "";
    why += checkField(theForm.CityOrZip.value, "-- City or Zip Code --", "City or Zip Code");
    if (why != "") {
        alert(why);
        return false;
    }

    // Just go to the next tab
    gotoTab2();
}
function verifyPage2(theForm)
{
    var why = "";
    //why += checkField(theForm.Donation.value, "-- Donation Amount --", "Donation Amount");
    if (why != "") {
        alert(why);
        return false;
    }
    
    return true;
}
function verifyPage3(theForm)
{
    var why = "";
    why += checkField(theForm.Name.value, "", "Your Name");
    why += checkField(theForm.Email.value, "", "Email Address");
    if (why != "") {
        alert(why);
        return false;
    }
    
    return true;
}

function checkField (val, valWhat, field) {
    var error = "";
    if (val == "" || val == valWhat) {
        error = "You must enter a value in the " + field + " field\n";
    }

    return error;
}

function clearField(text, target)
{
    if (target.value == text)
    {
        target.value = '';
    }
}

function openPage(target)
{
	window.location = target;
}

// Preload rollovers
btn1 = new Image();
btn1.src = 'gfx/next_over.gif';
btn2 = new Image();
btn2.src = 'gfx/send_request_over.gif';
btn3 = new Image();
btn3.src = 'gfx/view_over.gif';
btn4 = new Image();
btn4.src = 'gfx/back_over.gif';

// Handle rollover images - insert '_over' and take it out again
function rollover(target)
{
	if (document.getElementById(target).src.indexOf('_over') == -1)
	{
		newImg = document.getElementById(target).src.replace(/\.(.{3,4})$/g, "_over.$1");
		document.getElementById(target).src = newImg;
    }
}

function rollout(target)
{
	newImg = document.getElementById(target).src.replace(/\_over/g, "");
	document.getElementById(target).src = newImg;
}

// 'from' is a string like 'tcontent1', to is a function like openTab2
// While I could use this for nearly everything, I'm only using it to swap divs with the back buttons
function gotoTab(from, to)
{
	Effect.toggle(from, 'appear', { afterFinish: to, duration: 0.5 });
}
function gotoTab2()
{
	Effect.toggle('tcontent1', 'appear', { afterFinish: openTab2, duration: 0.5 });
}

function openTab1()
{
	Effect.toggle('tcontent1', 'appear', { duration: 0.5 } );
}
function openTab2()
{
	Effect.toggle('tcontent2', 'appear', { duration: 0.5 } );
}
function openTab3()
{
	Effect.toggle('tcontent3', 'appear', { duration: 0.5 } );
}
function openTab4()
{
	Effect.toggle('tcontent4', 'appear', { duration: 0.5 } );
}

// Submit first form
function verifySteps1And2(target)
{
	document.getElementById('action').value = 'mmrCheck'; // Set this to the 'default' to really run these numbers
	if (verifyPage2(target))
	{
		Effect.toggle('tcontent2', 'appear', { afterFinish: openTab3, duration: 0.5 });
		new Ajax.Updater('tcontent3', '/gc_central/brain.php', {asynchronous:true, parameters:Form.serialize(target)});
	}
	return false;
}

// Swap out 'close match' and load step 3 'no match' form
function refreshStep3(target)
{
	document.getElementById('action').value = 'mmrCheckForceNoMatch'; // Set this to force the 'no match' page
	Effect.toggle('tcontent3', 'appear', { afterFinish: openTab3, duration: 0.5 });
	new Ajax.Updater('tcontent3', '/gc_central/brain.php', {asynchronous:true, parameters:Form.serialize(target)});
}

// Open the 'step 3' form
function sendFinalForm(target)
{
	if (verifyPage3(target))
	{
		document.getElementById('action').value = 'mmrStep3'; // Set this to get the thank you page
		Effect.toggle('tcontent3', 'appear', { afterFinish: openTab4, duration: 0.5 });
		new Ajax.Updater('tcontent4', '/gc_central/brain.php', {asynchronous:true, parameters:Form.serialize(target)});
	}
	return false;
}