<!--
/*---------------------------------------------------------------*/
function openWindow()
{
	varURL = arguments[0];
	if (!arguments[1]) { varWidth = '300'; }else{ varWidth = arguments[1]; }
	if (!arguments[2]) { varHeight = '300'; }else{ varHeight = arguments[2]; }
	if (!arguments[3]) { varScrolling = 'yes'; }else{ varScrolling = arguments[3]; }
	if (!arguments[4]) { varStatus = '0'; }else{ varStatus = arguments[4]; }
	if (!arguments[5]) { varTitle = '0'; }else{ varTitle = arguments[5]; }
	if (!arguments[6]) { varLocation = '0'; }else{ varLocation = arguments[6]; }
	if (!arguments[7]) { varToolbar = '0'; }else{ varToolbar = arguments[7]; }
	winname = new String('window_'+Math.min(Math.random()));
	winname = window.open(varURL,'','toolbar='+varToolbar+',location='+varLocation+',status='+varStatus+',title='+varTitle+',width='+varWidth+',height='+varHeight+',scrollbars='+varScrolling+',resizable=yes,alwaysRaised=yes');
	winname.focus();
	return winname;
}
/*---------------------------------------------------------------*/
function inputdate()
{
	var obj = arguments[0]
	var value = obj.value;
	if ( value.length==2 || value.length==5 ) { obj.value += '/'; }
}
/*---------------------------------------------------------------*/
function nada()
{
	document.status = 'Please Wait';
}
/*---------------------------------------------------------------*/
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function isDate(day,month,year)
{
	// checks if date passed is valid
	// will accept dates in following format:
	// isDate(dd,mm,ccyy), or
	// isDate(dd,mm) - which defaults to the current year, or
	// isDate(dd) - which defaults to the current month and year.
	// Note, if passed the month must be between 1 and 12, and the
	// year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) )
	{
        return true;
    }else{
        return false;
	}
}
/*---------------------------------------------------------------*/
function showHideElement()
{
	theElement = arguments[0];

	if (theElement.style.visibility == 'visible')
	{
		theElement.style.position = 'absolute';
		theElement.style.visibility = 'hidden';
	}else{
		theElement.left = 200;
		theElement.top = 0;
		theElement.style.visibility = 'visible';
		theElement.style.position = 'absolute';
	}
}
/*-------------------------------------- CHECK FOR CHANGED VALUES ---------------------------------------------
Author:		Ross Crawford
Date:		05 12 2002
Description:
Function checks for a form element named tmpHasValueChanged and that it has a value of 0 if not then ask the user if they are sure they want to leave the section without submitting the form
------------------------------------------------------------------------------------------------------------*/
function chkChanged()
{
	for (c=0; c < document.forms.length; c++)
	{
		for (i=0; i < document.forms[c].elements.length; i++)
		{
			if ( document.forms[c].elements[i].name == 'tmpHasValueChanged' )
			{
				if ( document.forms[c].elements[i].value != 0 )
				{
					if ( !confirm('We have detected that you have changed a value on this page, but have not submitted the form.\r\rIf you select "OK" the changes you have just made will be lost.\r\rAre you sure you want to leave this section without updating the record?') )
					{
						return false;
					}					
				}
			}
		}
	}
}
/*-------------------------------------- UPDATE TEMP VALUES ---------------------------------------------
Author:		Ross Crawford
Date:		06 12 2002
Description:
Function changes the colour of the form element that has been changed so that the user can see elements they 
have changed before submitting the form.
------------------------------------------------------------------------------------------------------------*/
function updTmpVal()
{
	for (c=0; c < document.forms.length; c++)
	{
		for (i=0; i < document.forms[c].elements.length; i++)
		{
			if ( document.forms[c].elements[i].name == 'tmpHasValueChanged' )
			{
				if (document.forms[c].elements[arguments[0]].type != 'select-one' )
				{
					document.forms[c].elements[arguments[0]].style.background = '#cc0000';
					document.forms[c].elements[arguments[0]].style.color = '#ffffff';
					document.forms[c].elements[i].value = 1;
				}
			}
		}
	}
}
/*-------------------------------------- RESET STYLES ---------------------------------------------
Author:		Ross Crawford
Date:		06 12 2002
Description:
Function Resets the styles for all elements in a form
------------------------------------------------------------------------------------------------------------*/
function resetStyles()
{
	theForm = document.forms[arguments[0]];
	for (c=0; c < theForm.elements.length; c++)
	{
		theForm.elements[c].style.removeAttribute("color");
	}
}
/*-------------------------------------- CONFIRM EVENT ---------------------------------------------
Author:		Ross Crawford
Date:		31 01 2002
Description:
Function prompts user to confirm a specified event and returns true or false according to user selection.
confirmEvent('formname','< message >')
------------------------------------------------------------------------------------------------------------*/
function confirmEvent()
{
	var theForm = document.forms[arguments[0]];
	var confirmMsg = arguments[1];
	
	if( confirm(confirmMsg) )
	{
		return true;
	}else{
		return false;
	}
}
/*-------------------------------------- RANDOM NUMBER GENERATOR ---------------------------------------------
Author:		Ross Crawford
Date:		25 01 2002
Description:
Function generates an alpha or alpha/numeric number.
randAlphaNum('formname','0/1','field to recieve number','field to recieve number',etc)
------------------------------------------------------------------------------------------------------------*/
function randAlphaNum()
{
	var theElement = arguments[0]
	var theForm = theElement.form
	var varAlphaNumeric = arguments[1];
	var varRandomNum = '';
	var varRandNumeric = '';
	var varRandAlpha = '';
	var varTemp = '';
	
	varRandNumeric = Math.round( Math.random()*(9999999-1000000) )+1000000;	//	Random number.

	if(varAlphaNumeric == 1)	//	If arguments[1]=1 then append a letter to the front of the random number
	{
		varTemp = Math.round( Math.random()*(90-65) )+65;
		varRandAlpha = String.fromCharCode(varTemp);
		varRandomNum = varRandAlpha+'-'+varRandNumeric;
	}else{
		varRandomNum = varRandNumeric;
	}

	if( confirm('You are about to change this users password\r\rIn order to make this change permanent please submit the form') )
	{
			theElement.value = varRandomNum;
			if (theForm.elements['frmAccount_password_status'])
			{
				theForm.elements['frmAccount_password_status'][1].checked = true;
			}
			alert('The password has been changed to\r\r'+varRandomNum+'\r\rThis is a temporary password and the user will be asked to change it when they next log-on.');
	}else{
		alert('The password has not been changed');
	}	
		
}
/*-------------------------------------- LIMIT TEXTAREA CONTENT ---------------------------------------------
Author:		Ross Crawford
Date:		29 11 2001
Description:
Function limits the number of characters that can be entered into a textarea (comment fields) so that the DB 
does not crash when trying to insert the value.
------------------------------------------------------------------------------------------------------------*/
function chkCommentMaxChar(thisForm, thisElement)
{
	var theElement = document.forms[thisForm].elements[thisElement];
	var theContents = theElement.value;
	var varMaxLength = 1999;
	if (theElement.value.length > varMaxLength) {
		alert('Please enter less content in the comment field\r\r NOTE: Text will be removed to fit maximum.');
		//	REMOVE OFFENDING CHARS
		theElement.value = theContents.slice(0,varMaxLength);
		return false;
	}
}
/*-------------------------------------- CHECK EXPIRY DATES ---------------------------------------------
Author:		Ross Crawford
Date:		29 11 2001
Description:
Ensure that the date entered is greater than the current date.
------------------------------------------------------------------------------------------------------------*/
function chkExpiryDate(thisForm, thisElement) 
{
	var theElement = document.forms[thisForm].elements[thisElement];
	var thisDate = theElement.value;
	var today = new Date();
	var day = '';
	var month = '';
	var year = '';
	var day1 = today.getDate();
	var month1 = today.getMonth() + 1;	//	increment the month by one because of month counter starting at 0
	var year1 = today.getYear();
	var errMsg = "";

	//	EXRACT DD,MM,YYYY
	for (c = 0; c <= thisDate.length; c++)
	{
		if(c < 2){day = day + thisDate.charAt(c); }
		if(c == 3 || c == 4){month = month +  thisDate.charAt(c); }
		if(c == 6 || c == 7 || c == 8 || c==9){year = year + thisDate.charAt(c); }
	}
	//	SET TESTING PARAMETERS	
	var dateEntered = parseInt(year+month+day);
	var correctDate = year1.toString();

	//	APPEND 0 TO MONTH if MONTH IS LESS THAN 10
	if(month1 < 10)
	{
		 correctDate = correctDate + '0'+month1.toString();
	}else{
		 correctDate = correctDate + month1.toString();
	}
	//	APPEND 0 TO DAY if DAY IS LESS THAN 10
	if (day1 < 10)
	{
		 correctDate = correctDate + '0'+day1.toString();
	}else{
		 correctDate = correctDate + day1.toString();
	}	
	
	//	TESTS FOR VALID DATE
	if (dateEntered <= correctDate)
	{
		errMsg = 'Please enter a date greater than todays date.\n';
	}
	if (year < 2000)
	{
		errMsg = errMsg + 'You can only enter a year greater than 2000.\n';
	}
	//	CHECK IF ERROR FOUND
	if (errMsg != '')
	{
		alert(errMsg+'The date must be in DD/MM/YYYY Format');
		theElement.focus();
		theElement.select();
		theElement.value = '';
		return false;
	}

}
/*-------------------------------------- CHECK VALUE GREATER THAN 0 ----------------------------------------
Author:		Ross Crawford
Date:		11 12 2001
Description:
Ensure that the entered value is greater than 0
------------------------------------------------------------------------------------------------------------*/
function chkGreaterThanZero(thisForm, thisElement)
{
	var theElement = document.forms[thisForm].elements[thisElement];
	var theContents = theElement.value;

	//	CHECK VALUE IS GREATER THAN 0
	if (theContents <= 0)
	{
		alert('This value must be greater than 0.');
//		theElement.select();	//	Cant select: as two field next to each other with the same greater than 0 requirement will cause an infinte select loop
		theElement.value = '';
		return false;
	}
}
/*-------------------------------------- CHECK SAME VALUES ---------------------------------------------
Author:		Ross Crawford
Date:		08 07 2002
Description:
Checks that a field has the same value as the previous field.
------------------------------------------------------------------------------------------------------------*/
function sameValues()
{
	var thisForm = arguments[0];
	var thisElementValue = thisForm.elements[arguments[1]].value;
	for (i=0; i<thisForm.elements.length; i++)
	{
	 	if (thisForm.elements[i].name == arguments[1])
		{
		   if (thisForm.elements[i].value == thisForm.elements[i-1].value)
		   {
		   	  return true;
		   }else{
		   	  return 'error';
		   }
		}
	}

}

