//*************************************
//*   Inmagic JS Namespace Manager    *
//*************************************
if (typeof Namespace == 'undefined') var Namespace = {};
if (!Namespace.Manager) Namespace.Manager = {};

Namespace.Manager = {
 Register:function(namespace){
  namespace = namespace.split('.');

  if(!window[namespace[0]]) window[namespace[0]] = {};
  
  var strFullNamespace = namespace[0];
  for(var i = 1; i < namespace.length; i++)
  {
   strFullNamespace += "." + namespace[i];
   eval("if(!window." + strFullNamespace + ")window." + strFullNamespace + "={};");
  }
 }
};

//******************************** Inmagic Namespace Declarations ********************************************

// Register our Namespace for the Inmagic WebControls
Namespace.Manager.Register("Inmagicinc.WebControls");

//************************************* Inmagic Utility Methods **********************************************


// String trim functions, from http://www.developingskills.com/ds.php?article=jstrim&page=1
function strltrim() {
	return this.replace(/^\s+/,'');
}

function strrtrim() {
	return this.replace(/\s+$/,'');
}
function strtrim() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;
  

// Width allowed for sidebar on pages with an iframe
var intSidebarWidth = 320; 

function new_popwindow(url, width, height){
	var w;
	if(width == "-1" || height == "-1"){
	   w = window.open(url,"","dependent=yes,toolbar=0,location=0,directories=0, status=0,menubar=0,scrollbars=1,resizable=1");
	}
	else{
	   w = window.open(url,"","dependent=yes,toolbar=0,location=0,directories=0, status=0,menubar=0,scrollbars=1,resizable=1,width="+width+",height="+height+"");
	}
	if (w != null)  // SPR 2339
        w.focus();
}


function urlDecode(str){
    str=str.replace(new RegExp('\+','g'),' ');
    return unescape(str);
}

function urlEncode(str){
    str=escape(str);
    str=str.replace(new RegExp('\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

var END_OF_INPUT = -1;

var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);

var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
    reverseBase64Chars[base64Chars[i]] = i;
}

var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function readBase64(){    
    if (!base64Str) return END_OF_INPUT;
    if (base64Count >= base64Str.length) return END_OF_INPUT;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}
function encodeBase64(str){
    setBase64Str(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = readBase64()) != END_OF_INPUT){
        inBuffer[1] = readBase64();
        inBuffer[2] = readBase64();
        result += (base64Chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != END_OF_INPUT){
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != END_OF_INPUT){
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64Chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n');
            lineCount = 0;
        }
    }
    return result;
}
function readReverseBase64(){   
    if (!base64Str) return END_OF_INPUT;
    while (true){      
        if (base64Count >= base64Str.length) return END_OF_INPUT;
        var nextCharacter = base64Str.charAt(base64Count);
        base64Count++;
        if (reverseBase64Chars[nextCharacter]){
            return reverseBase64Chars[nextCharacter];
        }
        if (nextCharacter == 'A') return 0;
    } 
}

function ntos(n){
    n=n.toString(16);
    if (n.length == 1) n="0"+n;
    n="%"+n;
    return unescape(n);
}

function decodeBase64(str){
    setBase64Str(str);
    var result = "";
    var inBuffer = new Array(4);
    var done = false;
    while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT
        && (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){
        inBuffer[2] = readReverseBase64();
        inBuffer[3] = readReverseBase64();
        result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4));
        if (inBuffer[2] != END_OF_INPUT){
            result +=  ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2));
            if (inBuffer[3] != END_OF_INPUT){
                result +=  ntos((((inBuffer[2] << 6)  & 0xff) | inBuffer[3]));
            } else {
                done = true;
            }
        } else {
            done = true;
        }
    }
    return result;
}


