﻿function BackgroundColor(BGColorDiv) {

    var BGColorElem = document.getElementById(BGColorDiv);
    var Color = BGColorElem.innerHTML;
    
    var StylesNum = (document.styleSheets.length) - 1;

    if (document.styleSheets[0].addRule) {
        document.styleSheets[StylesNum].addRule("body", "background-color:#" + Color);
    }
    else {
        var rulelength = document.styleSheets[StylesNum].cssRules.length;
        document.styleSheets[StylesNum].insertRule("body{background-color:#" + Color + "}", rulelength - 1);
    }
}

function CustomColor(TagName, ElemId, cssName, cssAmount, ColorDiv, StyleTag, RequiresHover) {
    var AllElems = document.getElementsByTagName(TagName);

    var StylesNum = (document.styleSheets.length) - 1;

    if (AllElems) {
        var AllLength = AllElems.length;
        for (i = 0; i < AllLength; i++) {
            var lookin = new RegExp(ElemId);

            if (lookin.test(AllElems[i].id) == true) {
                
                var elemNumber = (parseInt(AllElems[i].id));
                var elemRemainder = elemNumber % cssAmount;
                var cssCombName = cssName + elemRemainder;
                var ColorElem = document.getElementById(ColorDiv + elemRemainder);
                if (ColorElem) {
                    var ColorInner = ColorElem.innerHTML;

                    AllElems[i].className = cssCombName;

                    if (document.styleSheets[0].addRule) {
                        if (RequiresHover) {
                            document.styleSheets[StylesNum].addRule("." + cssCombName + ":hover", "" + StyleTag + ColorInner);
                        }
                        else {
                            document.styleSheets[StylesNum].addRule("." + cssCombName + "", "" + StyleTag + ColorInner);
                        }
                    }
                    else {
                        var rulelength = document.styleSheets[StylesNum].cssRules.length;
                        if (RequiresHover) {
                            document.styleSheets[StylesNum].insertRule("." + cssCombName + ":hover{" + StyleTag + ColorInner + "}", rulelength - 1);
                        }
                        else {
                            document.styleSheets[StylesNum].insertRule("." + cssCombName + "{" + StyleTag + ColorInner + "}", rulelength - 1);
                        }
                    }
                }
            }
        }
    }
}

function CustomColor2(cssName, applyToHover, cssAmount, ColorDiv, StyleTag) {
    var CustomArray;
    if (document.styleSheets[3].cssRules) {
        CustomArray = document.styleSheets[3].cssRules;
    }
    else {
        CustomArray = document.styleSheets[3].rules;
    }

    var cssTag;
    var cssHoverTag;
    var x = 0;
    for (i = 0; i < CustomArray.length; i++) {

        if (CustomArray[i].selectorText == cssName) {
            cssTag = CustomArray[i].style.cssText;
            x++;
        }
        if (CustomArray[i].selectorText == (cssName + ":hover")) {
            cssHoverTag = CustomArray[i].style.cssText;
            x++;
        }
        if (x == 2) {break; }
    }

    for (i = 0; i < cssAmount; i++) {
        var getColor = document.getElementById(ColorDiv + i).innerHTML;
        if (getColor) {
            var newCssName = cssName + "" + i;
            var newCssNameHover = cssName + "" + i + ":hover";

            if (document.styleSheets[3].addRule) {
                if (applyToHover) {
                    document.styleSheets[3].addRule(newCssNameHover, cssHoverTag + "; " + (StyleTag + getColor));
                    document.styleSheets[3].addRule(newCssName, cssTag + "; ");
                }
                else {
                    document.styleSheets[3].addRule(newCssNameHover, cssHoverTag + "; ");
                    document.styleSheets[3].addRule(newCssName, cssTag + "; " + (StyleTag + getColor));
                }
            }
            else {
                var rulelength = document.styleSheets[3].cssRules.length;
                if (applyToHover) {
                    document.styleSheets[3].insertRule(newCssNameHover + "{" + cssHoverTag + " " + (StyleTag + getColor) + ";}", rulelength - 1);
                    document.styleSheets[3].insertRule(newCssName + "{" + cssTag + ";}", rulelength - 1);
                }
                else {
                    document.styleSheets[3].insertRule(newCssNameHover + "{" + cssHoverTag + ";}", rulelength - 1);
                    document.styleSheets[3].insertRule(newCssName + "{" + cssTag + " " + (StyleTag + getColor) + ";}", rulelength - 1);
                }
            }
        }
    }
}

