
var dragHotSpot = null;
function setDragHotSpot(hotSpot)
{
if ( hotSpot[0] == -1 )
return;
dragHotSpot = hotSpot;
var tblMainNav = document.getElementById('tblMainNav');
var divChatWindow = document.getElementById('divChatWindow');
if ( dragDiv != null )
{
tblMainNav.removeChild(dragDiv);
}
var rect = dragHotSpot;
var pos = getElemPosition(divChatWindow);
dragDiv = document.createElement('div');
dragDiv.style.position = 'absolute';
tblMainNav.appendChild(dragDiv);
dragDiv.style.zIndex = 90001;
dragDiv.style.left = pos[0] + 'px';
dragDiv.style.top = pos[1] + rect[1] + 'px';
dragDiv.style.width = rect[2]+ rect[0] - 30 + 'px';
dragDiv.style.height = rect[3] + 'px';
dragDiv.style.backgroundColor = '#FFFFFF';

dragDiv.style.cursor = 'pointer';
dragDiv.style.border = 'solid 1px #000000';
setElementTransparency(dragDiv, 0);
dragDiv.onmousedown = function(e) 
{ 
var pos = getElemPosition(dragDiv);
var width = dragDiv.offsetWidth;
var height = dragDiv.offsetHeight;
dragDiv.OriginalPos = pos;
dragDiv.OriginalWidth = width;
dragDiv.OriginalHeight = height;
dragDiv.style.top = dragDiv.OriginalPos[1] - 80 + 'px';
dragDiv.style.height = height + 160 + 'px';
dragDiv.style.left = dragDiv.OriginalPos[0] - 80 + 'px';
dragDiv.style.width = width + 130 + 'px';
bDragging = true;
}
dragDiv.onmousemove = function(e)
{
if ( bDragging )
{
var left = document.CurrentMouseX - document.LastMouseX;
var top = document.CurrentMouseY - document.LastMouseY;
var oldLeft = getElemPosition(dragDiv)[0];
var oldTop = getElemPosition(dragDiv)[1];
dragDiv.style.left = oldLeft + left + 'px';
dragDiv.style.top = oldTop + top + 'px';


var newLeft = oldLeft + left + 80;
var newTop = oldTop + top + 80;
divChatWindow.style.left = newLeft + 'px';
divChatWindow.style.top = newTop + 'px';
_fnSetCookie('ChatLocation', newLeft + ',' + newTop, 1);
}
}
function stopDragging()
{
if ( bDragging) 
{
var rect = dragHotSpot;
var pos = getElemPosition(divChatWindow);
dragDiv.style.left = pos[0] + 'px';
dragDiv.style.top = pos[1] + rect[1] + 'px';
dragDiv.style.width = rect[2]+ rect[0] - 30 + 'px';
dragDiv.style.height = rect[3] + 'px';
bDragging = false;
}
}
dragDiv.onmouseout = function()
{
if ( bDragging )
stopDragging();
}
dragDiv.onmouseover = function()
{
if ( bDragging )
stopDragging();
}
dragDiv.onmouseup = function()
{
if ( bDragging )
stopDragging();
}
}
var ChatHeight = '200px';
function ShowChat(bReload)
{
var divChatWindow = document.getElementById('divChatWindow');
divChatWindow.style.display = '';
divChatWindow.style.zIndex = 90000;
if ( bReload )
{
var chatFrame = document.getElementById('chatFrame');

chatFrame.src = chatURL;
}
if ( _fnGetCookie('ChatLocation') != null && _fnGetCookie('ChatLocation') != 'null' )
{
var pos = _fnGetCookie('ChatLocation');
var sPos = new String(pos);
if ( sPos && sPos != 'null' )
{
var left = sPos.split(',')[0] || 0;
var top = sPos.split(',')[1] || 0;
if ( left < 0 )
left = 0;
if ( top < 0 )
top = 0;
divChatWindow.style.left = left + 'px';
divChatWindow.style.top = top + 'px';
}
}
else
{
var tblMainNav = document.getElementById('tblMainNav');
divChatWindow.style.left = getElemPosition(tblMainNav)[0] + tblMainNav.offsetWidth / 2 - divChatWindow.offsetWidth / 2 + 'px';
divChatWindow.style.top = getElemPosition(tblMainNav)[1] + 20 + 'px';
}
var chatFrame = document.getElementById('chatFrame');
}
var dragDiv = null;
var bDragging = false;
function globalMouseMove(e)
{
document.LastMouseX = document.CurrentMouseX;
document.LastMouseY = document.CurrentMouseY;
if ( document.all ) 
{
document.CurrentMouseX = event.clientX + document.body.scrollLeft;
document.CurrentMouseY = event.clientY + document.body.scrollTop;
}
else
{
document.CurrentMouseX = e.pageX;
document.CurrentMouseY = e.pageY;
}
}
var oldFunc = document.onmousemove;
var newFunc = function(e)
{
if ( oldFunc )
oldFunc(e);
globalMouseMove(e);
}
document.onmousemove = newFunc;
function setElementTransparency(elem, opacity)
{
if ( typeof elem.style.filter != 'undefined' )
elem.style.filter = 'alpha(opacity = ' + ( opacity ) + ');';
else if (typeof elem.style.mozOpacity != 'undefined')
elem.style.mozOpacity = opacity / 100;
else
elem.style.opacity = opacity / 100;
}
var dragDiv = null;
function StartDrag()
{
dragDiv = document.createElement('div');
dragDiv.appendChild(document.createTextNode('&nbsp; '));
document.body.appendChild(dragDiv);
dragDiv.style.backgroundColor = '#FFFFFF';
dragDiv.style.position = 'absolute';
dragDiv.style.left = '0px';
dragDiv.style.top = '0px';
dragDiv.style.width = '500px';
dragDiv.style.height = '500px';
dragDiv.onmouseup = function() { alert('up!'); EndDrag(); }
setElementTransparency(dragDiv, 20);
}
function EndDrag()
{
document.body.removeChild(dragDiv);
}
function getElemPosition(elem)
{
var left = 0;
var top = 0;
do 
{
left += elem.offsetLeft;
top += elem.offsetTop;
elem = elem.offsetParent;
} while ( elem != null )
return [left,top];
}
function ResizeMe(iWidth,iHeight)
{
if ( iWidth > 0 && iHeight > 0 )
{
ChatHeight = iHeight;
ChatHeight = iWidth;
var divChatWindow = document.getElementById('divChatWindow');
divChatWindow.style.height = iHeight + 'px';
divChatWindow.style.width = iWidth + 'px';
var chatFrame = document.getElementById('chatFrame');
chatFrame.style.height = iHeight + 'px';
chatFrame.style.width = iWidth + 'px';
}
}
function HideChat()
{
var divChatWindow = document.getElementById('divChatWindow');
divChatWindow.style.display = 'none';
var chatFrame = document.getElementById('chatFrame');
setTimeout(resetChat, 1000);
}
function resetChat()
{
try
{
var chatFrame = document.getElementById('chatFrame');
chatFrame.src = chatFrameSrc;
}
catch(e)
{
}
}
function _fnSetCookie(sName, sValue, days)
{
if (days) 
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else 
var expires = "";
document.cookie = sName+"="+sValue+expires+"; path=/";
}
function _fnGetCookie(sName)
{
var nameEQ = sName + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) 
{
var c = ca[i];
while (c.charAt(0)==' ') 
c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) 
return c.substring(nameEQ.length,c.length);
}
return null;
}
function _fnDeleteCookie(sName)
{
this.SetCookie(sName, '', -1);
}
function changeClass(obj)
{
    obj.setAttribute("className", "Active");
    obj.parentElement.setAttribute("class", "Active");
}  