function ajaxGetSongList(afterFunc) {
	slPagingObj.perPage = parseInt($('pagingPerPage_inp').get('value'));
	slPagingObj.perPage = (slPagingObj.perPage > 0) ? slPagingObj.perPage : 20;
	currentSong = -1;
//	alertObject(slPagingObj);
	var req = new Request.HTML({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'getSongList',
				'user'          : user,
				'slSearchObj'   : slSearchObj,
				'slPagingObj'   : slPagingObj },
		onRequest: function() { 
			$('slStatus_div').set('html', 'Loading Song List');
			$('slStatus_div').setStyle('visibility', 'visible');
		},
		update: $('slContents_div'),
		onComplete: function(response) {
//						resized();
						updateDiv('sl_div');
						aSlSongs.length = 0;
						aSlSongRows.length = 0;
						$$('.slSong').each ( function(item) {
								var songNum = parseInt(item.id.match(/[0-9]+/));
								aSlSongs[songNum] = {
									cityId    : item.getAttribute('city_id'),
									songName  : item.getAttribute('song_name'),
									artist    : item.getAttribute('artist'),
									aVersions : parseInt(item.getAttribute('a_versions')),
									vVersions : parseInt(item.getAttribute('v_versions')),
									sVersions : parseInt(item.getAttribute('s_versions')),
									zVersions : parseInt(item.getAttribute('z_versions')),
									isCollab  : item.getAttribute('is_collab') };
								aSlSongs[songNum].totalVersions = aSlSongs[songNum].aVersions + aSlSongs[songNum].vVersions +
																  aSlSongs[songNum].sVersions + aSlSongs[songNum].zVersions;

								$('slDemoIcon'+ songNum + '-0_td').getChildren('img')[0].src =
								(aSlSongs[songNum].isCollab == 1) ? "assets/images/banners_logos/cl_logo_12x12.gif"
														 : spacer_img;
														 
								aSlSongRows[songNum] = new Array();
									
//										alertObject(aSlSongs[songNum]);
							} );
						
						$$('.slDetail').each ( function(item) {
									var songNum = getSongNum (item.id);
									var rowNum  = getRowNum  (item.id);
									aSlSongRows[songNum][rowNum] = {
										versionId     : item.getAttribute('version_id'),
										isProcessing  : item.getAttribute('is_processing'),
										media         : item.getAttribute('media'),
										isStem        : item.getAttribute('is_stem'),
										token         : item.getAttribute('token'),
										origFilename  : item.getAttribute('orig_filename'),
										fileSize      : item.getAttribute('file_size'),
										vote          : item.getAttribute('vote'),
										mediaName     : item.getAttribute('media_name'),
										mediaNameHTML : $('mediaName' + songNum + '-' + rowNum + '_td').get('html') };
										
										$('mediaIcon'+songNum+'-'+rowNum+'_td').getChildren('img')[0].src =
											aMediaIcons[aSlSongRows[songNum][rowNum].media];
											
	//										alertObject(aSlSongRows[songNum][rowNum]);
								} );

						slPagingObj.totalSongs = parseInt($('slSongs_div').getAttribute('totalSongs'));
						slPagingObj.pageNum    = parseInt($('slSongs_div').getAttribute('pageNum'));
						slPagingObj.totalPages = parseInt(Math.ceil(slPagingObj.totalSongs / slPagingObj.perPage));
						$('pagingCurrPage_span'  ).set('html', slPagingObj.pageNum);
						$('pagingTotalPages_span').set('html', slPagingObj.totalPages);
						$('pagingPerPage_inp'    ).set('value', slPagingObj.perPage);
						
						$('songCount_span').set('html', 'Showing ' + slPagingObj.totalSongs + ' Songs');
						
						setSongSummaries();
						$('slStatus_div').setStyle('visibility', 'hidden');
						afterFunc();
					}
				}).send();
}

function ajaxGetBanners(afterFunc) {
	var req = new Request.JSON({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'getBanners',
		 		'cityId'        : selectedCityId },
		onRequest: function() { },
		onComplete: function(response) {if (statusDisplay) alertObject (response.r1);
				bannersObj = response;
				displayBanners();
				if (afterFunc) afterFunc(response); }
			}).send();
		
}

function ajaxGetHTML (whichFunction, firstOption, secondOption, id, afterFunc) {
	var req = new Request.HTML({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : whichFunction,
				'firstOption'   : firstOption,
				'secondOption'  : secondOption,
				'id'            : id },
		onRequest: function() {
				$('slStatus_div').set('html', 'Loading');
				$('slStatus_div').setStyle('visibility', 'visible');
			},
		update: $(id),
		onComplete: function(response) {
				$('slStatus_div').setStyle('visibility', 'hidden');
				afterFunc(response);
			}
			}).send();
}