function RandomColor(elemId, cssAmount, cssType) {
    var amount = (cssAmount * 2);
    var num = Math.floor(Math.random() * amount / 2);
    var ColorElem = document.getElementById('ColorDiv' + num);
    if (ColorElem) {
        var elem = document.getElementById(elemId);
        if (elem) {
            if (cssType == "Back") {
                elem.style.backgroundColor = "#" + ColorElem.innerHTML;
            }
            else if (cssType == "Color") {
                elem.style.color = "#" + ColorElem.innerHTML;
            }
            else {
                elem.style.backgroundColor = "#" + ColorElem.innerHTML;
                elem.style.color = "#" + ColorElem.innerHTML;
            }
        }
    }
}

function ApplyColorToLink(elem, number) {

    var elemRemainder = number % 5;

    var ColorElem = document.getElementById('ColorDiv' + elemRemainder).innerHTML;

    var ElemHref = elem.href;

    elem.href = ElemHref + "&Color=" + ColorElem;
}

function ApplyThisColorToLink(elem) {

    var ColorElem = elem.parentNode.style.backgroundColor;
    var ColorHex = RGBtoHEX(ColorElem);

    var ElemHref = elem.href;

    var patt1 = "#";
    var color = ColorHex.replace(patt1, "");

    elem.href = ElemHref + "&Color=" + color;
}

