function centerWindow(theURL) 
{               
	var wi;
	var he;
	wi = "840";
	he = "630";
	var x=(screen.width-wi)/2;
	var y=(screen.height-he)/2;   
   	window.open(theURL,'Okno','height='+he+',width='+wi+',top='+y+',left='+x+',scrollbars=yes,toolbar=no,resizable=yes,menubar=no,status=no,directories=no,location=no');
}           

var isOpen = '';
var selection = new Object();

function popup(id)
{
	if(!isOpen)
	{
		isOpen = id;
		div = document.getElementById(id);
		div.style.display = 'block';
		/*div.parentNode.class = 'menuitemactive';*/
	}else if(isOpen == id){
		hide(id);
	}
}

function close_popup()
{
	if(isOpen)
	{
		hideMenu(isOpen);
	}
}

function hideMenu(id)
{
	isOpen = '';
	div = document.getElementById(id);
	
	div.style.display = 'none';	
}




function we_itemsDate ()
{
	var dnes = new Date();
	var actualTime;
	
	var year = dnes.getFullYear();
	var month = dnes.getMonth();
	var day = dnes.getDate();
	var hour = dnes.getHours();
	var minute = dnes.getMinutes();
	var second = dnes.getSeconds();

	month = month +1;


	if (month < 10)
	{
		month = "0" + month;
	}
	
	if (day < 10)
	{
		day = "0" + day;
	}
	
	if (hour < 10) {
		hour = "0" + hour;
	}
	
	if (minute < 10)
	{
		minute = "0" + minute;
	}
	
	if (second < 10)
	{
		second = "0" + second;
	}

	actualTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
	document.getElementById('itemsDate').value = actualTime;
}





function addPrice(op11, op12, op2) {
	op11 = Number(op11);
	op12 = Number('0.'+op12);
	op2 = Number(op2);
	return op11 + op12 + op2;
}

function multiplyPrice(op11, op12, op2) {
	op11 = Number(op11);
	op12 = Number('0.'+op12);
	op2 = Number(op2);
	return op11 * op2 + op12 * op2;
}

function dividePrice(op11, op12, op2) {
	op11 = Number(op11);
	op12 = Number('0.'+op12);
	op2 = Number(op2);
	return Number(((op2 == 0)? 0 : op11 / op2) + ((op2 == 0)? 0 : op12 / op2));
}

function format_prices() {
	var priceForm = document.getElementById('form');
	var regExp = new RegExp('([0-9]+)(,|\.)?([0-9]*)');

	var arr = regExp.exec(priceForm.price.value);

	if(arr != null && arr[1] != null){
		priceForm.price.value = Number(arr[1]+'.'+arr[3]).toFixed(2);
	}else{
		priceForm.price.value = '-';
	}

	arr = regExp.exec(priceForm.price_with_vat.value);

	if(arr != null && arr[1] != null){
		priceForm.price_with_vat.value = Number(arr[1]+'.'+arr[3]).toFixed(2);
	}else{
		priceForm.price_with_vat.value = '-';
	}
}

function eval_price(source) {
	var lastInput = null;
	var priceForm = document.getElementById('form');
	var regExp = new RegExp('([0-9]+)(,|\.)?([0-9]*)');

	switch(source)
	{
		case 0:
		{
			var arr = regExp.exec(priceForm.price.value);

			if(arr != null && arr[1] != null) {
				var num = Number(arr[1]+'.'+arr[3]).toFixed(2);
				arr = String(num).split('.');
				var diff = multiplyPrice(arr[0], arr[1], priceForm.vat.value * 0.01);
				priceForm.vatDifferent.value = diff.toFixed(2);
				priceForm.price_with_vat.value = addPrice(arr[0], arr[1], priceForm.vatDifferent.value).toFixed(2);
			}else{
				priceForm.vatDifferent.value = '-';
				priceForm.price_with_vat.value = '-';
			}
			lastInput = 0;
		}
		break;
		case 1:
		{
			var arr = regExp.exec(priceForm.price_with_vat.value);

			if(arr != null && arr[1] != null) {
				var num = Number(arr[1]+'.'+arr[3]).toFixed(2);
				arr = String(num).split('.');
				var diff = dividePrice(arr[0], arr[1], Number(priceForm.vat.value) + 100) * priceForm.vat.value;
				priceForm.vatDifferent.value = diff.toFixed(2);
				priceForm.price.value =  addPrice(arr[0], arr[1], -diff).toFixed(2);
			}else{
				priceForm.vatDifferent.value = '-';
				priceForm.price.value = '-';
			}
			lastInput = 1;
		}
		break;
		case 2:
		{
			var lastInput2 = lastInput;
			switch(lastInput) {
				case 0: eval_price(0);
				break;
				case 1: eval_price(1);
				break;
				default: eval_price(0);
			}
			lastInput = lastInput2;
		}
	}
}







