// JavaScript Document
var d = document;
var w = window;

var isIE = navigator.appName == "Microsoft Internet Explorer";
var isFF = d.getElementById && !d.all;

function nav(path) { if(path) window.location.href=path; }
function _hover(obj, col) { if(!obj) return; pb = obj.style.backgroundColor; obj.style.backgroundColor = (col ? col : '#e4effd'); obj.onmouseout = function() { obj.style.backgroundColor = pb; }  }
function _confirm(msg) { return confirm( (msg ? msg : 'This cannot be undone! Proceed with this action?') ); }
function _get(id) { return document.getElementById(id); }

function _tags(nm) { return d.getElementsByTagName(nm); }

function _attachEvent(obj, eventName, func)
{
	return (isIE) ? obj.attachEvent('on'+eventName, func) : obj.addEventListener(eventName, func, false);
}

navHover = function() {
	var lis = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}

	lis = document.getElementById("sidenav")
	if(lis) {
		lis.getElementsByTagName("LI");
		for (i=0; i<lis.length; i++) {
			lis[i].onmouseover=function() {
				this.className+=" iehover";
			}
			lis[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	}

}
if (window.attachEvent) window.attachEvent("onload", navHover);

function clear_search() {
	_get("search_text").value="%";
	_get("bsubmit").click();
}

function selected_remove()
{
	a = confirm("This action cannot be undone, are you sure you want to delete selected records?");
	if(a)
	{
		_get("a").value = "delete";
		_get("frmlisting").submit();
	}
}

function selected_status(status)
{
	switch(status)
	{
		case "Y": _get("a").value = "active"; break;
		case "N": _get("a").value = "inactive"; break;
	}
	_get("frmlisting").submit();

}

function selected_attend(status)
{
	switch(status)
	{
		case "Y": _get("a").value = "attend"; break;
		case "N": _get("a").value = "unattend"; break;
	}
	_get("frmlisting").submit();

}

function appendDOM(from, to, iID)
{
	var obf = _get(from); if(!obf) return false;
	var obt = _get(to);   if(!obt) return false;
	var obx = document.createElement('div');
		if(iID=="") {
		obx.innerHTML = obf.innerHTML.replace(/\$id\$/g, _getnewId(''));
		} else {
		obx.innerHTML = obf.innerHTML.replace(/\$id\$/g, iID);
		}
	while(obx.childNodes.length) { obt.appendChild(obx.childNodes[0]); }
}

function removeDOM(id)
{
	var ob =_get(id);
	if(!ob) return false;
	ob.parentNode.removeChild(ob);
}

function history_add() {
	a = _get("history_count").value;
	appendDOM("history_template","history_holder",a);
	_get("history_count").value = (a*1)+1;
}

function history_remove(id) {
	if(confirm("This action cannot be undone. Are you sure you want to proceed?")) {
		if(_get("history_new"+id)) {
		removeDOM("history_new"+id);
		} else {
		removeDOM("history_old"+id);
		}
	}
}