	var iOpacity=100;
	var iOpacity=100;
	var IE4 = (document.all);
	var NS4 = (document.layers);
	var dLastGridDate;


	function ButtonPostBack(oButton) {      
        oButton.disabled=true;
        Postback(oButton.id,'');
    }
	
	function Postback(sCommand, sArgument, bCheckDelete) {

		//confirm delete if required	
		if (bCheckDelete==true) {
			if (confirm('Are you sure that you want to delete this record?')==false) {
				return;
			}
		}


		if (typeof(oWYSIWYG)!='undefined') {
			TidyXHTML();
		}
		
		document.forms[0].Command.value=sCommand;
		document.forms[0].Argument.value=sArgument;
		document.forms[0].submit();
	}	
	
    
  
	
	function TextboxSubmit(oEvent, sCommand, sArgument) {
		if (oEvent.keyCode == 13) {
			document.forms[0].Command.value=sCommand;
			document.forms[0].Argument.value=sArgument;
			document.forms[0].submit();
			oEvent.cancelBubble = true;
			oEvent.returnValue = false;
			
		}
	}

	function SetFocus(sControlID) {
		var oControl=window.document.getElementById(sControlID);
		if (oControl != null){oControl.focus()};
	}	

	function IntegerOnly(oEvent) {
		return oEvent.keyCode>47 && oEvent.keyCode<58;
	}

	function IntegerMinusOnly(oEvent) {
		return oEvent.keyCode>47 && oEvent.keyCode<58 || oEvent.keyCode==45;
	}
	
	function NumberOnly(oEvent) {
		return (oEvent.keyCode>47 && oEvent.keyCode<58) || (oEvent.keyCode==46 || oEvent.keyCode==45);
	}	
	
	
	function selectAll(ID,bSelected) {
		var oForm = document.forms[0];
		var oControl; 
		
		var bChecked, sSelectAllID;
		
		if (bSelected==undefined) {
			sSelectAllID=ID + 'SelectAll';
			bChecked = document.getElementById(sSelectAllID).checked;
		} else {
			bChecked=bSelected;
		}
		var iLen = ID.length;
		
		//look for status of the 'check all' checkbox
		//and set the other checkbox' with ID accordingly 
		for (var i=0;i < oForm.length;i++) {
			oControl = oForm.elements[i];
			
			//&& oControl.style.display != 'none'
			if (oControl.type == 'checkbox'  && oControl.currentStyle.display != 'none' &&
				oControl.id != sSelectAllID && oControl.id.substring(0,iLen) == ID) {   
				
				oControl.checked = bChecked;         
			}
		}
	} 



function ListboxPostback(sCommand, sArgument, bCheckDelete, sConfirmVerb, sConfirmNoun) {

	//if confirm verb and confirm noun are undefined then set them to delete and record respectively
	if ((sConfirmVerb==undefined)||(sConfirmVerb=='')) {
        sConfirmVerb='delete';
	}
	
	if ((sConfirmNoun==undefined)||(sConfirmNoun=='')) {
        sConfirmNoun='record';
	}

	//confirm delete if required
	if (bCheckDelete==true) {
        if (confirm('Are you sure that you want to '+sConfirmVerb+' this '+sConfirmNoun+'?')==false) {
            return;
        }

	}
	
	Postback(sCommand, sArgument);
}

function DataListSetScroll(sListID, sRowID) {
		
	var oList=window.document.getElementById(sListID+'Scroll');
	var oRow=window.document.getElementById(sRowID);
	
	if (oRow!=null) {
		if (oRow.offsetTop > (oList.offsetHeight-oRow.offsetHeight)) {	
			oList.scrollTop=oRow.offsetTop-30;
		}
	}
}

function DropDownSelect(oList, oEvent, sAutoPostBack) {
				
		var oStoreKeyPress=document.getElementById('hid'+oList.name);
		
		if ((oEvent.keyCode==13)&&(sAutoPostBack!='true')) {
			return;
		} else if ((oEvent.keyCode==13)&&(sAutoPostBack=='true')) {
			Postback(oList.name,'')
		} else if (oEvent.keyCode!=27) {
			oStoreKeyPress.value=oStoreKeyPress.value+String.fromCharCode(oEvent.keyCode);
		} else {
			oStoreKeyPress.value='';
		}
		
		//find it
		SelectItemFromSearch(oList, oStoreKeyPress.value);
		return false;

	}
	
	function SelectItemFromSearch(oList, sSearch) {
		for (var i=0; i<oList.options.length; i++) {
			if (oList.options[i].text.toLowerCase().indexOf(sSearch.toLowerCase())==0) {
				oList.selectedIndex=i;				
				return;
			}
		}
		oList.selectedIndex=0;
	}
	
	function ClearSelection(oList) {
		
		document.getElementById('hid'+oList.name).value='';
	}
	

	
	function SafeInt(sInteger) {		
		if ((sInteger==null)||(sInteger=='')||(sInteger=='0')) {
			return 0;
		} else {
		
			//remove any commas
			var aInt = sInteger.split(",");
			var sTotal='';
			for (var loop=0; loop<aInt.length; loop++) {
				sTotal+=aInt[loop];
			}
			return parseInt(parseFloat(sTotal));
		}
	}
	
	function SafeNumeric(sNumber) {		
		if ((sNumber==null)||(sNumber=='')||(sNumber=='0')) {
			return 0;
		} else {
		
			//remove any commas
			var aInt = sNumber.split(",");
			var sTotal='';
			for (var loop=0; loop<aInt.length; loop++) {
				sTotal+=aInt[loop];
			}
			return parseFloat(sTotal);
		}
	}
	

		
	
	
