// Redirect
function redirect(Url){
	document.location = Url;
}

// Checkout
function deleteItem(id) {
	frm = document.getElementById('frmBasket');
	frm.action.value = 'deleteItem';
	frm.itemId.value = id;
	frm.submit();
}

// Toggle Views 
function toggleView(elId) {

	aEls = $$('#Accordion a.Link');

	for(i=0; i < aEls.length; i++)
		aEls[i].removeClassName('Selected');
	
	divEls = $$('#Accordion div');
	for(i=0; i < divEls.length; i++)
		divEls[i].hide();
		
	$('Link' + elId).addClassName('Selected');
	$('Item' + elId).show();
	
}

function addPrinter() {

	// Get the last DIV class in the parent container
	var lastChild = $$("#PrinterContainer div:last-child")[0];
	
	// Create a clone of the last DIV and update the form field names
	var newChild = lastChild.cloneNode(true);
	var newId = $('PrinterContainer').childElements().length + 1;
	
	// Quick and Dirty Id/Name changes for inputs
	newChild.id = 'Printer_' + newId;
			
	// Insert the new class DIV and fade it in gracefully
	lastChild.insert({after: newChild.hide()});
	
	// Loop over all INPUT fields within this clone and change to newId
	$$('#Printer_' + newId + ' input').each(function(el){
		
		// create a split array using "_" to get the current number and name and create new ones
		var aName =  el.name.split('_');
		
		newName = aName[0] + '_' + newId;

		// Change all NAME attributes to new element and clear fields
		el.name = newName;
		el.value = '';
		
		// If an ID was assigned change to new element ID
		if (el.id) {
			el.id = newName;
		}
		
	});
	
	// Update Printer Heading
	$$('#Printer_' + newId + ' h3').each(function(el){
		el.update('Printer ' + newId);
	});
	
	// Slide the new Printer down
	new Effect.BlindDown($(newChild.id),{ duration: 0.4 });
}

function removePrinter(el) {
	
	if ($('PrinterContainer').childElements().length > 1) {
		// Fade the element away nicely before removing it from DOM
		new Effect.BlindUp($(el).up(),{ duration: 0.4 });
		
		// Stagger the removal of the element as it shags the blind effect otherwise
		new PeriodicalExecuter(function(pe) {
			$(el).up().remove();
			pe.stop();	
		}, 0.5);	
	}
	
}