// ================================================================================================
// Updated user console menu (200909)

function submenu (areaId)
{
	subName = areaId+'sub';
	//console.log(subName);
	
	if (document.getElementById(subName))
	{
		//console.log("current:", document.getElementById(subName).style.display);
		
		if (document.getElementById(subName).style.display == 'block')
		{
			document.getElementById(subName).style.display = 'none';
		}
		else
		{
			document.getElementById(subName).style.display = 'block';
		}
	}
}

var currentConsole = 1;
function consoleSwap()
{
	if (currentConsole == 1)
	{
		document.getElementById("console1").style.display = 'none';
		document.getElementById("console0").style.display = 'block';
		currentConsole = 0;
	}
	else
	{
		document.getElementById("console0").style.display = 'none';
		document.getElementById("console1").style.display = 'block';
		currentConsole = 1;
	}
}

// ================================================================================================
// Edition / Language Selection

function setEdition()
{
	newEdition = document.getElementById('siteedition').value;
	//console.log("newEdition", newEdition);
	
	setEditionTo(newEdition);
}

function setEditionTo(edition)
{
	destinationUrl = "/changeedition.php?to="+edition;
	if (typeof(languageTarget) != "undefined")
	{
		destinationUrl += "&destination="+escape(languageTarget);
	}
	
	window.location = destinationUrl;
}

function setLanguage()
{
	newLanguage = document.getElementById('sitelanguage').value;
	//console.log("newLanguage", newLanguage);
	
	setLanguageTo(newLanguage);
}

function setLanguageTo(lang)
{
	destinationUrl = "/changelanguage.php?to="+lang;
	if (typeof(languageTarget) != "undefined")
	{
		destinationUrl += "&destination="+escape(languageTarget);
	}
	
	window.location = destinationUrl;
}

function languageChange()
{
	newLanguage = document.getElementById('lang').value;
	
	setLanguageTo(newLanguage);
}

// In-page panel

function langSelectClose()
{
	langCookie(selectedEdition);
	langSelectClosePanel();
}

function langSelectClosePanel()
{
	document.getElementById('editionSelectionDiv').style.display = 'none';
}

function langSelectSave()
{
	langCookie(selectedEdition);
	
	if (selectedEdition != currentEdition)
	{
		window.location.reload();
	}
	else
	{
		langSelectClosePanel();
	}
	
	return false;
}

function langCookie(language)
{
	switch (language)
	{
		case "en":
			newLanguage = "en";
			newEdition  = "en";
			break;
		case "sc":
			newLanguage = "sc";
			newEdition  = "sc";
			break;
		case "tc":
			newLanguage = "tc";
			newEdition  = "tc";
			break;
		case "hk":
			newLanguage = "hk";
			newEdition  = "tc";
			break;
	}
	
	// Set a cookie
	createCookie(languageCookieName, newLanguage+"|"+newEdition, 365);
}

// ================================================================================================
// User Selection

function selectUser(userid, newState, selectId)
{
	//console.log("selectUser(", userid, newState, ")");
	
	mode = 'general';
	if (typeof(selectId) != "undefined")
	{
		mode = 'specific';
	}
	//console.log("mode", mode);
	
	if (mode == 'general')
	{
		checkboxName  = 'usercheck'+userid;
		selectorName  = 'select'+userid;
	}
	else if (mode == 'specific')
	{
		checkboxName  = userid;
		selectorName  = selectId;
	}
	checkboxState = false;
	
	//console.log("checkboxName", checkboxName);
	//console.log("selectorName", selectorName);
	
	if (typeof(newState) != "undefined")
	{
		// Find all checkbox with same name
		// to cater for multiple occurance of the same username
		var checkboxes = document.getElementsByName(checkboxName);
		for (i=0; i<checkboxes.length; i++)
		{
			checkboxes[i].checked = newState;
		}
		checkboxState = document.getElementById(checkboxName).checked;
	}
	else
	{
		checkboxState = document.getElementById(checkboxName).checked;
	}

	//console.log("checkboxState", checkboxState);
	
	if (document.getElementById(selectorName))
	{
		var className = 'Selectable';
		if (checkboxState == true)
		{
			className = 'Selected';
		}
		//console.log("className", className);
		
		// Find all selectors with same name
		// to cater for multiple occurance of the same username
		var selectors = document.getElementsByName(selectorName);
		//console.log("selectorlength", selectors.length);
		
		if (selectors.length > 0)
		{
			// If multiple matching names are found
			//console.log("selectors", selectors);
			
			for (i=0; i<selectors.length; i++)
			{
				selectors[i].className = className;
			}
		}
		else
		{
			// No "name='X'" elements found, just use elementById
			document.getElementById(selectorName).className = className;
		}
	}
}

