//----------------------------------------//
// Javascript for employer/employee/tpa pages //
//----------------------------------------//

var hideMenuArray = new Array();

function goNav(navurl) {
    location.href = navurl;
}

function mouseOverNav(obj, dirname) {
    obj.style.color='#000000';
	obj.style.cursor = 'hand';
	window.status = dirname;
	return true;
}

function mouseOutNav(obj) {
    obj.style.color='#666666';
	window.status = '';
	return true;
}

function getContent(textInput) {
  content = new Object();
  if (document.selection) {
    var selectedRange = document.selection.createRange();
    if (selectedRange.parentElement() == textInput) {
      content.isSelected = true;
      content.selected = selectedRange.duplicate();
    }
    else {
      content.isSelected = false;
    }
  }
  else {
    content = null;
  }
  return content;
}

function formatContent(content,openTag,closeTag) {
  if (content && content.isSelected) {
  	var c = content.selected.text;
    content.selected.text = openTag + c + closeTag;
  }
}
/*
function showDisplayedText(obj) {
	obj.textbox.value = obj.textbox.value.replace(/\r\s+?/g,"\r");
	obj.textbox.value = obj.textbox.value.replace(/\s+?\r/g,"\r");
	obj.textbox.value = obj.textbox.value.replace(/([^\b<\/h[1-6]>\b]|[^\b<\/ol>\b]|[^\b<\/ul>\b]|[^\b<\/li>\b]|[^\b<br>\b]|[^\b<\/blockquote>\b])\r/g,"$1<br>\r");
	obj.textbox.value = obj.textbox.value.replace(/(<\/h[1-6]>|<\/ol>|<\/ul>|<\/li>|<\/blockquote>)<br>/g,"$1");
	obj.textbox.value = obj.textbox.value.replace(/<br>(<\/h[1-6]>|<\/ol>|<\/ul>|<\/li>|<\/blockquote>)/g,"$1");
	obj.textbox.value = obj.textbox.value.replace(/&[^\bamp;\b]/g,"&amp; ");
	document.all.displayedtext.innerHTML = obj.textbox.value;
}
*/
function showDetail(obj) {
	obj.style.borderLeftColor = '#000000';
	obj.style.borderTopColor = '#000000';
	obj.style.borderBottomColor = '#DDDDDD';
	obj.style.borderRightColor = '#DDDDDD';
}

function restoreDetail(obj,tpakey,erkey,eekey,plankey,pmtnum,clmnums,totalpmt,pmttype) {
	obj.style.borderLeftColor = '#DDDDDD';
	obj.style.borderTopColor = '#DDDDDD';
	obj.style.borderBottomColor = '#000000';
	obj.style.borderRightColor = '#000000';
    var detailPage = 'reimdetail.asp?tpakey=' + tpakey + '&erkey=' + erkey + '&eekey=' + eekey + '&plankey=' + plankey + '&pmtnum=' + pmtnum + '&clmnums=' + clmnums + '&totalpmt=' + totalpmt + '&pmttype=' + pmttype;
    detailWin = window.open(detailPage, 'DetailWindow', 'toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes, width=740, height=200, top=50, left=50');
}

