// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.
// ********************************
// application-specific functions *
// ********************************

// store variables to control where the popup will appear relative to the cursor position
// positive numbers are below and to the right of the cursor, negative numbers are above and to the left
var xOffset = 30;
var yOffset = -5;

function showPopup (targetObjectId, eventObj, strUserID, settingNeedHelp, settingBuddyList, settingContactMe, imageServer) {
    if(eventObj) {
	// hide any currently-visible popups
	hideCurrentPopup();
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	// move popup div to current cursor position 
	// (add scrollTop to account for scrolling for IE)
	var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
	    // if we successfully showed the popup
	    // store its Id on a globally-accessible object

		var strLabel = 'Member Buddy Settings';
		if (targetObjectId == "ForumPopup") {
			strLabel = settingNeedHelp;
		}
		
		
		var divString = '<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="buddy settings" style="margin: 0; background-color: #0066cc;">' +
  			'<tr>' +
    			'<td>' +
					'<p style="margin: 0; background-color: #0066cc; color: #ffffff; padding: 5px; font-size: 12px"><strong>' + strLabel + '</strong></p></td>' +
    				'<td><a class=closeLink href="#" onclick="hideCurrentPopup(); return false;"><img src="' + imageServer + '/images/q2001/buddies/close_box.gif" alt="close" width="10" height="10" border="0"></a>' + 
				'</td>' +
  			'</tr>' +
		'</table>' + 
		'<p style="margin: 0px; padding: 5px; font-size: 10px;">';	
		
		if (targetObjectId == "ForumPopup") {
		
			divString += settingBuddyList;
		
		} else if (targetObjectId == "BuddyOptionsPremium") {
			
			
			if (settingNeedHelp) {	
				divString += '<img src="' + imageServer + '/images/q2001/buddies/icon_i_need_help.gif" alt="I need help" width="21" height="18" vspace="2" border="0" align="absmiddle">&nbsp;<span style="color: #0066cc"><strong><a href="/community/qmail/delux/qn_newmessage.jtml?id=' + strUserID + '"  style="color: #0066cc">I need help</a></strong></span><br>';
			}
			
			if (settingBuddyList) {				
				divString += '<img src="' + imageServer + '/images/q2001/buddies/icon_make_list_public_lrg.gif" alt="View my buddy list" width="18" height="18" hspace="1" vspace="2" border="0" align="absmiddle">&nbsp;<strong><a href="/community/profile/qn_profilepeople_other.jtml?id=' + strUserID + '" style="color: #0066cc">View my buddy list </a></strong><br>';
			}
			
			if (settingContactMe) {
				divString += '<img src="' + imageServer + '/images/q2001/buddies/icon_okay_to_contact.gif" alt="Need quit support" width="19" height="11" hspace="1" vspace="2" border="0" align="absmiddle">&nbsp;<strong>Need quit support?</strong> <strong><a href="/community/qmail/delux/qn_newmessage.jtml?id=' + strUserID + '" style="color: #0066cc">Contact me </a></strong>';
			}			
			
	    		
	    } else {
			divString += '<a href="/qstore/b_info_registration.jtml?q_feature=73&return=/community/yellowpages/qn_people.jtml"><strong>click here</strong></a> for more information';			 
		}
		
		divString += '</p>';
		document.getElementById(targetObjectId).innerHTML = divString;
		window.currentlyVisiblePopup = targetObjectId;
	    return true;
	} else {
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
} // showPopup

function hideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
} // hideCurrentPopup



// ***********************
// hacks and workarounds *
// ***********************

// initialize hacks whenever the page loads
window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
document.onclick = hideCurrentPopup;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