function LogInBackGround(BGColorDiv, LoginDiv, Percent, includeBack, Dir) {
    var Login = document.getElementById(LoginDiv);
    if (Login) {
        var BGDivInner = document.getElementById(BGColorDiv).innerHTML;

        var HalfPercent = Percent / 2;
        HalfPercent = HalfPercent / 100;

        Percent = Percent / 100;

        var patt1;
        patt1 = /\w{1}/;

        var BegR1 = BGDivInner.match(patt1);
        var BegTwo = BGDivInner.replace(patt1, "");
        var BegR2 = BegTwo.match(patt1);
        var BegThree = BegTwo.replace(patt1, "");
        var BegG1 = BegThree.match(patt1);
        var BegFour = BegThree.replace(patt1, "");
        var BegG2 = BegFour.match(patt1);
        var BegFive = BegFour.replace(patt1, "");
        var BegB1 = BegFive.match(patt1);
        var BegSix = BegFive.replace(patt1, "");
        var BegB2 = BegSix.match(patt1);
        if (BegR1 == "A") { BegR1 = 10 }
        if (BegR1 == "B") { BegR1 = 11 }
        if (BegR1 == "C") { BegR1 = 12 }
        if (BegR1 == "D") { BegR1 = 13 }
        if (BegR1 == "E") { BegR1 = 14 }
        if (BegR1 == "F") { BegR1 = 15 }
        if (BegR2 == "A") { BegR2 = 10 }
        if (BegR2 == "B") { BegR2 = 11 }
        if (BegR2 == "C") { BegR2 = 12 }
        if (BegR2 == "D") { BegR2 = 13 }
        if (BegR2 == "E") { BegR2 = 14 }
        if (BegR2 == "F") { BegR2 = 15 }
        if (BegB1 == "A") { BegB1 = 10 }
        if (BegB1 == "B") { BegB1 = 11 }
        if (BegB1 == "C") { BegB1 = 12 }
        if (BegB1 == "D") { BegB1 = 13 }
        if (BegB1 == "E") { BegB1 = 14 }
        if (BegB1 == "F") { BegB1 = 15 }
        if (BegB2 == "A") { BegB2 = 10 }
        if (BegB2 == "B") { BegB2 = 11 }
        if (BegB2 == "C") { BegB2 = 12 }
        if (BegB2 == "D") { BegB2 = 13 }
        if (BegB2 == "E") { BegB2 = 14 }
        if (BegB2 == "F") { BegB2 = 15 }
        if (BegG1 == "A") { BegG1 = 10 }
        if (BegG1 == "B") { BegG1 = 11 }
        if (BegG1 == "C") { BegG1 = 12 }
        if (BegG1 == "D") { BegG1 = 13 }
        if (BegG1 == "E") { BegG1 = 14 }
        if (BegG1 == "F") { BegG1 = 15 }
        if (BegG2 == "A") { BegG2 = 10 }
        if (BegG2 == "B") { BegG2 = 11 }
        if (BegG2 == "C") { BegG2 = 12 }
        if (BegG2 == "D") { BegG2 = 13 }
        if (BegG2 == "E") { BegG2 = 14 }
        if (BegG2 == "F") { BegG2 = 15 }
        var BegR = 0;
        var BegG = 0;
        var BegB = 0;

        BegR1 = BegR1 * 16;
        BegR2 = BegR2 * 1;
        BegR = BegR1 + BegR2;

        BegG1 = BegG1 * 16;
        BegG2 = BegG2 * 1;
        BegG = BegG1 + BegG2;

        BegB1 = BegB1 * 16;
        BegB2 = BegB2 * 1;
        BegB = BegB1 + BegB2;

        if (BegR < 0) { BegR = 0 }
        if (BegG < 0) { BegG = 0 }
        if (BegB < 0) { BegB = 0 }
        if (BegR > 255) { BegR = 255 }
        if (BegG > 255) { BegG = 255 }
        if (BegB > 255) { BegB = 255 }

        var StepR = ((Percent * 256) - (Percent * BegR)) * 4.583;
        var StepG = ((Percent * 256) - (Percent * BegG)) * 4.583;
        var StepB = ((Percent * 256) - (Percent * BegB)) * 4.583;

        var TopR = Math.round(BegR + StepR);
        var TopG = Math.round(BegG + StepG);
        var TopB = Math.round(BegB + StepB);

        var BotR = Math.round(BegR - StepR);
        var BotG = Math.round(BegG - StepG);
        var BotB = Math.round(BegB - StepB);

        var MidStepR = ((HalfPercent * 256) - (HalfPercent * BegR)) * 4.583;
        var MidStepG = ((HalfPercent * 256) - (HalfPercent * BegG)) * 4.583;
        var MidStepB = ((HalfPercent * 256) - (HalfPercent * BegB)) * 4.583;

        if (Dir == "Out") {
            var BackR = Math.round(BegR + MidStepR);
            var BackG = Math.round(BegG + MidStepG);
            var BackB = Math.round(BegB + MidStepB);
        }
        if (Dir == "In") {
            var BackR = Math.round(BegR - MidStepR);
            var BackG = Math.round(BegG - MidStepG);
            var BackB = Math.round(BegB - MidStepB);
        }

        if (TopR < 0) { TopR = 0 }
        if (TopG < 0) { TopG = 0 }
        if (TopB < 0) { TopB = 0 }
        if (TopR > 255) { TopR = 255 }
        if (TopG > 255) { TopG = 255 }
        if (TopB > 255) { TopB = 255 }

        if (BotR < 0) { BotR = 0 }
        if (BotG < 0) { BotG = 0 }
        if (BotB < 0) { BotB = 0 }
        if (BotR > 255) { BotR = 255 }
        if (BotG > 255) { BotG = 255 }
        if (BotB > 255) { BotB = 255 }

        if (BackR < 0) { BackR = 0 }
        if (BackG < 0) { BackG = 0 }
        if (BackB < 0) { BackB = 0 }
        if (BackR > 255) { BackR = 255 }
        if (BackG > 255) { BackG = 255 }
        if (BackB > 255) { BackB = 255 }

        if (Dir == "Out") {
            Login.style.borderRightColor = "rgb(" + BotR + "," + BotG + "," + BotB + ")";
            Login.style.borderBottomColor = "rgb(" + BotR + "," + BotG + "," + BotB + ")";
            Login.style.borderTopColor = "rgb(" + TopR + "," + TopG + "," + TopB + ")";
            Login.style.borderLeftColor = "rgb(" + TopR + "," + TopG + "," + TopB + ")";
        }
        if (Dir == "In") {
            Login.style.borderRightColor = "rgb(" + TopR + "," + TopG + "," + TopB + ")";
            Login.style.borderBottomColor = "rgb(" + TopR + "," + TopG + "," + TopB + ")";
            Login.style.borderTopColor = "rgb(" + BotR + "," + BotG + "," + BotB + ")";
            Login.style.borderLeftColor = "rgb(" + BotR + "," + BotG + "," + BotB + ")";
        }
        if (includeBack) {
            Login.style.backgroundColor = "rgb(" + BackR + "," + BackG + "," + BackB + ")";
        }
    }
}

function ImgSizer(cssName, maxW, maxH) {
    var ImgLength = document.images.length;
    
    for (i = 0; i < ImgLength; i++) {
        if (document.images[i].className == cssName) {
            
            var imgW = document.images[i].width;
            var imgH = document.images[i].height;
            
            if (imgW >= imgH) {
                document.images[i].style.width = maxW + "px";
                document.images[i].style.height = "auto";
            }
            else if (imgH >= imgW) {
                document.images[i].style.height = maxH + "px";
                document.images[i].style.width = "auto";
            }
        }
    }
}

function SeeMe(id, val) {
    var Eid = document.getElementById(id);
    if (Eid) {
        Eid.style.display = val;
    }
}

function SeeMeVis(id, val) {
    var Eid = document.getElementById(id);
    if (Eid) {
        Eid.style.visibility = val;
    }
}