function restoreDetailLoS(obj,tpakey,erkey,eekey,plankey,pmtnum,clmnums,totalpmt,pmttype,lostype) {
	var detailPage;
	obj.style.borderLeftColor = '#DDDDDD';
	obj.style.borderTopColor = '#DDDDDD';
	obj.style.borderBottomColor = '#000000';
	obj.style.borderRightColor = '#000000';
	
	if (lostype == 106) {
	    detailPage = 'reimdetailhra.asp';
	} else {
		if (lostype == 0) {
		    detailPage = 'reimdetail.asp';
		} else {
		    detailPage = 'reimdetaillos.asp';
		}
	}
	detailPage = detailPage + '?tpakey=' + tpakey + '&erkey=' + erkey + '&eekey=' + eekey + '&plankey=' + plankey + '&pmtnum=' + pmtnum + '&clmnums=' + clmnums + '&totalpmt=' + totalpmt + '&pmttype=' + pmttype + '&lostype=' + lostype;
    detailWin = window.open(detailPage, 'DetailWindow', 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=740,height=200,top=50,left=50');
}

function restoreDetailCOBRA(obj,tpakey,erkey,eekey,bnkey) {
	obj.style.borderLeftColor = '#DDDDDD';
	obj.style.borderTopColor = '#DDDDDD';
	obj.style.borderBottomColor = '#000000';
	obj.style.borderRightColor = '#000000';
	
	var detailPage = 'cobradates.asp?tpakey=' + tpakey + '&erkey=' + erkey + '&eekey=' + eekey + '&bnkey=' + bnkey;
    detailWin = window.open(detailPage, 'DetailWindow', 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=500,height=300,top=50,left=50');
}

function restoreDetailHRA(obj,pcTPA,pnBN,pnER) {
	obj.style.borderLeftColor = '#DDDDDD';
	obj.style.borderTopColor = '#DDDDDD';
	obj.style.borderBottomColor = '#000000';
	obj.style.borderRightColor = '#000000';
	var lcLocation = 'inquiryHRA_bd.asp?tpa=' + pcTPA + '&bn=' + pnBN + '&er=' + pnER;
	window.open(lcLocation, 'hrabd', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
}

function restoreDetailLOSNew(obj,pykey,bnkey,pnLoS) {
	obj.style.borderLeftColor = '#DDDDDD';
	obj.style.borderTopColor = '#DDDDDD';
	obj.style.borderBottomColor = '#000000';
	obj.style.borderRightColor = '#000000';
	switch (pnLoS) {
		case 106:
			document.location = 'inquiryHRAdetail.asp?pk=' + pykey + '#b' + bnkey;
			break;
		case 125:
			document.location = 'inquiry125detail.asp?pk=' + pykey + '#b' + bnkey;
			break;
		case 132:
			document.location = 'inquiry132detail.asp?pk=' + pykey + '#b' + bnkey;
			break;
	}
}


function goEEBalance(passed_op_key,passed_tpakey,passed_erkey,passed_plan_key) {
	document.status.op_key.value = passed_op_key;
	document.status.tpakey.value = passed_tpakey;
	document.status.erkey.value = passed_erkey;
	document.status.plan_key.value = passed_plan_key;
	document.status.submit();
}

function goEEBalanceLoS(passed_op_key) {
	document.status.op_key.value = passed_op_key;
	document.status.submit();
}

function goEEHistory(passed_op_key,passed_tpakey,passed_erkey,passed_plan_key,passed_eekey) {
	document.balance.op_key.value = passed_op_key;
	document.balance.tpakey.value = passed_tpakey;
	document.balance.erkey.value = passed_erkey;
	document.balance.plan_key.value = passed_plan_key;
	document.balance.eekey.value = passed_eekey;
	document.balance.submit();
}

function goEEHistoryLoS(passed_eekey) {
	document.balance.eekey.value = passed_eekey;
	document.balance.submit();
}

function goReimDateFilter() {
	var datefrom = document.payments.monthfrom.value + '-' + document.payments.dayfrom.value + '-' + document.payments.yearfrom.value;
	var dateto = document.payments.monthto.value + '-' + document.payments.dayto.value + '-' + document.payments.yearto.value;
	var pyeqs = document.payments.pye[document.payments.pye.selectedIndex].value;
	location.href = 'payments.asp?pye=' + pyeqs + '&df=' + datefrom + '&dt=' + dateto;
}

function goERBalance(doccls, tpakey, planyear) {
	document.status.op_doccls.value = doccls;
	document.status.tpakey.value = tpakey;
	document.status.planyear.value = planyear;
	document.status.submit();	
}

function goERBalanceNew(tpakey, erkey, planyear, opkey) {
	document.status.tpakey.value = tpakey;
	document.status.client.value = erkey;
	document.status.planyear.value = planyear;
	document.status.option.value = opkey;
	document.status.submit();	
}


function goEEBalanceTPA(passed_op_doccls,passed_op_key,passed_tpakey,passed_erkey,passed_plan_key) {
	document.status.op_doccls.value = passed_op_doccls;
	document.status.op_key.value = passed_op_key;
	document.status.tpakey.value = passed_tpakey;
	document.status.erkey.value = passed_erkey;
	document.status.plan_key.value = passed_plan_key;
	document.status.submit();
}

function goEEHistoryTPA(passed_op_doccls,passed_op_key,passed_tpakey,passed_erkey,passed_plan_key,passed_eekey) {
	document.balance.op_doccls.value = passed_op_doccls;
	document.balance.op_key.value = passed_op_key;
	document.balance.tpakey.value = passed_tpakey;
	document.balance.erkey.value = passed_erkey;
	document.balance.plan_key.value = passed_plan_key;
	document.balance.eekey.value = passed_eekey;
	document.balance.submit();
}

function goEEHistoryTPANew(passed_op_key,passed_tpakey,passed_erkey,passed_plan_key,passed_eekey) {
	document.balance.op_key.value = passed_op_key;
	document.balance.tpakey.value = passed_tpakey;
	document.balance.erkey.value = passed_erkey;
	document.balance.planyear.value = passed_plan_key;
	document.balance.eekey.value = passed_eekey;
	document.balance.submit();
}


function goTPAStatus(passed_op_doccls,passed_tpakey,passed_planyear) {
	document.status.op_doccls.value = passed_op_doccls;
	document.status.tpakey.value = passed_tpakey;
	document.status.planyear.value = passed_planyear;
	document.status.submit();
}

function goProcessReturn(returnID) {
	document.achreturn.returnID.value = returnID;
	document.achreturn.submit();
}

function goTPAViewER(xprid,xpid,xrid,clientid) {
	if (clientid != -1) {
		document.clientlist.prid.value = xprid;
		document.clientlist.pid.value = xpid;
		document.clientlist.rid.value = xrid;
		document.clientlist.eid.value = clientid;
		document.clientlist.submit();
	}
}

function checkOptionsSelected(obj) {
	var numOpts = obj.options.length;
	for (x = 0; x < numOpts; x++) {
		if (obj.options[x].value == -1 && obj.options[x].selected == true) {
			for (y = x + 1; y < numOpts; y++) {
				if (obj.options[y].value == -1) {
					break;
				} else {
					obj.options[y].selected = true;
				}
			obj.options[x].selected = false;
			}
		}
	}
}

function showLogo(logoFile) {
    logoPage = 'viewlogo.asp?img=' + logoFile;
    logoWin = window.open(logoPage, 'LogoWindow', 'toolbar=no, menubar=no, location=no, scrollbars=auto, resizable=yes, width=320, height=320');
}

function verifyClientContactList() {
	var d = document.contacts.clientid;
	if (d.value == -1) {
		alert('You must select a client first. Please try again.');
		return false;
	} else {
		return true;
	}
}

function checkTPAContactSelect() {
	var d = document.tpacontacts.contactid;
	if (d[d.selectedIndex].value == -1) {
		alert('You must select a contact.');
		return false;
	} else {
		return true;
	}
}

function validateEESearch(obj) {
	if (obj.lastname.value.length < 1 && (obj.ssn1.value.length < 3 || obj.ssn2.value.length < 2 || obj.ssn3.value.length < 4)) {
		alert('You must enter the full SSN or a last name.');
		return false;
	} else {
		return true;
	}
}

function validatePartEESearch(obj) {
	if (obj.lastname.value.length < 1 && obj.ssn1.value.length < 2) {
		alert('You must enter part of a SSN (At least first 2 digits) or last name.');
		return false;
	} else {
		var llOK = true;
		if (obj.ssn1.value.length < 3 && (obj.ssn2.value.length > 0 || obj.ssn3.value.length > 0))
			llOK = false;
		if (obj.ssn1.value.length = 3 && obj.ssn2.value.length < 2 && obj.ssn3.value.length > 0)
			llOK = false;
		if (!llOK)
			alert('You must enter a valid/partly SSN or last name.');
			
		return llOK;
	}
}

function goShowBankAccounts(EntityID,EntityGroup) {
	document.bankacct.EntityID.value = EntityID;
	document.bankacct.EntityGroup.value = EntityGroup;
	document.bankacct.submit();
}

function goShowBankAccountDetail(acctID) {
	document.acctinfo.acctid.value = acctID;
	document.acctinfo.submit();
}

function goShowEmployerDetail(EntityID) {
	document.employer.EntityID.value = EntityID;
	document.employer.submit();
}

function goUpdateEmployerInfo(EntityID) {
	document.employer.entityid.value = EntityID;
	document.employer.submit();
}

function goShowEmployees(EntityID,SortOrder) {
	document.employees.EntityID.value = EntityID;
	document.employees.SortOrder.value = SortOrder;
	document.employees.submit();
}

function goShowEFTTransactionDetail(EFTTransID) {
	document.EFTTransaction.EFTTransID.value = EFTTransID;
	document.EFTTransaction.submit()
}

function checksAllLoSL(pcForm, pcChkName, pcLOSL) {
	var lcID, loObj;
		
	loObj = 'document.' + pcForm + '.' + pcChkName;
	loObj = eval(loObj);
	
	for (var x = 0; x < loObj.length; x++) {
		lcID = loObj[x].id;
		if (lcID.indexOf(pcLOSL) > -1) {
			loObj[x].checked = true;
		}
	}
}

function EFTHoldTransaction() {
	if (confirm("Do you wish to hold the transaction?")) {
		document.HoldTransaction.submit()
	}
}

function EFTClearTransaction() {
	if (confirm("Do you wish to process the transaction?")) {
		document.ClearTransaction.submit()
	}
}

function deleteEmpInfoTPASearch(pnEiid,pcEntityName,pcName, pnPID, pcRole) {
	if (confirm('Are you sure you want to unassign "'+pcName+'" as '+pcRole+' for ' + pcEntityName + '?') == true) {
		location.href = 'removehr.asp?delete=' + pnEiid + '&pid=' + pnPID;
		return true;
	} else {
		return false;
	}
}

function getNextIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
	return index;
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
	return found;
}

function autoTabInput(input, len, e) {
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);

	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		if (input.form[(getNextIndex(input)+1) % input.form.length].type == 'text') 
			input.form[(getNextIndex(input)+1) % input.form.length].select();
		input.form[(getNextIndex(input)+1) % input.form.length].focus();
	}
	return true;
}

function autoFillYear(poObj) {
	var lnYear = poObj.value;
	
	if (!isNaN(lnYear)) {
		if (lnYear < 100 && lnYear > 0) {
			poObj.value = Math.round(lnYear) + 2000;
		}
	}
	return true;
}

function isDate(pnYear, pnMonth, pnDay) {
	var ldDate = new Date(pnYear, pnMonth-1, pnDay);
	
	return (ldDate.getFullYear() == pnYear && (pnDay > 0 && pnDay < 32) && ldDate.getMonth()+1 == pnMonth);
}

function goShowMinBalHistory(AcctID, EntityID, EntityGroup) {
	document.MinBalHistory.AcctID.value = AcctID ;
	document.MinBalHistory.EntityID.value = EntityID ;
	document.MinBalHistory.EntityGroup.value = EntityGroup ;
	document.MinBalHistory.submit();
}

function goShowEditMinimumBalance(AcctID, BalanceID) {
	document.EditMinBal.AcctID.value = AcctID ;
	document.EditMinBal.BalanceID.value = BalanceID ;
	document.EditMinBal.submit();
}

function ValidMinBal(numEnter, numDefault) {
	numEnter = numEnter.toString().replace(/\$|\,/g, '');
	if	(isNaN(numEnter)) {
		alert("Please enter a valid minimum balance amount.")
		numEnter = numDefault.toString().replace(/\$|\,/g,'');
	}
	numEnter = Math.floor(numEnter*100+0.50000000001) ;
	cents = numEnter % 100 ;
	numEnter = Math.floor(numEnter/100).toString() ;
	if (cents < 10) {
		cents = "0" + cents;
	}
	for (var i = 0; i < Math.floor((numEnter.length-(1+i))/3); i++)
	numEnter = numEnter.substring(0,numEnter.length-(4*i+3))+','+
	numEnter.substring(numEnter.length-(4*i+3));

	return (numEnter + '.' + cents);
}

function addTPAClient() {
	alert('Still under construction');
	return true;
}

