﻿///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function handleOverlay(id,subHeight)
{
	var offsetTop = getOffsetTop();
		
	cntrlOverlay = document.getElementById("divOverlay");
	cntrlOverlaySub = document.getElementById("divOverlay_" + id);
	
	if (document.getElementById("divOverlay_" + id + "_SUB_1"))
	{
		cntrlOverlaySubSub1 = document.getElementById("divOverlay_" + id + "_SUB_1");
		cntrlOverlaySubSub2 = document.getElementById("divOverlay_" + id + "_SUB_2");
	}
		
	if (cntrlOverlay.style.visibility == "visible")
	{
		cntrlOverlay.style.width = "0%";
		cntrlOverlay.style.height = "0%";
		cntrlOverlay.style.visibility = "hidden";
		
		cntrlOverlaySub.style.visibility = "hidden";
		cntrlOverlaySub.style.width = "0%";
		cntrlOverlaySub.style.height = "0%";
		cntrlOverlaySub.style.top = "0px";
		
		if (document.getElementById("divOverlay_" + id + "_SUB_1"))
		{
			cntrlOverlaySubSub1.style.visibility = "hidden";
			cntrlOverlaySubSub1.style.height = "0px";
			cntrlOverlaySubSub2.style.visibility = "hidden";
			cntrlOverlaySubSub2.style.height = "0px";
		}
					
		//handle iframe overlay		
		document.getElementById("ifmeOverlay").style.height = "0px";
		document.getElementById("ifmeOverlay").src = "";
		document.getElementById("divOverlay_IFRAME_Button").style.visibility = "hidden";
		document.getElementById("divOverlay_IFRAME_Button").style.height = "0px";
		
		//handle msg overlay		
		document.getElementById("imgOverlay_MSG").style.visibility = "hidden";
		
		//handle scrollbars in main window
		document.getElementById("htmlMain").style.overflow = "auto";
		
	}
	else
	{
		cntrlOverlay.style.width = "100%";
		cntrlOverlay.style.height = "500%";
		cntrlOverlay.style.visibility = "visible";
		
		cntrlOverlaySub.style.width = "100%";
		if (subHeight == "")
		{
			cntrlOverlaySub.style.height = "100%";
		}
		else
		{
			cntrlOverlaySub.style.height = subHeight + "px";
		}
		cntrlOverlaySub.style.top = offsetTop.toString() + "px";
		cntrlOverlaySub.style.visibility = "visible";
		
		if (document.getElementById("divOverlay_" + id + "_SUB_1"))
		{
			cntrlOverlaySubSub1.style.visibility = "visible";
			cntrlOverlaySubSub1.style.height = "100%";
			cntrlOverlaySubSub2.style.visibility = "hidden";
			cntrlOverlaySubSub2.style.height = "0px";
		}
		
		//handle scrollbars in main window
		document.getElementById("htmlMain").style.overflow = "hidden";
	}

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showCoupon(strRID,e)
{
	xVal = getMouseCoords("X",e) - 340;
	yVal = getMouseCoords("Y",e) - 55;
				
	document.getElementById("ifmeCoupon").src = "coupon.aspx?P1=" + strRID;
	document.getElementById("ifmeCoupon").style.height = "100px";
	document.getElementById("divCouponPopup").style.left = xVal.toString() + "px";
	document.getElementById("divCouponPopup").style.top = yVal.toString() + "px";
	document.getElementById("divCouponPopup").style.visibility = "visible";

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function hideCoupon()
{
	document.getElementById("divCouponPopup").style.visibility = "hidden";
	document.getElementById("ifmeCoupon").style.height = "0px";
	document.getElementById("ifmeCoupon").src = "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function toggleFlag(e)
{
	if (document.getElementById("divFlagPopup").style.visibility == "visible")
	{
		document.getElementById("divFlagPopup").style.visibility = "hidden";
	}
	else
	{
		xVal = getMouseCoords("X",e) + 20;
		yVal = getMouseCoords("Y",e) - 70;
					
		document.getElementById("divFlagPopup").style.left = xVal.toString() + "px";
		document.getElementById("divFlagPopup").style.top = yVal.toString() + "px";
		document.getElementById("divFlagPopup").style.visibility = "visible";
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
																																						   
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function setClientSideMsg(strMsg, strColor, strWidth, strButtonAction)
{
	cntrlMSG = document.getElementById("ctl00_ucMSG_lblOverlayMsg");
	cntrlMSG.innerHTML = strMsg;
	cntrlMSG.style.color = strColor;
	
	cntrlDiv = document.getElementById("ctl00_ucMSG_divOverlay_MSG_SUB");
	cntrlDiv.style.width = strWidth + "px";
	
	cntrlButton = document.getElementById("ctl00_ucMSG_btnOK");
	cntrlImg = document.getElementById("imgOverlay_MSG");
		
	if (strButtonAction == "undefined" || strButtonAction == undefined || strButtonAction == "")
	{
		cntrlButton.onclick = function(){handleOverlay("MSG","")};
		cntrlImg.style.visibility = "visible";
	}
	else
	{
		eval("cntrlButton.onclick = function(){" + strButtonAction + "}");
		cntrlImg.style.visibility = "hidden";
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function setClientSideIframe(strSrc, strHeader, strWidth, strHeight, blShowButton)
{
	cntrlIFrame = document.getElementById("ifmeOverlay");
	cntrlHeader = document.getElementById("spnOverlay_IFRAME_Header");
	cntrlDiv = document.getElementById("divOverlay_IFRAME_SUB");
	cntrlButton = document.getElementById("divOverlay_IFRAME_Button");
	
	cntrlIFrame.src = strSrc;
	cntrlHeader.innerHTML = strHeader;
	cntrlIFrame.style.width = strWidth + "px";
	cntrlIFrame.style.height = strHeight + "px";
	cntrlDiv.style.width = strWidth + "px";
	
	if (blShowButton)
	{
		cntrlButton.style.height = "40px";
		cntrlButton.style.visibility = "visible";
	}
	else
	{
		cntrlButton.style.height = "0px";
		cntrlButton.style.visibility = "hidden";
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function handleStarRatingMouse(strClientId, intStarNum, strAction)
{	
	for (i=1;i<=5;i++) 
	{
	    document.getElementById("imgRatingStar_" + strClientId + "_" + i).src = "images/star_empty.gif";
	}
	if (strAction == "over")
	{
		for (i=1;i<=intStarNum;i++) 
		{
		    document.getElementById("imgRatingStar_" + strClientId + "_" + i).src = "images/star_full.gif";
		}
	}
	else
	{
		for (i=1;i<=document.getElementById("hidSetRating_" + strClientId).value;i++) 
		{
		    document.getElementById("imgRatingStar_" + strClientId + "_" + i).src = "images/star_full.gif";
		}
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function handleStarRatingClick(strClientId, intStarNum)
{	
	for (i=1;i<=intStarNum;i++) 
	{
	    document.getElementById("imgRatingStar_" + strClientId + "_" + i).src = "images/star_full.gif";
	    document.getElementById("hidSetRating_" + strClientId).value = intStarNum;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function initUsernameExists(id)
{
	document.getElementById("imgUserExists").style.width = "16px";
	document.getElementById("imgUserExists").style.visibility = "visible";
	document.getElementById("spnUserExists").innerHTML = "Checking to see if this Username already exists...";
	document.getElementById("spnUserExists").style.color = "gray";
	
	strFunction = "ajaxUsernameExists('" + id + "')";
	setTimeout(strFunction,1500);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function handleBecomeMemberPricing(id1, id2, id3, idSpan, condClicked)
{
	cntrlCond1 = document.getElementById(id1);
	cntrlCond2 = document.getElementById(id2);
	cntrlCond3 = document.getElementById(id3);
	cntrlPrice = document.getElementById(idSpan);
	
	dblPrice = 29.99;
	
	if (condClicked == 1)
	{
		if (cntrlCond1.checked)
		{
			cntrlCond2.checked = false;
			dblPrice = Math.round((dblPrice - 18)*100)/100;
		}
		if (cntrlCond3.checked)
		{
			dblPrice = Math.round((dblPrice - 10)*100)/100;
		}
	}
	else if(condClicked == 2)
	{
		if (cntrlCond2.checked)
		{
			cntrlCond1.checked = false;
			dblPrice = Math.round((dblPrice - 18)*100)/100;
		}
		if (cntrlCond3.checked)
		{
			dblPrice = Math.round((dblPrice - 10)*100)/100;
		}
	}
	else if(condClicked == 3)
	{
		if (cntrlCond1.checked || cntrlCond2.checked)
		{
			dblPrice = Math.round((dblPrice - 18)*100)/100;		
		}
		if (cntrlCond3.checked)
		{
			dblPrice = Math.round((dblPrice - 10)*100)/100;
		}
	}
	
	cntrlPrice.innerHTML = "$" + dblPrice.toString();
	
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//UNIVERSAL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getOffsetTop()
{
	var offsetTop = 0;
	if (parseInt(document.documentElement.scrollTop) && document.documentElement.scrollTop > 0)
	{
		offsetTop = document.documentElement.scrollTop;
	}
	else if (parseInt(window.pageYOffset) && window.pageYOffset > 0)
	{
		offsetTop = window.pageYOffset;
	}
	return offsetTop;	
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getY(oElement)
{
	var iReturnValue = 0;
	while(oElement != null)
	{
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getMouseCoords(axis,e)
{
	var posX = 0;
	var posY = 0;
	if (!e) var e = window.event;
	
	if (e.pageX || e.pageY)
	{
		posX = e.pageX;
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posX = e.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
		posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
		
	if (axis == "X")
	{
		return posX;
	}
	else if (axis == "Y")
	{
		return posY;
	}
	else
	{
		return 0;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeImage(id,imgName)
{
	cntrl = document.getElementById(id);
	cntrl.src = 'images/' + imgName;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function toggleElement(elemMain, elemLabel)
{	
	cntrlMain = document.getElementById(elemMain);
		
	if (cntrlMain.style.display == "none") 
	{
	    cntrlMain.style.display = "inline";
	    if (elemLabel != "")
		{
			document.getElementById(elemLabel).innerHTML = "Collapse";
		}
	}
	else
	{
	    cntrlMain.style.display = "none";
	    if (elemLabel != "")
		{
			document.getElementById(elemLabel).innerHTML = "Expand";
		}
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