function AddFocus(id) {
    var elem = document.getElementById(id);
    if (elem) {
        elem.focus();
    }
}

function ClearContents(id) {
    var elem = document.getElementById(id);
    if (elem) {
        elem.value = "";
    }
}

function FocusTxt(txtbox, cssName) {
    txtbox.className = cssName;
}

function NoApo(txtbox, e) {
    var txt = txtbox.value;
    var patt1 = /'/gi;
    if (e.keyCode == 222) {
        alert("no apostrophes please");
        txtbox.value = txt.replace(patt1, "");
    }
}

function LogInBoxes(txtbox, fontcolor, fontcolor2, isPass) {
    
    if (txtbox.style.color == fontcolor || txtbox.style.color == fontcolor2) {
        txtbox.value = "";
        txtbox.style.color = "#682ABC";
        if (isPass) {
            var PassBox = document.getElementById("ctl00_LoginView1_Txt_Pass");
            if (!PassBox) { PassBox = document.getElementById("LoginView1_Txt_Pass"); }
            txtbox.style.display = "none";
            PassBox.style.display = "inline";
            PassBox.focus();
        }
    }
}

function SignUpClick(clicktype, clicktypeID, memberUID, receiveID) {
    var ClickTypeE = document.getElementById(clicktypeID);
    if (ClickTypeE) {
        ClickTypeE.value = clicktype;
    }
    
    var Receiver = document.getElementById(receiveID);
    if (Receiver) {
        Receiver.value = memberUID;
    }
}

function InsertNotes(imgid, divid) {
    var Img = document.getElementById(imgid);
    if (Img) {
        var Elem = document.getElementById(divid);
        Elem.innerHTML = Img.title;
    }
}

function Confirm(message, hdn_id) {
    var Hdn = document.getElementById(hdn_id);
    var conf = confirm(message);
    if (!conf) {
        Hdn.value = "False";
    }
    else {
        Hdn.value = "True";
    }
}

function ConfirmRefresh(message) {
    var conf = confirm(message);
    if (conf) {
        return true;
    }
    else {
        window.location = location.href;
    }
}

function NoBlank(txtbox, img, src, altsrc) {
    var imgElem = document.getElementById(img);
    if (txtbox.value != "") {
        imgElem.src = src;
        imgElem.title = ":)";
    }
    else {
        imgElem.src = altsrc;
        imgElem.title = "This field is required";
    }
}

function PassVal(txtbox, img, src, altsrc) {
    var imgElem = document.getElementById(img);
    if (txtbox.value.length >= 7) {

        var patt1 = new RegExp("[0-9]");
        if (patt1.test(txtbox.value) == true) {
            imgElem.src = src;
            imgElem.title = "Password is valid :)";
        }
        else {
            imgElem.src = altsrc;
            imgElem.title = "Passwords must be at least 7 characters including at least 1 Number";
        }
    }
    else {
        imgElem.src = altsrc;
    }
}

function CompVal(txtbox1, txtbox2, img, src, altsrc) {
    var txt1 = document.getElementById(txtbox1);
    var txt2 = document.getElementById(txtbox2);
    var imgElem = document.getElementById(img);
    
    if (txt1.value != "" && txt2.value != "") {
        if (txt1.value == txt2.value) {
            imgElem.src = src;
            imgElem.title = "Password and confirm password match :)";
        }
        else {
            imgElem.src = altsrc;
            imgElem.title = "Password and confirm password do not match :(";
        }
    }
    else {
        imgElem.src = "icons/blank_22.png";
        imgElem.title = "Please enter a password";
    }
}

function BlackBoxExt(elemid) {
    var box = document.getElementById(elemid);
    if (box) {
        var height = document.documentElement.scrollHeight;
        box.style.height = "" + height + "px";
    }
}

var getX = function(evt) {
    if (evt.clientX) {
        return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
    }
    if (evt.pageX) { return evt.pageX; }
}
var getY = function(evt) {
    if (evt.clientY) {
        return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
    }
    if (evt.pageY) { return evt.pageY; }
}
var Movepop = function(evt, id) {
    var hover = document.getElementById(id);
    var hei = document.getElementById(id).offsetHeight;
    hover.style.left = getX(evt) - 15 + "px";
//    hover.style.top = getY(evt) - hei - 11 + "px";
}

var MovepopXY = function(evt, id, xadjust, yadjust) {
    var hover = document.getElementById(id);
    var hei = document.getElementById(id).offsetHeight;
    hover.style.left = getX(evt) + xadjust + "px";
    hover.style.top = getY(evt) - hei + yadjust + "px";
}

