﻿//Author: Shawn Renner (unless otherwise noted)
//Please do not copy without permission

function showPopup(divID)
{
    document.getElementById(divID).style.display = "block";
    /*var interval = window.setInterval("checkScroll(" + divID + ")", 500);*/
}

function hidePopup(divID)
{
    document.getElementById(divID).style.display = "none";
}

function togglePopup(divID, useVisibility)
{
    var theDiv = document.getElementById(divID);
    if(theDiv.style.display == "block") {
        if (useVisibility)
            theDiv.style.visibility = "hidden";
        else
            theDiv.style.display = "none";
    }
    else {
        if (useVisibility)
            theDiv.style.visibility = "visible";
        else
            theDiv.style.display = "block";
    }
}

function isNumberKey(evt)
{
    var charCode = '';
    if(!evt)
        evt = window.event;
    if(evt.keyCode)
        charCode = evt.keyCode;
    else
        charCode = evt.charCode;
    
    if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46) && (charCode != 9))
        return false;
    return true;
}
function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function addEventHandler(obj, event, onevent, functionToCall) {
    if (obj.addEventListener)
        obj.addEventListener(event, functionToCall, false);
    else
        obj.attachEvent(onevent, functionToCall);
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
function eraseCookie(name) {
    createCookie(name, "", -1);
}
function getCookieCarIndex(options) {
    var currentCar = readCookie("currentCar");
    for (var i = 0; i < options.length; i++) {
        if (options[i].value == currentCar) {
            return i;
        }
    }
    return 0;
}
