// Hackers.lv Web Engine v2.0
//
// author: BigUgga
// http://www.hackers.lv/
// mailto:marrtins@hackers.lv

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];
		//document.write(e.name + '<br>');
		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 searcherKeyHandler(http_root) {
	if(event.keyCode == 13)
		search(http_root);
	event.returnValue = true;
}

function changeIebr(form)
{
	ie_d = parseInt(form.elements["data[iebrauksana_d]"].value);
	iz_d = parseInt(form.elements["data[izbrauksana_d]"].value);
	ie_m = parseInt(form.elements["data[iebrauksana_m]"].value);
	iz_m = parseInt(form.elements["data[izbrauksana_m]"].value);
	ie_g = parseInt(form.elements["data[iebrauksana_g]"].value);
	iz_g = parseInt(form.elements["data[izbrauksana_g]"].value);

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

function mod_hide(module_id)
{
	el = document.getElementById('sub_' + module_id);
	if(el)
		if(el.style.display != 'none')
			el.style.display = 'none';

	td = document.getElementById('td_' + module_id);
	td.className = 'TD-cat'; 
	//if(td.style.backgroundColor != '#BCBC96')
		//td.style.backgroundColor = '#BCBC96';
}

function mod_show(module_id)
{
	el = document.getElementById('sub_' + module_id);
	if(el)
		if(el.style.display != 'block')
			el.style.display = 'block';

	td = document.getElementById('td_' + module_id);
	//if(td.style.backgroundColor != '#9E9E77')
		//td.style.backgroundColor = '#9E9E77';
	td.className = 'TD-cat-active'; 
}
