function AlertBoxes(errorvalue){
if(errorvalue==1001){
return "The text entry box contains at least 1 invalid character, please retry"
}

if(errorvalue==1002){
return "The text entry box does not contain a valid e-mail address, please retry"
}

if(errorvalue==1004){
return "The text entry box does not contain enough data, please retry"
}


if(errorvalue==1005){
return "The text entry box does not contain a valid number, please retry"
}


}

function AppFormOpen(){

window.open("ApplicationForm.asp","newwin","width=400,height=300,toolbars=0,scrollbars=0,location=0,status=0,menubar=0,directories=0")

}

function blankbox(inputbox){
if(inputbox == ""){
	return 1004
}
return 0
}


// ******************************************************************************
// ******************************************************************************
// ******************************************************************************
//
// This is the function to Check Valid E-Mail addresses
//
// Function Name -> CheckValidEmail()
//
// Required Parameters -> The reference of the text field
//                        Eg. document.forms[n].elements[n].value
//
// What it does -> Checks that the address is at least 7 chrs long
// 		-> Checks that no illegal characters are included
//		-> Checks that the address contains an '@' and a '.' and
//		   that there is only one instance of '@' and that there is a
//		   '.' after the '@'
//
// Function by Dan Massey 23/July/00 (yes, that's a Sunday)
//
// ******************************************************************************

function checkvalidemail(inputbox){

// Convert inputbox to string

var teststring 

teststring = inputbox.toString()

// First check for ""

	if(inputbox == ""){

		return 1002

	}

 	
// Check for at least 7 chrs

	if(teststring.length <= 6){

		return 1002

	}

// Check for Illegal Characters

var illegalchrs = new Array("*","£","$","!")

var counter
	
	for(counter=0;counter<=illegalchrs.length;counter++){

		if(teststring.indexOf(illegalchrs[counter]) != -1){

			return 1002
		}

	}

// Check for the @ and the dots

// First check that they both exist

var atpositionback = teststring.lastIndexOf("@")

var dotpositionback = teststring.lastIndexOf(".")

var atpositionfront = teststring.indexOf("@")


	if(atpositionback == -1){

		return 1002

	}

	if(dotpositionback == -1){

		return 1002

	}


	if(atpositionfront != atpositionback){

		return 1002

	}


	if(atpositionback > dotpositionback){

		return 1002

	}



return 0
}

// ******************************************************************************
// ******************************************************************************
// ******************************************************************************



// ******************************************************************************
// ******************************************************************************
// ******************************************************************************
//
// This is the function to Check Required String Lengths in Text Boxes
//
// Function Name -> testtextlen()
//
// Required Parameters  -> The reference of the text field
//                         Eg. document.forms[n].elements[n].value
//			-> The number of characters required	
//
// What it does -> Checks that the text string has the number of required elements
//
// Function by Dan Massey 23/July/00 (yes, that's a Sunday)
//
// ******************************************************************************

function testtextlen(thetextbox,chars){

// convert to string

	if(thetextbox == ""){

		return 1004

	}

var teststring = thetextbox.toString()


var quant = parseInt(chars,10) 

// check length

	if(teststring.length < quant){
	
		return 1004

	}

return 0

}
// ******************************************************************************
// ******************************************************************************
// ******************************************************************************

// ******************************************************************************
// ******************************************************************************
// ******************************************************************************
//
// This is the function to Check Teelphone / Fax Numbers in Text Boxes
//
// Function Name -> testphone()
//
// Required Parameters  -> The reference of the text field
//                         Eg. document.forms[n].elements[n].value	
//
// What it does -> Checks that the only data is numeric, space,"(",")","+"
//
// Function by Dan Massey 23/July/00 (yes, that's a Sunday)
//
// ******************************************************************************

function testphone(thephonebox){

// first check it's not empty

	if(thephonebox == ""){
		return 1005
	}

// convert to string

var teststring = thephonebox.toString()

// test for minimum length

	if(teststring.length < 10){

		return 1005
	}

// test for maximum length

	if(teststring.length > 20){
		
		return 1005
	}


var legalchrs = "0123456789()+ "

	for(counter=0; counter <= teststring.length; counter ++){

		if(legalchrs.indexOf(teststring.charAt(counter)) == -1){
			
			return 1005
		}

	}

return 0
}

// ******************************************************************************
// ******************************************************************************
// ******************************************************************************



