// Javascript document

/* -------------------------------------------------------- */
/* Copyright (c) 2008-2009 16th-FLOOR. All rights reserved. */
/* -------------------------------------------------------- */

// sets focus on first form field
function form_setfocus( aForm ) {
	if( aForm.elements[0] != null) {
		var i;
		var max = aForm.length;
		for( i = 0; i < max; i++ ) {
			if( aForm.elements[ i ].type != "hidden" &&
				!aForm.elements[ i ].disabled &&
				!aForm.elements[ i ].readOnly ) {
				aForm.elements[ i ].focus();
				aForm.elements[i].select();
				break;
			}
		}
	}
}

//Simple validation to make sure user entered something
//If error found, add hightlight class to the text field
function hb_form_check(thisForm) {	
	// get data
	var txt_field_01 = $('input[ name="txt_field_01"]');
	var txt_field_02 = $('input[ name="txt_field_02"]');
	var txt_field_03 = $('input[ name="txt_field_03"]');
	var txt_field_04 = $('input[ name="txt_field_04"]');
	var txt_field_05 = $('input[ name="txt_field_05"]');
	var txt_area_01 = $('textarea[name=txt_area_01]');

	//validate
	if (txt_field_01()=="") {
		txt_field_01.addClass('hightlight');
		txt_field_01.focus();
		txt_field_01.select();
		return false;
	} else txt_field_01.removeClass('hightlight');
	
	if (txt_field_02()=="") {
		txt_field_02.addClass('hightlight');
		txt_field_02.focus();
		txt_field_02.select();
		return false;
	} else txt_field_02.removeClass('hightlight');

	if (txt_field_03()=="") {
		txt_field_03.addClass('hightlight');
		txt_field_03.focus();
		txt_field_03.select();
		return false;
	} else txt_field_03.removeClass('hightlight');

	if (txt_field_04()=="") {
		txt_field_04.addClass('hightlight');
		txt_field_04.focus();
		txt_field_04.select();
		return false;
	} else txt_field_04.removeClass('hightlight');

	if (txt_field_05()=="") {
		txt_field_05.addClass('hightlight');
		txt_field_05.focus();
		txt_field_05.select();
		return false;
	} else txt_field_05.removeClass('hightlight');
	
	if (txt_area_01()=="") {
		txt_area_01.addClass('hightlight');
		txt_area_01.focus();
		txt_area_01.select();
		return false;
	} else txt_area_01.removeClass('hightlight');
	
	// everything ok
	return true;
}


// CSS changes for selected form field, used in form_check function
function doCSSstuff(activefield){
	activefield.addClass('hightlight');
	activefield.focus();
	activefield.select();
	return false;
}
