// JavaScript Document// Example: obj = findObj("image1");
function findObj(theObj, theDoc) {
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

function compute() {
	full = findObj("full").value;
	add = findObj("add").value;
	single = findObj("single").value;
	//singleparent = findObj("singleparent").value;
	aurorapickup = findObj("aurorapickup").value;
	donation = findObj("donation").value;
	findObj("total").value = (full * 495) + (add * 100) + (single * 375) + (aurorapickup * 495) + (donation * 1);
}

function toggle_payment() {
	findObj('card_name').disabled = (findObj('card').checked) ? false : true;
	findObj('card_number').disabled = (findObj('card').checked) ? false : true;
	findObj('card_expiration').disabled = (findObj('card').checked) ? false : true;
}

function toggle_mission() {
	findObj('mission_statement').className  = (findObj('mission_statement').className == "hide") ? "show" : "hide";
}

function focus_share_form() {
	findObj('full').focus();
}

function validate() {
	var errors = "";
	var error = 0;
	errors = '<p>We found the following errors with your form:</p>';
	errors += '<ul>';
	if((findObj("full").value + findObj("single").value) <= 0) {
		errors += '<li><label for="total">Share Options</label> - Please choose your share options</li>';
		error = 1;
	}
	if(findObj('card').checked) {
		if(!findObj("card_name").value) {
			errors += '<li><label for="card_name">Name on Card</label> - Please enter the name on your card</li>';
			error = 1;
		}
		if(!findObj("card_number").value) {
			errors += '<li><label for="card_number">Card Number</label> - Please enter your card number</li>';
			error = 1;
		} else if(!findObj("card_number").value.match(/^([0-9]{16})$/)) {
			errors += '<li><label for="card_number">Card Number</label> - Please enter a valid card number</li>';
			error = 1;
		}
		if(!findObj("card_expiration").value) {
			errors += '<li><label for="card_expiration">Card Expiration</label> - Please enter your card expiration date</li>';
			error = 1;
		} else if(!findObj("card_number").value.match(/^([0-9]{16})$/)) {
			errors += '<li><label for="card_number">Card Number</label> - Please enter a valid card number</li>';
			error = 1;
		}
	}
	if(!findObj("first_name").value) {
		errors += '<li><label for="first_name">First Name</label> - Please enter your first name</li>';
		error = 1;
	}
	if(!findObj("last_name").value) {
		errors += '<li><label for="last_name">Last Name</label> - Please enter your last name</li>';
		error = 1;
	}
	if(!findObj("address").value) {
		errors += '<li><label for="address">Address</label> - Please enter your address</li>';
		error = 1;
	}
	if(!findObj("city").value) {
		errors += '<li><label for="city">City</label> - Please enter your city</li>';
		error = 1;
	}
	if(!findObj("state").value) {
		errors += '<li><label for="state">State</label> - Please enter your state</li>';
		error = 1;
	}
	if(!findObj("zip").value) {
		errors += '<li><label for="zip">Zip Code</label> - Please enter your zip code</li>';
		error = 1;
	}
	if(!findObj("phone").value) {
		errors += '<li><label for="phone">Phone</label> - Please enter your phone number</li>';
		error = 1;
	} else if(!findObj("phone").value.match(/^([0-9]{3})-([0-9]{3})-([0-9]{4})$/)) {
		errors += '<li><label for="phone">Phone</label> - Please enter a valid phone number</li>';
		error = 1;
	}
	if(!findObj("email").value) {
		errors += '<li><label for="email">Email</label> - Please enter your email address</li>';
		error = 1;
	} else if(!findObj("email").value.match(/^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/)) {
		errors += '<li><label for="email">Email Address</label> - Please enter a valid email address</li>';
		error = 1;
	}
	errors += '</ul>';
	if(error) {
		findObj("errors").innerHTML = errors;
		findObj("errors").className = "show";
		document.location = "#top";
	} else {
		findObj("valid").value = 1;
		findObj("share_form").submit();
	}
}
