

addPreload('/images/wait.gif');

memberSearchString = '';

function findEmail() {
	f = document.search_form;
	if (eCheck(f.findEmail.value)) {
		document.getElementById('friendFinder').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
		memberSearchString = 'findEmail='+escape(f.findEmail.value);
		ajaxCall('/community/member-search.inc.php?'+memberSearchString,'friendFinder');
	} else {
		alert("Please enter a valid e-mail address.");
		f.findEmail.focus();
	}
}

function findScreenName() {
	f = document.search_form;
	document.getElementById('friendFinder').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	memberSearchString = 'findScreenName='+escape(f.findScreenName.value);
	ajaxCall('/community/member-search.inc.php?'+memberSearchString,'friendFinder');
}

function findInterest() {
	f = document.search_form;
	document.getElementById('friendFinder').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	memberSearchString = 'c='+escape(f.c.options[f.c.selectedIndex].value)+"&q="+escape(f.q.value);
	ajaxCall('/community/member-search.inc.php?'+memberSearchString,'friendFinder');
}

browsePageNum = 1;
function browseMembers(pageNum) {
	browsePageNum = pageNum;
	document.getElementById('friendFinder').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	ajaxCall('/community/member-search.inc.php?page='+browsePageNum+'&'+memberSearchString,'friendFinder');
}
function refreshFriends() {
	if (document.getElementById('friendFinder')) {
		browseMembers(browsePageNum);
	}
	refreshFriendRequests();
	refreshMessages();
}

requestPageNum = 1;
function browseRequests(pageNum) {
	requestPageNum = pageNum;
	document.getElementById('friendRequests').innerHTML = "";
	ajaxCall('/community/member-search.inc.php?page='+requestPageNum+'&requests=1','friendRequests');
}
function refreshFriendRequests() {
	if (document.getElementById('friendRequests')) {
		browseRequests(requestPageNum);
	}
}


function submitFriendRequest() {
	f = document.friend_form;
	friendId = f.friend.value;
	params = "message="+escape(f.message.value)+"&submitRequest=1";
	document.getElementById('dialogContent').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	ajaxCall('/community/dialog_friendAdd.inc.php?friend='+friendId,'dialogContent','',params);
}

function submitRemovalRequest() {
	f = document.friend_form;
	friendId = f.friend.value;
	params = "confirmRemoval=1";
	document.getElementById('dialogContent').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	ajaxCall('/community/dialog_friendRemove.inc.php?friend='+friendId,'dialogContent','',params);
}
function submitMessage() {
	f = document.msg_form;
	if (f.message.value) {
		friendId = f.friend.value;
		noRefresh = (f.noRefresh) ? f.noRefresh.value : '';
		params = "message="+escape(f.message.value)+"&private="+((f.private.checked)?'on':'')+"&submitRequest=1";
		document.getElementById('dialogContent').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
		ajaxCall('/community/dialog_friendMessage.inc.php?friend='+friendId+'&noRefresh='+noRefresh,'dialogContent','',params);
	} else {
		alert('Please enter a message.');
		f.message.focus();
	}
}
function refreshMessages() {
	if (document.getElementById('my_messages')) {
		messagePageNum = 1;
		browseMessages();
	}
}
messagePageNum = 1;
messageOwnerId = 0;
function browseMessages(pageNum) {
	if (pageNum) messagePageNum = pageNum;
	if (messageOwnerId) {
		msgEl = 'my_messages';
		if (messagePageNum>1) msgEl += messagePageNum;
		document.getElementById(msgEl).innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
		ajaxCall('/community/readMessages.inc.php?page='+messagePageNum+'&owner='+messageOwnerId,msgEl);
	}
}

imgId = 0;
function loadPhotoComments() {
	if (document.getElementById('photo_comments')) {
		document.getElementById('photo_comments').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
		ajaxCall('/community/displayPhotoComments.inc.php?img='+imgId,'photo_comments');
	}
}


function submitCommentDeletionRequest() {
	f = document.commentDeletion_form;
	commentId = f.comment.value;
	params = "confirmRemoval=1";
	document.getElementById('dialogContent').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	ajaxCall('/community/dialog_deleteComment.inc.php?comment='+commentId,'dialogContent','',params);
}
function refreshComments() {
	refreshMessages();
	loadPhotoComments();
}





function submitPhotoDeletionRequest() {
	f = document.photoDeletion_form;
	photoId = f.imgId.value;
	params = "confirmRemoval=1";
	document.getElementById('dialogContent').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	ajaxCall('/community/dialog_deletePhoto.inc.php?img='+photoId,'dialogContent','',params);
}


///////////// INVITE ///////////////

