function header(title){

	document.write('<link rel="tsh" type="text/css" href="alamedastyleclassroom.css" />');

	document.write('<style>');
	
	document.write('@import "alamedastyleclassroom.css";');

	document.write('</style>');
	
	document.write('<title>'+title+'</title>');
	document.write('<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />');	
	
	document.write('</head>');

	return;	

}


function navbuttons(room_num){

	document.write('<body id="pagestyle">');

	document.write('<table id="maintablestyle" cellspacing="0"  align="center" width=93%>');

	document.write('<tr>');
	document.write('<td colspan="2">');
	document.write('<p align="center"><a class="nav" href="http://www.alamedaschool.org/"><img src="images/banner.gif" border="0"></a></p>');
	document.write('</td></tr>');
	document.write('<tr>');
	document.write('<td colspan="2">');
	document.write('<p id=address align="center">Alameda Elementary School; 2732 NE Fremont St.; Portland, OR 97212</p>');
	document.write('</td></tr>');
	document.write('<tr>');
	document.write('<td colspan="2">');
	document.write('<br/>');
	document.write('</td></tr>');
	
/* starting new buttons on left */
	document.write('<tr><td valign="top" cellpadding="5";>');
	document.write('<table class="navbar" cellspacing="1">');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/staff.php">Staff/Find a Classroom</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/classroom.php?room_num='+room_num+'">Classroom Page</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/classcalendar.php?room_num='+room_num+'">Schedule/Calendar</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/homework.php?room_num='+room_num+'">Homework</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/newsletter.php?room_num='+room_num+'">Newsletters</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/gallery.php?room_num='+room_num+'">Gallery</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/upcoming_events.php?room_num='+room_num+'">Upcoming Events</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/wish_list.php?room_num='+room_num+'">Supply/Wish Lists</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/resources.php?room_num='+room_num+'">Resources</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/email.php?room_num='+room_num+'">Email</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/reading_challenge.html">Reading Challenge Forms</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org">Alameda Parent Site</a>');
	document.write('</td></tr>');
	document.write('<tr><td class="navb_blue">');
	document.write('<a class="nav" href="http://www.alamedaschool.org/classroom/classupdate.php?room_num='+room_num+'">Update Page (Class Reps)</a>');
	document.write('</td></tr>');
	document.write('</table>');
	document.write('</td>');

	document.write('<td id="maincell">');

}
function footer(){

	document.write('<p class="topref"><a class="topref" href="#top"><br/>Return to the Top</a></p>');

	document.write('</td>');

	document.write('</tr>');

	document.write('<tr>');

	document.write('<td colspan="2" bgcolor="CCCCCC">');

	document.write('<div id=footer><a href=http://www.alamedaschool.org>Return to the Alameda Parent Site</a></div>');

	document.write('</td>');

	document.write('</tr>');

	document.write('<tr>');

	document.write('<td colspan="2" bgcolor="0000CC">');

	document.write('<br/>');

	document.write('</td>');

	document.write('</tr>');

	document.write('</table>');

	document.write('</body>');

	document.write('</html>');

	return;

}

function Toggle(e){
	if (!document.getElementById) return;
		if(!e) var e = window.event;
	//which link was the mouse over?
	whichlink = (e.target) ? e.target.id : e.srcElement.id;
	
	// get the description
	obj=document.getElementById(whichlink+"desc");
	visible=(obj.style.display=="block")
	key=document.getElementById(whichlink);
	keyname=key.firstChild.nodeValue.substring(3);
	if (visible){
		obj.style.display="none";
		//change button to +
		key.firstChild.nodeValue="[+]"+keyname;
	}
	else{
		obj.style.display="block";
		//change button to -
		key.firstChild.nodeValue="[-]"+keyname;
	}
}
	
function addDescription(){
	i=1;
	while(document.getElementById("activityName"+i)){
		document.getElementById("activityName"+i).onclick=Toggle;
		i++;
	}
}
function addIndex(){
	i=1;
	while(document.getElementById("index"+i)){
		document.getElementById("index"+i).onclick=Toggle;
		i++;
	}
}

