/*
 DHTML popup 1.0
 (C) by Marcin Nowak           www.chomik.net   www.wyprawa.net
 Some rights reserved
 This code is available under the following licence: http://creativecommons.org/licenses/by-sa/3.0/
 You are free:
 * to Share — to copy, distribute and transmit the work
 * to Remix — to adapt the work

 Under the following conditions:
 * Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
 * Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.

 * For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
 * Any of the above conditions can be waived if you get permission from the copyright holder.
 * Nothing in this license impairs or restricts the author's moral rights.  */


var pu_dragg = false;
var pu_target;
var pu_dX;
var pu_dY;
var pu_fcOk;
var pu_fcCnc;

function pu_msUp(e) {
  if (!pu_dragg) return;
  pu_dragg = false;
}

function pu_msDwn(e) {
  pu_dragg = true;

  var ie = window.event;
  pu_dX = (ie ? window.event.clientX : e.clientX) - pu_target.offsetLeft;
  pu_dY = (ie ? window.event.clientY : e.clientY) - pu_target.offsetTop;
}

function pu_msMv(e) {
  if (!pu_dragg) return;

  var ie = window.event;
  var mouseX = ie ? window.event.clientX : e.clientX;
  var mouseY = ie ? window.event.clientY : e.clientY;

  pu_target.style.left = (mouseX-pu_dX)+'px';
  pu_target.style.top  = (mouseY-pu_dY)+'px';
}

function pu_Ok() {
	document.body.removeChild(pu_target);
	if (pu_fcOk)
	  pu_fcOk();
}

function pu_Cnc() {
  document.body.removeChild(pu_target);
	if (pu_fcCnc)
	  pu_fcCnc();
}
	
function pu_YN(title, html, fcOk, fcCnc) {

  if (document.getElementById('puYN') || document.getElementById('puOK'))
	  return;

	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', 'puYN');
	pu_target = newDiv;

	if (!title)
	title = "Komunikat";

	newDiv.innerHTML = '<div id="pu_title" onmousedown="pu_msDwn(event)" onmousemove="pu_msMv(event)" onmouseup="pu_msUp(event)">'+title+'</div>';
	newDiv.innerHTML = newDiv.innerHTML + '<table id="pu_msg"><tr><td valign="middle">'+html+'</td></tr></table>';
	newDiv.innerHTML = newDiv.innerHTML + '<div id="pu_buts"><img src="ok.png"><img src="cancel.png"></div></div>';
	document.body.appendChild(newDiv);
	var lewe = document.body.clientWidth;
	lewe = (lewe / 2) - 175;
	var gorne = document.body.clientHeight;
	gorne = (gorne / 2) - 92;
	newDiv.style.left = lewe;
	newDiv.style.top = gorne;

	//find ok buton, assign onOk function
	var _ok = document.getElementById("pu_buts").firstChild;
	_ok.onclick = pu_Ok;
	pu_fcOk = fcOk;
	//if (_ok.captureEvents) _ok.captureEvents(Event.CLICK);

	//find cancel buton, assign onCancel function
	var _cancel = _ok.nextSibling;
	_cancel.onclick = pu_Cnc;
	pu_fcCnc = fcCnc;	
	//if (_cancel.captureEvents) _cancel.captureEvents(Event.CLICK);

	//find bar, assign draging functions
	var _bar = document.getElementById("pu_title");
	_bar.onmouseDown = pu_msDwn;
	// if (_bar.captureEvents) _bar.captureEvents(Event.CLICK);
	_bar.onmouseDown = pu_msUp;
	// if (_bar.captureEvents) _bar.captureEvents(Event.CLICK);
	_bar.onmouseDown = pu_msMv;
	// if (_bar.captureEvents) _bar.captureEvents(Event.CLICK);

	//show window
	newDiv.style.display = 'block';
} 

function pu_null(){
}

function pu_OK(title, html, fcOk) {

	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', 'puOK');
	pu_target = newDiv;

	if (!title)
	title = "Komunikat";

	newDiv.innerHTML = '<div id="pu_title" onmousedown="pu_msDwn(event)" onmousemove="pu_msMv(event)" onmouseup="pu_msUp(event)">'+title+'</div>';
	newDiv.innerHTML = newDiv.innerHTML + '<table id="pu_msg"><tr><td valign="middle">'+html+'</td></tr></table>';
	newDiv.innerHTML = newDiv.innerHTML + '<div id="pu_buts"><img src="/lib/DHTMLpopup/ok.png"></div></div>';
	document.body.appendChild(newDiv);
	var lewe = document.body.clientWidth;
	lewe = (lewe / 2) - 175;
	var gorne = document.body.clientHeight;
	gorne = (gorne / 2) - 92;
	newDiv.style.left = lewe;
	newDiv.style.top = gorne;

	//find ok buton, assign onOk function
	var _ok = document.getElementById("pu_buts").firstChild;
	  _ok.onclick = pu_Ok;
	if (fcOk = "")
	  pu_fcOk = pu_null;
	else
	  pu_fcOk = fcOk;

	//find bar, assign draging functions
	var _bar = document.getElementById("pu_title");
	_bar.onmouseDown = pu_msDwn;
	// if (_bar.captureEvents) _bar.captureEvents(Event.CLICK);
	_bar.onmouseDown = pu_msUp;
	// if (_bar.captureEvents) _bar.captureEvents(Event.CLICK);
	_bar.onmouseDown = pu_msMv;
	// if (_bar.captureEvents) _bar.captureEvents(Event.CLICK);

	//show window
	newDiv.style.display = 'block';
}
