/* JavaScript Document ********************************************************
*
*	NOTICE: 
*	
*	This document and code is the property of Liquitech Web Technologies
*	(Copyright 2008) and is being licensed to Enhanced Dental Concepts, under contractual
*	agreement for the domain www.enhanceddentalconcepts.com.  Use of this code
*	without a license issued by Liquitech Web Technologies is stricly prohibited.
*
*	Lic. #5648957-EDC 
*	www.liquitechdesign.com
*
************************************************************************/

// ********************************************************************

	function getElement(elementId)
	{
		if (elementId != "")
		{
			return document.getElementById(elementId);	
		}
	}


// Variables ********************************************************

	var glassElement 	= getElement("glassPane");
	var shadedElement 	= getElement("shadedPane");
	var IE = document.all ? true : false;
	var shaderEnabled 	= false;
	var windowWidth 	= "";
  	var windowHeight 	= "";
  	var windowTop		= "";
 	var windowLeft		= "";

// On Load Event Calls **********************************************

	addScrollEvent(updateShadedPopupPosition);
	

/* Add Load Event **********************************************************
*
*	TAKES:		Function name (Ex: functionCall)
*	RETURNS:	NOTHING
*	NOTE:		Allows multiple event fucntion calls from various include
*				script sources. Adds each subsequesnt event function call
*				to the action list.
*
**************************************************************************/

	function addLoadEvent(func)
	{
	 
		var oldonload = window.onload;
		
		if (typeof window.onload != 'function')
		{
			// assigns function directly
			window.onload = func;
		}
		else
		{
			// Creates a new onload function  with old and new function calls
			window.onload = function()
			{
				if (oldonload)
				{
					oldonload();
				}
				
				func();
			}
		}
	}

/* Add Scroll Event **********************************************************
*
*	TAKES:		Function name (Ex: functionCall)
*	RETURNS:	NOTHING
*	NOTE:		Allows multiple event fucntion calls from various include
*				script sources. Adds each subsequesnt event function call
*				to the action list.
*
**************************************************************************/

	function addScrollEvent(func)
	{
	 
		var oldEvent = window.onscroll;
		
		if (typeof window.onscroll != 'function')
		{
			// assigns function directly
			window.onscroll = func;
		}
		else
		{
			// Creates a new onload function  with old and new function calls
			window.onscroll = function()
			{
				if (oldEvent)
				{
					oldEvent();
				}
				
				func();
			}
		}
	}

/*  Get Tag Group * *******************************************************
 *
 *	TAKES:		Element tag, regular expression that describes the id pattern
 *				of the  group of tag elements you're looking for.
 * 	RETURNS:	Element Array of matched element tag ids with the provided regular
 *				expression.
 *	NOTE:		Uses push to load the element array
 *
 *************************************************************************/
	
	function getTagGroup(elementTag, regExp)
	{
		var tagArray = document.getElementsByTagName(elementTag);
		var elementArray = new Array();
		
		for(ctr=0; ctr < tagArray.length; ctr++)
		{
			if ((tagArray[ctr].id).search(regExp) != -1)
			{
				if (elementArray.length > 0)
				{
					elementArray = elementArray.concat(new Array(tagArray[ctr]));
				}
				else
				{
					elementArray = new Array(tagArray[ctr]);
				}
			}
		}
		
		return elementArray;
	}

/*  Image View Popup * *******************************************************
 *
 *	TAKES:		Image Name, Image URL
 * 	RETURNS:	NOTHING
 *	NOTE:		Generates an image popup with the image name as the header description
 *				and image URL as the image.
 *
 ***********************************************************************************/
 
	function imageViewPopup(imageUrl)
	{
		shadePageBackground("#000000", 55);
		glassElement.style.display = "none";
		var content;
		
		content = "<table cellpadding=\"0\" cellspacing=\"0\">";
		content = content + "<tr><td background=\"/images/shadowLeftUp.png\" height=\"9\"></td><td background=\"/images/shadowUp.png\" height=\"9\"></td><td background=\"/images/shadowRightUp.png\" height=\"9\"></td></tr>";
		content = content + "<tr><td background=\"/images/shadowLeft.png\" width=\"9\"></td><td>";
		content = content + "	<div class=\"imagePopupContainer\"\">";
		content = content + "		<div stlye=\"padding: 3px 15px 3px 15px; \" align=\"right\">";
		content = content + "			<a href=\"javascript:restorePageBackground();\"><img src=\"/images/closeBtn.jpg\" class=\"navigationBtnContainer\"></a>";
		content = content + "		</div>";
		content = content + "		<div style=\"margin: 10px; padding: 15px; border: solid; border-width: 1px; border-color: #AAAAAA; background-color: #FFFFFF;\" align=\"center\">";
		content = content + "			<img src=\"" + imageUrl + "\">";
		content = content + "		</div>";
		content = content + "	</div>";
		content = content + "</td><td background=\"/images/shadowRight.png\" width=\"9\"></td></tr>";
		content = content + "<tr><td background=\"/images/shadowLeftDown.png\" height=\"9\"></td><td background=\"/images/shadowDown.png\" height=\"9\"></td><td background=\"/images/shadowRightDown.png\" height=\"9\"></td></tr>";
		content = content + "</table>";
		
		glassElement.innerHTML = content;
		glassElement.style.display = "block";
		updateShadedPopupPosition();
		
		setTimeout("updateShadedPopupPosition()", 1000);
		
	}

