var border1 = "1px solid #444444";
var border2 = "1px solid white";
var padding1 = "6px";
var padding2 = "5px";

function button_click(button) {
	with (button.style) {
		paddingLeft = padding1;
		paddingTop = padding1;
		paddingRight = padding2;
		paddingBottom = padding2;
		borderLeft = border1;
		borderTop = border1;
		borderRight = border2;
		borderBottom = border2;
	}
	button_clear_sel();
}

function button_release(button) {
	with (button.style) {
		paddingLeft = padding2;
		paddingTop = padding2;
		paddingRight = padding1;
		paddingBottom = padding1;
		borderRight = border1;
		borderBottom = border1;
		borderLeft = border2;
		borderTop = border2;
	}
	button_clear_sel();
}

function button_clear_sel() {
	if(document.selection)
		document.selection.empty();
}

function resizeDialogToContent()
{
	// resize window so there are no scrollbars visible
	var dh = window.dialogHeight;
	while (isNaN(dh))
	{
	  dh = dh.substr(0,dh.length-1);
	}
	var dw = window.dialogWidth;
	while (isNaN(dw))
	{
	  dw = dw.substr(0,dw.length-1);
	}
	//alert('dh:' + dh + ' window.dialogHeight:' + window.dialogHeight + ' this.document.body.clientHeight:' + this.document.body.clientHeight);
	difh = dh - this.document.body.clientHeight;
	difw = dw - this.document.body.clientWidth;

	//window.dialogHeight = this.document.body.scrollHeight+difh+'px';
	//window.dialogWidth = this.document.body.scrollWidth+difw+'px';
	window.dialogHeight = this.document.body.scrollHeight+difh+'px';
	window.dialogWidth = this.document.body.scrollWidth+difw+'px';
	//alert(window.dialogWidth);
}

function checkAll(form, what) {
	for (var i = 0; i < form.elements.length; i++)	{
		var e = form.elements[i];
		if (e.type == 'checkbox')
			e.checked = form[what.name].checked;
	}
}

function search(http_root) {
	if(search_q.value)
		location.replace(http_root + '/search/' + search_q.value)
	else {
		alert('J�ievada mekl�jamie v�rdi!');
		search_q.focus();
	}
}

function image_get_path()
{
	var editor = 'ed';
	var w = 350;
	var h = 400;
	
  var l = (screen.width - w) / 2;
  var t = (screen.height - h) / 2;

	window.open(editor_root + 'getfile/' + editor + '/banner/', 'insert_image', 'fullscreen=0,toolbar=0,status=1,scrollbars=1,menubar=0,location=0,resizable=0,channelmode=0,directories=0,width=' + w + ',height=' + h + ',top=' + t +',left=' + l);
}

function td_mouse(id, className)
{
	var obj = document.getElementById(id);
	if(obj)
	{
		obj.className = className;
	}
}

function changeIebr(form)
{
	ie_d = parseInt(form.elements["data[in_d]"].value);
	iz_d = parseInt(form.elements["data[out_d]"].value);
	ie_m = parseInt(form.elements["data[in_m]"].value);
	iz_m = parseInt(form.elements["data[out_m]"].value);
	ie_g = parseInt(form.elements["data[in_y]"].value);
	iz_g = parseInt(form.elements["data[out_y]"].value);

	if(ie_d>iz_d && ie_m>=iz_m && ie_g>=iz_g)
	{
		if(ie_d<31)
		{
			form.elements["data[out_d]"].value=ie_d+1;
		} else {
			if(ie_m<11)
			{
				form.elements["data[out_d]"].value=1;
				form.elements["data[out_m]"].value=ie_m+1;
				changeIebr(form);
			} else {
				form.elements["data[out_d]"].value=ie_d;
				form.elements["data[out_m]"].value=ie_m;
			}
		}
	} else if(ie_m>iz_m && ie_g>=iz_g) {
		if(ie_m<12)
		{
			form.elements["data[out_m]"].value=ie_m;
		} else {
			form.elements["data[out_m]"].value=1;
			form.elements["data[out_y]"].value=ie_g;
		}
		changeIebr(form);
	} else if(ie_g>iz_g) {
		form.elements["data[out_y]"].value=ie_g;
	}
}

function pop(theURL,w,h,name,feat)
{
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2;

	if(!feat)
	{
		feat = 'fullscreen=0,toolbar=0,status=0,scrollbars=0,menubar=0,location=0,resizable=0,channelmode=0,directories=0';
	}

	feat += ',width=' + w + ',height=' + h + ',top=' + t +',left=' + l;

	window.open(theURL, name, feat);
}


