

	// Create an associative array of 'pretty name' values
	var prettynames = {
						category_id:"Grant Category",
						cc_fname:"First Name",
						cc_lname:"Last Name",
						cc_addr:"Address",
						cc_city:"City",
						cc_state:"State",
						cc_zip:"Zip",
						cc_phonearea:"Phone Number Area Code",
						cc_phoneprefix:"Phone Number Prefix",
						cc_phoneextension:"Phone Number Ending",
						cc_email:"Email Address",
						app_gender:"Gender",
						app_citizenship:"Citizenship",
						app_age:"Your age",
						app_amount_needed:"The amount meeded",
						app_usedescription:"Describe what you will use the money for",
						app_uniqueness:"Uniqueness",

						diploma:"Do you have a high school diploma or GED?",
						online_business:"Would you like to start an online business to make money while you go to school if we could help pay for your training?",
						serious_scale:"In a scale of 1-10 how serious are you about getting a degree online?",
						college:"Have you gone to college?",
						degree:"Do you have a degree?",
						willing_second_degree:"Are you willing to get a second degree in business?",
						have_computer:"Do you have access to a computer for taking the online classes and working on your business?"
						};
						
// Utility function that returns true if a string contains only
// whitespace characters
// Taken from "Javascript: The Definitive Guide" pg. 264
function isblank(s)
{
	for (var i=0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((c!=' ') && (c != '\n') && (c != '')) 
		{
			return false;
		}
	}
	return true;
}

// Credit Card Validation Javascript
// copyright 12th May 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateCreditCard(s) {

// remove non-numerics
var v = "0123456789";
var w = "";
for (i=0; i < s.length; i++) {
x = s.charAt(i);
if (v.indexOf(x,0) != -1)
w += x;
}
// validate number
j = w.length / 2;
if (j < 6.5 || j > 8 || j == 7) return false;
k = Math.floor(j);
m = Math.ceil(j) - k;
c = 0;
for (i=0; i<k; i++) {
a = w.charAt(i*2+m) * 2;
c += a > 9 ? Math.floor(a/10 + a%10) : a;
}
for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
return (c%10 == 0);
}

function verify(f)
{

	// Taken from "Javascript: The Definitive Guide" pg. 264.
	// Modified heavily to suit our needs
	// Loop through each element of the form and validate each item
	//
	// Set the parameters for each field to be valid
	// If a field doesn't have any modifiers it is assumed to be 
	// a text field that can not be blank.
	
	f.cc_phonearea.requiredlength = 3;
	f.cc_phonearea.numeric = true;
	
	f.cc_phoneprefix.requiredlength = 3;
	f.cc_phoneprefix.numeric = true;
	
	f.cc_phoneextension.requiredlength = 4;
	f.cc_phoneextension.numeric = true;
	
	f.cc_zip.requiredlength = 5;
	f.cc_zip.numeric = true;
	
		
	var msg;
	var empty_fields = "";
	var errors = "";
	
	for (var i=0; i < f.length; i++)
	{	
		var element = f.elements[i];
		//document.getElementById('errorconsole').innerHTML += element.name + ":" + element.type + "<br>";
		if($(element).is(':hidden')) {
			continue;
		}

		if ((element.type == 'text' || element.type == 'textarea') && (element.name != 'granttype_other'))
		{
			if ( (element.value == null || element.value == "") || isblank(element.value) )
			{
				empty_fields += "\n        " + prettynames[element.name];
				continue;
			}
			if (element.numeric)
			{
				var v = parseFloat(element.value);
				if (isNaN(v))
				{
					errors +="- The field " + prettynames[element.name] + " must be a number\n";
				}
			}
			if ( (element.requiredlength > 0) && (element.value.length != element.requiredlength) )
			{
				errors += "- The field " + prettynames[element.name] + " must be " + element.requiredlength + " digits long\n";
			}
		}
		else if (element.type == 'select-one')
		{
			// The first option, option[0] can not be selected
			if ( (element.value == null || element.value == "" || element.selectedIndex == 0) || isblank(element.value) )
			{
				empty_fields += "\n        " + prettynames[element.name];
				continue;
			}
		}
		else if (element.type == 'radio')
		{
			if (!$('[name='+element.name+']:checked').val() && empty_fields.indexOf(prettynames[element.name]) == -1)
			{
				empty_fields += "\n        " + prettynames[element.name];
				continue;
			}
		}

	}
	
	
	
	if (!empty_fields && !errors) { return true; }
	
	msg		 = "__________________________________\n\n";
	msg		+= "The form was not submitted because of the following error(s).\n";
	msg		+= "Please correct these error(s) and re-submit.\n";
	msg		+= "__________________________________\n\n";
	
	if (empty_fields) 
	{
		msg += "- The following required field(s) are empty:" + empty_fields + "\n";
		if (errors) { msg += "\n"; }
	}
	msg += errors;
	alert(msg);
	return false;
}

function tab_phone(current,next) {

	var currentfield = document.getElementById(current);
	var nextfield = document.getElementById(next);
	
	if (currentfield.value.length == 3) { nextfield.focus(); }
	
}