userIds = [ ];
function selectAllUsers(newState)
{
	//console.log("selectAllUsers(", newState, ")");
	for (var i = 0; i < checkboxIds.length; i++)
	{
		checkboxid = checkboxIds[i];
		selectid   = selectIds[i];
		
		//console.log("Selecting "+userid);
		selectUser(checkboxid, newState, selectid);
	}
}

/*
function selectAllCheckboxes(form)
{
	var i = 0;
	for(i = 0; i < form.length; i++)
	{
		if(form[i].type == 'checkbox')
		{
			selectCheckbox(theform[i]);
		}
	}
}

function selectCheckbox(checkbox)
{
	checkboxName  = 'usercheck'+userid;
	selectorName  = 'select'+userid;
	checkboxState = false;
	
	if (typeof(newState) != "undefined")
	{
		if (document.getElementById(checkboxName))
		{
			document.getElementById(checkboxName).checked = newState;
			checkboxState = document.getElementById(checkboxName).checked;
		}
	}
	
	if (document.getElementById(selectorName))
	{
		if (checkboxState == true)
		{
			document.getElementById(selectorName).className = 'Selected';
		}
		else
		{
			document.getElementById(selectorName).className = 'Selectable';
		}
	}
}
*/
// ================================================================================================
// Form - Select Box - autoselect value

function setSelectedIndex(name, value)
{
	selectList = document.getElementById(name);
	for(i=0; i<selectList.options.length; i++)
	{
		 if(selectList.options[i].value == value)
		 {
			 selectList.selectedIndex = i;
			 break;
		 }
	}
	return i;
}

/*
//refer to /myfridae/travel/travel.php
new Array(
	"0" => ""; (id) //el id
	"1" => ""; (type) //text/area, selectList
	"2" => ""; (alert) // use alert boxes or div
	"3" => ""; (alertmsg) // alert msg
)*/
function formValidator(formElements)
{
	var errorCount = 0;
	var errorMsg = "";
	for (i=0; i<formElements.length; i++)
	{
		flag = true;
		el = document.getElementById(formElements[i][0]); //element
		switch (formElements[i][1]) //type of element
		{
			case "text": //textfield/textarea
				if(el.value=="")
				{
					errorCount++;
					flag = false;
				}
				break;
			case "select": //dropdown list
				if(el.selectedIndex==0)
				{
					errorCount++;
					flag = false;
				}
				break;
		}
		
		//if there is an error
		if(!flag)
		{
			if(formElements[i][2]=="") //divHolderID... if empty, use alertbox
			{
				errorMsg = errorMsg + " - " + formElements[i][3] + " \n";
			}
			else
			{
				showDivBox(formElements[i][2]);
			}
		}
	} 
	
	//if error
	if(errorCount>0)
	{
		//alert error msg
		if(errorMsg!="")
		{
			showAlertBox(errorMsg);
		}
		return false;
	}
	return true;
}

function showAlertBox(msg)
{
	alert(msg);
}

function showDivBox(id)
{
	document.getElementById(id).style.display = "";
}

// ================================================================================================
// Tab Sets

tabSetNames = [];
tabSetItems = [];

function createTabSet(name, tabids, clickid)
{
	tabSetNames.push(name);
	tabSetItems.push(tabids);
	
	//console.log(tabSetNames);
	//console.log(tabSetItems);
	
	//console.log("CID:",clickid);
	
	if (typeof(clickid) != 'undefined')
	{
		//console.log("click "+clickid+" in "+name+"...");
		clickTab(name, clickid);
	}
}

