// Validation File

var submitted = false;

function CheckEmailAddress (emailStr) {

	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address.
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
		 even fit the general mould of a valid e-mail address. */
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid
	if (user.match(userPat)==null) {
		// user is not valid
		return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false
			}
		}
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding
	   the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}

function CheckInputValidation( inputType, inputObj, boolCanBeEmpty, lngMinLength, lngMaxLength, boolStripChars )
{
	// Assume a negative
	var isValid = false;
	var inputValue = inputObj.value;


	if (inputObj.nodeName=='SELECT'){
		inputType="select";
	}

	
	switch (inputType){
	
		case 'select':
			isValid = CheckSelect( inputValue, boolCanBeEmpty );
			break;


		case 'email':
			isValid = CheckEmailAddress( inputValue, boolCanBeEmpty, lngMinLength, lngMaxLength, boolStripChars )	
			break;

		case 'phonenumber':
			isValid = CheckPhoneNumber( inputValue, boolCanBeEmpty, lngMinLength, lngMaxLength, boolStripChars )
			break;


		case 'radio':
			isValid = CheckRadio( inputObj, boolCanBeEmpty );
			break;


		case 'file':
			isValid = CheckFreeText( inputValue, boolCanBeEmpty, lngMinLength, 500, boolStripChars );
			break;

		case 'freetext':
		default:

			
			isValid = CheckFreeText( inputValue, boolCanBeEmpty, lngMinLength, lngMaxLength, boolStripChars );

			break;


	}	

	//Store default borderColor	
	if (isUndefined(inputObj.defaultBorderColor)){
		
		
		if (!isUndefined(inputObj.style.borderColor)){
			inputObj.defaultBorderColor=inputObj.style.borderColor;
		} else {		
			inputObj.defaultBorderColor="";
		}

	}
	

	//Store default backgroundColor	
	if (isUndefined(inputObj.defaultBackgroundColor)){
		
		
		if (!isUndefined(inputObj.style.backgroundColor)){
			inputObj.defaultBorderColor=inputObj.style.backgroundColor;
		} else {		
			inputObj.defaultBackgroundColor="";
		}
	}

	
	

	// Set the colour ...
	if ( isValid ) 
		
		switch (inputType){
		
		case  'radio':
			for (i = 0; i < inputObj.length; i++) {
				inputObj[i].style.borderColor = inputObj.defaultBorderColor;
			}
		break;

		case 'select':
			//Select controls cannot have styled borders in IE :-(
			inputObj.style.backgroundColor=inputObj.defaultBackgroundColor;
		break;

		default:
		
			inputObj.style.borderColor = inputObj.defaultBorderColor;

		}
	else 
		
		switch (inputType){
		
		case  'radio':
			for (i = 0; i < inputObj.length; i++) {
				inputObj[i].style.borderColor = 'red';
			}
			break;

		case 'select':
			inputObj.style.backgroundColor = 'red';

			
		default:
			inputObj.style.borderColor = 'red';
			
		}
	
	if (submitted && !isValid){

		errMsg = "";
		if (inputObj.id){
			errMsg = inputObj.id;
		}
		else{
			errMsg = "Elements in Red";
		}
		alert(errMsg + " must be completed\n");
		submitted = false;
	}
	// ... and return boolean indication
	return isValid;
}

function isPhoneNumber(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function isMoney(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if ((c < "0" || c > "9" ) && c !="," && c!=".") return false;
    }
    // All characters are numbers.
    return true;
}



function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function CheckRadio( inputObj, boolCanBeEmpty )
{
	var isValid = false;
	
	if ( boolCanBeEmpty == false ) {
		for (i = 0; i < inputObj.length; i++) {
			thisValid = inputObj[i].checked; 	 // had to do this cos of javascript 
			if ( thisValid == true ) isValid = true; // bombing out cos of some bug
		}
	}
	
	return isValid;
}

function CheckAttributes ( inputValue, boolCanBeEmpty, lngMinLength, lngMaxLength, strStripChars )
{



	var isValid = true;
	
	// Do we need to count spaces in the length check?
	if ( strStripChars != "" ) inputValue = stripCharsInBag( inputValue, strStripChars );

	// Is it empty? And can it be?
	

	if ( !boolCanBeEmpty && inputValue.length == 0 ) {
		return false;
	}

	// Check if its too short ...
	if (lngMinLength > 0 && inputValue.length < lngMinLength ) {
		return false;	
	}

	// Or too long?
	if ( inputValue.length > lngMaxLength ) {
		return false;
	}


	
	return isValid;
}	

