﻿// ====================================================================================================
//
//          Page: JSLibrary
//        Author: Michael Marzilli   ( http://www.linkedin.com/in/michaelmarzilli )
//       Created: May 29, 2008
//
//	Minify with: http://sundgaard.dk/javascript-minify.aspx
//
// VERS 1.0.000 : May 29, 2008 : Original File Created.
//			1.0.001 : Jun 27, 2008 : Modified toggleNode function to change the Display style attribute.
//			1.0.002 : Jul 11, 2008 : Added "setGotFocus" function to set focus to a textbox's last character.
//			1.0.003 : Oct 15, 2008 : Added "prototype.js" and "browser.js" libraries, which make it easier
//															 to gather browser/document information. 
//															 IE replace document.getElementById with $
//			1.0.004 : Dec 16, 2008 : Added code to handle resizing of Google Maps when page is resized.
//			1.0.005 : Apr 17, 2009 : Added ability to save the Toggleable Nodes Open/Close state across PostBacks.
//															 Using a hidden field:  <asp:HiddenField ID="nodeSave" runat="server" />
//															 Added ability to save the Scrollbar position across PostBacks.
//															 Using a hidden field:  <asp:HiddenField ID="pageScrollOffset" runat="server" />
//			1.0.006 : May 19, 2009 : Added Functions for handling several controls; Google Maps, Google Search and
//															 PayPal.
//			1.0.007 : May 29, 2009 : Added functions for handling the Photo Album.
//			1.0.008 : Jun 11, 2009 : Improved Photo Album functions, corrected Album Large View size compared
//															 to Document Width and Height.
//			1.0.009 : Jun 16, 2009 : Added an Upload File progress bar.
//			1.0.010 : Jun 22, 2009 : Resolved issue with FireFox browsers where photo album image was not
//															 loading properly. (increased time delay in the image load function).
//			1.0.011 : Jun 25, 2009 : Added Jeff Todnem's Password Strength script.
//			1.0.012 : Apr 07, 2010 : Added code for AJAX Web Chat.
//			1.0.013 : Apr 27, 2010 : Rewrote AJAX Code to be more Generic.  Rewrote Web Chat to use new AJAX Library.
//			1.0.014 : Jun 16, 2010 : Added an AJAX Commenting System.
//			1.0.015 : Jul 12, 2010 : Added code to handle Animated Button control.
//			1.0.016 : Aug 26, 2010 : Updated the Comments Code to allow Paging of Comments.
//			1.0.017 : Aug 11, 2011 : Moved AJAX and User Control-Specific code into separate files, 
//															 to be loaded on demand.
//
// ====================================================================================================





// DEFINE PROGRAM CONSTANTS
// ----------------------------------------------------------------------------------------------------

	var intTopOffset = 157;
	
	var intFadeIn    = 0;
	var opacLevel    = 0;
	var opacStep     = 0.10;
	var intBackgroundContentArea = 1;			// 1=Full Page, 2=Only Content Area (not the Header)





