/*
 *  Sex4HotMen
 * 	File modified for Cold Day In Hell Productions server.
 *  All instances of /userplane/ changed to userplane/
 *  ----------------------------------------------------------------------------------------------
 *	Avram Grossman / E-Novative, Inc.
 *  ----------------------------------------------------------------------------------------------
 *	It is of critical importance that this file is referenced inside the <body> tag of every page 
 * 	on your site.  For example: 
 *
 *	<body>
 *	<script src="userplane/functions.js" type="text/javascript" language="javascript"></script>
 *	
 *	!!! WE HIGHLY RECOMMEND YOU LEAVE up_bDoPresence TO true AND TO IMPLEMENT THE CODE IN ALL asp 
 *	PAGES IN THIS FOLDER !!!
 *
 *	Set up_bDoPresence to false if you have your own presence detection and will check for pending 
 *  Webmessenger windows and call up_launchWM on your own.  If so, you will need to call up_launchWM for 
 *  every pending WM window every time the user changes pages.  Also, you will need to implement the logic 
 *	in the wmWindowOpened.asp page to let you know when requests have been denied and also when windows 
 *	have successfully popped up
 */
var up_bDoPresence = true; 
/* 
 *	If you have up_bDoPresence set to true, this is how often (in seconds) we will connect to your 
 *	server via wmLauncher.asp or win_ie_pd.asp
 */
var up_iCheckSeconds = 10; 

// PLEASE DO NOT CHANGE ANY CODE BELOW THIS LINE



function up_launchWM( userID, destinationUserID, destinationName )
{
	up_localUserID = userID;
	
	var popupWindowTest = null;
	popupWindowTest = window.open( "http://www.atomicmen.com/userplane/wm.asp?strDestinationUserID=" + destinationUserID, "wmWindow_" + up_replaceAlpha(userID) + "_" + up_replaceAlpha(destinationUserID), "width=468,height=528,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0" );
	
	if( popupWindowTest == null )
	{
		up_showWMNotify( userID, destinationUserID, destinationName );
	}
	else
	{
		up_clearWMNotify( destinationUserID, false ); 
	}
}


function up_launchWMM( userID, destinationUserID, destinationName )
{
	up_localUserID = userID;
	
	var popupWindowTest = null;
	popupWindowTest = window.open( "http://www.atomicmen.com/userplane/wm.asp?strDestinationUserID=" + destinationUserID, "wmWindow_" + up_replaceAlpha(userID) + "_" + up_replaceAlpha(destinationUserID), "width=468,height=528,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0" );
	if( popupWindowTest == null )
	{
		up_showWMNotify( userID, destinationUserID, destinationName );
	}
	else
	{
		up_clearWMNotify( destinationUserID, false ); 
	}
}

function up_showWMNotify( userID, destinationUserID, destinationName )
{
	up_localUserID = userID;
	
	var bAdd = true;
	for( var i = 0 ; i < up_launchArray.length ; i++ )
	{
		if( up_launchArray[i].destID == destinationUserID )
		{
			if( destinationName != undefined )
			{
				up_launchArray[i].destName = "<strong>" + destinationName + "</strong>";
			}
			bAdd = false;
		}
	}
	
	destinationName = destinationName == undefined ? "A website member" : "<strong>" + destinationName + "</strong>";
	
	if( bAdd )
	{
		var userObj = new Object();
		userObj.destID = destinationUserID;
		userObj.destName = destinationName;
		up_launchArray.push( userObj );
	}
	
	up_showNotification();
}

function up_clearWMNotify( clearDestID, bForceClear )
{
	var tempArray = up_launchArray;
	up_launchArray = new Array();
	
	var bRemoved = false;
	
	while( tempArray.length > 0 )
	{
		var userObj = tempArray.pop();
		
		if( userObj.destID != clearDestID )
		{
			up_launchArray.push( userObj );
		}
		else
		{
			bRemoved = true;
		}
	}
	
	if( bRemoved || !bForceClear )
	{
		frames['up_wmLauncher'].location.href = "http://www.atomicmen.com/userplane/wmWindowOpened.asp?destinationUserID=" + clearDestID + "&doPresence=" + ( up_bDoPresence && !up_is_win_ie ? "true" : "false" ) + "&forceClear=" + ( bForceClear ? "true" : "false" ) + "&iRefreshInterval=" + up_iCheckSeconds + "&refresh=" + Math.floor( Math.random() * 100000000000 );
	}
	
	up_showNotification();
}

