/*
 * Vymena obrazku s udanim jen jeho jmena s preload
 * format obrazku OVER: name.ext, OUT: nameo.ext
 * $Id: functions.js,v 1.19 2010-10-21 12:12:34 petr Exp $
*/

var old_name;

function Del() {
	return confirm("Chcete data opravdu smazat?");
}

function DelAll() {
	q=confirm("POZOR! \nBudou nenavratne smazana data!");
	if(q) q=Del();
	return q;
	}

function Duplicate() {
	return confirm("Chcete data duplikovat?");
}

function openWIN(target,x,y) {
	popWin=window.open('',target,'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width='+x+',height='+y+',left=10,top=10');
	popWin.focus();
}

function openWinURL(target,url,x,y) {
	popWin=window.open(url,target,'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width='+x+',height='+y+',left=10,top=10');
	popWin.focus();
}

function openIFrame(target, w, h) {
	obj = new getObj(target);
	if (obj!='undefined') {
		var inhtml = '';
		inhtml = '<iframe name="' + target + '" src="" ';
		inhtml = inhtml + 'width="' + w + '" height="' + h + '" ';
		inhtml = inhtml + 'frameborer="1" ';
		inhtml = inhtml + '>' + '<' + '/iframe>';
		obj.innerHTML = inhtml;
	}
}

function getObj(name) {
	 return document.getElementById(name);
}

function priceWin(id)
{
	openWinURL('company_price_' + id, '../admin/?acc=company_price&load=' + id, 600, 450);
}

var obj = null;

function display_swap( id ) {
	obj = getObj(id);
	if (obj!='undefined' && obj!=null) {
		if (obj.style.display == 'none') {
			obj.style.display = 'block';
		} else {
			obj.style.display = 'none';
		}
	}
}

function cssHandler() {

	this.hide = function (id) {
		if (this.last!='undefined' && this.last!=null) {
			this.last.style.display = 'none';
			if (this.last.id == id) {
				this.last = null;
				return 0;
			}
			this.last = null;
		}
		if (id) {
			this.last = getObj(id);
			this.hide();
		}
		return id;
	}

	this.swap = function (id) {
		if (this.hide(id)) {
			this.show(id);
		}
	}

	this.show = function (id) {
		this.last = getObj(id);
		// polozky na prave strane
		var x;
		x = document.width - this.last.parentNode.offsetLeft;
		if (x < 300) {
			this.last.style.left = (this.last.parentNode.offsetLeft - x)+'px';
		}
		this.last.style.display = 'block';
		return true;
	}
	this.last = null;
}

var swapInfo = new cssHandler();

var rCal = {
	init: function(id, date) {
		if (this.visible) {
			this.hide(id);
			return;
		}
		this.get(id, date);
	},
	get: function(id, date) {
		$(id+'_cal').load('./?acc=creq_calendar&id='+id+'&date='+date+'&req=static');
		this.show(id);
	},
	set: function(id, date) {
		$(id).value=date;
		this.hide(id)
	},
	hide: function(id) {
		$(id+'_cal').innerHTML='';
		$(id+'_cal').style.display = 'none';
		this.visible=false;
	},
	show: function(id) {
		$(id+'_cal').style.display = 'block';
		this.visible=true;
	},
	visible: false
};


function getContent(url, target) {
	return getRequest(url, target);
}

// ----- Otevre requestem dialogove okno -----
function dialog(url, target, width, height) {
	var w = width ? width : 300;
	var h = height ? height : 100;
	var winw = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
	var winh = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
	var ofsx = window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft;
	var ofsy = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
	var popup = new Element('div',{ id:target });
	popup.inject(document.body);
	popup.style.left = (Math.round((winw-w)/2)+ofsx)+'px';
	popup.style.top = (Math.round((winh-h)/2)+ofsy)+'px';
	if(width) popup.style.width = w+'px';
	if(height) popup.style.height = h+'px';
	popup.style.minWidth = '150px';
	popup.style.minHeight = '50px';
	popup.load(url);
}