/* *************     Validation Functions ********** */
function ClientValidation(oButton, sTable) {

	var sControlID, sNiceName, sValidation,
		sControlPrefix, oControl, sControlValue, sWarnings='',
		iSelectedValue, sSelectedValue, sFocusControl='',bIsValid;
	
	//postback if we haven't got the validation array
	if (typeof(aValidation)=='undefined') {
		ButtonPostBack(oButton);
		return;
	}
				
	for (var i=0;i<aValidation.length;i++) {
		if (sTable=='' || sTable==aValidation[i][0]) {
			sControlID=aValidation[i][1];
			sNiceName=aValidation[i][2];
			sValidation=aValidation[i][3];
			
			oControl=document.getElementById(sControlID);
			bIsValid=true;
			
			//if the control is null then don't do nowt
			if (oControl!=null) {
				sControlPrefix=sControlID.substring(0,3);

				// textbox
				if (sControlPrefix=='txt') {

					sControlValue=oControl.value;

					// not empty
					if (sValidation.indexOf('NotEmpty')>-1 && sControlValue=='') {
						bIsValid=false;
						sWarnings+='The '+sNiceName+' must be specified|';
					}	
					
					/* not empty is numeric */
					if (sValidation.indexOf('NotEmpty')>-1 && oControl.className.indexOf('number')>-1
								 && SafeNumeric(sControlValue)==0) {
						bIsValid=false;
						sWarnings+='The '+sNiceName+' must be specified|';
					}			
					
					//email
					if (sValidation.indexOf('IsEmail')>-1 && IsEmail(sControlValue)==false) {
						bIsValid=false;
						sWarnings+='The '+sNiceName+' must be a Valid Email|';
					}		
					
				}
								

				// date textbox
				if (sControlPrefix=='dtb') {
					sControlValue=oControl.value;
					if (IsDate(sControlValue)==false) {
						bIsValid=false;
						sWarnings+='The '+sNiceName+' must be a Valid Date|';
					}
				}

				//plopdown
				if (sControlPrefix=='ddl' || sControlPrefix=='add' || sControlPrefix=='sdd') {

					iValue=SafeInt(oControl.options[oControl.selectedIndex].value);
					sValue=oControl.options[oControl.selectedIndex].text;

					//not empty
					if (sValidation.indexOf('NotEmpty')>-1 && 						
							((iValue==0 && sControlPrefix=='ddl' && sValue=='') ||
							(iValue==0 && sControlPrefix!='ddl'))) {
						bIsValid=false;
						sWarnings+='The '+sNiceName+' must be specified|';
					}
				}
				
				//set control valid class
				SetControlValidClass(oControl,bIsValid);

				//if it's the first warning then set the focus control
				if (sWarnings!='' && sFocusControl=='') {
					sFocusControl=sControlID;
				}
			}
		}
	}

	//postback if all's ok or show warnings instead
	if (sWarnings.length==0) {			
		ButtonPostBack(oButton);
	} else {
		ShowInfoBox(sWarnings,sFocusControl);	
	}	
}	

function SetControlValidClass(oControl,bIsValid) {	
	if (bIsValid==true) {
		oControl.className=oControl.className.replace('error','');
	} else {
		oControl.className=oControl.className+' error';
	}
}

function IsEmail(sEmail) {
     var sEmailRegEx = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var o = new RegExp(sEmailRegEx);
     return o.test(sEmail);
}

