//this variable is overriding userplane's variable in their f.js file.  
//It makes the IM notification always show up, whether pop-ups are blocked or not.
up_alwaysNotify=true;

//Launch the Instant Message window 
function launchIC_old( memberID, destinationMemberID, memberType, isReply, isPlat)
{
		var replyFlag = '0'
		replyFlag = isReply
		var allcookies = document.cookie;
		allcookies = unescape(allcookies);
		var pos = allcookies.indexOf("UserType=");
		if(pos != -1 && memberID != 0) {
			var start = pos + 9; 
			var end = start + 1;
			var value = allcookies.substring(start, end);
			if ((memberType == 1) || (isPlat == 1)) {
				window.open( "ic.aspx?strDestinationMemberID=" + destinationMemberID + "&rf=" + replyFlag + "&pf=" + isPlat, "ICWindow_" + memberID + "_" + destinationMemberID, "width=360,height=420,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0" );
			} else if (replyFlag != '0') {
				window.open( "ic.aspx?strDestinationMemberID=" + destinationMemberID + "&rf=" + replyFlag, "ICWindow_" + memberID + "_" + destinationMemberID, "width=360,height=420,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0" );
			} else {
				//window.location.href = "locked.aspx?pagename=P&amp;WT=SIM";
				window.location.href = "membership.aspx?pagename=sub_im&amp;to_im=" + destinationMemberID;
				//alert("basic logged in? is the person Platinum?" + isPlat);
			}
		}
		else {
//		alert('There is a problem with your cookies, check your browser to make sure cookies are turned on')
		//window.location.href = "locked.aspx?pagename=P&amp;WT=SIM";
		//window.location.href = "membership.aspx?pagename=sub_im&amp;to_im=" + destinationMemberID;
		window.location.href = "personal-ads-membership.aspx?sim=1&pid=" + destinationMemberID;
		//alert("not logged in? is the person Platinum?" + isPlat);
		}
}

