var dragdiv 	= null;
var dragFrame 	= null;
var dragFrameOrigin = null;
var dragx 	= 0;
var dragy 	= 0;
var posx 	= 0;
var posy 	= 0;

function draginit() {
	document.onmousemove 	= drag;
	document.onmouseup 		= dragstop;
}

function dragstart(element, frame) {
	dragdiv 	= element;
	
	dragx 		= posx - dragdiv.offsetLeft;
	dragy 		= posy - dragdiv.offsetTop;
	
	// ако имаме параметър frame генерираме iframe да скрива select-тите
	
	try
	{
		if( frame && dragFrameOrigin == null )
		{
			dragFrame = document.createElement('iframe');
			
			dragFrame.style.width 		= ( dragdiv.offsetWidth  - 5 )	+ "px";
			dragFrame.style.height 		= ( dragdiv.offsetHeight - 5 )	+ "px";
			dragFrame.style.position	= 'absolute';
			dragFrame.style.left 		= ( dragdiv.offsetLeft - 1 ) 	+ "px" ;
			dragFrame.style.top			=   dragdiv.offsetTop		 	+ "px" ;
			dragFrame.style.border		= '0px solid red';
						
			document.getElementsByTagName('body')[0].appendChild( dragFrame );
			
			dragFrameOrigin = dragFrame;
		}
		
		if( dragFrame == null && dragFrameOrigin != null )
		{
			dragFrame = dragFrameOrigin ;
		}
		
	}catch( e ){ dragFrame = null; } 
	
	
}

function dragstop() {
	dragdiv		= null;
	dragFrame 	= null;
}

function drag(ev) {
	posx = document.all ? window.event.clientX : ev.pageX;
	posy = document.all ? window.event.clientY : ev.pageY;
	
	if(dragdiv != null) {
		dragdiv.style.left 	= (posx - dragx) + "px";
		dragdiv.style.top 	= (posy - dragy) + "px";
	}
	
	if( dragFrame != null ){
		dragFrame.style.left 	= ( posx - dragx ) + "px";
		dragFrame.style.top		= ( posy - dragy ) + "px";
	}
	
}

function show_hide_div (div_name, show_hide_param, top, left) {
	var oDiv = document.getElementById(div_name);
	
	
try {
		show_background_div (show_hide_param);	
	}
catch (e){};

	if (show_hide_param!='none') { 
		oDiv.style.zIndex 	= "49"; 
		oDiv.style.border 	= "0.1mm solid black";
		oDiv.style.background 	= "#efefef";
		oDiv.style.position	= "absolute";
		oDiv.style.filter  	= "progid:DXImageTransform.Microsoft.dropshadow(OffX=5, OffY=5, Color='#cccccc, Positive='true')";
		if (typeof (top) == 'undefined')
			oDiv.style.top 		= ((document.body.offsetHeight - parseInt(oDiv.style.height)) / 2)+"px";
    	else
    		oDiv.style.top 		= top+"px";
    		
    	if (typeof (left) == 'undefined')	
			oDiv.style.left 	= ((document.body.offsetWidth  - parseInt(oDiv.style.width)) / 2)+"px";
		else
			oDiv.style.left 	= left+"px";
			
		oDiv.style.display 	= 'inline';   	
		
		if( dragFrameOrigin != null )
		{
			dragFrameOrigin.style.left 		= oDiv.style.left	;
			dragFrameOrigin.style.top 		= oDiv.style.top	;
			dragFrameOrigin.style.display 	= 'inline'			;
		}
		
	} else {
		
		oDiv.style.display 	= 'none';
		
		if( dragFrameOrigin != null )
			dragFrameOrigin.style.display = 'none';
	}		
		
	return true;
}

function show_background_div (show_hide_param) {
	
	var opacity = 10;
	var oBgIframe = document.getElementById("@bgiframe@");
	
	if( !oBgIframe ){
		
		
		oBgIframe1 					= document.createElement("iframe");
		oBgIframe1.id 				= "@bgiframe1@";
		oBgIframe1.style.background = "white";
		oBgIframe1.style.position	= "absolute";
		oBgIframe1.style.width 		= document.body.scrollWidth;
		oBgIframe1.style.height 	= document.body.scrollHeight;
		oBgIframe1.style.top 		= 0;
		oBgIframe1.style.left 		= 0;
		oBgIframe1.style.zIndex 	= 48;
		oBgIframe1.style['filter']	= "alpha(opacity="+opacity+")";
		oBgIframe1.style['-moz-opacity'] = "0."+opacity; 
		oBgIframe1.style['opacity'] = "0."+opacity; 
				
		document.body.appendChild(oBgIframe1);	
		
		oBgIframe 					= document.createElement("div");
		oBgIframe.id 				= "@bgiframe@";
		oBgIframe.style.background 	= "black";
		oBgIframe.style.position	= "absolute";
		oBgIframe.style.width 		= document.body.scrollWidth;
		oBgIframe.style.height 		= document.body.scrollHeight;
		oBgIframe.style.top 		= 0;
		oBgIframe.style.left 		= 0;
		oBgIframe.style.zIndex 		= 48;
		oBgIframe.style['filter']	= "alpha(opacity="+opacity+")";
		oBgIframe.style['-moz-opacity'] = "0."+opacity; 
		oBgIframe.style['opacity'] 		= "0."+opacity; 
				
		document.body.appendChild(oBgIframe);				
	}
	if( oBgIframe  )  oBgIframe.style.display = show_hide_param;	
	if( oBgIframe1 ) oBgIframe1.style.display = show_hide_param;	
	
}
