<!--
var debugIt = false;

var userContinue = '0'

var flagLoaded = new String('0')
var aLocation =  new String(' ')

var aHash =  ' '
var startPage = '0';

var okToEmpty = 2;

var myUtil;
var myStatus;
var mySys;
var edit_error = '';

var mWndo = null;

function onerror(msg, url, linenum) {
	alert(msg)
}
function itsLoaded() {
	if (!navigator) {
		return;
	}
	flagLoaded.value = '0';
	userContinue = '0';
	myUtil = new utilityObj();
	mySys = new systemObj();
	mySys.compID = thisID;
	myStatus = new statusObj(statusMsg);
	
	var wName = mySys.compID;
	wName = wName.replace('-', '');
	window.name = wName;

	aLocation.value = parent.location.href;
	okToEmpty = 2
	loadALink('stats.php?res=' + mySys.res + '&bs=' + mySys.browserString + '&sp=' + mySys.startPage, 'stats', 'replace');
	loadFrames();
}
function loadFrames() {
	if (flagLoaded.value != '1') {
		setTimeout('loadFrames()', 200);
		return;
	}	
	if (gotoDetail > ' ') {
		loadDetail(gotoDetail, 'replace');
	}
	else
	if (gotoStartPage && gotoStartPage > ' ') {
		loadALink(unescape(gotoStartPage), 'mainf', 'replace');
	}
	else
	if (gotoURL && gotoURL > ' ') {
		loadALink(unescape(gotoURL), 'mainf', 'replace');
	}
	else {	
		loadALink(defaultPage, 'mainf', 'replace');
	}
}
function unloadIt() {
	mWndo = closeWindow(mWndo);
}	
function goBack(aframe) {
	if (!aframe || aframe.toLowerCase() == 'mainf') {
		var l = escape(mainf.location.href);
		loadALink('*back.php?u='+l, 'mainf', 'replace');
	}
	else {
		var f = getFrame(aframe);
		if (f && f != null) {
			f.history.go(-1);
		}
	}			
}	
function clearFormr() {
	if (okToEmpty != 0) {
		setTimeout('clearFormr()', 5);
		return;
	}
	if (formr && formr.wID && formr.wID.toLowerCase() == 'empty') {
		okToEmpty = 2;
		return;
	}	
	formr.location.replace('emptyf.htm');
	tfCtr = 0;
	testFormr();
}
var tfCtr;
function testFormr() {
	if (okToEmpty != 1) {
		tfCtr++;
		if (tfCtr > 6000) {
			okToEmpty = 2;
		}
		else {			
			setTimeout('testFormr()', 5);
		}
		return;
	}
	if (saf == true || opera == true) {
		okToEmpty = 2;
	}
	else {		
		formr.history.go(-1);
	}
}
var lalHRef, lalLocation, lalMode, lalEmpty;
function loadALink(newHRef, newLocation, newMode, newEmpty) {
	if (newEmpty) {
		if (newEmpty == 'wait' && okToEmpty != 2) {
			lalHRef = newHRef;
			lalLocation = newLocation;
			lalMode = newMode;
			lalEmpty = newEmpty;
			setTimeout('loadALink(lalHRef, lalLocation, lalMode, lalEmpty)', 5);
			return;
		}
	}
	var thisHref = newHRef;
	var useBase = false;
	if (thisHref.substring(0, 1) == '*' && thisHref != '*back') {
		thisHref = thisHref.substring(1);
		useBase = true;
	}	
	var amode;
	if (!newMode) {
		amode = 'add';
	}
	else 
	if (newMode.toLowerCase() == '*back') {
		goBack(newLocation);
		return;
	}
	else
	if (newMode.toLowerCase() == 'add' || newMode.toLowerCase() == 'forceadd' || newMode.toLowerCase() == 'replace') {
		amode = newMode.toLowerCase();
	}
	else {
		amode = 'add';
	}
	var thislocation = newLocation.toLowerCase();
	if (thislocation == 'new') {
		window.open(setHref(thisHref, useBase) ,'' ,'');
		return;
	}
	if (thislocation == 'parent') {
		top.location.replace(setHref(thisHref, useBase));
		return;
	}

	var abase
	var newFrame = getFrame(thislocation)
	if (newFrame == null) {
		return;
	}	
	var hash = newHRef.indexOf("#");
	if (hash > 0) {
		abase = newHRef.substring(0, hash);
	}
	else {
		abase = newHRef;
	}
	var hash = newHRef.indexOf("?");
	if (hash > 0) {
		abase = newHRef.substring(0, hash);
	}
	else {
		abase = newHRef;
	}
	if (thisHref == '*back') {
		newFrame.history.back();
	}
	else
	if (amode == 'forceadd' || (newFrame.location.href.indexOf(abase) < 0 && amode == 'add')) {
//		alert('adding ' + setHref(thisHref, useBase) + ' to ' + newFrame.name);	
		newFrame.location.href = setHref(thisHref, useBase);
	}
	else {
//		alert('replacing ' + setHref(thisHref, useBase) + ' to ' + newFrame.name);	
		newFrame.location.replace(setHref(thisHref, useBase));
	}
	if (window.mWndo && window.mWndo.close && !mWndo.closed) {
		mWndo.focus();
	}
	else
	if (newFrame.name == 'mainf') {
		newFrame.focus();
	}
}
function setHref(href, base) {
	var newhref;
	if (base == true) {
		newhref = mySys.baseAddress + href;
	}
	else {
		newhref = href;
	}
	return newhref;
}