var BoxAnim;
var FadeAnim;
var moreH;
var opac = 100;

function ShowMoreDiv(id, hght) {
    BoxAnim = setInterval("AnimDiv('" + id + "', '" + hght + "')", 1);
}

function AnimDiv(id, hght) {
    
    var more = document.getElementById(id);
    moreH = parseInt(more.style.height);

    var intv = 7;
    if ((hght - moreH) < intv) {
        intv = (hght - moreH);
    }
    
    if (moreH < hght) {
        more.style.height = moreH + intv + "px";
    }
    else {
        more.style.height = hght + "px";
        clearInterval(BoxAnim);
    }
}

function ShowLessDiv(event, elem, hght) {
    if (!elem.style) {
        var elem = document.getElementById(elem);
    }
    if (event.type == "mouseout") {
        elem.style.display = "none";
        elem.style.height = "0px";
    }
    else {
        elem.style.display = "block";
        elem.style.height = hght + "px";
    }
    clearInterval(BoxAnim);
}

function setToBottomLeft(staticElem, movingElemID) {
    var movingElem = document.getElementById(movingElemID);

    movingElem.style.top = staticElem.clientHeight + staticElem.offsetTop + 16 + "px";
    movingElem.style.left = staticElem.offsetLeft + "px";
}

function ValAccountEntry(txtbox, Img) {
    var txt = document.getElementById(txtbox);
    if (txt.value !== "") {
        OpacFade(Img, 100, -5);
        SeeMeVis(Img, 'visible');
    }
    else {
        alert("you gotta have a name");
    }
}

function OpacFade(id, initOpac, intdir) {
    var elem = document.getElementById(id);
    elem.style.filter = "alpha(opacity=" + initOpac + ")";
    elem.style.opacity = (initOpac / 100);
    elem.style.MozOpacity = (initOpac / 100);
    elem.style.KhtmlOpacity = (initOpac / 100);
    opac = 100;
    
    FadeAnim = setInterval("AnimOpac('" + id + "','" + intdir + "')", 1);
}

function AnimOpac(id, intdir) {
    var elem = document.getElementById(id);
    
    if (opac <= 100 && opac >= 0) {
        elem.style.filter = "alpha(opacity=" + opac + ")";
        elem.style.opacity = (opac / 100);
        elem.style.MozOpacity = (opac / 100);
        elem.style.KhtmlOpacity = (opac / 100);
        opac = opac + parseInt(intdir);
    }
    else {
        clearInterval(FadeAnim);
    }
}

function IsImageOk(img) {
    if (!img.complete) {
        return false;
    }
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }
    return true;
}

function PageImport(id, url) {
    var req = false;
    // For Safari, Firefox, and other non-MS browsers
    if (window.XMLHttpRequest) {
        try {
            req = new XMLHttpRequest();
        } catch (e) {
            req = false;
        }
    } else if (window.ActiveXObject) {
        // For Internet Explorer on Windows
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                req = false;
            }
        }
    }
    var element = document.getElementById(id);
    if (!element) {
        alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
        return;
    }
    if (req) {
        // Synchronous request, wait till we have it all
        req.open('GET', url, false);
        req.send(null);
        element.innerHTML = req.responseText;
    } else {
    var curdate = new Date()
    var year = curdate.getYear()
    element.innerHTML =
   "Sorry, your browser is WAY too old for my website." +
   " It's " + year + ", which means your browsing the Internet with technology that is more than a decade old.";
    }
}

function CharCountDown(maxChars, txtbox, output) {
    var txt = document.getElementById(txtbox).value;
    var out = document.getElementById(output);
    var txtcount = txt.length;
    if (txtcount <= maxChars) {
        if (out) {
            out.innerHTML = (maxChars - txtcount);
        }
    }
    else {
        document.getElementById(txtbox).value = txt.slice(0, maxChars);
    }
}

function AddLabels(chkboxid, hdnvalueid, txtboxid) {
    var chk = document.getElementById(chkboxid);
    var lbl = document.getElementById(hdnvalueid);
    var txtbox = document.getElementById(txtboxid);

    var txtvalue = txtbox.value;
    var isAdded = new RegExp(lbl.value);

    if (isAdded.test(txtvalue) == false) {
        if (chk.checked) {
            if (txtvalue == "") {
                txtbox.value = lbl.value;
            }
            else {
                txtbox.value = txtvalue + ", " + lbl.value;
            }
        }
    }
    else {
        if (!chk.checked) {
            var FindLbl = new RegExp(lbl.value + ", ");
            var FindLbl2 = new RegExp(lbl.value);
            if (FindLbl.test(txtvalue) == true) {
                var newvalue = txtvalue.replace(lbl.value + ", ", "");
                txtbox.value = newvalue;
            }
            else if (FindLbl2.test(txtvalue) == true) {
                var newvalue = txtvalue.replace(lbl.value, "");
                txtbox.value = newvalue;
            }
        }
    }
}

