function on(img_name) {
  var s=document[img_name].src;
  var ss=s.substring(0,(s.length - 4))+'_a'+s.substring((s.length - 4),s.length);
  document[img_name].src=ss;
}

function off(img_name) {
  var s=document[img_name].src;
  var ss=s.substring(0,(s.length - 6))+s.substring((s.length - 4),s.length);
  document[img_name].src=ss;
}

function popUpFrame(url) {
  var win = window.open(url);
}

function sizedPopUpFrame(url) {
  var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes" + ",width=500,height=370";
  popup = window.open(url,"MenuPopup",windowprops);
}

function galleryPopUp(url) {
  var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes" + ",width=480,height=500";
  popup = window.open(url,"MenuPopup",windowprops);
}

function galleryPopUp2(url) {
  var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=yes,resizable=yes" + ",width=600,height=500";
  popup = window.open(url,"MenuPopup",windowprops);
}

function hideEmail(contact, email, emailHost) {
	document.write("<a href=" + "mail" + "to:" + email + "@" + emailHost+ ">" + contact + "</a>" + ".");
}


//********************************************************//
//The following section is for the image transition effect//
//********************************************************//
var currentPhoto = 0;
var secondPhoto = 1;

var currentOpacity = new Array();
 var imageArray = new Array("../ImageGallery/QE2010-1/IMG_0220_1stDay_tn.jpg","../ImageGallery/QE2010-1/IMG_0266_35thAnniv_tn.jpg","../ImageGallery/QE2010-1/IMG_4178_tn.jpg","../ImageGallery/QE2010-1/IMG_4017_tn.jpg","../ImageGallery/QE2010-1/IMG_4015_tn.jpg","../ImageGallery/QE2010-1/IMG_4119_tn.jpg","../ImageGallery/QE2010-1/IMG_4155_tn.jpg", "../ImageGallery/QE2010-1/IMG_3988_tn.jpg");
//var imageArray = new Array("../ImageGallery/QE2010-1/IMG_4017_tn.jpg","../ImageGallery/QE2010-1/IMG_3813_tn.jpg","../ImageGallery/QE2010-1/IMG_4143_tn.jpg","../ImageGallery/QE2010-1/IMG_4128_tn.jpg","../ImageGallery/QE2010-1/IMG_4155_tn.jpg","../ImageGallery/QE2010-1/IMG_4178_tn.jpg","../ImageGallery/QE2010-1/IMG_4119_tn.jpg","../ImageGallery/QE2010-1/IMG_3988_tn.jpg","../images/photos/schoollibrary.gif","../ImageGallery/QE2010-1/IMG_3813_tn.jpg", );

// var imageArray = new Array("../ImageGallery/QE2010-1/IMG_4017_tn.jpg","../images/photos/schoolfront.jpg","../images/photos/schoolfromstreet.gif","../images/photos/schoolyard.gif","../images/photos/schoolfromcurb.gif","../images/photos/schoolfrontinside.gif", "../images/photos/schoollibrary.gif","../images/photos/schoolinsite.gif");


var FADE_STEP = 2;
var FADE_INTERVAL = 10;
var pause = false;

function init() {
	currentOpacity[0]=99;
	for(i=1;i<imageArray.length;i++)currentOpacity[i]=0;
	mHTML="";
	for(i=0;i<imageArray.length;i++)mHTML+="<div id=\"photo\" name=\"photo\" class=\"mPhoto\"><img src=\"" + imageArray[i]  +"\"></div>";
	document.getElementById("mContainer").innerHTML = mHTML;

	if(document.all) {
		document.getElementsByName("photo")[currentPhoto].style.filter="alpha(opacity=100)";
	} else {
		document.getElementsByName("photo")[currentPhoto].style.MozOpacity = .99;
	}

	mInterval = setInterval("crossFade()",FADE_INTERVAL);
}

