//********************************************************************
//*	       Name:	common_scripts.js
//*	Description:	JavaScript functions for miraclebeam.com
//*	    Created:	06/28/2007
//*	    Updated:	11/08/2007
//********************************************************************

//********************************************************************
//* fnFixContentHeight()
//* Compare the content column height with the height of the subnav bar.
//* If the content is shorter then it is automatically adjusted so it doesn't look like shit.
//********************************************************************
function fnFixContentHeight(intAdjust)
{
	var objContentContainer = document.getElementById("ContentContainer");
	var objCopyrightContainer = document.getElementById('Copyright');
	var intContentContainer;
	var intCopyrightContainer;
	var intContentTotal;
	var intHeaderAdjust = intAdjust;
	var y;
	
	// all except Explorer
	if (self.innerHeight)
	{
		y = self.innerHeight;
	}
	// Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		y = document.documentElement.clientHeight;
	}
	// other Explorers
	else if (document.body)
	{
		y = document.body.clientHeight;
	}
	
	// Get the height of the content container
	if (objContentContainer.offsetHeight)
	{
		intContentContainer = objContentContainer.offsetHeight;
	}
	else if (objContentContainer.style.pixelHeight)
	{
		intContentContainer = objContentContainer.style.pixelHeight;
	}
	
	// Get the height of the copyright container
	if (objCopyrightContainer.offsetHeight)
	{
		intCopyrightContainer = objCopyrightContainer.offsetHeight;
	}
	else if (objCopyrightContainer.style.pixelHeight)
	{
		intCopyrightContainer = objCopyrightContainer.style.pixelHeight;
	}
	
	intContentTotal = intContentContainer + intCopyrightContainer + intHeaderAdjust;
		
	if (intContentTotal < y)
	{
		objContentContainer.style.height = intContentContainer + (y - intContentTotal) + 'px';
	}
}

function fnItemImage(strItemID)
{
	crossfade(document.getElementById('imgMain'), '_images/products/' + strItemID + '_md.jpg', '1', '');
	document.getElementById('imgMainLink').href = '_images/products/' + strItemID + '_lg.jpg';
}

function fnHighlightThumb(intThumbNum, blnDirection)
{
	if (intThumbNum == 0)
	{
		if (blnDirection == 1)
		{
			document.getElementById('divThumb').style.borderColor = '#E02A28';
		}
		else
		{
			document.getElementById('divThumb').style.borderColor = '#CCCCCC';
		}
	}
	else
	{
		if (blnDirection == 1)
		{
			document.getElementById('divThumb' + intThumbNum).style.borderColor = '#E02A28';
		}
		else
		{
			document.getElementById('divThumb'  + intThumbNum).style.borderColor = '#CCCCCC';
		}
	}
}

//* Validate that an e-mail address has been submitted for subscription
function fnValidateSubscription() {
	if (!fnCheckEmail(document.frmSubscribe.email.value)) {
		alert('Please enter in a valid e-mail address before subscribing.');
		// return false;
	}
	else {
		document.frmSubscribe.submit();
		// return true;
	}
}

//********************************************************************
//* fnCheckEmail(strEmail)
//* Check if the string is a valid e-mail address. Returns true or false.
//* strEmail = The string to validate
//********************************************************************
function fnCheckEmail(strEmail) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(strEmail)) {
		return true;
	}
	else {
		return false;
	}
}

function fnDetailsLink(intLinkID, blnAction)
{
	var objLinkIcon = document.getElementById('DetailsIcon' + intLinkID);
	var objLink = document.getElementById('DetailsLink' + intLinkID);
	var objLinkImage = document.getElementById('DetailsImage' + intLinkID);
	
	if (blnAction)
	{
		objLinkIcon.src = '_images/icon_right_arrow_active.gif';
		objLink.style.color = '#E02A28';
		objLinkImage.style.borderColor = '#E02A28';
	}
	else
	{
		objLinkIcon.src = '_images/icon_right_arrow.gif';
		objLink.style.color = '#666666';
		objLinkImage.style.borderColor = '#CCCCCC';
	}
}