// COOKIE FUNCTIONS
// ----------------------------------------------------------------------------------------------------

	function WriteCookie(name, value, days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function WriteCookieMinute(name, value, mins) {
		if (mins) {
			var date = new Date();
			date.setTime(date.getTime()+(mins*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function ReadCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		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;
	}

	function EraseCookie(name) {
		WriteCookie(name, '', -1);
	}


	// BOOKMARK FUNCTIONS
	// ----------------------------------------------------------------------------------------------------

	function CreateBookmark(strTitle, strURL)
	{
		if (window.sidebar)
		{ // Mozilla Firefox Bookmark
			window.sidebar.addPanel(strTitle, strURL, "");
		} else if (window.external)
		{ // IE Favorite
			window.external.AddFavorite(strURL, strTitle);
		} else if (window.opera && window.print)
		{ // Opera Hotlist
			alert('Please press CONTROL-D to bookmark this page.');
		}
		return false;
	}


	// GENERIC STRING FUNCTIONS
// ----------------------------------------------------------------------------------------------------

	function startsWith(str, prefix) { return str.indexOf(prefix)   == 0; }
	function endsWith(str, suffix)   { return str.match(suffix+"$") == suffix;	}
	function trim(str)               { return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); };

	// REPLACE URLS WITH HREF LINKS IN TEXT
	// ----------------------------------------------------------------------------------------------------
	function chat_string_create_urls(input)
	{
		return input
    .replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim, '<a href="$&" class="my_link" target="_blank">$&</a>')
    .replace(/([^\/])(www[\S]+(\b|$))/gim, '$1<a href="http://$2" class="my_link" target="_blank">$2</a>');
	}



// TIME OF DAY GREETING
// ----------------------------------------------------------------------------------------------------

	function TimeGreeting()
	{
		var dtDateNow  = new Date();
		var tmTimeNow  = dtDateNow.getTime();
		dtDateNow.setTime(tmTimeNow);
		var theHour    = dtDateNow.getHours();
		var strDisplay = 'Welcome, ';
		if (theHour > 17) 
			strDisplay = 'Good Evening, ';
		else if (theHour >11) 
			strDisplay = 'Good Afternoon, '; 
		else
			strDisplay = 'Good Morning, '; 
		
		var docWelcome = getObjectElementByID('', 'ctl00_lblMstrUser');
		if (docWelcome != null)
		{
			var strInner = docWelcome.innerHTML;
			if (strInner != null && strInner != '')
			{
				strInner = strInner.replace('Welcome, ', strDisplay);
				docWelcome.innerHTML = strInner;
			}
		}
	}
	function CopyContents(src, tgt)
	{
		var objSource = getObjectElementByID('', src);
		var objTarget = getObjectElementByID('', tgt);
		
		if (objSource != null && objTarget != null)
		{
			objTarget.value = objSource.value;
		}
	}


// PAGE SETUP FUNCTION
// ----------------------------------------------------------------------------------------------------

	function click(e) 
	{
		var message="Sorry, right-click has been disabled on this web site.";
		if (document.all) {
			if (event.button == 2) {
				alert(message);
				return false;
			}
		}
		if (document.layers) {
			if (e.which == 3) {
				alert(message);
				return false;
			}	
		}
	}
	function DisableCopy()
	{
		var pressedKey;
		try { pressedKey = String.fromCharCode(event.keyCode).toLowerCase(); } catch (err) { pressedKey = ''; }
		if (event.ctrlKey && pressedKey == 'c')
			event.returnValue = false;
	}

	function SetContentBackgroundImage()
	{
		var div = getObjectElementByID('', 'divMPpage');
		
		switch (intBackgroundContentArea)
		{
			case 1:		// THIS WILL SET THE ENTIRE PAGE'S BACKGROUND AREA
				div = getObjectElementByID('', 'divMPpage');
				break;
			case 2:		// THIS WILL SET THE CONTENT BACKGROUND AREA ONLY
				div = getObjectElementByID('', 'divMPcontent');
				break;
		}
		
		if (div != null)
		{
			if (strBGimage != '')
				div.style.backgroundImage = 'url(\'' + strBGimage + '\')';
			if (strBGalign != '')
				div.style.backgroundPosition = strBGalign;
			div.style.backgroundAttachment = 'fixed';
			div.style.backgroundSize       = '100% 100%';
		}
		
		if (intFadeIn == 1)
			fade_text();
	}

	function fade_text()
	{ 
		if (opacLevel >= 1)
			return;
		opacLevel = opacLevel + opacStep;
		document.body.style.filter       = 'alpha(opacity=' + (opacLevel * 100) + ')';
		document.body.style.opacity      = opacLevel;
		document.body.style.MozOpacity   = opacLevel;
		document.body.style.KhtmlOpacity = opacLevel;
		var t = setTimeout('fade_text()', 10);
	}	
	
	function OnPageLoad()
	{
		if (intFadeIn == 1)
		{
			document.body.style.filter       = 'alpha(opacity=0)';
			document.body.style.opacity      = 0;
			document.body.style.MozOpacity   = 0;
			document.body.style.KhtmlOpacity = 0;
		}
		
		// DISABLE RIGHT-CLICKS
		if (document.layers) {
			document.captureEvents(Event.MOUSEDOWN);
		}
		document.onmousedown = click;
	}


// SAVED SCROLLBAR OFFSET
// ----------------------------------------------------------------------------------------------------
	var blnSetScrollBar = 0;
	var intSetScrollBar = 0;
	var ivlScrollBar;
	
	function getThePageScrollOffset()
	{
		var sbOffset;
		var strObjectName = 'pageScrollOffset';
		
		sbOffset = getObjectElementByID('', strObjectName);
		
		return sbOffset;
	}
	function SetPageScrollOffset()
	{
		var sb = getThePageScrollOffset();
		var dv = document.getElementById("divMPcontent");

		if (sb != null && dv != null)
		{
			var intOffset = dv.scrollTop;
			sb.value = intOffset;
		}
		
		return false;
	}
	function GetPageScrollOffset()
	{
		if (blnSetScrollBar != 0 || intSetScrollBar > 20)
		{
			window.clearInterval(ivlScrollBar);
			return;
		}
		
		var sb = getThePageScrollOffset();
		var dv = document.getElementById("divMPcontent");
		
		if (sb != null && dv != null)
		{
			
			var intOffset = eval(sb.value - 0);
			if (sb.value == '')
				intOffset = 0;
		
			dv.scrollTop = intOffset; 

			if (dv.scrollTop == intOffset)	
				blnSetScrollBar = 1;
		} else {
			intSetScrollBar++;
			blnSetScrollBar = 1;
		}
	}
		
	
	
// Toggle a FAQ DIV Node Visible/Invisible
// ----------------------------------------------------------------------------------------------------
	function getNodeSave(strObjectName)
	{
		var ns;
		
		ns = getObjectElementByID('', strObjectName);
			
		return ns;
	}
	
	function initNode() {
		var ns = getNodeSave('nodeSave');
			
		if (ns != null)
		{
			var strItems = ns.value;

			if (strItems == '')
			{
				strItems = '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
				ns.value = strItems;
			}
		
			var intLen   = strItems.length;
			var strItem  = '';

			for(var i = 0; i < intLen; i++)
			{
				strItem = strItems.substring(i-1, i);
				initToggleNode(i, strItem);
			}			
		}
	}
	
	function initToggleNode(item, vis) {
		var nodeDiv  = getObjectElementByID('', 'N_' + item);
		var nodeIcon = getObjectElementByID('', 'I_' + item);
					
		if (nodeDiv == null || nodeIcon == null)
			return;
					
		if (vis == '1')
		{
			nodeDiv.style.visibility = 'visible';
			nodeDiv.style.display    = 'block';
			nodeIcon.src             = 'Images/tree/m.gif';
			nodeIcon.alt             = '-';
		}
		else
		{
			nodeDiv.style.visibility = 'hidden';
			nodeDiv.style.display    = 'none';
			nodeIcon.src             = 'Images/tree/p.gif';
			nodeIcon.alt             = '+';
		}
	}
	
	
	function toggleNode(item) {
		var nodeDiv  = getObjectElementByID('', 'N_' + item);
		var nodeIcon = getObjectElementByID('', 'I_' + item);
		var intItem  = eval(item - 0);
		var strVal   = '';
		var strOld   = '';
		var strNew   = '';

		if (nodeDiv == null || nodeIcon == null)
			return;
												
		if (nodeDiv.style.visibility == 'visible')
		{
			nodeDiv.style.visibility = 'hidden';
			nodeDiv.style.display    = 'none';
			nodeIcon.src             = 'Images/tree/p.gif';
			nodeIcon.alt             = '+';
			strVal                   = '0';
		}
		else
		{
			nodeDiv.style.visibility = 'visible';
			nodeDiv.style.display    = 'block';
			nodeIcon.src             = 'Images/tree/m.gif';
			nodeIcon.alt             = '-';
			strVal                   = '1';
		}
		
		var ns = getNodeSave('nodeSave');
		if (ns != null)
		{
			strOld = ns.value;
		
			if (intItem > 1)
				strNew = strOld.substring(0, intItem - 1);
			strNew = strNew + strVal;
			if (intItem < strOld.length)
				strNew = strNew + strOld.substring(intItem, strOld.length);
				
			ns.value = strNew;
		}
		
		return false;
	}
	
	function toggleControlNode(item, num) {
		if (item.indexOf('H_') > 0)
			item = item.substr(0, item.indexOf('H_'));
			
		var nodeDiv  = getObjectElementByID('', item + 'N_' + num);
		var nodeIcon = getObjectElementByID('', item + 'I_' + num);
		var intItem  = eval(num - 0);
		var strVal   = '';
		var strOld   = '';
		var strNew   = '';
		
		if (nodeDiv == null || nodeIcon == null)
		{
			return item + 'N_' + num;
		}
					
		if (nodeDiv.style.visibility == 'visible')
		{
			nodeDiv.style.visibility = 'hidden';
			nodeDiv.style.display    = 'none';
			nodeIcon.src             = 'Images/tree/p.gif';
			nodeIcon.alt             = '+';
		}
		else
		{
			nodeDiv.style.visibility = 'visible';
			nodeDiv.style.display    = 'block';
			nodeIcon.src             = 'Images/tree/m.gif';
			nodeIcon.alt             = '-';
		}
		
		var ns = getNodeSave('nodeSave');
		if (ns != null)
		{
			strOld = ns.value;
		
			if (intItem > 1)
				strNew = strOld.substring(0, intItem - 1);
			strNew = strNew + strVal;
			if (intItem < strOld.length)
				strNew = strNew + strOld.substring(intItem, strOld.length);
				
			ns.value = strNew;
		}
		
		return;
	}
	

// Toggle a DIV Node Visible/Invisible
// ----------------------------------------------------------------------------------------------------
	function ToggleObjectVisibility(item) {
		var nodeDiv  = getObjectElementByID('', item);
		
		if (nodeDiv.style.visibility == 'visible')
		{
			nodeDiv.style.visibility = 'hidden';
			nodeDiv.style.display    = 'none';
		}
		else
		{
			nodeDiv.style.visibility = 'visible';
			nodeDiv.style.display    = 'block';
		}
	}


// Toggle a DIV Node Visible/Invisible  -  Forced On or Off
// ----------------------------------------------------------------------------------------------------
	function ToggleObjectVisibility(item, isVisible) {
		var nodeDiv  = getObjectElementByID('', item);
		
		if (!isVisible)
		{
			nodeDiv.style.visibility = 'hidden';
			nodeDiv.style.display    = 'none';
		}
		else
		{
			nodeDiv.style.visibility = 'visible';
			nodeDiv.style.display    = 'block';
		}
	}


// Focus on a TextBox, and set the Cursor to the last position.
// ----------------------------------------------------------------------------------------------------
	function setGotFocus(myField, myValue) {
		document.forms[0][myField].value = myValue;
		document.forms[0][myField].focus();
	}


// Given a Control Name and an Element Name, return the Element Object.
// ----------------------------------------------------------------------------------------------------
	function getObjectElementByID(strControlName, strObjectName)
	{
		var ns;
		var strControlTemp;	
		
		ns = document.getElementById(strObjectName);
		
		if (ns == null)
			try { ns = document.forms[0][strObjectName]; } catch (Error) { }

		if (ns == null)
			try { ns = getObjectElementByID('', strObjectName); } catch (Error) { }
			
		// SEARCH INSIDE THE CONTENT CONTAINER
		if (ns == null)
		{
			strControlTemp = strControlName;
			if (strControlName != '')
				strControlTemp = strControlName + '$';
			try { ns = document.getElementById(strControlTemp + strObjectName); } catch (Error) { }
			strControlTemp = 'ctl00$ContentPlaceHolder1$' + strControlTemp + strObjectName;
			if (ns == null)				
				try { ns = document.getElementById(strControlTemp); } catch (Error) { }
		}
		
		if (ns == null)
		{
			strControlTemp = strControlName;
			if (strControlName != '')
				strControlTemp = strControlName + '_';
			try { ns = document.getElementById(strControlTemp + strObjectName); } catch (Error) { }
			strControlTemp = 'ctl00_ContentPlaceHolder1_' + strControlTemp + strObjectName;
			if (ns == null)				
				try { ns = document.getElementById(strControlTemp); } catch (Error) { }
		}
		
		// SEARCH OUTSIDE THE CONTENT CONTAINER
		if (ns == null)
		{
			strControlTemp = strControlName;
			if (strControlName != '')
				strControlTemp = strControlName + '$';
			strControlTemp = 'ctl00$' + strControlTemp + strObjectName;
			try { ns = document.getElementById(strControlTemp); } catch (Error) { }
		}
		
		if (ns == null)
		{
			strControlTemp = strControlName;
			if (strControlName != '')
				strControlTemp = strControlName + '_';
			strControlTemp = 'ctl00_' + strControlTemp + strObjectName;
			try { ns = document.getElementById(strControlTemp); } catch (Error) { }
		}
				
		return ns;
	}

	function getObjectElementParent(strControlName)
	{
		var strTemp = strControlName;
		var n       = strTemp.lastIndexOf("_");
		if (n >= 0)
			strTemp = strTemp.substring(0, n);
		
		return strTemp;
	}


	// Resize an Image
	// ----------------------------------------------------------------------------------------------------
	function ResizeImage(img, intWidth, intHeight)
	{
		var tempImg;

		try { tempImg = getObjectElementByID('', img); } catch (Error) { tempImg = null; }
		if (tempImg != null)
			img = tempImg;

		if (img == null)
			return;

		if (intWidth == 0 && intHeight == 0)
			return;

		var str = img.id;
		var origWidth = img.width;
		var origHeight = img.height;
		var iError = 0;

		while ((origWidth == 0 || origHeight == 0) && iError < 1000)
		{
			origWidth = img.width;
			origHeight = img.height;
			iError++;
		}

		if (intWidth > 0 && intHeight > 0)
		{
			img.width = intWidth;
			img.height = intHeight;
		}
		else if (origWidth > 0 && origHeight > 0)
		{
			if (intWidth > 0 && intHeight == 0)
				intHeight = origHeight * (intWidth / origWidth);

			if (intHeight > 0 && intWidth == 0)
				intWidth = origWidth * (intHeight / origHeight);

			img.width = intWidth;
			img.height = intHeight;
		} else
		{
			setTimeout("ResizeImage('" + str + "', " + intWidth + ", " + intHeight + ")", 300);
		}
	}


// DOCUMENT ELEMENT FUNCTIONS
// ----------------------------------------------------------------------------------------------------

	function GetDDLselectedItem(ddl)
	{
		return ddl.item(ddl.selectedIndex).value;
	}
	function SetDDLselectedItem(ddl, val)
	{
		for (var i = 0; i < ddl.length; i++)
		{
			if (ddl.item(i).value == val)
			{
				ddl.selectedIndex = i;
				return true;
			}
		}
		return false;
	}
	function SetDDLSelectedItem(ctrl, ddlName, ddlValue)
	{
		var ddl = getObjectElementByID(ctrl, ddlName);
		if (ddl != null)
		{
			for (var i = 0; i < ddl.length; i++)
			{
				if (ddl.item(i).value == ddlValue)
				{
					ddl.selectedIndex = i;
					return true;
				}
			}
		}
		return false;
	}
	function GetRadioValue(radioObj)
	{
		if (!radioObj)
			return "";
		var radioLength = radioObj.length;
		if (radioLength == undefined)
			if (radioObj.checked)
				return radioObj.value;
			else
				return "";
		for (var i = 0; i < radioLength; i++)
		{
			if (radioObj[i].checked)
			{
				return radioObj[i].value;
			}
		}
		return "";
	}

	function SetObjectElementByID(ctrl, objName, objValue)
	{
		var obj = getObjectElementByID(ctrl, objName);
		if (obj != null)
			obj.value = objValue;
	}
	function SetObjectVisibility(ctrl, objName, blnShow)
	{
		var obj = getObjectElementByID(ctrl, objName);
		if (obj != null)
		{
			if (blnShow)
			{
				obj.style.visibility = 'visible';
				obj.style.display    = 'inline-block';
			} else {
				obj.style.visibility = 'hidden';
				obj.style.display    = 'none';
			}
		}
	}
	function SetObjectEnabled(ctrl, objName, bln)
	{
		var obj = getObjectElementByID(ctrl, objName);
		if (obj != null)
			obj.disabled = !bln;
	}



// Determine the Width of the Window
// ----------------------------------------------------------------------------------------------------
	function getWindowWidth() {
	
    if( !document.all ) {
      //Non-IE
      return window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      return document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      return document.body.clientWidth;
    } else if (document.documentElement && 
				typeof document.documentElement.clientWidth!='undefined' &&
				document.documentElement.clientWidth!=0) {
			return document.documentElement.clientWidth;
		}
		if (document.body && 
				typeof document.body.clientWidth!='undefined') {
			return document.body.clientWidth;
		}
	}


// Determine the Height of the Window
// ----------------------------------------------------------------------------------------------------
	function getWindowHeight() {
    if( !document.all ) {
      //Non-IE
      return window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      return document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      return document.body.clientHeight;
    } else if (document.documentElement && 
				typeof document.documentElement.clientWidth!='undefined' &&
				document.documentElement.clientHeight!=0) {
			return document.documentElement.clientHeight;
		}
		if (document.body && 
				typeof document.body.clientWidth!='undefined') {
			return document.body.clientHeight;
		}
	}
	

// Adjust the Body of the page so that the Footer portion remains at the bottom of the page
// ----------------------------------------------------------------------------------------------------
	function AdjustContentSize() {
		var intDocWidth   = 400;
		var intDocHeight  = 400;
		var intModifier   = 45;
		var intOffset     = 0;
		var intBotOffset  = 0;
		var intContOffset = 0;
					
		if (intScrollingPage != '1')
			return;
						
		try
		{
			// CREATE PAGE OBJECTS
			var tblHeader  = getObjectElementByID('', 'divMPheader');
			var tblFooter  = getObjectElementByID('', 'divMPfooter');
			var tblBody    = getObjectElementByID('', 'divMPcontent');
			var tblMenu    = getObjectElementByID('', 'divMPmenu');
			var tblContent = getObjectElementByID('', 'divMPcontent');
			var tblLogin   = getObjectElementByID('', 'divLogin');
			if (tblLogin == null)
				tblLogin = getObjectElementByID('', 'ctl00_divLogin');
				
			// DETERMINE BROWSER INNER WINDOW SIZE
			intDocWidth  = getWindowWidth();
			intDocHeight = getWindowHeight();
				
			// ABORT IF THE WINDOW IS MADE TOO SMALL			
			if (intDocHeight <= intTopOffset + (intModifier * 3))
				return;
				
			// CALCULATE OFFSET FOR FOOTER
			if (tblFooter != null) 
				intBotOffset = tblFooter.offsetHeight; 
		
			// CALCULATE OFFSET FOR CONTENT PANEL OBJECT
			if (tblContent != null)
				intContOffset = tblContent.offsetHeight;
			 
			intOffset = intTopOffset + intBotOffset;		
							
			// REPOSITION THE LOGIN PANEL
			if (tblLogin != null)
			{
				tblLogin.style.left = (intDocWidth - 320) + 'px';
			}
			
			// RESIZE THE CONTENT PANEL
			SetTransDiv();
			if (tblBody != null) {
			
				// ONE PAGE SCROLLING ACTIVE
				if (intScrollingPage == "1") {
					if (tblContent.offsetHeight > intDocHeight - intTopOffset - 20) {
						tblBody.style.height = (intDocHeight - (intTopOffset + 22)) + 'px';	
						if (tblContent != null)
							tblContent.style.height = (intDocHeight - (intTopOffset + intBotOffset + intModifier)) + 'px';
						tblBody.style.overflow = "auto";
					} else {
						tblBody.style.height = (intDocHeight - (intTopOffset + 22)) + 'px';		
						if (tblContent != null)
							tblContent.style.height = (intDocHeight - (intTopOffset + intBotOffset + intModifier)) + 'px';
						tblBody.style.overflow = "auto";
						
					}
				} else {
					// ONE PAGE SCROLLING INACTIVE
					window.document.body.style.overflow = "auto";
					window.document.body.style.height   =  intDocHeight + 'px';
									
					if (tblContent.offsetHeight < intDocHeight - intTopOffset) {
						tblBody.style.height = (intDocHeight - (intTopOffset + 18)) + 'px';	

						if (tblContent != null) 
							tblContent.style.height = (intDocHeight - (intTopOffset + intBotOffset + intModifier)) + 'px';
					}
				}
			}
		} catch(Error) { }
	}
	
	
// Force Target Object Resize to Source Object's Height
// ----------------------------------------------------------------------------------------------------
	var strNewsSource = '';
	var strNewsTarget = '';

	function SourceHeightToTarget(strSource, strTarget) {
		var intSource = 0;
		var intTarget = 0;
		var intFooter = 0;
					
		// CREATE PAGE OBJECTS
		strNewsSource = strSource;
		strNewsTarget = strTarget;
		var tblSource = getObjectElementByID('', strSource);
		var tblTarget = getObjectElementByID('', strTarget);
		var tblFooter = getObjectElementByID('', 'masterTableFooter');

		// DETERMINE SOURCE'S HEIGHT
		if (tblSource != null) 
			intSource = tblSource.offsetHeight;
			
		// DETERMINE TARGET'S HEIGHT
		if (tblTarget != null)
			intTarget = tblTarget.offsetHeight;
			
		// DETERMINE FOOTER'S HEIGHT
		if (tblFooter != null)
			intFooter = tblFooter.offsetHeight;			
			
		// RE-CALCULATE
		if (intTarget - intFooter < intSource)
			tblTarget.style.height = (intSource + intFooter) + 'px';
	}


// Resize a Panel	
// ----------------------------------------------------------------------------------------------------
	function ResizeGridViewPanel(pnlName, gvName) {
		var pnlObj  = getObjectElementByID('', pnlName);
		var tbl     = getObjectElementByID('', gvName);
		
		if (pnlObj == null || tbl == null)
			return;
				
		try
		{
			var windowTop    = 230;
			var windowHeight = getWindowHeight(); 
			var gvHeight     = tbl.offsetHeight;
			var changeHeight = windowHeight;
			var newHeight    = 600;
				
			if (windowHeight > gvHeight)
				changeHeight = gvHeight + windowTop + 20;
							
			if (changeHeight > windowHeight)
				changeHeight = windowHeight;
						
			if (changeHeight < windowTop + 100)
				changeHeight = windowTop + 100;
			
			newHeight = changeHeight - windowTop;	
			pnlObj.style.height = newHeight + "px"; 				
		} catch(Error) { }
	}

	function SetTransDiv()
	{
		var obj = getObjectElementByID('', 'divTrans');
		
		try
		{
			if (obj != null)
			{
				obj.style.width  = getWindowWidth()  + 'px';
				obj.style.height = getWindowHeight() + 'px';
			}
		} catch(Error) { }
	}
	function ShowObject(obj)
	{
		if (obj != null)
		{
			obj.style.visibility = 'visible';
			obj.style.display = 'block';
		}
	}
	function HideObject(obj)
	{
		if (obj != null)
		{
			obj.style.visibility = 'hidden';
			obj.style.display    = 'none';
		}
	}

	
	
// Page Content Editor Functions
// ----------------------------------------------------------------------------------------------------

		function PageContentEditor_ShowDelete()
		{
			var btnDel = getObjectElementByID('', 'btnDelete');
			if (btnDel != null)
				btnDel.style.visibility = 'hidden';
			var btnYes = getObjectElementByID('', 'btnDeleteYes');
			if (btnYes != null)
				btnYes.style.visibility = 'visible';
			var btnNo = getObjectElementByID('',  'btnDeleteNo');
			if (btnNo != null)
				btnNo.style.visibility = 'visible';
		}
		function PageContentEditor_HideDelete()
		{
			var btnDel = getObjectElementByID('', 'btnDelete');
			if (btnDel != null)
				btnDel.style.visibility = 'visible';
			var btnYes = getObjectElementByID('', 'btnDeleteYes');
			if (btnYes != null)
				btnYes.style.visibility = 'hidden';
			var btnNo = getObjectElementByID('',  'btnDeleteNo');
			if (btnNo != null)
				btnNo.style.visibility = 'hidden';
		}
		function PageContentEditor_PopulatePageName()
		{
			var ddl = getObjectElementByID('', 'ddlASPfiles');
			var txt = getObjectElementByID('', 'txtEditPage');
			
			if (ddl != null && txt != null)
				txt.value = ddl.options[ddl.selectedIndex].value;
		}


		function SetDivColor(strDivID, theControl)
		{
			var theDiv = document.getElementById(strDivID);
			var strBGcolor;
			
			if (theControl != null)
				strBGcolor = theControl.value;

			if (theDiv != null)
				try {
					theDiv.style.backgroundColor = strBGcolor;
				} catch(Error) {
					theDiv.style.backgroundColor = 'white';
				}
			else
				alert('Could not find div: ' + strDivID + ', for Color: ' + strBGcolor);
		}

		function SetDivFont(strDivID, theControl)
		{
			var theDiv = document.getElementById(strDivID);
			var strFont;
			
			if (theControl != null)
				strFont = theControl.value;

			if (theDiv != null)
				try {
					theDiv.style.fontFamily = strFont;
				} catch(Error) {
					theDiv.style.fontFamily = 'Verdana';
				}
			else
				alert('Could not find div: ' + strDivID + ', for Color: ' + strBGcolor);
		}

		function SetAllDivColor()
		{
			var txt;
			
			// PRE-SET STORED FONTS
			txt = getObjectElementByID('ddlFonts', '');
			if (txt != null)
				SetDivFont('divFonts', txt);
			txt = getObjectElementByID('txtFonts', '');
			if (txt != null && txt.value != '')
				SetDivFont('divFonts', txt);
			
			// PRE-SET COLORS
			txt = getObjectElementByID('', 'txtPgColor');
			if (txt != null)
				SetDivColor('div1', txt);
			txt = getObjectElementByID('', 'txtPgBG');
			if (txt != null)
				SetDivColor('div3', txt);
			txt = getObjectElementByID('', 'txtContColor');
			if (txt != null)
				SetDivColor('div5', txt);
			txt = getObjectElementByID('', 'txtContBG');
			if (txt != null)
				SetDivColor('div7', txt);
			txt = getObjectElementByID('', 'txtFtrColor');
			if (txt != null)
				SetDivColor('div9', txt);
			txt = getObjectElementByID('', 'txtFtrBG');
			if (txt != null)
				SetDivColor('div11', txt);

			txt = getObjectElementByID('', 'txtPnlColor1');
			if (txt != null)
				SetDivColor('div13', txt);
			txt = getObjectElementByID('', 'txtPnlBG1');
			if (txt != null)
				SetDivColor('div15', txt);
			txt = getObjectElementByID('', 'txtPnlColor2');
			if (txt != null)
				SetDivColor('div17', txt);
			txt = getObjectElementByID('', 'txtPnlBG2');
			if (txt != null)
				SetDivColor('div19', txt);
			txt = getObjectElementByID('', 'txtPnlColor3');
			if (txt != null)
				SetDivColor('div21', txt);
			txt = getObjectElementByID('', 'txtPnlBG3');
			if (txt != null)
				SetDivColor('div23', txt);
				
			txt = getObjectElementByID('', 'txtPnlColor4');
			if (txt != null)
				SetDivColor('div25', txt);
			txt = getObjectElementByID('', 'txtPnlBG4');
			if (txt != null)
				SetDivColor('div27', txt);
			txt = getObjectElementByID('', 'txtCtrlColor');
			if (txt != null)
				SetDivColor('div29', txt);
			txt = getObjectElementByID('', 'txtCtrlBG');
			if (txt != null)
				SetDivColor('div31', txt);
			txt = getObjectElementByID('', 'txtMenuColor');
			if (txt != null)
				SetDivColor('div33', txt);
			txt = getObjectElementByID('', 'txtBrdrColor');
			if (txt != null)
				SetDivColor('div35', txt);

			txt = getObjectElementByID('', 'txtRTheaderColor');
			if (txt != null)
				SetDivColor('div14', txt);
			txt = getObjectElementByID('', 'txtRTheaderBG');
			if (txt != null)
				SetDivColor('div16', txt);
			txt = getObjectElementByID('', 'txtRTrowColor');
			if (txt != null)
				SetDivColor('div18', txt);
			txt = getObjectElementByID('', 'txtRTrowBG');
			if (txt != null)
				SetDivColor('div20', txt);
			txt = getObjectElementByID('', 'txtRTaltColor');
			if (txt != null)
				SetDivColor('div22', txt);
			txt = getObjectElementByID('', 'txtRTaltBG');
			if (txt != null)
				SetDivColor('div24', txt);

			txt = getObjectElementByID('', 'txtRTselColor');
			if (txt != null)
				SetDivColor('div26', txt);
			txt = getObjectElementByID('', 'txtRTselBG');
			if (txt != null)
				SetDivColor('div28', txt);
			txt = getObjectElementByID('', 'txtRTfooterColor');
			if (txt != null)
				SetDivColor('div30', txt);
			txt = getObjectElementByID('', 'txtRTfooterBG');
			if (txt != null)
				SetDivColor('div32', txt);
			txt = getObjectElementByID('', 'txtRTpagerColor');
			if (txt != null)
				SetDivColor('div34', txt);
			txt = getObjectElementByID('', 'txtRTpagerBG');
			if (txt != null)
				SetDivColor('div36', txt);

			txt = getObjectElementByID('', 'txtLnkNormalColor');
			if (txt != null)
				SetDivColor('div2', txt);
			txt = getObjectElementByID('', 'txtLnkNormalMOColor');
			if (txt != null)
				SetDivColor('div4', txt);
			txt = getObjectElementByID('', 'txtSubdueColor');
			if (txt != null)
				SetDivColor('div6', txt);
			txt = getObjectElementByID('', 'txtSubdueMOColor');
			if (txt != null)
				SetDivColor('div8', txt);
			txt = getObjectElementByID('', 'txtMinorColor');
			if (txt != null)
				SetDivColor('div10', txt);
			txt = getObjectElementByID('', 'txtMinorMOColor');
			if (txt != null)
				SetDivColor('div12', txt);
				
			txt = getObjectElementByID('', 'txtMTTC');
			if (txt != null)
				SetDivColor('div37', txt);
			txt = getObjectElementByID('', 'txtMSTC');
			if (txt != null)
				SetDivColor('div38', txt);
			txt = getObjectElementByID('', 'txtMTBG');
			if (txt != null)
				SetDivColor('div39', txt);
			txt = getObjectElementByID('', 'txtMSBG');
			if (txt != null)
				SetDivColor('div40', txt);
			txt = getObjectElementByID('', 'txtMUTC');
			if (txt != null)
				SetDivColor('div41', txt);
			txt = getObjectElementByID('', 'txtMBRD');
			if (txt != null)
				SetDivColor('div42', txt);
			txt = getObjectElementByID('', 'txtMUBG');
			if (txt != null)
				SetDivColor('div43', txt);
			txt = getObjectElementByID('', 'txtMSHD');
			if (txt != null)
				SetDivColor('div44', txt);
				
			txt = getObjectElementByID('', 'txtHdrBG');
			if (txt != null)
				SetDivColor('div45', txt);
		}
		
		function ResizeIcon(img, maxSize)
		{
			var tempWidth  = img.width;
			var tempHeight = img.height;
			
			if (img.width > maxSize || img.height > maxSize)
			{
				if (img.width == img.height)
				{
					img.width  = maxSize;
					img.height = maxSize;
				} else if (img.width > img.height) {
					img.width  = maxSize;
				} else {
					img.height = maxSize;
				}
			}
		}



// FILE UPLOAD PROGRESS BAR
// ----------------------------------------------------------------------------------------------------

    var  duration      = 2;
    var _progressWidth = 100;
    var _progressBar   = new String("●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●");
    var _progressEnd   = 10;
    var _progressAt    = 0;
    var _progressStyle = 1;

    // Create and display the progress dialog.
    // end: The number of steps to completion
    function ProgressCreate(end) {
        // Initialize state variables
        _progressEnd = end;
        _progressAt = 0;

        // Move layer to center of window to show
        if (document.all) {											// Internet Explorer
            progress.className = 'show';           
            progress.style.left = (document.body.clientWidth/2) - (progress.offsetWidth/2);
            progress.style.top = document.body.scrollTop+(document.body.clientHeight/2) - (progress.offsetHeight/2);            
        } else if (document.layers) {						// Netscape
            document.progress.visibility = true;
            document.progress.left = (window.innerWidth/2) - 100;
            document.progress.top = pageYOffset+(window.innerHeight/2) - 40;
        } else if (document.getElementById) {		// Netscape 6+
            document.getElementById("progress").className = 'show';
            var l = (window.innerWidth/2) - 100;
            var t = pageYOffset + (window.innerHeight/2) - 40;
            document.getElementById("progress").style.left = l + "px";
            document.getElementById("progress").style.top  = t + "px";
        }
				if (_progressStyle == 0)
	        ProgressUpdate();    // Initialize bar
    }
    // Hide the progress layer
    function ProgressDestroy() {
        // Move off screen to hide
        if (document.all) {											// Internet Explorer
            progress.className = 'hide';
        } else if (document.layers) {						// Netscape
            document.progress.visibility = false;
        } else if (document.getElementById) {		// Netscape 6+
            document.getElementById("progress").className = 'hide';
        }
    }
    // Increment the progress dialog one step
    function ProgressStepIt() {
        _progressAt++;
        if(_progressAt > _progressEnd) _progressAt = _progressAt % _progressEnd;
        ProgressUpdate();
    }
    // Update the progress dialog with the current state
    function ProgressUpdate() {
        var n = (_progressWidth / _progressEnd) * _progressAt;
        if (document.all) {								// Internet Explorer
            var bar = document.all["dialog"].document.getElementById("bar");
				} else if (document.layers) {		// Netscape         
					var bar = document.layers["progress"].document.forms["dialog"].bar;
					n = n * 0.55;									// characters are larger
        } else if (document.getElementById){        
					var bar=document.dialog.bar
				}
        var temp = _progressBar.substring(0, n);
        try { bar.value = temp; } catch (err) { }
    }
    // Demonstrate a use of the progress dialog.
    function Demo(jsDuration) {
        ProgressCreate(jsDuration);
        window.setTimeout("Click()", 100);
    }
    function Click() {
        if(_progressAt >= _progressEnd) {
            ProgressDestroy();
            return;
        }
        ProgressStepIt();
        window.setTimeout("Click()", (duration-1)*1000/10);
    }
    function CallJS(jsStr) { 
      return eval(jsStr);
    }
		function InitJSuploadProgress()
		{
			document.write("<span id=\"progress\" class=\"hide\">");
			document.write("<DIV name=\"dialog\" id=\"dialog\">");
			document.write("<TABLE border=2 style=\"background-color:Navy;\" >");
			document.write("<TR><TD ALIGN=\"center\" style=\"FONT-FAMILY:trebuchet ms; PADDING:0px; FONT-WEIGHT:bold; COLOR:white;\">");
			document.write("Please wait<BR>");
			if (_progressStyle == 1)
			{
				document.write("<img src=\"Images/ProgressBar.gif\">");
			} else {
				document.write("<input type=\"label\" name=\"bar\" value=\"Please Wait.........\" size=\"" + _progressWidth/2 + "\"");
				if(document.all || document.getElementById)
					document.write(" bar.style=\"color:navy;\">");
				else 
					document.write(">");
			}
			document.write("</TD></TR>");
			document.write("</TABLE>");
			document.write("</DIV>");
			document.write("</span>");
			ProgressDestroy();  		
		}
		
		
		function UpdateUploadProgress()
		{
			var img = document.getElementById('imgProgress');
			if (img != null)
				img.src = 'Images/ProgressBar.gif';
			window.setTimeout('UpdateUploadProgress()', 2000);
		}
		function ShowUploadProgress()
		{
			divTrans.style.visibility = 'visible';
			divUploadProgress.style.visibility = 'visible';
			UpdateUploadProgress();
			return true;
		}
		
		
		



// DATABASE URL BUTTON HIGHLIGHT FUINCTIONS
// ----------------------------------------------------------------------------------------------------
	function DBbtn_Interact(obj, foreColor, backColor)
	{
		if (obj != null)
		{
			// CHANGE THE COLOR OF THE BUTTON DIV
			obj.style.color           = foreColor;
			obj.style.backgroundColor = backColor;
				
			// CHANGE THE COLOR OF THE HPYERLINK
			var hypX;
			var strTemp = '' + obj.id;
			strTemp = strTemp.replace('div', 'ctl00_ContentPlaceHolder1_');
			strTemp = strTemp + '_hypCtrlLink'
			try { hypX = document.getElementById(strTemp); } catch (err) { 
				alert('ERROR!  ' + err);
			}
			if (hypX != null)
			{
				hypX.style.color = foreColor;
			}
		}
	}


// DATE SELECT CONTROL - DropDown List Functions
// ----------------------------------------------------------------------------------------------------
	function DateSelectDDLchange(ddl)
	{
		// DETERMINE THE OBJECT, GET THE DOM PREFIX
		var ddlName = ddl.id;
		var prefix = ddlName.substr(0, ddlName.lastIndexOf('_') + 1);

		// GET THE CONTROL'S DATE DROPDOWN LISTS
		var ddlMonth = getObjectElementByID('', prefix + 'ddlDSmonth');
		var ddlDay = getObjectElementByID('', prefix + 'ddlDSday');
		var ddlYear = getObjectElementByID('', prefix + 'ddlDSyear');

		// GET THE DROPDOWN LISTS' VALUES
		var intMonth = parseInt(ddlMonth.options[ddlMonth.selectedIndex].value);
		var intDay = parseInt(ddlDay.options[ddlDay.selectedIndex].value);
		var intYear = parseInt(ddlYear.options[ddlYear.selectedIndex].value);

		// PERFORM CHECKS ON THE DATE
		var intMax = 31;
		switch (intMonth)
		{
			case 2:
				if (intYear % 4 == 0)
					intMax = 29;
				else
					intMax = 28;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				intMax = 30;
				break;
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				intMax = 31;
				break;
		}
		// RE-POPULATE THE DAY FIELD, BASED ON MONTH and YEAR
		ddlDay.options.length = 0;
		for (var i = 1; i <= intMax; i++)
		{
			var opt = document.createElement('option');
			opt.value = i;
			opt.text = i;
			if (i < 10)
				opt.text = '0' + i;
			ddlDay.options.add(opt);
		}
		// SET THE DAY DROPDOWN LIST TO THE APPROPRIATE DAY
		if (intDay > intMax)
			intDay = intMax;
		SetDDLselectedItem(ddlDay, intDay)
	}


// GOOGLE MAPS - Resize a Google Map DIV panel
// ----------------------------------------------------------------------------------------------------
	function ResizeGoogleMapDIV(intNewHeight, intMargin) {
		
		intNewHeight = intNewHeight - intMargin;
		var intNewWidth = (intNewHeight / 3) * 4;
		
		var divMap = getObjectElementByID('', 'divMap');
		if (divMap != null && intMapResizeable) {
			divMap.style.width  = intNewWidth  + 'px';		
			divMap.style.height = intNewHeight + 'px';		
		}
	}
	
	
// GOOGLE SEARCH - Load Search Criteria, Create the Search Control (links to Google)
	// ----------------------------------------------------------------------------------------------------
	function SearchStart()
	{
		try
		{
			if (google != null)
			{
				google.load('search', '1.0');
				google.setOnLoadCallback(SearchControlOnLoad, true);
			}
		} catch (err)
		{
			searchcontrol.innerHTML = 'Unable to Load Google Search';
		}
	}
	function SearchGetFilter(intPlace)
	{
		intPlace = intPlace - 1;
		var st = searchFilters.substr(intPlace, 1);
		
		if (st == '1')
			return true;
		return false;
	}
	function SearchFilterCount()
	{
		var intCount = 0;
		
		for (var i=0; i < searchFilters.length; i++)
		{
			if (searchFilters.substr(i, 1) == '1')
				intCount++;
		}
		return intCount;
	}
	function AddFilterToSearch(theSearcher)
	{
		if (searchDomain != '')
		{
			theSearcher.setUserDefinedLabel(searchDomain);
			theSearcher.setUserDefinedClassSuffix("siteSearch");
			theSearcher.setSiteRestriction(searchDomain);
		}
	
		return theSearcher;
	}
	function SearchControlOnLoad() 
	{
		// Create a search control
		var searchControl = new google.search.SearchControl();
		var containerDiv  = getObjectElementByID(searchControlID, 'searchcontrol');
		var intCount      = SearchFilterCount();
		var siteSearch;

		// SET SEARCH RESULTS SIZE
		searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);

		// SET SEARCH RESULTS EXPAND SIZE
		options = new google.search.SearcherOptions();
		if (intCount > 1)
			options.setExpandMode(google.search.SearchControl.EXPAND_MODE_CLOSED);
		else	
			options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);

		// ESTABLISH SAVED SEARCH CALLBACK
		if (searchSaveSearches == '1')
			searchControl.setOnKeepCallback(this, SearchSavedSearchesHandler);

			
		// CREATE THE SEARCH FOR , APPLY ANY RESTRICTIONS
		if (SearchGetFilter(1))
		{
			siteSearch = new google.search.WebSearch();
			siteSearch = AddFilterToSearch(siteSearch);
			searchControl.addSearcher(siteSearch, options);
		}
		if (SearchGetFilter(2))
		{
			siteSearch = new google.search.NewsSearch();
			siteSearch = AddFilterToSearch(siteSearch);
			searchControl.addSearcher(siteSearch, options);
		}
		if (SearchGetFilter(3))
		{
			siteSearch = new google.search.LocalSearch();
			siteSearch = AddFilterToSearch(siteSearch);
			searchControl.addSearcher(siteSearch, options);
		}
		if (SearchGetFilter(4))
		{
			siteSearch = new google.search.VideoSearch();
			siteSearch = AddFilterToSearch(siteSearch);
			searchControl.addSearcher(siteSearch, options);
		}
		if (SearchGetFilter(5))
		{
			siteSearch = new google.search.BlogSearch();
			siteSearch = AddFilterToSearch(siteSearch);
			searchControl.addSearcher(siteSearch, options);
		}
		if (SearchGetFilter(6))
		{
			siteSearch = new google.search.ImageSearch();
			siteSearch = AddFilterToSearch(siteSearch);
			searchControl.addSearcher(siteSearch, options);
		}
		if (SearchGetFilter(7))
		{
			siteSearch = new google.search.BookSearch();
			siteSearch = AddFilterToSearch(siteSearch);
			searchControl.addSearcher(siteSearch, options);
		}
		if (SearchGetFilter(8))
		{
			siteSearch = new google.search.PatentSearch();
			siteSearch = AddFilterToSearch(siteSearch);
			searchControl.addSearcher(siteSearch, options);
		}

		// DRAW THE SEARCH CONTROL
		searchControl.draw(containerDiv);

		// EXECUTE INITIAL SEARCH
		searchControl.execute("");
	}
    
	function SearchSavedSearchesHandler(result) {

		var containerDiv  = getObjectElementByID(searchControlID, 'searchsaved');
	
		// clone the result html node
		var node = result.html.cloneNode(true);

		// attach it
		containerDiv.appendChild(node);
	}

	