function checkTPAClient(obj) {
	var llOK = true;
	var lcTest = obj.clienttaxid.value;

	if (obj.clientname.value == '') {
		alert('Please specify a name for the client');
		llOK = false;
	}
	if (llOK && obj.clienttaxid.value == '') {
		alert('Please specify a Tax ID for the client');
		llOK = false;
	}

	if (llOK) {	
		
		if (lcTest.length != 10)
			llOK = false;
		
		if (llOK && isNaN(lcTest.substring(0, 2)))
			llOK = false;
	
		if (llOK && lcTest.substring(2, 3) != '-')
			llOK = false;
		
		if (llOK && isNaN(lcTest.substring(3)))
			llOK = false;
			
		if (!llOK)
			alert('Please specify a valid Tax ID [99-9999999]');
	}
	return llOK;
}

function checkEmploymentHRAdd(obj) {
	if (obj.eid.value == '-1') {
		alert('You must select an employer.')
		return false;
	} else {
		return true;
	}
}

function selectFSAaggregatereport(obj) {
// page: /tpa/services/aggregatefsa(_new).asp
// does: Display "select plan year" for selected client
// made: by Erik on 01/28/2002
	var lnCnt, lcYears, lcValue, lcPrompt;
	
	obj.planyear.style.visibility = 'hidden';
	if (document.all.item("reporttable") != undefined)
		document.all.item("reporttable").style.visibility = 'hidden';

	for (lnCnt = obj.planyear.options.length; lnCnt >= 0; lnCnt--)
			obj.planyear.options[lnCnt] = null;
	
	lcYears = obj.client.value;
	if (lcYears != '-1') {
		lcYears = lcYears.substring(lcYears.indexOf("|")+1);
	
		obj.planyear.options[0] = new Option('-- Please select a plan year --');
		obj.planyear.options[0].value = -1;
	
		lnCnt = 0;
		while (lcYears.length > 0) {	
			lnCnt++;
			lcValue = lcYears.substring(0, lcYears.indexOf(","));
			lcYears = lcYears.substring(lcYears.indexOf(",")+1);
			lcPrompt = lcYears.substring(0, lcYears.indexOf("|"));
			lcYears = lcYears.substring(lcYears.indexOf("|")+1);
			
			obj.planyear.options[lnCnt] = new Option(lcPrompt);
			obj.planyear.options[lnCnt].value = lcValue;
		}
		obj.planyear.style.visibility = 'visible';
		obj.planyear.focus();
	}
}


function showNavMenu(poItem, pcColor, pcFColor, pcOrgColor, pcOrgFColor) {
	hideNavMenu('menuBar', pcOrgColor, pcOrgFColor);
	
	for (var i=0; i < document.all.length; i++) {
		if (document.all[i].type != null) {
			var lcType = document.all[i].type;
			if (lcType.indexOf("select-") >= 0) {
				if (document.all[i].style.visibility != "hidden") {
					document.all[i].style.visibility = "hidden";
					hideMenuArray.push(i);
				}
			}
		}
	}

	var menu = eval(poItem.menu);
	var bar = eval(poItem.id);
	
	bar.style.backgroundColor = pcColor;
	bar.style.color = pcFColor;
	bar = eval(poItem.id + "_IMG_1");
	bar.style.backgroundColor = pcColor;
	bar.style.color = pcFColor;
	bar = eval(poItem.id + "_IMG_2");
	bar.style.backgroundColor = pcColor;
	bar.style.color = pcFColor;
	
	menu.style.visibility = "visible";
	menu.style.pixelTop = poItem.getBoundingClientRect().top + poItem.offsetHeight + document.body.scrollTop - 2;
	menu.style.pixelLeft = poItem.getBoundingClientRect().left + document.body.scrollLeft-2;
}

function hideNavMenu(poItem, pcOrgColor, pcOrgFColor) {
	for (var i=0; i < hideMenuArray.length; i++) {
		document.all[hideMenuArray[i]].style.visibility = "visible";
	}
	var tempAry = hideMenuArray.splice(0, hideMenuArray.length);
	
	if (document.all.item(poItem) != null) {
		var poMenu = document.all.item(poItem);
		if (poMenu.hasChildNodes() == true) {
			var child = poMenu.children;
			
			for (var j=0; j<child.length; j++) {
				child[j].style.color = pcOrgFColor;
				child[j].style.backgroundColor = pcOrgColor;
				if (child[j].menu != null) {
					var childMenu = eval(child[j].menu);
					childMenu.style.visibility = "hidden";			
				}

				if (child[j].hasChildNodes() == true) {
					var child2 = child[j].children;
					for (var i=0; i<child2.length; i++) {
						child2[i].style.color = pcOrgFColor;
						child2[i].style.backgroundColor = pcOrgColor;
					}
				}
			}		
		}
	}
}

function doNavMenu(poItem) {
	var cmd = poItem.cmd;
	if (cmd != null)
		location.href= cmd;
}

function highlightNavMenu(poItem, pcColor, pcFColor, pcOrgColor, pcOrgFColor) {
	var PElement = eval(poItem.parentElement.id);
	
	if (PElement.hasChildNodes() == true) {
		var Elements = PElement.children;
		for(var i=0;i<Elements.length;i++) {
			TE = eval(Elements[i].id);
			TE.style.color = pcOrgFColor;
			TE.style.backgroundColor = pcOrgColor;
		}
	}
	poItem.style.color = pcFColor;
	poItem.style.backgroundColor = pcColor;
}


function selectBillingStatement(obj) {
// page: /tpa/services/billing.asp
// does: Display "select statement end date" for selected year
// made: by Erik on 04/16/2002
	var lnCnt, lcDates, lcValue, lcPrompt;
	
	obj.statementdate.style.visibility = 'hidden';
	for (lnCnt = obj.statementdate.options.length; lnCnt >= 0; lnCnt--)
			obj.statementdate.options[lnCnt] = null;
	
	lcDates = obj.statementyear.value;
	lcDates = lcDates.substring(lcDates.indexOf("|")+1);
	
	obj.statementdate.options[0] = new Option(( lcDates.length > 0 ? '-- Select statement --' : '-- No statements found --'));
	obj.statementdate.options[0].value = -1;
	
	lnCnt = 0;
	while (lcDates.length > 0) {	
		lnCnt++;
		lcPrompt = lcDates.substring(0, lcDates.indexOf(","));
		lcDates = lcDates.substring(lcDates.indexOf(",")+1);
		lcValue = lcPrompt.substring(lcPrompt.indexOf("|")+1);
		lcPrompt = lcPrompt.substring(0, lcPrompt.indexOf("|"));
		
		obj.statementdate.options[lnCnt] = new Option(lcPrompt);
		obj.statementdate.options[lnCnt].value = lcValue + "|" + lcPrompt;
	}
	obj.statementdate.style.visibility = 'visible';
	obj.statementdate.focus();
}


function goShowEFTClearedReimbursementDetail(intReimburseLink) {
//	document.TransactionDetail.ReimburseLink.value = intReimburseLink;
	document.TransactionDetail.TransactionID.value = intReimburseLink;
	document.TransactionDetail.submit()
}


function expanderClick(poImg, poDiv, pcName) {
	var imgsrc = poImg.src;
	var llExpand = (poImg.src.indexOf('/plus.gif') >= 0  ? true : false);
	
	if (llExpand) {
		var i = 1;
		var lcDiv = pcName + '_' + i;
		var lcImg;
		
		do {
			lcImg = 'img'+lcDiv;
			document.all.item(lcImg).src = '/images/plus.gif';
			document.all.item(lcDiv).style.display = 'none';
			
			i++;
			lcDiv = pcName + '_' + i;
		} while (document.all.item(lcDiv) != null);		
	}

	poImg.src = '/images/' + (llExpand  ? 'minus.gif' : 'plus.gif');
	poDiv.style.display = (llExpand ? '' : 'none');
}

function emailCheck(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("E-mail address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	if (user.match(userPat)==null) {
	    alert("The e-mail address username doesn't seem to be valid.")
	    return false;
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("The e-mail address' destination IP address is invalid!");
			return false;
		    }
	    }
	    return true;
	}
	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		alert("The e-mail address' domain name doesn't seem to be valid.");
	    return false;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>4) {
	   alert("The e-mail address must end in a three or four-letter domain, or two letter country.");
	   return false;
	}
	if (len<2) {
	   var errStr="The e-mail address is missing a hostname!";
	   alert(errStr);
	   return false;
	}
	return true;
}