function CheckFreeText(inputValue, boolCanBeEmpty, lngMinLength, lngMaxLength, strStripChars )
{

	
	var isValid = CheckAttributes( inputValue, boolCanBeEmpty, lngMinLength, lngMaxLength, strStripChars );	
	return isValid;
}

function CheckSelect( inputValue, boolCanBeEmpty )
{

	var isValid 	= false;
	
	
	// Can this field be empty? And is it? Don't check then
	// Is it a select?
	if ( 	( boolCanBeEmpty == true )  ||
		( ( boolCanBeEmpty == false ) && !( ( inputValue == "" )  ) ) 
	)
		isValid = true;

	return isValid;	
	
	// Ignore this  .... deals with mutiple selects, maybe useful one day?
	var inputObj;
	
	if ( boolCanBeEmpty == false ) {
		var lngSelectCount = 0;
		for (i = 0; i < inputObj.length; i++) {
			thisValid = inputObj[i].selected;
			if ( thisValid ) lngSelectCount++;
		}	
	}	
}

function CheckPhoneNumber(inputValue, boolCanBeEmpty, lngMinLength, lngMaxLength, boolStripChars )
{

	// Declaring required variables
	var digits = "0123456789";

	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";

	// characters which are allowed in international phone numbers (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";

	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;

	var isValid = CheckAttributes( inputValue, boolCanBeEmpty, lngMinLength, lngMaxLength, boolStripChars );

	if ( isValid ) { 
		s=stripCharsInBag(inputValue,validWorldPhoneChars);
		isValid = (isPhoneNumber(s) && s.length >= minDigitsInIPhoneNumber);	
	}
	
	return isValid;
}



function GetKeyCode(e) { // event object is being passed from function call.

	//Cross Browser functionality :-)
	

	//Call as follows: <textarea name="text" rows="4" cols="25" onKeypress="var x=GetKeyCode(event);alert(x);"></textarea>


	if(e){ // if the event object is present (NN only)
		e = e // var e = event
	}
	else {
		e = window.event // else e = winddow.event for IE
	}

	if(e.which){ // if there is syntax support for the property 'which' (NN only)
		var keycode = e.which // e.which is stored in variable "keycode"
	}
	else {
		var keycode = e.keyCode // otherwise for IE, var keycode stores e.keyCode syntax
	}


	return keycode;

	//These can be used to trap things from other functions (not that e must be passed)
	    //e.returnValue=false;
	//return false;


}