// INTERACTIVE PASSWORD STRENGTH CHECK FUNCTION
// ----------------------------------------------------------------------------------------------------
/*
**    Original File: pwd_meter.js
**    Created by: Jeff Todnem (http://www.todnem.com/)
**    Created on: 2007-08-14
**    Last modified: 2007-08-30
**
**    License Information:
**    -------------------------------------------------------------------------
**    Copyright (C) 2007 Jeff Todnem
**
**    This program is free software; you can redistribute it and/or modify it
**    under the terms of the GNU General Public License as published by the
**    Free Software Foundation; either version 2 of the License, or (at your
**    option) any later version.
**    
**    This program is distributed in the hope that it will be useful, but
**    WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**    General Public License for more details.
**    
**    You should have received a copy of the GNU General Public License along
**    with this program; if not, write to the Free Software Foundation, Inc.,
**    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**    
**    
*/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		};
	}
}

String.prototype.strReverse = function() {
	var newstring = "";
	for (var s=0; s < this.length; s++) {
		newstring = this.charAt(s) + newstring;
	}
	return newstring;
};

function chkPass(pwd) {
	var oScoreCont	= document.getElementById("scoreborder");
	var oScorebar   = document.getElementById("scorebar");
	var oComplexity = document.getElementById("complexity");
	var nScore = 0;
	var nLength = 0;
	var nAlphaUC = 0;
	var nAlphaLC = 0;
	var nNumber = 0;
	var nSymbol = 0;
	var nMidChar = 0;
	var nRequirements = 0;
	var nAlphasOnly = 0;
	var nNumbersOnly = 0;
	var nRepChar = 0;
	var nConsecAlphaUC = 0;
	var nConsecAlphaLC = 0;
	var nConsecNumber = 0;
	var nConsecSymbol = 0;
	var nConsecCharType = 0;
	var nSeqAlpha = 0;
	var nSeqNumber = 0;
	var nSeqChar = 0;
	var nReqChar = 0;
	var nReqCharType = 3;
	var nMultLength = 4;
	var nMultAlphaUC = 3;
	var nMultAlphaLC = 3;
	var nMultNumber = 4;
	var nMultSymbol = 6;
	var nMultMidChar = 2;
	var nMultRequirements = 2;
	var nMultRepChar = 1;
	var nMultConsecAlphaUC = 2;
	var nMultConsecAlphaLC = 2;
	var nMultConsecNumber = 2;
	var nMultConsecSymbol = 1;
	var nMultConsecCharType = 0;
	var nMultSeqAlpha = 3;
	var nMultSeqNumber = 3;
	var nTmpAlphaUC = "";
	var nTmpAlphaLC = "";
	var nTmpNumber = "";
	var nTmpSymbol = "";
	var sAlphas = "abcdefghijklmnopqrstuvwxyz";
	var sNumerics = "01234567890";
	var sComplexity = "Too Short";
	var sStandards = "Below";
	
	if (document.all) { var nd = 0; } else { var nd = 1; }
	
	if (pwd == '')
	{
		oScoreCont.style.visibility = 'hidden';
	} else {
		oScoreCont.style.visibility = 'visible';
	}
	if (pwd) {
		nScore = parseInt(pwd.length * nMultLength);
		nLength = pwd.length;
		var arrPwd = pwd.replace (/\s+/g,"").split(/\s*/);
		var arrPwdLen = arrPwd.length;
		
		/* Loop through password to check for Symbol, Numeric, Lowercase and Uppercase pattern matches */
		for (var a=0; a < arrPwdLen; a++) {
			if (arrPwd[a].match(new RegExp(/[A-Z]/g))) {
				if (nTmpAlphaUC !== "") { if ((nTmpAlphaUC + 1) == a) { nConsecAlphaUC++; nConsecCharType++; } }
				nTmpAlphaUC = a;
				nAlphaUC++;
			}
			else if (arrPwd[a].match(new RegExp(/[a-z]/g))) { 
				if (nTmpAlphaLC !== "") { if ((nTmpAlphaLC + 1) == a) { nConsecAlphaLC++; nConsecCharType++; } }
				nTmpAlphaLC = a;
				nAlphaLC++;
			}
			else if (arrPwd[a].match(new RegExp(/[0-9]/g))) { 
				if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; }
				if (nTmpNumber !== "") { if ((nTmpNumber + 1) == a) { nConsecNumber++; nConsecCharType++; } }
				nTmpNumber = a;
				nNumber++;
			}
			else if (arrPwd[a].match(new RegExp(/[^a-zA-Z0-9_]/g))) { 
				if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; }
				if (nTmpSymbol !== "") { if ((nTmpSymbol + 1) == a) { nConsecSymbol++; nConsecCharType++; } }
				nTmpSymbol = a;
				nSymbol++;
			}
			/* Internal loop through password to check for repeated characters */
			for (var b=0; b < arrPwdLen; b++) {
				if (arrPwd[a].toLowerCase() == arrPwd[b].toLowerCase() && a != b) { nRepChar++; }
			}
		}
		
		/* Check for sequential alpha string patterns (forward and reverse) */
		for (var s=0; s < 23; s++) {
			var sFwd = sAlphas.substring(s,parseInt(s+3));
			var sRev = sFwd.strReverse();
			if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqAlpha++; nSeqChar++;}
		}
		
		/* Check for sequential numeric string patterns (forward and reverse) */
		for (var s=0; s < 8; s++) {
			var sFwd = sNumerics.substring(s,parseInt(s+3));
			var sRev = sFwd.strReverse();
			if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqNumber++; nSeqChar++;}
		}
		
	/* Modify overall score value based on usage vs requirements */

		/* General point assignment */
		if (nAlphaUC > 0 && nAlphaUC < nLength) 
			nScore = parseInt(nScore + ((nLength - nAlphaUC) * 2));
		if (nAlphaLC > 0 && nAlphaLC < nLength) 
			nScore = parseInt(nScore + ((nLength - nAlphaLC) * 2)); 
		if (nNumber > 0 && nNumber < nLength) 
			nScore = parseInt(nScore + (nNumber * nMultNumber));
		if (nSymbol > 0) 
			nScore = parseInt(nScore + (nSymbol * nMultSymbol));
		if (nMidChar > 0) 
			nScore = parseInt(nScore + (nMidChar * nMultMidChar));
		
		/* Point deductions for poor practices */
		if ((nAlphaLC > 0 || nAlphaUC > 0) && nSymbol === 0 && nNumber === 0)   // Only Letters
			nScore = parseInt(nScore - nLength);
		if (nAlphaLC === 0 && nAlphaUC === 0 && nSymbol === 0 && nNumber > 0)   // Only Numbers
			nScore = parseInt(nScore - nLength); 
		if (nRepChar > 0)   // Same character exists more than once
			nScore = parseInt(nScore - (nRepChar * nRepChar));
		if (nConsecAlphaUC > 0)   // Consecutive Uppercase Letters exist
			nScore = parseInt(nScore - (nConsecAlphaUC * nMultConsecAlphaUC)); 
		if (nConsecAlphaLC > 0)   // Consecutive Lowercase Letters exist
			nScore = parseInt(nScore - (nConsecAlphaLC * nMultConsecAlphaLC)); 
		if (nConsecNumber > 0)   // Consecutive Numbers exist
			nScore = parseInt(nScore - (nConsecNumber * nMultConsecNumber));  
		if (nSeqAlpha > 0)   // Sequential alpha strings exist (3 characters or more)
			nScore = parseInt(nScore - (nSeqAlpha * nMultSeqAlpha)); 
		if (nSeqNumber > 0)   // Sequential numeric strings exist (3 characters or more)
			nScore = parseInt(nScore - (nSeqNumber * nMultSeqNumber)); 

		/* Determine if mandatory requirements have been met and set image indicators accordingly */
		nRequirements = nReqChar;
		if (pwd.length >= intMinPWlen) { var nMinReqChars = 3; } else { var nMinReqChars = 4; }
		if (nRequirements > nMinReqChars)   // One or more required characters exist
			nScore = parseInt(nScore + (nRequirements * 2)); 
		
		/* Determine complexity based on overall score */
		if      (nScore > 100) { nScore = 100; } else if (nScore < 0) { nScore = 0; }
		if      (nScore >=  0 && nScore < 20)   { sComplexity = "Very Weak";   oScorebar.style.color = "Green";}
		else if (nScore >= 20 && nScore < 40)   { sComplexity = "Weak";        oScorebar.style.color = "Blue";}
		else if (nScore >= 40 && nScore < 60)   { sComplexity = "Good";        oScorebar.style.color = "Black";}
		else if (nScore >= 60 && nScore < 80)   { sComplexity = "Strong";      oScorebar.style.color = "Orange";}
		else if (nScore >= 80 && nScore <= 100) { sComplexity = "Very Strong"; oScorebar.style.color = "Red"; }
		if (pwd.length < intMinPWlen)           { sComplexity = "Too Short";   oScorebar.style.color = "Green"; }
		oScorebar.style.color = "Black";

		/* Display updated score criteria to client */
		oScorebar.style.backgroundPosition = "-" + parseInt(nScore * 4) + "px";
		oScorebar.innerHTML   = nScore + "%";
		oComplexity.innerHTML = sComplexity;
 	}
	else {
		/* Display default score criteria to client */
		initPwdChk();
		oScorebar.innerHTML   = nScore + "%";
		oComplexity.innerHTML = sComplexity;
	}
}

