﻿/****************************************************************************************
*  COPYRIGHT NOTICE:                                                                    *
*=======================================================================================* 
*  All Code Copyright ©Industrial Pixel 2002-2008. All rights reserved.                 *
*  You are not permitted to copy, distribute or edit this code in any way.              *
*  Legal action will be taken against theft of copyright.                               *
*  This code instance is licensed for use on www.avrchurchbutchery.co.uk domain ONLY         *
*  Industrial Pixel - info@industrialpixel.com                                          *
*=======================================================================================*
*  NOTICE ENDS                                                                          *
****************************************************************************************/

function grayOut(vis, options) {

    var options = options || {};
    var zindex = options.zindex || 50;
    var opacity = options.opacity || 70;
    var opaque = (opacity / 100);
    var bgcolor = options.bgcolor || '#ffffff';
    var canvasDv = options.canvasDv ;
    var dark = document.getElementById('darkenScreenObject');

    if (!dark) {
        if (canvasDv == 'body') {
            var tbody = document.getElementsByTagName("body")[0];
            //alert("tbody is BODY: " + x + " : " + y);
        }
        else {
            var tbody = $get(canvasDv);
            //alert("tbody is" + x + " : " + y);
        }
       
        
        var tnode = document.createElement('div');
        tnode.style.position = 'absolute';
        tnode.style.top = '0px';
        tnode.style.left = '0px';
        tnode.style.overflow = 'hidden';
        tnode.style.display = 'none';
        tnode.id = 'darkenScreenObject';
        tbody.appendChild(tnode);
        dark = document.getElementById('darkenScreenObject');
    }
    var tbody = $get(canvasDv);
    var tbodyBounds = Sys.UI.DomElement.getBounds(tbody);
    var theWidth = tbodyBounds.width;
    var theheight = tbodyBounds.height;
    if (vis) {
        if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
            var pageWidth = document.body.scrollWidth + 'px';
            var pageHeight = document.body.scrollHeight + 'px';
        }
        else
            if (document.body.offsetWidth) {
            var pageWidth = document.body.offsetWidth + 'px';
            var pageHeight = document.body.offsetHeight + 'px';
        }
        else {
            var pageWidth = '100%';
            var pageHeight = '100%';
        }

        dark.style.opacity = opaque;
        dark.style.MozOpacity = opaque;
        dark.style.filter = 'alpha(opacity=' + opacity + ')';
        dark.style.zIndex = zindex;
        dark.style.backgroundColor = bgcolor;
        //dark.style.width = pageWidth;
        //dark.style.height = pageHeight;
        //Sys.UI.DomElement.setLocation(dark, x, y);
        dark.style.width = theWidth;
        dark.style.height = theheight;
        //Sys.UI.DomElement.setLocation(dark, tbodyBounds.x, tbodyBounds.y);
        dark.style.display = 'block';

    }
    else {
        dark.style.display = 'none';
    }
}



function TruncateString(inputString, charLimit) {
    var outputString = inputString;
    if (outputString.length > charLimit && charLimit > 0) {
        outputString = outputString.substring(0, charLimit);
        if (inputString.substring(outputString.length, 1) != " ") {
            var lastSpace = outputString.lastIndexOf(" ");
            if (lastSpace != -1) {
                outputString = outputString.substring(0, lastSpace);
            }
        }
        outputString += "...";
    }
    return outputString;
}





