function init()
{
	if( typeof( pageSetup ) != 'undefined' )
	{
		pageSetup();
	}
}

function plus( articleId )
{
	var el	=	getElement( 'articleAmount' + articleId );
	var val	=	getValue( el );
	el.value	=	val+1;
}

function doSort()
{
	var sField = document.getElementById( 'sortField' );
	var dField = document.getElementById( 'sortDir' );

	var sFieldValue = sField[sField.selectedIndex].value;
	var dFieldValue = dField[dField.selectedIndex].value;

	var uri = dispatcher+'&sortField=' + sFieldValue + '&sortDir=' + dFieldValue;
	document.location = uri;
}

function getValue( el )
{
	var val	=	el.value;

	if( !val.match(/[0-9]/) )
	{
		val	=	0;
	}

	if( typeof( val ) != 'number' )
	{
		val	=	val * 1;
	}

	return val;
}

function minus( articleId )
{
	var el	=	getElement( 'articleAmount' + articleId );
	var val	=	getValue( el );

	val	=	val-1;
	if( val < 1 )
	{
		val	=	0
	}

	el.value	=	val;
}

function minusMore( articleId )
{
	var el	=	getElement( 'articleAmount' + articleId );
	var val	=	getValue( el );

	val	=	val-10;
	if( val < 1 )
	{
		val	=	0
	}

	el.value	=	val;
}

function plusMore( articleId )
{
	var el	=	getElement( 'articleAmount' + articleId );
	var val	=	getValue( el );
	el.value	=	val+10;
}

function xshFormSubmit()
{
	if( typeof( pageFormSubmit ) != 'undefined' )
	{
		pageFormSubmit();
	}

	return true;
}

function displayHistory()
{
	var el = document.getElementById( 'history' );

	if( el.style.visibility == 'visible' )
	{
		el.style.visibility = 'hidden';
	}
	else
	{
		el.style.visibility = 'visible';
	}
}

function displayBlock( bid )
{
	var el = getElement( bid );
	el.style.display = 'block';
}

function hideBlock( bid )
{
	var el = getElement( bid );
	el.style.display = 'none';
}

function Login_CheckState()
{
	var eCEl = getElement( 'eC' );
	var nCEl = getElement( 'nC' );

	if( eCEl.checked )
	{
		displayBlock( 'LoginExisting' );
		hideBlock( 'LoginRegister' );
		hideBlock( 'LoginRegister2' );
		displayBlock( 'LoginHint' );
	}
	else if( nCEl.checked )
	{
		hideBlock( 'LoginExisting' );
		displayBlock( 'LoginRegister' );
		displayBlock( 'LoginRegister2' );
		displayBlock( 'LoginHint' );
	}
	else
	{
		hideBlock( 'LoginHint' );
		hideBlock( 'LoginExisting' );
		hideBlock( 'LoginRegister' );
		hideBlock( 'LoginRegister2' );
	}
}

// hide/show the shipping block depending
// on the state of the checkbox
function Address_updateBlocks( checkObj )
{
	var el = document.getElementById( 'shipping' );

	if( checkObj.checked )
	{
		el.style.display = 'none';
	}
	else
	{
		el.style.display = 'block';
	}
}

function Note_toggleNote()
{
	var el = getElement( 'xshNote' );
	var sel = getElement( 'switchNote' );

	if( sel.checked )
	{
		el.style.display = 'block';
	}
	else
	{
		el.style.display = 'none';
	}
}

var CreditCard_Profiles = [];

function CreditCard_addProfile( id )
{
	CreditCard_Profiles.push(id);
}

function CreditCard_selectProfile( btnEl, id )
{
	// deselect all profiles
	for( var i = 0; i < CreditCard_Profiles.length; i++ ) {
		document.getElementById( 'profile'+CreditCard_Profiles[i] ).className = 'profileN';
	}

	// select the button and the profile
	btnEl.selected = true;
	document.getElementById( 'profile'+id ).className = 'profileA';
}

function Cart_checkConfirm()
{
	if( document.getElementById('ConfirmAGBEL').checked ) {
		document.getElementById('OrderButton').style.display = 'block';
	} else {
		document.getElementById('OrderButton').style.display = 'none';
	}
}