var NS4;
var OldText;
var searchTimeout;
var timeout = 1000;
//document.onmousedown = cancelMenu;
window.onresize = resizeWin
if (navigator.appName == 'Netscape')
{
	NS4 = true;
} else {
	NS4 = false;
}
function doDocList(doc_page)
{
	var url = '';
	url = '/LIBRARY_ALL.ASP?doc_page=' + doc_page
	location.href = url
}
function resizeWin()
{
//	var cell1 = document.all('mainCell')
//	var cell2 = document.all('menuTbl')
//	var cell3 = document.all('newsFlash')
	
//	if (cell1 != null && cell2 != null && cell3 != null)
//	{
//		var visWidth = document.body.offsetWidth;
//		var totWidth = document.body.scrollWidth;
//		if ((totWidth + 20)!= visWidth)
//		{
//			visWidth = totWidth;
//		}
			
//		var menuWidth = getWidth(cell2)
//		cell3.style.width = menuWidth
//		var newsflashWidth = getWidth(cell3)
//		var setTo = visWidth - menuWidth;
//		var setTo = visWidth - menuWidth - newsflashWidth;
//	/	cell1.style.width = setTo
//	}
}
function SetCookie (name, value) 
{  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) +  ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");

}
function getCookieVal (offset) 
{  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}

	return null;

}

