function addFriend() {

	// Get the last DIV class in the parent container
	var lastChild = $$("#FriendsContainer div:last-child")[0];
	
	// Create a clone of the last DIV and update the form field names
	var newChild = lastChild.cloneNode(true);
	var newId = $('FriendsContainer').childElements().length + 1;
	
	// Quick and Dirty Id/Name changes for inputs
	newChild.id = 'Friends_' + 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
	$$('#Friends_' + 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;
		}
		
	});
	
	// Slide the new Printer down
	new Effect.BlindDown($(newChild.id),{ duration: 0.4 });
}


// 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();
	
}

// Change colour for thumbnail view
function changeColour(productContainerId, productName, productUrl, productImage){
	
	var imageTemplate = new Template('<a href="#{productUrl}"><img src="#{productImage}" alt=""></a>');	
	
	$(productContainerId).update(imageTemplate.evaluate({ 
		productUrl:productUrl, 
		productImage:productImage 
	}));
	
}

// Change additional image for product details
function changeImage(containerId, imageName, imageLocation, largeLocation){
	
	if(largeLocation.length){
		imageTemplate = new Template('<a href="#{largeLocation}" class="lightwindow" title="#{imageName}"><img src="#{imageLocation}" alt=""></a>');
	
		$(containerId).update(imageTemplate.evaluate({ 
			imageName:imageName, 
			imageLocation:imageLocation,
			largeLocation:largeLocation
		}));
		
		// Have to call lightwindow again to parse the DOM tree finding all the lightwindow references
		lightwindowInit();
		
	}
	else {
		
		imageTemplate = new Template('<img src="#{imageLocation}" alt="">');
		
		$(containerId).update(imageTemplate.evaluate({ 
			imageLocation:imageLocation
		}));
	}

	
}

// 
function changeImageView(image,large){
	
}

// Online Help 
function toggleOnlineHelp(elId) {

	aEls = $$('#OnlineHelp a.Link');

	for(i=0; i < aEls.length; i++)
		aEls[i].removeClassName('Selected');
	
	divEls = $$('#OnlineHelp div');
	for(i=0; i < divEls.length; i++)
		divEls[i].hide();
		
	$('Link' + elId).addClassName('Selected');
	$('Item' + elId).show();
	
}

// Gallery - wallpapers
function MM_jumpMenu(targ,selObj,restore) { //v3.0

	eval("window.open('"+selObj.options[selObj.selectedIndex].value+"','image','')");
	if(restore) 
		selObj.selectedIndex = 0;
		
}

function displayPrettySearch(){

	var els = document.getElementsByTagName('input');

	for(var i=0; i<els.length ;i++){

		if(Element.hasClassName(els[i],'PrettySearch'))

			new Control.DecorateSearch(els[i]);

	}

}

/*function displayVideo(relroot,el,videofile,imagefile,summary,autoplay) {
	
	// Set the path to the video player
	var playerPath = relroot + '/flash/videoplayer/video-player.swf';
	
	// Create a new video object
	var objVideo = new FlashObject(playerPath,"VideoMain","640","385","9","#000000");
				
	objVideo.addVariable("imagePath",imagefile);
	objVideo.addVariable("videoPath",videofile);
	objVideo.addVariable("videoBufferTime","2.0");
	objVideo.addVariable("viewFullscreenButton","false");
	objVideo.addVariable("viewInfoButton","false");
	objVideo.addVariable("videoAutoPlay",autoplay);
	objVideo.addVariable("fullSizeView","1");
	objVideo.addVariable("videoLoop","false");
	objVideo.addVariable("viewTime","true");
	objVideo.addVariable("controlHeight","25");
	
	objVideo.addVariable("color1","0x002A4A");
	objVideo.addVariable("color2","0x0D283D");
	objVideo.addVariable("alpha1","1");
	objVideo.addVariable("alpha2","1");
	objVideo.addVariable("borderColor","0x001D33");
	objVideo.addVariable("borderAlpha","1");
	
	objVideo.addVariable("timeColor1","0x001D33");
	objVideo.addVariable("timeColor2","0x001D33");
	objVideo.addVariable("timeAlpha1","1");
	objVideo.addVariable("timeAlpha2","1");
	
	objVideo.addVariable("timeTextColor1","0xffffff");
	objVideo.addVariable("timeTextColor2","0x888888");
	objVideo.addVariable("scrubberColor1","0x001D33");
	objVideo.addVariable("scrubberAlpha1","1");
	objVideo.addVariable("scrubberColor2","0x47d2ff");
	objVideo.addVariable("scrubberAlpha2","1");
	
	objVideo.addParam("wmode","opaque"); 
	objVideo.write(el);
	
	// Write the Video summary
	if($('VideoInfo'))
		$('VideoInfo').update(summary);
}*/

function displayVideo(relroot,el,videofile,imagefile,summary,autoplay) {
	
	// Set the path to the video player
	var playerPath = relroot + '/flash/flowplayer/flowplayer-3.1.5.swf';
	var controlsPath = relroot + '/flash/flowplayer/flowplayer.controls-3.1.5.swf';

	flowplayer(el, playerPath, {        // supply the configuration 
 
	    clip : {
	        autoPlay: true, 
	        autoBuffering: true
	    }, 
	 
	    playlist: [
	        videofile
	    ],
		
		plugins: {
			
			controls: {
				
				url: controlsPath, 
				progressColor:'#d5181e',
				progressGradient:'medium',
				bufferColor:'#be797b',
				bufferGradient:'low',
		        autoHide: 'never',
				timeColor:'#efd347',
				scrubber:true
				
			}
			
		}
		
	}); 

	// Write the Video summary
	if($('VideoInfo'))
		$('VideoInfo').update(summary);
}

function scrollNews(success,msg) {
	
	// Hide the loader and display the update message
	$('Loader').hide();
	$('Message').show().addClassName('Highlight').update(msg);
	
	// If success is true then submit the external login process
	if (success) {
		// Wait 1.5 seconds before submitting form so the DOM has a chance to change the message
		new PeriodicalExecuter(function(pe) {
			$('NewsPanel').next();
			pe.stop();	
		}, 3);
	}
	
}