var isIE = document.all && document.getElementById;

function formSubmit(formAction, actionValue, pre) {
    var doSubmit = eval(pre);
    if (doSubmit)
    {
        formRef.action = formAction;
        formRef.actionValue.value = actionValue;
    }
    else
    {
        return false;
    }
}

function go()
{
    return true;
}

function selectMasthead(bounce) {
    var header = document.getElementById("masthead")
    var select = parseInt(getCookie("masthead"));
    //var select = 5;
    var form1 = document.getElementById("form1");
    if (isNaN(select) || select < 0) {
        select = Math.round(Math.random() * 5);
        if (form1 != null) {
            setSelectedRadio(form1.change, -1);
        }
    } else {
        if (form1 != null) {
            setSelectedRadio(form1.change, select);
        }
    }
    switch (select) {
        case 0:
            header.style.backgroundImage = "url(/images/kangaroo.jpg)";
            header.style.height = "134px";
            break;
        case 1:
            header.style.backgroundImage = "url(/images/sheep.jpg)";
            header.style.height = "123px";
            break;
        case 2:
            header.style.backgroundImage = "url(/images/bridge.jpg)";
            header.style.height = "115px";
            break;
        case 3:
            header.style.backgroundImage = "url(/images/mountain.jpg)";
            header.style.height = "135px";
            break;
        case 4:
            header.style.backgroundImage = "url(/images/me_masthead.jpg)";
            header.style.height = "130px";
            break;
        case 5:
            header.style.backgroundImage = "url(/images/shadow.jpg)";
            header.style.height = "130px";
            break;
    }

    if (bounce) {
        document.getElementById("top").focus();
    }

}


function setPermMasthead(select) {
    setPermCookie("masthead", select);
    selectMasthead(true);
}

function setPermCookie(name, value) {
    var now = new Date();
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + value + "; expires=" + now.toGMTString();

}

function setCookie(name, value) {
    document.cookie = name + "=" + value;
}

function getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return(setStr);
}

function setSelectedRadio(radioRef, value) {
    for (var i = 0; i < radioRef.length; i++) {
        if (radioRef[i].value == value) {
            radioRef[i].checked = true;
        }
    }
}

function popupWindow(url, winName, features) {
    window.open(url, winName, features);
}

function blankTarget(link) {
    window.open(link.href, '_blank');
    return false;
}


function isBlank(string) {
    for (var i = 0; i < string.length; i++) {
        var c = string.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) {
            return false;
        }
    }
    return true;
}

function getStyleNum(style) {
    return parseInt(style.split("px")[0]);
}


function showPicture(event, id) {
    if (!event) {
        event = window.event;
    }

    if (isIE) {
        scrollX = document.body.scrollLeft;
        scrollY = document.body.scrollTop;
    } else {
        scrollX = window.pageXOffset;
        scrollY = window.pageYOffset;
    }


    var photo = document.getElementById("photo" + id);
    if ((event.clientX + scrollX + 170) > document.body.clientWidth) {
        photo.style.left = (event.clientX + scrollX - 170) + "px";
    } else {
        photo.style.left = (event.clientX + scrollX + 20) + "px";
    }
    if ((event.clientY + scrollY + 170) > document.body.clientWidth) {
        photo.style.top = (event.clientY + scrollY - 130) + "px";
    } else {
        photo.style.top = (event.clientY + scrollY - 10) + "px";
    }


    photo.style.visibility = "visible";

}

function hidePicture(event, id) {
    var photo = document.getElementById("photo" + id);
    photo.style.visibility = "hidden";
}

function cancelBubbling(event) {
    if (!event) {
        event = window.event;
    }
    event.cancelBubble = true;
    if (event.stopPropagation) {
        event.stopPropagation();
    }
}