function initPwdChk(restart) {

	document.getElementById("scorebar").style.backgroundPosition = "0";
	
}


// SCROLLING BACKGROUND FUNCTION
function ScrollingBackground(divName, backgroundheight, intSpeed)
{
	// divNames = divMPheader, divMPcontent
	
	// Abort if Invalid DIV is passed
	if (divName != 'divMPheader' && divName != 'divMPcontent')
		return;
		
	// get the current minute/hour of the day
	var now    = new Date();
	var hour   = now.getHours();
	var minute = now.getMinutes();
 
	// work out how far through the day we are as a percentage - e.g. 6pm = 75%
	var hourpercent   = hour / 24 * 100;
	var minutepercent = minute / 60 / 24 * 100;
	var percentofday  = Math.round(hourpercent + minutepercent);
 
	// calculate which pixel row to start graphic from based
	// on how far through the day we are
	var offset = backgroundheight / 100 * percentofday;
 
	// graphic starts at approx 6am, so adjust offset by 1/4
	offset = offset - (backgroundheight / 4);
 
	function scrollbackground() {
		// decrease the offset by 1, or if its less than 1 increase it by
		// the background height minus 1
   		offset = (offset < 1) ? offset + (backgroundheight - (intTopOffset + 30)) : offset - 1;
   		
		// apply the background position
		var bgg = getObjectElementByID('', divName);
		if (bgg != null)
		{
			if (bgg.style.backgroundImage == '')
				return;
			bgg.style.backgroundPosition = '50% -' + offset + 'px';
		} else
			return;
								
		// call self to continue animation
		setTimeout(function() {
				scrollbackground();
			}, intSpeed
		);
	}
 
	// Start the animation
	scrollbackground();
}

function PlaySound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}



