﻿s4 = document.layers
ie4 = document.all 
nn6 = document.getElementById && !document.all 

function ToggleMinMax(link, obj) {
    if(obj != null){
        if(obj.style.visibility == 'hidden')
        {
            obj.style.display = 'block';
            obj.style.visibility = 'visible';
            link.style.backgroundImage = 'url("/Stylesheets/images/hide_bw.gif")';
        }
        else
        {
            obj.style.display = 'none';
            obj.style.visibility = 'hidden';
            link.style.backgroundImage = 'url("/Stylesheets/images/expand_bw.gif")';
        } 
    }
}

function ToggleEdit(id){
    obj = document.getElementById(id);

    if(obj.style.width == null || obj.style.width.length == 0){
	    obj.style.width = 10;
    }
    else{
	    obj.style.width = null;
    }
}

function PopupEditor(url){
    var w = screen.availWidth * .7
    var h = screen.availHeight * .7
    var x = (screen.availWidth - w) / 3
    var y = (screen.availHeight - h) / 3

    var newwindow = window.open(url, "editor", "left="+x+",top="+y+",width="+w+",height="+h+",status=0,menubar=0,toolbar=1,resizable=1,scrollbars=1");
    newwindow.focus();
}

function LaunchPopup(url, title, w, h, x, y, stat, mb, sb, tb, rs){
    if (w <= 0)
    {
        w = screen.availWidth * .8;
    }
    if (h <= 0)
    {
        h = screen.availHeight * .8;
    }
    if (x <= 0)
    {
        x = (screen.availWidth - w) / 3;
    }
    if (y <= 0)
    {
        y = (screen.availHeight - h) / 3;
    }

    var nw = window.open(url, title, "width="+w+",height="+h+",left="+x+",top="+y+",status="+stat+",menubar="+mb+",scrollbars="+sb+",toolbar="+tb+",resizable="+rs);
    nw.focus();
}

// we use the list to keep them around until the DOM is done
// we use the pairs because ie6 sucks at using document.getElementById
var injectionList = new Array();
var injectedPairs = new Array();

// We only need to use this method because IE breaks when you try
// to modify the DOM before the components are fully closed
function AddWaitInjection(text, id){
    var newInjection = new Array();
    newInjection["id"] = id;
    newInjection["text"] = text;
    
    injectionList.push(newInjection);
}

function InjectWaitMessages(){
    for(var i = 0; i < injectionList.length; i++){
        var id = injectionList[i]["id"];
        var text = injectionList[i]["text"];

        var backDiv = document.createElement("div");
        var infoDiv = document.createElement("div");
        var image = document.createElement("img");
        
        image.id = "wait" + id;
        image.src = "/Stylesheets/images/statuscircle.gif";

        infoDiv.innerHTML = "<br/>";
        infoDiv.innerHTML += text;
        infoDiv.appendChild(image);
        

        document.body.appendChild(backDiv);
        document.body.appendChild(infoDiv);

        backDiv.setAttribute("id", "backDiv" + id);
        backDiv.setAttribute("class", "backDiv");
        infoDiv.setAttribute("id", "infoDiv" + id);
        infoDiv.setAttribute("class", "infoDiv");
        
        image.style.marginLeft = "30px";
        image.style.verticalAlign = "middle";
        
        // The css styles work alone fine in FF, but IE sucks once again
        backDiv.style.mozOpacity = "0.5";
        backDiv.style.filter = "alpha(opacity=50)";
        backDiv.style.backgroundColor = "#000000";
        backDiv.style.position = "absolute";
        backDiv.style.zIndex = "555";
        backDiv.style.top = "0px";
        backDiv.style.left = "0px";
        backDiv.style.width = "100%";
        backDiv.style.height = "100%";
        backDiv.style.display = "none";

        // The css styles work alone fine in FF, but IE sucks once again
        infoDiv.style.float = "left";
        infoDiv.style.backgroundColor = "#ffffff";
        infoDiv.style.zIndex = "999";
        infoDiv.style.position = "absolute";
        infoDiv.style.textAlign = "center";
        infoDiv.style.color = "#000000";
        infoDiv.style.border = "3px solid #114466";
        infoDiv.style.fontWeight = "bold";
        infoDiv.style.fontSize = "14px";
        infoDiv.style.display = "none";
        
        var newInjectedPair = new Array();
        newInjectedPair["back"] = backDiv;
        newInjectedPair["info"] = infoDiv;
        
        injectedPairs[id] = newInjectedPair;
    }
}

var displayID = "";
var registerTime;
var waitImage;
// Registering the id allows us to use more than one wait message on a single page

function RegisterDisplayWaitMessage(id){
    displayID = id;
    registerTime = new Date().getTime();
}

function DisplayWaitMessage(id){
    // using register time, we can handle unsubmittable forms that launch the validation options
    if(id == displayID && injectedPairs[id] && (new Date().getTime() - registerTime) < 500){
        var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
        
        var backDiv = injectedPairs[id]["back"];
        var infoDiv = injectedPairs[id]["info"];
        
        var infoHeight = 63;
        var infoWidth = 375;
        
        var width;
        var height;
        
        if(window.innerWidth){
            width = window.innerWidth;
            height = window.innerHeight;
        } else {
            width = document.documentElement.clientWidth;
	        height = document.documentElement.clientHeight;
        }
        
        var infoLeft = (width - infoWidth) / 2;
        var infoTop = (height - infoHeight) / 2;
        
        infoDiv.style.width = infoWidth + "px";
        infoDiv.style.height = infoHeight + "px";
        infoDiv.style.left = infoLeft + "px";
        infoDiv.style.top = infoTop + "px";
        infoDiv.style.position = "fixed";

        backDiv.style.display = "block";
        backDiv.style.height = "100%";
        backDiv.style.position = "fixed";
        infoDiv.style.display = "block";
        
        document.body.scolling = "no";
        
        window.setTimeout(restartWaitAnimation, 500);
    }
}

function restartWaitAnimation() {
    waitImage = document.getElementById("wait" + displayID);
    waitImage.style.visibility = "visible";   
    
    waitImage.src = "/Stylesheets/images/statuscircle.gif";
}

function SelectAllRecords(selectorId) {
    var element = document.getElementById(selectorId);
    var checked = element.checked;
    var elems = document.forms[0].elements;
    
    for (var i=0; i < elems.length; i++) {
        var elem = elems[i];
        
        if (elem.id.indexOf("RequiredCheckBox") > 0) {
            if (!elem.disabled) { elem.checked = checked; }
        }
    }
}

//checks all DataGrid CheckBoxes with the given name with the given value
function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) {
    re = new RegExp(".*" + aspCheckBoxID + ".*")
    
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]

        if (elm.type == 'checkbox') {
            if (re.test(elm.id) && !elm.disabled) {
                elm.checked = checkVal
            }
        }
    }
}

function integerOnly(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = 'This field accepts numbers only.';
        return false;
    }
    status = '';
    return true;
}
