/*************************************************************************
Copyright (c) 2006-2010 by TangoWire Corporation. All Rights Reserved.

You DO NOT have license, verbal, written, or implied, to copy, transfer,
or utilize this source code in any commercial, freeware, shareware, or
any other type of distributed application or documentation.
*************************************************************************/


function gotoTangos() {
		if (activeHandle != null) {
			window.location.href = '/Member/Tango/' + activeHandle;
		}
}

function saveSearch(formID) {
	var searchNameInput = eval('document.SavedSearchForm' + formID + '.SearchName');
	if (searchNameInput) {
		var noName = true;
		if (searchNameInput.value != null) {
			var charCount = 0;
			for (var i = 0; i < searchNameInput.value.length; i++) {
				if (searchNameInput.value.charAt(i) != ' ') {
					charCount++;
					if (charCount >= 3) {
						noName = false;
						break;
					}
				}
			}
		}
		if (noName) {
			tmb_showPanel_TangoAlertPanel('You must supply a Name for your search!  <BR/>(At least three characters please)', 'Alert!');
			searchNameInput.focus();
		} else {
			var form = eval('document.SavedSearchForm' + formID);
			if (form) form.submit();
		}
	}
}



function showForward(mID) {
	var forwardPanel = document.getElementById('ForwardPanel');
	var bgPanel = document.getElementById('ForwardPanelBG');
	if (forwardPanel && bgPanel) {
		if (mID != null) {
			var midDiv = document.getElementById('RMID');
			if (midDiv) midDiv.value = mID;
		}
		sizePanel('ForwardPanel', null, null);
		var clientHeight = GetClientAreaHeight();
		var clientWidth = GetClientAreaWidth();
		var top = Math.max(Math.round((clientHeight - parseInt(forwardPanel.style.height))/2) + document.body.scrollTop,document.body.scrollTop);
		var left = Math.max(Math.round((clientWidth - parseInt(forwardPanel.style.width))/2) + document.body.scrollLeft,document.body.scrollLeft);
		forwardPanel.style.top = top + 'px';
		forwardPanel.style.left = left + 'px';
		bgPanel.style.width = Math.max(document.body.scrollWidth, clientWidth) +'px';
		bgPanel.style.height = Math.max(document.body.scrollHeight, clientHeight) + 'px';
		bgPanel.style.display = 'block';
		var toEmail = document.getElementById('ToEmail');
		if (toEmail) toEmail.focus();
	}
}

	var activeHandle = null;

function displayProfile(obj, e, thumbID, handle, gender, ageSunSign, seeking, cityLocation, flagURI, hasTangos, showPremium) {
		var panel = document.getElementById('GalleryProfilePanel');
		activeHandle = handle;
		if (panel == null) panel = document.getElementById('GalleryProfilePanelInline');
		if (panel != null) {
			document.getElementById('GalleryProfileHandleTD').innerHTML = '<A HREF="/Browse/Profile/' + handle + '" CLASS="Link2">' + handle + '</A>';
			document.getElementById('GalleryProfileGender').innerHTML = gender;
			document.getElementById('GalleryProfileAgeSunSign').innerHTML = ageSunSign;
			document.getElementById('GalleryProfileSeeking').innerHTML = seeking;
			document.getElementById('GalleryProfileCityLocation').innerHTML = cityLocation;
			document.getElementById('GalleryProfileFlag').src = flagURI;
			var premiumRow = document.getElementById('GalleryProfilePremium');
			if (premiumRow) {
				if (showPremium) {
					premiumRow.style.display = '';
				} else {
					premiumRow.style.display = 'none';
				}
			}
			var profileLinkRow = document.getElementById('GalleryProfileLinkRow');
			if (profileLinkRow) {
				if (hasTangos) {
					profileLinkRow.style.display = '';
				} else {
					profileLinkRow.style.display = 'none';
				}
			}
			obj.abbr = 'PL' + handle;
			panel.abbr = 'PL' + handle;
			var width = 200;
			var thumbTable = document.getElementById('GalleryThumbnailTable');
			if (thumbID != null) {
				thumbTable.style.display = 'block';
				thumbTable.style.backgroundPosition = '3px 3px';
				document.getElementById('GalleryThumbnailTD').innerHTML = '<A HREF="/Browse/Profile/' + handle + '" CLASS="Link2"><img src="/Images/Cached/Photos/' + thumbID + '.jpg"></A>';
				width += 67;
			} else {
				thumbTable.style.display = 'none';
			}
			panel.style.width = width + 'px';
			if (e != null) {
				var posAboveBelow = false;
				var posX = e.clientX + document.body.scrollLeft + 4;
				var posY = e.clientY + document.body.scrollTop - 22;
				if ((posX + parseInt(panel.style.width)) > document.body.clientWidth) {
					posX = e.clientX + document.body.scrollLeft - parseInt(panel.style.width) - 20;
				}
				if (posX < document.body.scrollLeft) {
					posX = document.body.scrollLeft;
					posAboveBelow = true;
				}
				if (!posAboveBelow) {
					if ((e.clientY + 145) > document.body.clientHeight) {
						posY = document.body.clientHeight - 145;
					}
					if (posY < document.body.scrollTop) {
						posY = document.body.scrollTop;
					}
				} else {
					if (e.clientY < 155 ) {
						posY = e.clientY + document.body.scrollTop + 20;
					} else {
						posY = e.clientY + document.body.scrollTop - 155;
					}
				}
				panel.style.left = posX + 'px';
				panel.style.top  = posY + 'px';
			}
			panel.style.display = 'block';
		}
}

function hideProfile() {
		var panel = document.getElementById('GalleryProfilePanel');
		if (panel != null) {
			panel.style.display = 'none';
		}
}

document.onmousemove = hdlPMouseMove;
function hdlPMouseMove(e) {
		var infoPanel = document.getElementById('GalleryProfilePanel');
		if ((infoPanel) && (infoPanel.style.display == 'block')) {
			var te = getTE(e);
			if (te.ref == null || te.ref != 'PL' + activeHandle) {
				hideProfile();
			}
		}
}
function m2mTangos(e) {
		if (activeHandle != null) {
			window.location.href = '/Member/Tango/' + activeHandle;
			e.cancelBubble = true;
		}
}