function setSize(id) {
// Sets the height and width of the iframe object with the specifed id
// Height is specified as total available browser height, minus an offset calculated as the
// Y coordinate of the iframe itself plus a buffer of 20 pixels.
// Width is specified as total available browser width, minus an offset calculated as the
// value of intSidebarWidth (see comment above). 

	var intWinHeight, intWinWidth, blnIsIE;
	//debugger;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		intWinWidth = window.innerWidth;
		intWinHeight = window.innerHeight;
		blnIsIE = false;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		intWinWidth = document.documentElement.clientWidth;
		intWinHeight = document.documentElement.clientHeight;
		// Does not have 'box model bug'
		blnIsIE = false;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		intWinWidth = document.body.clientWidth;
		intWinHeight = document.body.clientHeight;
		blnIsIE = true;
	}		

  	var objFrameContainer = document.getElementById(id);
	//debugger;
  	if (objFrameContainer) {
		var intOffsetY = findPosY(objFrameContainer);
		if (intWinWidth > intSidebarWidth)
			intWinWidth -= intSidebarWidth;
		if (intWinHeight > intOffsetY)	
			intWinHeight -= intOffsetY;
			
		// SPR 3283: set both style.width & width, style.height & height
		objFrameContainer.width = intWinWidth;
		objFrameContainer.style.width = intWinWidth;
		if (intWinHeight > 15) {
			objFrameContainer.height = intWinHeight - 15;
			objFrameContainer.style.height = intWinHeight - 15;
			}
		//var frame = document.frames[id];
		var frame = document.getElementById(id);
		if (frame.blnResizable) {
			if (frame.blnIsFrameset) {
				frame.frameDisplay.setBody();
			} else {
				frame.setBody();
			}
		}
	} 
	
	// Set height of divFocalScroll, if it exists; used only where the focal div should be a fixed-height, 
    // scrollable div that has form-commit buttons below it
	var intFocalHeight;
	var objFocalDiv = document.getElementById('divFocalScroll');

	if (objFocalDiv) {
		var intIEOffset = 0;
		// Addresses IE's box-model CSS problem (accounts for padding as part of div height)
		if (blnIsIE) intIEOffset = 50;	
		
		// Check whether there are form buttons at the bottom of the page; if so, leave a buffer for them
		var intButtonOffset = 0;
		if (document.getElementById('divFormButtons')) { 
			intButtonOffset = 120;
		} else {
			intButtonOffset = 72;
		}
				 
		var intOffsetY = findPosY(objFocalDiv) + intButtonOffset - intIEOffset;
		intFocalHeight = intWinHeight - intOffsetY;
		if (intFocalHeight<300) intFocalHeight = 300;  // Enforce minimum height
		objFocalDiv.style.height = intFocalHeight + "px";
	} 	
}

function findPosX(obj) {
// Function for finding the x coordinate of an object whose pointer is given as an argument.
// Returns the x coordinate as an integer, relative to the top left origin.
	var intCurlLeft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			intCurlLeft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		intCurlLeft += obj.x;
	return intCurlLeft;
}	

function findPosY(obj) {
// Function for finding the y coordinate of an object whose pointer is given as an argument.
// Returns the y coordinate as an integer, relative to the top left origin.
	var intCurlTop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			intCurlTop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		intCurlTop += obj.t;
	return intCurlTop;
}	

function setBody(id) {
// Sets the width of a web page that is framed inside an iframe in a main page.
// Finds the width of the parent page (as determined by the width of the browser window),
// and subtracts an offset amount specified by a Javascript variable 'intSidebarOffset'
// specified in the parent page (this offset accounts for the width of the sidebar
// that exists on all framed pages).

	var objFrameContainer = top.document.getElementById(id);
	if (objFrameContainer) {
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			newWidth = top.window.innerWidth - parent.intSidebarOffset;
			// @ TO DO: Need to find out about frmResults
			var objForm=document.getElementById('frmResults');
			objForm.style.width=newWidth+"px";
		} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			//IE 6+ in 'standards compliant mode'
			newWidth = top.document.body.offsetWidth - (parent.intSidebarOffset + 20);
			document.body.style.width=newWidth+"px";
		} 	
	} 
}

