// ==================================================
// $id: popdiv, $ver: 0.05, $last: 05.10.2008    Exp$
// $dsc: popup DIV instead of popup window
// $seealso: functions.js, dragdrop.js, popdiv.css, popdiv.inc.php
// ==================================================

// settings
var picdir = '/images';

// --------------------------------------------------
// CloseOnKeyPress()
// --------------------------------------------------
var CloseOnKeyPress = function(e) {
	if(!e) e = window.event
	if(!e) return;
	if(e.keyCode == 27) {
		_close();
	}
	removeEvent(document,"keypress",CloseOnKeyPress);
} // CloseOnKeyPress()

// --------------------------------------------------
// ck4popdiv()
// --------------------------------------------------
function ck4popdiv() {
	var popdiv = document.getElementById('popdiv');
	if (!popdiv) {
		popdiv = document.createElement("DIV");
		popdiv.id = 'popdiv';
		document.body.appendChild(popdiv);
	}
	popdiv.style.zIndex=100;
	popdiv.style.position='absolute';
	return popdiv;
} // ck4popdiv()

// --------------------------------------------------
// ck4iframe()
// --------------------------------------------------
function ck4iframe(div) {
	var frame = document.getElementById(div.id+"_frame");
	if (!frame) {
		frame = document.createElement("IFRAME");
		frame.src = "javascript:''";
		frame.id = div.id+"_frame";
		frame.style.position = 'absolute';
		frame.style.zIndex = div.style.zIndex-1;
		document.getElementById('popdiv').appendChild(frame);
	}
	frame.style.width = div.offsetWidth + "px";
	frame.style.height = div.offsetHeight + "px";
	frame.style.left = div.style.left;
	frame.style.top = div.style.top;
	frame.style.visibility = 'visible';
	return frame;
} // ck4iframe()

// ====================================================================================================
// --------------------------------------------------
// hide_loading()
// --------------------------------------------------
function hide_loading() {
	var div = ge('loading');
	if (!div) {
		div = window.parent.document.getElementById('loading');
	}
	if (div && div.style) {
		div.style.display = 'none';
	}

	var sh = ge('loading_shadow');
	if (!sh) {
		sh = window.parent.document.getElementById('loading_shadow');
	}
	if (sh && sh.style) sh.style.display = 'none';
} // hide_loading()

// --------------------------------------------------
// show_loading()
// --------------------------------------------------
function show_loading() {
	var div = ge('loading');
	if (!div) {
		div = document.createElement("div");
		div.id = 'loading';
		div.className = 'loading';
		document.body.appendChild(div);
	}
	div.style.top = 19+document.body.scrollTop+'px';
	div.style.right = 50+document.body.scrollLeft+'px';
	div.style.position = 'absolute';
	if (mybw.ie) {var pt=5;} 
	else {var pt=7;} 
	div.innerHTML = '<div style="padding-top:'+pt+'px"><img src="'+picdir+'/wait.gif" alt="" align=absmiddle> &nbsp; подождите ...</div>';
	div.onclick=hide_loading;

	div.style.display = 'block';

	//attach_shadow(div,5);
} // show_loading()

// --------------------------------------------------
// attach_shadow()
// --------------------------------------------------
function attach_shadow(div,dxShadow) {
	if (isNaN(dxShadow)) dxShadow = 5;
	if (dxShadow > 0) {
		var img = document.getElementById(div.id+'_shadow');
		if (!img) {
			if (mybw.ie) {
	 			img = document.createElement("DIV");
	 			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+picdir+"/shadow.png',sizingMethod='scale')";
			}
			else {
	 			img = document.createElement("IMG");
				img.src = picdir+'/shadow.png';
			}
			img.id = div.id+'_shadow';
			document.body.appendChild(img);
		}
		img.style.position = 'absolute';
		zIndex = parseInt(div.style.zIndex)-2;
		img.style.zIndex = zIndex;

		img.style.width = div.offsetWidth+'px';
		img.style.height = div.offsetHeight+'px';
		img.style.left = Math.round(parseInt(div.style.left))+dxShadow+'px';
		img.style.top = Math.round(parseInt(div.style.top))+dxShadow+'px';
		img.style.visibility = 'visible';
		img.style.display = 'block';
	}
} // attach_shadow()

// --------------------------------------------------
// popdivurl()
// --------------------------------------------------
function popdivurl(ww,wh,title,url) {
	// activate/create div
	var obj = ck4popdiv();
	obj.className = 'hide';

	// + added 05.10.2008 gene2109
	/*
	try {
	  ge(obj.id+'_frame').src = '/inc/showwait.php';
	  ge(obj.id+'_frame').style.display='block';
	}
	catch(e){}
	*/

	// + added 10.01.2008 11:52:01
	addEvent(document, "keypress", CloseOnKeyPress);

	var zIndex = parseInt(obj.style.zIndex);
	if (zIndex <= 0 || isNaN(zIndex)) {
		zIndex = 100;
		obj.style.zIndex = zIndex;
	}

	var scrbarw=mybw.ns6up&&mybw.win?14:mybw.ns6up&&!mybw.win?16:mybw.ns4?16:0

	scrw=(mybw.ie?document.body.clientWidth:innerWidth)-scrbarw

	scrh=(mybw.ie?document.body.clientHeight:innerHeight)

	var wx=(scrw/2)-(ww/2)-20 + document.body.scrollLeft;
	var wy=(scrh/2)-(wh/2)-40 + document.body.scrollTop;

	obj.style.position = 'absolute';
	obj.style.width = parseInt(ww)+'px';
	obj.style.height = parseInt(wh)+'px';
	obj.style.top=wy+'px';
	obj.style.left=wx+'px';
	obj.style.display='block';

	attach_shadow(obj,11);

	tobj = ge('tdiv');
	t="<div class='popdivtitle'>"+title+"</div>";
	if (tobj) tobj.innerHTML = t;

	show_loading();

	inobj = ge(obj.id+'_frame');
	inobj.style.display='block';

	addEvent(inobj,"load",hide_loading);

	inobj.src = url;
} // popdivurl()
