var colourSelectBoxId;
var sizeSelectBoxId;

function toggleChildMenu(id)
{
	var maxLinks = 101;

	if(id != -1)
		var displayType = document.getElementById('smenu'+id).style.display;

	/*
	Hide all child menus, and reset all links back to default values.
	*/
	for(i=0; i<maxLinks;i++)
	{
		if(document.getElementById('smenu'+i))
		{
			document.getElementById('smenu'+i).style.display='none';
			document.getElementById('smenuh'+i).style.color='#9b9b9b';
			document.getElementById('smenuh'+i).style.background='none';
                }	
	}
	
	/*
	Show the child menu and change the link colour
	*/
	if(id != -1)
	{
		if(displayType == "none" || displayType == "")
		{
			document.getElementById('smenu'+id).style.display='block';
			document.getElementById('smenuh'+id).style.color='#f2be1f';
			document.getElementById('smenuh'+id).style.background='url(images/menu_bgdots.png) no-repeat';
		}
	}
}

function confirmInvoiceIssue()
{
	return confirm("Are you sure you want to issue the invoice?");
}

function confirmOrderCancel()
{
	return confirm("Are you sure you want to cancel your order?");
}

function confirmCancelOrder()
{
	return confirm("Are you sure you want to cancel this order?\nThis can not be undone.");
}

function disableButton(btn)
{
	if(btn.disabled == true)
		btn.disabled = false;
	else
		btn.disabled = true;
	
	return true;
}

function updateItem(url)
{
	window.open(url,'Update Item','toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=1,width=500,height=300,left=200,top=200');
}


function toggleSpecificStateClient(specCountry)
{
	country = document.getElementById('country').value;
	//country = document.chshipping.country.value;
	
	if(specCountry != "")
		country = specCountry;

	if(country == "Australia")
	{
		document.getElementById('state_specific').style.display = 'none';
		document.getElementById('state').style.display = 'block';
	}
	else
	{
		document.getElementById('state_specific').style.display = 'block';
		document.getElementById('state').style.display = 'none';
	}
}

function toggleColourLists(fabric)
{
	if(document.getElementById(colourSelectBoxId))
		document.getElementById(colourSelectBoxId).style.display = 'none';

	if(fabric == null || fabric == "")
		var fabric = document.getElementById('fabric').value;

	if(fabric != "")
	{
		var colour = document.getElementById(fabric);

		colourSelectBoxId = fabric;

		colour.style.display = 'block';
	}
}


function toggleSizeLists(length)
{
	if(document.getElementById(sizeSelectBoxId))
		document.getElementById(sizeSelectBoxId).style.display = 'none';

	if(length == null || length == "")
	{
		var length = document.getElementById('lengths').value;
	}

	if(length != "")
	{
		length = length.replace(" ","");
		var sizebox = document.getElementById(length + "_length");

		sizeSelectBoxId = sizebox.name;

		sizebox.style.display = 'block';
	}
}

function toggleColourImage(url, theid)
{
	thevalue = document.getElementById(theid).value;
	
	imgName = thevalue.split(":");
	img = imgName[1];
	
	if(img != "" && thevalue != "")
	{
		document.getElementById('cimage').setAttribute('src',url + 'thumbs/' + img);
		document.getElementById('clink').setAttribute('href',url + img);
		document.getElementById('colourimage').value=img;
	}
}