// <!-- Begin
function gobutton( pcform, pcLocation )
{
		// generic onClick handler for buttons to go to a particular page		
		document.forms[pcform].action = pcLocation;
		document.forms[pcform].submit();
		
		return false;
}

function checkEntries(lierrct1, lcerrmsg1, lierrct2, lcerrmsg2)
{
	// check values
	obj = document.getElementById("errormsg");
	obj.innerHTML = '&nbsp;';
	
	if (lierrct1 > 0)
	{
		obj.innerHTML = '<b><i>You must enter the following: ' + lcerrmsg1 + '.</i></b>';
	}
	if (lierrct2 > 0)
	{
		obj.innerHTML += (lierrct1 > 0) ? '<br>' : '' ;
		obj.innerHTML += '<b><i>' + lcerrmsg2 + '</i></b>';
	}

	if ((lierrct1 > 0) || (lierrct2 > 0))
	{
		return false;
	}
	else
	{
		obj.innerHTML = '&nbsp;';
		// document.all.main.submit();
		return true;
	}
}

function checkTeacherCredentials(pcAction)
{
	// check values

	var lcerrmsg = "";
	var lierrct = 0;
	var lichkerrct = 0;
	var obj;

	obj = document.getElementById("errormsg");
	obj.innerHTML = '&nbsp;';
	
	obj = document.getElementById("userid");
	if (obj.value == "")
	{
		lcerrmsg = lcerrmsg + (lierrct == 0 ? "" : ", ") + "your CPS ID";
		lierrct++;
	}
	
	obj = document.getElementById("fname");
	if (obj.value == "")
	{
		lcerrmsg = lcerrmsg + "your first name";
		lierrct++;
	}
	
	obj = document.getElementById("classid");
	if (obj.value == "")
	{
		lcerrmsg = lcerrmsg + (lierrct == 0 ? "" : ", ") + "your classroom ID if you are assigned to a classroom";
//		lierrct++;
	}
	
	if (lierrct == 0)
	{
		obj = document.getElementById("main");
		obj.action = pcAction;
	}
	
	return checkEntries( lierrct, lcerrmsg, 0, "");

}

function checkStudentCredentials()
{
	// check values

	var lcerrmsg = "";
	var lcerrmsg2 = "";
	var lierrct = 0;
	var lichkerrct = 0;

	document.all.errormsg.innerHTML = '&nbsp;';
	
	if (document.all.fname.value == "")
	{
		lcerrmsg = lcerrmsg + "your first name";
		lierrct++;
	}
	
	if (document.all.userid.value == "")
	{
		lcerrmsg = lcerrmsg + (lierrct == 0 ? "" : ", ") + "your CPS ID";
		lierrct++;
	}
	
	if (document.all.classid.value == "")
	{
		lcerrmsg = lcerrmsg + (lierrct == 0 ? "" : ", ") + "your classroom ID";
		lierrct++;
	}

	if (!document.all.chkTutorial.checked  && 
		!document.all.chkVideo.checked &&
		!document.all.chkGame.checked &&
		!document.all.chkDrill.checked &&
		!document.all.chkQuiz.checked)
	{
		lcerrmsg2 = "You must select at least one resource type to search for.";
		lichkerrct++;
	}
	
	return checkEntries( lierrct, lcerrmsg, 0, lcerrmsg2);

}

function checkCriteria()
{

	var lcerrmsg = "";
	var lcerrmsg2 = "";
	var lierrct = 0;
	var lierrct2 = 0;

	document.all.errormsg.innerHTML = '&nbsp;';
	
	if (!document.all.lvl1.checked  && 
		!document.all.lvl2.checked &&
		!document.all.lvl3.checked)
	{
		lcerrmsg = "You must select at least one level to search for.";
		lierrct++;
	}
	
	if (!document.all.chkTutorial.checked  && 
		!document.all.chkVideo.checked &&
		!document.all.chkQuiz.checked)
	{
		lcerrmsg2 = "You must select at least one resource type to search for.";
		lierrct2++;
	}
	
	return checkEntries( lierrct, lcerrmsg, lierrct2, lcerrmsg2);
}
		

function checkAddCriteria()
{

	var lcerrmsg = "";
	var lcerrmsg2 = "";
	var lierrct = 0;
	var lichkerrct = 0;
	var obj;

	document.all.errormsg.innerHTML = '&nbsp;';
	document.all.state.value = "update";
	
	if (!document.all.stagea.checked  && 
		!document.all.stageb.checked  && 
		!document.all.stagec.checked  && 
		!document.all.staged.checked  && 
		!document.all.stagee.checked  && 
		!document.all.stagef.checked  && 
		!document.all.stageg.checked  && 
		!document.all.stageh.checked  && 
		!document.all.stagei.checked)
	{
		lcerrmsg = "You must select at least one stage.";
		lichkerrct++;
	}
	
	if (!document.all.chkTutorial.checked  && 
		!document.all.chkVideo.checked &&
		!document.all.chkQuiz.checked)
	{
		lcerrmsg2 = "You must select at least one resource type.";
		lichkerrct++;
	}

	if (!document.all.chkTutorial.checked  && 
		!document.all.chkVideo.checked &&
		!document.all.chkQuiz.checked)
	{
		lcerrmsg2 = "You must select at least one resource type.";
		lichkerrct++;
	}
	
	obj = document.getElementById("rating");
	if (!obj.checked)
	{
		lcerrmsg2 = "You must select a rating.";
		lichkerrct++;
	}
	
	
	return checkEntries( lichkerrct, lierrct, lcerrmsg, lcerrmsg2);
}