function sendInvitation() {
	f = document.invite_form;
	params = "process=1&message="+escape(f.message.value);
	eConfirm = 0;
	for(i=1;i<=20;i++) {
		if (f['friendName'+i] && f['friendName'+i].value) params += "&friendName"+i+"="+escape(f['friendName'+i].value);
		if (f['friendEmail'+i] && f['friendEmail'+i].value) {
			if (!eCheck(f['friendEmail'+i].value)) {
				alert("Please enter a valid email address.");
				f['friendEmail'+i].focus();
				return false;
			}
			eConfirm++;
			params += "&friendEmail"+i+"="+escape(f['friendEmail'+i].value);
		}
	}
	if (!eConfirm) {
		alert("Please enter at least one e-mail address.");
		return false;
	}
	if (!f.message.value) {
		alert("Please enter a personal invitation message.");
		return false;
	}
	document.getElementById('invitationForm').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	ajaxCall('/community/invitation.inc.php','invitationForm','',params);
}
function resetInvitation() {
	document.getElementById('invitationForm').innerHTML = "<div align='center'><img src='/images/wait.gif' class='waiting' /></div>";
	ajaxCall('/community/invitation.inc.php','invitationForm');
}






///////////// PROMPTS //////////////

function friendAdd(friendId) {
	showDialog("dialog_friendAdd.inc.php?friend="+friendId);
}

function friendRemove(friendId) {
	showDialog("dialog_friendRemove.inc.php?friend="+friendId);
}

function friendMessage(friendId,noRefresh) {
	if (!noRefresh) noRefresh = '';
	showDialog("dialog_friendMessage.inc.php?friend="+friendId+"&noRefresh="+noRefresh);
}

function deleteMsg(msgId) {
	showDialog("dialog_deleteComment.inc.php?comment="+msgId);
}

function deletePhoto(imgId) {
	showDialog("dialog_deletePhoto.inc.php?img="+imgId);
}

function showDialog(dialogUrl) {
	document.getElementById('dialog').style.display = 'block';
	document.getElementById('dialogContent').innerHTML = "<div style='padding:10px;'>Loading...</div>";
	ajaxCall(dialogUrl,'dialogContent');
}

function cancelDialog() {
	document.getElementById('dialog').style.display = 'none';
	document.getElementById('dialogContent').innerHTML = "&nbsp;";
}


function hideThread(threadId) {
	showDialog("dialog_hidethread.inc.php?thread="+threadId);
}

function unhideThread(threadId) {
	showDialog("dialog_unhidethread.inc.php?thread="+threadId);
}





/////////////// HIDDEN FORUM THREADS /////////////////

function showHiddenThreads() {
	// gather DIVs
	divs = document.getElementsByTagName('DIV');
	for(i=0;i<divs.length;i++) {
		divEl = divs[i];
		if (divEl.className=='hiddenThread') {
			divEl.style.display = 'block';
		}
	}
	document.getElementById('hiddenThreads').style.display = 'none';
}

function showHiddenThreadsOptions(nr) {
	document.getElementById('numHidden').innerHTML = nr;
	document.getElementById('hiddenThreads').style.display = 'block';
}



////////////// toggle orange bars ////////////////

addPreload('/images/up.gif');
function toggleBar(barId) {
	bEl = document.getElementById(barId);
	iEl = document.getElementById(barId+'_toggle');
	if (bEl.style.display=='none') {
		bEl.style.display = 'block';
		iEl.src = '/images/down.gif';
	} else {
		bEl.style.display = 'none';
		iEl.src = '/images/up.gif';
	}
}





///////////////// AWARDS ///////////////////

function initAwards() {
	if (document.getElementById('awards')) {
		addPreload('/images/award-left.gif');
		addPreload('/images/award-right.gif');
		awardEls = document.getElementById('awards').getElementsByTagName('A');
		for(aw=0;aw<awardEls.length;aw++) {
			awardEl = awardEls[aw];
			awardEl.onmouseover = function() {
				awardImgs = this.getElementsByTagName('IMG');
				awardImg = awardImgs[0];
				awardTitle = awardImg.alt;
				titleEl = document.getElementById('award_title');
				titleEl.innerHTML = "<img src='/images/award-left.gif' alt='&gt;&gt;&gt;' width='19' height='9' />"+awardTitle+"<img src='/images/award-right.gif' alt='&lt;&lt;&lt;' width='19' height='9' />";
			}
			awardEl.onmouseout = function() {
				titleEl = document.getElementById('award_title');
				titleEl.innerHTML = "&nbsp;";
			}
		}
	}
}
loadMeUp += "initAwards();";






///////////////// PHOTO DISPLAY ///////////////////

function initPhotoDisplay() {
	// find imageOutline links
	tableEls = document.getElementsByTagName('TABLE');
	for (i=0;i<tableEls.length;i++) {
		tEl = tableEls[i];
		if (tEl.className=='imageOutline') {
			aEls = tEl.getElementsByTagName('A');
			for(j=0;j<aEls.length;j++) {
				aEl = aEls[j];
				aEl.onmouseover = function() {
					pEl = this.parentNode;
					while (pEl != document && pEl.className != 'imageOutline') pEl = pEl.parentNode;
					pEl.style.borderColor = '#666';
				}
				aEl.onmouseout = function() {
					pEl = this.parentNode;
					while (pEl != document && pEl.className != 'imageOutline') pEl = pEl.parentNode;
					pEl.style.borderColor = '';
				}
			}
		}
	}
}
loadMeUp += "initPhotoDisplay();";





