
var lastMouseX;
var lastMouseY;
var curPopupWindow = null;
var curPopunderWindow = null;

function manualSubmit(action) {
    var f = document.forms[0];
    f.action = action
    f.submit();
}

function mouseCursor(cursor) {
    var el = event.srcElement;
    switch (cursor) {
        case "hand":
            el.style.cursor = "hand";
            break
        default:
            el.style.cursor = "default";
    }
}

// cross browser compatible
function changeCursor(cursor, evt) {
    evt = (evt) ? evt : event;
    var el = (evt.target) ? evt.target : event.srcElement;

    switch (cursor) {
        case "hand":
            el.style.cursor = "pointer"; // for modzilla, don't change order
            el.style.cursor = "hand"; // for ie
            break
        default:
            el.style.cursor = "";
    }
}

function openPopup(url, name, width, height, features, snapToLastMousePosition) {
    closePopup();
    if (snapToLastMousePosition) {
        if (lastMouseX - width < 0) lastMouseX = width;
        if (lastMouseY + height > screen.height) lastMouseY -= (lastMouseY + height + 50) - screen.height;
        lastMouseX -= width;
        lastMouseY += 10;
        features += "screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
    }
    curPopupWindow = window.open(url, name, features, false);
}

function setLastMousePosition(evt) {
    evt = (evt) ? evt : event;
    lastMouseX = evt.screenX;
    lastMouseY = evt.screenY;
}

function closePopup() {
    if (curPopupWindow != null) {
        if (!curPopupWindow.closed) curPopupWindow.close();
        curPopupWindow = null;
    }
}

function popUp_Scroll(url, name, width, height) {
    openPopup(url, name, width, height, "width=" + width + ",height=" + height + ",dependent=no,resizable=yes,toolbar=no,status=yes,directories=no,menubar=no,scrollbars=1", false);
}

function popUp(url, name, width, height) {
    openPopup(url, name, width, height, "width=" + width + ",height=" + height + ",dependent=no,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0", false);
}

function popUp_Snap(url, name, width, height) {
    openPopup(url, name, width, height, "width=" + width + ",height=" + height + ",dependent=no,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0", true);
}

function popUnder(url, name, width, height) {
    closePopunder();
    curPopunderWindow = window.open(url, name, "width=" + width + ",height=" + height + ",dependent=no,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0");
    curPopunderWindow.blur();
    window.focus();
}

function closePopunder() {
    if (curPopunderWindow != null) {
        if (!curPopunderWindow.closed) curPopunderWindow.close();
        curPopunderWindow = null;
    }
}
function pick(field, val) {
    var f = document.forms[0];
    f[field].value = val;
    closePopup();
    return false;
}
// -- CUSTOM FUNCTIONS ---------------------------------------------------------------------------</>-
// Absolute Div Close Funtion
//this version doesn't block out the flash links on home pages when it's hidden
//use showlinkSize function below if you close the div using this version.

function hidelinkSize(layername) {

    if (!document.getElementById) return

    if (layername.style.visibility == "visible") {
        layername.style.visibility = "hidden";
        layername.style.top = "-9999px";
        layername.style.height = "0px";
        layername.style.width = "0px";

    }
    else {
        layername.style.visibility = "hidden";
        layername.style.top = "-9999px";
        layername.style.height = "0px";
        layername.style.width = "0px";
    }
}

// Div pop up Funtion
//needs input parameters to set size and distace to restore placement - if closed using the close script above, it has moved it off screen.
//call like this: showlinkSize(document.getElementById('Promo2'), '150px', '640px', '260px')
function showlinkSize(layername, topUnit, divWidth, divHeight) {

    if (!document.getElementById)
        return

    if (layername.style.visibility == "hidden") {
        layername.style.visibility = "visible";
        layername.style.top = topUnit;
        layername.style.height = divHeight;
        layername.style.width = divWidth;
    }
    else {
        layername.style.visibility = "visible";
        layername.style.top = topUnit;
        layername.style.height = divHeight;
        layername.style.width = divWidth;
    }
}
// Div pop up Funtion

function showlink(layername) {

    if (!document.getElementById)
        return
    if (layername.style.visibility == "hidden")
        layername.style.visibility = "visible"
    else
        layername.style.visibility = "visible"
}

// Absolute Div Close Funtion