function VoteHighlighter(img, idExt, h_src, o_src) {
    var lookin = new RegExp(idExt);
    var x = 0;
    for (i = 0; i < document.images.length; i++) {
        var idS = document.images[i].id;
        if (lookin.test(idS) == true) {
            x++;
        }
    }

    var imgId = parseInt(img.id);

    for (i = 1; i <= x; i++) {
        var C_img = document.getElementById(i + idExt);
        if (i <= imgId) {
            C_img.src = h_src;
        }
        else {
            C_img.src = o_src;
        }
    }
}

function Vote(imgId, hdn_vote) {
    var val = parseInt(imgId);
    document.getElementById(hdn_vote).value = val;
    var star;
    if (val == 1) {
        star = "star&nbsp;";
    }
    else {
        star = "stars";
    }
    document.getElementById(hdn_vote).nextSibling.nextSibling.innerHTML = val + " " + star;
}

function Progress(proId, barId, imgId, hdnId) {
    var div = document.getElementById(proId);
    var img = document.getElementById(imgId);
    var bar = document.getElementById(barId);
    var hdn = document.getElementById(hdnId);
    if (div) {
        var imgWidth = img.width;
        div.style.width = imgWidth + "px";
        div.style.height = img.height + "px";
        bar.style.height = img.height + "px";

        var hdn_pct = hdn.value / 5;
        var barWidth = hdn_pct * imgWidth;
        bar.style.width = barWidth + "px";
    }
}

var LoadImg1 = new Image(54, 12);
LoadImg1.src = "icons/load/load1.png";
var LoadImg2 = new Image(54, 12);
LoadImg2.src = "icons/load/load2.png";
var LoadImg3 = new Image(54, 12);
LoadImg3.src = "icons/load/load3.png";
var LoadImg4 = new Image(54, 12);
LoadImg4.src = "icons/load/load4.png";
var LoadImg5 = new Image(54, 12);
LoadImg5.src = "icons/load/load5.png";
var LoadImg6 = new Image(54, 12);
LoadImg6.src = "icons/load/load6.png";
var LoadImg7 = new Image(54, 12);
LoadImg7.src = "icons/load/load7.png";
var LoadImg8 = new Image(54, 12);
LoadImg8.src = "icons/load/load8.png";
var LoadImg9 = new Image(54, 12);
LoadImg9.src = "icons/load/load9.png";
var LoadImg10 = new Image(54, 12);
LoadImg10.src = "icons/load/load10.png";

var C_LoadImg1 = new Image(40, 40);
C_LoadImg1.src = "icons/load/circle1.png";
var C_LoadImg2 = new Image(40, 40);
C_LoadImg2.src = "icons/load/circle2.png";
var C_LoadImg3 = new Image(40, 40);
C_LoadImg3.src = "icons/load/circle3.png";
var C_LoadImg4 = new Image(40, 40);
C_LoadImg4.src = "icons/load/circle4.png";
var C_LoadImg5 = new Image(40, 40);
C_LoadImg5.src = "icons/load/circle5.png";
var C_LoadImg6 = new Image(40, 40);
C_LoadImg6.src = "icons/load/circle6.png";
var C_LoadImg7 = new Image(40, 40);
C_LoadImg7.src = "icons/load/circle7.png";
var C_LoadImg8 = new Image(40, 40);
C_LoadImg8.src = "icons/load/circle8.png";

var LoadInt;

function LoadAnim(imgid, imgsrc, imgTot) {
    var img = document.getElementById(imgid);
    if (img) {
        if (img.style.display == "inline") {
            LoadInt = setInterval("Load('" + imgid + "', '" + imgsrc + "', '" + imgTot + "')", 150);
        }
        else {
            clearInterval(LoadInt);
        }
    }
}
var Loadx = 1;

function Load(imgid, imgsrc, imgTot) {
    var img = document.getElementById(imgid);
    if (img.src) {
        if (Loadx <= imgTot) {
            img.src = "icons/load/" + imgsrc + "" + Loadx + ".png";
            Loadx++;
        }
        else {
            Loadx = 1;
        }
    }
}