/*  Image View Popup * *******************************************************
 *
 *	TAKES:		Image Name, Image URL
 * 	RETURNS:	NOTHING
 *	NOTE:		Generates an image popup with the image name as the header description
 *				and image URL as the image.
 *
 ***********************************************************************************/
 
	function imageViewPopup(imageUrl, thisWidth, thisHeight)
	{
		shadePageBackground("#000000", 55);
		glassElement.style.display = "none";
		var content;
		
		content = "<table cellpadding=\"0\" cellspacing=\"0\">";
		content = content + "<tr><td background=\"/images/shadowLeftUp.png\" height=\"9\"></td><td background=\"/images/shadowUp.png\" height=\"9\"></td><td background=\"/images/shadowRightUp.png\" height=\"9\"></td></tr>";
		content = content + "<tr><td background=\"/images/shadowLeft.png\" width=\"9\"></td><td>";
		content = content + "	<div class=\"imagePopupContainer\"\">";
		content = content + "		<div stlye=\"padding: 3px 15px 3px 15px; \" align=\"right\">";
		content = content + "			<a href=\"javascript:restorePageBackground();\"><img src=\"/images/closeBtn.jpg\" class=\"navigationBtnContainer\"></a>";
		content = content + "		</div>";
		content = content + "		<div style=\"margin: 10px; padding: 15px; border: solid; border-width: 1px; border-color: #AAAAAA; background-color: #FFFFFF;\" align=\"center\">";
		content = content + "			<img src=\"" + imageUrl + "\" width=\"" + thisWidth + "\" height=\"" + thisHeight + "\">";
		content = content + "		</div>";
		content = content + "	</div>";
		content = content + "</td><td background=\"/images/shadowRight.png\" width=\"9\"></td></tr>";
		content = content + "<tr><td background=\"/images/shadowLeftDown.png\" height=\"9\"></td><td background=\"/images/shadowDown.png\" height=\"9\"></td><td background=\"/images/shadowRightDown.png\" height=\"9\"></td></tr>";
		content = content + "</table>";
		
		glassElement.innerHTML = content;
		glassElement.style.display = "block";
		updateShadedPopupPosition();
		
		setTimeout("updateShadedPopupPosition()", 1000);
		
	}
	
/*  Shade Page Background* *******************************************************
 *
 *	TAKES:		Shade Color value (e.g. #000000), Shade Opacity value (0-100)
 * 	RETURNS:	NOTHING
 *	NOTE:		This function uses the GLOBAL varible shading element object to 
 *				overlay the website with the shade color and opacity specified.
 *
 *************************************************************************/
 
	function shadePageBackground(shadeColor, shadeOpacity)
	{
		if (shadedElement)
		{
			shaderEnabled = true;
			
			if (parseInt(navigator.appVersion)>3)
			{
				 if (!IE)
				 {
					  windowWidth 	= window.innerWidth+20 + "px";
					  windowHeight 	= window.innerHeight+300 + "px";
				 }
				 else
				 {
					  windowWidth 	= document.body.offsetWidth+20;
					  windowHeight 	= document.body.offsetHeight+300;
				 }
				
				windowTop		= getPageYOffset() + "px";
				windowLeft		= document.body.scrollLeft;
			}
			
			shadedElement.style.top = windowTop;
			shadedElement.style.left = 0;
			shadedElement.style.width = windowWidth;
			shadedElement.style.height = windowHeight;
			
			shadedElement.style.backgroundColor = "#000000";
			shadedElement.style.filter = "alpha(opacity=" + shadeOpacity + ");"; // IE
			shadedElement.style.MozOpacity = shadeOpacity/100; // FireFox, Safari
			shadedElement.style.display = "block";
			
		}
		else
		{
			alert("ERROR brdApiPopup >> shadePageBackground(shadedElement, shadeColor, shadeOpacity):\n- shadedElement is undefined.");	
		}
	}

/*  Restore Page Background* *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *	NOTE:		Hides the shading element object.
 *
 *************************************************************************/
 
	function restorePageBackground()
	{
		shadedElement.style.display = "none";
		glassElement.style.display = "none";
		shaderEnabled = false;
	}



/*  Updated Shaded Popup Position * *******************************************************
 *
 *	TAKES:		Popup Element Object
 * 	RETURNS:	NOTHING
 *	NOTE:		Repositions the popup object to be centered with the webpage, both
 *				vertically and horizontally.
 *
 ***********************************************************************************/
 
	function updateShadedPopupPosition()
	{
		if (glassElement)
		{
			if (shadedElement.style.display == "block")
			{
				shadePageBackground("#000000", 55);
			}
			
			glassElement.style.left = getPosX(glassElement) + "px";
			glassElement.style.top	= (getWindowHeight()/2) - (getHeight(glassElement)/2) + getPageYOffset() + "px";
		}
		else
		{
			alert("ERROR brdApiPopup >> updateShadedPopupPosition():\n- glassElement is undefined.");	
		}
	}

