
String.prototype.trim = function()
{
    var str = this;
    str = str.replace(/^\s*(.*)/, "$1");
    str = str.replace(/(.*?)\s*$/, "$1");
    return str;
}

String.prototype.lTrim = function()
{
    var str = this;
    str = str.replace(/^\s*(.*)/, "$1");
    return str;
}

String.prototype.rTrim = function()
{
    var str = this;
    str = str.replace(/(.*?)\s*$/, "$1");
    return str;
}

function listLen(list)
{
    var delimeter = "";
    if (arguments[1] == null) delimeter = ",";
    else delimeter = arguments[1];

    var tempArray = list.split(delimeter);
    return tempArray.length;
}

function listGetAt(list, position)
{
    var delimeter = "";
    if (arguments[2] == null) delimeter = ",";
    else delimeter = arguments[2];

    var tempArray = list.split(delimeter);
    if (position >= tempArray.length) {
        return "";
    } else {
        return tempArray[position];
    }
}

function listSetAt(list, position, newValue)
{
    var delimeter = "";
    if (arguments[3] == null) delimeter = ",";
    else delimeter = arguments[3];

    var tempArray = list.split(delimeter);
    tempArray[position] = newValue;
    return tempArray.join(delimeter);
}

/* this got really stupid because IE started getting a 'Pure Virtual Function Call' error upon switching the image */
function switchCarImage(index)
{
    try {
        for (var i = 0; i < carImages.length; i++) {
            if (i == index) {
                document.getElementById('carImage').src = carImages[i];
                document.getElementById(carImageCaptions[i]).style.display = 'inline';
            } else {
                document.getElementById(carImageCaptions[i]).style.display = 'none';
            }
        }
    } catch (e) {}
}