function RGBtoHEX(rgbValue) {
    var isRGB = new RegExp(",", "g");
    if (isRGB.test(rgbValue)) {
        var LC = RegExp.leftContext;
        var RC = RegExp.rightContext;
        var patt2 = new RegExp("[0-9]{1,3}", "g");

        var R = parseInt(LC.match(patt2));

        var patt3 = new RegExp(",", "g");
        patt3.test(RC);

        var G = parseInt(RegExp.leftContext);

        var Three = RegExp.rightContext;

        var B = parseInt(Three.match(patt2));

        var totR;
        var totG;
        var totB;
        var wholeR;
        var wholeG;
        var wholeB;
        var remainR;
        var remainG;
        var remainB;

        totR = R / 16;
        wholeR = Math.floor(totR);
        remainR = R % 16;

        totG = G / 16;
        wholeG = Math.floor(totG);
        remainG = G % 16;

        totB = B / 16;
        wholeB = Math.floor(totB);
        remainB = B % 16;

        if (wholeR == 10) { wholeR = "A" }
        if (wholeR == 11) { wholeR = "B" }
        if (wholeR == 12) { wholeR = "C" }
        if (wholeR == 13) { wholeR = "D" }
        if (wholeR == 14) { wholeR = "E" }
        if (wholeR == 15) { wholeR = "F" }
        if (remainR == 10) { remainR = "A" }
        if (remainR == 11) { remainR = "B" }
        if (remainR == 12) { remainR = "C" }
        if (remainR == 13) { remainR = "D" }
        if (remainR == 14) { remainR = "E" }
        if (remainR == 15) { remainR = "F" }
        if (wholeB == 10) { wholeB = "A" }
        if (wholeB == 11) { wholeB = "B" }
        if (wholeB == 12) { wholeB = "C" }
        if (wholeB == 13) { wholeB = "D" }
        if (wholeB == 14) { wholeB = "E" }
        if (wholeB == 15) { wholeB = "F" }
        if (remainB == 10) { remainB = "A" }
        if (remainB == 11) { remainB = "B" }
        if (remainB == 12) { remainB = "C" }
        if (remainB == 13) { remainB = "D" }
        if (remainB == 14) { remainB = "E" }
        if (remainB == 15) { remainB = "F" }
        if (wholeG == 10) { wholeG = "A" }
        if (wholeG == 11) { wholeG = "B" }
        if (wholeG == 12) { wholeG = "C" }
        if (wholeG == 13) { wholeG = "D" }
        if (wholeG == 14) { wholeG = "E" }
        if (wholeG == 15) { wholeG = "F" }
        if (remainG == 10) { remainG = "A" }
        if (remainG == 11) { remainG = "B" }
        if (remainG == 12) { remainG = "C" }
        if (remainG == 13) { remainG = "D" }
        if (remainG == 14) { remainG = "E" }
        if (remainG == 15) { remainG = "F" }

        var HEX = "" + wholeR + "" + remainR + "" + wholeG + "" + remainG + "" + wholeB + "" + remainB;
        return HEX;
    }
    else {
        return rgbValue;
    }
}

var isCTRL = false;

function CtrlCheck(txtbox, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 17) {
        isCTRL = true;
    }
    if (isCTRL) {
        if (keyCode == 13) {
            if (txtbox.value != "") {
                AsyncWait('ctl00_Main_Content_Btn_Talk', 'none', 'loadImg', 'inline', 'load', 10);
                ClearContents(txtbox.id);
                isCTRL = false;
                __doPostBack('ctl00$Main_Content$Btn_Talk', '');
            }
            else {
                ClearContents(txtbox.id);
                isCTRL = false;
                alert('type something first');
            }
        }
    }
}

function ClearKeys() {
    isCTRL = false;
}

function YearDisp(elem) {
    if (elem.innerHTML == "1984") {
        var d = new Date();
        elem.innerHTML = d.getFullYear();
    }
    else {
        elem.innerHTML = "1984";
    }
}

var YearCount = 0;
function YearCounter() {
    YearCount++;
}

function YearNote() {
    if (YearCount == 5) {
        var d = new Date();
        alert("yes, it always goes back and forth between 1984 and " + d.getFullYear() + "");
    }
    if (YearCount == 10) {
        alert("despite my previous notification, you continue to mouse over the year...");
    }
    if (YearCount == 20) {
        alert("ok...what are you trying to accomplish really?");
    }
    if (YearCount == 40) {
        alert("have you noticed it takes more and more mouse overs to get another alert?  that's because I'm trying to discourage you from doing it");
    }
    if (YearCount > 50 && YearCount < 99) {
        alert("you really have nothing better to do? you've done this " + YearCount + " times");
    }
    if (YearCount == 99) {
        alert("do it one more time, I dare you");
    }
    if (YearCount == 100) {
        __doPostBack('ctl00$Btn_Year', '');
    }
}

