var tid, g_shop, g_productId, g_shopId, g_cnt;

function generateButtons()
{
	document.getElementById("message").innerHTML += 
		'	<div>' +
		'		<button onclick="changeTab(' + g_shopId + ', \'v\'); hideWindow();">Ano</button>' +
		'		<button onclick="xajax_pemar_add(\'' + g_shop + '\', ' + g_productId + ', ' + g_cnt + '); showWindow(\'<br /><br /><br />Zboží bylo přidáno do košíku.\', true);">Ne</button>' +
		'	</div>';
}

function generateButtonsStandard()
{
	document.getElementById("message").innerHTML += 
		'	<div>' +
/*		'		<img src="./template/templates/output/pemarcz/images/basket2.gif" alt="" />' +*/
		'		<br /><br /><button onclick="window.location.href = \'page-kosik\';">Přejít do košíku</button>' +
		'		<button onclick="hideWindow();">Pokračovat v nákupu</button>' +
		'		<!--<span onclick="hideWindow();">x</span>-->' +
		'	</div>';
}

function addToBasket(shop, basket, productId, shopId)
{
	var cnt = basket.parentNode.getElementsByTagName("input")[0].value;
	
	if (shop == "m")
	{
		g_shop = shop;
		g_productId = productId;
		g_shopId = shopId;
		g_cnt = cnt;
		
		showWindow("", false);
		xajax_pemar_message(g_productId);
	}
	else
	{
		showWindow("<br />Zboží bylo přidáno do košíku.", false);
		generateButtonsStandard();
		xajax_pemar_add(shop, productId, cnt);
	}
}

function showWindow(msg, isTimeout)
{
	var message = document.getElementById("message");
	
	var scr = {
			width: document.documentElement.clientWidth,
			height: document.documentElement.clientHeight,
			scrollbar: document.documentElement.scrollTop
	};
	
	message.innerHTML = msg;
	
	with (message.style)
	{
		display = "block";
		left = Math.round((scr.width - 400) / 2) + "px";
		top = Math.round((scr.height - (130 + 65)) / 2 + scr.scrollbar) + "px";
	};
	
	if (isTimeout)
	{
		if (tid)
			window.clearTimeout(tid);
		
		tid = window.setTimeout("hideWindow()", 2000);
	}
}

function hideWindow()
{
	if (tid)
		window.clearTimeout(tid);
	
	document.getElementById("message").style.display = 'none';
}





function getBoxes()
{
	var inputs = document.getElementById("kosik").getElementsByTagName("input");
	var boxes = new Array();
	
	for (var i = 0; inputs[i]; i++)
		if (inputs[i].getAttributeNode("type").value == "checkbox")
			if (inputs[i].checked)
				boxes.push(inputs[i].value);
	
	return boxes.join(",");
}

function hideBoxes(ids)
{
	var trs = document.getElementById("kosik").getElementsByTagName("tr");
	ids = ids.split(/[,]+/g);
	
	for (var i = 0; ids[i]; i++)
		for (var t = 0; trs[t]; t++)
			if (ids[i] == trs[t].id.match(/[\d]+/g))
				trs[t].style.display = "none";
	
	recountRows();
}

function recountRows()
{
	var cnt = 0;
	var trs = document.getElementById("kosik").getElementsByTagName("tr");
	
	for (var t = 0; trs[t]; t++)
		if (trs[t].id.match(/[\d]+/g) && trs[t].style.display != "none")
			trs[t].className = (cnt++ % 2 ? "odd" : "");
}


function check_form(form, names)
{/*
	names = names.split(/[,]+/g);
	
	for (var i = 0; names[i]; i++)
	{
		eval("var obj = document.forms[form]." + names[i] + ";");
		alert(obj.value);
		//return false;
	}
*/	
	return true;
}

function only_number(evt)
{
	/*
	if (!isNaN(parseInt(obj.value)) && obj.value.length)
		obj.value = parseInt(obj.value);
	else
		obj.value = "";
	*/
	
	/*
	if (e.keyCode < 48 || e.keyCode > 57)
		e.returnValue= false;
	*/
	
	 var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	 return true;
}


function first_enter_IC()
{
	var IC = document.getElementById("form_ico");
	//var IC_ok = (document.getElementById("ico_ok") ? true : false);
	var IC_ok = (document.getElementById("ico_ok") ? document.getElementById("ico_ok").value : 0);
	
	var nocomp = document.getElementById("no_company");
	
	var res = (IC_ok && IC.value.length && !nocomp.checked) || (nocomp.checked);
	
	if (res)
	{
//		xajax_pemar_user();
		window.location.href = 'page-pokladna';
	}
	else
		//alert("Vyberte mezi \"nejsem firma\" a zadáním platného IČ.\n\nKombinace není dovolena.");
		alert("Zadejte a potvrďte svoje IČ tlačítkem \"»\" nebo zaškrtněte \"Nejsem firma\".");
	
	return res;
}
/*
function synchronize_addresses()
{
	with (document.pokladna)
	{
		frm_title2.value = frm_title.value;
		frm_name2.value = frm_name.value;
		frm_surname2.value = frm_surname.value;
		frm_company2.value = frm_company.value;
		frm_street2.value = frm_street.value;
		frm_city2.value = frm_city.value;
		frm_zip2.value = frm_zip.value;
	}
}
*/

function guard_IC()
{
	var IC = document.getElementById("form_ico");
	var nocomp = document.getElementById("no_company");
	
	//nocomp.checked = (IC.value.length == 0);
	nocomp.disabled = (IC.value.length != 0);	
}

function guard_nocomp()
{
	var IC = document.getElementById("form_ico");
	var nocomp = document.getElementById("no_company");
	
	IC.disabled = nocomp.checked;
}



/* * * žádost o kalkulaci alá poptávkový formulář * * */

function popt_form()
{
	xajax_antispam(document.poptform.antispam.value);
	
	window.setTimeout("popt_form_check();", 1000);
	return false;
}

function popt_form_check()
{
	with (document.poptform)
		if (name.value.length && surname.value.length && is_mail_ok(email.value) && document.getElementById("antispamok").value == 1)
			document.poptform.submit();
		else
			alert("Vyplňte korektně všechny podbarvené položky.");
}

/* * * poslat mailem * * */

function email_form()
{
	xajax_antispam(document.emailform.antispam.value);
	
	window.setTimeout("email_form_check();", 1000);
	return false;
}


function email_form_check()
{
	if (is_mail_ok(document.emailform.to.value) && document.getElementById("antispamok").value == 1)
		document.emailform.submit();
	else
		alert("Vyplňte korektně všechny podbarvené položky.");
}



