//Launch the Instant Message window 
function launchIC( userID, destinationUserID, memberType, isReply, isPlat)
{
	//alert(userID + ' ' + destinationUserID + ' ' + memberType + ' ' + isReply + ' ' + isPlat);
	up_localUserID = userID;
	var replyFlag = '0'
	replyFlag = isReply
	var allcookies = document.cookie;
	allcookies = unescape(allcookies);
	var pos = allcookies.indexOf("UserType=");
	if(pos != -1 && userID != 0) 
	{
		var start = pos + 9; 
		var end = start + 1;
		var value = allcookies.substring(start, end);
		if ((memberType == 1) || (isPlat == 1)) 
		{
			window.open( "http://" + document.domain + "/up/wm.aspx?strDestinationUserID=" + destinationUserID + "&rf=" + replyFlag + "&pf=" + isPlat, "WMWindow_" + up_replaceAlpha(userID) + "_" + destinationUserID, "width=360,height=420,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
		} 
		else if (replyFlag != '0') 
		{
			window.open( "http://" + document.domain + "/up/wm.aspx?strDestinationUserID=" + destinationUserID + "&rf=" + replyFlag, "WMWindow_" + up_replaceAlpha(userID) + "_" + destinationUserID, "width=360,height=420,toolbar=1,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
		} 
		else 
		{
			window.location.href = "http://" + document.domain + "/membership.aspx?pagename=sub_im&to_im=" + destinationUserID;
		}
	}
	else 
	{
		window.location.href = "http://" + document.domain + "/personal-ads-membership.aspx?sim=1&pid=" + destinationUserID;
	}
}

function up_launchWebchat()
{
	window.open("http://" + document.domain + "/dating.aspx?pagename=E5","CUPID_WEBCHAT","width=700,height=500,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=1,resizable=1");
}

function up_launchWM( userID, destinationUserID, destinationName )
{
	up_localUserID = userID;

	var popupWindowTest = window.open( "http://" + document.domain + "/up/wm.aspx?strDestinationUserID=" + destinationUserID, "WMWindow_" + up_replaceAlpha(userID) + "_" + up_replaceAlpha(destinationUserID), "width=360,height=420,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );

	if( popupWindowTest == null )
	{
		alert( "Your popup blocker stopped an IM window from opening" );
	}
}
 
function up_launchUL()
{	
	window.open( "http://" + document.domain + "/up/ul.aspx" , "ULWindow" , "width=200,height=750,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}
 
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 openProfileInIframe(userID)
{
	if( typeof( self.opener.parent.iframe ) != 'undefined' )
	{
		//open the profile in the window that opened the IM
		self.opener.parent.iframe.location.href = "http://" + document.domain + "/_profile_myview.aspx?id_member=" + userID;
		return true;
	}
	else
		return false;
}

function openProfileInPopup(userID)
{
	var profilePopup = window.open("http://" + document.domain + "/_profile_myview.aspx?id_member=" + userID + "&pp=1","profilepopup","width=525,height=500,scrollbars=yes")
	if(profilePopup == null)
		return false;
	else
		return true;
}

function openProfile(userID)
{
	if (openProfileInIframe(userID) == false)
		openProfileInPopup(userID);
}

function up_csEvent( strEvent, strParameter1, strParameter2, strUserID )
{

	if( strEvent == "InstantCommunicator.StartConversation" )
	{
		var strTargetUserID = strParameter1;
		var bServer = strParameter2;
		// open up an InstantCommunicator window.  For example:
		up_launchWM( strUserID, strTargetUserID );
	}
	else if( strEvent == "User.ViewProfile" )
	{		
		openProfile(strParameter1);
	}
	else if( strEvent == "User.Block" )
	{
		var strBlockedUserID = strParameter1;
		var bBlocked = strParameter2;
	}
	else if( strEvent == "User.AddFriend" )
	{
		addFriend(strParameter2);
	}
	else if( strEvent == "Chat.Help" )
	{
		window.open("http://" + document.domain + "/popups/webchat_help.htm","chathelp","width=500,height=400,scrollbars=1,toolbar=0,directories=0,menubar=0,status=0,location=0,resizable=1");
	}
	else if( strEvent == "User.NoTextEntry" )
	{
	}
	else if( strEvent == "Connection.Success" )
	{
	}
	else if( strEvent == "Connection.Failure" )
	{
		if( strParameter1 == "Session.Timeout" )
		{
			//handle timeout here, both inactivity and session timeouts
		}
		if( strParameter1 == "User.Banned" )
		{
			//handle ban event here
		}
	}
	else if( strEvent == "Custom.UserList.Logout" )
	{
		window.close();
	}			
}

function getLocaleData()
{
	var data = new Object();
	data.downloadingLabel = "Downloading ...";
	data.initializingLabel = "Initializing ...";
	data.onlineUsersTitle = "Online";
	data.applicationTitle = "Cupid Friend List";
	data.buddyListTitle = "My Friends";
	data.onlineStatusLabel = "Here";
	data.awayStatusLabel = "Away";
	data.offlineStatusLabel = "Offline";
	data.searchButtonLabel = "Search";
	data.chatWithUserLabel = "Chat";
	data.viewProfileLabel = "View Profile";
	data.addBuddyLabel = "Add Friend";
	data.removeBuddyLabel = "Remove Friend";
	data.sortByNameLabel = "Sort by Name";
	data.sortByStatusLabel = "Sort by Status";
	data.connectingStatusMessage = "Connecting ...";
	data.connectedStatusMessage = "Connected";
	data.authorizingStatusMessage = "Authorizing ...";
	data.authorizedStatusMessage = "Authorized";
	data.disconnectedStatusMessage = "Disconnected";
	data.authorizationDeniedStatusMessage = "Not Authorized";
	data.defaultAwayMessage = "I'm away!";
	data.defaultAvailableMessage = "I'm here!";
	data.noUsersOnlineMessage = "No users online.";
	data.noBuddiesMessage = "You have not added any friends.";
	data.reconnectingStatusMessage = "You were disconnected.\nReconnecting ...";
	data.statusWindowTitle = "Status";
	data.customJSCommands =
		[
			{label:"Logout", data:"Custom.UserList.Logout"}				
		];
	return data;
}
		
function addFriend(flag)
{
	if(flag==true)
	{
		alert("Your friend invitation has been sent!");	
	}
	else
	{
		alert("This member has been removed from your Cupid Friend List.");	
	}
}

function up_sendCommand( commandIn, valueIn, userID)
{
	if( commandIn == "focus" )
	{
		// DO NOT EDIT
	
		var wmObject = getWMObject();
		// only do the focus if we are sure it is not going remove focus from typing area
		if( wmObject != null && ( wmObject.focus != undefined || ( navigator.userAgent.indexOf( "MSIE" ) >= 0 && navigator.userAgent.indexOf( "Mac" ) >= 0 ) ) )
		{
			window.focus();
			wmObject.focus();
		}
	}
	else
	{
		// EDIT HERE: you will need to handle the following commands from the wm client
		if( commandIn == "viewProfile" )
		{
			if( valueIn == "-1" )
			{
				openProfileInPopup(userID);
			}
			else
			{
				openProfileInPopup(valueIn);
			}
		}
		else if( commandIn == "help" )
		{
			// view the help
		}
		else if( commandIn == "buddyList" )
		{
			// view their buddy list
			up_launchUL();
		}
		else if( commandIn == "preferences" )
		{
			// view the preferences
		}
		else if( commandIn == "addBuddy" )
		{		
			addFriend(true);
		}
		else if( commandIn == "block" )
		{
			// they blocked the user
			alert("This person has been added to your blocked member list on Cupid.");
		}
		else if( commandIn == "unblock" )
		{
			// they unblocked the user
			alert("This person has been removed from your blocked member list on Cupid.");
		}
		else if( commandIn == "Connection.Success" )
		{
			// client successfully connected to server
		}
		else if( commandIn == "Connection.Failure" )
		{
			// client was disconnected from server
		}
		else if( commandIn == "Game.Open" )
		{
			openGameWindow( valueIn );
		} 								
	}
}

function vrEvent( strEvent )
{
	var msg = " ";
	
	switch (strEvent)
	{
		case "onRecordStart":
			msg = "Recording..."
			break;
		case "onRecordFinish":
			msg = "Be sure to save your recording. By saving this recording, any previous recordings will be erased.";
			break;
		case "onRecorderDelete":
			msg = "Click \"REC\" to start a new recording.";
			break;
		case "onSaveStart":			
			msg = "Saving...";
			break;
		case "onSaveFinish":
			msg = "Your recording has been saved. Please allow 2 business days for it to be approved.";
			break;
		case "onPlayerDeleteStart":
			msg = "Deleting...";
			break;
		case "onPlayerDeleteFinish":
			msg = "Click \"REC\" to start a new recording.";
			break;
		case "Connection.Success":
			msg = "Connected.";
			break;
		case "Connection.Failure":
			msg = "Could not load video recorder."
			break;
	}
	
	if(document.all){
		document.getElementById('status_message').innerText = msg;
	} else{
		document.getElementById('status_message').textContent = msg;
	}	
	
}

function openGameWindow( qs )
{

	var newWindow = window.open("http://www.userplane.com/chatlite/games/?"+qs,"game","width=600,height=555,scrollbars=yes,resizable=yes,menubar=yes,location=no,status=no,directories=no,toolbar=no");
	if (newWindow == null)
	{
		alert( "Your popup blocker stopped the game window from opening" );
	}
} 

function focusIt()
{
	window.focus();

	var wmObject = getWMObject();
	
	if( wmObject != null && wmObject.focus != undefined )
	{
		wmObject.focus();
	}
}

function getWMObject()
{
	if(document.all)
	{
		return document.all["wm"];
	}
	else if(document.layers)
	{
		return document.wm;
	}
	else if(document.getElementById)
	{
		return document.getElementById("wm");
	}
	
	return null;
}

function wm_DoFSCommand( command, args ) 
{
}
		
function getWebrecorder( type, domainID, recordingName, sessionGUID, viewingMemberID, divID )
{
	var swfName = "vrPlayer.swf";
	var enableJavascript = "false";
	var playerWidth = "320";
	var playerHeight = "381";
	
	if ( type == "recorder" )
	{
		swfName = "vrRecorder.swf";
		enableJavascript = "true";
		playerHeight = "261";
	}
	
	if ( type == "admin" )
	{
		playerHeight = "261";
		playerWidth = "160";
		enableJavascript = "true";
	}

	if ( divID == "" )
	{
		divID = "flashcontent";
	}
	
	var fo = new FlashObject("http://swf.userplane.com/Webrecorder/" + swfName, "wr", playerWidth, playerHeight, "6", "#ffffff", false, "best");
	fo.addParam("scale", "noscale");
	fo.addParam("menu", "false");
	fo.addParam("salign", "LT");
	fo.addVariable("server", "flashcom.cupid.userplane.com");
	fo.addVariable("swfServer", "swf.userplane.com");
	fo.addVariable("applicationName", "Webrecorder");
	fo.addVariable("domainID", domainID);
	fo.addVariable("sessionGUID", sessionGUID);
	fo.addVariable("key", "");
	fo.addVariable("locale", "english");
	//uncomment the next line to allow multiple recordings per user
	//fo.addVariable("recordingName", recordingName);
	//delete the next line to allow multiple recordings
	fo.addVariable("recordingName", "");	
	fo.addVariable("enableJavascript", enableJavascript);
	if ( type != "recorder" )
	{
		fo.addVariable("viewingMemberID", viewingMemberID);
	}
	if ( type == "admin" )
	{
		fo.addVariable("admin", "true");
	}
	fo.write(divID);
}

function up_notify(_8){
	//this function overrides the userplane function in f.js.  It allows us to customize the IM notification slider.
	var _9=true;
		
	for(var i=0;i<up_la.length;i++){
		if(up_la[i].uid==_8){
			_9=false;
		}
	}
	if(_9){
		var _b=new Object();
		_b.uid=_8;
		getHandle(_b.uid);
		up_la.push(_b);
	}
	up_show();
}

function up_show(){
//this function overrides the userplane function in f.js.  It allows us to customize the IM notification slider.
	if(up_la.length>0){
		if(up_uid_display!=up_la[0].uid){			
			up_uid_display=up_la[0].uid;
			up_animate(200);
		}
	}else{
		up_uid_display="";
		up_animate(-200);
	}
}

var xmlHttp

function getHandle(idMember)
{ 
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
	return;
	} 
	
	var url="/up/wmxml.aspx?action=gethandle&memberID=" + idMember + "&domainid=new.cupid.com";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	
if (xmlHttp.readyState==4)
{ 
	if (xmlHttp.status==200)
	{				
		var divText = xmlHttp.responseText;
		if(divText.length>0){
			document.getElementById("up_nd").innerHTML=divText;
		}
	}
}

}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
