//Global vars
var searchHelpElement = 'SearchHelpWebShop';

function showAddonsOnAddToBasketClick(webID, imgControlPrimary, typePrimary)
{
	var imgPrimary = typePrimary;
	var typePrimary = typePrimary + webID;
	var imgControlPrimary = document.getElementById(imgControlPrimary);

	var boxPrimary = document.getElementById('Box' + typePrimary);
	var itemRowBasic = document.getElementById('ArticleRowBasic' + webID);
	var itemRowDetailed = document.getElementById('ArticleRowDetailed' + webID);

	//Default value for the table row
	itemRowBasic.className = 'ArticleRow';

	//Show the details/addons again
	boxPrimary.className = 'Visible';
	imgControlPrimary.className = imgPrimary + 'Close';
	itemRowBasic.className += ' ArticleRowBasic';
	itemRowDetailed.className = '';
	return true;
}

function changeOpenStatus(webID, imgControlPrimary, imgControlSecondary, typePrimary, typeSecondary, closeAll)
{
	imgPrimary = typePrimary;
	imgSecondary = typeSecondary;
	typePrimary = typePrimary + webID;
	typeSecondary = typeSecondary + webID;

	imgControlPrimary = document.getElementById(imgControlPrimary);
	imgControlSecondary = document.getElementById(imgControlSecondary);

	var boxPrimary = document.getElementById('Box' + typePrimary);
	var boxSecondary = document.getElementById('Box' + typeSecondary);

	var itemRowBasic = document.getElementById('ArticleRowBasic' + webID);
	var itemRowDetailed = document.getElementById('ArticleRowDetailed' + webID);

	//Default value for the table row
	itemRowBasic.className = 'ArticleRow';
	
	if (elementIsNull(typePrimary))
	{
		//The clicked box is null so we want to show the row and let ajax fill the object.
		boxPrimary.className = 'Visible';
		imgControlPrimary.className = imgPrimary + 'Close';
		itemRowBasic.className += ' ArticleRowBasic';
		itemRowDetailed.className = '';
		return true;
	}

	if (itemRowDetailed.className == 'Hidden')
	{
		//Show the details/addons again
		boxPrimary.className = 'Visible';
		imgControlPrimary.className = imgPrimary + 'Close';
		itemRowBasic.className += ' ArticleRowBasic';
		itemRowDetailed.className = '';
		return false;
	}

	//The clicked element is visible so we want to hide it.
	//If the clicked element is details we also wanna hide the addons.
	//If the clicked element is addons we still want to keep the details view visible
	if (elementIsNull(typeSecondary))
	{
		//No secondary box is avaiable so we just hide the clicked element
		imgControlPrimary.className = imgPrimary + 'Open';
		boxPrimary.className = 'Hidden';
		itemRowDetailed.className = 'Hidden';
		return false;
	}

	if (boxPrimary.className == "Visible" && closeAll == 1)
	{
		//Secondary box is available and its addons so we close them both
		imgControlPrimary.className = imgPrimary + 'Open';
		imgControlSecondary.className = imgSecondary + 'Open';
		boxPrimary.className = 'Hidden';
		boxSecondary.className = 'Hidden';
		itemRowDetailed.className = 'Hidden';
		return false;
	}

	if (boxPrimary.className == "Visible" && closeAll == 0)
	{
		//Hide the addons box
		imgControlPrimary.className = imgPrimary + 'Open';
		boxPrimary.className = 'Hidden';
		if (elementIsNull(typeSecondary) || boxSecondary.className == "Hidden")
		{
			//Hide the row aswell if the user only displays the addons
			itemRowDetailed.className = 'Hidden';
		}
		else
			itemRowBasic.className += ' ArticleRowBasic';

		return false;
	}

	//Clicked box (addons) is hidden so we show it again
	imgControlPrimary.className = imgPrimary + 'Close';
	boxPrimary.className = 'Visible';
	itemRowBasic.className += ' ArticleRowBasic';

	return false;
}

function hideShowLocations(id)
{
	var box = document.getElementById('row' + id);

	if (box.className == 'Hidden')
	{
		box.className = '';
		return false;
	}

	box.className = 'Hidden';
	return false;
}

function hideElement(element)
{
	if (document.getElementById(element) != null) { document.getElementById(element).className = 'Hidden'; }
}

function searchTabChanged(sender, args)
{
	if (document.getElementById('EPiServerSearchOptions') != null)
	{
		tabIndex = sender.get_activeTabIndex();
		if (tabIndex == 1)
		{
			hideElement(searchHelpElement);
			searchHelpElement = 'SearchHelp';
			document.getElementById('EPiServerSearchOptions').className = '';
		}
		else
		{
			hideElement(searchHelpElement);
			searchHelpElement = 'SearchHelpWebShop';
			document.getElementById('EPiServerSearchOptions').className = 'Hidden';
		}
	}
}

function ToggleSearchHelp()
{
	var helpDiv = document.getElementById(searchHelpElement);
	helpDiv.className = (helpDiv.className == '' ? 'Hidden' : '');
}

function elementIsNull(element)
{
	if (document.getElementById(element) == null) { return true; }
	return false;
}

function showHideHistoryBox(elementID, currentCssClass)
{
	var clickedElement = document.getElementById("headerLink" + elementID);
	
	if (document.getElementById(elementID) != null)
	{
		var obj = document.getElementById(elementID);
		if (obj.className == 'Hidden')
		{
			obj.className = '';
			clickedElement.className = "Selected" + currentCssClass;
		}
		else
		{
			obj.className = 'Hidden';
			clickedElement.className = currentCssClass;
		}
	}
}

function checkChilds(inputContainerID, thisObject)
{
	var obj = document.getElementById("row" + inputContainerID);
	var inputs = obj.getElementsByTagName("input");
	var checkValue = false;
	if (thisObject.checked)
		checkValue = true;

	for (x = 0; x < inputs.length; x++)
	{
		if (inputs[x].type == 'checkbox')
		{
			if (checkValue)
				inputs[x].checked = checkValue;

			if (checkValue)
				inputs[x].disabled = true;
			else
				inputs[x].disabled = false;
		}
	}
}

function ie6HoverFix(e)
{
	if(e.className.indexOf('hover', 0) > 0)
		e.className = e.className.replace('hover', '');
	else
		e.className += ' ' + 'hover';
}
function selectBoxContent(e)
{
	e.select();
}

function simpleFlashLoader(url, identifier, width, height, vars)
{
	var flashvars = {};
	var params = {};
	params.quality = "high";
	params.allowscriptaccess = "sameDomain";
	params.scale = "default";
	params.wmode = "transparent";
	params.allowfullscreen = "true";
	params.bgcolor = "#ffffff";
	params.align = "middle";
	if (vars != null)
	{
		params.flashvars = vars;
	}
	var attributes = {};
	swfobject.embedSWF(url, identifier, width, height, '9.0.0', false, flashvars, params, attributes);
}

function simpleFlashPlayerLoader(player, url, identifier, width, height)
{
	var flashvars = {};
	flashvars.file = url;
	var params = {};
	params.quality = "high";
	params.allowscriptaccess = "sameDomain";
	params.scale = "default";
	params.wmode = "transparent";
	params.allowfullscreen = "true";
	var attributes = {};
	swfobject.embedSWF(player, identifier, width, height, '9.0.0', false, flashvars, params, attributes);
}