var appletwindow;
var flag;
var nonparent;
var status;
function openIMWindow(memberid, chatwith)
{
	try
	{
		if(appletwindow == null)
		{
			//appletwindow = window.open(memberid + ".asp?chatwith=" + chatwith ,memberid,"width=100,height=100");
			appletwindow = window.open("/cupidim.aspx?chatwith=" + chatwith, "CupidImLauncher", 'width=1,height=1,left=2599,top=1999');
		}
		else
		{
			if(chatwith != "0")
			{
				appletwindow.document.applets[0].openIMWindow(chatwith);
			}
		}
	}catch(e)
	{
		if((appletwindow != null) && (e.message.indexOf("Access is denied.") > -1))
		{	
			//appletwindow = window.open(memberid + ".asp?chatwith=" + chatwith ,memberid,"width=100,height=100");
			appletwindow = window.open("/cupidim.aspx?chatwith=" + chatwith, "CupidImLauncher", 'width=1,height=1,left=1999,top=1999');
		}
	}
}

//added 7/13/06 by J. Skibitsky
//this is for closing the IM when a basic member has the IM open, tries to chat,
//and is forwarded to subscribe page 
function closeIMifOpen()
{
	if (status == "exists" || thisOpened)
	{
		appletwindow.close();
		thisOpened = false;
	}
}
							
//added 7/12/06 by J. Skibitsky 
//this is needed for the "Upgrade to Chat" path
function openIMWindowOrSubscribe(memberid, chatwith, memberType, fromPage)
{
     
	if (memberType == 1)
	{
		try
		{
			if(appletwindow == null)
			{
				//appletwindow = window.open(memberid + ".asp?chatwith=" + chatwith ,memberid,"width=100,height=100");
				appletwindow = window.open("/cupidim.aspx?chatwith=" + chatwith, "CupidImLauncher", 'width=1,height=1,left=2599,top=1999');
			}
			else
			{
				if(chatwith != "0")
				{
					appletwindow.document.applets[0].openIMWindow(chatwith);
				}
			}
		}catch(e)
		{
			if((appletwindow != null) && (e.message.indexOf("Access is denied.") > -1))
			{	
				//appletwindow = window.open(memberid + ".asp?chatwith=" + chatwith ,memberid,"width=100,height=100");
				appletwindow = window.open("/cupidim.aspx?chatwith=" + chatwith, "CupidImLauncher", 'width=1,height=1,left=1999,top=1999');
			}
		}
	}
	else
	{
	   if (memberid != 0)
	      closeIMifOpen();
		  
	   var fp = "";
       if (fromPage != '')
          fp = "&amp;fp=" + fromPage;
		  
	   window.location.href = "membership.aspx?pagename=sub_im&amp;to_im=" + chatwith + fp;
	}
	
}


function exitApplication()
 {
  // old document.applets[0].destroy();
 // new
 	  window.open('', '_parent','');
  		window.close(); 
 }

 
 function launchBrowser(strURL)
 {
  if(opener == null)
  {
    opener.location.href = window.open(strURL, "_blank", "resizable=1,status=yes,scrollbars=1,menubar=1,toolbar=1,location=1");
  } 
  else
  {
   try
   {
    if(opener.closed ==false)
    {
		opener.location.href = strURL;
    }
    else
    {
		if(nonparent != null)
		{
    		nonparent.location.href = strURL;
    	}
    	else
    	{
    		nonparent = window.open(strURL, "_blank", "resizable=1,status=yes,scrollbars=1,menubar=1,toolbar=1,location=1");
    	}
    }
   }
   catch(e)
   {
    nonparent = window.open(strURL, "_blank", "resizable=1,status=yes,scrollbars=1,menubar=1,toolbar=1,location=1");
   }
  }
 }
 
 
 
function closeWindow()
 {
/* OLD if(window.opener && !window.opener.closed)
 {
	window.opener.document.images['left_im'].src = '/images/buttons/im_off_hi.gif';
	window.opener.document.images['right_im'].src = '/images/buttons/im_on_no_hi.gif';
	window.opener.flipOnClick();
	window.opener.thisOpened = false;
 }
  window.opener = top;
  window.close();
 */
  try
 {
	window.opener.document.images['left_im'].src = '/images/buttons/im_off_hi.gif';
	window.opener.document.images['right_im'].src = '/images/buttons/im_on_no_hi.gif';
	window.opener.thisOpened = false;
	window.opener.flipOnClick();
 }
 catch(error)
 {
 // window.open('', '_parent','');
 // window.close(); 
 } 
 window.open('', '_parent','');
 window.close();
 }
 
 
function UpdateParent()
{
try{
	opener.appletwindow = this;
	}catch(e)
	{}
}

function ManageCookie()
{  
	var kill_time = new Date();
	kill_time.setSeconds(kill_time.getSeconds() + 3);
	document.cookie = "AppletSingleton=AppletSingleton;expires=" + kill_time.toGMTString();
}


function setCookie(name, value)
{
  var kill_time = new Date();
  kill_time.setSeconds(kill_time.getSeconds() + 3);
  var hostArr = new Array();
  hostArr = window.location.hostname.split(".");
  var pathString = hostArr[hostArr.length-2] + "." + hostArr[hostArr.length-1];

  document.cookie = name + "=" + escape(value) + ";expires=" + kill_time.toGMTString() + '; path=/; domain=' + pathString;
  flag = true; 
}

function getCookie(name)
{	
	var ret = null;
	var str = document.cookie.indexOf(name);
	if(str > -1)
	{
		ret = "exists";
	}
   return ret;
}


function changestatus()
{
	appletwindow.document.applets[0].changeMemberStatus(status);
	if(status == "true")
	{
		status = "false";
	}
	else
	{
		status = "true";
	}
}


function createEntry(uid,nick,group)
{
	if(appletwindow != null)
	{
		appletwindow.document.applets[0].createEntry(uid,nick,group);
	}
}

function killCookie()
{
var kill_time = new Date("January 1, 1970");
document.cookie = "AppletSingleton=AppletSingleton;expires=" + kill_time.toGMTString();
}