var _ie = document.all;
var _ie6 = false;
var _moz = document.getElementById && !_ie;

var focus_timeout = false;
var focus_interval = 4;
var current_focus = 1;

var audio_on = false;

if (_ie) {
	if (navigator.appVersion.indexOf('MSIE 7') == -1) {
		_ie6 = true;
	}	
}

function rotateFocus () {
	if (current_focus == 5) {
		next_focus = 1;
	} else {
		next_focus = current_focus + 1;
	}
	
	changeFocus(next_focus);

	focus_timeout = window.setTimeout("rotateFocus();", focus_interval * 1000);
}

function changeFocus (index) {
	var img = document.getElementById('tpl_focus_img');
	var current = document.getElementById('tpl_focus_cell_' + current_focus);
	var nxt = document.getElementById('tpl_focus_cell_' + index);

	if (focus_timeout) {
		window.clearTimeout(focus_timeout);
	}
	
	tpl_focus_img.src = tpl_img_path + page_name + "/focus_" + index + ".jpg";
	current.className = "tpl_focus_cell_out";
	nxt.className = "tpl_focus_cell_over";
	
	current_focus = index;
}

function clearConfirm () {
	if (div = document.getElementById('page_confirm_msg')) {
	 	div.outerHTML = "";
	}
}

function clearError () {
	if (div = document.getElementById('page_error_msg')) {
	 	div.outerHTML = "";
	}
}

function changeButtonPos (img, pos) {	
	switch (pos) {
		case 'out':
			mod = 'over';
			break;
		case 'over':
			mod = 'out';
			break;
		case 'down':
			pos = 'click'
			mod = 'over';
			break;
		case 'up':
			pos = 'over'
			mod = 'click';
			break;
	}
	
	img.src = img.src.replace("_" + mod, "_" + pos);
}

function getParent(elm) {
	if (_ie) {
		return elm.parentElement;
	} else {
		return elm.parentNode;
	}
}

function getFirstChild(elm) {
	if (_ie) {
		return elm.firstChild;
	} else {
		return elm.firstChild.nextSibling;
	}
}

function getNextSibling(elm) {
	if (_ie) {
		return elm.nextSibling;
	} else {
		return elm.nextSibling.nextSibling;
	}
}

function areaCode (area) {	
	if (area.value.length == 3) {
		var phone = area.nextSibling.nextSibling;
		
		phone.focus();	
	}
}

function _void () {
	
}

function currencyRound(value) {
	if (value == 0) {
		value = "0.00";
	} else {
		value *= 100;
		value = Math.round(value) + "";
	
		value = value.substring(0, value.length - 2) + "." + value.substring(value.length - 2, value.length);
	}
	
	return value.valueOf();	
}