f=1;
function freqst(){
	while(document.getElementById("frequency"+f+"icon")){
		document.getElementById("frequency"+f+"icon").onmouseover=ScreenTip;
		document.getElementById("frequency"+f+"icon").onmouseout=clear_ScreenTip;
		f++;
	}
}
tod=1;
function todst(){
	while(document.getElementById("timeOfDay"+tod+"icon")){
		document.getElementById("timeOfDay"+tod+"icon").onmouseover=ScreenTip;
		document.getElementById("timeOfDay"+tod+"icon").onmouseout=clear_ScreenTip;
		tod++;
	}
}
sac=1;
function sacst(){
	while(document.getElementById("schoolAgedChildren"+sac+"icon")){
		document.getElementById("schoolAgedChildren"+sac+"icon").onmouseover=ScreenTip;
		document.getElementById("schoolAgedChildren"+sac+"icon").onmouseout=clear_ScreenTip;
		sac++;
	}
}
smc=1;
function smcst(){
	while(document.getElementById("smallChildren"+smc+"icon")){
		document.getElementById("smallChildren"+smc+"icon").onmouseover=ScreenTip;
		document.getElementById("smallChildren"+smc+"icon").onmouseout=clear_ScreenTip;
		smc++;
	}
}

function ScreenTip(e){
	if (!e) var e = window.event;
	whichlink = (e.target) ? e.target.id : e.srcElement.id;
	d=document.getElementById(whichlink+"st");
	d.style.display="block";
}
function clear_ScreenTip(e){
	if (!e) var e = window.event;
	whichlink = (e.target) ? e.target.id : e.srcElement.id;
	d=document.getElementById(whichlink+"st");
	d.style.display="none";
}
function ShowStyle(){
	if (location.href == "http://www.alamedaschool.org/volunteer.html" || (location.href).indexOf("http://www.alamedaschool.org/calendar.php")>-1) 
	{
		if ((location.href).indexOf("http://www.alamedaschool.org/calendar.php?num_events=only")>-1)
		{
			if ((location.href).indexOf("#calendar")<0)
				document.form1.num_events[1].checked=true;
			if ((location.href).indexOf("cbschool")>-1)
				document.form1.cbschool.checked=true;
			if ((location.href).indexOf("cbbaschool")>-1)
				document.form1.cbbaschool.checked=true;
			if ((location.href).indexOf("cbpta")>-1)
				document.form1.cbpta.checked=true;
			if ((location.href).indexOf("cbfoundation")>-1)
				document.form1.cbfoundation.checked=true;
		}
		if (document.form1.num_events[0].checked == true)
			document.getElementById("show_only").style.display='none';
		else
			document.getElementById("show_only").style.display='block';
	}
}
function Display(id_to_change,row_to_hide,row_to_show){
	document.getElementById(id_to_change).style.display='block';
	document.getElementById(row_to_hide).style.display='none';
	document.getElementById(row_to_show).style.display='block';
}
function Hide(id_to_change,row_to_hide,row_to_show){
	document.getElementById(id_to_change).style.display='none';
	document.getElementById(row_to_hide).style.display='block';
	document.getElementById(row_to_show).style.display='none';
}
function SelectAll(){
	document.form1.One_Time_Event.checked = true;
	document.form1.Multi_Event.checked = true;
	document.form1.Weekly.checked = true;
	document.form1.Monthly.checked = true;
	document.form1.Ongoing.checked = true;
	document.form1.During_School.checked = true;
	document.form1.Before_After_School.checked = true;
	document.form1.Evening_Weekends.checked = true;
	document.form1.Work_from_Home.checked = true;
	document.form1.sakids.checked = true;
	document.form1.smkids.checked = true;
}
function DeselectAll(){
	document.form1.One_Time_Event.checked = false;
	document.form1.Multi_Event.checked = false;
	document.form1.Weekly.checked = false;
	document.form1.Monthly.checked = false;
	document.form1.Ongoing.checked = false;
	document.form1.During_School.checked = false;
	document.form1.Before_After_School.checked = false;
	document.form1.Evening_Weekends.checked = false;
	document.form1.Work_from_Home.checked = false;
	document.form1.sakids.checked = false;
	document.form1.smkids.checked = false;
}
function ExpandAll(){
	for(i=0;i<document.form1.num_entries.value;i++)
	{
		index=i+1;
		prefix=document.getElementById("activityName"+index+"desc");
		prefix.style.display = "block";
	}
}
function CollapseAll(){
	for(i=0;i<document.form1.num_entries.value;i++)
	{
		index=i+1;
		prefix=document.getElementById("activityName"+index+"desc");
		prefix.style.display = "none";
	}
}
isAlpha="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
isNumber="0123456789";
isAlphaNumeric=isAlpha+isNumber;
function isBadString(str,goodstring){
	for(i=0;i<str.length;i++){
		if (goodstring.indexOf(str.charAt(i))<0)
			return true;		
	}
	return false;
}
function validateFirstName(){
if (!document.form1.first_name)
	return true;
else{
	if (document.form1.first_name.value.length < 1 || document.form1.first_name.value.length>20 || isBadString(document.form1.first_name.value,isAlpha+" -'"))
	{
		fn=document.getElementById('first_name_label');
		fn.innerHTML='First Name\*';
		fn.style.color='red';
		document.form1.first_name.focus();
		error_array[num_errors]="first name";
		num_errors++;
		return false;
	}
	fn=document.getElementById('first_name_label');
	fn.innerHTML='First Name';
	fn.style.color='black';
	return true;
    }
}
function validateLastName(){
if (!document.form1.last_name)
	return true;
	if (document.form1.last_name.value.length < 1 || document.form1.last_name.value.length>20 || isBadString(document.form1.last_name.value,isAlpha+" -'")){
		ln=document.getElementById('last_name_label');
		ln.innerHTML='Last Name\*';
		ln.style.color='red';
		document.form1.last_name.focus();
		error_array[num_errors]="last name";
		num_errors++;
		return false;
	}
	fn=document.getElementById('last_name_label');
	fn.innerHTML='Last Name';
	fn.style.color='black';
	return true;
}
function validateUserName(){
if (!document.form1.fusername)
	return true;
	if (document.form1.fusername.value.length < 6 || document.form1.fusername.value.length>20 || isBadString(document.form1.last_name.value,isAlpha+isNumber+"_-'")){
		ln=document.getElementById('fusername_label');
		ln.innerHTML='Desired Username\*';
		ln.style.color='red';
		document.form1.fusername.focus();
		error_array[num_errors]="username between 6 and 20 characters consisting of letters, numbers, and/or \"_-'\"";
		num_errors++;
		return false;
	}
	fn=document.getElementById('fusername_label');
	fn.innerHTML='Desired Username';
	fn.style.color='black';
	return true;
}
function isValidEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true					
}
function validateEmail(){
if (!document.form1.email)
	return true;
	if (document.form1.email.value.length < 1 || document.form1.email.value.length>75 || !isValidEmail(document.form1.email.value)){
		e=document.getElementById('email_label');
		e.innerHTML='Email\*';
		e.style.color='red';
		document.form1.email.focus();
		error_array[num_errors]=" a valid email address";
		num_errors++;
		return false;
	}
	fn=document.getElementById('email_label');
	fn.innerHTML='Email';
	fn.style.color='black';
	return true;
}
phonesyntax="() .-"+isNumber;
function validatePhone(){
if (!document.form1.phone || !document.form1.alt_phone){
	return true;
}
else{	if (document.form1.phone.value.length <10 && document.form1.alt_phone.value.length <10)
	{
		ph=document.getElementById('phone_label');
		ph.innerHTML='Phone\*';
		ph.style.color='red';
		document.form1.phone.focus();
		error_array[num_errors]="a valid phone number";
		num_errors++;
		return false;
	}
	if(document.form1.phone.value.length <10 || isBadString(document.form1.phone.value,phonesyntax)){
		ph=document.getElementById('phone_label');
		ph.innerHTML='Phone\*';
		ph.style.color='red';
		document.form1.phone.focus();
		error_array[num_errors]="a valid phone number";
		num_errors++;
		return false;
	}
	if((document.form1.alt_phone.value.length >1 && document.form1.alt_phone.value.length <10) || isBadString(document.form1.alt_phone.value,phonesyntax)){
		ph=document.getElementById('alt_phone_label');
		ph.innerHTML='Alternate Phone\*';
		ph.style.color='red';
		document.form1.alt_phone.focus();
		error_array[num_errors]="a valid alternate phone number (or you may leave it blank)";
		num_errors++;
		return false;
	}
	fn=document.getElementById('phone_label');
	fn.innerHTML='Phone';
	fn.style.color='black';
	fn=document.getElementById('alt_phone_label');
	fn.innerHTML='Alternate Phone';
	fn.style.color='black';
	return true;
    }
}
password_syntax=+isNumber+isAlpha+"~!@#$%^&*()_+`-=,.?/"; 
function validatePassword(){
if (!document.form1.fpassword || !document.form1.ckpassword)
	return true;
	if (document.form1.fpassword.value != document.form1.ckpassword.value)
	{
		ph=document.getElementById('ckpassword_label');
		ph.innerHTML='Retype Password\*';
		ph.style.color='red';
		document.form1.ckpassword.focus();
		error_array[num_errors]=" your passwords do not match. Please retype your password";
		num_errors++;
		return false;
	}
	if(document.form1.fpassword.value.length <6 || document.form1.fpassword.value.length >16 || isBadString(document.form1.fpassword.value,password_syntax))
	{
		ph=document.getElementById('fpassword_label');
		ph.innerHTML='Password\*';
		ph.style.color='red';
		document.form1.fpassword.focus();
		error_array[num_errors]="a password between 6 and 16 characters including letters, numbers, and characters in \"~!@#$%^&*()_+`-=,.?/\"";
		num_errors++;
		return false;
	}
	fn=document.getElementById('fpassword_label');
	fn.innerHTML='Password';
	fn.style.color='black';
	fn=document.getElementById('ckpassword_label');
	fn.innerHTML='Retype Password';
	fn.style.color='black';
	return true;
}
function validateAddress(){
if (!document.form1.address1 || !document.form1.address2){
	return true;
}
	if (document.form1.address1.value.length <1 && 
document.form1.address2.value.length <1){
		alert("Please enter your street address.");
		return false;
	}
	return true;
}	
function validateCity(){
if (!document.form1.city){
	return true;
}	if (document.form1.city.value.length < 1){
		alert("Please enter your city.");
		return false;
	}
	return true;
}	
function validateState(){
if (!document.form1.state){
	return true;
}	if (document.form1.state.value.length < 1){
		alert("Please enter your state or province.");
		return false;
	}
	return true;
}	
function validateZip(){
if (!document.form1.zip){
	return true;
}	if (document.form1.zip.value.length < 1){
		alert("Please enter your ZIP or postal code.");
		return false;
	}
	return true;
}	
function validate(){
	num_errors=1;
	error_array=new Array();
	while (num_errors>0){
		num_errors=num_errors-1;
		//ph=validatePhone();
		u_n=validateUserName();
		pswd=validatePassword();
		em=validateEmail();
		l_n=validateLastName();
		f_n=validateFirstName();
		if (num_errors>0){
			string="Please enter ";
			if (num_errors == 1)
				string=string+error_array[0];
			if (num_errors == 2)
				string=string+error_array[1]+" and "+error_array[0];
			if (num_errors >2)
			{
				for (i=num_errors-1;i>0;i--){
					string=string+error_array[i]+", ";
				}
				string=string+"and "+error_array[i];
			}	
			string=string+".";
			d=document.getElementById('message');
			d.innerHTML=string;
			d.style.display = 'block';
			return false;
		}
	}
	while (!validateFirstName() || !validateLastName() || 
		!validateEmail() || !validatePhone() || 
		!validateUserName() || !validatePassword() ||
		!validateAddress() || !validateCity() ||
		!validateState() || !validateZip()){	
		alert ("in while loop");
		return false;
	}
		 
/*	while (!validateLastName()){
		return false;
	}
	while (!validateEmail()){
		return false;
	}
	while (!validatePhone()){
		return false;
	}
	while (!validateAddress()){
		return false;
	}
	while (!validateCity()){
		return false;
	}
	while (!validateState()){
		return false;
	}
	while (!validateZip()){
		return false;
	}*/
	return true;
}
function isSignUp()
{
	signup=false;
	num=document.form1.num_entries.value;
	for(ctr=0;ctr<num;ctr++)
	{
		index=ctr+1;
		prefix=document.getElementById('javalabel'+index);
		foo=prefix.firstChild.checked;
		if(foo == true)
			signup=true;
	}
	return signup;
}
function checkSignUp()
{
	while (!isSignUp())
	{
		ph=document.getElementById("message");
		ph.innerHTML="Please sign up for at least one event to continue.";
		ph.style.color="red";
		ph.style.display="block";
		return false;
	}
	return true;	
}

