﻿var clearMsgTimer = 0; //keeps track of the timer that closes tha add or remove msg in the header
var otherFunction = false; //if this is set to true, then the profile card is not shown automatically
var loadedFirstProfile = false; //if the first profile needs to load the profiledetail in navmain - this is the indicater

function ReplaceClassOver(theElementName)
{
	try
	{	
		//swaps a class with a over version and back
		var theElement = document.getElementById(theElementName);
		if(theElement != null)
		{		
			var currentClass = new String(theElement.className); //get the current classname
			var newClassName = '';	
			if(currentClass.indexOf('Over') > -1)
			{
				//if the old class is the over vrsion, replace it with the original	
				newClassName = 	new String(currentClass.replace('Over',''));		
			}
			else
			{
				//replace the original version with the over class	
				newClassName = 	new String(currentClass + 'Over');	
			}
			theElement.className = newClassName;
		}
	}
	catch(e){}	
}	

function HighliteUserName(obj)
{
	//highlights the username in the profile card as the user mouses over it
	var femaleAccount = obj.id;  //get the account
	var userNameTd = 'UserName' + femaleAccount; //create the element name
	ReplaceClassOver(userNameTd);
	
	//if in favorites, add the title to the grayed out girl that is in the matches too	
	var pageTitle = new String(document.getElementById('uxPageTitle').src);
	pageTitle = pageTitle.toLowerCase();
	if(pageTitle.indexOf("hdr_favorites") > -1)	
	{	
		var favNew = 'IsFavNew' + femaleAccount;		
		if(document.getElementById(favNew).innerHTML == '0-True' || document.getElementById(favNew).innerHTML == '1-True')
		{
			obj.title = 'This favorite has been moved to your matches folder.'
		}
	}
}

function HighliteHostessUserName()
{
	//highlights the username as the user mouses over it	
	ReplaceClassOver('HostessUserName');
}

function GetProfile(obj)
{
	//changes the border as the user click in the card
	if(document.getElementsByTagName)
	{//loop through and turn off any that are on
  var divItem = document.getElementsByTagName('DIV');
		for(var i=0; i<divItem.length; i++)
		{
		 var oldClassName = 	new String(divItem[i].className);
			divItem[i].className = oldClassName.replace('Over','');
		}
	}	
	var currentClass = new String(obj.className);
	obj.className = currentClass + 'Over'; //add the over to the cur class and replace	
	
	if(otherFunction != true)
	{	//if the otherFunction (indicates not to open profile) is false, open profile
		var femaleAccount = obj.id;	
		var navMainLocal = new String(parent.NavMain.location);
		navMainLocal = navMainLocal.toLowerCase();	
		if (!(navMainLocal.indexOf('profile.aspx') > -1 && navMainLocal.indexOf(femaleAccount) > -1))
		{	
			parent.NavMain.location = '../profile/profile.aspx?toid=' + femaleAccount;
		}	
	}
	else
	{
		otherFunction = false;
	}			
}

function SendEmail(obj,femaleAccount)
{
 otherFunction = true; //set this to true so the profile does not get opened
 var userID = GetCookieValue('ASPSessionID'); //make sure they are logged in (in getdata.js)
	if(userID != null)
	{
		if(femaleAccount != 0)
		{//open email page
			parent.NavMain.location = '../email/email_noframe.asp?toid=' + femaleAccount + '&func=send'; 
		}
	}
	else
	{//not logged in, prompt to join or log in
		ShowLoginPrompt();
	}
}

function ShowLoginPrompt()
{//shows message to login or join
	var messagesDiv = document.getElementById('NotMessage');

	with(messagesDiv.style)
	{		//posy is in Mice07272007.js - reuturns y pos of mouse
		left = 10 + 'px';
		top = GetScrollY() + 'px'
		display = 'block';
	}
}

function CloseLoginPrompt()
{	//closes the ShowLoginPrompt function above
	document.getElementById('NotMessage').style.display = 'none';
}

