﻿

function bookmark(url, title) {
    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
        window.external.AddFavorite(location.href, title);
    } else if (navigator.appName == "Netscape") {
        window.sidebar.addPanel(title, url, "");
    } else {
        alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
    }
}

var KeyValue;
function ProcessJsonValidationResults(containerId, content) {
    var retVal = true;
    var json = jQuery.parseJSON(content);
    var result = eval(json);

    resetValSummary(containerId);

    KeyValue = result.KeyValue;

    if (result.Successful) {
        // all good
    }
    else {
        retVal = false;
        $('#' + containerId + '').prepend('<span><br>' + result.Message + '</span>')

        for (var err in result.Errors) {
            var propertyName = result.Errors[err].PropertyName;
            var errorMessage = result.Errors[err].Error;
            var message = errorMessage;

            $('#' + propertyName.replace(".", "_")).addClass('input-validation-error');
            $('#' + containerId + ' > ul').append('<li>' + message + '</li>');
        }
    }

    return retVal;
}

function resetValSummary(containerId) {
    $(".validation-summary-errors > span").empty();
    $(".validation-summary-errors > ul").empty();
    $("#" + containerId + " > span").empty();
    $("#" + containerId + " > ul").empty();
    $(':input').removeClass('input-validation-error');

}



$(document).ready(function () {
    $("table.sorter").tablesorter({}).bind("sortEnd", function () {
        $('.sorter > tbody > tr').removeClass('alternate');
        $('.sorter > tbody > tr:nth-child(odd)').addClass('alternate');
    });
    $('.sorter > tbody > tr:nth-child(odd)').addClass('alternate');

});

function switchImage(href, newImage, numImgs) {
    var oldImg = document.getElementById("imgMainVehicle");
    var newImg = document.getElementById(newImage);
    oldImg.src = newImg.src.replace(/w=95/, "w=500");
    var fullSizeLink = newImg.src.replace(/w=95/, "w=1200");
    oldImg.parentNode.href = fullSizeLink;
    //resetThumbStyles(numImgs);
   // newImg.parentNode.className = "xthumbNailSelected";
}

function resetThumbStyles(totalImgs) {
    for (i = 1; i <= totalImgs; i++) {
        var thisImg = document.getElementById("img" + i);
        thisImg.parentNode.className = "thumbNailImage";
    }
}

$(function () {
    $('.trig-contact').click(function () {
        var message = $(this).attr('message');
        $('#Message').val(message);
        
        $('#contact-form').dialog({
            resizable: false,
            height: 400,
            width: 350,
            modal: true,
            autoOpen: true,
            show: "fade",
            title: "Request More Information on Trailer" 
        });

        return false;
    });
});
