// rollover functions

function tab_item (img_name, loc, width, height) {
	// remove jsession param on first load
	var ix = loc.indexOf(";jsess");
	if (ix != -1) {
		loc = loc.substring (0, ix);
	}
	img_str = loc + "/" + img_name;

	this.img_name_off = new Image (width, height);
	this.img_name_off.src = img_str + "_off.jpg";
	this.img_name_on = new Image (width, height);
	this.img_name_on.src = img_str + "_on.jpg";
}

function new_tab_item (img_name, loc, width, height) {
	tab_item [img_name] = new tab_item (img_name, loc, width, height);
}

function tn_over (img_name) {
	document.images[img_name].src = tab_item[img_name].img_name_on.src;
}

function tn_out (img_name) {
	document.images[img_name].src = tab_item [img_name].img_name_off.src;
}

function initNavBar (baseUrl) {
	new_tab_item ('home', baseUrl, 61, 86);
	new_tab_item ('abou', baseUrl, 112, 86);
	new_tab_item ('serv', baseUrl, 77, 86);
	new_tab_item ('cont', baseUrl, 65, 86);
	new_tab_item ('stor', baseUrl, 69, 86);
	new_tab_item ('real', baseUrl, 76, 86);
}

/**
 * Searches for the fragment '<number>_' in the given string...
 */
function match(str) {
	  if (isEmpty(str)){
		return false;
	  }
	  var re = new RegExp(/[0-9]+_[a-zA-Z0-9_]/g);
	  return str.match(re);
}

function hasClass(el, className){
	if ((isNull(el)) || isEmpty(className) || (isNotNull(el) && el.className === "")){
		return false;
	}

	return (el.className.indexOf(className) !== -1);
}


function validateForm(form){
	var emptyErrMsg = "";
	if (isNull(form)){
		form = document.forms[0];
	}
	var elements = form.elements;
	for (var i=0; i<elements.length; i++){		
		var name = elements[i].name;		
		var value = elements[i].value;
		try {
			if (match(name) && hasClass(elements[i], "input_required") && isEmpty(value)){
				emptyErrMsg = ERR_FILL_ALL_REQUIRED_FIELDS;
				break;
			}
		} catch(e){}
	}
	if (emptyErrMsg.length > 0){
		alert(emptyErrMsg);
		return false;
	}
	return true;
	
}