function eResize(strIDs)
{
	var strTheIDs = strIDs.split(",");
	var winW = 630, winH = 460;
	var leftPos = 0;
	var i = 0;

	winW = document.body.clientWidth;

	if(winW >= 1000) {
		leftPos = Math.floor(winW/2 - 500);
		for(i=0;i<strTheIDs.length;i+=2)
			$(strTheIDs[i]).style.left = leftPos + parseInt(strTheIDs[i+1],10);
	}
	else {
		for(i=0;i<strTheIDs.length;i+=2)
			$(strTheIDs[i]).style.left = parseInt(strTheIDs[i+1]);
	}

	for(i=0;i<strTheIDs.length;i+=2)
		$(strTheIDs[i]).style.visibility = "visible";
}

function wGo(url)
{
	window.location.href=url;
}


var oscLoginWindowInError = false;
function oscLogin()
{
	new Ajax.Request
	(
		"catalog/login.php?action=process",
		{
			parameters:
			{
				email_address: $('ltsUsername').value,
				password: $('ltsPassword').value
			},

			onSuccess : function(transport)
			{
				if(transport.responseText.indexOf("Error") == -1)
				{
					window.location.reload(false);
				}
				else
				{
					oscLoginFail();
				}
			},

			onFailure : function(transport)
			{
				return oscLoginFail();
			}
		}
	);
}
function oscOpenLoginWindow()
{
	var loginHTML = "";

	loginHTML += "<center>";
	loginHTML += "<input type='button' value='Create New Account' style='width:130px;background-color:#f8981e;color:#ffffff;' onclick=\"wGo('create_account.php');\" />&nbsp;&nbsp;&nbsp;";
	loginHTML += "<input type='button' value='Forgot Password' style='width:130px;background-color:#ffffff;' onclick=\"wGo('password_forgotten.php');\" />&nbsp;&nbsp;&nbsp;";
	loginHTML += "<div style='font-size:1px;line-height:1px;height:8px;'>&nbsp;</div>";
	loginHTML += "<form id=\"loginForm\" onsubmit=\"LTSun.showLoadingWindow({afterFinish: function(){oscLogin();}}); return false;\">";
	loginHTML += "<table><tr><td id=\"ltsUsernameLoginTD\" align=\"right\" style=\"font-size:12px;color:#333333;font-weight:bold;\">";
	loginHTML += "E-mail: &nbsp;&nbsp; </td><td> <input id=\"ltsUsername\" type=\"text\" onKeyDown=\"oscRestoreLoginFail();\" />";
	loginHTML += "<div style=\"clear:both\"></div>";
	loginHTML += "</td></tr><tr><td colspan=\"2\" style=\"font-size:1px;line-height:1px;height:4px;\">&nbsp;";
	loginHTML += "</td></tr><tr><td id=\"ltsPasswordLoginTD\" align=\"right\" style=\"font-size:12px;color:#333333;font-weight:bold;\">";
	loginHTML += "Password: &nbsp;&nbsp; </td><td> <input id=\"ltsPassword\" type=\"password\" onKeyDown=\"oscRestoreLoginFail();\" /> <input type=\"submit\" style=\"display:none;visibility:hidden;\" />";
	loginHTML += "<div style=\"clear:both\"></div>";
	loginHTML += "</td></tr></table>";
	loginHTML += "</form>";
	loginHTML += "</center>";

	LTSun.showWindow({
		bgColor: "#CCE82E",
		bgFirstColor: "#000000",
		animationSpeed: 100,
		html: loginHTML,
		cancelLabel: "Quit",
		okLabel: "Login",
		okAction: "LTSun.showLoadingWindow({afterFinish: function(){oscLogin();}});",
		afterFinish: function(){$("ltsUsername").focus();}
	});
}
function oscLogout()
{
	LTSun.showLoadingWindow({
		afterFinish: function()
		{
			new Ajax.Request
			(
				"catalog/logoff.php",
				{
					onSuccess : function(transport)
					{
						setTimeout("window.location.reload(false);", 1200);
					},
	
					onFailure : function(transport)
					{
						setTimeout("window.location.reload(false);", 1200);
					}
				}
			);
		}
	});
}
function oscLoginFail()
{
	LTSun.hideLoadingWindow({
		afterFinish: function()
		{
			LTSun.morphWindow({bgColor: '#ff0000', textElementIDs:['ltsUsernameLoginTD','ltsPasswordLoginTD'],
				afterFinish: function()
				{
					oscLoginWindowInError = true;
				}
			});
		}
	});
}
function oscRestoreLoginFail()
{
	if(oscLoginWindowInError)
	{
		oscLoginWindowInError = false;
		LTSun.morphWindow({bgColor: '#CCE82E', fgColor: '#333333', textElementIDs:['ltsUsernameLoginTD','ltsPasswordLoginTD']});
	}
}
function oscLogoutFail()
{
	alert('Logout failure?!  Please Report this Error.');
	window.location.reload(false);
}