// SPRID 210: typically need to 'return clickbutton(..) in keypress handler to suppress usual keypress handling to retain effect of <control>.focus()
function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      }
} 

function findFrame(frameID, IFrameID) {
	if ((IFrameID == null) || (IFrameID == ''))
		return top.document.getElementById(frameID);
	var iframeFrame = top.document.getElementById(IFrameID);
	return findFrameAux(frameID, iframeFrame);
}

function findFrameAux(frameID, parentFrame) {
	//debugger;
	var ret = null;
	if (navigator.appName.indexOf('Netscape')>(-1)) {
		if (parentFrame != null)
			{
			var doc = parentFrame.contentDocument;
			if (doc != null)
				ret = doc.getElementById(frameID);
			}
		return ret;
	} 
	if (navigator.appName.indexOf('Microsoft Internet Explorer')>(-1)) {
		if (parentFrame != null)
			{
			if (parentFrame.contentWindow != null)
				ret = parentFrame.contentWindow.frames[frameID];
			if (ret == null)
				ret = parentFrame.document.getElementById(frameID);
			}
		return ret; 
	} 
}

function getDocument(frameObj) {
	if (frameObj.contentWindow != null)
		return frameObj.contentWindow.document;
	else
		return frameObj.document;
	}
	
function isSystemAdminChecked(pCheckBoxListClientId, pAllCheckboxName)
{
    var i = 0;
    var checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
    while(null != checkbox)
    {                  
        var roleName = '';
        //get the role name  
        if(document.all)
        { roleName = checkbox.nextSibling.innerText.toLowerCase(); }
        else
        { roleName = checkbox.nextSibling.textContent.toLowerCase(); }
           
        pAllCheckboxName = pAllCheckboxName.toLowerCase();
                        
        if (roleName == pAllCheckboxName)
        {                
            i++;            
            checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
            continue;             
        }                
        //Replace the spaces      
        roleName = roleName.replace(' ', '');
        if( roleName.startsWith("systemadministrator") && checkbox.checked )
            return true;
        
        i++;            
        checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
    }       
    
    return false;               	   	    
}


var blnScrollbusybox;

function setScrimHeight() {
// Sets the height of the scrim layer, and positions the busybox.
// Height is specified as total available browser height.

    var objScrim = document.getElementById('tblScrim');
    if (objScrim) {
		// make sure Scrim cover full screen with clientHeight&clientWidth or 
		// full scrollHeight if there is scroll bar
        var intScrimHeight = getWinHeight();
        if (intScrimHeight > document.body.clientHeight)
			objScrim.style.height = intScrimHeight + "px";
	    else 
			objScrim.style.height = document.body.clientHeight + "px";
	     
        objScrim.style.width = document.body.clientWidth + "px";
   }     
    
   setBusyboxPosition();
}

function setBusybox() {
// Positions the busybox in the center of the window.

	if (blnScrollbusybox)
		setBusyboxPosition();
	else
		return;
}

function setBusyboxPosition() {
		
    var scrollPosition;
    
    if (navigator.appName == "Microsoft Internet Explorer"){
        scrollPosition = document.body.scrollTop ;
    } else {
        scrollPosition = window.pageYOffset;
    }
            
    var intWinHeight = getWinHeight();
    var intWinWidth = getWinWidth();
    
    var objBusybox = document.getElementById('divBusybox');
    if (objBusybox) {
        var intBusytop = (intWinHeight-objBusybox.offsetHeight);
        var intBusyleft = (intWinWidth-objBusybox.offsetWidth);
        intBusytop = Math.round(intBusytop/2) - 60 + scrollPosition;
        intBusyleft = Math.round(intBusyleft/2);
        if (intBusytop < 10) intBusytop = 10;
        if (intBusyleft < 10) intBusyleft = 10;
        var strBusytop = intBusytop + "px";
        var strBusyleft = intBusyleft + "px";
        objBusybox.style.top = strBusytop;
        objBusybox.style.left = strBusyleft;
    }
}