function ajaxFillHTML (obj, afterFunc) {
//	alert (obj.whichFunction + ", " + obj.table);
//	$(obj.id).innerHTML = "Test";
//  alert (obj.id + ", " + obj.parentId);
	$(obj.parentId).innerHTML = '<select id="' + obj.id + '"><option>Loading...</option></select>';
//	alert ('Sending currentSel of ' + obj.currentSel);
	var req = new Request.HTML({
		method: 'get',
		url: 'ajaxsvr.php',
		data: obj,
		onRequest: function() { },
		update: $(obj.parentId),
		onComplete: afterFunc }).send();
}

function ajaxGetUserSongSelector (includeAllUsers, name, id, parentId, afterFunc) {
	var req = new Request.HTML({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction'   : 'getUserSongSelector',
				'name'            : name,
				'id'              : id,
				'includeAllUsers' : includeAllUsers,
				'user'            : user },
		onRequest: function() { },
		update: $(parentId),
		onComplete: afterFunc }).send();
}

function ajaxGetCitySongSelector (cityId, name, id, parentId, afterFunc) {
	var req = new Request.HTML({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction'   : 'getCitySongSelector',
				'name'            : name,
				'id'              : id,
				'cityId'          : cityId,
				'user'            : user },
		onRequest: function() { },
		update: $(parentId),
		onComplete: afterFunc }).send();
}

function ajaxGetCityInfo(cityId, afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'getCityInfo',
		 		'cityId'            : cityId },
		onRequest: function() { },
		onComplete: function(response) { afterFunc(response); }
			}).send();
		
}

function ajaxGetName(id, table, afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'getName',
		 		'id'            : id,
				'table'         : table },
		onRequest: function() { },
		onComplete: function(response) { afterFunc(response); }
			}).send();
		
}

function ajaxCheckEmail(email, afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'checkEmail',
		 		'email'         : email },
		onRequest: function() { },
		onComplete: afterFunc
			}).send();
		
}

function ajaxSignIn(email, password, validate, afterFunc) {
	var userId = validate ? validate : -1;
	var req = new Request.JSON({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'signIn',
		 		'email'    : email,
				'password' : password,
				'validate' : userId },
		onRequest: function() { },
		onComplete: function(response) { afterFunc(response); }
			}).send();
		
}

function ajaxReg (userObj, mode, afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'reg',
		 		'user'          : userObj,
				'mode'			: mode },
		onRequest: function() { },
		onComplete: function(response) {
			afterFunc (response); }
			}).send();
}

function ajaxUploadAudio (songObj, afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'uploadAudio',
		 		'song'          : songObj },
		onRequest: function() { },
		onComplete: function(response) {
			afterFunc (response); }
			}).send();
}

function ajaxUploadVideo (videoObj, afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'uploadVideo',
		 		'video'         : videoObj },
		onRequest: function() { },
		onComplete: function(response) {
			afterFunc (response); }
			}).send();
}

function ajaxProcessAudio (songObj, afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'processAudio',
		 		'song'          : songObj },
		onRequest: function() {
						$('slStatus_div').set('html', 'Processing Upload');
						$('slStatus_div').setStyle('visibility', 'visible');
			},
		onComplete: function(response) {
			$('slStatus_div').setStyle('visibility', 'hidden');
			afterFunc (response); }
			}).send();
}

/* function ajaxRegister(afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'register',
		 		'user'          : user },
		onRequest: function() { },
		onComplete: function(response) {afterFunc (response); }
			}).send();
}

function ajaxUpdateRegistration(afterFunc) {
	var req = new Request({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'updateRegistration',
		 		'user'          : user },
		onRequest: function() { },
		onComplete: function(response) { afterFunc (response); }
			}).send();
} */

