function openGlossaryWindow(strTerm) {
    jsWindow = window.open("/GlossaryItem.aspx?term=" + strTerm, "glossary_win", "width=390,height=250,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
    jsWindow.focus();
}

function sdcOpenNewWindow(strURL) {
    jsWindow = window.open(strURL, "new_win", "width=750,height=" + (screen.height - 150) + ",top=1,left=1,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes");
    jsWindow.focus();
}
function sdcOpenNewSmallWindow(strURL) {
    jsWindow = window.open(strURL, "small_win", "width=600,height=500,top=1,left=1,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no");
    jsWindow.focus();
}

function openCopyrightWindow(strURL, strHeight, strWidth) {
    jsWindow = window.open(strURL, "search_criteria_win", "width=750" + strWidth + ",height=300" + strHeight + ",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,top=1,left=1");
    jsWindow.focus();
}

function sdcOpenWindow(strDestination, strWindowName, strOptions) {
    jsWindow = window.open(strDestination, strWindowName, strOptions);
    jsWindow.focus();
}

function sdcOpenWindowBlurry(strDestination, strWindowName, strOptions) {
    jsWindow = window.open(strDestination, strWindowName, strOptions);
}

function ToggleOnOff(id) {
    var item = document.getElementById(id);
    if (item.style.display == 'none') {
        item.style.display = '';
    }
    else {
        item.style.display = 'none';
    }
}

function openWindow(strURL) {
    //    jsWindow = window.open("", "new_win", "width=800,height=1200,toolbar=yes,menubar=yes, location=yes, scrollbars=yes,resizable=yes,top=1,left=1");
    //    jsWindow.close();
    //    newWin = window.open(strURL, "new_win", "width=800,height=1200,toolbar=yes,menubar=yes, location=yes, scrollbars=yes,resizable=yes,top=1,left=1");
    //      if (window.focus) {
    //          newWin.focus();
    //   }
    jsWindow = window.open(strURL, "new_win", "width=800,height=1200,toolbar=yes,menubar=yes, location=yes, scrollbars=yes,resizable=yes,top=1,left=1");
    //jsWindow.focus();
}

function openWindowPDF(strURL) {
    //    jsWindow = window.open("", "new_win", "width=800,height=1200,toolbar=yes,menubar=yes, location=yes, scrollbars=yes,resizable=yes,top=1,left=1");
    //    jsWindow.close();
    //    newWin = window.open(strURL, "new_win", "width=800,height=1200,toolbar=yes,menubar=yes, location=yes, scrollbars=yes,resizable=yes,top=1,left=1");
    //      if (window.focus) {
    //          newWin.focus();
    //   }
    jsWindow = window.open(strURL, "new_win", "width=1000,height=1200,toolbar=yes,menubar=yes, location=yes, scrollbars=yes,resizable=yes,top=1,left=1");
    //jsWindow.focus();
}

/* ========== Rotating Masthead Script ================ */

var backgroundSrcs = new Array("/images/masthead01.jpg", "/images/masthead02.jpg", "/images/masthead03.jpg", "/images/masthead04.jpg", "/images/masthead05.jpg")

function pickimage() {
    var bgimage = backgroundSrcs[(Math.round(Math.random() * (backgroundSrcs.length - 1)))]

    document.getElementById("masthead").style.background = "url('" + bgimage + "') no-repeat top right #ffffff";
}

/* ============= End Rotating Masthead Script =============== */


function addListeners() {
    var link = document.getElementById('hideMe');
    link.addEventListener('click', HideAll, false);
}


/*  ------ Collapsible menu - Idividual Subjects  ------ */
menu_status = new Array();
function showHide(theid) {
    if (document.getElementById) {
        var switch_id = document.getElementById(theid);

        if (document.getElementById(theid).className == 'show') {
            switch_id.className = 'hide';
        }
        else {
            switch_id.className = 'show';
        }
    }
}

function swap(obj) {
    var img = obj.getElementsByTagName('img')[0];
    if (document.getElementById) {
        if (img.src.indexOf("/images/expanded.gif") != -1) {
            img.src = "/images/collapsed.gif";
        }
        else {
            img.src = "/images/expanded.gif";
        }
    }
}

function addListeners() {
    var link = document.getElementById('hideRes');
    link.addEventListener('click', HideResAll, false);
}
/*----------------------------*/


function printpr() {
    var PPVIEW = 7;
    /* PPVIEW values:
    * 6 - print
    * 7 - print preview
    * 1 - open window
    * 4 - Save As
    */
    var PROMPT = 1; // 2 DONTPROMPTUSER 
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
    document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(PPVIEW, PROMPT);
    WebBrowser1.outerHTML = "";
}

function openHelpWindow(strFileName) {
    jsWindow = window.open(strFileName, "winHelp", "width=350,height=150,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
    jsWindow.focus();
}

function bValidEmailAddress(emailStr) {
    var emailPat = /^(.+)@(.+)$/
    var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    var validChars = "\[^\\s" + specialChars + "\]"
    var quotedUser = "(\"[^\"]*\")"
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    var atom = validChars + '+'
    var word = "(" + atom + "|" + quotedUser + ")"
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$")
    var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$")
    var matchArray = emailStr.match(emailPat)
    if (matchArray == null) {
        alert("Please enter a valid email address.")
        return false
    }
    var user = matchArray[1]
    var domain = matchArray[2]

    if (user.match(userPat) == null) {
        alert("Please enter a valid email address.")
        return false
    }

    var IPArray = domain.match(ipDomainPat)
    if (IPArray != null) {
        // this is an IP address
        for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
                alert("Please enter a valid email address.")
                return false
            }
        }
        return true
    }

    // Domain is symbolic name
    var domainArray = domain.match(domainPat)
    if (domainArray == null) {
        alert("Please enter a valid email address.")
        return false
    }

    var atomPat = new RegExp(atom, "g")
    var domArr = domain.match(atomPat)
    var len = domArr.length
    if (domArr[domArr.length - 1].length < 2 ||
		domArr[domArr.length - 1].length > 3) {
        alert("Please enter a valid email address.")
        return false
    }

    if (len < 2) {
        var errStr = "Please enter a valid email address."
        alert(errStr)
        return false
    }
    return true;
}