function checkNewPersonForm(obj) {
	if (obj.eid.value == -1) {
		alert('You must assign HR position to an employer.');
		return false;
	} else if (obj.firstname.value == '') {
		alert('You must enter a first name.')
		return false;
	} else if (obj.lastname.value == '') {
		alert('You must enter a last name.')
		return false;
	} else if (obj.ssn.value == '') {
		alert('You must enter a Social Security number.')
		return false;
	} else if (obj.ssn.value.length != 9) {
		alert('You must enter a valid Social Security number. ')
		return false;
	} else if (obj.primaryemail.value.length > 0) {
		return emailCheck(obj.primaryemail.value);
	}
}

function goReimDateFilterSelectAll(){
	document.payments.monthfrom.value = -1;
	document.payments.dayfrom.value = -1;
	document.payments.yearfrom.value = -1;
	document.payments.monthto.value = -1;
	document.payments.dayto.value = -1;
	document.payments.yearto.value = -1;
	var datefrom = '';
	var dateto = '';
	var pyeqs = document.payments.pye[document.payments.pye.selectedIndex].value;
	
	location.href = 'payments.asp?pye=' + pyeqs + '&df=' + datefrom + '&dt=' + dateto;
}

function goUpdateDocSlot(DocumentSlotID) {
	document.updateslot.DocumentSlotID.value = DocumentSlotID;
	document.updateslot.submit() ;
}

function goUpdateDocLayout(DocumentLayoutID) {
	document.updatestoc.DocumentLayoutID.value = DocumentLayoutID;
	document.updatestoc.submit() ;
}


function enrollCheckValidNumber(poField, pnMin, pnMax) {
	var lnNum = poField.value;
	
	if (isNaN(lnNum) == true) {
		if (lnNum.length > 0) {
			alert('Please assign a valid amount or none at all.');
			poField.focus();
			poField.select();
		}
	} else {
		if (lnNum < 0) {
			alert('Please assign a positive amount or none at all.');
			poField.focus();
			poField.select();
		} else {
			if (lnNum > 0 && pnMin > 0 && lnNum < pnMin) {
				alert('Amount is below minimum allowed value.');
				poField.focus();
				poField.select();
			}
			if (lnNum > 0 && pnMax > 0 && lnNum > pnMax) {
				alert('Amount is above maximum allowed value.');
				poField.focus();
				poField.select();
			}
		}
	}
}

function ltrim(pcStr) {
	var lcTemp = pcStr;
	
	while (lcTemp.length > 0 && lcTemp.substr(0, 1) == ' ')
		lcTemp = lcTemp.substr(1);
	
	return lcTemp;
}

function rtrim(pcStr) {
	var lcTemp = pcStr;
	
	while (lcTemp.length > 0 && lcTemp.substr(lcTemp.length-1, 1) == ' ')
		lcTemp = lcTemp.substr(0, lcTemp.length-1);
	
	return lcTemp;
}

function alltrim(pcStr) {
	return rtrim(ltrim(pcStr));
}

// -------------------------------------------------------------

function checkCOBRAQE(poForm) {
	var llOK = true;

	if (poForm.qevent.value == -1) {
		alert('Please select an event before continuing.');
		llOK = false;
	} else {
		var lnYear = poForm.eventyear.value;
		
		if (!isNaN(lnYear)) {
			if (lnYear < 100 && lnYear > 0) {
				lnYear = Math.round(lnYear) + 2000;
			}
		}
		if (!isDate(lnYear, poForm.eventmonth.value, poForm.eventday.value)) {
			alert('Please enter a valid date.');
			llOK = false;
		}
	}
	
	if (llOK) {
		if (poForm.qevent.value == 100 || poForm.qevent.value == 104) {
			var lcEvent = poForm.qevent.options[poForm.qevent.selectedIndex].text;
			llOK = confirm('Are you sure you wish to perform this qualifying event?\n\r\n\r' + lcEvent);
		}
	}
	
	return llOK;
}


function doRemovalCheck(poChk, poForm) {
	var lnCnt;
	for (lnCnt = 0; lnCnt < poForm.elements.length; lnCnt++) {
		if (poForm.elements[lnCnt].type == 'checkbox') {
			if (poForm.elements[lnCnt].pvalue == poChk.pvalue && poForm.elements[lnCnt] != poChk) {
				poForm.elements[lnCnt].checked = poChk.checked;
			}
		}
	}
}

function checkACHFileDelete(fileid) {
	if (confirm('Are you sure you want to delete this file?') == true) {
		location.href = 'delete.asp?fileid=' + fileid;
		return true;
	} else {
		return false;
	}
}


function validatePasswordChange(obj) {
	var d = document.modifyaccount;
	if (d.newpassword.value == '') {
		alert('The password field cannot be blank. Please enter a password.');
		return false;
	} else if (d.newpassword.value != d.confirmpassword.value) {
		alert('The passwords do not match. Please try again.');
		d.newpassword.value = '';
		d.confirmpassword.value = '';
		return false;
	} else {
		return true;
	}
}

//  ------------------------------------------------------------------------------------------
//  Functions for TPA Benefits - Carriers and Plans
//  ------------------------------------------------------------------------------------------

function showCarrierPlans(lnCarrier) {
	var loPlans = document.all.Carriers.lstPlans;
	for (lnCnt = loPlans.options.length; lnCnt >= 0; lnCnt--)
		loPlans.options[lnCnt] = null;

	if (eval('document.all.Carriers.carrierplans' + lnCarrier) != undefined) {
		var lcStr = eval('document.all.Carriers.carrierplans' + lnCarrier+'.value')
		var lnCnt, lcValue, lcPrompt;
	
		lnCnt = -1;
		while (lcStr.length > 12) {
			lnCnt++;
			lcStr = lcStr.substring(12);
			lcValue = lnCarrier + '_'+lcStr.substring(0, lcStr.indexOf("_"));
			lcStr = lcStr.substring(lcStr.indexOf("_")+1);
			lcPrompt = lcStr.substring(0, lcStr.indexOf("_CHIDDENPLAN"));
			lcStr = lcStr.substring(lcStr.indexOf("_CHIDDENPLAN"));
			
			loPlans.options[lnCnt] = new Option(lcPrompt);
			loPlans.options[lnCnt].value = lcValue;
		}
	}
}