function up_showNotification()
{
	var elem = document.getElementById( "up_wmNotifications" );
	
	if( up_launchArray.length > 0 )
	{
		if( up_displayedNotificationID != up_launchArray[0].destID )
		{
	
			elem.innerHTML = '<div>' + ( up_is_win_ie ? '' : '<table width="300"  cellpadding="0" cellspacing="0"><tr><td align="center">' ) + '<table bgcolor="#ffffff" border="0" cellpadding="2" cellspacing="3" width="300"><tr><td nowrap align="center" class="AMHeadText2_featured"><strong>Incoming IM Message</strong></td></tr><tr><td align="center" class="home_td">' + up_launchArray[0].destName + ' wants to IM you.<br>Would you like to accept? <div class="td_spacer"></div><a href="" onClick="javascript: ' + ( up_is_win_ie | up_is_safari ? 'up_launchWM' : 'up_launchWMM') + ' ( \'' + up_localUserID + '\', \'' + up_launchArray[0].destID + '\' ); return false;" onMouseUp="document.getElementById(\'up_wmNotifications\').style.display=\'none\'">Yes, Please</a> &nbsp; &nbsp; | &nbsp; &nbsp; <a href="" onClick="javascript: up_clearWMNotify( \'' + up_launchArray[0].destID + '\', true ); return false;" onMouseUp="document.getElementById(\'up_wmNotifications\').style.display=\'none\'" >No, Thanks</a></td></tr></table>' + ( up_is_win_ie ? '' : '</td></tr></table>' ) + '</div>';
			up_displayedNotificationID = up_launchArray[0].destID;
			up_animate( 5 );
		}
	}
	else
	{
		up_displayedNotificationID = "";
		up_animate( -50 );
			}
}

function up_animate( iWhereTo )
{
	if( up_iDivCurrentX != iWhereTo )
	{
		up_iDivCurrentX += iWhereTo < up_iDivCurrentX ? 0 : 0;
		
		var elem = document.getElementById( "up_wmNotifications" );
		elem.style.top = up_iDivCurrentX;
		
		setTimeout( "up_animate(" + iWhereTo + ")", 1500  );
		
	}
}

function up_replaceAlpha( strIn )
{
	var strOut = "";
	for( var i = 0 ; i < strIn.length ; i++ )
	{
		var cChar = strIn.charAt(i);
		if( ( cChar >= 'A' && cChar <= 'Z' )
			|| ( cChar >= 'a' && cChar <= 'z' )
			|| ( cChar >= '0' && cChar <= '9' ) )
		{
			strOut += cChar;
		}
		else
		{
			strOut += "_";
		}
	}
	
	return strOut;
}

function up_checkWM()
{
	if( up_is_win_ie )
	{
		up_wmCheckImage = new Image();
		up_wmCheckImage.onLoad = up_onImageLoad();
		up_wmCheckImage.src = "http://www.atomicmen.com/userplane/win_ie_pd.asp?refresh=" + Math.floor( Math.random() * 100000000000 );
	}
	else
	{
		frames['up_wmLauncher'].location.href = "http://www.atomicmen.com/userplane/wmLauncher.asp?iRefreshInterval=" + up_iCheckSeconds + "&refresh=" + Math.floor( Math.random() * 100000000000 );
	}
}

function up_onImageLoad()
{
	clearTimeout( up_timeoutID );
	
	if (!up_wmCheckImage.complete)
	{
		up_timeoutID = setTimeout("up_onImageLoad()", 250);
	}
	else
	{
		if( up_wmCheckImage.height == 2 )
		{
			frames['up_wmLauncher'].location.href = "http://www.atomicmen.com/userplane/wmLauncher.asp?iRefreshInterval=0&refresh=" + Math.floor( Math.random() * 100000000000 );
		}
		else
		{
			//alert( "Nothing to launch" );
		}
		
		up_timeoutID = setTimeout("up_checkWM()", 10000 * up_iCheckSeconds);
	}
}
//<td 	bgcolor="#515151"
document.write( '<style type="text/css">' );
document.write( '.up_mbox { background-color: #CECDCD; border: 0; margin: 2px 0 6px 0; padding: 10px; }' );
document.write( '.up_mboxgut { font: #333333 11pt Verdana, Geneva, Arial, Helvetica, Helve, Sans-serif; margin: 0; padding: 0 10px 0 10px; word-wrap: break-word; }' );
document.write( '</style>' );
document.write( '<iframe name="up_wmLauncher" id="up_wmLauncher" style="width:0px; height:0px; border: 0px" src=""></iframe>' );
document.write( '<div id="up_wmNotifications" style="position:absolute; width:350px; z-index:9; left: 200px; top: 71px;"></div>' );
var up_iDivCurrentX =  71;

var up_launchArray = new Array();
var up_localUserID = "";
var up_displayedNotificationID = "";

var up_wmCheckImage = null;
var up_timeoutID = null;

// determine if is Windows IE (up_is_win_ie)
var up_agt 			= navigator.userAgent.toLowerCase();
var up_appVer 		= navigator.appVersion.toLowerCase();
var up_is_mac 		= up_agt.indexOf('mac') != -1;
var up_is_safari 	= up_agt.indexOf('safari') != -1 && up_is_mac;
var up_is_khtml  	= up_is_safari || up_agt.indexOf('konqueror') != -1;
var up_is_ie  	 	= up_appVer.indexOf('msie') != -1 && up_agt.indexOf("opera") == -1 && !up_is_khtml;
var up_is_win   	= up_is_mac ? false : (up_agt.indexOf("win") != -1 || up_agt.indexOf("16bit") != -1);
var up_is_win_ie 	= up_is_win && up_is_ie; 

if( up_bDoPresence )
{
	up_checkWM();
}
