﻿function preloadImages(imageArray) {
    for (i = 0; i < imageArray.length; i++) {
        var imageX = new Image();
        imageX.src = imageArray[i];
    }
}

function URLEncode(strPlainText) {
    // The Javascript escape and unescape functions do not correspond
    // with what browsers actually do...
    var SAFECHARS = "0123456789" + 				// Numeric
	    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
	    "abcdefghijklmnopqrstuvwxyz" +
	    "-_.!~*'()"; 				// RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";

    var strEncoded = "";
    for (var i = 0; i < strPlainText.length; i++) {
        var ch = strPlainText.charAt(i);
        if (ch == " ") {
            strEncoded += "+"; 			// x-www-urlencoded, rather than %20
        } else if (SAFECHARS.indexOf(ch) != -1) {
            strEncoded += ch;
        } else {
            var charCode = ch.charCodeAt(0);
            if (charCode > 255) {
                /* alert( "Unicode Character '" 
                + ch 
                + "' cannot be encoded using standard URL encoding.\n" +
                "(URL encoding only supports 8-bit characters.)\n" +
                "A space (+) will be substituted." ); */
                strEncoded += "+";
            } else {
                strEncoded += "%";
                strEncoded += HEX.charAt((charCode >> 4) & 0xF);
                strEncoded += HEX.charAt(charCode & 0xF);
            }
        }
    } // for

    return strEncoded;
};

function URLDecode(strEncoded) {
    // Replace + with ' '
    // Replace %xx with equivalent character
    // Add a space to the output if %xx is invalid.
    var HEXCHARS = "0123456789ABCDEFabcdef";
    var strPlainText = "";
    var i = 0;
    while (i < strEncoded.length) {
        var ch = strEncoded.charAt(i);
        if (ch == "+") {
            strPlainText += " ";
            i++;
        } else if (ch == "%") {
            if (i < (strEncoded.length - 2)
		&& HEXCHARS.indexOf(strEncoded.charAt(i + 1)) != -1
		&& HEXCHARS.indexOf(strEncoded.charAt(i + 2)) != -1) {
                strPlainText += unescape(strEncoded.substr(i, 3));
                i += 3;
            } else {
                // alert( 'Bad escape combination near ...' + encoded.substr(i) );
                // strPlainText += "%[ERROR]";
                strPlainText += "%32";
                i++;
            }
        } else {
            strPlainText += ch;
            i++;
        }
    } // while

    return strPlainText;
};

function escapeHTML(strX) {
    var div = document.createElement('div');
    var text = document.createTextNode(strX);
    div.appendChild(text);
    return div.innerHTML;
}

function getBodyClientWidth() {
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}
function getBodyClientHeight() {
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
}

function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}


function isNumeric(valX) {
    valX = valX.replace(/\./g, "");
    valX = valX.replace(/\-/g, "");
    if (valX.match(/^[0-9]+$/)) {
        return true;
    } else {
        return false;
    }
}

if ((Sys.WebForms.PageRequestManager.getInstance()._processingRequest==false)&&(Sys.WebForms.PageRequestManager.getInstance()._request==null)&&(Sys.WebForms.PageRequestManager.getInstance()._postBackSettings==null)) {
    Sys.Application.add_load(funcAppLoad);
}

function funcAppLoad() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
}
function EndRequest(sender, args) {
    if (args.get_error() != undefined) {
        if (args._errorHandled == false) {
            args.set_errorHandled(true);
                top.location = '/SorryPage.aspx?t=' + new Date().getTime() + '&sourceURL=' + args._response._webRequest._url + '&location=' + top.location.href + '&ajaxError=' + args._error.description;
        } 
    }
}

