
var lastShowedFloatingItem = 0;
var lastShowedFloatingSubItem = 0;

function ShowPanel(id)
{
	var tr = document.getElementById(id);
	
	if(tr) {
		tr.style.display = tr.style.display == 'none' ? '' : 'none';	
		Set_Cookie('isShowedFAP',tr.style.display,0,"/","coldline.hu");
	}
	
}

function LoadFloatingContent(item,targetid,issubmenu,serv)
{
	var olditem = 0;

	if( issubmenu ) {
		olditem = lastShowedFloatingSubItem;	
	} else {	
		olditem = lastShowedFloatingItem;
	}
	
	if( item == olditem ) return;

	var url = 'http://'+serv+'.coldline.hu/cl_fap.php?contentid='+item;
	
	putcontentevalpre(url,targetid);
	
	var trnm = document.getElementById(item+"_menu");
	
	var trom = document.getElementById(olditem+"_menu");
	
	trnm.style.borderBottom = '';	
	trnm.style.textDecoration = "none";
	
	if(trom) { 
		trom.style.borderBottom = "1px solid black";
		trom.style.textDecoration = "underline";
	}
	
	if( issubmenu ) {
		lastShowedFloatingSubItem = item;
		Set_Cookie('lastShowedFAPSubMenu',item,0,"/","coldline.hu");
	} else {	
		lastShowedFloatingItem = item;
		Set_Cookie('lastShowedFAPMenu',item,0,"/","coldline.hu");
	}
	
	
	
}

function putcontentevalpre(url,itemid)
{
	var tr = document.getElementById(itemid);

	tr.innerHTML = '<div align="center"><br><br>Betöltés...<br><br><img src=\"http://services.coldline.hu/pics/preloader.gif\" alt="betolt"></div>';

	var xmlHttpObj=null;
	try { 
		xmlHttpObj=new XMLHttpRequest();
	} catch (e) { 
		try { 
			xmlHttpObj=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
			try {
				xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	if (xmlHttpObj==null) return;
	

	xmlHttpObj.onreadystatechange=function() {
		if(xmlHttpObj.readyState == 4) {
			tr.innerHTML = xmlHttpObj.responseText;
			tr.display = '';
			
			var re = /<script\b[\s\S]*?>([\s\S]*?)<\//ig;
			var match;
			while (match = re.exec(xmlHttpObj.responseText)) {
				eval(match[1]);
			}			
			
		}
		
	}


	xmlHttpObj.open("GET",url,true);
	xmlHttpObj.setRequestHeader('Content-Type','text/html');
	xmlHttpObj.send(null);

}


var elementPosX = 0;
var elementPosY = 0;

var _startX = 0; // mouse starting positions 
var _startY = 0; 
var _offsetX = 0; // current element offset 
var _offsetY = 0; 
var _dragElement; // needs to be passed from OnMouseDown to OnMouseMove 
var _oldZIndex = 0; // we temporarily increase the z-index during drag 
var _debug = -1; // makes life easier
var _dragClass = 'floating_assist_head';

InitDragDrop(); 

function InitDragDrop() 
{ 
	document.onmousedown = OnMouseDown; 
	document.onmouseup = OnMouseUp; 
}


function OnMouseDown(e)
{
    // IE is retarded and doesn't pass the event object
    if (e == null) 
        e = window.event; 
		
    
    // IE uses srcElement, others use target
    var target = e.target != null ? e.target : e.srcElement;
    
	if(_debug != -1) _debug.innerHTML = target.className == _dragClass ? 'draggable element clicked' : 'NON-draggable element clicked';
		
    // for IE, left click == 1
    // for Firefox, left click == 0
    if ((e.button == 1 && window.event != null || 
        e.button == 0) && 
        target.className == _dragClass)
    {
        // grab the mouse position
		
		target = target.parentNode;
		
        _startX = e.clientX;
        _startY = e.clientY;
        
        // grab the clicked element's position
        _offsetX = ExtractNumber(target.style.left);
        _offsetY = ExtractNumber(target.style.top);
        
        // bring the clicked element to the front while it is being dragged
        _oldZIndex = target.style.zIndex;
        target.style.zIndex = 10000;
        
        // we need to access the element in OnMouseMove
        _dragElement = target;

        // tell our code to start moving the element with the mouse
        document.onmousemove = OnMouseMove;
        
        // cancel out any text selections
        document.body.focus();

        // prevent text selection in IE
        document.onselectstart = function () { return false; };
        // prevent IE from trying to drag an image
        target.ondragstart = function() { return false; };
        
        // prevent text selection (except IE)
        return false;
    }
}

function OnMouseUp(e)
{
    if (_dragElement != null)
    {
        _dragElement.style.zIndex = _oldZIndex;

        // we're done with these events until the next OnMouseDown
        document.onmousemove = null;
        document.onselectstart = null;
        _dragElement.ondragstart = null;

        // this is how we know we're not dragging      
        _dragElement = null;
        
		Set_Cookie('fap_position_x',elementPosX,0,"/","coldline.hu");
		Set_Cookie('fap_position_y',elementPosY,0,"/","coldline.hu");
				
        if(_debug != -1) _debug.innerHTML = 'mouse up';
    }
}


function OnMouseMove(e)
{
    if (e == null) 
        var e = window.event; 

    // this is the actual &quot;drag code&quot;
    _dragElement.style.left = (_offsetX + e.clientX - _startX) + 'px';
    _dragElement.style.top = (_offsetY + e.clientY - _startY) + 'px';
    
	elementPosY = _dragElement.style.top;
	elementPosX = _dragElement.style.left;
	
    if(_debug != -1) _debug.innerHTML = '(' + _dragElement.style.left + ', ' + _dragElement.style.top + ')';   
}

function ExtractNumber(value)
{
    var n = parseInt(value);
	
    return n == null || isNaN(n) ? 0 : n;
}

// this is simply a shortcut for the eyes and fingers
function $(id)
{
    return document.getElementById(id);
}