
function cmsWindowOpenLink(pThis, pName, pFeatures, pReplace) {
    var oNewWindow = window.open(pThis.href, pName, pFeatures, pReplace);
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsWindowOpen(pUrl, pName, pFeatures, pReplace) {
    var oNewWindow = window.open(pUrl, pName, pFeatures, pReplace);
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
    }
}

function cmsPopupImage(pUrl, pName) {
    var oNewWindow = window.open(pUrl, pName, 'directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsPopupImageSmall(pUrl, pName) {
    var oNewWindow = window.open(pUrl, pName, 'height=250,width=250,directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsPopupAnchor(pAnchor, pName) {
    var oNewWindow = window.open(pAnchor.href, pName, 'directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}


function cmsPopupAnchorSmall(pAnchor, pName) {
    var oNewWindow = window.open(pAnchor.href, pName, 'height=250,width=250,directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsPopupAnchorMedium(pAnchor, pName) {
    var oNewWindow = window.open(pAnchor.href, pName, 'height=450,width=800,directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsPopupAnchorMediumWidthQSPopup(pAnchor, pName) {
    var sHref = pAnchor.href;
    if(sHref.indexOf('?') != -1)
    {
        sHref = sHref + '&Popup=1';
    }
    else
    {
        sHref = sHref + '?Popup=1';
    }

    var oNewWindow = window.open(sHref, pName, 'height=450,width=800,directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsGetKb(pBytes) {
    var num = 0.00;
    num = (parseInt(pBytes) / 1024);
    var s = num.toFixed(2) + "kb";
    return s;
}

function cmsIsImage(pFile) {
    var re = /^\S+\.(gif|jpg|jpeg|png)$/i;
    return re.test(pFile);
}

function cmsScrubUrlName(pValue) {
    var c = ' "\'&:*%+;?';
    var s = "";
    
    for (var i = 0; i < c.length; i++) {
        s = c.substr(i, 1);
        pValue = pValue.replace(s, '-');
    }
    return pValue;
}

function tbClearEntry(pThis, pValue) {
    if (pThis.value == pValue) {
        pThis.value = '';
    }
}

function fnTrapEnterKD(btnId, e) {
    var btn = document.getElementById(btnId);
    var key;

    if (btn == null) {
        return;
    }

    if (window.event) {
        //IE
        key = window.event.keyCode;
        if (key == 13) {
            btn.click();
            event.keyCode = 0;
        }
    }
    else {
        //firefox
        key = e.which;
        if (key == 13) {
            btn.click();
        }
    }
}

function IsValidEmail(pEmail)
{
    if (pEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
        return true;
    }
    else {
        return false;
    }
}

function IsValidObjEmail(pTexbox) {

    var string = pTextbox.value;
    
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
        return true;
    }
    else {
        return false;
    }
}

function ToggleRadioButton(pID) {
    $("#" + pID + " input[type='radio']").each(function() {
        this.checked = !this.checked;
    });
}

function ToggleCheckBox(pID) {
    $("#" + pID + " input[type='checkbox']").each(function() {
        this.checked = !this.checked;
    });
}

function RandomBetween(p1, p2) {
    var rand_no = Math.floor((p2 - (p1 - 1)) * Math.random()) + p1;
    return rand_no;
}

function AlwaysTrue() {
    return true;
}

function AlwaysFalse() {
    return false;
}

function aTxMouseOver(pId)
    {
       $("#" + pId).css({ display: 'block' });
    }

function aTxMouseOut(pId)
{
   $("#" + pId).css({ display: 'none' });
}

function fcmOK(pThis,pId,pWord,pTx) {
    $("#fctd" + pId).css({ display: 'none' });
    var words = $("#divFlashCardCorrect").html();
    if (words == "") {
        $("#divFlashCardCorrect").html(pWord + " - " + pTx);
    } else {
    $("#divFlashCardCorrect").html(words + "<br />" + pWord + " - " + pTx);
    }

    var c = parseInt($("#spanFlashCardCorrect").html());
    
    c++;
    $("#spanFlashCardCorrect").html(c);
    
    var t = parseInt($("#spanFlashCardTotal").html());

    if(c >= t)
    {
        $("#divFlashCardCompleted").css({display:'block'});
    }
}
    
// lessons
function Response_OnTimeOut(arg) {
    alert("TimeOut encountered.");
    return false;
}

function Response_OnError(arg) {
    alert("Error encountered: " + arg);
    return false;
}
// end lessons

if (typeof Array.prototype.copy === 'undefined') {
    Array.prototype.copy = function() {
        var a = [], i = this.length;
        while (i--) {
            a[i] = typeof this[i].copy !== 'undefined' ? this[i].copy() : this[i];
        }
        return a;
    };
}

//This prototype is provided by the Mozilla foundation and is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license


if (!Array.prototype.filter) {
    Array.prototype.filter = function(fun /*, thisp*/) {
    var len = this.length;
    if (typeof fun != "function")
        throw new TypeError();
    var res = new Array();
    var thisp = arguments[1]; 
        for (var i = 0; i < len; i++) {
            if (i in this) {
                var val = this[i]; // in case fun mutates this
                if (fun.call(thisp, val, i, this))
                    res.push(val);
            }
        }
        return res;
    };
}

if (!Array.prototype.every) {
    Array.prototype.every = function(fun /*, thisp*/) {
    var len = this.length;
    if (typeof fun != "function")
        throw new TypeError();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
        if (i in this && !fun.call(thisp, this[i], i, this))
            return false;
    }
    return true;
    };
}

if (!Array.prototype.forEach) {
    Array.prototype.forEach = function(fun /*, thisp*/) {
    var len = this.length;
    if (typeof fun != "function")
        throw new TypeError();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
        if (i in this)
            fun.call(thisp, this[i], i, this);
    }
    };
}

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(elt /*, from*/) {
    var len = this.length;
    var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from);
    if (from < 0) from += len;
    for (; from < len; from++) {
        if (from in this && this[from] === elt)
            return from;
    } return -1;
    };
}

if (!Array.prototype.lastIndexOf) {
    Array.prototype.lastIndexOf = function(elt /*, from*/) {
    var len = this.length;
    var from = Number(arguments[1]);
    if (isNaN(from)) { from = len - 1; }
    else {
        from = (from < 0) ? Math.ceil(from) : Math.floor(from);
        if (from < 0) from += len;
        else if (from >= len) from = len - 1;
    }
    for (; from > -1; from--) {
        if (from in this && this[from] === elt)
            return from;
    }
    return -1;
    };
}

if (!Array.prototype.map) {
    Array.prototype.map = function(fun /*, thisp*/) {
    var len = this.length;
    if (typeof fun != "function")
        throw new TypeError();
    var res = new Array(len);
    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
        if (i in this)
            res[i] = fun.call(thisp, this[i], i, this);
    } return res;
    };
}

if (!Array.prototype.some) {
    Array.prototype.some = function(fun /*, thisp*/) {
        var len = this.length;
        if (typeof fun != "function")
            throw new TypeError();

        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this &&
          fun.call(thisp, this[i], i, this))
                return true;
        }

        return false;
    };
}

Array.prototype.sortNum = function() {
    return this.sort(function(a, b) { return a - b; });
}

Array.prototype.find = function(searchStr) {
    var returnArray = false;
    for (i = 0; i < this.length; i++) {
        if (typeof (searchStr) == 'function') {
            if (searchStr.test(this[i])) {
                if (!returnArray) { returnArray = [] }
                returnArray.push(i);
            }
        } else {
            if (this[i] === searchStr) {
                if (!returnArray) { returnArray = [] }
                returnArray.push(i);
            }
        }
    }
    return returnArray;
}

Array.prototype.shuffle = function() {
    for (var rnd, tmp, i = this.length; i; rnd = parseInt(Math.random() * i), tmp = this[--i], this[i] = this[rnd], this[rnd] = tmp);
};


Array.prototype.compare = function(testArr) {
    if (this.length != testArr.length) return false;
    for (var i = 0; i < testArr.length; i++) {
        if (this[i].compare) {
            if (!this[i].compare(testArr[i])) return false;
        }
        if (this[i] !== testArr[i]) return false;
    }
    return true;
}