function getWinHeight() {
// Returns the integer height of the visible area of the browser window, in pixels
	var intHeight, blnIsIE;

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		intHeight = window.innerHeight;
		blnIsIE = false;
	} else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		intHeight = document.documentElement.clientHeight;
		// Does not have 'box model bug'
		blnIsIE = false;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		intHeight = document.body.clientHeight;
		blnIsIE = true;
	}			
	return intHeight;
}

function getWinWidth() {
// Returns the integer width of the visible area of the browser window, in pixels
	var intWidth, blnIsIE;

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		intWidth = window.innerWidth;
		blnIsIE = false;
	} else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		intWidth = document.documentElement.clientWidth;
		// Does not have 'box model bug'
		blnIsIE = false;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		intWidth = document.body.clientWidth;
		blnIsIE = true;
	}			
	return intWidth;
}

function showBusybox(message, progressMessage) {
// Rewrites the text message shown in the busybox, and makes it visible
    if (frames["frameBusybox"] != null)
        {
	    frames["frameBusybox"].setMessage(message, progressMessage);
	    frames["frameBusybox"].restartAnimation();
	    setScrimHeight();
	    show("tblScrim");
	    }
}

function hideBusybox() {
// Hides the busybox and scrim
	var objHide = document.getElementById('tblScrim');
	if (objHide)
	{
        if (frames["frameBusybox"] != null)
	    	hide(objHide, frames["frameBusybox"]);
	}
	else 
	{
		objHide = top.document.getElementById('tblScrim');
		if (objHide)
		{
            if (frames["frameBusybox"] != null)
		    	hide(objHide, top.frames["frameBusybox"]);
		}
	}
}

function autoHideBusybox() {
// Hides the busybox and scrim if there are no child frames
	//debugger;
	if(window.frames.length > 0) {
		var objHide = document.getElementById('tblScrim');
		if (objHide)
		{ 
			hide(objHide, frames["frameBusybox"]);
		}
	}
}

function setBusyBoxDefaultMessage(defaultMessage) {
    //debugger;
	frames["frameBusybox"].setDefaultMessage(defaultMessage);
}

function show(objID) {
	var objShow = document.getElementById(objID);
	objShow.style.visibility = "visible";
	blnScrollbusybox = true;
}
		
function hide(objHide, frameAnimation) {
// Makes an object with ID objID hidden
	objHide.style.visibility = "hidden";
	frameAnimation.stopAnimation();
	blnScrollbusybox = false;
}

function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

// Fixes a decoding error in ComponentArt Grid columns which leaves '<' undecoded (but not '>')
function decodeLBrackets(uri) {
    var ret = uri;
    while (ret.search('#%cLt#%') >= 0)
        ret = ret.replace('#%cLt#%', '<');
    if (ret == "")
        // SPR 1712
        return "&nbsp;";
    else
        return ret;
}

function OpenHelpWindow(helpUrlForIE)
{
	w=window.open(helpUrlForIE, '', "left=650,top=650,width=1,height=1,toolbar=0,status=0,menubar=0");
	w.blur();
	setTimeout("w.close()", 3000);
}

