var bPageIsDirty = false;

	function ShowCal(oText){
		oText.dateField = oText.value
		alert(oText.dateField)
		calendar = window.open('include/calendar.asp','cal')
		document.all("cal").style.display = ''
		//var arr = showModalDialog("include/calendar.htm",oText.value,"status:no; help:no; edge:sunken; scroll:no; dialogWidth:266px; dialogHeight:227px");
		
		//if (arr != null) {
		//	oText.value = arr
		//} 
	}

	function FormatDateForSave(sDate){
		var oDate = new Date(sDate)
		if(isNaN(oDate)){
			return false
		}
		else{
			nDay	= oDate.getDate()
			nMonth	= oDate.getMonth()+1
			nYear	= oDate.getYear()
			nHour	= oDate.getHours()
			nMin	= oDate.getMinutes()
			nSec	= oDate.getSeconds()
			
			sDate = nMonth+'/'+nDay+'/'+nYear+' '+nHour+':'+nMin+':'+nSec
			return(sDate)
			
		}
	}
	
	function SearchList(oList,sSearchType,QueryString,bDoChange){

		if (QueryString){
			var sQueryString = QueryString
		}
		else{
			var sQueryString = ''
		}
		
		var arr = showModalDialog("SearchListFrame.asp?"+sQueryString+"SearchType="+sSearchType,"","status:no; help:no; edge:sunken; scroll:no; dialogWidth:570px; dialogHeight:430px");
		//window.open("SearchListFrame.asp?"+sQueryString+"SearchType="+sSearchType,"","status=no help=no; edge=sunken; scroll=no Width=570 Height=430")
		//return
		
		if (arr != null) {
			nID = arr[0]
			sText = arr[1]
			if (document.all(oList).options(nID)){
			}
			else{
				var temp = document.all(oList);
				temp.options[temp.options.length] = new Option(sText,nID)
				temp.options[temp.options.length-1].id = nID
				temp.options[temp.options.length-1].name = nID
				temp.options[temp.options.length-1].value = nID
			}
			document.all(oList).options(nID).selected = true
			if(bDoChange)document.all(oList).onchange()
		} 
	}
	
	function PickTime(oObj){
		if(document.all(oObj)){
			var arr = showModalDialog("PickTime.asp?sTime="+document.all(oObj).value,"","status:no; help:no; edge:sunken; scroll:no; dialogWidth:175px; dialogHeight:120px");
			//window.open("PickTime.asp?sTime="+document.all(oObj).value,"","status:no, help:no, edge:sunken, scroll:auto, height=100,width=175");
		}

		if (arr != null) {
			document.all(oObj).value = arr
		} 
	}
	


	function ShowHideButtons(bShowHide){
		switch(bShowHide){
			case true:
				if(document.all("ButtonFooter"))document.all("ButtonFooter").style.display = 'none'
				if(document.all("ButtonFooterHeight"))document.all("ButtonFooterHeight").style.height = 0
				if(document.all("TBLSearch")){
					var nHeight = parseInt(document.all("TBLSearch").height)
					nHeight += 30
					document.all("TBLSearch").height = nHeight
				}
			break
			case false:
				if(document.all("ButtonFooter"))document.all("ButtonFooter").style.display = ''
				if(document.all("ButtonFooterHeight"))document.all("ButtonFooterHeight").style.height = 20
				if(document.all("TBLSearch")){
					var nHeight = parseInt(document.all("TBLSearch").height)
					nHeight -= 30
					document.all("TBLSearch").height = nHeight
				}
			break
		}
	}

	function addtolist(oList,sValue,sText){
		var oOption = document.createElement("OPTION");
		oOption.text=sText;
		oOption.value=sValue;
		eval('document.all.'+oList.id+'.add(oOption)');

	}
	function RemoveFromlist(nindex,oList){
		if (nindex > -1)	document.all(oList.id).remove(nindex)
	}

	function ManageListBoxex(nCommand,nSelIndex,oListFrom,oListTo){

			switch (nCommand){
				case 1:
					if (nSelIndex > -1){
						var sValue = document.all(oListFrom.id).options(nSelIndex).value
						var sText = document.all(oListFrom.id).options(nSelIndex).text
						addtolist(oListTo,sValue,sText)
						RemoveFromlist(nSelIndex,oListFrom)
					}
				break
				case 2:
					var nListLength = oListFrom.length
					for (iSelIndex = 0; iSelIndex < nListLength; iSelIndex++) {
						var sValue = document.all(oListFrom.id).options(0).value
						var sText = document.all(oListFrom.id).options(0).text
						addtolist(oListTo,sValue,sText)
						RemoveFromlist(0,oListFrom)
					}
				break	
			}

	}

	function GetListKeys(sList,sChild){
		var sKeyString = ''
		if(sChild != ''){sChild = sChild+'.'}
		var oList = eval(sChild+'document.all("'+sList+'")')
		for (i=0; i<oList.options.length; i++) {
			sKeyString = sKeyString + oList.options(i).value + ","
		}
		sKeyString = sKeyString.substr(0,sKeyString.length-1)
		return sKeyString
	}
	
	function UnFormatPhoneNumber(sField){
		document.all(sField).value = ReplaceChar(document.all(sField).value, '-', '')
		document.all(sField).value = ReplaceChar(document.all(sField).value, ' ', '')
		document.all(sField).value = ReplaceChar(document.all(sField).value, ')', '')
		document.all(sField).value = ReplaceChar(document.all(sField).value, '(', '')

	}
	
	function FormatPhoneNumber(sField){
		UnFormatPhoneNumber(sField)
		var sFieldValue = new String(document.all(sField).value)
		if(sFieldValue.length == 10)
			document.all(sField).value = '(' + sFieldValue.substr(0,3) + ') ' + sFieldValue.substr(3,3) + '-' + sFieldValue.substr(6,4)
	}
	
	
	function window_beforeUnload()   {
		if (bPageIsDirty == true){
			event.returnValue = 'This action will discard the changes you have made.';
		}	
	}
	
	function MakeDirty(){
		bPageIsDirty = true
		if (document.all("NotesHeader")){
			var sCaption = document.all("NotesHeader").innerText
			if(sCaption.charAt(sCaption.length-1)=='*'){
			}else{
				document.all("NotesHeader").innerText = document.all("NotesHeader").innerText + '*'
			}
		}
	}

	function ltrim(sString){
		do{
		if (sString.charAt(0) == ' ') sString = sString.substr(1)
		}
		while (sString.charAt(0) == ' ')
		return sString
	}
		
	function rtrim(sString){
		do{
		if (sString.charAt(sString.length-1) == ' ') sString = sString.substr(0,sString.length-1)
		}
		while (sString.charAt(sString.length-1) == ' ')
		return sString
	}
		
	function trim(sString){
		sString = rtrim(sString)
		sString = ltrim(sString)
		return sString
	}
	
	function CheckSave(sDesc){
		var bSaveit
		if (bPageIsDirty == true){
			bSaveit = window.confirm("Discard changes to " + sDesc + "?")
			return bSaveit;
		}else{
			return true;
		}	
	}
		
	function logoff(){
		if(confirm("Are you sure you want to logoff?")){
			parent.location="logoff.asp"
			window.close()
		}		
	}

	function checkDecimals(fieldName, fieldValue) {

		decimals = 2;  // how many decimals are allowed?

		if (isNaN(fieldValue)) {
			alert("That does not appear to be a valid dollar amount. Please enter only numbers.");
			fieldName.select();
			fieldName.focus();
		}
		else {
			timeshundred = parseFloat(fieldValue * Math.pow(10, decimals));
			integervalue = parseInt(parseFloat(fieldValue) * Math.pow(10, decimals));
		if (timeshundred != integervalue)
		{
			alert ("Please enter a number with up to " + decimals + " decimal places.");
			fieldName.select();
			fieldName.focus();
      }
		}
	}

	function checkDelete(sDeleteURL, sTarget){
		var bKillData = window.confirm("Are you sure you wish to delete this record?");
		if (bKillData == true){
			if (sTarget > ''){
				window.open(sDeleteURL, sTarget);	
			}else{
				window.open(sDeleteURL);	
			}
		}
	}	
	
	function checkRemoveAssoc(sDeleteURL, sTarget){
		var bKillData = window.confirm("Are you sure you wish to remove this association?");
		if (bKillData == true){
			if (sTarget > ''){
				window.open(sDeleteURL, sTarget);	
			}else{
				window.open(sDeleteURL);	
			}
		}
	}	
	
	var bValidRecord
	function ValidateField(strFieldValue, strMsg)	{
		if (strFieldValue == ""){
			if (bValidRecord){
				alert(strMsg)
				bValidRecord = false;
			}
		}
	}
	
	function ValidateRadio(oField, strMsg)	{

		var bChecked = false
		var nLength = oField.length

		for (iRadio = 0; iRadio < nLength; iRadio++) 
		{  
			if (oField(iRadio).checked){bChecked = true}
		}
		
		if (bChecked == false){
			if (bValidRecord){
				alert(strMsg)
				oField(0).focus()
				bValidRecord = false;
			}
		}
	}
	