function CheckStuff()
{
	try
	{	
	//if there is an incomming account - highlight the profilecard
	var url = new String(document.location);
	url = url.toLowerCase();
 if(url.indexOf('toid') > -1)
	{
		//highlight it
		var toid = GetQueryStringItem('toid')
		var herProfileCard = document.getElementById(toid);
		if(herProfileCard != null)
		{
			herProfileCard.className =	herProfileCard.className + 'Over';
		}	
	}
	if(document.getElementsByTagName)
	{
		//loop through the divs and indicate if any of the matches or admirers are new	
  var divItem = document.getElementsByTagName('DIV')
		for(var i=0; i<divItem.length; i++)
		{
			var tagID = new String(divItem[i].id)
			if(tagID.indexOf('IsFavNew') > -1)
			{
				var theValue = 	document.getElementById(tagID).innerHTML;
			 theValue = theValue.replace(' ','');
				var valueArray =  theValue.split('-');
				var newFav = valueArray[0]	;
				var isMatch = 	valueArray[1];
				var femaleAccount = tagID.replace('IsFavNew','');	
				//load a profile in the navmain area if there isn't anything	
				if(loadedFirstProfile == false && parent.NavMain != null)	
				{	
					var navMainDoc = new String(parent.NavMain.document.location);
					if(navMainDoc.indexOf('blank.htm') > -1)
					{
					  parent.NavMain.document.location = '../profile/profile.aspx?toid=' + femaleAccount;	
						loadedFirstProfile = true;
						//highlight it
						var profileCard = document.getElementById(femaleAccount);
						profileCard.className =	profileCard.className + 'Over';
					}
				}
				if(newFav == '1')	
				{
					var userNameTd = 'UserName' + femaleAccount;					
					var oldClassName = 	new String(document.getElementById(userNameTd).className);
					var newClassName = 	new String(oldClassName + 'Over');	
					document.getElementById(userNameTd).className = newClassName;
				}
				var pageTitle = new String(document.getElementById('uxPageTitle').src);
				if((isMatch == 'True' || isMatch == 1) && pageTitle.indexOf('hdr_favorites.gif') > -1)
				{
					var femaleAccount = tagID.replace('IsFavNew','');
					setOpacity(femaleAccount);					
				}				
			}	
		}
	}	
	}catch(e){}
}
function setOpacity(femaleAccount) 
{
	try		
	{	//puts a gray over any favorites in his matches
		var femaleDiv = document.getElementById(femaleAccount);
		femaleDiv.style.backgroundColor = '#666666';
  // IE/Win
  femaleDiv.style.filter = "alpha(opacity:50)";
  
  // Safari<1.2, Konqueror
  femaleDiv.style.KHTMLOpacity = .5;
  
  // Older Mozilla and Firefox
  femaleDiv.style.MozOpacity = .5;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  femaleDiv.style.opacity = .5;  
		femaleDiv.title = 'She has been added to your matches';
	}
	catch(e)
	{}		
}

var giftShopToId = 0;
var giftShopUsername = '';

function Gifts(obj,femaleAccount, userName)
{
	otherFunction = true;
	var userID = GetCookieValue('ASPSessionID');
	clearTimeout(clearMsgTimer);
	CloseBannerMsg();
	if(userID != null)
	{	
		giftShopToId = femaleAccount;
		giftShopUsername = userName;
		ManageGiftList();
		var currentIcon = new String(obj.src);
		if(currentIcon.indexOf('i_gift') > -1)
		{
			obj.src =  '../images/i_removegift.gif'
			obj.title = 'Add ' + giftShopUsername + ' to your gift list.';
		}
		else
		{
			obj.src =  '../images/i_gift.gif';
			obj.title = 'Add ' + giftShopUsername + ' to your gift list.';	
		}
	}
	else
	{
		ShowLoginPrompt();
	}			
}

function ManageGiftList()
{
  try
  {
    var url = '../searches/managegiftlist.aspx?femaleaccount=' + giftShopToId + '&i=' + Math.random();    
    if(window.XMLHttpRequest)
    {
      xmlhttpGiftlist = new XMLHttpRequest();
      with(xmlhttpGiftlist)
      {
        onreadystatechange = GoToGiftShop;open("GET",url,true);send(null);
      }
    }
    else if (window.ActiveXObject)
    {
      xmlhttpGiftlist = new ActiveXObject("Microsoft.XMLHTTP");
      if (xmlhttpGiftlist)
      {
        with(xmlhttpGiftlist)
        {
          onreadystatechange = GoToGiftShop;open("GET",url,true);send();
        }
      }
    }
  }
  catch(e){}
}

