﻿var frameName = null;

for(var i = 0;i < parent.frames.length; i++)
{
  if(parent.frames[i].name == 'NavContent')
  {
    frameName = parent.NavContent;
  }
  else if(parent.frames[i].name == 'MailMain')
  {
    frameName = parent.MailMain;
  }
  if(frameName == '' || frameName == null)
  {
    try{
    frameName = top.NavContent;
    }catch(e){}
  }
  }

function Chat(obj,femaleAccount)
{
  var userID = GetCookieValue('ASPSessionID'); //make sure they are logged in (in getdata.js)
  if(userID != null)
  {
    if(femaleAccount != 0)
    {
      try
      {
        if(parent.frames.length > 0)
        {
          if(frameName.chatRequestsTimerId != null)
          {
            frameName.OpenChat(femaleAccount,1);
          }
          else
          {
            top.location = '../myhome/?func=profile&picAcct=' + femaleAccount;
          }
        }
        else
        {
          OpenChat(femaleAccount,1);
        }
        return;
      }
      catch(e){}
    }
  }
  else
  {//not logged in, prompt to join or log in and open trial chat window		
    var chatPath = '../chattrial/' + femaleAccount + '.htm'; 
    features='height=450,width=785,menubar=0,personalbar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0';
    window.open(chatPath,"",features);
  }
}

function LeaveChatHandler(girl)
{
  try
  {
    var url ='../chat/ChatClear.aspx?girl=' + girl + '&id=' + Math.random();
    if(window.XMLHttpRequest)
    {
      xmlhttpLeave = new XMLHttpRequest();
      with(xmlhttpLeave) 
      { 
        onreadystatechange = EvalDeparture;open("GET",url,false);send(null);
      }
    }
    else if (window.ActiveXObject)
    {
      xmlhttpLeave = new ActiveXObject("Microsoft.XMLHTTP");
      if (xmlhttpLeave)
      {
        with(xmlhttpLeave)
        {  
          onreadystatechange = EvalDeparture;open("GET",url,true);send();
         }
       }
    }
	}
	catch(e){}
}

function EvalDeparture()
{
	if(xmlhttpLeave.readyState == 4)
	{
	  if (xmlhttpLeave.status == 200)
	  {
	     try
      {
        if(parent.frames.length > 0)
        {
          frameName.clearTimeout(frameName.chatRequestsTimerId);
					     frameName.inChat = false;
					     frameName.timertime	= 250;
					     frameName.ChatRequestsTimer();
        }
        else
        {
          clearTimeout(chatRequestsTimerId);
				      inChat = false;
				      timertime	= 250;
				      ChatRequestsTimer();
        }
        return;
      }
      catch(e){}
	  }
	}
}