function CheckKey(nValue, sType){
	if (sType == 'Numeric'){
		switch(nValue){
			case 48: return true; // 0 Key
			case 49: return true; // 1 Key
			case 50: return true; // 2 Key
			case 51: return true; // 3 Key
			case 52: return true; // 4 Key
			case 53: return true; // 5 Key
			case 54: return true; // 6 Key
			case 55: return true; // 7 Key
			case 56: return true; // 8 Key
			case 57: return true; // 9 Key
			case 9: return true; //tabkey
			case 10: return true; //enterkey
			case 13: return true; //enterkey 
		}
	}
	
	if (sType == 'Money'){
		
		switch(nValue){
			case 48: return true; // 0 Key
			case 49: return true; // 1 Key
			case 50: return true; // 2 Key
			case 51: return true; // 3 Key
			case 52: return true; // 4 Key
			case 53: return true; // 5 Key
			case 54: return true; // 6 Key
			case 55: return true; // 7 Key
			case 56: return true; // 8 Key
			case 57: return true; // 9 Key
			case 45: return true; // - Key
			case 46: return true; // . Key
			case 9: return true; //tabkey
			case 10: return true; //enterkey
			case 13: return true; //enterkey 
			
		}
	}
	
	if (sType == 'SSN'){
		switch(nValue){
			case 48: return true; // 0 Key
			case 49: return true; // 1 Key
			case 50: return true; // 2 Key
			case 51: return true; // 3 Key
			case 52: return true; // 4 Key
			case 53: return true; // 5 Key
			case 54: return true; // 6 Key
			case 55: return true; // 7 Key
			case 56: return true; // 8 Key
			case 57: return true; // 9 Key
			case 45: return true; // - Key
		}
	}
	
	if (sType == 'ZipCode'){
		switch(nValue){
			case 48: return true; // 0 Key
			case 49: return true; // 1 Key
			case 50: return true; // 2 Key
			case 51: return true; // 3 Key
			case 52: return true; // 4 Key
			case 53: return true; // 5 Key
			case 54: return true; // 6 Key
			case 55: return true; // 7 Key
			case 56: return true; // 8 Key
			case 57: return true; // 9 Key
			case 45: return true; // - Key
		}
	}
					return false;
					
}

	function StrSearch(sString, sFind)
	{
	  var s = sString
	  var r = new RegExp(sFind, "i");
	  n = s.search(r);
	  return(n);
	}

	function GetnumInString(sString, sReplace)
	{
	  var s = sString
	  var r = new RegExp(sReplace, "i");
	  r.compile(sReplace, "g");
	  var a =s.match(r);
	  return(a);
	}

	function NumToCurrency(nNum){
		var nNewNum = nNum
		nNewNum = nNewNum.toString()

		if (nNewNum.charAt(0) == '('){
			nNewNum = nNewNum.substring(1,nNewNum.length-1)
			nNewNum = '-' + nNewNum
		}
		nNewNum = Math.round(nNewNum * 100)
		nNewNum = nNewNum.toString()
		nNumDec = nNewNum.substring(nNewNum.length-2)
		nNewNum = nNewNum.substring(0, nNewNum.length-2)
		//nNewlen = (nNewNum.length/3)
		//nNewlen = nNewlen.toString()
		//nNewlen = nNewlen.substring(0, 1)
		//for (i = 0; i < nNewlen; i++) 
		//{  
		//	
		//}
		nFinalNum = nNewNum+'.'+nNumDec
		if (nFinalNum == '.0')nFinalNum= '0.00'
		return(nFinalNum)
	}
	
	function ReplaceStr(sString, sReplace, sReplaceWith){
	  var r, rm;
	  var s = sString;
	  r = GetnumInString(sString, sReplace)
	  if (r) {
		r = r.length
	  }else{
	    r = 0
	  }
		for (i = 0; i < r; i++) 
		{                        
		  s = s.replace(sReplace, sReplaceWith);             
		}
	  return(s);
	}
	
		function ReplaceChar(sString, sReplace, sReplaceWith){
	  var r, rm;
	  var s = sString;
    s = s.replace(sReplace, sReplaceWith);             
	  return(s);
	}