function clickTab(tabset, clickid)
{
	//console.log("clicking "+clickid+" in "+tabset+"...");
	
	tabSetId = 0;
	
	// find tabset
	for (var x = 0; x < tabSetNames.length; x++)
	{
		//console.log(x);
		//console.log(tabSetNames[x] + " -vs- " + tabset);
		if (tabSetNames[x] == tabset)
		{
			tabSetId = x;
		}
	}
	
	//console.log('tabSetId=',tabSetId);
	
	// get tabs
	targetTabs = tabSetItems[tabSetId];
	//console.log("targetTabs", targetTabs);
	
	for (var y = 0; y < targetTabs.length; y++)
	{
		tabid     = targetTabs[y];
		contentid = targetTabs[y]+'content';
		
		//console.log(tabid, contentid);
		
		if (document.getElementById(tabid))
		{
			//console.log("Deactivating tab "+tabid);
			document.getElementById(tabid).className = 'Inactive';
		}
		if (document.getElementById(contentid))
		{
			//console.log("Hiding content "+contentid);
			document.getElementById(contentid).style.display = 'none';
		}
	}
	//console.log("clickid=",clickid);
	
	clickidcontent = clickid+'content';
	//console.log("clickidcontent=",clickidcontent);
	if (document.getElementById(clickid))
	{
		document.getElementById(clickid).className = 'Active';
	}
	if (document.getElementById(clickidcontent))
	{
		document.getElementById(clickidcontent).style.display = 'block';
	}
	
}

// ================================================================================================
// Popup Windows

function userToUserConversation(cid, iid)
{
	popup("/conversation.php?c="+cid+"&i="+iid, "conversationWindow"+cid, 280, 450, 0);
	
	return false;
}

function selectEdition()
{
	popup("/edition.php", "editionWindow", 500, 400);
}

function liveChat(roomName)
{
	paramStr = "";
	if (roomName)
	{
		paramStr = "?channel="+roomName;
	}
	
	popup("/chat/interface.php"+paramStr, "liveChatWindow", 999, 650);
}

function viewProfile(username, page, heartId)
{
	if (userId > 0)
	{
		params = username;
		if (typeof(page) != "undefined")
		{
			params += "/"+page;
		}
		if (typeof(heartId) != "undefined")
		{
			params += "?h="+heartId;
		}
		
		popup("/userpop/"+params, "profileWindow"+username, 660, 690);
	}
	else
	{
		alert(pleaseLoginProfile);
	}
}