function format_originalPrices() {
	var priceForm = document.getElementById('form');
	var regExp = new RegExp('([0-9]+)(,|\.)?([0-9]*)');

	var arr = regExp.exec(priceForm.originalPrice.value);

	if(arr != null && arr[1] != null){
		priceForm.originalPrice.value = Number(arr[1]+'.'+arr[3]).toFixed(2);
	}else{
		priceForm.originalPrice.value = '-';
	}

	arr = regExp.exec(priceForm.originalPrice_with_vat.value);

	if(arr != null && arr[1] != null){
		priceForm.originalPrice_with_vat.value = Number(arr[1]+'.'+arr[3]).toFixed(2);
	}else{
		priceForm.originalPrice_with_vat.value = '-';
	}
}

function eval_originalPrice(source) {
	var lastInput = null;
	var priceForm = document.getElementById('form');
	var regExp = new RegExp('([0-9]+)(,|\.)?([0-9]*)');

	switch(source)
	{
		case 0:
		{
			var arr = regExp.exec(priceForm.originalPrice.value);

			if(arr != null && arr[1] != null) {
				var num = Number(arr[1]+'.'+arr[3]).toFixed(2);
				arr = String(num).split('.');
				var diff = multiplyPrice(arr[0], arr[1], priceForm.vat.value * 0.01);
				priceForm.originalPrice_vatDifferent.value = diff.toFixed(2);
				priceForm.originalPrice_with_vat.value = addPrice(arr[0], arr[1], priceForm.originalPrice_vatDifferent.value).toFixed(2);
			}else{
				priceForm.originalPrice_vatDifferent.value = '-';
				priceForm.originalPrice_with_vat.value = '-';
			}
			lastInput = 0;
		}
		break;
		case 1:
		{
			var arr = regExp.exec(priceForm.originalPrice_with_vat.value);

			if(arr != null && arr[1] != null) {
				var num = Number(arr[1]+'.'+arr[3]).toFixed(2);
				arr = String(num).split('.');
				var diff = dividePrice(arr[0], arr[1], Number(priceForm.vat.value) + 100) * priceForm.vat.value;
				priceForm.originalPrice_vatDifferent.value = diff.toFixed(2);
				priceForm.originalPrice.value =  addPrice(arr[0], arr[1], -diff).toFixed(2);
			}else{
				priceForm.originalPrice_vatDifferent.value = '-';
				priceForm.originalPrice.value = '-';
			}
			lastInput = 1;
		}
		break;
		case 2:
		{
			var lastInput2 = lastInput;
			switch(lastInput) {
				case 0: eval_originalPrice(0);
				break;
				case 1: eval_originalPrice(1);
				break;
				default: eval_originalPrice(0);
			}
			lastInput = lastInput2;
		}
	}
}



























function clock() 
{
	var dnes = new Date();
	var actualTime;
	var year = dnes.getFullYear();
	var month = dnes.getMonth();
	var day = dnes.getDate();	
	var hour = dnes.getHours();
	var minute = dnes.getMinutes();
	var second = dnes.getSeconds();

	month = month +1;

	if (month < 10) {
		month = "0" + month;
	}
	if (day < 10) {
		day = "0" + day;
	}
	if (hour < 10) {
		hour = "0" + hour;
	}
	if (minute < 10) {
		minute = "0" + minute;
	}
	if (second < 10) {
		second = "0" + second;
	}	
	actualTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
	document.getElementById('date').innerHTML = actualTime ;
	setTimeout("clock()",1000);
}

function selectKey() 
{
	/*document.getElementById('date')*/
		
}

/////////////////keywords////////////////////

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

var keywords = new Array();
var kwIds = new Array();
var kwText;

function highlightKeywords()
{
	if(!document.forms['kw'])
		return;

	var e = null;
	var checked = new Array();
	var kwReg = new RegExp('kw_(.+)');
	var match;
	var str = '';
	
	kwText = document.getElementById('kw_text');

	for(i = 0; i < document.forms['kw'].elements.length; i++)
	{
		e = document.forms['kw'].elements[i];
	
		if(e.name == 'checkedKeywords[]')
		{
			if(e.checked)
			{
				checked = checked.concat(e.value);
			}
		}
		else if(match = kwReg.exec(e.name))
		{
			keywords = keywords.concat(match[1]);
			kwIds = kwIds.concat(e.value);
		}
	}	
	
	var isChecked = false;
	var spans = new Array();
	
	for(i = 0; i < keywords.length; i++)
	{
			isChecked = false;
			
			for(j = 0; j < checked.length; j++)
			{							
				if(checked[j] == keywords[i])
				{
					isChecked = true;
					break;
				}			
			}									
	
			if(isChecked)
			{
				spans = getElementsByClassName(kwText, 'span', 'kw_'+kwIds[i]);
				
				for(j = 0; j < spans.length; j++)
				{
					spans[j].style.color = '#E26600';
				}
			}
	}
	
}

function switchKeyword(index)
{
	var checkbox = document.getElementById('kw_check_'+index);

	for(i = 0; i < keywords.length; i++)
	{
		if(keywords[i] == checkbox.value)
		{
			index = i;
			break;		
		}
	}
	
	if(index === false)
		return;
	
	var spans = getElementsByClassName(kwText, 'span', 'kw_'+kwIds[index]);

	if(checkbox.checked)
	{
		for(i = 0; i < spans.length; i++)
		{
			spans[i].style.color='#E26600';
		}
	}else{
		for(i = 0; i < spans.length; i++)
		{
			spans[i].style.color='';
		}				
	}
}

