﻿function d(s) { return window.document.getElementById(s); }
function n(s) { return window.document.getElementsByName(s)[0]; }

function showMoreIntro(b)
{
	if(b)
	{
		
		d("moreText").style.display = "none";
		d("moreIntro").style.display = "inline";
		d("lessText").style.display = "inline";
	}
	else
	{
		d("lessText").style.display = "none";
		d("moreIntro").style.display = "none";
		d("moreText").style.display = "inline";
	}
	
}

function hideBlocks()
{
	for(var i = 0; i < arguments.length; i++)
		d(arguments[i]).style.display = "none";
}

function hideAllBlocks()
{
	hideBlocks("ep1Block", "ep2Block", "buyBlock", "introBlock", "linkBlock", "newsBlocks", "quoteBlocks");	
}

function switchBlocks()
{
	hideAllBlocks();
	showBlocks.apply(null, arguments);
}

function showBlocks()
{
	for(var i = 0; i < arguments.length; i++)
		d(arguments[i]).style.display = "block";
}

function showEp1Block()
{
	switchBlocks("ep1Block");	
}

function showEp2Block()
{
	switchBlocks("ep2Block");
}

function showBuyBlock()
{
	switchBlocks("buyBlock");
}

function showIntroBlock()
{
	switchBlocks("introBlock", "newsBlocks", "linkBlock");
}

function showQuotes()
{
	switchBlocks("quoteBlocks");
}

function toggleView(o)
{
	var c = o.parentNode.childNodes;
	
	for(var i = 0; i < c.length; i++)
		if(c.item(i).className == "newsBody")
			break;
	
	var to = c.item(i).style;
	
	if(to.display != "block") to.display = "block";
	else to.display = "none";
}

function fold_event_view(o)
{
	var c = o.parentNode.childNodes;
	
	for(var i = 0; i < c.length; i++)
		if(c.item(i).className == "event_text")
			break;
	
	var to = c.item(i).style;
	
	if(to.display != "block") to.display = "block";
	else to.display = "none";
}

function on_change_dvd_qty()
{
	var two_or_more = (Number(d("quantity_1").value) + Number(d("quantity_2").value) >= 2);
	d("soundtrack_price_tag").firstChild.nodeValue = two_or_more ? "$0.00" : "$6.99";
}

function on_submit_order_form()
{
	var two_or_more = (Number(d("quantity_1").value) + Number(d("quantity_2").value) >= 2);
	var j = 1;
	
	if(Number(d("quantity_1").value)) add_item(1, j++);
	if(Number(d("quantity_2").value)) add_item(2, j++);	
	
	if(d("quantity_3").checked)
	{
		if(two_or_more) d("on0_1").setAttribute("name", "on0_1");
		else add_item(3, j++);
	}

	/*if(n("shipping_1") && n("shipping_2"))
	{
		d("shipping_2").disabled = true;
		d("shipping_1").value = Number(d("shipping_1").value) + d("quantity_2")
	}*/
		
	return true;
}

function add_item(i, j)
{
	d("item_name_" + i).setAttribute("name", "item_name_" + j);
	d("item_number_" + i).setAttribute("name", "item_number_" + j);
	d("amount_" + i).setAttribute("name", "amount_" + j);
	d("quantity_" + i).setAttribute("name", "quantity_" + j);
	d("shipping_" + i).setAttribute("name", "shipping_" + j);
	d("shipping2_" + i).setAttribute("name", "shipping2_" + j);
}