function sendHeart(username)
{
	if (userId > 0)
	{
		popup("/usertools/heart.php?username="+username, "toolWindowHeart", 400, 105);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function sendMessage(username)
{
	if (userId > 0)
	{
		popup("/usertools/message.php?username="+username, "toolWindowMessage"+username, 400, 385);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function bookmarkUser(username)
{
	if (userId > 0)
	{
		popup("/usertools/favourite.php?username="+username, "toolWindowFavourite", 400, 105);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function requestFriend(username)
{
	if (userId > 0)
	{
		popup("/usertools/friend.php?username="+username, "toolWindowFriend", 400, 105);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function addNote(username)
{
	if (userId > 0)
	{
		popup("/usertools/note.php?username="+username, "toolWindowNote"+username, 400, 375);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function forwardUser(username)
{
	if (userId > 0)
	{
		popup("/usertools/forward.php?username="+username, "toolWindowForward", 400, 400);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function requestKey(username)
{
	if (userId > 0)
	{
		popup("/usertools/requestkey.php?username="+username, "toolWindowRequestKey", 400, 105);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function giveKey(username)
{
	if (userId > 0)
	{
		popup("/usertools/givekey.php?username="+username, "toolWindowGiveKey", 400, 105);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function blacklistUser(username)
{
	if (userId > 0)
	{
		if (confirm(blacklistConfirm))
		{
			popup("/usertools/blacklist.php?username="+username, "toolWindowBlacklist", 400, 105);
		}
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function deleteComment(commentid)
{
	if (userId > 0)
	{
		popup("/usertools/commentdelete.php?commentid="+commentid, "toolWindowCommentDeletion"+commentid, 400, 105);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function reportProfile(userid)
{
	popup("/usertools/report.php?id="+userid+"&type=p", "toolWindowReportUser"+userid, 400, 380);
}
function reportProfilePhoto(userid,photoid)
{
	popup("/usertools/report.php?id="+userid+"-"+photoid+"&type=f", "toolWindowReportProfilePhoto"+userid+"-"+photoid, 400, 380);
}
function reportComment(commentid)
{
	popup("/usertools/report.php?id="+commentid+"&type=c", "toolWindowReportComment"+commentid, 400, 380);
}
function reportMessage(messageid)
{
	popup("/usertools/report.php?id="+messageid+"&type=m", "toolWindowReportMessage"+messageid, 400, 380);
}
function reportEvent(eventid)
{
	popup("/usertools/report.php?id="+eventid+"&type=e", "toolWindowReportEvent"+eventid, 400, 380);
}
function reportListing(listingid)
{
	popup("/usertools/report.php?id="+listingid+"&type=l", "toolWindowReportEvent"+listingid, 400, 380);
}
function reportListingMoveClose(listingid)
{
	popup("/usertools/report.php?id="+listingid+"&type=mc", "toolWindowReportEvent"+listingid, 400, 350);
}
function reportListingMove(listingid)
{
	popup("/usertools/report.php?id="+listingid+"&type=mc&preselect=moved", "toolWindowReportEvent"+listingid, 400, 350);
}

function editComment(commentid)
{
	popup("/usertools/commentedit.php?commentid="+commentid, "toolWindowComment"+commentid, 400, 275,1);
}

function voteCommentUp(commentid)
{
	if (userId > 0)
	{
		popup("/usertools/commentvote.php?commentid="+commentid+"&vote=up", "toolWindowCommentVoteUp"+commentid, 400, 105);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function voteCommentDown(commentid)
{
	if (userId > 0)
	{
		popup("/usertools/commentvote.php?commentid="+commentid+"&vote=down", "toolWindowCommentVoteDown"+commentid, 400, 105);
	}
	else
	{
		alert(pleaseLoginFunction);
	}
}

function photoGalleryNew(userid, galleryid, photoid)
{
	if (viewmode == 'full')
	{
		if (typeof(photoid) == undefined)
		{
			photoid = 1;
		}
		popup("/usertools/photogallerynew.php?uid="+userid+"&gid="+galleryid+"&pid="+photoid, "photoGalleryNew"+userid+""+photoid, 620, 580);
	}
	else
	{
		alert('Sorry, you have reached your daily profile view limit.');
	}
}

function photoGallery(userid, photoid)
{
	if (viewmode == 'full')
	{
		if (typeof(photoid) == undefined)
		{
			photoid = 1;
		}
		popup("/usertools/photogallery.php?t=p&uid="+userid+"&pid="+photoid, "photoGallery"+userid+""+photoid, 620, 580);
	}
	else
	{
		alert('Sorry, you have reached your daily profile view limit.');
	}
}

function vaultGallery(userid, photoid)
{
	if (typeof(photoid) == undefined)
	{
		photoid = 1;
	}
	popup("/usertools/photogallery.php?t=v&uid="+userid+"&pid="+photoid, "photoGallery"+userid+""+photoid, 620, 545);
}
function pictureGallery(userid, galleryid, photoid, page)
{
	popup("/usertools/picturegallery.php?uid="+userid+"&gid="+galleryid+"&pid="+photoid+"&pg="+page, "photoGallery"+userid+""+galleryid, 620, 580);
}
function listingPhoto(listingid, photoid)
{
	popup("/directory/listing.php?action=photo&photoid="+photoid+"&listingid="+listingid, "listingPhoto"+listingid+"-"+photoid, 620, 545);
}

function eventPhoto(eventid, photoid)
{
	popup("/agenda/event-photos.php?action=photo&photoid="+photoid+"&eventid="+eventid, "eventphoto"+eventid+"-"+photoid, 620, 545);
}

function popup(url, windowName, windowX, windowY, scrollbars)
{
	//windowName = windowName.replace(/-/, '_');
	windowName = stripNonAlphanumeric(windowName);
	
	posXY = centerWindowCoords(windowX, windowY);
	positionX = posXY[0];
	positionY = posXY[1];
	
	scrollbarsNumber = 0;
	if (scrollbars)
	{
		scrollbarsNumber = 1;
	}
	
	winParams = 'toolbar=0,scrollbars='+scrollbarsNumber+',location=0,statusbar=0,menubar=0,resizable=0,width='+windowX+',height='+windowY+',left='+positionX+',top='+positionY;
	//console.log("winParams: ", winParams);
	var newWindow = window.open(url, windowName, winParams);
	newWindow.focus();
}

function centerWindowCoords(width, height)
{
	var w = 480, h = 340;
	
	if (document.all || document.layers)
	{
		w = screen.availWidth;
		h = screen.availHeight;
	}
	if (screen.width && screen.height)
	{
		w = screen.width;
		h = screen.height;
	}
	
	var popW = width, popH = height;
	
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	
	return [leftPos, topPos];
}

// ================================================================================================
// View Mode Swappers

function setViewMode(targetId, newMode)
{
	if (newMode == 'G')
	{
		writeMode = 'GALLERY';
	}
	else
	{
		writeMode = 'LIST';
	}
	document.getElementById(targetId).value = String(writeMode).toLowerCase();
	
	viewModesOff(targetId);
	
	fullTargetId = targetId+'-selector-'+newMode.toLowerCase();
	viewModeOn(fullTargetId);
}

function viewModesOff(target)
{
	document.getElementById(target+'-selector-l').className = '';
	document.getElementById(target+'-selector-g').className = '';
}

function viewModeOn(fullTargetId)
{
	document.getElementById(fullTargetId).className = 'Active';
}

// ================================================================================================
// Info Swappers

function swapInfoOn(setName)
{
	document.getElementById('swap'+setName+'Link').style.display = 'none';
	document.getElementById('swap'+setName+'Info').style.display = 'block';
}
function swapInfoOff(setName)
{
	document.getElementById('swap'+setName+'Link').style.display = 'block';
	document.getElementById('swap'+setName+'Info').style.display = 'none';
}

// ================================================================================================
// Comment DHTML

function showComment(commentid)
{
	document.getElementById('commentLow'+commentid).style.display = 'none';
	document.getElementById('comment'+commentid).style.display = 'block';
}

// ================================================================================================
// Ajax for Session Update

var AjaxTouchSession = 
{
	handleSuccess: function(o)
	{
		this.processResult(o);
	},
	handleFailure: function(o)
	{
	},
	processResult: function(o)
	{
		try
		{
			var response = YAHOO.lang.JSON.parse(o.responseText);
		}
		catch (e)
		{
			// Error in JSON data!
		}
	},
	startRequest: function()
	{
		YAHOO.util.Connect.asyncRequest('GET', '/ajax/touch-session.php', touchSessionCallback);
	}
};

var touchSessionCallback = {
	success: AjaxTouchSession.handleSuccess,
	failure: AjaxTouchSession.handleFailure,
	scope: AjaxTouchSession
};

function touchSession()
{
	AjaxTouchSession.startRequest();
}


// ================================================================================================
// Ajax for Conversation Invitations

var AjaxConversationInvitations = 
{
	handleSuccess: function(o)
	{
		this.processResult(o);
	},
	handleFailure: function(o)
	{
	},
	processResult: function(o)
	{
		//console.log(o.responseText);
		
		try
		{
			var response = YAHOO.lang.JSON.parse(o.responseText);
		}
		catch (e)
		{
			// Error in JSON data!
		}
		
		if (typeof(response) != "undefined")
		{
			cInv = [];
			
			for (var z = 0; z < response.invitations.length; z++)
			{
				inv = response.invitations[z];
				
				console.log("Invitation received: ", inv.c, inv.u, inv.i);
				
				cInv.push(inv);
			}
			
			updateInvitations();
		}
	},
	startRequest: function()
	{
		YAHOO.util.Connect.asyncRequest('GET', '/ajax/conversation-invitations.php', conversationInvitationsCallback);
	}
};

var conversationInvitationsCallback = {
	success: AjaxConversationInvitations.handleSuccess,
	failure: AjaxConversationInvitations.handleFailure,
	scope: AjaxConversationInvitations
};

function checkConversationInvitations()
{
	AjaxConversationInvitations.startRequest();
}

var cInv = [];

function updateInvitations()
{
	invdiv = document.getElementById("invitations");
	
	invdiv.innerHTML = "";
	
	for (var z = 0; z < cInv.length; z++)
	{
		inv = cInv[z];
		
		var x = document.createElement("a");
		x.setAttribute("href", "#");
		x.setAttribute("onClick", "return openConversation("+inv.c+", "+inv.i+");");
		x.innerHTML = inv.u;
		
		invdiv.appendChild(x);
	}
}

function openConversation(conversationId, invitationId)
{
	userToUserConversation(conversationId, invitationId);
}

function checkConversationInvitationsTimer()
{
	checkConversationInvitations();
	setTimeout("checkConversationInvitationsTimer()", 30000);
}


var AjaxConversationStart = 
{
	handleSuccess: function(o)
	{
		this.processResult(o);
	},
	handleFailure: function(o)
	{
	},
	processResult: function(o)
	{
		console.log(o.responseText);
		
		try
		{
			var response = YAHOO.lang.JSON.parse(o.responseText);
		}
		catch (e)
		{
			// Error in JSON data!
		}
		
		if (typeof(response) != "undefined")
		{
			if (response.result && response.conversationid)
			{
				openConversation(response.conversationid);
			}
		}
	},
	startRequest: function(username)
	{
		YAHOO.util.Connect.asyncRequest('GET', '/ajax/conversation-init.php?username='+escape(username), conversationStartCallback);
	}
};

var conversationStartCallback = {
	success: AjaxConversationStart.handleSuccess,
	failure: AjaxConversationStart.handleFailure,
	scope: AjaxConversationStart
};

function startConversation(username)
{
	AjaxConversationStart.startRequest(username);
}

// ================================================================================================
// Ajax for Feautred Profiles

var AjaxFeaturedProfiles = 
{
	handleSuccess: function(o)
	{
		// o.responseText
		// o.responseXML
		//console.log(o.responseText);
		this.processResult(o);
	},
	handleFailure: function(o)
	{
		// o.responseText
		// o.responseXML
	},
	processResult: function(o)
	{
		//console.log("prefix=", this.prefix);
		
		try
		{
			var fpdata = YAHOO.lang.JSON.parse(o.responseText);
		}
		catch (e)
		{
			// Error in JSON data!
		}
		
		if (typeof(fpdata) == "undefined")
		{
		}
		else
		{
			//console.log(fpdata,1);
			
			featuredProfilesHTML = fpdata.html;
			
			document.getElementById('fpcontent').innerHTML = featuredProfilesHTML;
		}
	},
	startRequest: function(countryId)
	{
		YAHOO.util.Connect.asyncRequest('GET', '/ajax/featured-profiles.php?cid='+countryId, featuredProfilesCallback);
	}
};

var featuredProfilesCallback = {
	success: AjaxFeaturedProfiles.handleSuccess,
	failure: AjaxFeaturedProfiles.handleFailure,
	scope: AjaxFeaturedProfiles
};

function featuredProfiles()
{
	if (document.getElementById("fpcc"))
	{
		countryId = document.getElementById("fpcc").value;
		AjaxFeaturedProfiles.startRequest(countryId);
	}
}

// ================================================================================================
// Ajax for User Console

var AjaxUserConsole = 
{
	handleSuccess: function(o)
	{
		// o.responseText
		// o.responseXML
		//console.log(o.responseText);
		this.processResult(o);
	},
	handleFailure: function(o)
	{
		// o.responseText
		// o.responseXML
	},
	processResult: function(o)
	{
		//console.log("prefix=", this.prefix);
		
		try
		{
			var consoledata = YAHOO.lang.JSON.parse(o.responseText);
		}
		catch (e)
		{
			// Error in JSON data!
		}
		
		//console.log("status:", status);
		
		if (typeof(consoledata) == "undefined")
		{
		}
		else
		{
			//console.log(consoledata,1);
			
			// v1
			emHearts     = document.getElementById('numHearts');
			emMessages   = document.getElementById('numMessages');
			emMessagesLg = document.getElementById('numMessagesLarge');
			emAlerts     = document.getElementById('numAlerts');
			emRequests   = document.getElementById('numRequests');
			emFriends    = document.getElementById('numFriends');
			emTracks     = document.getElementById('numTracks');
			
			// v2
			numHearts       = document.getElementById('numhrt');
			numMessages     = document.getElementById('nummsg');
			numMessagesI    = document.getElementById('nummsginb');
			numAlerts       = document.getElementById('nummsglrt');
			numMessagesRoot = document.getElementById('nummsg');
			numOnlineNow    = document.getElementById('numnow');
			numRequests     = document.getElementById('numreq');
			numRequestsF    = document.getElementById('numreqfrd');
			numRequestsV    = document.getElementById('numreqkey');
			numRequestsP    = document.getElementById('numreqprt');
			numFriends      = document.getElementById('numnowfrd');
			numFavourites   = document.getElementById('numnowfav');
			numTracks       = document.getElementById('numusptrk');
			
			if (emHearts)
			{
				emHearts.innerHTML = consoledata.hearts;
				if (consoledata.hearts)
				{
					emHearts.style.display = 'block';
				}
				else
				{
					emHearts.style.display = 'none';
				}
			}
			
			if (emMessages)
			{
				emMessages.innerHTML = consoledata.messages;
				if (consoledata.messages)
				{
					emMessages.style.display = 'block';
				}
				else
				{
					emMessages.style.display = 'none';
				}
			}
			
			if (emMessagesLg)
			{
				emMessagesLg.innerHTML = consoledata.messages;
			}
			
			if (emAlerts)
			{
				emAlerts.innerHTML = consoledata.alerts;
				if (consoledata.alerts)
				{
					emAlerts.style.display = 'block';
				}
				else
				{
					emAlerts.style.display = 'none';
				}
			}
			
			if (emRequests)
			{
				emRequests.innerHTML = consoledata.requests;
				if (consoledata.requests)
				{
					emRequests.style.display = 'block';
				}
				else
				{
					emRequests.style.display = 'none';
				}
			}
			
			if (emFriends)
			{
				emFriends.innerHTML = consoledata.friends;
				if (consoledata.friends)
				{
					emFriends.style.display = 'block';
				}
				else
				{
					emFriends.style.display = 'none';
				}
			}
			
			if (emTracks)
			{
				emTracks.innerHTML = consoledata.tracks;
				if (consoledata.friends)
				{
					emTracks.style.display = 'block';
				}
				else
				{
					emTracks.style.display = 'none';
				}
			}
			
			// v2
			if (numHearts)
			{
				numHearts.innerHTML = consoledata.hearts;
				if (consoledata.hearts)
				{
					numHearts.style.display = 'block';
				}
				else
				{
					numHearts.style.display = 'none';
				}
			}
			
			if (numMessagesI)
			{
				numMessagesI.innerHTML = consoledata.messages;
				if (consoledata.messages)
				{
					numMessagesI.style.display = 'block';
				}
				else
				{
					numMessagesI.style.display = 'none';
				}
			}
			
			if (numMessages)
			{
				numMessages.innerHTML = consoledata.messages + consoledata.alerts;
				if (consoledata.messages + consoledata.alerts > 0)
				{
					numMessages.style.display = 'block';
				}
				else
				{
					numMessages.style.display = 'none';
				}
			}
			
			if (numAlerts)
			{
				numAlerts.innerHTML = consoledata.alerts;
				if (consoledata.alerts)
				{
					numAlerts.style.display = 'block';
				}
				else
				{
					numAlerts.style.display = 'none';
				}
			}
			
			if (numRequests)
			{
				numRequests.innerHTML = consoledata.requests;
				if (consoledata.requests)
				{
					numRequests.style.display = 'block';
				}
				else
				{
					numRequests.style.display = 'none';
				}
			}
			
			if (numRequestsF)
			{
				numRequestsF.innerHTML = consoledata.requestsf;
				if (consoledata.requestsf)
				{
					numRequestsF.style.display = 'block';
				}
				else
				{
					numRequestsF.style.display = 'none';
				}
			}
			
			if (numRequestsV)
			{
				numRequestsV.innerHTML = consoledata.requestsv;
				if (consoledata.requestsv)
				{
					numRequestsV.style.display = 'block';
				}
				else
				{
					numRequestsV.style.display = 'none';
				}
			}
			
			if (numRequestsP)
			{
				numRequestsP.innerHTML = consoledata.requestsp;
				if (consoledata.requestsp)
				{
					numRequestsP.style.display = 'block';
				}
				else
				{
					numRequestsP.style.display = 'none';
				}
			}
			
			if (numOnlineNow)
			{
				numOnlineNow.innerHTML = consoledata.friends + consoledata.favourites;
				if (consoledata.friends + consoledata.favourites)
				{
					numOnlineNow.style.display = 'block';
				}
				else
				{
					numOnlineNow.style.display = 'none';
				}
			}
			
			if (numFriends)
			{
				numFriends.innerHTML = consoledata.friends;
				if (consoledata.friends)
				{
					numFriends.style.display = 'block';
				}
				else
				{
					numFriends.style.display = 'none';
				}
			}
			
			if (numFavourites)
			{
				numFavourites.innerHTML = consoledata.favourites;
				if (consoledata.favourites)
				{
					numFavourites.style.display = 'block';
				}
				else
				{
					numFavourites.style.display = 'none';
				}
			}
			
			if (numTracks)
			{
				numTracks.innerHTML = consoledata.tracks;
				if (consoledata.friends)
				{
					numTracks.style.display = 'block';
				}
				else
				{
					numTracks.style.display = 'none';
				}
			}
		}
	},
	startRequest: function()
	{
		YAHOO.util.Connect.asyncRequest('GET', '/ajax/menu.php', userConsoleCallback);
	}
};

var userConsoleCallback = {
	success: AjaxUserConsole.handleSuccess,
	failure: AjaxUserConsole.handleFailure,
	scope: AjaxUserConsole
};

function updateUserConsole()
{
	if (typeof(userId) != "undefined" && userId > 0)
	{
		AjaxUserConsole.startRequest();
		setTimeout('updateUserConsole()', 300000);
	}
	else
	{
		//console.log("not logged in");
	}
}
if (typeof(userId) != "undefined" && userId > 0)
{
	setTimeout('updateUserConsole()', 300000);
}


/* cityguides left menu */
function gotoCityguide(url)
{
	if(url)
	{
		window.location = url;
	}
}

// ================================================================================================
// RATINGS for comments

var ratingClicked = 0;

function ratingHover(containerId, destinationId, ratingNumber)
{
	//console.log("hover", ratingNumber);
	
	if (ratingNumber == 0)
	{
		ratingNumber = ratingClicked;
	}
	
	//console.log("ratingNumber", ratingNumber);
	
	document.getElementById(containerId).className = 'Rating'+ratingNumber;
	document.getElementById(destinationId).value = ratingNumber;
	
	//console.log("ratingText.value = ", document.getElementById('ratingText').value);
}

function ratingClick(destinationId, ratingNumber)
{
	//console.log("click", destinationId, ratingNumber);
	
	ratingClicked = ratingNumber;
	document.getElementById(destinationId).value = ratingNumber;
	
	//console.log("ratingText.value = ", document.getElementById('ratingText').value);
}


// ================================================================================================
// Print

function printPage()
{
	window.print();
}

// ================================================================================================
// Show/Hide comment controls based on userid

function commentControls()
{
	if (commentOwners)
	{
		for (var commentId in commentOwners)
		{
			ownerId = commentOwners[commentId];
			
			spanId = 'commentControlSpan'+commentId;
			
			if (document.getElementById(spanId))
			{
				if (ownerId == userId || adminId > 0)
				{
					document.getElementById(spanId).style.display = 'inline';
				}
				else
				{
					document.getElementById(spanId).style.display = 'none';
				}
			}
		}
	}
}


// ================================================================================================
// Strip non-alphanumeric characters from string

function stripNonAlphanumeric(string)
{
	return string.replace(/[^a-zA-Z 0-9]+/g, '');
}

// ================================================================================================
// Cookie handling
// From: http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}