function shopping(item_id)
{
	var itemArray = new Array();
	var found = false;
	var str = new String();
	if (item_id != null)
	{
		str = GetCookie('SelItems');
		if (str != null)
		{
			itemArray = str.split(',')
			for (i=0;i<itemArray.length;i++)
			{
				if (itemArray[i] == item_id.name)
				{
					if (!item_id.checked)
					{
						itemArray[i] = '';
						found = true
					}
				}
			}	
		}
		if (!found)
		{
			if (item_id.checked)
			{
				itemArray[itemArray.length] = item_id.name
			}
		}
		str = '';
		for (i=0;i<itemArray.length;i++)
		{
			if (itemArray[i].length !=0)
			{
				str = str + itemArray[i];
				if (i != itemArray.length-1)
				{
					str = str + ','
				}
			}
		}
		
	
	
		if (item_id.checked)
		{
			SetCookie('SelItems',str);
		} else {
			SetCookie('SelItems',str);
		};
	}
}
function clearShopping()
{
	SetCookie('SelItems','')
//	SetCookie('1','1','01/01/1990');
}
function switchBack(id)
{
	var parentWin = window.opener;
	try
	{
		if (parentWin.name != null)
		{
			parentWin.location.href = '/LIBRARY_ALL_PIS.ASP?MENUID=' + id
		} 
	}catch(e){
			w = 550;
			h = 450;
			newwin = window.open('/LIBRARY_ALL_PIS.ASP?MENUID=' + id,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=1,titlebar=1,location=1,toolbar=1,status=1');
			newwin.focus();
	};
	window.close();	
}
function showPI(path)
{
	w = 550;
	h = 450;
	newwin = window.open(path,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=0,titlebar=0');
	newwin.focus();

	
}
function doCheck()
{
	w = 332;
	h = 350;
	newwin = window.open('','','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=0,titlebar=0');
	newwin.document.write('<font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#660099">');
	newwin.document.write(document.all('descriptionFld').value);
	newwin.document.write('</font>');

}
function doAdvEdit(fldName)
{
	w = 332;
	h = 350;
	newwin = window.open('/global/advancededit/advancededit.htm',fldName,'width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=0,titlebar=0');
//	newwin.document.advEdit.HTMLTEXT = document.all(fldName).value;
}
function cancelMenu()
{
	if (event.button == 2)
	{
		EL = event.srcElement;
		while (EL.tagName != 'BODY')
		{
			if (EL.tagName == 'A')
			{
				if (EL.href.length > 11)
				{
					if (EL.href.substr(0,11) == 'javascript:')
					{
						EL.click();
					}
				}
			}
			EL = EL.parentElement;
		}
	}
}




function goto(path)
{
	window.location.href = path
}

function showDesc(text)
{
	e = window.event;
	obj = document.all('descriptionLayer');
	if (obj != null) {
		obj.innerHTML = '<table border=0 CELLSPACING=0 CELLPADDING=2 BGCOLOR=#FFFFCC BORDERcolor=#000000><tr><td nowrap><FONT face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">' + text + '</font></td></tr></table>';
		obj.style.left = getRealLeft(e.srcElement)
//		clientX + 10;
		obj.style.top = getRealTop(e.srcElement) + 15
//		e.clientY- 10;
		obj.style.visibility = 'visible';
	}
}
function checkLength(fld)
{
	if (fld.value.length == 0)
	{
		alert('You must enter a username');
	} else {
		document.security.submit()	
	}

}

function getRealLeft(imgElem) {
	xPos = 0;
	if (imgElem.id != 'image') {
		xPos = eval(imgElem).offsetLeft;
	}
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}
function getWidth(imgElem) {
	tempE1 = imgElem;
	if (tempE1.id == 'image') {
		tempE1 = tempE1.parentElement;
		tempE1 = tempE1.cells(0);
	}
	if (tempE1.style != null) 
	{
		xPos = tempE1.style.pixelWidth;
		if (xPos == 0) xPos = tempE1.clientWidth
			return xPos;
	}
}
function getRealTop(imgElem) {

	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function runDate(fld)
{
	if (window.event != null)
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	w = 332;
	h = 330;
	newwin = window.open('/global/scripts/date.asp',fld.name,'width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=0,scrollbars=0,menubar=0,titlebar=0');
	newwin.focus();

}
function popupWin(url)
{
	newwin = window.open(url,'','width=500,height=500,left=' + eval(screen.width/2 - 500 /2) + ',top=' + eval(screen.height/2 - 500/2) +  ',resizable=1,scrollbars=1,menubar=1,titlebar=1,toolbar=1,location=1' );
	newwin.focus();
}
function newsFlashPopup(id)
{
	w = 700;
	h = 300;
	newwin = window.open('/system/module/news/newsFlash.asp#' + id,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=1,status=1,titlebar=1,location=1,toolbar=1');
	newwin.focus();
}
function newsItemPopup(catid,id)
{
	w = 700;
	h = 300;
	newwin = window.open('/system/module/news/newsListing.asp?NEWS_ID=' + catid +'#' + id,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=1,status=1,titlebar=1,location=1,toolbar=1');
	newwin.focus();
}
function newsPopup(id)
{
	w = 700;
	h = 300;
	newwin = window.open('/system/module/news/newsListing.asp?NEWS_ID=' + id,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=1,status=1,titlebar=1,location=1,toolbar=1');
	newwin.focus();
}
function faqPopup(id)
{
	w = 550;
	h = 300;
	newwin = window.open('/system/module/FAQ/FAQListing.asp?FAQ_ID=' + id,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=1,status=1,titlebar=1,location=1,toolbar=1');
	newwin.focus();
}
function docsPopup(id)
{
	w = 700;
	h = 300;
	newwin = window.open('/system/module/document/USER_DOC_LISTING.ASP?DOCCAT_ID=' + id,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=1,status=1,titlebar=1,location=1,toolbar=1');
	newwin.focus();
}
function staffMembersPopup(id)
{
	w = 550;
	h = 300;
	newwin = window.open('/system/module/staff/staff_listing.asp?id=' + id,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=1,status=1,titlebar=1,location=1,toolbar=1');
	newwin.focus();
}
function hideDesc()
{
	obj = document.all('descriptionLayer');
	if (obj != null) {
		obj.innerHTML = '';
		obj.style.visibility = 'hidden';
	}
}
function swapImage(imgObj,imgFilename)
{
	if (NS4) 
	{
		document.images[imgObj].src = imgFilename;
	} else {
		document.all(imgObj).src = imgFilename;
	}
}
function parentBackOneAndClose()
{
	var win = window.opener;
	if (win != null)
	{
		win.history.back(-1);
	}
	close()
}
function refreshParent()
{
	var str=window.opener.location.href 
	window.opener.location.href = str;
	window.close()
}
function refreshParentKeepOpen()
{
	var str=window.opener.location.href 
	window.opener.location.href = str;
}
function sendToLogon()
{
	var win1;
	var win2;
	var win3;
	var win4;
	var win1 = window.opener;
	if (win1 != null)
	{
		var win2 = win1.opener;
	} else {
		window.location.href = '/SYSTEM/MODULE/SECURITY/DEFAULT.ASP';
		return false
	}

	if (win2 != null)
	{
		var win3 = win2.opener;
	}
	if (win3 != null)
	{
		var win4 = win3.opener;
	}
	if (win4 != null)
	{
		win4.location.href = '/SYSTEM/MODULE/SECURITY/DEFAULT.ASP';
		win3.close();
		win2.close();
		win1.close();
		window.close();
	}
	if (win3 != null)
	{
		win3.location.href = '/SYSTEM/MODULE/SECURITY/DEFAULT.ASP';
		win2.close();
		win1.close();
		window.close();
	}
	if (win2 != null)
	{
		win2.location.href = '/SYSTEM/MODULE/SECURITY/DEFAULT.ASP';
		win1.close();
		window.close();
	}
	if (win1 != null)
	{
		win1.location.href = '/SYSTEM/MODULE/SECURITY/DEFAULT.ASP';
		window.close();
	}
}
function refreshParentsParent()
{
	var str=window.opener.location.href 
	window.opener.location.href = str;
	if (window.opener.opener != null)
	{
		var str=window.opener.opener.location.href 
		window.opener.opener.location.href = str;
	}

	window.close()
}
function refreshParentsParentClose()
{
	var str=window.opener.location.href 
	window.opener.location.href = str;
	if (window.opener.opener != null)
	{
		var str=window.opener.opener.location.href 
		window.opener.opener.location.href = str;
		window.opener.close();
	}

	window.close()
}
function refreshMainandClose(winNameToKeepOpen)
{
	var str;
	var win = window;
	while (win.name != winNameToKeepOpen)
	{
		win = win.opener;
	}
	if ( win != null) 
	{
		str = win.location.href;
		win.location.href = str;
		win = win.opener;
		while (win != null)
		{
		
			str = win.location.href;
			win.location.href = win.location.href;
			win = win.opener;
		}
	}
	window.close();
}
function sendOpenerTo(url)
{
	window.opener.location.href = url;
	window.close()
}
function NoSpaces(t)
{
	if (NS4) 
	{
		Key = window.e.which
	} else {
		Key = window.event.keyCode
	}

	if (Key < 48 || Key > 57)
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
}
function dontAllowSpecialChars()
{
	if (NS4) 
	{
		Key = window.e.which
	} else {
		Key = window.event.keyCode
	}
	if (Key == 123 || Key == 125)
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
}
function cancelInput()
{
	if (NS4) 
	{
		Key = window.e.which
	} else {
		Key = window.event.keyCode
	}
	window.event.cancelBubble = true;
	window.event.returnValue = false;
}
function charsNotAllowed()
{
	if (NS4) 
	{
		Key = window.e.which
	} else {
		Key = window.event.keyCode
	}

//	if (Key == 39)
//	{
//		window.event.cancelBubble = true;
//		window.event.returnValue = false;
//	}
}

function NoSpace()
{
	if (NS4) 
	{
		Key = window.e.which
	} else {
		Key = window.event.keyCode
	}

	if (Key == 32)
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
}
function maxichar(cha,num)
{
	if (cha.value.length > num-1)
	{
		alert('Field cannot be longer than ' + num + ' characters');
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return false;
	}
}
function isValidDate(dateStr) 
{
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables

	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})	\2(\d{2}|\d{4})$/;

	// To require a 4 digit year entry, use this line instead:

	 var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); 
	// is the format ok?
	if (matchArray == null) 
	{
		alert("Date is not in a valid format.")
		return false;
	}
	month = matchArray[3]; 
	// parse date into variables
	day = matchArray[1];
	year = matchArray[4];

	if (month < 1 || month > 12) 
	{ 
		//check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) 
	{
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month "+month+" doesn't have 31 days!")
		return false
	}
	if (month == 2) 
	{ 
		// check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
		}
	}
	return true;  // date is valid
}
function moneyOnly()
{
	if (NS4) 
	{
		Key = window.e.which
	} else {
		Key = window.event.keyCode
	}
	if (Key == 13)
	{
		return false;
	}
	if (Key != 46)
	{
		if (Key < 48 || Key > 57)
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
	}
}
function numberOnly()
{
	if (NS4) 
	{
		Key = window.e.which
	} else {
		Key = window.event.keyCode
	}
	if (Key == 13)
	{
		return false;
	}
	if (Key < 48 || Key > 57)
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}
function money(t) {
	num = t.value;
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	if(cents < 10) cents = "0" + cents;
//	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
//	num = num.substring(0,num.length-(4*i+3)) + num.substring(num.length-(4*i+3));
	t.value = num + '.' + cents;
}
function numberVal(t) {
	num = t.value;
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	if(cents < 10) cents = "0" + cents;
//	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
//	num = num.substring(0,num.length-(4*i+3)) + num.substring(num.length-(4*i+3));
	t.value = num
}

function fix_string(text)
{
	var str1
	var str2
	str1 = '';
	str2 = '';
	for (i = 0; i < text.length;i++)
	{
		str1 = text.substr(i,1);
		if (str1 == '&')
		{
			str2 = str2 + '^';
		} else {
			if (str1 == '#')
			{
				str2 = str2 + '~';
			} else {
				if (str1 == '%')
				{
					str2 = str2 + '¬';
				} else {
					str2 = str2 + str1;
				}
			}
		}
	}
	return str2;
}
// LOCATOR MODULE FUNCTION
function doLocatorNopopup(fld,order_by,page)
{
	w = 450;
	h = 450;
	if (fld.value.length > 0)
	{	
		var str = fix_string(fld.value)
		location.href = '/system/module/locator/results.asp?SRCH=' + str + '&order_by=' + order_by + '&page=' + page
	}
}
function doLocator(fld)
{
	w = 800;
	h = 450;
	if (fld.value.length > 0)
	{	
		var str = fix_string(fld.value)
		newwin = window.open('/system/module/locator/results.asp?SRCH=' + str +'&order_by=1','','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) + ',resizable=1,scrollbars=1,menubar=1,toolbar=1,titlebar=1,location=1,status=1');
	}
}
function doUserLocator(fld)
{
	w = 800;
	h = 450;
	if (fld.length > 0)
	{	
		var str = fix_string(fld)
		newwin = window.open('/system/module/locator/results.asp?SRCH=' + str +'&order_by=1','','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) + ',resizable=1,scrollbars=1,menubar=1,toolbar=1,titlebar=1,location=1,status=1');
	}
}
function cancelLocatorTimeOut()
{
	clearTimeout(searchTimeout);
}
function showLocator()
{
	clearTimeout(searchTimeout);
	var e = window.event;
	var lay = document.all('locatorL')
	lay.style.top = getRealTop(e.srcElement) - 94
	lay.style.left = getRealLeft(e.srcElement) + 50
	lay.style.visibility = 'visible';
	document.all('scrhText').focus()
}
function hideLocator()
{
	searchTimeout = setTimeout("doHideLocator()",timeout);
	
}
function doHideLocator()
{
	searchTimeout = setTimeout("doHideSaerch()",timeout);
	clearTimeout(searchTimeout);
	var lay = document.all('locatorL')
	lay.style.visibility = 'hidden';
	
}
function submitIfEnter(obj)
{
	Key = window.event.keyCode
	if (Key == 13)
	{
		obj.click();
	}
}

function setSearchRecs(num)
{
	var ExpDate = new Date(2010,1,1);
	SetCookie('SrchrecsPerPage',num,ExpDate);
	doWorking()
	location.href = location.href;
}
function setSearchRecsLatestAddtions(num,days,menuid)
{
	var ExpDate = new Date(2010,1,1);
	SetCookie('SrchrecsPerPage',num,ExpDate);
	doLatestAdditions(1,days,menuid);
}
function setLocatorRecs(num)
{
	var ExpDate = new Date(2010,1,1);
	SetCookie('recPerPage',num,ExpDate);
	doWorking()
	location.href = location.href;
}
// STAFF MODULE FUNCTION
function staffDetails(ownerid)
{
	w = 400;
	h = 450;
	newwin = window.open('/system/module/staff/admin/staff_listing.asp?OWNERID=' + ownerid,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) + ',resizable=1,scrollbars=1,menubar=1,toolbar=1,titlebar=1,location=1,status=1');
}
function documentLog(id,cat)
{
	w = 1;
	h = 1;
	window.open('/system/module/document/log.asp?id=' + id + '&cat=' + cat,'','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 ) + ',top=' + eval(screen.height/2 ) + ',resizable=0,scrollbars=0,menubar=0,toolbar=0,titlebar=0,location=0,status=0');
}

function showStaffDetails(staff_number)
{	
	w = 550;
	h = 375;
	newwin = window.open('/system/module/staff/PersonDetails.asp?staff_number=' + staff_number,'StaffDetails','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=1,scrollbars=1,menubar=0,status=0,titlebar=0');
	newwin.focus();
}
function confirmBox(str) 
{ 
	return confirm(str + '\n\nClick \'OK\' to proceed or \'Cancel\' to cancel the operation.') 
} 
function doWorking()
{
//	w = 200;
//	h = 200;
//	newwin = window.open('/GLOBAL/INCLUDE/WAITING.HTM','','width=' + w + ',height=' + h + ',left=' + eval(screen.width/2 - w /2) + ',top=' + eval(screen.height/2 - h /2) +  ',resizable=0,scrollbars=0,menubar=0,status=0,titlebar=0');
//	newwin.focus();
}