function sdcJumpField(txtCurrentField, txtDestField, iNumChar) {
    if (txtCurrentField.value.length >= iNumChar && event.keyCode != 9 && event.keyCode != 16 && event.keyCode != 37 && event.keyCode != 39) {
        txtDestField.focus();
    }
}

function bAllTheSameCharacter(strStringToCheck) {
    var iIndex;
    var charLength = strStringToCheck.length;
    var firstChar = strStringToCheck.substring(0, 1);
    var retval = 0;

    if (charLength == 0) {
        retval += 1;
    }

    for (var iIndex = 0; iIndex <= charLength; iIndex++) {
        if (firstChar != strStringToCheck.substring(iIndex, 1)) {
            return false;
        }
    }

    return true;
}


/*-- Clear Text Input On Focus --*/

function clearText(thefield) {
    if (thefield.defaultValue == thefield.value)
        thefield.value = ""
}

function change(that, fgcolor) {
    that.style.color = fgcolor;
}

/*-- End Input Text Style --*/

function isValidDate(dateStr) {
    var reg = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

    // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
    if (reg.test(dateStr) == false) {
        return false;
    }
    return true;
}

function validatePhoneNumber(Number, IsWork) {
    /*
    This function validates the phone numbers based upon the NANP standard i.e.
    NXX-NXX-XXXX
    where N is any digit 2-9 and X is any digit 0-9.
    This function also validates the repetitive occurances in the area code e.g.
    555 or 333 or 666 are invalid area codes.
    HAPPY PROGRAMMING!!!
    */
    //alert(Number.replace(/\s+/g,"") );//Jam's trimming!
    if (!IsWork) {
        var RegEx = /^(\d)(\1)\2\d{7}|[01]\d{9}|\d{3}[01]\d{6}$/; // Home/Mobile Validation
    }
    else {
        var RegEx = /^([^8])(\1)\2\d{7}|[01]\d{9}|\d{3}[01]\d{6}$/; // Work Validataion
    }
    if ((Number == '') || (Number.replace(/\s+/g, "").length < 10) || (isNaN(Number)) || (Number.match(RegEx))) {

        return false;
    } else {

        return true;

    }
}

