var popWin = null;
var lastMouseX;
var lastMouseY;
var isIE = navigator.appName.indexOf("Microsoft") != -1;

function clearText(thefield) {
    if (thefield.defaultValue  == thefield.value)
        thefield.value = ""
}

function clearText2(thefield, defaultValue) {
    if (defaultValue == thefield.value)
        thefield.value = ""
}

function setDefault(thefield, defaultValue) {
    if (thefield.value == "")
        thefield.value = defaultValue;  
}


function calendar(idDate) {
    url = 'PopupCal.aspx?idDate=' + idDate + '&selected=' + document.forms[0].elements[idDate].value;
    openWin(url, "S", 195, 150, 0, 0, 0);
}

// Open Popup window
function popupWin(type, url) {
    switch (type) {
        case "VIEW": openWin(url, "T", 500, 400, 1, 0, 0); return;
        case "MOREPICT": openWin(url, "T", 850, 700, 1, 0, 0); return;
        case "SAVE": openWin(url, "C", 400, 200, 1, 0, 1); return;
        case "EVENT": openWin(url, "C", 500, 350, 1, 0, 1); return;
        default: openWin(url, "C", 500, 400, 1, 0, 0);
    }
}

// Open Popup Window
function openWin(url, pos, width, height, scrollbar, toolbar, resize) {
    var top = 0;
    var left = 0;
    if (pos == "C") {
        top = ((screen.height - 100) - height) / 2;
        left = ((screen.width - 100) - width) / 2;
    }
    else if (pos == "R") {
        top = 0;
        left = (screen.width - width + 25);
    }
    else // Snap to Mouse Position
    {
        if (lastMouseX - width < 0) lastMouseX = width;
        if (lastMouseY + height > screen.height) lastMouseY -= (lastMouseY + height + 50) - screen.height;
        lastMouseX -= width;
        lastMouseY += 10;
        top = lastMouseY;
        left = lastMouseX;
        moreFeat = ",screenX=" + lastMouseX + ",screenY=" + lastMouseY;
    }
    var sFeatures = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",scrollbars=" + scrollbar + ",toolbars=" + toolbar + ",resizable=" + resize;
    if (popWin && !popWin.closed) popWin.close();
    popWin = window.open("", "", sFeatures);
    if (url != "") popWin.location.href = url;
}

function setLastPos(e) {
    if (isIE) e = window.event;
    lastMouseX = e.screenX;
    lastMouseY = e.screenY;
}

function initPage() {
    window.status = "";
}

function exitPage() {
    if (popWin && !popWin.closed) popWin.close();
}

window.onload = initPage;
window.onunload = exitPage;
// End of Script//
