﻿// Functions for the instant messages functionality of the site

function OpenChat() 
{
	var popup = window.open('/chatroom/','chatWindow','width=630,height=450');
	if (!popup.opener) popup.opener = self;
	dismissbox();
}

var xhrt = false;
var nIMTimer = 0;

function dismissbox()
{
	nIMTimer = setInterval("checkForMessages()", 1000*60);
}

function checkForMessages()
{
	//var d = AJS.getRequest("http://www.transformdestiny.com/checkinstantmessages.asp");
	//d.addCallback(function(res_txt, req){receiveMessages(res_txt, req);});
	//d.sendReq({contactid: nVisitorID});
	
	$("#IMWnd").load("http://www.transformdestiny.com/checkinstantmessages.asp", "contactid=" + nVisitorID,
			function(responseText, textStatus, req){
				if (textStatus == "success")
				{	
					$("#IMWnd").html(responseText);
					$("#IMWnd").attr("title", "You have an instant message...");
					$("#IMWnd").dialog();
					//$("#IMWnd").dialog('open');
					clearInterval(nIMTimer);
					nIMTimer = 0;
				}
			});

	if (nIMTimer == 0) nIMTimer = setInterval("checkForMessages()", 1000*30);
}

/*function receiveMessages(res_txt, req)
{
	if (req.readyState == 4 && req.status == 200)
	{
		//document.getElementById("IMBody").innerHTML = xhrt.responseText;
		GB_hide = function(a){GB_CURRENT.hide(a); var d = AJS.getRequest("http://www.transformdestiny.com/deleteinstantmessages.asp"); d.sendReq({contactid: nVisitorID});};
		GB_showCenter('You have an Instant Message from Transform Destiny', "/checkinstantmessages.asp?contactid=" + nVisitorID, 350, 450);
		clearInterval(nIMTimer);
		nIMTimer = 0
	}
}*/