function AutoTab(Source, Destination) {
    if (Source.getAttribute &&
            Source.value.length == Source.getAttribute("maxlength")) {
        //alert(Destination);
        Destination.focus()
    }
}


function goNewWin() {
    TheNewWin = window.open("scc.aspx?pid=460", 'TheNewpop', 'toolbar=1, location=1,directories=1,status=1,menubar=1, scrollbars=1,resizable=1');
    TheNewWin.blur();
}

function goNewWinalt() {
    TheNewWin = window.open("scc.aspx?pid=460", 'TheNewpop', 'toolbar=1, location=1,directories=1,status=1,menubar=1, scrollbars=1,resizable=1');
    TheNewWin.blur();
}


function Querystring(qs) {
    this.params = new Object()
    this.get = Querystring_get

    if (qs == null)
        qs = location.search.substring(1, location.search.length)

    if (qs.length == 0) return

    qs = qs.replace(/\+/g, ' ')
    var args = qs.split('&')

    for (var i = 0; i < args.length; i++) {
        var value;
        var pair = args[i].split('=')
        var name = unescape(pair[0])

        if (pair.length == 2)
            value = unescape(pair[1])
        else
            value = name

        this.params[name] = value
    }
}

function Querystring_get(key, default_) {
    if (default_ == null) default_ = null;

    var value = this.params[key]
    if (value == null) value = default_;

    return value
}


function showClassesOnlineMessage(DropDown, SchoolName) {
    if (DropDown[DropDown.selectedIndex].value == 'Y') {
        alert(SchoolName + ' requires that you must be able to physically attend classes. \n\n  If you can physically attend classes and are still interested in this offer, please select NO for your answer to this question');
    }
}


function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}



//Start question roll overs
function getHelpTopic(helpTopicID) {

    $.ajax({
        type: "POST",
        url: "/HelpTopic.aspx",
        data: "topicid=" + helpTopicID,
        dataType: "json",
        success: function (msg) {

            setHelpTopic(msg);
        }

    });
}
function setHelpTopic(transport) {
    var json = transport;
    var title;
    var desc;
    title = json.title;
    desc = json.desc;
    $(".tooltip").html('<strong>' + title + '</strong><br />' + desc);


}
//End question roll overs


// ================================================================== Start Content Management System functions
function setLink(Lselection, Lid, Lbox, Lrange, LstartContainer) {

    if (Lselection != "") {

        document.getElementById(Lbox).innerHTML = Lselection;
      
        Lrange = Lselection.getRangeAt(0);

        LstartContainer = Lrange.startContainer;
       
        var spanNode = document.createElement("a");
        spanNode.setAttribute('href', '/SCHLINK_' + Lid + '/');
        var docfrag = Lrange.extractContents();
        spanNode.appendChild(docfrag);
        Lrange.insertNode(spanNode);
        spanNode.innerHTML = " " + document.getElementById(Lbox).innerHTML;
    }

}

function parseTreeviewParentId(Phref, Pid) {
    Phref = Phref.substring(1, Phref.length - 1);
    var id_array = Phref.split("/");
    if (id_array.length == 1) {
        id = id_array[0];
    }
    else if (id_array.length == 2) {
        Pid = id_array[0];
        id = id_array[1];
    }

    return id;
}