function DateEntryAutoHandler(objControl,e,strFormat) {

	// Copyright Chris Barnes / Delivered Systems 2009


	var objDate=new Date();
	var datLocaleNow;

	var lngNewCaretPos;
	var strTmp;
	var strRejectMessage="";
	var strWarningMessage="";
	var arrConfig=Array();

	displayControlWarning(objControl,"");

	var keycode=GetKeyCode(e);

	//displayControlWarning(objControl,keycode);
	
	if (keycode >=96 && keycode <=105){
		//Offset for Numlock
		keycode=keycode -48;	
	}
	
	

	if (isEmpty(strFormat)) {
		strFormat="";
	}	
		
	switch(strFormat){
	
		case strFormat:
		
			strFormat='dd/MM/yyyy hh:mm';
			var lngSeparatorCode=47;
			var strSeparatorChar="/";
			datLocaleNow= formatDate(objDate,strFormat);
			
			
			break;

	
	
		default:
		

			alert("This function currently only handles format dd/mm/yyyy hh:mm");
			setControlBorderColour(objControl,strWarningColour);
			e.returnValue=false;
			return false;		
	
	}
	
	
	
	
	var strEntered=String.fromCharCode(keycode);
	strEntered=strEntered.toString();
	
	var lngCaretPos=GetCaretPosition(objControl);
	
	var strText=objControl.value; //Note this is the value prior to update
	

	var arrCurrentText=strText.split("");
	arrCurrentText=resetSeparatorsInDateArray(arrCurrentText);
	

	if (keycode == 110 || keycode==78){
		if (strText != "") {
			e.returnValue=false;
			if (confirm("Insert Todays Date ?") !=true) {
				boolReject=true;
				e.returnValue=false;
				return false;
			}
		}
		objControl.value=datLocaleNow;
		return false;	
	}

	//Allow Tab to move
	if (keycode==9){
		setCaretPosition(objControl,0);
		e.returnValue=true;
		return true;		
	}
	
	//Cursor Keys  can go where they like
	if (keycode==37 || keycode==39  ) {	
		
		arrCurrentText=resetSeparatorsInDateArray(arrCurrentText);
		arrCurrentText=zeroPadDateArraySegmentByCaretPos(arrCurrentText,15);
		objControl.value=arrCurrentText.join("");
		setCaretPosition(objControl,lngCaretPos);
		
		e.returnValue=true;
		return true;
		
	}
	
	
	
	//Now we're into processing we don't want ANYTHING returned.

	e.returnValue=false;
	
	
	//Backspace
	if (keycode==8){
		arrCurrentText[lngCaretPos -1]=" ";
		arrCurrentText=resetSeparatorsInDateArray(arrCurrentText);
		objControl.value=arrCurrentText.join("");
		setCaretPosition(objControl,lngCaretPos -1);
		setControlBorderColour(objControl,"#00ff00");
		return false;	

	}


	//Reset the control value anyway so that we see separators whatever happens
	objControl.value=arrCurrentText.join(""); // Flatten array to string	
	
	
	

	var lngFirstEmpty=getFirstEmptyPositionInDateArray(arrCurrentText);	


	if (lngFirstEmpty !=lngCaretPos){
		setCaretPosition(objControl,lngFirstEmpty);
		displayControlWarning(objControl,"Please enter a date in the format<br>" + strFormat);
		return false;
	}
	

	switch(lngCaretPos){

	case 0:
		if (isUndefined(arrCurrentText[1])){
			arrCurrentText[1]=" ";			
		}
		
		
		//Day Digit 1
		if (isNaN(strEntered)){
			//alert(strEntered);
			if (strEntered=="/"){
				strEntered=" ";
				lngNewCaretPos=3;
			} else {
				strRejectMessage="Please enter a date in the format<br>" + strFormat;
			}
		
		} else {
		
			var lngTmp=strEntered.toString() + arrCurrentText[1].toString();
			if (lngTmp > 31){
				strRejectMessage="There can never be more than 31 days in a month";
			} else {
				lngNewCaretPos=1;
			}
			

		}		
		
		
		
		break;

	case 1:
		if (isNaN(strEntered)){
			if (strEntered=="/"){
				strEntered=" ";
				lngNewCaretPos=3;
			} else {
				strRejectMessage="Please enter a date in the format<br>" + strFormat;
			}
		} else {		
			//Day Digit 2
		
			//Do not use parseInt .... it breaks on 08
			var lngTmp=String(arrCurrentText[0].toString()) + String(strEntered.toString());
						
			
			
			if (lngTmp > 31 || lngTmp==0){
				if (lngTmp > 31){
					strRejectMessage="There can never be more than 31 days in a month";
				}
				if (lngTmp==0){
					strRejectMessage="Please enter a valid number of days";			
				}
				
			} else {
				lngNewCaretPos=3;
			}
			

		}

		break;		

	case 2://Separator

		strEntered="/";
		lngNewCaretPos=3;
		break;
		
		
		break;


	case 3:
		//Month Digit 1
		if (isNaN(strEntered)){
			if (strEntered=="/"){
				strEntered=" ";
				lngNewCaretPos=6;
			} else {
				strRejectMessage="Please enter a date in the format<br>" + strFormat;
			}		

		} else {		
			//Do not use parseInt .... it breaks on 08
			var lngTmp=(strEntered.toString() + arrCurrentText[4].toString());
			if (lngTmp > 12){
				strRejectMessage="There can never be more than 12 months in a year";
			} else {
				lngNewCaretPos=4;
			}
		}		


		break;	

	case 4:
		//Month Digit 2
		if (isNaN(strEntered)){
			if (strEntered=="/"){
				strEntered=" ";
				lngNewCaretPos=6;
			} else {
				strRejectMessage="Please enter a date in the format<br>" + strFormat;
			}

		} else {
		
			var lngTmp=arrCurrentText[3].toString() + strEntered.toString();
			
			if (lngTmp > 12 || lngTmp==0){
				if (lngTmp > 12){
					strRejectMessage="There can never be more than 12 months in a year";
				} 
				if (lngTmp ==0){
					strRejectMessage="Please enter a valid number of months";			
				}

			} else {
				lngNewCaretPos=6;
			}
		}		


		break;	

	case 5:
	
		strEntered="/";
		lngNewCaretPos=6;
		break;
			
			



	case 6:
	

	
		//YEAR
		if (isNaN(strEntered)){
		
			strRejectMessage="Please enter a date in the format<br>" + strFormat;
		} else {
			var lngTmp=parseInt(strEntered.toString());
			// Y2K Compliance enforcement
			if (lngTmp ==0){
				strRejectMessage="Please enter the full year";
			} else {
				if (lngTmp==1){
					strWarningMessage="Are you sure you want to enter a date from the last millenium ?";
				}
				if (lngTmp > 2){
					strWarningMessage="Are you sure you want to enter a date more than a thousand years in the future ?<br>Perhaps you've invented time travel ?";
				}
				
				
				
				lngNewCaretPos=7;
			}
		}
	
		break;	

	case 7:
		if (isNaN(strEntered)){
			strRejectMessage="Please enter a date in the format<br>" + strFormat;
		} else {
			lngNewCaretPos=8;
		}

		break;
	case 8:
		if (isNaN(strEntered)){
			strRejectMessage="Please enter a date in the format<br>" + strFormat;
		} else {
			lngNewCaretPos=9;			
		}

		break;

	case 9:

		if (isNaN(strEntered)){
			strRejectMessage="Please enter a date in the format<br>" + strFormat;
		} else {
			lngNewCaretPos=10;
		}

		break;

	case 10:
		strEntered=" ";
		lngNewCaretPos=11;
		break;

	case 11:
		//Hour of day Digit 1
		if (isNaN(parseInt(strEntered))){
			strRejectMessage="Please enter a date in the format<br>" + strFormat;
		} else {
			var lngTmp=parseInt(strEntered.toString() + arrCurrentText[12].toString());
			if (lngTmp >= 24){
				strRejectMessage="There can never be more than 24 hours in a day";
			} else {
				lngNewCaretPos=12;
			}
		}		
		
		
		
		break;

	case 12:
		//Hour of Day Digit 2
		if (isNaN(parseInt(strEntered))){
			strRejectMessage="Please enter a date in the format<br>" + strFormat;
		} else {
			var lngTmp=parseInt( arrCurrentText[11].toString() + strEntered.toString());
			if (lngTmp >= 24){
				strRejectMessage="There can never be more than 24 hours in a day";
			} else {
				lngNewCaretPos=14;
			}
		}		


		break;	

	case 13:
		//Time separator
		strEntered=":";
		lngNewCaretPos=14;
		break;		
	

	case 14:
		//Minute Digit 1
		if (isNaN(parseInt(strEntered))){
			strRejectMessage="Please enter a date in the format<br>" + strFormat;
		} else {
			var lngTmp=parseInt(strEntered.toString() + arrCurrentText[15].toString());
			if (lngTmp >= 60){
				strRejectMessage="There can never be more than 60 minutes in an hour";
			} else {
				lngNewCaretPos=15;
			}
		}		
		
		
		
		break;

	case 15:
		//Minute Digit 2
		if (isNaN(parseInt(strEntered))){
			strRejectMessage="Please enter a date in the format<br>" + strFormat;
		} else {
			var lngTmp=parseInt( arrCurrentText[14].toString() + strEntered.toString());
			if (lngTmp >= 60){
				strRejectMessage="There can never be more than 60 minutes in an hour";
			} else {
				lngNewCaretPos=16;
			}
		}		


		break;	



	default:
		//strRejectMessage="Please enter a date in the format<br>" + strFormat;
		strEntered="";
		lngNewCaretPos=15;
		
	}




	if (strRejectMessage !="") {
		displayControlWarning(objControl,strRejectMessage);
		objControl.style.borderColor="#FF0000";		
		setCaretPosition(objControl,lngCaretPos);
		return false;
	}

	arrCurrentText[lngCaretPos]=strEntered;


	arrCurrentText=zeroPadDateArraySegmentByCaretPos(arrCurrentText,lngNewCaretPos);
	arrCurrentText=resetSeparatorsInDateArray(arrCurrentText);

	objControl.value=arrCurrentText.join("");
	setCaretPosition(objControl,lngNewCaretPos);
	setControlBorderColour(objControl,'default');
	if (strWarningMessage !=""){
		displayControlWarning(objControl,strWarningMessage);
	}
	
	return false;


}


