function toggleHelp(t) {
	var div = document.getElementById(t);	
	if ($(div).is(":hidden")) {
		$(div).slideDown("slow");
	} else {
		$(div).slideUp('slow');
	}
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);     // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

	if (fld.value == "") {
		error = "\nYou didn't enter an email address.\nIf you do not have an email address, enter \"None\".";
	} else if (!emailFilter.test(tfld) && fld.value.toLowerCase() != "none") {
		error = "\nPlease enter a valid email address.\n";
	} else if (fld.value.match(illegalChars)) {
		error = "\nThe email address contains illegal characters.\n";
	}
    return error;
}

function comparePasswords(pw) {
	var first = document.getElementById(pw);
	var second = document.getElementById(pw+'2');
	if (second.value != first.value) {
		second.focus();
		second.select();
		return true;
	}
}

function trim(s) {
  return s.replace(/^\s+|\s+$/, '');
}

// checkField[e++] = new Array('First_Name','checkEmpty','req','Please include a first name for our records.');
// checkEmpty, checkChecked, checkSelected, checkEmail.
// 'opt' (optional) or 'req' (required)
function validate(t) {
	if (checkField) {
		for(i=0; i<checkField.length; i++) { // Check field by id.
			var element = document.getElementById(checkField[i][0]);
			
			if (element) { // Confirm element exists.
	
				if ((checkField[i][1]=='checkEmpty' && element.value=='') 
					|| (checkField[i][1]=='checkChecked' && element.checked==false) 
					|| (checkField[i][1]=='checkSelected' && element.selectedIndex==0)
					|| (checkField[i][1]=='checkEmail' && validateEmail(element)) 
					|| (checkField[i][1]=='comparePasswords' && comparePasswords(checkField[i][0]))) {
					var msg = checkField[i][3];
					if (checkField[i][2] == 'opt') {
						if (!confirm(msg)) {
							element.focus();
							return false;
						}
					} else {
						alert(msg) 
						element.focus();
						return false;
					}
				}
			}
		}
	}	
	return true;
}

// Double confirm deletes
function doubleConfirm(item) {
	var check1=confirm("Are you sure you want to delete this "+item+"? \n\nIt cannot be undone.");
	if (check1) {
		var check2=confirm("Please confirm again that you want to delete this "+item+" by clicking \"OK\". \n\nIf not, click \"Cancel\".");
		if (check2) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

//Header image rotator
tN=0;
var theImages = new Array()
theImages[tN++] = '/templates/fchm1/images/header1.gif'
theImages[tN++] = '/templates/fchm1/images/header2.gif'
theImages[tN++] = '/templates/fchm1/images/header3.gif'
theImages[tN++] = '/templates/fchm1/images/header4.gif'
theImages[tN++] = '/templates/fchm1/images/header5.gif'
theImages[tN++] = '/templates/fchm1/images/header6.gif'
theImages[tN++] = '/templates/fchm1/images/header7.gif'
theImages[tN++] = '/templates/fchm1/images/header8.gif'
theImages[tN++] = '/templates/fchm1/images/header9.gif'
theImages[tN++] = '/templates/fchm1/images/header10.gif'
var p = theImages.length;
var pickImage = Math.round(Math.random()*(p-1));
var i = pickImage;

 //preload the image into cache
var preBuffer = new Array()
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]

function showImage() {
document.write('<img src="'+theImages[i]+'" width="579" height="100" />');
}

//Quote rotator
qN=0;
var Quotes = new Array()
Quotes[qN++] = '<i>"Friday School is a lot of fun!"</i><p align="right" style="margin-right:8px;">-First Class Mom<br /> Portland, OR</p>'
Quotes[qN++] = '<i>"First Class has filled the desire of our heart...We have felt welcome, at home, and uplifted"</i><p align="right" style="margin-right:8px;">-First Class Parent<br />Battle Ground, WA</p>'
Quotes[qN++] = '<i>"First Class has been an answer to prayer for our family. May God bless you richly!"</i><p align="right" style="margin-right:8px;">-First Class Parent<br />Longview, WA</p>'
Quotes[qN++] = '<i>"I cannot tell you how excited we are about First Class! This is such an answer to prayer. I have been hoping for a group that I could get together with and put our ideas together. Sharing in fellowship, education, and fun."</i><p align="right" style="margin-right:8px;">First Class Family<br />Ridgefield, WA</p>'
Quotes[qN++] = '<i>"I cannot begin to tell you how excited we are that FC3 is here in the Portland/Vancouver area! We were so excited when we heard about your co-op. I almost cried! I have been praying for a Christian co-op - First Class has been an answer to many months of prayer."</i><p align="right" style="margin-right:8px;">-First Class Mom<br />Vancouver, WA</p>'
Quotes[qN++] = '<i>"Thank you for Friday School!"</i><p align="right" style="margin-right:8px;">-8 year old student<br />Kelso, WA</p>'
Quotes[qN++] = '<i>"It never ceases to amaze me how blessed we are to be a part of such a wonderful opportunity. It\’s impossible to express the smile God must have when He walks thru the halls with us at Friday School, I can only compare it to mine and that does no justice. Thank you."</i><p align="right" style="margin-right:8px;">-First Class Dad<br />Ridgefield, WA</p>'
Quotes[qN++] = '<i>"First Class is a "First Class" co-op....Our family has been very blessed by attending."</i><p align="right" style="margin-right:8px;">-First Class Mom<br />Vancouver, WA</p>'
Quotes[qN++] = '<i>"We are looking forward to continuing the friendships we have started at First Class."</i><p align="right" style="margin-right:8px;">-First Class Mom<br />Camas, WA</p>'
Quotes[qN++] = '<i>"I like my classes a lot. Thank you Friday School"</i><p align="right" style="margin-right:8px;">-6 yr old student<br />Portland, OR</p>'
Quotes[qN++] = '<i>"First Class is FIRSTCLASSTIC!"</i><p align="right" style="margin-right:8px;">-First Class Dad<br />Vancouver, WA</p>'

var Q = Quotes.length;
var whichQuote = Math.round(Math.random()*(Q-1));

function showQuote() {
document.write(Quotes[whichQuote]);
}

//place where quote is to appear.
//showQuote();
// --> 



