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 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("divMemberCompanies");
        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() {
    var hfPopupState = document.getElementById("hfPopupState");
    var divMemberCompanies = document.getElementById("divMemberCompanies");
    // set the flag
    hfPopupState.value = "hidden";
    // close popup
    divMemberCompanies.style.visibility = "hidden";
}
// *** end moveable popup