function insertAtCaret(areaId, text) {
    var txtarea = document.getElementById(areaId);
    var scrollPos = txtarea.scrollTop;
    var strPos = 0;
    var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?
		"ff" : (document.selection ? "ie" : false));
    if (br == "ie") {
        txtarea.focus();
        var range = document.selection.createRange();
        range.moveStart('character', -txtarea.value.length);
        strPos = range.text.length;
    }
    else if (br == "ff") strPos = txtarea.selectionStart;

    var front = (txtarea.value).substring(0, strPos);
    var back = (txtarea.value).substring(strPos, txtarea.value.length);
    txtarea.value = front + text + back;
    strPos = strPos + text.length;
    if (br == "ie") {
        txtarea.focus();
        var range = document.selection.createRange();
        range.moveStart('character', -txtarea.value.length);
        range.moveStart('character', strPos);
        range.moveEnd('character', 0);
        range.select();
    }
    else if (br == "ff") {
        txtarea.selectionStart = strPos;
        txtarea.selectionEnd = strPos;
        txtarea.focus();
    }
    txtarea.scrollTop = scrollPos;
}


function handleCommonPageTemplateElements(lnk) {
    if (lnk != '') {
        $(lnk).each(function () {
            $("a[href^=/]").attr("target", "_top");
        });
    }
  
}


function setSizeiframe() {
    $('iframe').load(function () {
        if (this.id != '') {
            this.style.height =
        this.contentWindow.document.body.offsetHeight + 30 + 'px';
            this.style.width = '100%';
        }

    });

}

function handleTooltips(areaId, posx, posy, showchild) {
 
    if ($.browser.msie && $.browser.version == "6.0") {
        $(areaId).click(function (e) {
            openFileWindow('/HelpTopic.aspx?topicid=' + $(this).attr('id') + '');
        });
    }
    else {

        $(areaId).mouseenter(function (e) {

            getHelpTopic($(this).attr('id'));
            $(this).css('z-index', '15')
		            .children(showchild)
		            .fadeIn("fast")
		            .css({ 'bottom': posx, 'left': posy, 'display': 'block' });

        }).mousemove(function (e) {
            //$(this).children("div.tooltip").css({'bottom': posiX,'left': posiY});
        }).mouseleave(function () {
            $(this).css('z-index', '1')
		.children(showchild)
		.hide()
        });
    }

}

function breakOutFrame() {
    $("a[href^=/]").attr("target", "_top");
}

function SelectAll(id) {
    var frm = document.forms[0];
    for (i = 0; i < frm.elements.length; i++) {
        if (frm.elements[i].type == "checkbox") {
            frm.elements[i].checked = document.getElementById(id).checked;
        }
    }
}

function formatTextLink(el) {
    /* IF INTERNET EXPLORER */
    if (window.showModalDialog) {


        var myText = window.showModalDialog('chooseLink.aspx',
                                                    'name',
                                                    'dialogWidth:900px;dialogHeight:600px;');

        if (myText != "iamempty") {
            var selectedText = document.selection.createRange().text;

            if (selectedText.toLowerCase().indexOf("<a ") >= 0) {
                selectedText = $(selectedText).text();
            }



            if (selectedText != "") {

                var newText = myText + selectedText + "</a>";
                document.selection.createRange().text = newText;

            }

            else {

                el.focus(el.caretPos);
                el.caretPos = document.selection.createRange().duplicate();
                if (el.caretPos.text.length == 0) {
                    if (el.caretPos.text != '') {

                        el.caretPos.text = myText + "</a>";
                    }

                }
            }

        }
    }
    /* IF MOZILLA */
    else {
        window.open('chooseLink.aspx',
                            'name',
                            'height=180,width=530,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
    }


}

function toggleView(areaone, arearwo, areaid) {
    if ($(areaone).is(':visible')) {
        $(areaone).hide();
        $(arearwo).html($(areaid).val());
        $(arearwo).show();
    }
    else {
        $(areaone).show();
        $(arearwo).hide();
    }

}

//End Content Management System functions

function formatString(str) {
    str = str.replace('&amp;', '&');
    return str;
}
       