function checkEmail(){
	while (!validateEmail())
		return false;
	return true;
}
$total_num_rows=0;
function AddorChangeButton(num_rows){
	if(!num_rows) //called after having changed a "remove" button to an Add on none, where number of rows not known
		num_rows=total_num_rows; // a global variable that is set the first time this function is passed through when number of rows is known
	else
		total_num_rows=num_rows; // it's set right here when we did know what it was because it was passed
	for(i=1; i<num_rows+1; i++){	
		if(document.getElementById("filerow"+i)){
			document.getElementById("filerow"+i).onclick=ChangetoBrowse;
		}
	}
	for(i=1; i<num_rows+1; i++){	
		if(document.getElementById("filerow"+i+"rem")){
			document.getElementById("filerow"+i+"rem").onclick=ChangetoBrowse;
		}
	}
}

function ChangetoBrowse(e){
	if (!document.getElementById) return;
		if(!e) var e = window.event;
	//which link was the mouse over?
	whichlink = (e.target) ? e.target.id : e.srcElement.id;
	if (document.getElementById(whichlink).innerHTML=="Change"){
		if (!confirm("Are you sure you want to change this file?"))
			return;
	}
	if (document.getElementById(whichlink).innerHTML=="Remove"){
		if (confirm("Are you sure you want to delete this file?")){
			locofrem=whichlink.indexOf("rem");
			cellname=whichlink.substring(0,locofrem);
			rownum=whichlink.substring(7,locofrem);
			cell=document.getElementById(cellname+"cell");
			cell.innerHTML="<td id='"+cellname+"cell'><table class=tiny_blue_table><tr><td class=like_input><input name='"+rownum+"rowfilename' type=text value='none'><td class=tiny_blue_cell><a id='"+cellname+"' class=tinynav href='#'>Add</a></td></tr></table></td>";
			AddorChangeButton();
			return;
		}
		else
			return;
	}
	len=whichlink.length;
	rownum=whichlink.substring(7,len);
	cell=document.getElementById(whichlink+"cell");
	cell.innerHTML=	"<td><input name='"+rownum+"rowfilename' type=file></td>";
}
function DeleteRow(form,num){
	indexlabel="rowremove"+num;
	checkbox=eval("document."+form+"."+indexlabel);
	if (checkbox.checked == true){
		if (!confirm("Are you sure you want to remove this entry?"))
			checkbox.checked=false;
	}
	return;
}
function EvaluateGrade(form,num,addormod){
	indexlabel="rowwholegrade"+num;
	checkbox=eval("document."+form+"."+indexlabel);
	if (checkbox.checked == true){
		if (!confirm("Are you sure you want to "+addormod+" this entry for every classroom in this grade?"))
			checkbox.checked=false;
	}
	return;
}	
function ConfirmEmailDeletion(){
	checkbox=eval("document.form1.deletebox");
	if (checkbox.checked == true){
		if (!confirm("Are you sure you want to delete this entry (email address) from our database?"))
			checkbox.checked=false;
	}
	return;
}

/*function Toggle(e){
	if (!document.getElementById) return;
		if(!e) var e = window.event;
	//which link was the mouse over?
	whichlink = (e.target) ? e.target.id : e.srcElement.id;
	
	// get the description
	obj=document.getElementById(whichlink+"desc");
	visible=(obj.style.display=="block")
	key=document.getElementById(whichlink);
	keyname=key.firstChild.nodeValue.substring(3);
	if (visible){
		obj.style.display="none";
		//change button to +
		key.firstChild.nodeValue="[+]"+keyname;
	}
	else{
		obj.style.display="block";
		//change button to -
		key.firstChild.nodeValue="[-]"+keyname;
	}
}
	
function addDescription(){
	i=1;
	while(document.getElementById("activityName"+i)){
		document.getElementById("activityName"+i).onclick=Toggle;
		i++;
	}
}
function addIndex(){
	i=1;
	while(document.getElementById("index"+i)){
		document.getElementById("index"+i).onclick=Toggle;
		i++;
	}
}
*/