// ******************************************************************************
// ******************************************************************************
// ******************************************************************************
//
// This is the function to Check Password Applications from 2 boxes
//
// Function Name -> testpasswords()
//
// Required Parameters  -> The reference of the text fields (2 number)
//                         Eg. document.forms[n].elements[n].value	
//
// What it does -> The function checks that the password fields match
//
// Function by Dan Massey 23/July/00 (yes, that's a Sunday)
//
// ******************************************************************************

function testpasswords(box1,box2){

}

// ******************************************************************************
// ******************************************************************************
// ******************************************************************************
//
// This is the function to ensure correct date input
//
// Function Name -> dodate(endstring,formnumber,ele)
//
// Required Parameters  -> The reference of the text fields (2 number)
//                         Eg. document.forms[n].elements[n].value
//			   The forms array number (usually 0)
//			   The text box's element number	
//
// What it does -> The function ensures the date is inputted dd/mm/yyyy
//
// Note: this function is tagged as such to the text box element
//
// <input type="text" name="T1" size="20" onKeyUp="dodate(document.forms[0].elements[0].value,0,0)">
//
//
// Function by Dan Massey 23/July/00 (yes, that's a Sunday)
//
// ******************************************************************************



var yeartoggle = 0

function dodate(endstring,formnumber,ele){

// make string of allowed characters

var goodc = "1234567890/"

var replacement

// convert

teststring = endstring.toString()

// Strip out the shite characters on the fly

if(goodc.indexOf(teststring.charAt(teststring.length-1)) == -1){

	// make new string

	replacement = teststring.substring(0,teststring.length-1)
	
	// Assign new string value 

	document.forms[formnumber].elements[ele].value = replacement

}

// Add leading zero on the day part
 
if(teststring.charAt(teststring.length-1) == "/" && teststring.length == 2){

	replacement = 0 + teststring 

	document.forms[formnumber].elements[ele].value = replacement

	

}

// Check day total is not over 31

if(teststring.length==2 && teststring.indexOf("/") == -1){

	checkdays = parseInt(teststring.substring(0,2))
	
	if(checkdays >31){
	
		alert("Day value is too high")
	
		document.forms[formnumber].elements[ele].focus()
		
		document.forms[formnumber].elements[ele].select()
	}

}	 

// Add leading zero to month

if(teststring.charAt(teststring.length-1) == "/" && teststring.length == 5){

	trailer = teststring.substring(3,5)
	
	replacement = teststring.substring(0,3) + 0 + trailer 

	document.forms[formnumber].elements[ele].value = replacement

}

// check months

if(teststring.length==6){

	checkmonths = parseInt(teststring.substring(3,5))
	
	if(checkmonths >12){
	
		alert("Month value is too high")
		
		replacement = teststring.substring(0,3)
		
		document.forms[formnumber].elements[ele].value = replacement	
	}
}

// Force full Date year

if(yeartoggle==0){

	if(teststring.length==7){ 

		if(teststring.charAt(teststring.length-1) > 5 && teststring.charAt(teststring.length-1) <= 9){

			trailer = teststring.charAt(teststring.length-1)

			replacement = teststring.substring(0,6) + 19 + trailer
	
			document.forms[formnumber].elements[ele].value = replacement
	
			yeartoggle = 1
		}

		else{
	
			trailer = teststring.charAt(teststring.length-1)
	
			replacement = teststring.substring(0,6) + 20 + trailer
	
			document.forms[formnumber].elements[ele].value = replacement
	
			yeartoggle = 1
	
		}
	
	}
}

if(teststring.length == 10){

	// Now the really clever bit - Is the date real?

	//document.write("arrived")

	var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December") 

	var doms = new Array("31","28","31","30","31","30","31","31","30","31","30","31")

	var leapyear = 2000

	// get current date into variables

	daysindate = parseInt(teststring.substring(0,2))

	monthindate = parseInt(teststring.substring(3,5))

	yearindate = parseInt(teststring.substring(6,10))

	// Run Checks with alert boxes

	// Adjust for Leap Years

	if(yearindate%4 ==0){

		doms[1] = "29"

	}

	if(daysindate > parseInt(doms[monthindate-1])){

		alert("Invalid Date - " + months[monthindate-1] + " only has " + doms[monthindate-1] + " days, please retry")

	}

}

if(teststring.length == 11){

	replacement = teststring.substring(0,10)

	document.forms[formnumber].elements[ele].value = replacement
}
}
