var	expireDate = new Date;
expireDate.setMonth(expireDate.getMonth()+6);

var cookiename = "username";
var cookieclass = "userclass";

var username = "";
var userclass = "";

var children = new Array;
var	numkids=0;

var	numclasses=11;

function ClassTeacher(classnumber)
{
	if (classnumber =="1")
		return "Miss Medlow";
	if (classnumber =="2")
		return "Mrs Reynolds";
	if (classnumber =="3")
		return "Miss Moreton";
	if (classnumber =="4")
		return "Mrs George";
	if (classnumber =="5")
		return "Mrs Townsend";
	if (classnumber =="6")
		return "Mrs Marsh";
	if (classnumber =="7")
		return "Ms Williams";
	if (classnumber =="8")
		return "Mrs Wyatt";
	if (classnumber =="9")
		return "Mr Reynolds";
	if (classnumber =="10")
		return "Mrs Brackenbury";
	if (classnumber =="11")
		return "Mrs Handley-Sawer";
}

function ClassPage(classnumber)
{
	var	strClassPage;

	strClassPage = "./Class" + classnumber + "/index.htm";

	return strClassPage;
}

function ClassPageTitle(classnumber)
{
	document.write(ClassTeacher(classnumber));
}

function ListChildren()
{
	var info;
	if (numkids > 0)
	{
		for(i=0; i<numkids; i++)
		{
			info = children[i].split(":");
			document.write("<p><STRONG>" + info[0] + "</STRONG> whose teacher is <STRONG>" + ClassTeacher(info[1])+"</STRONG><p>");
		}
	}
	else
	{
		document.write("<P>No-one yet...</p>");
	}
}

function AddChild(child,teacher)
{
	children[numkids] = child + ":" + teacher;
	numkids = numkids + 1;
	StoreChildren();
	window.location.reload( false );
}

function StoreChildren()
{
	var allkids = "";
	var nextchild;
	if (numkids > 0)
	{
		for(i=0; i<numkids; i++)
		{
			nextchild = children[i] + "!";
			allkids = allkids + nextchild;
		}
		SetCookie("children",allkids);
	}
}

function LoadChildren()
{
	var allkids;
	var	cookievalue;
	
	if(document.cookie != "")
	{
		cookievalue = unescape(document.cookie);
		allkids = cookievalue.split("=")[1];
		children = allkids.split("!");
		numkids = children.length-1;
	}
}

function strDate()
{  
	var thedate = new Date( );
	var theyear = thedate.getYear( );
	var themonth = thedate.getMonth( ) + 1;
	var theday = thedate.getDate( );
	var strDate = theday + " / " + themonth + " / " + theyear; 

	document.write(strDate)
}

function ReadAllCookies()
{
	var	datasplit;
	var value;
	
	if(document.cookie != "")
	{
		whole_cookie = unescape(document.cookie);
		each_cookie = whole_cookie.split(";");

		username="";
		userclass="";

		for (i = 0; i < each_cookie.length; i++)
		{
			datasplit = each_cookie[i].split("=");
			value = datasplit[1];
			
			if (datasplit[0].indexOf(cookiename) >= 0)
			{
				username = value;
			}
			if (datasplit[0].indexOf(cookieclass) >= 0)
			{
				userclass = value;
			}
		}
	}	
}

function SetCookie(name, value)
{
	document.cookie = name + '=' + escape(value) + ";expires=" + expireDate.toGMTString();
}

function KillCookie(name)
{
	var kill_date = new Date();

	kill_date.setTime (kill_date.getTime() - 1);  // the past

	document.cookie = name + "=;expires=" + kill_date.toGMTString();
}

function Forget()
{
	KillCookie("children");
	numkids=0;
	window.location.reload( false );
}

function scrollit()
{
	scrollbox.innerText = scrollingText.substring(0,40);
    scrollingText = scrollingText.substring(1) +
                    scrollingText.substring(0,1);
    setTimeout('scrollit()',200);
}

function WelcomeBack()
{
	if (numkids>0)
	{
		document.write("<p align=left>Hello again ");
		
		for(i=0; i<numkids; i++)
		{
			document.write(children[i].split(":")[0]);

			if (numkids > 1)
			{
				if ( (i == numkids-2))
				{
					document.write(" and ");
				}
				else if (i < numkids-2)
				{
					document.write(", ");
				}
			}
		}	
		document.write(" !</p>");
	}
}

function ClassButtons(pre,mid,post)
{
	if (numkids>0)
	{
		for(i=0; i<numkids; i++)
		{
			document.write( pre );
			document.write( ClassPage(children[i].split(":")[1]) );
			document.write( mid );
			document.write( children[i].split(":")[0] + "'s Class" );
			document.write( post );
		}	
	}	
}

function UnderConstruction()
{
	document.write("<p><H3>Waiting for pages to be created....</H3><p>");
}