var displayMode;
var ie = document.all;
var nn6 = document.getElementById && !document.all;
var isdrag = false;
var x, y;
var dobj;

function mouseHover() {
	var f, e = window.event;
	f = (e.type == "mouseover") ? ('_f2') : ('');
	e.srcElement.src = "images/" + e.srcElement.id + f + ".gif";
}

function mouseHoverCSS() {
	var e = window.event, g = e.srcElement.className;
	e.srcElement.className = (e.type == "mouseover") ? (g + "_over") : (g.substr(0, g.length - 5));
}

function validateNumeric() {
	var kc = event.keyCode;
	var txt = event.srcElement;
	var bl = kc < 48 || kc > 57 ? false : true;
	return bl;
}

function validateAddEditMode() {
	if (displayMode == "Add" || displayMode == "Edit") {
		return confirm("Are you sure you want to navigate away from this page and lose all entered information?");
	} else {
		return true;
	}
}

function validateSelected(msg) {
	var ctrl, i;
	for (i = 0; i < document.all.length; i++) {
		ctrl = document.all[i];
		if (ctrl.id.indexOf("chkSelect") > -1 && ctrl.checked) {
			return true;
		}
	}
	alert(msg);
	return false;
}

function navigatePage(url) {
	if (validateAddEditMode()) {
		location.href = url;
	}
}

function confirmCancel() {
	return confirm("Are you sure you want to cancel editing and lose all the information you entered?");
}

function confirmDelete(name) {
	return confirm("Are you sure you want to delete this " + name + "?");
}

function confirmReset() {
	return confirm("Are you sure you want to reset password for this Member?");
}

function enlargePicture(img) {
	// save image source in the cookie
	setCookie("picture", img.src);
	// open new window
	var oPictureWindow = window.open("picture.htm", "picture", "left=300, top=100, directories=no, fullscreen=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=yes, toolbar=no");
	// set focus on a new window
	oPictureWindow.focus();
}

function right(e) {
	if (navigator.appName == "Netscape" && (e.which == 3 || e.which == 2))
		return false;
	else if (navigator.appName == "Microsoft Internet Explorer" && (event.button == 2 || event.button == 3)) {
		alert("Sorry, you do not have permission to right click.");
		return false;
	}
	return true;
}

function startHighlight(gvw_name) {
	var gvw = document.all(gvw_name);
	if (gvw != null) {
		// get a reference to the tbody element 
		var tbody = gvw.childNodes[0];
		for (i = 1; i < tbody.childNodes.length; i++) {
			var node = tbody.childNodes[i];
			if (node.nodeName == "TR") {
				node.onmouseover = function() {
					this.className = "over";
				}
				node.onmouseout = function() {
					this.className = this.className.replace("over", "");
				}
			}
		}
	}
}

function getCookie(name) {
	var start = document.cookie.indexOf(name + '=');
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(';', len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
}

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + '=' + escape(value) +
        ((expires) ? ';expires=' + expires.toGMTString() : '') +
        ((path) ? ';path=' + path : '') +
        ((domain) ? ';domain=' + domain : '') +
        ((secure) ? ';secure' : '');
}

// *** start movable popup
function movemouse(e) {
	if (isdrag) {
		dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
		dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
		return false;
	}
}

function selectmouse(e) {
	var fobj = nn6 ? e.target : event.srcElement;
	var topelement = nn6 ? "HTML" : "BODY";

	if (fobj.className == "dragme") {
		isdrag = true;
		dobj = document.getElementById(fobj.box);
		tx = parseInt(dobj.style.left + 0);
		ty = parseInt(dobj.style.top + 0);
		x = nn6 ? e.clientX : event.clientX;
		y = nn6 ? e.clientY : event.clientY;
		document.onmousemove = movemouse;
		return false;
	}
}

function closePopup(box) {
	var hfPopupState = document.getElementById("hfPopupState");
	var div = document.getElementById(box);
	// set the flag
	hfPopupState.value = "hidden";
	// close popup
	div.style.visibility = "hidden";
}
// *** end moveable popup