/*-------------------------------------- CHECK KEY ELEMENT ---------------------------------------------
Author:		Ross Crawford
Date:		10 01 2002
Description:
Checks that a field has a value before allowing to submit
return checkKeyElement('nameOfForm','dependantElement','keyElement');
the first argument MUST be the name of the form.
------------------------------------------------------------------------------------------------------------*/
function checkKeyElement()
{
	//	IF SELECTEDINDEX OF DEPENDANT ELEMENT INDEX GREATER THAN 0
	if(document.forms[arguments[0]].elements[arguments[1]].selectedIndex > 0)
	{
		//	IF KEY ELEMENT DOES NOT HAVE A VALUE RETURN FALSE
		if(document.forms[arguments[0]].elements[arguments[2]].selectedIndex == 0)
		{
			alert('You must select an ISP to search by status');
			return false;
		}
	}
}

/*-------------------------------------- CHECK REQUIRED FIELDS ---------------------------------------------
Author:		Ross Crawford
Date:		07 01 2002
Description:
Checks arguments passed in that are field names and then checks that each field in the list has a value.
function call description
return requiredFields('nameOfForm','fieldName','fieldDisplayName');
the first argument MUST be the name of the form.
------------------------------------------------------------------------------------------------------------*/
function requiredFields()
{
	var thisForm = arguments[0];
	var varFoundChecked = false;
	var thisElement = thisForm.elements[arguments[1]];
	// Check for dropdowns
	if (thisElement.type == 'select-one')
	{
		if (thisElement.options[thisElement.options.selectedIndex].value == '' || thisElement.options[thisElement.options.selectedIndex].value.length == 0 )
		{
			return 'error';
		}else{
			return 'none';
		}
	}

	// Check for radio buttons
	if (thisElement[0])
	{
		// loop through radio array and check for checked element
		for (g=0; g<thisElement.length; g++)
		{
			if (thisElement[g].checked)
			{
				ischecked = 1;
				break;
			}else{
				ischecked = 0;
			}
		}
		// if checked element not found then error
		if (ischecked==1)
		{
			return 'none';
		}else{
			return 'error';
		}
	}
	// Check for text fields
	if (thisElement.type == 'text' || thisElement.type == 'textarea' || thisElement.type == 'password')
	{
		if (thisElement.value.length < 1)
		{
			return 'error';
		}else{
			return 'none';
		}
	}
/*	if ( thisForm.elements[arguments[1]][thisForm.elements[arguments[1]].selectedIndex]) 
	{
		if (thisForm.elements[arguments[1]][thisForm.elements[arguments[1]].selectedIndex].value.length < 1 || thisForm.elements[arguments[1]].length < 1 )
		{
			return 'error';
		}else{
			return 'none';
		}
		
	}else if ( thisForm.elements[arguments[1]].value )
	{
		// Text fields and lists 		
		var thisElementValue = thisForm.elements[arguments[1]].value;
		if(thisElementValue.length < 1 || thisElementValue == '')
		{
			return 'error';
		}else{
			return 'none';
		}
	}else{
		// Radio buttons
		for (j=0; j < thisForm.elements[arguments[1]].length; j++ )
		{
			if( !thisForm.elements[arguments[1]][j].checked ) { varFoundChecked = true }
		}
		if( !varFoundChecked )
		{
			return 'error';
		}else{
			return 'none'		
		}		
	}*/
}
/*------------------------------------------------- INTEGER CHECK ---------------------------------------------
Author:		Ross Crawford
Date:		18 10 2001
Description:
Checks if the value of a form field is an integer
------------------------------------------------------------------------------------------------------------*/
function check_isInteger()
{
	var theForm = arguments[0];
	var elementValue = theForm.elements[arguments[1]].value;
	var int_errorFound = false;
	
	for ( count = 0; count < elementValue.length; count++ ) 
	{ 
	  if (elementValue.charAt(count) != '.')
	  {
				var theElement = parseInt(elementValue.charAt(count));

				if ( theElement != elementValue.charAt(count) & elementValue.charAt(count) != ' ' )
				{
				   int_errorFound = true;
				   break;
				}
	  }
	}

	//	Test for errorFound
	if( int_errorFound == true)
	{
		return 'error';
	}else{
		return 'none'
	}
}
/*------------------------------------------------- EMAIL CHECK ---------------------------------------------
Author:		Ross Crawford
Date:		21 11 2001
Description:
Change a form element to see if it contains a valid email address. All chars except SPACES are allowed
Emails must contiain an @ sign and a . with the . appearing after the @.

If more characters are to be disallowed at them to the disAllowedChars array located at ln 15. ('32','<newNum>'
------------------------------------------------------------------------------------------------------------*/
function checkforEmail()
{
	var thisForm = arguments[0];
	
	var theElement = arguments[1];
	var elementValue = thisForm.elements[theElement].value;
	
	var atFound = false;
	var firstDotFound = false;
	var errMsg = 'Please enter a valid email address in:\r\r';
	var errorsFound = false;
	var disAllowedChars = new Array ('32');	//	ASCII values for banned characters
	var charFound = false;
	var numArguments = arguments.length;

if ( elementValue.length > 0 )
{
	for ( count=0; count < elementValue.length; count++ ) 
	{ 
		for (cntr=0; cntr < disAllowedChars.length; cntr++) 
		{
			if (disAllowedChars[cntr] == elementValue.charCodeAt(count)){charFound = true; }
		}
		
		if ( elementValue.charAt(count) == '@' ){ atFound = true; }
		
		if (firstDotFound == false) 
		{
			if ( elementValue.charAt(count) == '.' & atFound == true  ){ firstDotFound = true; }			
		}
	}

	//	TEST FOR ERROR, IF FOUND BREAK ELSE CONTINUE
	if ( atFound != true || firstDotFound != true || charFound != false ) 
	{ 
		return 'error';
	}else{
		return 'none';
	}
}else{
	  return true;
}
}
/*-------------------------------------- CHECK FOR VALID DATE ---------------------------------------------
Author:		Ross Crawford
Date:		08 01 2002
Description:
Checks for a valid date
Requires:
	Function call must pass into function validDate(0 or 1,'form name','field names',etc)
	0 or 1 indicates wether these fields are required values.
	form name is the name of the form being acted on
	field names is a comma seperated list of strings
------------------------------------------------------------------------------------------------------------*/
function validDate()
{	
	var theForm = arguments[0];
	var theElement = arguments[1];
	var day = "";
	var month = "";
	var year = "";
	var thisDate = theForm.elements[theElement].value;
	var errors = false;
	var valDate_varTemp = '';

		//	TEST IS INTEGER

			//	EXRACT DD,MM,YYYY
			for (cn = 0; cn <= thisDate.length; cn++)
			{
				//	Day
				if(cn < 2)
				{
					//	REMOVE 0 from primary digit
					if(cn == 0 & thisDate.charAt(cn) != '0')
					{
						day = day + thisDate.charAt(cn); 
					}
					if(cn == 1)
					{
						day = day + thisDate.charAt(cn); 
					}
				}
				
				//	Month
				if(cn == 3 || cn == 4){
					//	REMOVE 0 from primary digit
					if(cn == 3 & thisDate.charAt(cn) != '0')
					{
						month = month +  thisDate.charAt(cn); 
					}
					if(cn == 4)
					{
						month = month +  thisDate.charAt(cn); 
					}
				}
				
				//	Year
				if(cn == 6 || cn == 7 || cn == 8 || cn==9)
				{
					year = year + thisDate.charAt(cn);
				}

				
			}
		

		//	TEST FOR ERRORS IN DATE FORMAT
		if(errors == false)
		{
			if(theElement == 0 & thisDate != '')
			{				
				if((day > 31) || (month > 12) || (year < 2000))
				{
					errors = true;
				}
				
			}
		}
	
	//	ALERT IF ERRORS WERE FOUND
	if(errors == true)
	{ 
		return 'error';
	}else{
		return 'none';
	}

}
/*-------------------------------------- CHECK AT LEAST ONE VALUE IS CHECKED ---------------------------------------------
Author:		Ross Crawford
Date:		20 09 2002
Description:
Check that at least one in a series of commonly named form elements has been selected.
------------------------------------------------------------------------------------------------------------*/
function checkOneSelected()
{
	var thisForm = arguments[0];
	var elementName = arguments[1];
	var elementsOfName = new Array();
	var oneFound = false;
	
	for (c = 0; c < thisForm.elements.length; c++)
	{
		varTest = thisForm.elements[c].name;

		if( varTest.indexOf(elementName) == 0)
		{
    		//  Test for element types
    		if (thisForm.elements[varTest].type == 'checkbox') 
    		{
    		   if ( thisForm.elements[varTest].checked != false ) { oneFound = true; }
    		}
    		if (thisForm.elements[varTest].type == 'text') 
    		{
    		   if ( thisForm.elements[varTest].value != '' ) { oneFound = true; }		
    		}else{
			// radio buttons
    			for (i=0; i < thisForm.elements[varTest].length; i++)
    			{
        		   if ( thisForm.elements[varTest][i].checked == true ) { oneFound = true;break;break; }
    			}   		
    		}

		}		
	}

	if(oneFound != true)
	{
		return 'error';
	}else{
		return 'none';
	}
}
/*-------------------------------------- GLOBAL FORM CHECK ---------------------------------------------
Author:		Ross Crawford
Date:		22 01 2002
Description:
Loops through array and splits arguments passed into 3 sections
1: Name of form element.
2: Name of form to Display on error.
3: Type of check to perform.
	3:1: Required
	3:2: Integer
	3:3: Email
	3:4: Date
	3:5: At least one option must be selected (field name specified must be common element names i.e. checkboxlist_1)
	3:6: Checks an elements value is the same as the next elements value.
------------------------------------------------------------------------------------------------------------*/
function gblChkFields()
{
	var thisForm = document.forms[arguments[0]];

	var elementName = '';
	var displayName = '';
	var testDataType = '';
	
	var varLoopCnt = 0;
	
	var outerLoopVal = arguments.length-1;	
	
	var counter = 0;
	var varTemp = 0;
	
	var thisArray = '';
	var varErrorsFound = '';
	var ErrorsFound = false;
		
//	alert(outerLoopVal);return false;
//	alert(arguments.length-1);return false;
	
	// Get elements from arguments and split into 3 arrays.	
	for( mainCntr = 1; mainCntr <= outerLoopVal; mainCntr+=3 )
	{ 
		elementName = arguments[ mainCntr ];
		displayName =  arguments[mainCntr + 1]; 
		testDataType = arguments[mainCntr + 2];		
		
//			alert(elementName+' , '+displayName+' , '+testDataType+' , :'+c);return false;
		//	Perform datatype test depending on argument 3
		switch (testDataType)
		{   			
			// 3:1: Requireds
			case '1' :
				varTemp = requiredFields(thisForm,elementName);
				 if( varTemp == 'error' )
				 {
				 	varErrorsFound = varErrorsFound + displayName +': is a required field.' + "\n";
					ErrorsFound = true;
				 }
				 break;
				 
			//	3:2: Integer
			case '2' :			
				varTemp = check_isInteger(thisForm,elementName);
				if( varTemp == 'error' )
				{
					varErrorsFound = varErrorsFound + displayName +': must be an Integer. (i.e. 1,2,3,etc).' + "\n";
					ErrorsFound = true;
				}			
				 break;
			
			//	3:3: Email
			case '3' : 
				varTemp = checkforEmail(thisForm,elementName);
				if( varTemp == 'error' )
				{
					varErrorsFound = varErrorsFound + displayName +': must be valid. (i.e. yourName@yourIsp.com).' + "\n";
					ErrorsFound = true;
				}
				 break;
			
			//	3:4: Date NEEDS FIXING
			case '4' : 
				varTemp = validDate(thisForm,elementName);
				if( varTemp == 'error' )
				{
					varErrorsFound = varErrorsFound + displayName +': Must be a valid date: (dd/mm/yyyy)\ndd = less than 32\nmm = less than 13\nyyyy = greater than 2000\nAll Integers.' + "\n";
					ErrorsFound = true;
				}
				 break;

			//	3:8: At least one (1) option must be selected
			case '5' :
				varTemp = checkOneSelected(thisForm,elementName);				
				if( varTemp == 'error' )
				{
					varErrorsFound = varErrorsFound + displayName +': At least one value present must be selected' + ". \n";
					ErrorsFound = true;
				}
			 break; 

			
			//	3:6: Element 1 value = element-1 value
			case '6' : 
				varTemp = sameValues(thisForm,elementName);				
				if( varTemp == 'error' )
				{
				//	Outputs the previous counters display name as a comparison.
					varErrorsFound = varErrorsFound + displayName +': Must be the same as '+arguments[mainCntr - 5]+". \n";
					ErrorsFound = true;
				}
			break;
			
		}
	}
	//	Test for error.
	if(ErrorsFound == true)
	{
		alert(varErrorsFound);
		ErrorsFound = false;
		return false;
	}else{
		return true;
	}
}
/*-------------------------------------- CONCATENATE FIELD VALUES ---------------------------------------------
Author:		Ross Crawford
Date:		22 12 2002
Description:
Function concatenates field values into one value
------------------------------------------------------------------------------------------------------------*/
function catVals()
{
	var thisSpacer = arguments[0]
	var targetField = arguments[1]
	var catVal = '';
	// c = 1 to miss out on the target field passed in.
	for (c = 2; c < arguments.length; c++)
	{
		if ( c < arguments.length-1 ) { spacer = thisSpacer; }else{ spacer = ''; }
		catVal += arguments[c]+spacer;
	}
	targetField.value = catVal;
}
-->