function addProductToCart(prodId)
{
	new Ajax.Request
	(
		"catalog/index.php?action=buy_now&products_id=" + prodId,
		{
			onSuccess : function(transport)
			{
				getCart(false);
			},

			onFailure : function(transport)
			{
				alert("Error: Unable to add product to cart. Network Connection Disabled.");
			}
		}
	);
}


function getCart(change)
{
	var cart = $("osc_shopping_cart_contents");

	new Ajax.Request
	(
		"catalog/shopping_cart.php?action=update_product&regCheck=true",
		{
			parameters : (change?($("cart_quantity")?Form.serialize("cart_quantity"):""):""),
			onSuccess : function(transport)
			{
				cart.innerHTML = transport.responseText;
			},

			onFailure : function(transport)
			{
				cart.innerHTML = transport.responseText + " Error...";
			}
		}
	);
}


        function makeOrangeBarNavHighlight(id)
        {
                $("orangeBarNavHighlightDiv").setStyle({
                        top: LTSun.getElementTop(id) + 23,
                        left: LTSun.getElementLeft(id),
                        width: LTSun.getElementWidth(id),
                        visibility: "visible"
                });
        }

        function showDDMenu(menuNumber)
        {
                if($("navMenuContent_"+menuNumber).innerHTML.length > 100)
                {
                        var leftPos = 0;

                        if((LTSun.getElementLeft("nav_top_link_"+menuNumber)+LTSun.getElementWidth("navMenuContent_"+menuNumber)) > (LTSun.getElementLeft("nav_top_links")+1000))
                                leftPos = (LTSun.getElementLeft("nav_top_links")+1000) - LTSun.getElementWidth("navMenuContent_"+menuNumber);
                        else
                                leftPos = LTSun.getElementLeft("nav_top_link_"+menuNumber);

                        if($("navMenuContent_"+menuNumber))
                        {
                                if(navigator.appName.indexOf("Microsoft") == -1)
                                {
                                        $("navMenuContent_"+menuNumber).setStyle({
                                                left: leftPos,
                                                visibility: "visible",
                                                opacity: 0
                                        });

                                        new Effect.Opacity("navMenuContent_"+menuNumber, {duration: 0.2, from: 0.0, to:1.0});
                                }
                                else
                                {
                                        $("navMenuContent_"+menuNumber).setStyle({
                                                left: leftPos,
                                                visibility: "visible"
                                        });
                                }
                        }
                }
        }




        function menuHighlight(id)
        {
                $(id).setStyle({
                        background: "#eeeeee",
                        color:  "#363636"
                });
        }
        function menuUnHighlight(id)
        {
                $(id).setStyle({
                        background: "transparent url(media/menu-title-bg.png) repeat",
                        color:  "#eeeeee"
                });
        }

        function menuProductHighlight(id)
        {
                $(id).setStyle({
                        background: "#f9f9f9",
                        color:  "#222222"
                });
        }
        function menuProductUnHighlight(id)
        {
                $(id).setStyle({
                        background: "transparent url(media/menu-product-bg.png) repeat",
                        color:  "#666666"
                });
        }

        function openMenu(menuToOpenId, currentMenuId, offset)
        {
                for(var i=0;i<menu_ids.length;i++)
                {
                        if(LTSun.getElementLeft(menu_ids[i]) >= LTSun.getElementLeft(currentMenuId)+(offset?320:0))
                                if($(menu_ids[i])) $(menu_ids[i]).style.visibility = "hidden";
                }

                //if($(menuToOpenId).innerHTML.length > 0)
                if($(menuToOpenId).innerHTML.length > 400)
                {
                        if(navigator.appName.indexOf("Microsoft") == -1)
                        {
                                $(menuToOpenId).setStyle({
                                        left: LTSun.getElementLeft(currentMenuId)+(offset?320:0),
                                        visibility: "visible",
                                        opacity: 0
                                });

                                new Effect.Opacity(menuToOpenId, {duration: 0.2, from: 0.0, to:1.0});
                        }
                        else
                        {
                                $(menuToOpenId).setStyle({
                                        left: LTSun.getElementLeft(currentMenuId)+(offset?320:0),
                                        visibility: "visible"
                                });
                        }
                }
        }
        function closeAllMenus(e)
        {
                for(var i=0;i<menu_ids.length;i++)
                {
                        if($(menu_ids[i]))
                                $(menu_ids[i]).style.visibility = "hidden";
                }

                for(i=0;i<50;i++)
                {
                        if($("navMenuContent_"+i))
                                $("navMenuContent_"+i).style.visibility = "hidden";
                }

                if($("orangeBarNavHighlightDiv"))
                        $("orangeBarNavHighlightDiv").style.visibility = "hidden";
        }
        document.documentElement.onclick = function(event){closeAllMenus(event);};

