function PopupMessage(sTitle) {
    /*if (window.document.title != '') {
        var $dialog = $('<div></div>').html($('#div_imlogin').html()).dialog({ autoOpen: false, title: sTitle }); $dialog.dialog('open');
    }
    else {
        window.parent.ShowPopupMessage($('#div_imlogin').html(), sTitle);
    }*/
}

window.ShowPopupMessage = function(sText, sTitle) {
    /*var $dialog = $('<div></div>').html(sText).dialog({ autoOpen: false, title: sTitle }); $dialog.dialog('open');*/
}


var imgMsg = "This content is copyrighted by the owner.\n\nUnauthorized use of this image is illegal.";

function hookC(img)
{
	if (document.layers){document.captureEvents(Event.MOUSEDOWN);img.onmousedown=disRC;}
	else if (document.all&&!document.getElementById){img.onmousedown=disRC;}
	img.oncontextmenu=new Function("alert(imgMsg);return false");
}

function disRC(e)
{
    if( !e ) {
        if( window.event ) {
            e = window.event;
        } else {
            return;
        }
    }

    if( typeof( e.which ) == 'number' ) {
        e = e.which;
    } else {
        if( typeof( e.button ) == 'number' ) {
             e = e.button;
         } else {
            return;
         }
    }

	if( navigator.appName == 'Netscape' && e == 3 ){
		alert(imgMsg);
		return false;
	}
	
	if (navigator.appName == 'Microsoft Internet Explorer' && e==2) {
		alert(imgMsg);
		return false;
	}
	else return true;	
}

function getDim(el){
	for (var lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly}
}

var isHiding = false;

function isOldIE()
{
	var s = navigator.appVersion;
	if (s.match(/MSIE\s*(\d)\./))
	{
		var version = RegExp.$1;
		if (version <= "6")
		{
			return true;
		}
	}
	return false;
}

function hideInputs()
{
	if (isOldIE())
	{
		if( !isHiding )
		{
			var objs = document.getElementsByTagName('select');
			for( var i = 0; i < objs.length; i++ )
			{
				if( objs[i].style.display!='none' )
				{
					var d = document.createElement('div');
					d.innerHTML=objs[i].options[objs[i].selectedIndex].text;			
					d.style.display='inline'; d.style.width=objs[i].clientWidth; d.style.padding='2px'; d.style.border='1px solid #999999'; d.style.backgroundColor='white';			
					if(objs[i].style.fontSize=='8pt') d.style.fontSize='8pt';
					else d.style.fontSize='9pt';
					objs[i].parentNode.insertBefore(d,objs[i]);			
					objs[i].style.display='none';
				}
			}
			
			isHiding = true;
		}			
	}
}

function showInputs()
{
	if (isOldIE())
	{
		if( isHiding )
		{	
			var objs = document.getElementsByTagName('select');
			for( var i = 0; i < objs.length; i++ )
			{
				objs[i].style.display='';
				if( objs[i].previousSibling && objs[i].previousSibling.tagName ) if( objs[i].previousSibling.tagName.toLowerCase()=='div' ) objs[i].parentNode.removeChild(objs[i].previousSibling);
			}
			
			isHiding = false;
		}
	}
}

var hideHdl = null; hideMnu = null; hideHdl2 = null; hideMnu2 = null; hideHdl3 = null; hideMnu3 = null;
var curMenu = null; curMenu2 = null; curMenu3 = null;
function showMenu(cid, pid)
{
	var o = document.getElementById(cid);
	var op = document.getElementById(pid);	
	if( o.style.display != '' )
	{
		if(o&&op)
		{
			hideVisibleMenus();	
			var dim = getDim(op);
			var clientHeight = op.clientHeight == 0 ? 15 : op.clientHeight;
			o.style.top=dim.y+clientHeight+4;
			o.style.left=dim.x;
			o.style.display='';
			curMenu = o;
		}
	}
	clearTimeout(hideHdl);
	clearTimeout(hideHdl2);
	
	hideInputs();
}

function showMenu2(cid, pid, yOff)
{
	var o = document.getElementById(cid);
	var op = document.getElementById(pid);
	if( o && o.style.display != '' )
	{
		if(o&&op)
		{
			hideVisibleMenus2();
			var dim = getDim(op);
			o.style.top=dim.y;
			o.style.left=dim.x+op.clientWidth;
			o.style.display='';
			if( o.offsetHeight > Math.abs(yOff) )
				if(yOff)o.style.top=dim.y+yOff;
			curMenu2 = o;		
		}
	}
	clearTimeout(hideHdl);
	clearTimeout(hideHdl2);
	
	hideInputs();
}