function IsURL(sURL) {
	var sURLRegEx=/(ht|f)tp(s?)\:\/\/[a-zA-Z0-9\-\._]+(\.[a-zA-Z0-9\-\._]+){2,}(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?/;
	var o=new RegExp(sURLRegEx);
	return o.test(sURL);
}

function IsDate(sDate) {
	var nonDigit = /\D/g;
	var displaydateformat=/^[0-3][0-9]\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(19|20)\d\d$/;
	var now=new Date();
	var dDate;
	var iDay;
	var sMonth;
	var iYear;

	//bomb out if no characters
	if (sDate.length==0) return false;			

	//display date
	if (displaydateformat.test(sDate)) {
		
		//test for max days
		iDay=parseInt(sDate.substring(0,2));
		sMonth=sDate.substring(3,6);
		iYear=parseInt(sDate.substring(7,11));				
		if (iDay<=31 && (sMonth=='Jan' || sMonth=='Mar' || sMonth=='May' || sMonth=='Jul' 
					|| sMonth=='Aug' || sMonth=='Oct' || sMonth=='Dec')) {
			return true;
		} else if (iDay<=30 && (sMonth=='Apr' || sMonth=='Jun' || sMonth=='Sep' || sMonth=='Nov')) {
			return true;
		} else if (sMonth=='Feb' && ((iDay<=29 && CheckLeapYear(iYear)==true)
						|| (iDay<=28 && CheckLeapYear(iYear)==false))) {
			return true;
		} else {
			return false;
		}
		
	} else {
		return false;
	}

}

function HideInfoBox(e){
	var Key='';				
		
	if (document.layers) 
		Key=''+ e.which ;
	else 
		Key = window.event.keyCode;
			
	//if info box is displayed + Key is the return key
	if (iOpacity>0 && Key==13 || Key==27) {
		CloseInfoBox();
		Key=0;
		return false;
	}	
}

function CloseInfoBox(){
	var DivRef = document.getElementById('divInfobox');
	var oMask = document.getElementById('infomask');			
	
	//hide frame mask
	oMask.style.display="none";
	
	DivRef.style.display="none";
	iOpacity=100;

	//set focus control if necessary
	var oHidden=document.getElementById('FocusControl');
	if (oHidden!=null) {
		if (oHidden.value!='') {
			SetFocus(oHidden.value);
		}
	}
}



function ShowInfoBox(sWarnings, sFocusControl){

	//get the ul
	var oInfoBox=document.getElementById('divInfoBox');
	var ulInfoBox=document.getElementById('ulInfoItems');
	var oMask=document.getElementById('infomask');
	var oLi;				
	
	//chop off the last manpipe
	sWarnings=sWarnings.substring(0,sWarnings.length-1);				
	
	//remove any client ones (don't want to add them twice)
	for (iLoop=ulInfoBox.childNodes.length;iLoop>0;iLoop=iLoop-1) {
		oLi=ulInfoBox.childNodes[iLoop-1];
		ulInfoBox.removeChild(oLi);
	}
	
	//add any client warnings
	var aWarnings=sWarnings.split('|');
	for (iLoop=0;iLoop<aWarnings.length;iLoop++) {
			oLi=document.createElement("li");
			oLi.innerText=aWarnings[iLoop];
			ulInfoBox.appendChild(oLi);
	}			
	
	//make sure it's all on display
	oInfoBox.style.display='block';
	oMask.style.display='block';
	oInfoBox.className='warning';		
	
	var oHidden=document.getElementById('FocusControl');
	if (oHidden!=null && sFocusControl!=undefined) {
		oHidden.value=sFocusControl;	
	}

}


function ValidateAddAddress() {
    var sWarn = '';
    var oName = document.getElementById('txtName');
    var sName = oName.value
    var oEmail = document.getElementById('txtEmail');
    var sEmail = oEmail.value;
   
    if (sName == '') {
        sWarn += 'A Contact Name must be specified.\n';
        oName.className = 'text error';
    } else {
        oName.className = 'text';
    }

    if (sEmail == '' || IsEmail(sEmail) == false) {
        sWarn += 'A Valid Email Address must be specified.\n';
        oEmail.className = 'text error';
    } else {
        oEmail.className = 'text';
    }


    if (sWarn == '') {
        Postback('Email', 0);
    } else {
        alert(sWarn);
    }
}


function ValidateContactDetails() {

	var sWarn='';
	var oName=document.getElementById('txtContactName');
	var sName=oName.value
	var oEmail=document.getElementById('txtEmail');
	var sEmail=oEmail.value;
	var oSubject=document.getElementById('txtSubject');
	var sSubject=oSubject.value;
	var oComments=document.getElementById('txtComments');
	var sComments=oComments.value;
	
	if (sName=='') {
		sWarn+='A Contact Name must be specified.\n';
		oName.className='textbox error';
	} else {
		oName.className='textbox';
	}
	
	if (sEmail==''||IsEmail(sEmail)==false) {
		sWarn+='A Valid Email Address must be specified.\n';
		oEmail.className='textbox error';
	} else {
		oEmail.className='textbox';
	}
	
	
	if (sSubject=='') {
		sWarn+='A Subject must be specified.\n';
		oSubject.className='textbox error';
	} else {
		oSubject.className='textbox';
	}
	
	if (sComments=='') {
		sWarn+='A Message must be specified.\n';
		oComments.className='textbox error';
	} else {
		oComments.className='textbox';
	}
	
	if (sWarn=='') {
		Postback('Email',0);
	} else {
		alert(sWarn);
	}

}




