
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;
    }
}

// -- 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 hidelink(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;
    }
}

//home page image on refresh rotator
function ImageRotator() {
    var low = 0;
    var high = 10;
    var curr = 0;
    GetRandomNumber();
    RoundIt();

    curr = RoundIt();

    if (curr < low)
    { curr = low }
    if (curr > high)
    { curr = high }

    var dir = "images/";
    var images = new Array(10);

    
    images[00] = "home_challenger.jpg";
    images[01] = "home_wrangler.jpg";
    images[02] = "home_charger.jpg";
    images[03] = "home_300.jpg";
    images[04] = "home_cherokee.jpg";
    images[05] = "home_ramhd.jpg";
    images[06] = "home_ramhd2.jpg";
    images[07] = "home_srt.jpg";
    images[08] = "home_journey.jpg";
    images[09] = "home_2011grandcherokee.jpg";
    images[10] = "home_ram.jpg";


    //alert(images[curr]);
    //document.write("\<img src=\"" + dir + images[curr] + "\">");
    //document.write("\<td valign=\"top\" background=\"" + dir + images[curr] + " style=\"background-repeat:no-repeat\"\>");
    //document.write("\<td valign=\"top\" background=\"" + dir + images[curr] + "\"style=background-repeat:no-repeat\>");
    document.write("\<img src=\"images/home/" + images[curr] + "\" width=\"920\" height=\"310\"\>")
}

function GetRandomNumber() {
    return Math.random() * 17
}

function RoundIt() {
    return Math.round(GetRandomNumber())
}
//end header rotator


// -- CUSTOM FUNCTIONS ---------------------------------------------------------------------------</>-

// 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"
}