	function validDate(datectr,forceTF){
		datestr = datectr.value
		if (datestr.length > 0 | forceTF == true)
		{
			datearray = datestr.split("/");
			if (datearray.length != 3){
	
				alert("Invalid Date.\rUse / as a separator \re.g. dd/mm/yyyy");
				datectr.value = datectr.defaultValue;
				datectr.blur();
				datectr.focus();
				}
				else
				{
				day = parseInt(datearray[0],10);
				month = parseInt(datearray[1],10) - 1;
				year = parseInt(datearray[2],10);
				today = new Date(year,month,day);
				day = today.getDate();
				month = (today.getMonth() + 1);
				year = today.getFullYear();
				if (day < 10){
					day = "0" + day
					}
				if (month < 10){
					month = "0" + month
					}
				if (year < 1900){
					if (year < 50){
						year += 2000
					}else{
						year += 1900
					}
				}
				todaystr = day + "/";
				todaystr += month + "/";
				todaystr += year;
				datectr.value = todaystr;
				}
		}
	}
function checkNumeric(elementRef)
{
	tempVal = Number(elementRef.value);
	if (isNaN(tempVal) || elementRef.value == "") 
	{
		elementRef.value = "";
	} else {
		elementRef.value = tempVal;
	}
}
function checkPositiveNumeric(elementRef)
{
	tempVal = Number(elementRef.value);
	if (isNaN(tempVal) || elementRef.value == "") 
	{
		tempVal = 0;
	} else {
		//elementRef.value = tempVal;
	}
	elementRef.value = Math.abs(tempVal);
}
function checkInteger(elementRef)
{
	tempVal = parseInt(elementRef.value,10);
	if (isNaN(tempVal) || elementRef.value == "") 
	{
		elementRef.value = "";
	} else {
		elementRef.value = tempVal;
	}
}
function chgFocus(formRef)
{
	var elID=document.getElementById(formRef);
	elID.className="focussed";
} 
function chgBlur(formRef)
{
	//formRef.style.border = "1px solid black" 
	//formRef.style.background = "white" 
	var elID=document.getElementById(formRef);
	elID.className="";
} 

function highlightRow(objRef)
{
	objRef.style.defaultBackgroundColor = objRef.style.backgroundColor;
	objRef.style.backgroundColor = "#cccccc";
	return true;
}
function unHighlightRow(objRef)
{
	objRef.style.backgroundColor = "";
	objRef.style.backgroundColor = objRef.style.defaultBackgroundColor;
	return true;
}
function toggleShowDiv(itemID)
{
	if (itemID && document.getElementById(itemID))
	{
		var itemDiv = document.getElementById(itemID);
	        if (itemDiv.style.display=='none')
			{
				itemDiv.style.display='';
			} else {
				itemDiv.style.display='none';
			}
	}
}
window.onscroll=checkCentreDialog;
window.onresize=checkCentreDialog;
var dbDefaultSrc='/common/loading.asp';
var dbReturnFunc;
var dbReturnVal="";

function checkCentreDialog()
{
	if(document.getElementById("dialogDiv") && document.getElementById("dialogDiv").display!='none')
	{
		centreDialog();
	}
}

function openDialog(dbWidth,dbHeight,dbType,value1,value2)
{
	var dialogDiv = document.getElementById("dialogDiv");
	var dialogContentDiv = document.getElementById("dialogContentDiv");
	var dialogContentHTMLDiv = document.getElementById("dialogContentHTMLDiv");
	var dialogContentFrame = document.getElementById("popupFrame");
	var dialogContentTitleDiv = document.getElementById("dialogContentTitleDiv");

	if(!dbWidth || dbWidth < 50){ 
		dbWidth=500;
	}
	if(!dbHeight || dbWidth < 50){ 
		dbHeight=500;
	}
	// alert(document.body.scrollTop);
	dialogContentDiv.style.width = dbWidth + 'px';
	dialogContentDiv.style.height = dbHeight + 'px';
	// set height and width of content elements
	dialogContentHTMLDiv.style.width = dbWidth - 2 + 'px';
	dialogContentHTMLDiv.style.height = dbHeight - parseInt(dialogContentTitleDiv.style.height,10) - 2 + 'px';
	dialogContentFrame.style.width = dbWidth - 20 + 'px';
	dialogContentFrame.style.height = dbHeight - parseInt(dialogContentTitleDiv.style.height,10) - 30 + 'px';
	centreDialog();
	dialogDiv.style.display='';
	dialogContentFrame.src = dbDefaultSrc;
	if(dbType.toLowerCase()=="url")
	{
		dialogContentHTMLDiv.style.display='none';
		dialogContentFrame.style.display='';
		dialogContentFrame.src = value1;
		dbReturnFunc = value2;
	}
	if(dbType.toLowerCase()=="html")
	{
		dialogContentHTMLDiv.style.display='';
		dialogContentFrame.style.display='none';
		dialogContentHTMLDiv.innerHTML = value1;
		dbReturnFunc = value2;
	}
}
function centreDialog()
{
	if(document.getElementById("dialogDiv"))
	{
		var dialogDiv = document.getElementById("dialogDiv");
		var dialogContentDiv = document.getElementById("dialogContentDiv");
		//opera Netscape 6 Netscape 4x Mozilla 
		if (window.innerWidth || window.innerHeight){ 
			docwidth = window.innerWidth; 
			docheight = window.innerHeight; 
		} 
		//IE Mozilla 
		if (document.body.clientWidth || document.body.clientHeight){ 
			docwidth = document.body.clientWidth; 
			docheight = document.body.clientHeight; 
		}
		docScrollHeight = document.body.scrollHeight;
		if(docScrollHeight < parseInt(document.documentElement.scrollHeight,10))
		{
			docScrollHeight = parseInt(document.documentElement.scrollHeight,10);		
		} 	
		docScrollTop = document.body.scrollTop || document.documentElement.scrollTop;
		dialogDiv.style.width = "100%";
		dialogDiv.style.height = parseInt(docScrollHeight,10) + 'px';
		var dialogDivLeft = (docwidth/2) - (parseInt(dialogContentDiv.style.width,10)/2);
		if (dialogDivLeft < 0){
			dialogDivLeft = 1
		}
		dialogContentDiv.style.left = dialogDivLeft + 'px';
		var dialogDivTop = dialogContentDiv.style.top = docScrollTop + ((docheight*.8)/2) - (parseInt(dialogContentDiv.style.height,10)/2);
		if (dialogDivTop < 0){
			dialogDivTop = 1
		}
		dialogContentDiv.style.top = dialogDivTop + 'px';
	}
}
function closeDialog(returnValue)
{
	document.getElementById("popupFrame").src = dbDefaultSrc;
	var dialogDiv = document.getElementById("dialogDiv");
	dbReturnVal = returnValue;
	if(returnValue!=null && dbReturnFunc!=null){
		//alert(dbReturnFunc+":"+returnValue)
		window.setTimeout(dbReturnFunc, 1)
	}
	dialogDiv.style.width = 0;
	dialogDiv.style.height = 0;
	dialogDiv.style.display='none';
}

function Trim(str) {
  return str.replace(/^\s*/, "").replace(/\s*$/, "");
}