function showMenu3(cid, pid) { hideVisibleMenus(); showMenu2( cid, pid ); }

function hideMenu(cid)
{
	clearTimeout(hideHdl);
	
	var o = document.getElementById(cid);
	if(o)
	{
		hideHdl = setTimeout('hideMenu2("' + cid + '");', 200);
		hideMnu = o;
	}		
}

function hideMenuEx(cid)
{
	clearTimeout(hideHdl2);
	
	var o = document.getElementById(cid);
	if(o)
	{
		hideHdl2 = setTimeout('hideMenu2("' + cid + '");', 200);
		hideMnu2 = o;
	}
}

function hideMenu2(cid)
{
	var o = document.getElementById(cid);
	if(o) o.style.display='none';
	showInputs();
}

function hideVisibleMenus2()
{
	if( hideMnu2 ) hideMnu2.style.display='none';
	if( hideMnu3 ) hideMnu3.style.display='none';
	if( curMenu2 ) curMenu2.style.display='none';
	if( curMenu3 ) curMenu3.style.display='none';
}

function hideVisibleMenus()
{
	if( hideMnu ) hideMnu.style.display='none';
	if( hideMnu2 ) hideMnu2.style.display='none';
	if( hideMnu3 ) hideMnu3.style.display='none';
	if( curMenu ) curMenu.style.display='none';
	if( curMenu2 ) curMenu2.style.display='none';
	if( curMenu3 ) curMenu3.style.display='none';
}

function displaySendMessage(id)
{
	window.open("/SendMessage.aspx?id=" + id, 
				"sendMessage", 
				config="toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=470,height=400");
}

function displaySendReply(id, replyid)
{
	window.open("/SendMessage.aspx?id=" + id + "&mode=reply&replyid=" + replyid, 
				"sendMessage", 
				config="toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=470,height=400");
}

function displayPhoto(pid, mid)
{
	window.open("/ViewPhoto.aspx?PhotoId=" + pid + "&MemberId=" + mid, 
				"viewPhoto", 
				config="toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=500");
}

function togglePanel(oDiv, oMsg, sOff, sOn)
{
	if (oDiv)
	{
	
		if ('' == oDiv.style.display)
		{
			oDiv.style.display = 'none';
			if (oMsg.innerText)
			{	// IE
				oMsg.innerText = sOff;
			}
			else
			{	// Firefox
				oMsg.textContent = sOff;
			}
		}
		else
		{
			oDiv.style.display = '';
			if (oMsg.innerText)
			{	// IE
				oMsg.innerText = sOn;
			}
			else
			{	// Firefox
				oMsg.textContent = sOn;
			}
		}
	}
	return false;
}

function tch(o, cls)
{
	if( o != null )
	{
		o.className = cls;
	}
}

function _doHover()
{
	var o = window.parent.document.getElementById('l_tn_mnuRequests');
	if( o ) doHover(o);
	else doHover(document.getElementById('l_tn_mnuRequests'));
}

function _doUnHover()
{
	var o = window.parent.document.getElementById('l_tn_mnuRequests');
	if( o ) doUnHover(o);
	else doUnHover(document.getElementById('l_tn_mnuRequests'));
}

function _openWindow()
{
	location.href = '/OnlineRequests.aspx'; 
}

var curSel;
var oldClass;
function doHover(o)
{
	if(curSel!=o.id)
	{
		oldClass = o.className;
		o.className = "mnuSelItem";
		curSel = o;
	}
}
function doUnHover(o)
{
	if(o!=null)
	{
		o.className = oldClass;
		curSel = null;
		oldClass = "";
	}
}

var curSel2;
var oldClass2;
function doHover2(o)
{
	if(curSel!=o.id)
	{
		oldClass2 = o.className;
		o.className = "mnuSelItem2";
		curSel2 = o;
	}
}
function doUnHover2(o)
{
	if(o!=null)
	{
		o.className = oldClass2;
		curSel2 = null;
		oldClass2 = "";
	}
}