function hidelink(layername) {

    if (!document.getElementById)
        return
    if (layername.style.visibility == "visible")
        layername.style.visibility = "hidden"
    else
        layername.style.visibility = "hidden"
}

//start bodyshop referral functions
function bodyshopreferral() {

    if ((document.forms[0].Zip.value).length == 5) {
        switch (document.forms[0].Zip.value) {

            //bremerton 
            case '98310':
            case '98311':
            case '98312': { window.location.href = "default.aspx?html=bodyshop-bremerton.html&s=bodyshop-referral"; break }

                //gig harbor
            case '98359':
            case '98329':
            case '98335':
            case '98332': { window.location.href = "default.aspx?html=bodyshop-gigharbor.html&s=bodyshop-referral"; break }

                //kent auburn
            case '98001':
            case '98002':
            case '98031':
            case '98092':
            case '98032': { window.location.href = "default.aspx?html=bodyshop-kent-auburn.html&s=bodyshop-referral"; break }

                //north puyallup
            case '98404':
            case '98354':
            case '98371':
            case '98372':
            case '98390':
            case '98443':
            case '98444':
            case '98445': { window.location.href = "default.aspx?html=bodyshop-north-puyallup.html&s=bodyshop-referral"; break }

                //olympia
            case '98501':
            case '98503':
            case '98506':
            case '98512':
            case '98513':
            case '98516': { window.location.href = "default.aspx?html=bodyshop-olympia.html&s=bodyshop-referral"; break }

                //tacoma north
            case '98403':
            case '98405':
            case '98406':
            case '98407':
            case '98408':
            case '98409':
            case '98418':
            case '98465':
            case '98466': { window.location.href = "default.aspx?html=bodyshop-tacoma-north.html&s=bodyshop-referral"; break }

                //tacoma south
            case '98467':
            case '98433':
            case '98438':
            case '98327':
            case '98498':
            case '98499': { window.location.href = "default.aspx?html=bodyshop-tacoma-south.html&s=bodyshop-referral"; break }

                //portorchard
            case '98367':
            case '98366': { window.location.href = "default.aspx?html=bodyshop-portorchard.html&s=bodyshop-referral"; break }

                //poulsbo
            case '98346':
            case '98342':
            case '98340':
            case '98339':
            case '98110':
            case '98325':
            case '98365':
            case '98392':
            case '98370': { window.location.href = "default.aspx?html=bodyshop-poulsbo.html&s=bodyshop-referral"; break }

                //sequim portangeles
            case '98362':
            case '98363':
            case '98368':
            case '98376':
            case '98382': { window.location.href = "default.aspx?html=bodyshop-sequim-portangeles.html&s=bodyshop-referral"; break }

                //silverdale
            case '98315':
            case '98383': { window.location.href = "default.aspx?html=bodyshop-silverdale.html&s=bodyshop-referral"; break }

                //south 512
            case '98338':
            case '98360':
            case '98328':
            case '98387':
            case '98373':
            case '98374':
            case '98375':
            case '98446': { window.location.href = "default.aspx?html=bodyshop-south-512.html&s=bodyshop-referral"; break }

                //yelm
            case '98558':
            case '98576':
            case '98580':
            case '98589':
            case '98597': { window.location.href = "default.aspx?html=bodyshop-yelm.html&s=bodyshop-referral"; break }

                //fife north same as tacoma north for now
            case '98421':
            case '98422':
            case '98424':
            case '98003':
            case '98023': { window.location.href = "default.aspx?html=bodyshop-tacoma-north.html&s=bodyshop-referral"; break }

            default: document.getElementById("msg").innerHTML = "<br /><b><font color='#999999'>Your zip code is not located near any of our recommended bodyshops.<br /> Please enter another 5 digit zip code below:</font></b><br>";

        }
    }


    else
        document.getElementById("msg").innerHTML = "<br /><b><font color='#999999'>You must enter a 5 digit zip code.<br />Please enter a 5 digit zip code below:</font></b><br>";
}

//checkenter function to enable enter key for bodyshop referral form
function checkEnter(e) { //e is event object passed from function invocation
    var characterCode //literal character code will be stored in this variable

    if (e && e.which) { //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else {
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
        // document.forms[0].submit() //submit the form

        bodyshopreferral();
        return false
    }
    else {
        return true
    }

}
//end bodyshop referral 