Inmagicinc.WebControls.CommonScripts = function()
{ 
    return {
        CreateCookie : function (Name,Value,ExpireInDays){
            createCookie(Name,Value,ExpireInDays);
        },
        
        ReadCookie : function(Name) {
            return readCookie(Name);
        },
        
        SetCUIControlVisibility : function(cuiRowFormat, visible) {
            var ctrlRowID;
            var ctrlRow;
            for (var i = 1; i <= 3; i++) {
                ctrlRowID = String.format(cuiRowFormat, i);
                ctrlRow = document.getElementById(ctrlRowID);
                if (ctrlRow != null) {
                    if (visible)
                        ctrlRow.style.display = 'block';
                    else
                        ctrlRow.style.display = 'none';
                }
            }
        },
        
        GetRandomID : function() {
            var rand_id1 = parseInt(Math.random()*10000);
            var rand_id2 = parseInt(Math.random()*10000);
            var dt = new Date();
            
            return rand_id1 + '-' + dt.format("yyyyLLddmmhhMMssLL") + '-' + rand_id2;
        }
    };
    
    //*******************************  Private methods *********************************
    
    function createCookie(name,value,days) {
        var expires = "";
	    if (days) {
		    var date = new Date();
		    date.setTime(date.getTime()+(days*24*60*60*1000));
		    expires = "; expires="+date.toGMTString();
	    }
        var cookie_props = name+"="+value+expires+"; path=/";
	    document.cookie = name+"="+value+expires+"; path=/";
    }

    function readCookie(name) {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    //alert(document.cookie);
	    for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) 
		    {
		        return c.substring(nameEQ.length,c.length);
		    }
	    }

	    return null;
    }
}

//***************************************************
//* Methods to Base64 encode/decode string to UTF-8 *
//* Creator: http://www.webtoolkit.info/            *
//***************************************************
Inmagicinc.WebControls.Base64 = function()
{
    return {
        // private property
	    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	    // public method for encoding
	    encode : function (input) {
		    var output = "";
		    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		    var i = 0;
 
		    input = _utf8_encode(input);
 
		    while (i < input.length) {
 
			    chr1 = input.charCodeAt(i++);
			    chr2 = input.charCodeAt(i++);
			    chr3 = input.charCodeAt(i++);
 
			    enc1 = chr1 >> 2;
			    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			    enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			    enc4 = chr3 & 63;
 
			    if (isNaN(chr2)) {
				    enc3 = enc4 = 64;
			    } else if (isNaN(chr3)) {
				    enc4 = 64;
			    }
 
			    output = output +
			    this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			    this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		    }
 
		    return output;
	    },
 
	    // public method for decoding
	    decode : function (input) {
		    var output = "";
		    var chr1, chr2, chr3;
		    var enc1, enc2, enc3, enc4;
		    var i = 0;
 
		    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		    while (i < input.length) {
 
			    enc1 = this._keyStr.indexOf(input.charAt(i++));
			    enc2 = this._keyStr.indexOf(input.charAt(i++));
			    enc3 = this._keyStr.indexOf(input.charAt(i++));
			    enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			    chr1 = (enc1 << 2) | (enc2 >> 4);
			    chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			    chr3 = ((enc3 & 3) << 6) | enc4;
 
			    output = output + String.fromCharCode(chr1);
 
			    if (enc3 != 64) {
				    output = output + String.fromCharCode(chr2);
			    }
			    if (enc4 != 64) {
				    output = output + String.fromCharCode(chr3);
			    }
 
		    }
 
		    output = _utf8_decode(output);
 
		    return output;
 
	    }
	};
 
	// private method for UTF-8 encoding
	function _utf8_encode (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	}
 
	// private method for UTF-8 decoding
	function _utf8_decode (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}

}

