﻿// This is a global ready function and it gets applied to all pages.
// if a page specific version is needed then the script should be embedded
// in either another script document referenced from the page, or 
// referenced in the page itself.
$(document).ready(function () {

});

/// Handles silverlight errors.
function onSilverlightError(sender, args) {
    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }

    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    if (errorType == "ImageError" || errorType == "MediaError") {
        return;
    }

    var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}

// Highlights the object, specified by id, with a blue border.
function highlightEditableObject(objectId) {
    
    // Simply add border to the object using jquery.
    $("#" + objectId).css("border", "solid 1px #0000ff");
}

// Highlights the object, specified by id, with a blue border.
function resetEditableObject(objectId) {

    // Simply add border to the object using jquery.
    $("#" + objectId).css("border", "none");
}