function resetSeparatorsInDateArray(arrLocaleDate){


	for(var i=0;i < 16;i++){
		if (isUndefined(arrLocaleDate[i])){
			arrLocaleDate[i]=" ";
		}	
	}


	//Note that isNaN(" ") returns false ! aaaagh !
	if (isNaN(parseInt(arrLocaleDate[0])) || isNaN(parseInt(arrLocaleDate[1]))){	
		
		
		 
		arrLocaleDate[1]=" "; 
		arrLocaleDate[2]=" "; 
		arrLocaleDate[3]=" ";
		arrLocaleDate[4]=" ";
		arrLocaleDate[5]=" ";
		arrLocaleDate[6]=" ";
		arrLocaleDate[7]=" ";
		arrLocaleDate[8]=" ";
		arrLocaleDate[9]=" ";
		arrLocaleDate[10]=" ";

	} else {
		
		arrLocaleDate[2]="/";
		arrLocaleDate[5]="/";
	}
	
	//Remove time element if not applicable
	if (isNaN(parseInt(arrLocaleDate[11]))){
		
		arrLocaleDate[11]=" ";
		arrLocaleDate[12]=" ";
		arrLocaleDate[13]=" ";
		arrLocaleDate[14]=" ";
		arrLocaleDate[15]=" ";
	} else {
		arrLocaleDate[13]=":";
	}

	return arrLocaleDate;
}