function ajaxBuildCountryCitySelectors(which) { // alert ('building for city ' + browserSettings.city_id);
	var countryFirstOption = '';
	var countryCurrentSel  = '';
	var cityFirstOption    = '';
	var cityCurrentSel     = '';
	var cityFirstOption2   = '';
	var cityCurrentSel2    = '';
	
	ajaxGetCityInfo(browserSettings.city_id, function(response) {	// Get the info about the current cityId
//		alert (response);
		switch (which) {
			case 'search':
				countryFirstOption = 'all';
				countryCurrentSel  = 'all';
				cityFirstOption    = 'all';
				cityCurrentSel     = 'all';
				cityFirstOption2   = 'all';
				cityCurrentSel2    = 'all';
			break;
	
			case 'cs':
				countryFirstOption = 'Choose...';
				countryCurrentSel  = JSON.decode(response).country_id;
				cityFirstOption    = 'Choose...';
				cityCurrentSel     = browserSettings.city_id;
				cityFirstOption2   = '';
				cityCurrentSel2    = '';
			break;
			
			case 'uploadSong':
				countryFirstOption = 'Choose...';
				countryCurrentSel  = JSON.decode(response).country_id;
				cityFirstOption    = 'Choose...';
				cityCurrentSel     = browserSettings.city_id;
				cityFirstOption2   = '';
				cityCurrentSel2    = '';
			break;
			
		}
		
		ajaxFillHTML ({'whichFunction' : 'buildSelector',			// Build the country selector
					   'table'         : 'countries',
					   'firstOption'   : countryFirstOption,
					   'currentSel'    : countryCurrentSel,
					   'id'            : which+'Country_sel',
					   'parentId'      : which+'Country_td'}, function() {
							$(which+'Country_sel').onchange = function() {
							var countryId = $(which+'Country_sel').get('value');
							if (countryId != 'Choose...') {         // Make sure they've chosen comething other than Choose...
//								browserSettings.city_id    = cityCurrentSel2;
								ajaxFillHTML ({'whichFunction' : 'buildSelector',	// If country changes, rebuild city selector
											   'table'         : 'cities',
											   'firstOption'   : cityFirstOption2,
											   'currentSel'    : cityCurrentSel2,
											   'parentKey'     : 'country_id',
											   'parentSel'     : countryId,
											   'id'            : which+'City_sel',
											   'parentId'      : which+'City_td'}, 
											   function() {
												   if (which == 'search') {
													   $('searchCity_sel').onchange = fnSubmitSearchForm;
													   fnSubmitSearchForm();
												   }
											   });
							}
						}
					});
		
		ajaxFillHTML ({'whichFunction' : 'buildSelector',			// Build the city selector
					   'table'         : 'cities',
					   'firstOption'   : cityFirstOption,
					   'currentSel'    : cityCurrentSel,
					   'parentKey'     : 'country_id',
					   'parentSel'     : JSON.decode(response).country_id,
					   'id'            : which+'City_sel',
					   'parentId'      : which+'City_td'}, 
					   function() { if (which == 'search') $('searchCity_sel').onchange = fnSubmitSearchForm; });
	});
}

function ajaxProcessAudioFile(filename, afterFunc) {
	var req = new Request.JSON({
		method: 'get',
		url: 'clprocessor.php',
		data: { 'whichFunction' : 'signIn',
		 		'filename'      : filename },
		onRequest: function() { },
		onComplete: function(response) { afterFunc(response); }
			}).send();
		
}

function ajaxDownloadFile(filename, afterFunc) {
	var req = new Request.JSON({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'downloadFile',
		 		'filename'      : filename },
		onRequest: function() { },
		onComplete: function(response) { afterFunc(response); }
			}).send();
		
}

function ajaxResetPassword(userId, afterFunc) {
	var req = new Request.JSON({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'resetPassword',
		 		'userId'        : userId },
		onRequest: function() { },
		onComplete: function(response) { afterFunc(response); }
			}).send();
		
}

function ajaxResendValidationEmail(userId, afterFunc) {
	var req = new Request.JSON({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'resendValidationEmail',
		 		'userId'      : userId },
		onRequest: function() { },
		onComplete: function(response) { afterFunc(response); }
			}).send();
		
}

function ajaxSendSystemEmail(emailObject, afterFunc) {
	var req = new Request.JSON({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'sendSystemEmail',
		 		'emailObject'   : emailObject },
		onRequest: function() { },
		onComplete: function(response) { afterFunc(response); }
			}).send();
		
}

function ajaxRecordVote(versionId, songNum, rowNum, userId, voteStatus, afterFunc) {
	var req = new Request.JSON({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'recordVote',
		 		'versionId'     : versionId,
		 		'userId'        : userId,
				'voteStatus'    : voteStatus },
		onRequest: function() { },
		onComplete: function(response) {
//			alertObject(response);
			aSlSongRows[songNum][rowNum].vote = response.status;
			if (aSlSongRows[songNum][rowNum].vote == 1) {				// If they've voted for this version
				aButtonStates['playerVote_btn'] = true;
			} else {
				aButtonStates['playerVote_btn'] = false;
			} // alert ('Ajax: songNum: ' + songNum + ', rowNum: ' + rowNum + ', .vote: ' + aSlSongRows[songNum][rowNum].vote);
			fnLightPlayerVoteButton();
			fnShowHideVotes(songNum);
		
			afterFunc(response); }
		}).send();
		
}

function ajaxLogActivity (type, versionId, userId, afterFunc) {
	var req = new Request.JSON({
		method: 'get',
		url: 'ajaxsvr.php',
		data: { 'whichFunction' : 'logActivity',
				'type'          : type,
		 		'versionId'     : versionId,
		 		'userId'        : userId },
		onRequest: function() { },
		onComplete: function(response) {
//			alertObject (response);
			if (afterFunc) afterFunc(response);
			}
		}).send();
		
}