var CodeNum = 0;
var Prev = 0;
function Code(e) {
    var keyCode = event.keyCode || e.which || e.charCode;
    
    if (keyCode == 38 && Prev == 33) {
        Prev = 35;
    }
    if (keyCode == 38 && Prev == 0) {
        Prev = 33;
    }
    if (keyCode == 40 && Prev == 32) {
        Prev = 34;
    }
    if (keyCode == 40 && Prev == 35) {
        Prev = 32;
    }
    if (keyCode == 37 && Prev == 34) {
        Prev = 37;
    }
    if (keyCode == 39 && Prev == 37) {
        Prev = 39;
    }
    if (keyCode == 37 && Prev == 39) {
        Prev = 36;
    }
    if (keyCode == 39 && Prev == 36) {
        Prev = 39;
    }
    if (keyCode == 66 && Prev == 39) {
        Prev = 66;
    }
    if (keyCode == 65 && Prev == 66) {
        CodeNum++;
    }
    if (keyCode == 13 && CodeNum != 0) {
        __doPostBack('ctl00$Btn_Code', '');
    }
}

function confirm_delete() {
    var grabtable = document.getElementById('BoxTable');

    var i = 0;
    var x = 0;

    if (grabtable) {
        var rowcount = grabtable.rows.length;
        for (i = 0; i < rowcount; i++) {
            var grabcheck = document.getElementById('ctl00_User_Content_BoxView_ctrl' + i + '_Chk_BoxItem');
            if (grabcheck) {
                if (grabcheck.checked == true) {
                    x = x + 1;
                }
            }
        }
    }

    if (x == 0) {
        alert("No items have been selected.");
    }
    else {
        var addS;
        if (x == 1) {
            addS = "";
        }
        else {
            addS = "s";
        }
        var conf = confirm("Are you sure you want to delete the selected " + x + " message" + addS + "?");
        if (conf == true) {
            return true;
        }
        else {
            if (grabtable) {
                for (i = 0; i < rowcount; i++) {
                    var grabcheck = document.getElementById('ctl00_User_Content_BoxView_ctrl' + i + '_Chk_BoxItem');
                    if (grabcheck) {
                        grabcheck.checked = false;
                    }
                }
            }
        }
    }
}

function SelectOne() {

    var grabtable = document.getElementById('BoxTable');

    var i = 0;
    var x = 0;

    if (grabtable) {
        var rowcount = grabtable.rows.length;
        for (i = 0; i < rowcount; i++) {
            var grabcheck = document.getElementById('ctl00_User_Content_BoxView_ctrl' + i + '_Chk_BoxItem');
            if (grabcheck) {
                var upper = grabcheck.parentNode.parentNode;
                var upperBackColor = upper.style.borderColor;
                if (grabcheck.checked == true) {
                    upper.style.backgroundImage = "none";
                    upper.style.backgroundColor = "#FCF580";
                }
                else {
                    upper.style.backgroundImage = "url('icons/white_trans_90.png')";
                    upper.style.backgroundColor = upperBackColor;
                }
            }
        }
    }
}

function SelectAll() {

    var grabtable = document.getElementById('BoxTable');

    var i = 0;
    var x = 0;

    if (grabtable) {
        var rowcount = grabtable.rows.length;
        var grapcheckAll = document.getElementById('ctl00_User_Content_BoxView_Chk_ChkAllItems');
        if (grapcheckAll) {
            if (grapcheckAll.checked == true) {
                grapcheckAll.title = "Deselect All";
                for (i = 0; i < rowcount; i++) {
                    var grabcheck = document.getElementById('ctl00_User_Content_BoxView_ctrl' + i + '_Chk_BoxItem');
                    if (grabcheck) {
                        grabcheck.checked = true;
                        var upper = grabcheck.parentNode.parentNode;
                        upper.style.backgroundImage = "none";
                        upper.style.backgroundColor = "#FCF580";
                    }
                }
            }
            else {
                grapcheckAll.title = "Select All";
                for (i = 0; i < rowcount; i++) {
                    var grabcheck = document.getElementById('ctl00_User_Content_BoxView_ctrl' + i + '_Chk_BoxItem');
                    if (grabcheck) {
                        grabcheck.checked = false;
                        var upper = grabcheck.parentNode.parentNode;
                        var upperBackColor = upper.style.borderColor;
                        upper.style.backgroundImage = "url('icons/white_trans_90.png')";
                        upper.style.backgroundColor = upperBackColor;
                    }
                }
            }
        }
    }
}