
function setInitFocus ()
{

    myObj = document.getElementById('first_input_field_error');

    if (myObj) {
	myObj.focus();
	myObj.select();
	//alert('first_input_field_error: ' + myObj);
	return true;
    }

    myFrmForm = document.getElementById('frm_form')

    if (myFrmForm) {

	myObjs = getElementsByClass('has_error', myFrmForm);
	if (myObjs) {

	    for (i in myObjs) {
		myObj = myObjs[i];

		if (myObj.type != 'hidden')  {
		    myObj.focus();

		    if (myObj.type == 'text')  {
			myObj.select();
		    }

		    //alert (myObj);
		    return true;
		}

	    }
	}

	for (i in myFrmForm.elements) {
	    myObj = myFrmForm.elements[i];

	    if (myObj.type != 'hidden')  {
		myObj.focus();			// FIXME: IE6 makes JS error

		if (myObj.type == 'text')  {
		    myObj.select();
		}

		//alert (myObj);
		return true;
	    }

	}
    }

    return false;

    /*
    myContent = document.getElementById('content');
    myObj = myContent.getElementsByTagName('a')[0];

    alert (myObj);
    */

}


function getElementsByClass (searchClass, node, tag) {

	if ( node == null ) { node = document }
	if ( tag == null ) { tag = '*' }

	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

	var classElements = new Array();

	for (i = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements.push (els[i]);
		}
	}

	return classElements;
}

