// remote call of ajax-enabled function
function rCall( component, method, params, options, loadingId, containerId) {
	var target = $(options.domupdate_id);
	var fnOnComplete = options.onComplete;
	var sReturnFormat = options.returnFormat;
	var sHttpMethod = options.method;
	var objLoadingStatus = $( loadingId );
	var container = $( containerId );
	var sRelPath = sBasePath;
	
	// get or post
	if (!$defined(sHttpMethod)) {
		sHttpMethod = 'post';
		}
		
	// html or JSON
	if (!$defined(sReturnFormat)) {
		sReturnFormat = 'html';
		}		
		
	if (!$defined(sRelPath)) {
		sRelPath = '/';		
		}
		
	if (!$defined(objLoadingStatus)) {
		objLoadingStatus = $( 'idLoadingStatus' );
	}
	
	if (!$defined(container)) {
		container =  $( 'idAffiliateOutput' );
	}
	
	var container_width = container.getStyle('width').toInt();
	var container_height = container.getStyle('height').toInt();	
		
	// show loading status?
	if ($defined(objLoadingStatus)) {
		objLoadingStatus.setStyle( 'left', ( (container_width - 31) / 2)).setStyle( 'top', ( (container_height - 31) / 2)).setStyle( 'display', '' );
		}
		
	var myRequest = new Request(
			{method: sHttpMethod,
			 url: sRelPath + 'apps/services/oRemote.cfm',
			 evalScripts: true,
			  onComplete: function(response) {
			  	
			  	// update target if provided
			  	if ($defined(target)) {
			  		target.set( 'html', response );
			  		}
			  		
			  	// execute a fn when data has been loaded
			  	if ($defined(fnOnComplete))	{
					fnOnComplete(response);
					}
			  		
			  	// hide loading status bar
			  	if ($defined(objLoadingStatus)) {
			  		objLoadingStatus.setStyle( 'display', 'none' );
			  		}
			  		
			  	// track the ajax request
			  	pageTracker._trackPageview( "/ajax/" + method + "/" );
			  	}
			  	
			 }
			 );
			 
	myRequest.send( 'hm=' + component + '&fn=' + method + '&fo=' + sReturnFormat + '&req=' + encodeURIComponent(JSON.encode( params )) + '&rel=' + escape( sRelPath ) );
	}
	
// display cart with items and actions
function reloadCart( hm ) {	
	rCall( hm, 'renderCart', {}, { 'domupdate_id' : 'idCartOutput' } );		
	}

// update header navigation with the various level 1 bundles
function UpdateBundleHeader( active ) {
	var lActive = $(active);
	var uidHeaderBundleList = $( 'idHeaderBundleList' );
	var oTabs = $( 'myTabs' );
	
	oTabs.getElements( '.replace_me' ).set('html', lActive.get('title').split(' ')[0] );
	
	uidHeaderBundleList.getElements( 'li' ).removeClass( 'active' );
	var oParent = lActive.getParent('li');
	
	if ($defined(oParent)) {
		oParent.addClass( 'active' );
		}
	}
	
// update header navigation with the various level 1 bundles
function UpdateBundleSearchHeader( active ) {
	var lActive = $(active);
	var uidHeaderBundleList = $( 'idHeaderSearchBundleList' );
	var oTabs = $( 'myTabs2' );
	
	oTabs.getElements( '.replace_me' ).set('html', lActive.get('title').split(' ')[0] );
	
	uidHeaderBundleList.getElements( 'li' ).removeClass( 'active' );
	var oParent = lActive.getParent('li');
	
	if ($defined(oParent)) {
		oParent.addClass( 'active' );
		}
	}
	
// paginator for bundle items
function UpdateBundleItemsListing( currentstartrow, rowsperpage, maxrows, sGenreBoxID ) {
	// JS is zero based ...
	var currentstartrow = currentstartrow - 1;
	var items = $( 'idBundleItemsListing' ).getElements( 'li' );
	var iStart = (currentstartrow + rowsperpage );
	var iTo = (currentstartrow  + (rowsperpage * 2) );
	var imaxrows = items.length;
	
	if (iTo > maxrows) { iTo = maxrows };
	
	// hide all
	items.setStyle( 'display', 'none' );
	
	// show right items
	for (var i = iStart; i < iTo; i++) {
		$(items[ i ]).setStyle( 'display', '' );			
		}

	if (currentstartrow > -1) {
		$(sGenreBoxID).getElements( 'input.back' ).removeClass( 'invisible' );
		} else {
			$(sGenreBoxID).getElements( 'input.back' ).addClass( 'invisible' );
		}
		
	if (iTo == maxrows) {
		$(sGenreBoxID).getElements( 'input.forward' ).addClass( 'invisible' );
		} else {
			$(sGenreBoxID).getElements( 'input.forward' ).removeClass( 'invisible' );
		}
		
	// set new startrow (CF style)
	iCurBundleStartrow = iStart + 1;
	}
	
// musicload album details
function loadMusicloadAlbumDetails( hm, album_ID, cartlink_encoded, prelistelink_encoded ) {
	var oAlbumContainer = $('idMLAlbumListing');
	
	oAlbumContainer.setStyle( 'display', '' );
	oAlbumContainer.getElements( '.content' ).set( 'html', '' );
	oAlbumContainer.getElements( '.loadingimg' ).removeClass( 'invisible' );
	
	rCall( hm, 'getRenderedMusicLoadAlbumInformationAndTracks', { 'sAlbum_ID' : album_ID, 'sCartlink_encoded' : cartlink_encoded, 'sPrelistenLink_encoded' : prelistelink_encoded }, { 'onComplete' : function( content ) {
	
		oAlbumContainer.getElements( '.loadingimg' ).addClass( 'invisible' );
		oAlbumContainer.getElements( '.content' ).set( 'html', content );	
		} }, 'idLoadingMusicloadAlbumInfo', 'idMLAlbumListing' );
	
	
	}