/*
	Author: Matt Johnson
	Company: Bullhorn.co.uk
	Last Mod: 25/01/2008
*/
function convictDateUpdate(funkedElement) {
	if (funkedElement) {
		var _prefix = funkedElement.id.replace('UiConvictionDate_Day', '').replace('UiConvictionDate_Month', '').replace('UiConvictionDate_Year', '')
		var UiConvictionDate_Day = dGetById(_prefix + 'UiConvictionDate_Day');
		var UiConvictionDate_Month = dGetById(_prefix + 'UiConvictionDate_Month');
		var UiConvictionDate_Year = dGetById(_prefix + 'UiConvictionDate_Year');
		var UiConvictionDate = dGetById(_prefix + 'UiConvictionDate');
		if (UiConvictionDate_Day && UiConvictionDate_Month && UiConvictionDate_Year && UiConvictionDate) {
			UiConvictionDate.value = String(UiConvictionDate_Day.value) + '\/' + String(UiConvictionDate_Month.value) + '\/' + String(UiConvictionDate_Year.value);
		}
	}
}
function medicalDateUpdate(funkedElement) {
	if (funkedElement) {
		var _prefix = funkedElement.id.replace('UiMedicalDate_Day', '').replace('UiMedicalDate_Month', '').replace('UiMedicalDate_Year', '')
		var UiClaimDate_Day = dGetById(_prefix + 'UiMedicalDate_Day');
		var UiClaimDate_Month = dGetById(_prefix + 'UiMedicalDate_Month');
		var UiClaimDate_Year = dGetById(_prefix + 'UiMedicalDate_Year');
		var UiClaimDate = dGetById(_prefix + 'UiMedicalDate');
		if (UiClaimDate_Day && UiClaimDate_Month && UiClaimDate_Year && UiClaimDate) {
			UiClaimDate.value = String(UiClaimDate_Day.value) + '\/' + String(UiClaimDate_Month.value) + '\/' + String(UiClaimDate_Year.value);
		}
	}
}
function claimDateUpdate(funkedElement) {
	if (funkedElement) {
		var _prefix = funkedElement.id.replace('UiClaimDate_Day', '').replace('UiClaimDate_Month', '').replace('UiClaimDate_Year', '')
		var UiClaimDate_Day = dGetById(_prefix + 'UiClaimDate_Day');
		var UiClaimDate_Month = dGetById(_prefix + 'UiClaimDate_Month');
		var UiClaimDate_Year = dGetById(_prefix + 'UiClaimDate_Year');
		var UiClaimDate = dGetById(_prefix + 'UiClaimDate');
		if (UiClaimDate_Day && UiClaimDate_Month && UiClaimDate_Year && UiClaimDate) {
			UiClaimDate.value = String(UiClaimDate_Day.value) + '\/' + String(UiClaimDate_Month.value) + '\/' + String(UiClaimDate_Year.value);
		}
	}
}
function createCalendarClaim(calendarCount, isAdditional) {
	var prefix = 'ctl00_ContentPlaceHolder1_UiProposerClaim_' + String(calendarCount) + '_';
	if (isAdditional) {
		prefix = 'ctl00_ContentPlaceHolder1_UiAdditional_Claim_' + String(calendarCount) + '_';
	}
	var element = dGetById(prefix + 'UiClaimDate_Day');
	if (element) {
		if (!window['_createCalendarX_' + String(calendarCount)])
			window['_createCalendarX_' + String(calendarCount)] = new DatePicker(element);
		element.id = String(element.id).replace('$', '_').replace('$', '_').replace('$', '_').replace('$', '_');
		if (window['_createCalendarX_' + String(calendarCount)]) {
			window['_createCalendarX_' + String(calendarCount)].dayObject = element;
			window['_createCalendarX_' + String(calendarCount)].monthObject = dGetById(prefix + 'UiClaimDate_Month');
			window['_createCalendarX_' + String(calendarCount)].yearObject = dGetById(prefix + 'UiClaimDate_Year');
			window['_createCalendarX_' + String(calendarCount)].privateUpdate = dGetById(prefix + 'UiClaimDate');
			window['_createCalendarX_' + String(calendarCount)].create(element, window['_createCalendarX_' + String(calendarCount)]);
		}
	}
}
function createCalendarConviction(calendarCount, isAdditional) {
	var prefix = 'ctl00_ContentPlaceHolder1_UiProposerConviction_' + String(calendarCount) + '_';
	if (isAdditional) {
		prefix = 'ctl00_ContentPlaceHolder1_UiAdditional_Conviction_' + String(calendarCount) + '_';
	}
	var element = dGetById(prefix + 'UiConvictionDate_Day');
	if (element) {
		if (!window['_createCalendarY_' + String(calendarCount)])
			window['_createCalendarY_' + String(calendarCount)] = new DatePicker(element);
		element.id = String(element.id).replace('$', '_').replace('$', '_').replace('$', '_').replace('$', '_');
		if (window['_createCalendarY_' + String(calendarCount)]) {
			window['_createCalendarY_' + String(calendarCount)].dayObject = element;
			window['_createCalendarY_' + String(calendarCount)].monthObject = dGetById(prefix + 'UiConvictionDate_Month');
			window['_createCalendarY_' + String(calendarCount)].yearObject = dGetById(prefix + 'UiConvictionDate_Year');
			window['_createCalendarY_' + String(calendarCount)].privateUpdate = dGetById(prefix + 'UiConvictionDate');
			window['_createCalendarY_' + String(calendarCount)].create(element, window['_createCalendarY_' + String(calendarCount)]);
		}
	}
}
function createCalendarMedical(calendarCount) {
	var prefix = 'ctl00_ContentPlaceHolder1_UiProposerMed_' + String(calendarCount) + '_';
	var element = dGetById(prefix + 'UiMedicalDate_Day');
	if (element) {
		if (!window['_createCalendarX_' + String(calendarCount)])
			window['_createCalendarX_' + String(calendarCount)] = new DatePicker(element);
		element.id = String(element.id).replace('$', '_').replace('$', '_').replace('$', '_').replace('$', '_');
		if (window['_createCalendarX_' + String(calendarCount)]) {
			window['_createCalendarX_' + String(calendarCount)].dayObject = element;
			window['_createCalendarX_' + String(calendarCount)].monthObject = dGetById(prefix + 'UiMedicalDate_Month');
			window['_createCalendarX_' + String(calendarCount)].yearObject = dGetById(prefix + 'UiMedicalDate_Year');
			window['_createCalendarX_' + String(calendarCount)].privateUpdate = dGetById(prefix + 'UiMedicalDate');
			window['_createCalendarX_' + String(calendarCount)].create(element, window['_createCalendarX_' + String(calendarCount)]);
		}
	}
}
function handleEmploymentKey(e, selectionBoxName, evalItem) {
	if (!e)
		e = window.event;
	if (e.keyCode == 13) {
		var selectionBox = dGetById(selectionBoxName);
		if (selectionBox) {
			var selectedIndex = 0;
			if ((window['__emplSelitemIndex' + selectionBoxName]) || (window['__emplSelitemIndex' + selectionBoxName] == 0))
				selectedIndex = Number(window['__emplSelitemIndex' + selectionBoxName]);

			var oC = 0;
			for (oC = 0 ; oC < selectionBox.options.length ; oC++ ) {
				var opt = selectionBox.options[oC];
				if (oC == selectedIndex) {
					opt.selected = true;

					if (selectionBoxName.indexOf('UiEmployerCodes') > 0) {
						lastSearchData_E = selectionBox.options[oC].innerHTML;
					} else if (selectionBoxName.indexOf('UiBusinessCodes') > 0) {
						lastSearchData_B = selectionBox.options[oC].innerHTML;
					} else if (selectionBoxName.indexOf('UiPartTimeEmployerCodes') > 0) {
						lastSearchData_PE = selectionBox.options[oC].innerHTML;
					} else if (selectionBoxName.indexOf('UiPartTimeBusinessCodes') > 0) {
						lastSearchData_PB = selectionBox.options[oC].innerHTML;
					}
				}
			}
			if (evalItem) {
				eval(evalItem.replace('selectionBoxName', '\'' + selectionBoxName + '\''));
				window['__emplSelitemIndex' + selectionBoxName] = -1;
			}
		}
		cancelBubble(e);
	} else if ((e.keyCode == 38) || (e.keyCode == 40)) {
		var selectedIndex = -1;
		var selectionBox = dGetById(selectionBoxName);
		if ((window['__emplSelitemIndex' + selectionBoxName]) || (window['__emplSelitemIndex' + selectionBoxName] == 0))
			selectedIndex = Number(window['__emplSelitemIndex' + selectionBoxName]);
		if (selectionBox) {
			if ((e.keyCode == 38) && (selectedIndex > 0)) {
				selectedIndex = (selectedIndex - 1);
			} else if ((e.keyCode == 40) && (selectedIndex >= -1) && (selectedIndex < (selectionBox.options.length - 1))) {
				selectedIndex = (selectedIndex + 1);
			}
			if (selectedIndex == -1) {
				selectedIndex = 0;
			}
			var oC = 0;
			for (oC = 0 ; oC < selectionBox.options.length ; oC++ ) {
				var opt = selectionBox.options[oC];
				if (oC == selectedIndex) {
					opt.style.background = '#00f';
					opt.style.color = '#fff';
					opt.selected = true;
					opt.selected = false;
				} else {
					opt.style.background = '#fff';
					opt.style.color = '#000';
				}
			}
			window['__emplSelitemIndex' + selectionBoxName] = selectedIndex;
		}
		cancelBubble(e);
	}
}