function show(){
	if (document.all||document.getElementById||document.layers){
		document.form1.t1.value=screen.width
		document.form1.t2.value=screen.height
		document.form1.t3.value=screen.colorDepth
		document.form1.t4.value=screen.pixelDepth
	}
}


	function SetFieldToNumber(objField){
		var nValue = document.all(objField).value
		nValue = ConvertToNumber(nValue)
		document.all(objField).value = nValue
	}
	
	function SetFieldToCurrency(objField){
		var nValue = document.all(objField).value
		nValue = CurrencyToNum(nValue)
		document.all(objField).value = nValue
	}
	
	
	function ConvertToNumber(nValue){

		var nValue = ReplaceStr(nValue,'$','')
		var nValue = ReplaceStr(nValue,',','')
			if (nValue.charAt(0) == '('){
				nValue = nValue.substring(1,nValue.length-3)
				nValue = '-' + nValue
			}
		return(nValue)
	}
	
	function CurrencyToNum(nNum){
		nNum = nNum.toString()

		if (StrSearch(nNum, '.') > 0){
			nNum = nNum + '.'
		}
		//nNum = nNum + '00'
		nNum = Math.round(nNum * 100)
		nNum = nNum / 100
		
		if(isNaN(nNum)){
			nNum = '0.00'
		}
		
		nNum = '$' + nNum

		return(nNum)
	}
	
	