/*  Get Width ********************************************************
 *
 *	TAKES:		Element Object
 * 	RETURNS:	The Width of the element object.
 *
 *************************************************************************/	

	function getWidth(element)
	{
		return element.clientWidth;
	}
	
	
/*  Get Height * *******************************************************
 *
 *	TAKES:		Element Object
 * 	RETURNS:	The Height of the element object.
 *
 *************************************************************************/
 
	function getHeight(element)
	{
		return element.clientHeight;
	}
	

/*  Get Position X * *******************************************************
 *
 *	TAKES:		Element Object
 * 	RETURNS:	The X position of the center of the webpage based on the width
 *				of the element object
 *	NOTE:		This function is based on a standard website width space of 818px,
 *				and calculates the center position of the element object within that
 *				space.  This eliminates the abiguity of various monitor sizes,
 *				resolutions, and aspect ratios.
 *
 *************************************************************************/
	
	function getPosX(contentElement)
	{
		var posX;
		
		posX = getWindowWidth()/ 2;  							// Center with window
		posX = posX - getWidth(contentElement)/2;		// Center based on Element width
		return posX;	
	}
	

/*  Get Position Y * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	The value of the scroll offset plus 100px
 *	NOTE:		Used for postioning elements 100px below the top of the page
 *
 *************************************************************************/

	function getPosY()
	{
		return getPageYOffset() + 100;
	}


/*  Set Position X * *******************************************************
 *
 *	TAKES:		Element Object, X position value
 * 	RETURNS:	NOTHING, changes the X position of the element object.
 *
 *************************************************************************/
 
	function setPosX(element, posXValue)
	{
			element.style.left = posXValue;
		
	}
	
	
/*  Set Position Y * *******************************************************
 *
 *	TAKES:		Element Object, Y position value
 * 	RETURNS:	NOTHING, changes the Y position of the element object.
 *
 *************************************************************************/
	
	function setPosY(element, posYValue)
	{
			element.style.top	= posYValue;	
	}
	
 
 /*  Get Window Width * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	The width of the window.
 *	
 *************************************************************************/
 
 	function getWindowWidth()
	{
		var myWidth = 0;
		
		if ( typeof( window.innerWidth ) == "number" )
		{
			//Non-IE
			myWidth = window.innerWidth;
		}
		else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
		}
		else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
			//IE 4 compatible
			myWidth = document.body.clientWidth;
		}

		return myWidth;	
	}


 /*  Get Window Height * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	The height of the window.
 *	
 *************************************************************************/
 
	function getWindowHeight()
	{
		var myHeight = 0;
		
		if ( typeof( window.innerWidth ) == "number" )
		{
			//Non-IE
			myHeight = window.innerHeight;
		}
		else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
			//IE 6+ in 'standards compliant mode'
			myHeight = document.documentElement.clientHeight;
		}
		else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
			//IE 4 compatible
			myHeight = document.body.clientHeight;
		}

		return myHeight;	
	}

 /*  Get Page Y Offset  * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	The offset from the top of the webpage.
 *	NOTE:		This is the value of webpage, not the browser or window offset.
 *	
 *************************************************************************/
 
	function getPageYOffset()
	{
		var ScrollTop = document.body.scrollTop;
		
		if (ScrollTop == 0)
		{
			if (window.pageYOffset)
				ScrollTop = window.pageYOffset;
			else
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		
		return ScrollTop;
	}
	
 /*  Get Page X Offset  * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	The offset from the top of the webpage.
 *	NOTE:		This is the value of webpage, not the browser or window offset.
 *	
 *************************************************************************/
 
	function getPageXOffset()
	{
		var ScrollTop = document.body.scrollLeft;
		
		if (ScrollTop == 0)
		{
			if (window.pageXOffset)
				ScrollTop = window.pageXOffset;
			else
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
		}
		
		return ScrollTop;
	}
	
// Navigation Button Setup **************************
	
	function setNavigationBtnActions()
	{
		var navLinks = getTagGroup("div", "navLink");
		var navLinkElement = "";
		
		if (navLinks.length > 0)
		{
			for(ctr=0; ctr<navLinks.length; ctr++)
			{
				navLinkElement = navLinks[ctr];
				
				navLinkElement.onmouseover = function()
				{
					this.style.cursor = "pointer";
					this.className = "navigationBtnHover";	
				}
				
				navLinkElement.onmouseout = function()
				{
					this.style.cursor = "";
					this.className = "navigationBtn";	
				}
				
				navLinkElement.onclick = function()
				{
					document.location.href = getElement(this.id + "Url").value; // Hidden Input Tag in Header
				}
			}
		}
	}
	
	function clearTextarea(element, defaultText)
	{
		if (element.value == defaultText)
		{
			element.value = "";	
		}
	}