function setlevel( pctype, pclevel )
{
	return changeStandard();
}		// setlevel


function changeStandard()
{
	document.all.main.state.value = "notadding";
	return gobutton( "main", "addresources.php" );
}

function getlevel(pctype)
{
	var lclevel = "";
	
	switch (pctype)
	{
		case "P":
			break;
		case "F":
			break;
		default:
			break;
	}
	return 1;
}


function getstdcat()
{
	var lcStdCatValue = "B";
	
	if (document.main.stdcat[1].checked)
		 lcStdCatValue = "P";
	else if (document.main.stdcat[2].checked)
		 lcStdCatValue = "F";
	else			
		 lcStdCatValue = "B";
		 
	return lcStdCatValue;
}

function findresources()
{
	//document.all.main.findresources.value = "x";
	return checkCriteria();
}


function clearresources()
{
		// lcStr = "";
		// for (i = 1; i < document.all.main.elements.length; i++)
		//	lcStr += document.all.main.elements[i].name + "<br>";
		
		// document.all.main.elements[document.all.main.elements.length].name = "clearresources";
		// document.all.main.clearresources.value = "clear";
		// document.all.main.submit();
		return true;
}


function maintainresources(piresid)
{
	var obj;
	
	obj = document.getElementById("nresid");
	obj.value = piresid;
	
	//alert(piresid);
	
	//document.all.edtresource.submit();
	document.getElementById("edtresource").submit();
}

function initaddresourcespage()
{
	var i;
	var lcStr = "";
	
	showquotes();
	
//	setlevel(getstdcat(), ""); // document.all.stdcat.value);
	
/*
	for (prop in document)
	{
		document.write("name: " + prop + ", value: " + document[prop], "<br>");
	}
	lcStr += document.forms[0].name + " ";
	// lcStr += document.forms[0].elements.length;
 	for(i=0; i< document.forms[0].elements.length; i++)
    {
    	lcStr += "The field name is: " + document.forms[0].elements[i].name + "; value is: " + document.forms[0].elements[i].value + ".<br />";
    }
    document.write(lcStr);
	//document.close();
*/
/*
	for (i = 0; i < document.all.length; i++)
	{
		document.writeln("name: " + document.all[i].name +  "<br>");
	}
 	document.writeln(document.main.elements.length);
 	for(i=0; i< document.main.elements.length; i++)
    {
    	document.write("The field name is: " + document.main.elements[i].name + "; value is: " + document.main.elements[i].value + ".<br />");
    }

	// document.write(document.all.stdcat.value);
 */

}

function showquotes()
{
	var obj;
	var how_many_quotes = 18;
	var now = new Date();
	var sec = now.getSeconds();
	var iquote = sec % how_many_quotes;
	var quotes = new Array(
		"<i>\"I pursue learning because that is how I assert myself as a free person.\" - Theresa Perry</i>",
		"<i>\"The tide of change approaches.\" - Fortune cookie fortune</i>",
		"<i>\"It takes a village to raise a child.\"  - African Proverb</i>",		
		"<i>\"The illiterate of the 21st century will not be those who cannot read and write, but those who cannot learn, unlearn, and relearn.\" - Alvin Toffler</i>",
		"<i>\"I pursue learning because that is how I claim my humanity.\" - Theresa Perry</i>",
		"<i>\"I pursue learning so I can work for the liberation of my people.\" - Theresa Perry</i>",
		"<i>\"We\'re outgunned and undermanned, but you know something? We\'re going to win. And I will tell you why. Superior attitude, superior state of mind.\" - Mason Storm (Steven Segal),</i> Hard to Kill",
		"<i>\"The future belongs to those who believe in the beauty of their dreams.\" - Eleanor Roosevelt</i>",
		"<i>\"There\'s no such thing as tough. There\'s trained and untrained.\" - Denzel Washington,</i> Man on Fire",
		"<i>\"I pursue learning so I can prepare myself to lead my people.\" -- Theresa Perry</i>",
		"<i>\"The only real mistake is the one from which we learn nothing.\" - John Powell</i>",
		"<i>\"The freedom struggle of African Americans has always been a gift of life and truth to all of society. Always.\" - Vincent Harding</i>",
		"<i>\"Education is for improving the lives of others and for leaving your community and world better than you found it.\" - Marian Wright Edelman</i>",
		"<i>\"Educate or die.\" - <a href=\"http://www.blackstarproject.org/home/\">The Black Star Project</a></i>",
		"<i>\"Education is our passport to the future, for tomorrow belongs to the people who prepare for it today.\" - Malcolm X</i>", 
		"<i>\"The future depends on what we do in the present.\" - Mahatma Gandhi</i>",
		"<i>\"Knowledge is an event, not an object.\" - Arthur Zajonc</i>",
		"<i>\"Each particle in the universe reflects the rest of the universe, but knowledge is only given to human beings as a result of an active and social relation to the rest of reality.\" - Christopher Caudwell</i>"
	);
	obj = document.getElementById("quotes");
	obj.innerHTML = quotes[iquote];
}
// End -->

