﻿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);
}

function CartClose() {
    var width = getClientWidth();
    if (width < minWidth) { width = minWidth }
    var control = document.getElementById("ctl00_MainBody_Xaml");
    control.Content.Page.JavascriptClose();
}

function ScrollCart(e) {
    var y = f_scrollTop();
    var control = document.getElementById("ctl00_MainBody_Xaml");
    control.Content.Cart.FloatCart(y);
    return y;
}

function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

if (window.addEventListener) {
    window.addEventListener('scroll', function(e) { ScrollCart() }, false);
} else if (document.addEventListener) {
    document.addEventListener('scroll', function(e) { ScrollCart() }, false);
} else if (window.attachEvent) {
    window.attachEvent('onscroll', function(e) { ScrollCart() } );
}

