function Clickbutton(e, targetButton) {
	if (e.keyCode == 13) {
		//alert('clickbutton()');
		ResetButtons(targetButton);
		targetButton.click();
		return false;
	}
	return true;
}

function ResetButtons(targetButton) {
	els = document.forms[0].elements;
	
	for(index = 0; index < els.length; index++) {
		if (els[index].type == "submit" && els[index] != targetButton) {
			els[index].disabled = true;
		}
	}
}

function DisableEnter (e) {
	if (e.keyCode == 13) {
		e.keyCode = 9;
	}
}

function firstElementFocus() {
	//alert('inside of firstElementFocus(); totalelements: ' + document.forms[0].elements.length);
	if (setForcedFocus()){
		return;
	}
	var fms = document.forms;
	var found = false;
	if (fms != null) {
		for (i=0; i<fms.length; i++) {
			var fm = document.forms[i];
			var els = fm.elements;
			if (els != null) {
				for (j=0; j<els.length; j++) {
					var el = els[j];
					if (canReceiveFocusOnLoad(el)) {
						//alert('founded: ' + el.name);
						el.focus();
						//el.select();
						found = true;
						break;
					}
				}
			}
			if (found)
				break;
		}
	}
	// if in frame, scroll to top
	scrollToTop();
}

function setForcedFocus() {

	var el = document.getElementById("forcedFocus");
	//alert(el);
	if (el != null) {
		//alert("found hidden: value=" + el.value);
		var toFokusEl = null;
		if (el.value != null && el.value != "") {
			toFokusEl = document.getElementById(el.value);
		}
		
		if (toFokusEl != null){
			//alert("found to focus" + toFokusEl.type);
			if (canReceiveFocusOnLoad(toFokusEl)) {
				//alert("can focus");
				toFokusEl.focus();
				return true;
			}	
		}
	}
	return false;
}

function canReceiveFocusOnLoad(el) {
	//alert(el.name + ' ' + el.type + ' disabled: ' + el.disabled + ' parent vis: ' + el.parentNode.style.visibility);
	//interrogate(el.parentNode.style.visibility);
	if (!el.disabled && (el.parentNode != null && (!el.parentNode.style.visibility || !el.parentNode.style.visibility == 'hidden'))
		&& (el.type == 'text' || el.type == 'textarea' || el.type == 'password' 
			|| el.type == 'radio' || el.type == 'checkbox' || el.type == 'submit' || el.type =='select-one')){
		
		return true;
	}
	return false;
}
function interrogate(what) {
	var output = what+'\n';
	for (var i in what)
		output += i+ ', ';
	alert(output);
}

function scrollToTop(){
	if (!/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{ 
		var parentWin = window.parent;
		if (parentWin != null) {
			var parentFrames =  parentWin.frames;
			if (parentFrames != null) {
				var framesCount = parentFrames.length;
				if (framesCount > 0) {
			 		parentWin.scroll(0,0);
				}
			}
		}
	}
}

function onClickCombo(aCombo) {
	
	firstOption = aCombo.options[0];
	selIndex = aCombo.selectedIndex;
	if (firstOption.value == '-1'){
		aCombo.remove(0);
		if (selIndex ==0) {
			aCombo.selectedIndex =0;
		}
	}
}

function fncShowCalendar(aField) {
	var newWindow;
	var urlstring = 'resources/popwincal/calendar.htm';
	gCalendarField=document.getElementById(aField);
	//alert('gCalendarField=' + gCalendarField);
	newWindow = window.open(urlstring,'','height=200,width=280,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no');
}