function crossFade() {
	if(pause)return;

	currentOpacity[currentPhoto]-=FADE_STEP;
	currentOpacity[secondPhoto] += FADE_STEP;

	if(document.all) {
		document.getElementsByName("photo")[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
		document.getElementsByName("photo")[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
	} else {
		document.getElementsByName("photo")[currentPhoto].style.MozOpacity = currentOpacity[currentPhoto]/100;
		document.getElementsByName("photo")[secondPhoto].style.MozOpacity =currentOpacity[secondPhoto]/100;
	}

	if(currentOpacity[secondPhoto]/100>=.98) {
		currentPhoto = secondPhoto;
		secondPhoto++;
		if(secondPhoto == imageArray.length)secondPhoto=0;
		pause = true;
		xInterval = setTimeout("pause=false",2000);
	}
}

function doPause()  {
	if(pause) {
		pause = false;
		document.getElementById("pauseBtn").value = "pause";
	} else {
		pause = true;
		document.getElementById("pauseBtn").value = "play";
	}
}

function displayDate() {
	// Script to display Todays Date
	var month=new Array(12);	
	month[1]="Jan";		
	month[2]="Feb";
	month[3]="Mar";
	month[4]="Apr";
	month[5]="May";
	month[6]="Jun";
	month[7]="Jul";
	month[8]="Aug";
	month[9]="Sep";
	month[10]="Oct";
	month[11]="Nov";
	month[12]="Dec";

	var the_day=new Date();				

	var the_month=month[the_day.getMonth() + 1];
	var the_date=the_day.getDate();
	var the_year=the_day.getFullYear();
	var the_daynum = the_day.getDay() + 1;

	if(the_daynum==1) day = "Sunday";
	if(the_daynum==2) day = "Monday";
	if(the_daynum==3) day = "Tuesday";
	if(the_daynum==4) day = "Wednesday";
	if(the_daynum==5) day = "Thursday";
	if(the_daynum==6) day = "Friday";
	if(the_daynum==7) day = "Saturday";

	var the_daysdate = (day + " &nbsp;&nbsp;" + the_month + "/" + the_date + "/" + the_year);
	return (the_daysdate);

}

function popitup(url) {
	newwindow=window.open(url,'name','height=600,width=800,resizable=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}


function validate_required(value,alerttxt)
{
		if (value==null||value==""){
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
}

function validatePhone(sText)
{
	var validChars = "0123456789";
	var isNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && isNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (validChars.indexOf(Char) == -1) {
			isNumber = false;
		}
	}
	if (isNumber && i>9) 
		return true;
	return false;
}

function validate_form(thisform) {
		var form = document.getElementById(thisform);
		if (validate_required(form.parentLastName.value, "Parent Last Name is Required!")==false) {
			form.parentLastName.focus();
			return false;
		} 
		if (validate_required(form.parentFirstName.value,"Parent First Name is Required!")==false) {
			form.parentFirstName.focus();
			return false;
		}
		
		if (validate_required(form.parentPhoneInfo.value,"Phone Number must be filled out!")==false) {
			form.parentPhoneInfo.focus();
			return false;
		}
		
		if (validatePhone(form.parentPhoneInfo.value)==false) {
			alert("Enter your 10-digit phone number, including Area code. For example: 8183334444");
			form.parentPhoneInfo.focus();
			return false;
		}
		
		if (validate_required(form.studentsName.value,"Student Name is Required!")==false) {
			form.studentsName.focus();
			return false;
		} 
		if (validate_required(form.studentGrade.value,"Student Grade is Required!")==false) {
			form.studentGrade.focus();
			return false;
		} 
		if (validate_required(form.parentEmailId.value,"Email must be filled out!")==false) {
			form.parentEmailId.focus();
			return false;
		}
		
		var countCheckedValue=0;
		
		for(var i = 1; i < 200; i++) {
			var formElement = form.elements[i];
			if (formElement!=null) {
				var formElementName = formElement.name;
				if (formElementName.indexOf("valId")>=0) {
				 	if (formElement.checked == true) {
 						countCheckedValue++;
 					}
 				}
 			} else {
 				break;
 			}
		}
		
		if (countCheckedValue==0) {
			alert ('Please select at least one Event');
			return false;
		} else if (countCheckedValue>5) {
			alert ('Please select at most Five (5) Events');
			return false;
		}
		form.submit();
}