function GoToGiftShop()
{
  try
  { 
    if(xmlhttpGiftlist.readyState == 4)
    {
      if(xmlhttpGiftlist.status == 200)
      {
        var theResponse = xmlhttpGiftlist.responseText;
        if(theResponse == '0' || theResponse == '')
        {
          var bbLocal = new String(top.document.location);
          bbLocal = bbLocal.toLowerCase();
          if(bbLocal.indexOf("blackbook/default.asp") == -1)
          {
            top.document.location = '../blackbook/default.asp?toid=' + giftShopToId + '&giftshop=true';
          }
          else
          {
            if(parent.NavDetail != null)
            {
              var bbToid = parent.NavDetail.document.getElementById('ToID');
              if(bbToid != null){bbToid.value = giftShopToId;}
            }
            parent.NavMain.document.location = '../giftshop/?toid=' + giftShopToId;
          }
        }
        else
        {
          var msgDiv = parent.NavBannerRight.document.getElementById('miscmsgs');
          if(msgDiv != null)	
          {
            ClearMsgBlock()
            var msg = giftShopUsername + ' has been removed from your gift list.';
            with(parent.NavBannerRight.document)	
            {
              getElementById('msgthumb').src = '../lb_photos/' + giftShopToId + '/' + giftShopToId + '_tn.jpg';
              getElementById('msgtoshow').innerHTML = msg;
              getElementById('msgsusername').innerHTML = giftShopUsername;
              var msgTable = getElementById('msgstable').innerHTML;	
            }
            msgDiv.innerHTML = 	msgTable;
            msgDiv.style.display = 'block'	;
            clearMsgTimer = setTimeout("CloseBannerMsg()", 10000);
          }
        }
      }
    }
  }
  catch(e){}
}

function Intros(obj,femaleAccount)
{
	otherFunction = true;
	var userID = GetCookieValue('ASPSessionID');
	clearTimeout(clearMsgTimer);
	if(userID != null)
	{	
		var introIcon = new String(obj.src);	
		if (introIcon.indexOf("i_intro_whitebg.gif") > -1)
		{
			var url = '../email/SendIntroLetter.asp?acctnum=' + femaleAccount;
			feats='top=150,left=200,height=400,width=600,menubar=0,personalbar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0';
			window.open(url,"intro" + femaleAccount,feats);
		}
	}
	else
	{
		ShowLoginPrompt();
	}			
}

function CloseBannerMsg()
{
	var msgDiv = parent.NavBannerRight.document.getElementById('miscmsgs');
	 if(msgDiv != null)
	 {	
			msgDiv.style.display = 'none'
	 }
}

function CheckInput()
{
 if(form1.uxSortList.value == '')
	{
		return false;
	}
	else
	{
	  CheckForm();
		return true;
	}
}

function CheckForm()
{
	if(document.all || document.getElementById)
	{
	  var objID = '';
	  var tempobj = '';
    for (i = 0; i < document.form1.length; i++)
    {
		  tempobj = document.form1.elements[i];
			cleanupscript(tempobj);
    }
	}	
}

function cleanupscript(obj)
{//look for and remove script tags from text
	var the_value = new String(obj.value);
  the_value = RemoveBad(the_value);
  obj.value = the_value;
}

function RemoveBad(strTemp)
{ 
 strTemp = strTemp.replace(/\<|\>|\%|\*|\?|\%3c|\%3e|\)|\(|/g,""); //remove script tags
 return strTemp;
}

var hostessHideClick =false;

function GetHostess()
{
	if(hostessHideClick == false)
	{	
	  var hostess = document.getElementById('HostessAccount').innerHTML;
		feats='height=500,width=600,menubar=0,personalbar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0';
		window.open("../hostesschat/" + hostess + ".htm","newHostess",feats);
	}
} 

function ShowHideHostess()
{	
	var hostessDiv = document.getElementById('HostessDiv');
	var hiddenDostessDiv = document.getElementById('HiddenHostessDiv');	
	if(hostessDiv != null)
	{
	 if(hostessDiv.style.display == 'none')
  	{
  		hostessHideClick =false;	
  		hostessDiv.style.display='block';
  		hiddenDostessDiv.style.display = 'none';
  		DeleteCookie('HideHostess','/','')
  	}
  	else
  	{
  		hostessHideClick = true;	
  		hostessDiv.style.display='none';
  		hiddenDostessDiv.style.display = 'block'
  		CreateCookie('HideHostess','1',0);
		}
	}	
}

function EditChatContacts()
{
	with(document.getElementById('ChatContactsEditDiv'))
	{	
		innerHTML = '<iframe src="../chat/ChatContactEditList.aspx" frameborder="no" height="300" width="200" scrolling="auto-y" id="contactlistframe" />'
	  style.display = 'block'; 
	}
}

function Chat(obj,femaleAccount)
{
	otherFunction = true; //set this to true so the profile does not get opened
	var userID = GetCookieValue('ASPSessionID'); //make sure they are logged in (in getdata.js)
	if(userID != null)
	{
		if(femaleAccount != 0)
		{
		  balance = 1;
		  if(credits != -1)
		  {
		    balance = credits;
		  }  
		  OpenChat(femaleAccount,balance);//in check_checker.js
		}
	}
	else
	{//not logged in, 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,"newChat" + femaleAccount,features);		
	}
}