//*******************************  Modal Popup Class *********************************
Inmagicinc.WebControls.ModalPopup = function(PopupCtrlID, BoxWidth, BoxHeight)
{ 
    //Call the initialize method upon creating the object
    initmb();
    
    //Declare the global values
    var _pcID = PopupCtrlID;
    var _width = BoxWidth;
    var _height = BoxHeight;
    
    //*******************************  Public methods *********************************
    return {
        Show : function() {
            showModal(_pcID, _width, _height);
        },
        
        Hide : function () {
            hideModal(_pcID);
        }
    };
    
    //*******************************  Private methods *********************************
    
    // Modal Dialog Box copyright 8th July 2006 by Stephen Chapman, http://javascript.about.com/, permission to use this Javascript on your web page is granted provided that all of the code in this script (including these comments) is used without any alteration
    function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
    function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
    function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
    function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
    function $(x){return document.getElementById(x);}
    function scrollFix(){var obol=$('modalOverlay');obol.style.top=posTop()+'px';obol.style.left=posLeft()+'px'}function sizeFix(){var obol=$('modalOverlay');obol.style.height=pageHeight()+'px';obol.style.width=pageWidth()+'px';}
    function kp(e){ky=e?e.which:event.keyCode;if(ky==88||ky==120)hm();return false}
    function inf(h){
        //tag=document.getElementsByTagName('select');
        //for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
        tag=document.getElementsByTagName('iframe');
        for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
        tag=document.getElementsByTagName('object');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
    }
    
    function showModal(obl, wd, ht){
        var h='hidden';var b='block';var p='px';var obol=$('modalOverlay'); var obbxd = $('mbd');obbxd.innerHTML = $(obl).innerHTML;obol.style.height=pageHeight()+p;obol.style.width=pageWidth()+p;obol.style.top=posTop()+p;obol.style.left=posLeft()+p;obol.style.display=b;var tp=posTop()+((pageHeight()-ht)/2)-12;var lt=posLeft()+((pageWidth()-wd)/2)-12;var obbx=$('modalBox');obbx.style.top=(tp<0?0:tp)+p;obbx.style.left=(lt<0?0:lt)+p;obbx.style.width=wd+p;obbx.style.height=ht+p;inf(h);obbx.style.display=b;return false;
    }
    function hideModal(){var v='visible';var n='none';$('modalOverlay').style.display=n;$('modalBox').style.display=n;inf(v);document.onkeypress=''}
    function initmb(){var ab='absolute';var n='none';var obody=document.getElementsByTagName('body')[0];var frag=document.createDocumentFragment();var obol=document.createElement('div');obol.setAttribute('id','modalOverlay');obol.style.display=n;obol.style.position=ab;obol.style.top=0;obol.style.left=0;obol.style.zIndex=998;obol.style.width='100%';frag.appendChild(obol);var obbx=document.createElement('div');obbx.setAttribute('id','modalBox');obbx.style.display=n;obbx.style.position=ab;obbx.style.zIndex=999;var obl=document.createElement('span');obbx.appendChild(obl);var obbxd=document.createElement('div');obbxd.setAttribute('id','mbd');obl.appendChild(obbxd);frag.insertBefore(obbx,obol.nextSibling);obody.insertBefore(frag,obody.firstChild);
    window.onscroll = scrollFix; window.onresize = sizeFix;}
}

 function areAllElementsChecked(pCheckBoxListClientId)
    {        
        var allChecked = true;
        var i = 0;
        var checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        var permissionSelected;
        while(null != checkbox)
        {            
            permissionSelected = checkbox.nextSibling.innerHTML;
            if( permissionSelected.toLowerCase() != "all" )
            {
                allChecked = allChecked && checkbox.checked;                                                                 
            }
            i++;            
            checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );            
        }
                        
        return allChecked;
    }   
    
    function areAllElementsCheckedWillAllCheckboxName( pAllCheckboxName, pCheckBoxListClientId )
    {        
        var allChecked = true;
        var i = 0;
        var checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        var permissionSelected;
        
        
        pAllCheckboxName = pAllCheckboxName.toLowerCase();
        while(null != checkbox)
        {            
            permissionSelected = checkbox.nextSibling.innerHTML;
            if( permissionSelected.toLowerCase() != pAllCheckboxName )
            {
                allChecked = allChecked && checkbox.checked;                                                                 
            }
            i++;            
            checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );            
        }
                        
        return allChecked;
    }   
    
    function handleCheckboxListClickWithAllCheckboxName(pAllCheckboxName, pCheckBoxListClientId, checkbox)
    {                   
        var cbxSelected = checkbox.nextSibling.innerHTML;       
        pAllCheckboxName = pAllCheckboxName.toLowerCase(); 
        
        if( cbxSelected.toLowerCase() == pAllCheckboxName )
        {
           checkAllElements(pCheckBoxListClientId, checkbox.checked); 
        }
        else
        {
           checkAllCheckboxWithAllCheckboxName(pAllCheckboxName, pCheckBoxListClientId, areAllElementsCheckedWillAllCheckboxName(pAllCheckboxName,pCheckBoxListClientId));           
        }                                                                        
    }      
        
       
    function handleCheckboxListClick(pCheckBoxListClientId, checkbox)
    {                   
        var cbxSelected = checkbox.nextSibling.innerHTML;   
        cbxSelected = cbxSelected.toLowerCase();
             
        
        if( cbxSelected == "all" )
        {
           checkAllElements(pCheckBoxListClientId, checkbox.checked); 
        }
        else
        {
           checkAllCheckbox(pCheckBoxListClientId, areAllElementsChecked(pCheckBoxListClientId));           
        }    
        
        if( cbxSelected != "create active" && cbxSelected != "create inactive" && cbxSelected != "view" && checkbox.checked )                         
        {
            checkCheckBox(pCheckBoxListClientId, "view", true);
        }     
                
    }
    
    function checkCheckBox(pCheckBoxListClientId, pCheckboxToCheck, pShouldCheck)
    { 
        var i = 0;
        var checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
                
        while(null != checkbox)
        {                        
            var permissionSelected = checkbox.nextSibling.innerHTML;
                            
            if (permissionSelected.toLowerCase() == pCheckboxToCheck)
            {                
               checkbox.checked = pShouldCheck;             
            }
            
            i++;            
            checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        }       
    }


    function checkAllElements(pCheckBoxListClientId, pShouldCheck)
    {                
        var i = 0;
        var checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        while(null != checkbox)
        {                        
            checkbox.checked = pShouldCheck;
            
            i++;            
            checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        }       
               
    }    
    
    function EnabledAspNetLinkButton(pButton, uniqueId)
    {        
        pButton.removeAttribute("disabled");
        pButton.style.color="";
        pButton.setAttribute("href", "javascript:__doPostBack('" + uniqueId + "','')");                        
    }   
    
    function DisableAspNetLinkButton(pButton, uniqueId)
    {        
        pButton.setAttribute("disabled","disabled");
        pButton.style.color="gray";
        pButton.removeAttribute("href");
        
    }   
    
    function GetNumberOfListItems(pAllCheckboxName, pCheckBoxListClientId)    
    {
        var i = 1; //start with 1 since the 0 index is the "Select All Roles"
        var checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        while(null != checkbox)
        {   
            var roleName = '';
            
            //get the role name  
            if(document.all)
            { roleName = checkbox.nextSibling.innerText.toLowerCase(); }
            else
            { roleName = checkbox.nextSibling.textContent.toLowerCase(); }
            
            if (roleName != pAllCheckboxName.toLowerCase())
                i++; 
            
            checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        }       
        
        return i-1;
    }
    
    function checkAllCheckbox(pCheckBoxListClientId, pShouldCheck)
    {
        var i = 0;
        var checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        while(null != checkbox)
        {                        
            var permissionSelected = checkbox.nextSibling.innerHTML;
                            
            if (permissionSelected.toLowerCase() == "all")
            {                
               checkbox.checked = pShouldCheck;             
            }
            
            i++;            
            checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        }                
    }    
    
    function checkAllCheckboxWithAllCheckboxName(pAllCheckboxName, pCheckBoxListClientId, pShouldCheck)
    {
        var i = 0;
        var checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        
        pAllCheckboxName = pAllCheckboxName.toLowerCase();
        while(null != checkbox)
        {                        
            var permissionSelected = checkbox.nextSibling.innerHTML;
                            
            if (permissionSelected.toLowerCase() == pAllCheckboxName)
            {                
               checkbox.checked = pShouldCheck;             
            }
            
            i++;            
            checkbox = document.getElementById(pCheckBoxListClientId + "_" + i );
        }                
    }    
 
    