function getFirstEmptyPositionInDateArray(arrLocaleDate){

	//A space is allowed at position 10

	for(var i=0;i <=16;i++){
		if (i !=10){
			if (isUndefined(arrLocaleDate[i])){	
				return i;
			}
			
			if (arrLocaleDate[i]==" "){
				return i;
			}
			
		}
	}
	
	

}


function zeroPadDateArraySegmentByCaretPos(arrLocaleDate,lngCaretPos){

	//Corrections for zero padding
	if (lngCaretPos >1){
		arrLocaleDate=zeroPadDateArraySegment(arrLocaleDate,0);
	}


	//Corrections for zero padding
	if (lngCaretPos >4){
		arrLocaleDate=zeroPadDateArraySegment(arrLocaleDate,1);
	}

	//Corrections for zero padding
	if (lngCaretPos >12){
		arrLocaleDate=zeroPadDateArraySegment(arrLocaleDate,3);
	}

	if (lngCaretPos >15){
		arrLocaleDate=zeroPadDateArraySegment(arrLocaleDate,4);
	}

	return arrLocaleDate;

}


function zeroPadDateArraySegment(arrLocaleDate,lngSegmentPostion){


	//arrLocaleDate is an array where each element represents the position in the string of each element of a locale date
	//lngSegmentPostion indicates the day, month,year,hour, minute to which zero padding should be applied
	//This is locale agnostic such that lngSegmentPostion=0 represents day for UK dates and month for US dates
	//Chris Barnes 2009

	var lngPosA;
	var lngPosB;


	switch (lngSegmentPostion){
	
		case 0:
			//day for UK, month for US
			lngPosA=0;
			lngPosB=1;
		
			break;
		case 1:
			//month for UK, day for US
			lngPosA=3;
			lngPosB=4;		
				
			break;
		case 2:
			//Not implemented for year

			break;

		case 3:
			//Hour
			//dd/MM/yyyy hh:mm
			lngPosA=11;
			lngPosB=12;

			break;
	
		case 4:
		
			//Minute
			lngPosA=14;
			lngPosB=15;
			break;
	
	}

	if (isNaN(lngPosA)){
		return arrLocaleDate;
	}

	lngTmp=parseInt(arrLocaleDate[lngPosA].toString() + arrLocaleDate[lngPosB].toString());
	
	
	
	if (lngTmp==0 || isNaN(lngTmp)){
		return arrLocaleDate;
	}
	
	if (lngTmp < 10){
		arrLocaleDate[lngPosA]=0;
		arrLocaleDate[lngPosB]=lngTmp;
	}


	return arrLocaleDate;

}




function setControlBorderColour(objControl,strColour){

	//if strColour is set to "default" then revert to default from css or whatever
	
	//Store default borderColor	
	if (isUndefined(objControl.defaultBorderColor)){
		
		if (!isUndefined(objControl.style.borderColor)){
			objControl.defaultBorderColor=objControl.style.borderColor;
		} else {		
			objControl.defaultBorderColor="";
		}

	}
	
	if (strColour=="default"){
		objControl.style.borderColor=objControl.defaultBorderColor;
		return;
	}
	
	objControl.style.borderColor=strColour;

}