var oCPPreviewWin = null;
function carrierPlansButton(pcButton) {
	var llReturn = true;
	var lcLocation = '';
	var lcCarrier = document.all.Carriers.lstCarriers.value;
	var lcPlan = document.all.Carriers.lstPlans.value;
	
	switch (pcButton) {
		case 'carrieradd':
			lcLocation = 'carriers.asp?add=yes';
			break;
		case 'carrieredit':
			lcLocation = 'carriers.asp?edit='+lcCarrier;
			llReturn = (lcCarrier != '');
			break;
		case 'carrierremove':
			lcLocation = 'carriers.asp?del='+lcCarrier;
			llReturn = (lcCarrier != '');
			if (llReturn)
				llReturn = confirm("Are you sure?");
			break;
		case 'carrierpreview':
			lcLocation = 'carrierplanspreview.asp?carrier='+lcCarrier;
			llReturn = false;
			if (lcCarrier != '') {
				if (oCPPreviewWin != null)
					oCPPreviewWin.close;
				oCPPreviewWin = window.open(lcLocation, 'planpreview', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
				oCPPreviewWin.focus();
			}
			break;
		case 'plansadd':
			lcLocation = 'carrierplans.asp?add='+lcCarrier;
			llReturn = (lcCarrier != '');
			break;
		case 'plansedit':
			lcLocation = 'carrierplans.asp?edit='+lcPlan;
			llReturn = (lcPlan != '' && lcCarrier != '');
			break;
		case 'plansremove':
			lcLocation = 'carrierplans.asp?del='+lcPlan;
			llReturn = (lcPlan != '' && lcCarrier != '');
			if (llReturn)
				llReturn = confirm("Are you sure?");
			break;
		case 'planpreview':
			lcLocation = 'carrierplanspreview.asp?plan='+lcPlan;
			llReturn = false;
			if (lcPlan != '') {
				if (oCPPreviewWin != null)
					oCPPreviewWin.close;
				oCPPreviewWin = window.open(lcLocation, 'planpreview', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
				oCPPreviewWin.focus();
			}
			break;
	}
	if (llReturn)
		document.location = lcLocation;

	return llReturn;
}

function previewSummaryPlan(pnCID, pnPID, pnGroup) {
	var lcPlan = pnCID + "_" + pnPID;
	var lcLocation = 'carrierplanspreview.asp?plan='+lcPlan + '&group=' + pnGroup;
	if (lcPlan != '') {
		if (oCPPreviewWin != null)
			oCPPreviewWin.close;
		oCPPreviewWin = window.open(lcLocation, 'planpreview', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
		oCPPreviewWin.focus();
	}
	return false;
}

function previewClientSummary(pnEID, pnBID, pnGroup) {
	var lcLocation = 'clientsummarypreview.asp?eid='+pnEID+'&bid='+pnBID+'&group='+pnGroup;
	if (oCPPreviewWin != null)
		oCPPreviewWin.close;
	oCPPreviewWin = window.open(lcLocation, 'summarypreview', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
	oCPPreviewWin.focus();
	return false;
}


function checkCarrierPlanEdit(poForm) {
	var llReturn = true;
	var lcTemp = alltrim(poForm.planname.value);
	
	if (lcTemp.length == 0) {
		alert('Please assign a name to the plan.');
		poForm.planname.focus();
		llReturn = false;
	}
	return llReturn;
}

function checkCarrierEdit(poForm) {
	var llReturn = true;
	var lcTemp = alltrim(poForm.cname.value);
	
	if (lcTemp.length == 0) {
		alert('Please assign a name to the carrier.');
		poForm.cname.focus();
		llReturn = false;
	}

	lcTemp = alltrim(poForm.cshortname.value);
	if (llReturn && lcTemp.length == 0) {
		alert('Please assign a short name to the carrier.');
		poForm.cshortname.focus();
		llReturn = false;
	}
	
	lcTemp = alltrim(poForm.email.value);
	if (llReturn && lcTemp.length > 0) {
		if (lcTemp.indexOf('@') < 0 || lcTemp.indexOf('.') < 0) {
			alert('Please assign a valid e-mail address.');
			poForm.email.focus();
			llReturn = false;
		}
	}
	
	lcTemp = alltrim(poForm.website.value);
	if (lcTemp.length > 0) {
		lcTemp = lcTemp.toLowerCase();
		if (lcTemp.substring(0, 4) != 'http') {
			lcTemp = 'http://' + lcTemp;
			poForm.website.value = lcTemp;
		}
	}
	
	return llReturn;
}

function checkBenefitResrcEdit(poForm) {
	var llReturn = true;

	lcTemp = alltrim(poForm.link.value);
	if (lcTemp.length > 0) {
		lcTemp = lcTemp.toLowerCase();
		if (lcTemp.substring(0, 4) != 'http') {
			lcTemp = 'http://' + lcTemp;
			poForm.link.value = lcTemp;
		}
	} else {
		llReturn = false;
		alert('Please enter a URL!');
		poForm.link.focus();
	}
	
	return llReturn;
}


function checkContactEdit(poForm) {
	var llReturn = true;
	var lcTemp = alltrim(poForm.about.value);
	
	if (lcTemp.length == 0) {
		alert('Please enter what the contact is about.\n\rFor example: Claims');
		poForm.about.focus();
		llReturn = false;
	}

	lcTemp = alltrim(poForm.email.value);
	if (llReturn && lcTemp.length > 0) {
		if (lcTemp.indexOf('@') < 0 || lcTemp.indexOf('.') < 0) {
			alert('Please assign a valid e-mail address.');
			poForm.email.focus();
			llReturn = false;
		}
	}

	lcTemp = alltrim(poForm.comment.value);
	if (llReturn && lcTemp.length > 300) {
		alert('Comment may max. be 300 characters.\n\rCurrent length: ' + lcTemp.length);
		poForm.comment.focus();
		llReturn = false;
	}	
	
	lcTemp = alltrim(poForm.web.value);
	if (lcTemp.length > 0) {
		lcTemp = lcTemp.toLowerCase();
		if (lcTemp.substring(0, 4) != 'http') {
			lcTemp = 'http://' + lcTemp;
			poForm.web.value = lcTemp;
		}
	}
	
	return llReturn;
}

function fillCarrierContact(poForm, pcFirst, pcLast, pcAddr1, pcAddr2, pcCity, pcState, pcZIP, pcProvince, pcCountry, pcPhone, pcFax, pcEmail, pcWeb) {
	var loTemp = poForm.firstname;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcFirst;
	loTemp = poForm.lastname;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcLast;
	loTemp = poForm.address1;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcAddr1;
	loTemp = poForm.address2;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcAddr2;
	loTemp = poForm.city;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcCity;
	loTemp = poForm.state;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcState;
	loTemp = poForm.zip;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcZIP;
	loTemp = poForm.province;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcProvince;
	loTemp = poForm.country;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcCountry;
	loTemp = poForm.phone;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcPhone;
	loTemp = poForm.fax;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcFax;
	loTemp = poForm.email;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcEmail;
	loTemp = poForm.web;
	if (alltrim(loTemp.value).length == 0)
		loTemp.value = pcWeb;
}



function componentOrder(poObj, plIsUp, pnGroup) {
	var lcASP = (pnGroup == 0 ? 'carrierplansummary.asp' : 'carriercontsummary.asp');
	if (poObj.summaries.value != '') {
		var lcLoc = lcASP + '?o=' + poObj.summaries.value + '&dir=' + (plIsUp ? 'u' : 'd');
		document.location = lcLoc;
	}
}

function clientComponentOrder(poObj, plIsUp, pnEID, pnBID, pnDID) {
	if (poObj.summaries.value != '') {
		var lcLoc = 'benefitsconfigure.asp?action=edit&did='+pnDID+'&eid='+pnEID+'&bid='+pnBID+'&o=' + poObj.summaries.value + '&dir=' + (plIsUp ? 'u' : 'd');
		document.location = lcLoc;
	}
}


function planSummaryButton(pcButton, pnPlanID) {
	var llReturn = true;
	var lcLocation = '';
	var lcSummary = document.all.summary.summaries.value;
	
	switch (pcButton) {
		case 'add':
			lcLocation = 'carrierplansummaryedit.asp?add=' + pnPlanID;
			break;
		case 'edit':
			lcLocation = 'carrierplansummaryedit.asp?edit='+lcSummary;
			llReturn = (lcSummary.substring(0,1) == 'C');
			break;
		case 'remove':
			lcLocation = 'carrierplansummaryedit.asp?del='+lcSummary;
			llReturn = (lcSummary.substring(0,1) == 'C');
			if (llReturn)
				llReturn = confirm("Are you sure?");
			break;
	}
	if (llReturn)
		document.location = lcLocation;

	return llReturn;
}

function contSummaryButton(pcButton, pnPlanID) {
	var llReturn = true;
	var lcLocation = '';
	var lcSummary = document.all.summary.summaries.value;
	
	switch (pcButton) {
		case 'add':
			lcLocation = 'carriercontsummaryedit.asp?add=' + pnPlanID;
			break;
		case 'edit':
			lcLocation = 'carriercontsummaryedit.asp?edit='+lcSummary;
			llReturn = (lcSummary.substring(0,1) == 'C');
			break;
		case 'remove':
			lcLocation = 'carriercontsummaryedit.asp?del='+lcSummary;
			llReturn = (lcSummary.substring(0,1) == 'C');
			if (llReturn)
				llReturn = confirm("Are you sure?");
			break;
	}
	if (llReturn)
		document.location = lcLocation;

	return llReturn;
}


function clientSummaryButton(pcButton, pnEID, pnBID, pnDID) {
	var llReturn = true;
	var lcLocation = '';
	var lcSummary = document.all.summary.summaries.value;
	
	switch (pcButton) {
		case 'add':
			lcLocation = 'clientsummaryedit.asp?add=0';
			break;
		case 'edit':
			lcLocation = 'clientsummaryedit.asp?edit='+lcSummary;
			llReturn = (lcSummary.substring(0,1) == 'C');
			break;
		case 'remove':
			lcLocation = 'clientsummaryedit.asp?del='+lcSummary;
			llReturn = (lcSummary.substring(0,1) == 'C');
			if (llReturn)
				llReturn = confirm("Are you sure?");
			break;
	}
	if (llReturn)
		document.location = lcLocation + '&eid='+pnEID+'&bid='+pnBID+'&did='+pnDID;

	return llReturn;
}

function clientContSummaryButton(pcButton, pnEID, pnBID, pnDID) {
	var llReturn = true;
	var lcLocation = '';
	var lcSummary = document.all.summary.summaries.value;
	
	switch (pcButton) {
		case 'add':
			lcLocation = 'clientcontsummaryedit.asp?add=0';
			break;
		case 'edit':
			lcLocation = 'clientcontsummaryedit.asp?edit='+lcSummary;
			llReturn = (lcSummary.substring(0,1) == 'C');
			break;
		case 'remove':
			lcLocation = 'clientcontsummaryedit.asp?del='+lcSummary;
			llReturn = (lcSummary.substring(0,1) == 'C');
			if (llReturn)
				llReturn = confirm("Are you sure?");
			break;
	}
	if (llReturn)
		document.location = lcLocation + '&eid='+pnEID+'&bid='+pnBID+'&did='+pnDID;

	return llReturn;
}

function clientBenefitFAQButton(pcButton, pnEID, pnBID, pnDID) {
	var llReturn = true;
	var lcLocation = '';
	var lcSummary = document.all.summary.summaries.value;
	
	switch (pcButton) {
		case 'add':
			lcLocation = 'clientfaqedit.asp?add=0';
			break;
		case 'edit':
			lcLocation = 'clientfaqedit.asp?edit='+lcSummary;
			llReturn = (lcSummary != '');
			break;
		case 'remove':
			lcLocation = 'clientfaqedit.asp?del='+lcSummary;
			llReturn = (lcSummary != '');
			if (llReturn)
				llReturn = confirm("Are you sure?");
			break;
		case 'pick':
			llReturn = false;
			lcLocation = 'clientfaqpicklist.asp?eid='+pnEID+'&bid='+pnBID+'&did='+pnDID;
			if (oCPPreviewWin != null)
				oCPPreviewWin.close;
			oCPPreviewWin = window.open(lcLocation, 'faqpicklist', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
			oCPPreviewWin.focus();
			break
		case 'preview':
			llReturn = false;
			lcLocation = 'clientfaqpreview.asp?eid='+pnEID+'&bid='+pnBID;
			if (oCPPreviewWin != null)
				oCPPreviewWin.close;
			oCPPreviewWin = window.open(lcLocation, 'faqpreview', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
			oCPPreviewWin.focus();
			break;
	}
	if (llReturn && lcLocation != '')
		document.location = lcLocation + '&eid='+pnEID+'&bid='+pnBID+'&did='+pnDID;

	return llReturn;
}


function toggleDetailViewSummary(plShow) {
	var llConfirm = true;
	
	if (!plShow && detailframe2.document.body.innerHTML != '')
		llConfirm = confirm('Out of Network has entered text and will be lost when saved.\n\rAre you sure you wish to do this?');
		
	if (llConfirm) {	
		document.all.detail1header.innerHTML = (plShow ? 'In Network' : 'Detail');
		document.all.detail2header.innerHTML = (plShow ? 'Out of Network' : '');	
		document.all.detail2header.style.visibility = (plShow ? 'visible' : 'hidden');
		document.all.detail2text.style.visibility = (plShow ? 'visible' : 'hidden');
	}
	return llConfirm;
}

function checkHCSummarySave(poForm) {
	var llReturn = true;
	
	if (poForm.header.value == '-1') {
		alert('Please assign a summary header!');
		llReturn = false;
	}

	if (llReturn && poForm.component.value == '-1') {
		alert('Please assign a summary component!');
		llReturn = false;
	}

	if (llReturn) {
		poForm.detail1.value = detailframe1.document.body.innerHTML;
		poForm.detail2.value = detailframe2.document.body.innerHTML;
	}
		
	return llReturn;
}

var oHCWin = null;
function HeaderComponentButtons(pcType, pcButton, pnID, pnHID, pnGroup) {
	if ((pnID > 0 || pcButton == 'Add') && pnHID >= 0) {
		var ldX, ldY;
		ldX = document.body.clientWidth-400;
		ldX = (ldX < 0 ? 0 : ldX /2)
		ldX += window.screenLeft;
		ldY = document.body.clientHeight-120;
		ldY = (ldX < 0 ? 0 : ldY / 2)
		ldY += window.screenTop;
		if (oHCWin != null)
			oHCWin.close;

		oHCWin = window.open('hc_window.asp?type='+pcType +'&id='+pnID+'&action='+pcButton+'&hid='+pnHID+'&group='+pnGroup, 'hc_window', 'dependent=yes,location=no,status=no,width=400,height=120,menubar=no,toolbar=no,left=' + ldX + ',top=' + ldY);
		oHCWin.focus();
	}
}
var oCDWin = null;
function planSummaryDetailEdit(pnDetail, pnPSID, pnGroup) {
	var ldX, ldY, loTempID;
	loTempID = (pnDetail == 1 ? document.all.summarydetail.detail1tempid : document.all.summarydetail.detail2tempid);
	
	ldX = document.body.clientWidth-750;
	ldX = (ldX < 0 ? 0 : ldX /2)
	ldX += window.screenLeft;
	ldY = document.body.clientHeight-500;
	ldY = (ldX < 0 ? 0 : ldY / 2)
	ldY += window.screenTop;
	if (oCDWin != null)
		oCDWin.close;
	oCDWin = window.open('hc_detailedit.asp?id='+pnPSID+'&group='+pnGroup+'&detail='+pnDetail+'&multi='+(document.all.summarydetail.ismulti.checked ? 'yes': 'no')+(loTempID.value != '0' ? '&tempid='+loTempID.value : ''), 'hc_detailedit', 'dependent=yes,location=no,status=no,width=750,height=500,menubar=no,toolbar=no,left=' + ldX + ',top=' + ldY);
	oCDWin.focus();
}

function clientSummaryDetailEdit(pnDetail, pnCSID, pnGroup) {
	var ldX, ldY, loTempID;
	loTempID = (pnDetail == 1 ? document.all.summarydetail.detail1tempid : document.all.summarydetail.detail2tempid);
	
	ldX = document.body.clientWidth-750;
	ldX = (ldX < 0 ? 0 : ldX /2)
	ldX += window.screenLeft;
	ldY = document.body.clientHeight-500;
	ldY = (ldX < 0 ? 0 : ldY / 2)
	ldY += window.screenTop;
	if (oCDWin != null)
		oCDWin.close;
	oCDWin = window.open('cs_detailedit.asp?id='+pnCSID+'&group='+pnGroup+'&detail='+pnDetail+'&multi='+(document.all.summarydetail.ismulti.checked ? 'yes': 'no')+(loTempID.value != '0' ? '&tempid='+loTempID.value : ''), 'cs_detailedit', 'dependent=yes,location=no,status=no,width=750,height=500,menubar=no,toolbar=no,left=' + ldX + ',top=' + ldY);
	oCDWin.focus();
}

function clientEligibilityDetailEdit(pnDetail, pnCSID, pnGroup) {
	var ldX, ldY, loTempID;
	loTempID = document.all.summarydetail.detail1tempid;
	
	ldX = document.body.clientWidth-750;
	ldX = (ldX < 0 ? 0 : ldX /2)
	ldX += window.screenLeft;
	ldY = document.body.clientHeight-500;
	ldY = (ldX < 0 ? 0 : ldY / 2)
	ldY += window.screenTop;
	if (oCDWin != null)
		oCDWin.close;
	oCDWin = window.open('cs_detailedit.asp?id='+pnCSID+'&group='+pnGroup+'&detail='+pnDetail+'&multi=no'+(loTempID.value != '0' ? '&tempid='+loTempID.value : ''), 'cs_detailedit', 'dependent=yes,location=no,status=no,width=750,height=500,menubar=no,toolbar=no,left=' + ldX + ',top=' + ldY);
	oCDWin.focus();
}

function checkEligibilitySubmit(poForm) {
	var loComp = poForm.component;
	var llReturn = true;
	if (loComp.value == -1) {
		alert('Please select a component!');
		llReturn = false;
	} else {
		poForm.detail1.value = detailframe1.document.body.innerHTML;
	}
	return llReturn;
}

function CarrierPlanHeaderChange(poSelect) {
	var loComp = document.all.summarydetail.component;
	for (lnCnt = loComp.options.length; lnCnt >= 0; lnCnt--)
		loComp.options[lnCnt] = null;


	if (poSelect.value == -1) {
		loComp.options[0] = new Option('-- Please select a header first! --');
		loComp.options[0].value = -1;
		document.all.summarydetail.compadd.disabled = true;
		document.all.summarydetail.compedit.disabled = true;
		document.all.summarydetail.compdel.disabled = true;
	} else {
		loComp.options[0] = new Option('-- Please select a component! --');
		loComp.options[0].value = -1;

		if (eval('document.all.summarydetail.comps' + poSelect.value) != undefined) {
			var lcStr = eval('document.all.summarydetail.comps' + poSelect.value +'.value')
			var lnCnt, lcValue, lcPrompt;

			lnCnt = 0;
			while (lcStr.length > 0) {
				lnCnt++;
				lcStr = lcStr.substring(2);
				lcValue = lcStr.substring(0, lcStr.indexOf("_"));
				lcStr = lcStr.substring(lcStr.indexOf("_")+1);
				lcPrompt = (lcStr.indexOf("_C") > 0 ? lcStr.substring(0, lcStr.indexOf("_C")) : lcStr);
				lcStr =  (lcStr.indexOf("_C") > 0 ? lcStr.substring(lcStr.indexOf("_C")) : '');
				
				loComp.options[lnCnt] = new Option(lcPrompt);
				loComp.options[lnCnt].value = lcValue;
			}
		}
		document.all.summarydetail.compadd.disabled = false;
		document.all.summarydetail.compedit.disabled = false;
		document.all.summarydetail.compdel.disabled = false;
	}
}

function ClientSummaryHeaderChange(poSelect) {
	var loComp = document.all.summarydetail.component;
	for (lnCnt = loComp.options.length; lnCnt >= 0; lnCnt--)
		loComp.options[lnCnt] = null;


	if (poSelect.value == -1) {
		loComp.options[0] = new Option('-- Please select a header first! --');
		loComp.options[0].value = -1;
	} else {
		loComp.options[0] = new Option('-- Please select a component! --');
		loComp.options[0].value = -1;

		if (eval('document.all.summarydetail.comps' + poSelect.value) != undefined) {
			var lcStr = eval('document.all.summarydetail.comps' + poSelect.value +'.value')
			var lnCnt, lcValue, lcPrompt;

			lnCnt = 0;
			while (lcStr.length > 0) {
				lnCnt++;
				lcStr = lcStr.substring(2);
				lcValue = lcStr.substring(0, lcStr.indexOf("_"));
				lcStr = lcStr.substring(lcStr.indexOf("_")+1);
				lcPrompt = (lcStr.indexOf("_C") > 0 ? lcStr.substring(0, lcStr.indexOf("_C")) : lcStr);
				lcStr =  (lcStr.indexOf("_C") > 0 ? lcStr.substring(lcStr.indexOf("_C")) : '');
				
				loComp.options[lnCnt] = new Option(lcPrompt);
				loComp.options[lnCnt].value = lcValue;
			}
		}
	}
}


function clientSelection(pnEID) {
	var loList = document.all.clients.lstCPlans;
	var lnCnt;
	for (lnCnt = loList.options.length; lnCnt >= 0; lnCnt--)
		loList.options[lnCnt] = null;

	if (eval('document.all.clients.erplans' + pnEID) != undefined) {
		var lcStr = eval('document.all.clients.erplans' + pnEID +'.value')
		var lnCnt, lcValue, lcPrompt;

		lnCnt = -1;
		while (lcStr.length > 0) {
			lnCnt++;
			lcStr = lcStr.substring(4);
			lcValue = lcStr.substring(0, lcStr.indexOf("_"));
			lcStr = lcStr.substring(lcStr.indexOf("_")+1);
			lcPrompt = (lcStr.indexOf("_ERP") > 0 ? lcStr.substring(0, lcStr.indexOf("_ERP")) : lcStr);
			lcStr =  (lcStr.indexOf("_ERP") > 0 ? lcStr.substring(lcStr.indexOf("_ERP")) : '');
			
			loList.options[lnCnt] = new Option(lcPrompt);
			loList.options[lnCnt].value = lcValue;
		}
	}
}

function clientAssignButtons(pcAction, pnEID, pnBID) {
	var lcLocation = '';
	switch (pcAction) {
		case 'Add':
			lcLocation = (pnEID != '' ? 'benefitsassign.asp?action=add&eid='+pnEID+'&bid=0' : '');
			break;
		case 'Modify':
			lcLocation = (pnBID != '' && pnEID != '' ? 'benefitsassign.asp?action=edit&eid='+pnEID+'&bid='+pnBID : '');
			break;
		case 'Remove':
			if (pnBID != '' && pnEID != '')
				if (confirm('Are you sure?!?\n\rThis will remove all entered information for this Plan Benefit!'))
					lcLocation = 'benefitsassign.asp?action=del&eid='+pnEID+'&bid='+pnBID;
			break;
	}
	if (lcLocation != '') {
		document.location = lcLocation;
	}		
}

function checkNewPlanBenefit(poForm) {
	//isDate(pnYear, pnMonth, pnDay)
	var llReturn = true;

	if (alltrim(poForm.benefitname.value).length == 0) {
		alert('Please assign a name to the Plan Benefit!');
		poForm.benefitname.focus();
		llReturn = false;
	}
	
	if (llReturn && poForm.carrierplan.value == -1) {
		alert('Please select a Carrier Plan!');
		poForm.carrierplan.focus();
		llReturn = false;
	}

	if (llReturn && !isDate(poForm.edyear.value, poForm.edmonth.value, poForm.edday.value)) {
		alert('Please assign a valid Effective Date!');
		poForm.edmonth.focus();
		llReturn = false
	}
	
	if (llReturn && !isDate(poForm.etdyear.value, poForm.etdmonth.value, poForm.etdday.value)) {
		alert('Please assign a valid Effective Thru Date!');
		poForm.etdmonth.focus();
		llReturn = false
	}

	if (llReturn) {
		var lnCnt, loChk, lnChkCnt = 0, lnYear, lnDay, lnMonth;
		for (lnCnt = 0; llReturn && lnCnt < poForm.elements.length; lnCnt++) {
			loChk = poForm.elements[lnCnt];
			if (loChk.type == 'checkbox' && loChk.name.substring(0, 7) == 'catchk_' && loChk.checked)	{
				lnYear = eval('poForm.year' + loChk.name.substring(6)+'.value');
				lnMonth = eval('poForm.month' + loChk.name.substring(6)+'.value');
				lnDay = eval('poForm.day' + loChk.name.substring(6)+'.value');
				if (lnYear != '' && lnMonth != '' && lnDay != '' && !isDate(lnYear, lnMonth, lnDay)) {
					alert('A Display Starting Date is not valid. Please locate and fill out correctly.');
					llReturn = false;
				}
				if (llReturn) {
					lnYear = eval('poForm.eyear' + loChk.name.substring(6)+'.value');
					lnMonth = eval('poForm.emonth' + loChk.name.substring(6)+'.value');
					lnDay = eval('poForm.eday' + loChk.name.substring(6)+'.value');
					if (lnYear != '' && lnMonth != '' && lnDay != '' && !isDate(lnYear, lnMonth, lnDay)) {
						alert('A Display Ending Date is not valid. Please locate and fill out correctly.');
						llReturn = false;
					}
				}
			}
		}
	}
	
	return llReturn;
}

function showSelectToolTip(poObj) {
	if (poObj.options.selectedIndex != -1) {
		document.all.tooltip.innerHTML = poObj.options[poObj.options.selectedIndex].text;
		document.all.tooltip.style.pixelTop = poObj.getBoundingClientRect().top + poObj.offsetHeight + document.body.scrollTop;
		document.all.tooltip.style.pixelLeft = poObj.getBoundingClientRect().left + document.body.scrollLeft ;
		document.all.tooltip.style.visibility = "visible";
	}
}

function hideSelectToolTip() {
	if (typeof document.all.tooltip != 'undefined') {
		document.all.tooltip.style.visibility = "hidden";
	}
}

function ToolTip(poObj, pcText) {
	if (typeof document.all.tooltip != 'undefined') {
		if (pcText != '') {
			pcText = pcText.replace(/</g, '&lt');
			pcText = pcText.replace(/>/g, '&gt');
			document.all.tooltip.innerHTML = pcText;
			document.all.tooltip.style.pixelTop = poObj.getBoundingClientRect().top + poObj.offsetHeight + document.body.scrollTop;
			document.all.tooltip.style.pixelLeft = poObj.getBoundingClientRect().left + document.body.scrollLeft ;
			document.all.tooltip.style.visibility = "visible";
		} else {
			document.all.tooltip.style.visibility = "hidden";
		}
	}
}




function warningCheckbox(poObj, pnDID) {
	var laMsg = new Array('Benefit Summary Detail', 'Eligility Detail',
						  'Contribution Detail', 'and uploaded Legal Desciptions', 'and uploaded Product Brochures', 
						  'FAQs', 'Provider Directory URL', 'Contact Information', 'Document Form Assignments', 
						  'Internet Resources', 'News & References');
	var llReturn = true;
	if (!poObj.checked) {
		if (pnDID == 7) {
			llReturn = confirm('This will clear the '+laMsg[pnDID-1] + ' when saving.\n\rAre you sure?!?');
		} else {
			llReturn = confirm('This will delete all configured '+laMsg[pnDID-1] + ' when saving.\n\rAre you sure?!?');
		}
	}
	return llReturn;
}

function clientEligibilityButton(pcAction, pnEID, pnBID, pnDID) {
	var lcLocation = '';
	var lcValue = document.all.summary.summaries.value;
	switch (pcAction) {
		case 'add':
			lcLocation = 'clienteligibilityedit.asp?add=0&eid='+pnEID+'&bid='+pnBID+'&did='+pnDID;
			break;	
		case 'edit':
			lcLocation = (lcValue != '' ? 'clienteligibilityedit.asp?edit='+lcValue+'&eid='+pnEID+'&bid='+pnBID+'&did='+pnDID : '');
			break;	
		case 'remove':
			lcLocation = (lcValue != '' ? 'clienteligibilityedit.asp?remove='+lcValue+'&eid='+pnEID+'&bid='+pnBID+'&did='+pnDID : '');
			if (lcLocation != '')
				lcLocation = (confirm('Are you sure?!?') ? lcLocation : '');
			break;	
		case 'preview':
			lcLocation = 'clienteligibilitypreview.asp?eid='+pnEID+'&bid='+pnBID;
			if (oCPPreviewWin != null)
				oCPPreviewWin.close;
			oCPPreviewWin = window.open(lcLocation, 'eligibilitypreview', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
			oCPPreviewWin.focus();
			lcLocation = '';
			break;	
	}
	if (lcLocation != '')
		document.location = lcLocation;
		
	return (lcLocation != '');
}

function doBenefitFAQSave(poForm, poEditor) {
	var llReturn = true;
	poForm.answer.value = poEditor.document.body.innerHTML;
	
	if (alltrim(poForm.short.value).length == 0) {
		alert('Please assign a Short Description.');
		llReturn = false;
	}
	
	if (llReturn && alltrim(poForm.question.value).length == 0) {
		alert('Please enter a question for the FAQ.');
		llReturn = false;
	}

	if (llReturn && alltrim(poForm.answer.value).length == 0) {
		alert('Please enter an answer for the FAQ.');
		llReturn = false;
	}
	
	return llReturn;
}

function checkCategoryClick(poChk, pcMonth, pcDay, pcYear) {
	if (poChk.value) {
		var lcRef = poChk.name.substring(6);
		var poMonth = eval('document.all.assign.month'+lcRef);
		var poDay = eval('document.all.assign.day'+lcRef);
		var poYear = eval('document.all.assign.year'+lcRef);
		poMonth.value = pcMonth;
		poDay.value = pcDay;
		poYear.value = pcYear;
	}
}

function checkProviderURL(poForm) {
	var lcTemp = alltrim(poForm.url.value);
	if (lcTemp.length > 0) {
		lcTemp = lcTemp.toLowerCase();
		if (lcTemp.substring(0, 4) != 'http') {
			lcTemp = 'http://' + lcTemp;
			poForm.url.value = lcTemp;
		}
	}
	return true;
}


function checkBenefitCompare(poForm, pnRecordCnt) {
	var llReturn = false;
	var lnCnt, lnChecked = 0, loChk;
	
	for (lnCnt = 0; lnCnt < poForm.elements.length; lnCnt++) {
		loChk = poForm.elements[lnCnt];
		if (loChk.type == 'checkbox' && loChk.name.substring(0, 11) == 'comparechk_' && loChk.checked)
			lnChecked++;
	}

	if (lnChecked > 0) {
		if (pnRecordCnt > 1) {
			if (lnChecked == 1) {
				alert('Only one Benefit Plan checked for comparison. Please check more than one.');			
			} else {
				llReturn = true;
			}
		} else {
			llReturn = confirm('Only one Benefit Plan. Nothing to compare.\n\rDo you wish to view the Benefit Plan anyway?');
		}
	} else {
		alert('Please check Benefit Plans for comparison.');
	}
	return llReturn;
}

function checkBrochureLegal(poForm, plIsEdit, pnType) {
	var llReturn = true;
	var lcTemp;
	
	if (!plIsEdit) {
		lcTemp = alltrim((pnType == 1 ? poForm.brochure.value : poForm.legal.value));
		if (lcTemp.length == 0) {
			llReturn = false;
			alert('Please browse for a file.');
		}

		if (llReturn) {
			lcTemp = lcTemp.toLowerCase();
			if (lcTemp.substring(lcTemp.length-4) != '.pdf' && lcTemp.substring(lcTemp.length-4) != '.doc') {
				llReturn = false;			
				alert('Please only upload PDF or DOC files.');
			}
		}		
	}

	lcTemp = alltrim(poForm.description.value);
	if (llReturn && lcTemp.length == 0) {
		llReturn = false;
		alert('Please assign a short description.');
	}
	
	lcTemp = alltrim(poForm.comment.value);
	if (llReturn && lcTemp.length > 500) {
		llReturn = false;
		alert('The comment must maximum be 500 character long.\n\rCurrent length: ' + lcTemp.length);
	}
	
	if (!plIsEdit && llReturn) {
		document.all.waitmessage.style.display = '';
		document.all.savebutton.disabled = true;
	}
	return llReturn;
}

function checkNewGroupName(poForm) {
	var llReturn = true;
	
	var lcTemp = alltrim(poForm.groupname.value);
	if (lcTemp.length == 0) {
		llReturn = false;
		alert('Please enter a group name.');
		poForm.groupname.focus();
	}

	return llReturn;
}

function removeGroupClick(pcLocation) {
	var llReturn = confirm('Please note. Group will not be removed if associated with another benefit.\n\rAre you sure you wish to remove the group?');
	if (llReturn) {
		document.location = pcLocation;
	}
	return llReturn;
}

function checkModifyDocForms(poForm) {
	var llReturn = true;
	
	var lcTemp = alltrim(poForm.formname.value);
	if (lcTemp.length == 0) {
		llReturn = false;
		alert('Please assign a short description to the Document Form.');
		poForm.formname.focus();
	}
	
	return llReturn;
}

function showmeChange(pnWhat) {
	if (pnWhat > 0) {
		document.location = 'benefitshowme.asp?what=' + pnWhat;
	}
}


// ------------------

function showHRAbenefitDesign(pcTPA, pnER, pnBN) {
	var lcLocation = 'inquiryHRA_bd.asp?tpa=' + pcTPA + '&bn=' + pnBN + '&er=' + pnER;
	window.open(lcLocation, 'hrabd', 'dependent=yes,location=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
}



