﻿function OpenPopUp(url) {
    var hWnd = window.open(url, "", "width=500,height=345,resizable=yes,status=yes,scrollbars=yes,toolbar=yes");
    if ((document.window != null) && (!hWnd.opener))
        hWnd.opener = document.window;
}

function OpenReport(url) {

    var hWnd = window.open(url, "", "width=500,height=345,resizable=yes,status=no,scrollbars=no,toolbar=no");
    if ((document.window != null) && (!hWnd.opener))
        hWnd.opener = document.window;
}


function displayAlert() {

    alert("For your protection, you are about to be automatically signed out from My School Year.");
    self.location = "http://MySchoolYear.com/Default.aspx?action=logout";

}

function setupTimeout(timeOutMilliseconds) {
    window.setTimeout('displayAlert()', timeOutMilliseconds);
}


function enableSubElements(element, isCheckbox, warnUser) {
    if (isCheckbox) {
        var secondCheck = new getObj(element);
        secondCheck.obj.disabled = !secondCheck.obj.disabled;
        secondCheck.parent.disabled = !secondCheck.parent.disabled;
        // secondCheck.obj.checked = !secondCheck.obj.checked;
        if  ((warnUser) & ( secondCheck.obj.disabled))
        {
            alert("You have un-enrolled the student from the school term. This student's records (assignments, grades, subjects, etc.) for this school term will be moved to the Wastebasket for 30 days before being PERMANENTLY deleted. You may opt to re-enroll now or recover from the Wastebasket within 30 days.");
        }
    }
    else {
        document.getElementById(element).disabled = !document.getElementById(element).disabled;

    }
}


var obj;
var style;
var parent;

function getObj(name) {
    /* DHTML Micro API
    * Source: http://www.quirksmode.org/js/dhtmloptions.html
    */
    if (document.getElementById) // test if browser supports document.getElementById
    {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
        this.parent = document.getElementById(name).parentNode;
    }
    else if (document.all) // test if browser supports document.all
    {
        this.obj = document.all[name];
        this.style = document.all[name].style;
        this.parent = document.all[name].parentElement;
    }
    else if (document.layers) // test if browser supports document.layers
    {
        this.obj = document.layers[name];
        this.style = document.layers[name].style;
        this.parent = document.layers[name].parentNode;
    }
}


function IsCurrency(sender, args) {
    var input = args.Value;

    // Check for currency formatting. 
    // Expression is from http://regexlib.com/REDetails.aspx?regexp_id=70 
    re = /^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$/;
    isCurrency = input.match(re);

    if (isCurrency) {
        // Convert the string to a number. 
        var number = parseFloat(CleanUp(input));
        if (number != NaN) {
            // Check the range. 
            var min = 0;
            var max = 1000000;
            if (min <= number && max >= number) {
                // Input is valid. 
                args.IsValid = true;
                return;
            }
        }
    }

    // Input is not valid if we reach this point. 
    args.IsValid = false;
    return;
}

function CleanUp(number) {
    re = /^\$|,/g;
    return number.replace(re, ""); // remove "$" and "," 
}  