function gotoPage(pagename) {
	loadALink('*' + pagename, 'mainf', 'add');
}
function loadList(how) {
	if (how && how == 'specials') {
	}
	else
	if (how && how == 'all') {
	}
	else {
		how = 'search';
	}
	setSearchString(how);
	var ahref = 'list.php'+searchString;
	loadALink(ahref, 'mainf', 'forceadd');
}
function loadDetail(sid) {
	var ahref = '*detail.php?id=' + sid;	
	loadALink(ahref, 'mainf', 'add');
}
function loadContact() {
	var rid = '0';
	if (whatScreen() == 'detail') {
		rid = mainf.recid;
	}
	var ahref = '*contact.php?id=' + rid;	
	loadALink(ahref, 'mainf', 'add');
}
function loadStats() {
	if (window.stats.stopTimer) {
		stats.stopTimer();
	}	
	var aHref = '*stats.php';
	loadALink(aHref, 'stats', 'replace');
}
function show_error(how) {
	if (window.mainf.showError && edit_error > ' ') {
		if (how == 'onscreen') {
			mainf.showErrorOnScreen();
		}
		else {
			mainf.showError();
		}
	}
}
function refreshScreen(noTest) {
}
function whatScreen() {
	if (mainf && mainf.wID) {
		return mainf.wID.toLowerCase();
	}
	return '';		
}
function WOP_goBack() {
	if (window.mWndo && mWndo.wID && mWndo.wID != 'invoice') {
		mWndo = closeWindow(mWndo);
	}	
	if (window.parent && window.parent.mainf && window.parent.goBack) {
		parent.goBack('mainf');
	}
	else
	if (window.mainf) {
		goBack('mainf');
	}
}		
function openWindow (wObj, name, ahref, opts) {
	wObj = closeWindow(wObj);
	if (wObj && wObj.close && !wObj.closed) {
		return null;
	}	
		
	if (opts && opts > ' ') {
		wObj = window.open(ahref, name, opts);
	}
	else {
		wObj = window.open(ahref, name);
	}
	if (!wObj || !wObj.close || !wObj.location) {
		wObj = null;
	}
	return wObj;
}
function closeWindow(wObj) {
	if (wObj && wObj.close && !wObj.closed) {
		wObj.close();
	}
	if (wObj && wObj.close && !wObj.closed) {
		return wObj;
	}
	else {	
		return null;
	}
}
function isWindowOpen(wObj) {
	if (wObj && wObj.close && wObj.location && !wObj.closed) {
		return true;
	}
	else {
		return false;
	}	
}
//
// form field functions
//
function getElement(theForm, field) {
	var theElement;
	for (i=0; i < theForm.elements.length; i++) {
		theElement = theForm.elements[i];
		if (theElement.name.toLowerCase() == field.toLowerCase()) {
			return theElement;
		}
	}
	return null;
}
function testField(theForm, field, err, index, alias) {
	edit = true;
	if (index == null) {
		index = 0;
	}	
	var theElement = getElement(theForm, field);
	if (theElement != null) {
		if (theElement.type && theElement.type.indexOf('select') >= 0) {
			if (theElement.selectedIndex < index) {
				edit = false;
				if (err && err == 'show') {
					showError(theElement, alias);
				}
			}
			else {
				if (trimIt(theElement[theElement.selectedIndex].value) <= ' ') { 
					theElement[theElement.selectedIndex].value = theElement[theElement.selectedIndex].text; 
				}
			}
		}	
		else {
			theElement.value = trimIt(theElement.value);				
			if (theElement.value <= ' ') {
				edit = false;
				if (index != -1) {
					if (err && err == 'show') {
						showError(theElement, alias);
					}
				}
			}	
		}
	}
	return edit;
}
function showError(theElement, alias) {
	var n = '';
	if (alias && trimIt(alias) > ' ') {
		n = alias;
	}
	else {
		n = theElement.name;
	}	 
	alert(n + ' is a required piece of information!\n\nWe can NOT process this Request without it.');
	selectField(theElement);  
}
function gotoField(theForm, field) {
	var theElement = getElement(theForm, field);
	if (theElement != null) {
		selectField(theElement);  
	}
}
function selectField(theElement) {
	theElement.focus();
	if (theElement.type) {
		if (theElement.type == 'text') {
			theElement.select();
		}
	}		
}
function trimIt(s) {
	return s.replace(/\s+$/,'');
}
function setTextArea (mesg) {
	var aEnd = '%0D%0A';
	var re = /%3Cbr%3E/;
	var mesg = escape(unescape(mesg));
	var doit = true;
	var newM;
	while (doit) {
		newM = mesg.replace(re , aEnd);
		if (newM == mesg) {
			doit = false;
		}	
		else {
			mesg = newM;
		}		
	}

	return unescape(newM);
}

//-->
