function focusOnFirstText(){
	if (document.all!=null){
		var coll = document.all.tags("input");
		if (coll!=null)	{
		    for (i=0; i<coll.length; i++) {
		    	if (coll[i]!=null){
		    		if (coll[i].type=="text"){
		    			if (coll[i].style!=null&coll[i].style.visibility!="hidden"&coll[i].disabled!=true){
			    			coll[i].focus();
			    			break;
		    			}
		    		}
		    	}
		    }
		}	
	}
}

function getHidden(elem, formIndex){
	var form = getForm(formIndex);
	if (!form[elem]){
		var hidden = document.createElement('INPUT');
		hidden.type='hidden';
		hidden.name=elem;
		form.appendChild(hidden);
		return hidden;
	} else {
		return form[elem];
	}
}

function execute(act, formIndex){
	getHidden('act', formIndex).value=act;
	getForm(formIndex).submit();
}

function executeWithParam(act, param, formIndex){
	getHidden('executeParam', formIndex).value = param;
	execute(act, formIndex);
}

function goToStep(num, formIndex) {
	getHidden('act', formIndex).value = 'step';
	getHidden('step', formIndex).value = num;
	getForm(formIndex).submit();	
}


function getForm(formIndex){
	if (document.forms!=null){
		if (!formIndex || document.forms.length <= formIndex){
			formIndex = 0
		}
		if (document.forms[formIndex]!=null){
			return document.forms[formIndex];
		}
	}	
	alert('Form with index ' + index + ' wasn\'t found');
	return null;
}

function submitForm(formIndex){
	var form = getForm(formIndex);
	if (form != null){
		form.submit();
	}
}

function keyDown(formname) {
	if (event.keyCode == 10 || event.keyCode == 13) {
		document.forms[formname].submit();
	}
}

function defineEnterSubmit() {
	if (document.forms==null || document.forms[0]==null) return;
	var formname = document.forms[0].name;
	if (document.all!=null){
		var coll = document.all.tags("input");
		if (coll!=null)	{
		    for (i=0; i<coll.length; i++) {
		    	if (coll[i]!=null){
		    		if (coll[i].type=="text"){
		    			if (!coll[i].onkeydown) {
							coll[i].onkeydown=new Function('return keyDown("' + formname + '")');
		    			} else {
		    				var text = coll[i].onkeydown+'';
		    				var functionText = text.substring(text.indexOf('{')+1, text.indexOf('}'))+ ' keyDown("' + formname + '");';
		    				coll[i].onkeydown=new Function(functionText);
		    			}
		    		}
		    	}
		    }
		}	
		var coll = document.all.tags("select");
		if (coll!=null)	{
		    for (i=0; i<coll.length; i++) {
		    	if (coll[i]!=null){
					coll[i].onkeydown=new Function('return keyDown("' + formname + '")');
		    	}
		    }
		}	

	}
}

function scrollUp(){
	window.scrollTo(0,0);	
}
