

function checkSize(sFilename) {
    var fiveMeg = 5242880;
    var tooBig = false;
    var img = new Image(); //Create a temporary image
    img.src = "file:///" + sFilename;

    var startLoad = new Date(); //store when we start loading the temp image
    var endLoad = new Date(); //store when we finish loading the temp image
    if (img.fileSize === -1) {
        return true;
    }
    do //wait until the image is loaded or we timeout...
    {
        endLoad = new Date();
    } while (img.fileSize === -1 && (endLoad.getTime() - startLoad.getTime()) / 1000 < 10);


    if (img.fileSize > 0) //check the size and that the image has loaded properly
    {
        if (img.fileSize > fiveMeg) {
            tooBig = true;
        }
    }
    else {
        tooBig = true;
    }

    return !tooBig
}


//rollover rotating image
function getlayer(layername) {
    var theLayer;
    if (document.layers) {
        theLayer = document.layers[layername];
    } else {
        if (document.getElementById) {
            theLayer = document.getElementById(layername);
        } else {
            theLayer = document.all[layername];
        }
    }
    return theLayer;
}

if (typeof(FR) == "undefined") {
    FR = {};
}

FR.showModalPopup = function(behaviourID) {
    var modalPopupBehavior = $find(behaviourID);
    if (modalPopupBehavior) {
        modalPopupBehavior.show();
    }
};
FR.hideModalPopup = function(behaviourID) {
    var modalPopupBehavior = $find(behaviourID);
    if (modalPopupBehavior) {
        modalPopupBehavior.hide();
    }
};


function layeron(slayer, dispBlock) {
    if (slayer) {
        if (document.layers) {
            slayer.visibility = "visible";
        } else {
            slayer.style.visibility = "visible";
            if (dispBlock) {
                slayer.style.display = "block";
            } else {
                slayer.style.display = "inline";
            }
        }
    }
}

function layeroff(slayer) {
    if (slayer) {
        if (document.layers) {
            slayer.visibility = "hide";
        } else {
            slayer.style.visibility = "hidden";
            slayer.style.display = "none";
        }
    }
}

function request(var_name) {
    var loc = document.location.href;
    if (loc.toLowerCase().indexOf(var_name) <= 0) {
        return '';
    } else if (loc.toLowerCase().indexOf('&', loc.toLowerCase().indexOf(var_name)) <= 0) {
    return loc.substring(loc.toLowerCase().indexOf(var_name) + var_name.length + 1);
    } else {
    return loc.substring(loc.toLowerCase().indexOf(var_name) + var_name.length + 1, loc.toLowerCase().indexOf('&', loc.toLowerCase().indexOf(var_name)));
    }
}



// To cover IE 5.0's lack of the push method
Array.prototype.push = function() {
    var n = this.length >>> 0;
    for (var i = 0; i < arguments.length; i++) {
        this[n] = arguments[i];
        n = n + 1 >>> 0;
    }
    this.length = n;
    return n;
};

var allSelected = true;
function SelectAllOrNone() {
    var allCheckBoxes;
    if (allSelected === true) {
        allCheckBoxes = document.getElementsByTagName("input");
        for (i = 0; i < allCheckBoxes.length; i++) {
            if (allCheckBoxes[i].type == 'checkbox') {
                allCheckBoxes[i].checked = false;
            }
        }
        allSelected = false;
    }
    else {
        allCheckBoxes = document.getElementsByTagName("input");
        for (i = 0; i < allCheckBoxes.length; i++) {
            if (allCheckBoxes[i].type == 'checkbox') {
                allCheckBoxes[i].checked = true;
            }
        }
        allSelected = true;
    }
}

function URLEncode(sStr) {
    // 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 plaintext = sStr;
    var encoded = "";
    for (var i = 0; i < plaintext.length; i++) {
        var ch = plaintext.charAt(i);
        if (ch === " ") {
            encoded += "+"; 			// x-www-urlencoded, rather than %20
        } else if (SAFECHARS.indexOf(ch) != -1) {
            encoded += ch;
        } else {
            var charCode = ch.charCodeAt(0);
            if (charCode > 255) {
                encoded += "+";
            } else {
                encoded += "%";
                encoded += HEX.charAt((charCode >> 4) & 0xF);
                encoded += HEX.charAt(charCode & 0xF);
            }
        }
    }
    return encoded;
}

function URLDecode(sStr) {

    var HEXCHARS = "0123456789ABCDEFabcdef";
    var encoded = sStr;
    var plaintext = "";
    var i = 0;
    while (i < encoded.length) {
        var ch = encoded.charAt(i);
        if (ch == "+") {
            plaintext += " ";
            i++;
        } else if (ch == "%") {
            if (i < (encoded.length - 2) &&
					HEXCHARS.indexOf(encoded.charAt(i + 1)) != -1 &&
					HEXCHARS.indexOf(encoded.charAt(i + 2)) != -1) {
                plaintext += unescape(encoded.substr(i, 3));
                i += 3;
            } else {
                alert('Bad escape combination near ...' + encoded.substr(i));
                plaintext += "%[ERROR]";
                i++;
            }
        } else {
            plaintext += ch;
            i++;
        }
    }
    return plaintext;
}


function notSameChar(value) {
    if (value.length === 0) { return true; }
    var ch = value.charAt(0);
    var ret = false;
    for (i = 1; i < value.length; i++) {
        var chartest = value.charAt(i);
        if (ch != chartest) {
            ret = true;
            break;
        }
    }
    return ret;
}

function validateIsGreaterThanValue(value, element, params) {

    if (value.length === 0) { return true; }
    return (value > params);
}


(function() {
    function toArray(pseudoArray) {
        var result = [];
        for (var i = 0; i < pseudoArray.length; i++) {
            result.push(pseudoArray[i]);
        }
        return result;
    }
    Function.prototype.bind = function(object) {
        var method = this;
        var oldArguments = toArray(arguments).slice(1);
        return function() {
            var newArguments = toArray(arguments);
            return method.apply(object, oldArguments.concat(newArguments));
        };
    };
    Function.prototype.bindEventListener = function(object) {
        var method = this;
        var oldArguments = toArray(arguments).slice(1);
        return function(event) {
            return method.apply(object, event || window.event, oldArguments);
        };
    };
})();

Function.prototype.inherits = function(superclass) {
    var c = function() { };
    c.prototype = superclass.prototype;
    this.prototype = new c();
};


String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
};

function trim(string) {
    return string.replace(/^\s+|\s+$/g, "");
}