function UpdateOnlineStatuses()
{
  var url = '../searches/WhosOnlineChecker.aspx?i=' + Math.random();
  if(window.XMLHttpRequest)
  {
    xmlHttpOnlineCheck = new XMLHttpRequest();
    with(xmlHttpOnlineCheck)
    {
      onreadystatechange = EvalOnlineCheck;open("GET",url,false);send(null);
    }
  }
  else if (window.ActiveXObject)
  {
    xmlHttpOnlineCheck = new ActiveXObject("Microsoft.XMLHTTP");
    if (xmlHttpOnlineCheck)
    {
      with(xmlHttpOnlineCheck)
      {
        onreadystatechange = EvalOnlineCheck;open("GET",url,false);send();
      }
    }
  }
}

function EvalOnlineCheck()
{
  if (xmlHttpOnlineCheck.readyState == 4) 
  {
    if(xmlHttpOnlineCheck.status == 200)
    {
      var theResponse = xmlHttpOnlineCheck.responseText;
      if(theResponse.length > 0)
      {
        var accountsArray =  theResponse.split(',');
        CheckProfileCards(accountsArray);
      }
    }
  }
}

function CheckProfileCards(accountsOnlineArray)
{
  var accountsOnPage = new Array();
  var pageDivs = document.getElementsByTagName('DIV');
  //go through divs and create array of the females
  for(var i = 0; i < pageDivs.length; i++)
  {
    var divID = parseInt(pageDivs[i].id);
    if(!(isNaN(divID)))
    {
      var arrayCount = accountsOnPage.length;     
      accountsOnPage[arrayCount] = divID;
    }
  }
  
  if(accountsOnPage.length > 0)
  {
    //start checking each girl against list
    for(var a = 0; a < accountsOnPage.length; a++)
    {
      var femalePageAccount = parseInt(accountsOnPage[a]);      
      
      var femalesDiv = document.getElementById(femalePageAccount);
      
      //find chat icon to compare the status
      var imgs = femalesDiv.getElementsByTagName('IMG');
      var chatIcon = null;
      for(var b = 0; b < imgs.length; b++)
      {
        var iconID = new String(imgs[b].id);
        if(iconID.indexOf('uxChatIcon') > 0)
        {
          chatIcon = imgs[b];
          break;
        }
      }
      if(chatIcon != null)
      {
        var isStreamingSrc = 'i_webcamani.gif';
        var isOnlineSrc = 'chat_on.gif';
        var NotOnlineSrc = 'chat_off.gif';
        var currentSrc = chatIcon.src;
        currentSrc = currentSrc.toLowerCase();
        
        var userName = document.getElementById('UserName' + femalePageAccount).innerHTML;
        
        //now go through and see if online or not
        
        var isOnline = false;
        
        for(var c = 0; c < accountsOnlineArray.length; c++)
        {
          var femaleOnlineAccountInfo = accountsOnlineArray[c].split('-');
          var femaleOnlineAccount = femaleOnlineAccountInfo[0];
          
          if(femalePageAccount == femaleOnlineAccount)
          {
            isOnline = true;
            var femaleOnlineIsStreaming = femaleOnlineAccountInfo[1];
            //check is streaming
            var imgIsstreamingIjndex = currentSrc.indexOf(isStreamingSrc);
            if(femaleOnlineIsStreaming == 'True')
            {
              if(imgIsstreamingIjndex < 0)
              {
                chatIcon.src = '../images/' + isStreamingSrc;
                chatIcon.title = 'Click here to chat with and watch ' + userName + ' live!';
              }
            }
            else
            {
              if(imgIsstreamingIjndex >= 0)
              {
                chatIcon.src = '../images/' + isOnlineSrc;
                chatIcon.title = 'Click here to chat with ' + userName + '!';
              }
            }
            
            break;//found her, stop searching
          }
          
        }
        
        if(isOnline == false)
        {
          if(currentSrc.indexOf(NotOnlineSrc) == -1)
          {
            //show her as offline
            chatIcon.src = '../images/' + NotOnlineSrc;
            chatIcon.title = userName + ' is not online.';
            chatIcon.onclick = null;
          }
        }
        else
        {
          //if was offline, add onclick chat event
          if(currentSrc.indexOf(NotOnlineSrc) > -1)
          {
            chatIcon.onclick = new Function("Chat(this," + femalePageAccount + ");");
            chatIcon.src = '../images/' + isOnlineSrc;
            chatIcon.title = 'Click here to chat with ' + userName + '!';
          }
        }
        
      }
    
    }  
  }
  setTimeout('UpdateOnlineStatuses()', 30000);
}

setTimeout('UpdateOnlineStatuses()', 30000);
