function submitonEnter(evt, frm){
	if (window.event) { //IE
		var charCode = event.keyCode;
	} else {
		var charCode = evt.which;
	}
	if(charCode == '13'){
		document.forms[frm].submit();
	}
}

function searchonEnter(evt, frm){
	if (window.event) { //IE
		var charCode = event.keyCode;
	} else {
		var charCode = evt.which;
	}
	if(charCode == '13'){
		doSearchRefined();
	}
}

function chkDelete(tbl, id, ref) {
	if (confirm("Are you sure you want to delete this record?")) { 
		self.location.href = 'dbdeleterecord.php?tbl=' + tbl + '&id=' + id + '&ref=' + ref;
	}	
}
function checkEmailAddress(field){
	var x = field.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)){
		return(true);
	} else {
		alert('Incorrect email address format');
		field.focus();
		return(false);
	}
}
function validateText(field, descField) {
	if (field.value == "") {
		alert ("Please complete the " + descField + " field.")
		field.focus();
		return (false);
	}
	return (true)
}

function validateSingleChkbox(field, descField) {
	if (!field.checked) {
		alert ("Please complete the " + descField + ".")
		field.focus();
		return (false);
	}
	return (true)
}

function validateChkbox(field, descField) {
	var valid
	valid = false
	for (i = 0; i < field.length; i++) {
		if (field[i].checked){
			valid = true
		}
	}
	if (!valid) {
		alert ("Please complete the " + descField + ".")
		field[0].focus();
		return (false);
	}
	return (true)
}

function validateCombo(field, descField) {
	with(field) {
		if (options[selectedIndex].text == "") {
		alert ("Please complete the " + descField + " field.")
		field.focus();
		return (false);
		}
		return (true)
	}
}

function validateNumber(field, descField) {
	with(field) {
		var re = /,/g 
		var tmpNum = field.value.replace(re,"")
		tmpNum = tmpNum.replace('$', "")
		tmpNum = parseFloat(tmpNum)
		if (Number(tmpNum) != tmpNum) {
			alert ("Please enter a valid number for the " + descField + " field.");
			field.focus();
			return (false);
		}
		return (true)
	}
}

function isFloat(s,allowCommas) { 
        var result; 
        var re = /,/g 
        if(typeof(allowCommas)=='undefined') { var allowCommas = false; } 
        
        if (allowCommas) { 
                result = s != "" && parseFloat(s.replace(re,"")) == s.replace(re,""); 
        } 
        else { 
                result = s != "" && parseFloat(s) == s; 
        } 
        return result;         
} 


//Pop up window functions
function openWindow (url, strWidth, strHeight) {
	//Get the screen size
//	if (document.all) {
//	   w = document.body.clientWidth;
//	   h = document.body.clientHeight;
//	}
//	else if (document.layers) {
//	   w = window.innerWidth;
//	   h = window.innerHeight;
//	}
	//Calc the centre position
	w = 1024;
	h = 768;
	var topPos = (h-strHeight)/2, leftPos = (w-strWidth)/2;
	//Create the window
     popWindow = window.open ( url,'popWindow', 'width=' + strWidth + ',height=' + strHeight + 'top=' + topPos + ',left=' + leftPos + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1')
     popWindow.focus();
}

function openWindowMenu (url, strWidth, strHeight) {
	//Get the screen size
//	if (document.all) {
//	   w = document.body.clientWidth;
//	   h = document.body.clientHeight;
//	}
//	else if (document.layers) {
//	   w = window.innerWidth;
//	   h = window.innerHeight;
//	}
	//Calc the centre position
	w = 1024;
	h = 768;
	var topPos = (h-strHeight)/2, leftPos = (w-strWidth)/2;
	//Create the window
     popWindow = window.open ( url,'popWindow', 'width=' + strWidth + ',height=' + strHeight + 'top=' + topPos + ',left=' + leftPos + ',toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1')
     popWindow.focus();
}

function showProcessing() {
	processing.style.visibility = "visible";
}
function hideProcessing() {
	processing.style.visibility = "hidden";
}


function isValidObject(objToTest) {
	if (null == objToTest) {
		return false;
	}
	if ("undefined" == typeof(objToTest) ) {
		return false;
	}
	return true;
}

//@Left equivalents
function strLeft(sourceStr, keyStr){
return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : sourceStr.split(keyStr)[0];
}
function nLeft(str, n){
if (n <= 0)     // Invalid bound, return blank string
	return "";
else if (n > String(str).length)   // Invalid bound, return
	return str;  // entire string
else // Valid bound, return appropriate substring
	return String(str).substring(0,n);
}

//@Right equivalents
function strRight(sourceStr, keyStr){
idx = sourceStr.indexOf(keyStr);
return (idx == -1 | keyStr=='') ? '' : sourceStr.substr(idx+ keyStr.length);
}
function nRight(str, n){
if (n <= 0)     // Invalid bound, return blank string
	return "";
else if (n > String(str).length)   // Invalid bound, return
	return str;  // entire string
else { // Valid bound, return appropriate substring
	var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);}
}

//@RightBack equivalent
function rightBack(sourceStr, keyStr){
arr = sourceStr.split(keyStr);
return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : arr.pop()
}

//@LeftBack equivalent
function leftBack(sourceStr, keyStr){
arr = sourceStr.split(keyStr)
arr.pop();
return (keyStr==null | keyStr=='') ? '' : arr.join(keyStr)
}

//@Middle equivalent
function middle(sourceStr, keyStrLeft, keyStrRight){ 
return strLeft(strRight(sourceStr,keyStrLeft), keyStrRight);
} 

function dialogAddressLookup(fieldName) {
	//Get the screen size
	if (document.all) {
	   w = document.body.clientWidth;
	   h = document.body.clientHeight;
	}
	else if (document.layers) {
	   w = window.innerWidth;
	   h = window.innerHeight;
	}
	//Calc the centre position
	var strWidth=250;
	var strHeight=430;
	var topPos = (h-strHeight)/2, leftPos = (w-strWidth)/2;
	var pathname;
	var url;
	pathname = (window.location.pathname);
	url=pathname.substring(0,(pathname.lastIndexOf('.nsf')+5))+'screenAddressBook?OpenForm&rf=' + fieldName
	window.open(url ,'Address', 'status=yes, resizable=no,scrollbars=no,top=' + topPos + ',left=' + leftPos + ',width=' + strWidth + ',height=' + strHeight);
}

function rowHighlight(objectThis, strClass) {
	objectThis.className=strClass
}
