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

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 checkType()
{
	var l_type=document.getElementsByName('data[l_type]');

	var l_spec=document.getElementById('data[l_spec]');
	var l_sertnr=document.getElementById('data[l_sertnr]');
	var l_sertexpire=document.getElementById('data[l_sertexpire]');

	l_spec.disabled=!l_type[0].checked;
	l_sertnr.disabled=!l_type[0].checked;
	l_sertexpire.disabled=!l_type[0].checked;
}

function _image_get_path(editor, imgSrc, doc)
{
	var form = doc['banner_edit'];

	if(form)
	{
		form.elements['data[b_imagepath]'].value = imgSrc;
	} else {
		var form = doc['article_editor'];
		if(form)
		{
			form.elements['data[art_imagepath]'].value = imgSrc;
		}
		/*
		 else {
			var form = doc['at_edit'];
			if(form)
			{
				form.elements['data[at_imagepath]'].value = imgSrc;
			}
		}*/
	}
	
	//form.elements["data[b_imagepath]"] = imgSrc;
}

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 menu_resize()
{
	var panel1 = document.getElementById('panel1');
	var panel2 = document.getElementById('panel2');

	menu_width = 0;
	menu_init('federacija', panel1);
	menu_init('turniri', panel1);
	menu_init('reitingi', panel1);
	menu_init('statistika', panel1);
	menu_init('abece', panel1);

	menu_width = 0;
	menu_init('klubi', panel2);
	menu_init('laukumi', panel2);
	menu_init('linki', panel2);
	menu_init('19bedrite', panel2);
	menu_init('forums', panel2);
}

function menu_show(ev)
{
	window.showMenu(this.menu, this.menu.startx, this.menu.starty);
}

function menu_hide(ev)
{
	window.hideMenu(this.menu);
}

function menu_init(id, panel_id, height)
{
	var mainmenu = document.getElementById('mainmenu_' + id);
	var menu = eval('window.menu_' + id);

	if(mainmenu && menu)
	{
		menu.startx = menu_width + panel_id.offsetLeft;
		menu.starty = panel_id.offsetTop + panel_id.offsetHeight;

		mainmenu.menu = menu;
		mainmenu.onmouseover = menu_show;
		//mainmenu.onmouseout = menu_hide;
	}

	menu_width += mainmenu.offsetWidth;
}

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);
}

function confirmAction(msg, href)
{
	if(confirm(msg))
	{
		location.href = href;
	}
}

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;
	}
}

