//Author: Dave Coop, Damage Case; E-mail: dave@damagecase.co.za; Web: http://www.damagecase.co.za
//A Damage Case tip of the hat to JavaScript programmers all over the world who assisted with this.

//Remove spaces around a sent string
function trim (str){
	while (str.charAt(0) == ' ')
		str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);
return str;}

//Check the form fields on the login page (/admin/default.asp)
function ChkLoginForm(theForm){
	if (theForm.login.value == ""){
		alert("Please enter your Login Name.");
		theForm.login.focus();
		return (false);}
	if (theForm.passwd.value == ""){
		alert("Please enter your Password.");
		theForm.passwd.focus();
		return (false);}
return (true);}

//Check that a valid option was selected when selecting from the drop-downs
function ChkUpdForm()
{
	if (document.forms.UpdSelect.UpdThis.value == "")
	{return (false);}
	document.forms.UpdSelect.submit();
	return (true);
}

//Check that a valid option was selected when updating user details (/admin/upduser.asp)
function ChkUpdUserForm()
{
	if (document.forms.UpdUserSelect.UpdThisUser.value == "")
	{return (false);}
	document.forms.UpdUserSelect.submit();
	return (true);
}

//Check the form fields on the admin user pages (/admin/adduser.asp and /admin/upduser2.asp)
function ChkUserForm(theForm){
	if (theForm.fname.value == ""){
		alert("Please enter a First Name.");
		theForm.fname.focus();
		return (false);}
	if (theForm.sname.value == ""){
		alert("Please enter a Surname.");
		theForm.sname.focus();
		return (false);}
	if (theForm.email.value == ""){
		alert("Please enter an E-mail Address for this user.");
		theForm.email.focus();
		return (false);}
	if (theForm.email.value != ""){
		if (theForm.email.value.indexOf("@")==-1 || theForm.email.value.indexOf(".")==-1 || theForm.email.value.indexOf(" ")!=-1 || theForm.email.value.length<6){
			alert("Sorry, this e-mail address is not valid.");
			theForm.email.focus();
			return (false);}}
	return (true);}

//Round off numbers to two decimal places
 function roundoff(number){
	return Math.round(number*Math.pow(10,2))/Math.pow(10,2);}

	
//The script to run the date and time function on certain pages
var day="";
var month="";
var myweekday="";
var year="";
mydate = new Date();
myday = mydate.getDay();
mymonth = mydate.getMonth();
myweekday= mydate.getDate();
weekday= myweekday;
myyear= mydate.getYear();
dcyear= mydate.getYear();
year = myyear
if(myday == 0)
day = " Sunday"      
else if(myday == 1)
day = " Monday"
else if(myday == 2)
day = " Tuesday"   
else if(myday == 3)
day = " Wednesday"   
else if(myday == 4)
day = " Thursday"
else if(myday == 5)
day = " Friday"
else if(myday == 6)
day = " Saturday"
if(mymonth == 0) {
month = "January"}
else if(mymonth ==1)
month = "February"
else if(mymonth ==2)
month = "March"
else if(mymonth ==3)
month = "April"
else if(mymonth ==4)
month = "May"
else if(mymonth ==5)
month = "June"
else if(mymonth ==6)
month = "July"
else if(mymonth ==7)
month = "August"
else if(mymonth ==8)
month = "September"
else if(mymonth ==9)
month = "October"
else if(mymonth ==10)
month = "November"
else if(mymonth ==11)
month = "December"

DateandTime = day + ' ' + myweekday + ' ' + month + ' ' + myyear;

function nowDateTime(){
var now = new Date();
hrs = now.getHours();
min = now.getMinutes();
sec = now.getSeconds();
if (hrs < 10)
	{hrs = "0" + hrs}
if (min < 10)
	{min = "0" + min}
if (sec < 10)
	{sec = "0" + sec}

	document.Report.ShowTime.value=(DateandTime + ' ' + hrs + ':' + min + ':' + sec);
	setTimeout('nowDateTime()',1000);  //repeat every 1000 millisecs ie. every sec
}

//Set different styles for Microsofto Exploder and other browsers
var sSubHeader="subheader";
if (navigator.appName != "Microsoft Internet Explorer"){
	sSubHeader += "N";}

//Check that a valid search is being made (comment.html in top frame)
function chkSearchForm(theForm){
if(theForm.SearchWord.value == "" || trim(theForm.SearchWord.value) == "" || theForm.SearchWord.value.length <= 3){
	alert("Please enter a Search word or phrase.\nWords under 3 letters are not valid search terms.");
	theForm.SearchWord.focus();
	return (false);}
return (true);}

//Check that a valid option was selected on a drop-down
function ChkSelectForm(){
	if (document.forms.SelectForm.ST.value == "")
	{return (false);}
	document.forms.SelectForm.submit();
	return (true);}