var curSel3;
var oldClass3;
function doHover3(o)
{
	if(curSel!=o.id)
	{
		oldClass3 = o.className;
		o.className = "mnuSelItem3";
		curSel2 = o;
	}
}
function doUnHover3(o)
{
	if(o!=null)
	{
		o.className = oldClass3;
		curSel3 = null;
		oldClass3 = "";
	}
}

function doClick(url)
{
	location.href=url;
}

function toggleText(obj)
{
	if(obj)
	{
		if(obj.className=="mnuHighlight")
			obj.className="mnuHighlight2";
		else
			obj.className="mnuHighlight";
	}
}

function launchChat(id)
{
	window.open('/Chat/PublicChat.aspx?mode=join&id=' + id, '', config='toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width=800,height=400');
}

function launchProfile(id)
{
	window.open('/ViewProfileShort.aspx?id=' + id, '', config='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=550');
}

function requestChat(srcid, destid, destName)
{
	window.open("/Chat/RequestChat.aspx?mode=new&src=" + srcid + "&dest=" + destid + "&destname=" + destName, '', config="toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=400");
}

function AMM_OpenWindow(width, height, frame)
{
	window.open('', frame, config='toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=' + width + ',height=' + height + '');
}

function AMM_OpenWindow2(width, height, frame)
{
	window.open('', frame, config='toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=' + width + ',height=' + height + '');
}

function changeSubmit(el, evt, subBut)
{
	var code = null;	
	try { code = evt.keyCode; }
	catch(e) { code = evt.which; }	
	if(code==13)
	{
		document.getElementById(subBut).click();
		return false;
	}
}

/* Version 3.0 Functions */
function sel(o,cls)
{
	if(o.checked)
		o.parentNode.parentNode.className = 'subCellSelb';
	else
		o.parentNode.parentNode.className = cls;
}

function sel2(o,cls)
{
	if(o.checked)
	{
		o.parentNode.parentNode.className = 'subCellSelb';
		o.parentNode.parentNode.nextSibling.className = 'subCellSelb';
	}
	else
	{
		o.parentNode.parentNode.className = cls;
		o.parentNode.parentNode.nextSibling.className = cls;
	}
}
		
function selAll(o)
{
	var s = o.checked;
	var c = document.getElementsByTagName('input');
	for( i = 0; i < c.length; i++ )
	{
		if( c[i].type == 'checkbox' )
		{
			if( c[i].checked == !s )
			{
				c[i].click();
			}
		}				
	}
}

function makeParam(name, value) 
{ 
        var p = document.createElement("param"); 
        p.name = name; 
        p.value = value; 
        return p; 
} 

function fnPrepareSound()
{
	var o = document.createElement('EMBED');	
	o.id="playSound";
	o.autostart=true;
	o.width=1;
	o.height=1;
	document.body.appendChild(o);
	return o;
}

function fnPlaySound(i)
{
	var o = document.getElementById("playSound");	
	if( o ) { document.body.removeChild(o); }
	
	o = fnPrepareSound();
		
	if(i==1){
		o.autostart=true; o.src='/Sounds/newMsg.wav';
	}else if(i==2){
		o.autostart=true; o.src='/Sounds/newMsg2.wav';
	}else if(i==3){
		o.autostart=true; o.src='/Sounds/newMsg3.wav';
	}
}

/* IM Functions */
function toggleText(obj)
	{
	if(obj)
	{
		if(obj.className=="mnuHighlight")
			obj.className="mnuHighlight2";
		else
			obj.className="mnuHighlight";
	}
}

function fnSwapToIframe() {
	document.getElementById('l_tn_imPre').parentNode.style.display='none';
	document.getElementById('l_tn_instantMessage').style.top='0px';
	document.getElementById('l_tn_instantMessage').src='/Streams/IMD.aspx';
	document.getElementById('l_tn_instantMessage').style.display='';
	preSwap = false;
}

function fnSwapToIframeClear()
{
	document.getElementById('l_tn_imPre').parentNode.style.display='none';
	document.getElementById('l_tn_instantMessage').style.top='0px';
	document.getElementById('l_tn_instantMessage').src='/Streams/IMD.aspx?action=clear';
	document.getElementById('l_tn_instantMessage').style.display='';
	preSwap = false;
}

function fnClearIM()
{
	if(!preSwap)
		document.getElementById('l_tn_instantMessage').contentWindow.location.href='/Streams/IMD.aspx?action=clear';
	else
		fnSwapToIframeClear();
		
	return false;
}

function fnInitFlashText(a)
{
	o = a; c = 0;
	tHdl = setInterval( 'fnFlashText()', 500 );
}

function fnFlashText()
{
	c++;
	for(i = 0 ; i < o.length; i++ ){ 
		if(o[i]){
			if( o[i].style.fontWeight == 'bold' )
				o[i].style.fontWeight = '';
			else
				o[i].style.fontWeight = 'bold';
		}
	}
	if(c>11) clearTimeout(tHdl);
}

var requests = -1;
function fnShowPrivateChats(num)
{
	if(num==0)
	{
		if( window.parent.getTimerHandle ) if( window.parent.getTimerHandle('privChat') != 0 ) window.parent.clearInterval( window.parent.getTimerHandle('privChat') );
		requests = 0;
		isFlashing = false;
		var o = window.parent.document.getElementById('l_tn_mnuRequests');
		if(o)
		{
			o.onmouseout='';
			o.onmouseover='';
			o.onclick='';
			o.innerHTML='';
		}
	}
	else if(num!=-1)
	{
		if(requests!=num)
		{
			requests = num;
			var o = window.parent.document.getElementById('l_tn_mnuRequests');
			if(o)
			{
				o.onmouseout=window.parent._doUnHover;
				o.onmouseover=window.parent._doHover;
				o.onclick=window.parent._openWindow;
				o.innerHTML='<STRONG id="lblIn" class="mnuHighlight" title="' + num + ' Chat Request(s) Pending"><img src="/images/iconPrivateChatRequest.gif" alt="' + num + ' Chat Request(s) Pending" /></STRONG>';
			}
			if(window.parent.getTimerHandle('privChat')==0)
			{
				window.parent.setTimerHandle('privChat', setInterval('toggleText(window.parent.document.getElementById("lblIn"))', 400));
				isFlashing = true;
			}
		}
	}
}

function fnGetInstantMessages()
{
	try
	{
		if( document.getElementById('chatStream') )
		{
			document.getElementById('chatStream').dataurl = '/Streams/InstantMessage.aspx?id=' + mid + '&msgid=' + msgid;
			document.getElementById('chatStream').reset();		
		}
	}
	catch(e)
	{
		try
		{
			lastAutoError = e
			parent.fnSetPollValue('lae', 'fnGetInstantMessages\nMsg' + lastAutoError.message);
		}
		catch(e){}	
	}
}

var tHdl, c, o;
var requiresUpdate = true;
var lastManualRefresh = 'none';
var lastAutoRefresh = 'none';
var lastAutoError = 'none';

function fnManualRefresh()
{
	if( requiresUpdate )
	{
		try
		{
			lastManualRefresh = new Date();
			parent.fnSetPollValue('lmr', lastManualRefresh);
		}
		catch(e){}
		location.reload(false);
	}
}

function fnInstantMessage(rs)
{
	if( !rs.EOF )
	{
		requiresUpdate = false;
		var chats = -1;
		try
		{
			msgid = rs.fields("msg").value;
			rs.moveNext();
			chats = rs.fields("msg").value;
			rs.moveNext();
		}
		catch(e) 
		{
			try
			{
				lastAutoError = e
				parent.fnSetPollValue('lae', 'fnInstantMessage.1\n' + lastAutoError.message);
			}
			catch(e){}
			var err = true; 
		}
		try
		{
			try
			{
				lastAutoRefresh = new Date();
				parent.fnSetPollValue('lar', lastAutoRefresh);
			}
			catch(e){}
			
			var a = new Array(10), i = 0, n = false;
			while( !rs.EOF )
			{
				n = true;
				var o = document.createElement('span');
				o.style.fontSize = "8pt";
				o.innerHTML = rs.fields("msg").value;
				if(document.getElementById('instantMessage').hasChildNodes()){
					document.getElementById('instantMessage').insertBefore(o,document.getElementById('instantMessage').childNodes[0]);
				}
				else{
					document.getElementById('instantMessage').insertBefore(o);
				}
				a[i] = o;
				rs.moveNext();
			}
			if( n == true ){
				fnInitFlashText(a);
				fnPlaySound(sound_pref);
			}
		}
		catch(e) 
		{
			try
			{
				lastAutoError = e
				parent.fnSetPollValue('lae', 'fnInstantMessage.2\n' + lastAutoError.message);
			}
			catch(e){}
		}
		fnShowPrivateChats( chats );
	}
}

