function ShowMessageBox(sPrefix, sMsg, sPostfix, bError) {
	alert(sPrefix + "\n" + sMsg + sPostfix);
	return !bError;
}

function SetCookie(sName, mValue, iDays) {
  if (iDays) {
    var iDate = new Date();
    iDate.setTime(iDate.getTime()+(iDays*24*60*60*1000));
    var sExpires = "; expires="+iDate.toGMTString();
  }
  else var sExpires = "";
  document.cookie = sName+"="+mValue+sExpires+"; path=/";
}

function deobfuscate(sStr) {
	var aChars = sStr.split(/-/);
	var sOut = '';
	for (var i = 0; i < aChars.length; i++) {
		sOut += String.fromCharCode(aChars[i]);
	}
	return sOut;
}

function toggleActivity(oCheckbox, fieldPrefix, disabledClass, enabledClass) {
	var oForm = oCheckbox.form;

	for (var i = 0; i < oForm.elements.length; i++) {
		if (oForm.elements[i].id.indexOf(fieldPrefix) == 0) {
			oForm.elements[i].disabled = !oCheckbox.checked;
			oForm.elements[i].className = (oCheckbox.checked ? enabledClass : disabledClass);
			if ((oLabel = document.getElementById(oForm.elements[i].name + '_label'))) {
				oLabel.style.display = (oCheckbox.checked ? 'inline' : 'none');
			}
		}
	}
}

function validateCartForm(oForm, bPro, sMsg) {
	var isTransport = false;
	
	if (bPro) {
		var sPCRE = /^itm_Prom_[0-9]+$/;
	}
	else {
		var sPCRE = /^itm_[0-9]+$/;
	}
	for (var i = 0; i < oForm.elements.length; i++) {
		if(oForm.elements[i].type == "text"){
			if ((oForm.elements[i].id.match(sPCRE) && isNaN(parseInt(oForm.elements[i].value)) || oForm.elements[i].value < 0)) {
				oForm.elements[i].select();
				alert(sMsg);
				return false;
			}
			oForm.elements[i].value = parseInt(oForm.elements[i].value);
		}
	}
	
	return true;
}

function togglePollVisibility(oObj, iId, iQId) {
	if (aVisPoll[iQId]) {
		oCurrVis = document.getElementById('dep_' + aVisPoll[iQId]);
		oCurrVis.style.display = 'none';
	}
	oBlock = document.getElementById('dep_' + iId);
	oBlock.style.display = 'block';
	aVisPoll[iQId] = iId;
}

function clearRadios(oObj, sName)  {
	if (oObj.value.replace(/^\s+/, '').replace(/\s+$/, '') != '') {
		// czyszczenie przyciskow
		aItems = document.getElementsByName(sName);
		for (var i = 0; i < aItems.length; i++) {
			aItems[i].checked = false;
		}
	}
}

function clearText(iId)  {
	$('qo_' + iId).value = '';
}

function hidePoll(iQId) {
	if (aVisPoll[iQId]) {
		oCurrVis = document.getElementById('dep_' + aVisPoll[iQId]);
		oCurrVis.style.display = 'none';
	}
}

function toggleVisibility(oA, sId) {
	oObj = document.getElementById(sId);
	oObj.style.display = oA.checked ? 'block' : 'none';
}

function toggleVisibility2(oA, sId, sShowTxt, sHideTxt) {
	oDesc = document.getElementById(sId);
	if (oA.innerHTML == sShowTxt) {
		// pokazanie opisu
		oDesc.style.display = 'block';
		oA.innerHTML = sHideTxt;
	}
	else {
		// ukrycie opisu
		oDesc.style.display = 'none';
		oA.innerHTML = sShowTxt;
	}
}

function toggleSubMenuVisibility(iMId) {
	oMenuItem = $('menu_item_' + iMId);
	oSubMenu = $('sub_menu_' + iMId);
	oMenuItem.className = oSubMenu.style.display == 'none' ? 'selected' : '';
	oSubMenu.style.display = oSubMenu.style.display == 'none' ? 'block' : 'none';
}


function activeTab(tab){
	var iNumber = tab.id.substring(3,2);
	var sPrefix = "boxTop_";
	var sCookieName = "beck_actTab";
	
	for(var i = 1; i < 5; i++){
		document.getElementById(sPrefix+i).style.display = "none";
		document.getElementById('l_'+i).className = "";
	}
	
	document.getElementById(sPrefix + iNumber).style.display = "block";
	document.getElementById("l_" + iNumber).className = "selected";
	
	document.cookie = sCookieName + "=" + iNumber + ";path=/";
}

function height_pol(els){
	var height = new Array();
	var max = 0;
	for( i = 0; i < els.length; i++){
		height = document.getElementById('pol_'+i).offsetHeight;
		if(height > max) max = height;
	}
	return max;
}

function $(id){
	return document.getElementById(id);
}

function getRegistrationForm(){
	var Form = $('userAccountForm');
	if(Form.payment_data.checked == true){
		sFirm = Form.nazwa.value;
		if(sFirm == ''){
			sFirm = Form.imie.value + ' ' + Form.nazwisko.value;
		}	
		sStreet = Form.ulica.value;
		sPostal= Form.kod.value;
		sCity = Form.miasto.value;
	} else {
		sFirm = '';
		sStreet = '';
		sPostal = '';
		sCity = '';
		sNip = '';
	}
	$('platnik_nazwa').value = sFirm;
	$('platnik_ulica').value = sStreet;
	$('platnik_kod').value = sPostal;
	$('platnik_miasto').value = sCity;	
}

function changeItmValueUp(iId) {
		oInp = document.getElementById("itm_"+iId);
		oInp.value = (isNaN(oInp.value) ? 0 : parseInt(oInp.value)) + 1;
}
function changeItmValueDown(iId) {
	var oInp = document.getElementById("itm_"+iId);
	oInp.value = (isNaN(oInp.value) ? 0 : parseInt(oInp.value)) - 1;
	if( oInp.value < 0 ) {
		oInp.value = 0;
	}
}

function showAdv(){
	document.getElementById("advanced").style.display = document.getElementById("advanced").style.display == "block" ? "none" : "block";
	document.getElementById("adv").value = document.getElementById("adv").value == "1" ? "0" : "1";
	document.getElementById("more_link").innerHTML = document.getElementById("advanced").style.display == "block" ? "Ukryj szczegóły" : "Pokaż szczegóły";
}

function changeDest(oForm){
	dest = oForm.value;

	if ( dest == "1" ){
		document.getElementById("adv").value = "1";
		if(document.getElementById("showAdv")){
			document.getElementById("showAdv").style.display = "block";
		}
		document.getElementById("category").style.display = "block";
		document.getElementById("advanced").style.display = "block";
		if(document.getElementById("more_link")){
			document.getElementById("more_link").innerHTML = "Ukryj szczegóły";
		}
	} else {
		document.getElementById("adv").value = "0";
		if(document.getElementById("showAdv")){
			document.getElementById("showAdv").style.display = "none	";
		}
		document.getElementById("advanced").style.display = "none";
		document.getElementById("category").style.display = "none";
	}
}

function checkPayment(oForm){
	if (oForm.payment_id.value == ''){
		alert('Musisz wybrać formę płatności!');
		return false;
	} else {	
		return true;
	}
}

function cart_transport(fTotalPrice, fTransportPrice, iValue){
	fTotalPrice = parseFloat(fTotalPrice);
	fTransportPrice = parseFloat(fTransportPrice);
	fPriceWithTransport = fTotalPrice + fTransportPrice;
	

	fPriceWithTransport = String(fPriceWithTransport);
	fPriceWithTransport = fPriceWithTransport.replace('.',',');
	if(fPriceWithTransport.indexOf(",") == -1){
		fPriceWithTransport = fPriceWithTransport + ",00";
	} else {
		aTab = fPriceWithTransport.split(",");
		if(aTab[1].length == 1){
			fPriceWithTransport = fPriceWithTransport + "0";
		}
	}
	fTransportPrice = String(fTransportPrice);
	fTransportPrice = fTransportPrice.replace('.',',');
	if(fTransportPrice.indexOf(",") == -1){
		fTransportPrice = fTransportPrice + ",00";
	} else {
		aTab = fTransportPrice.split(",");
		if(aTab[1].length == 1){
			fTransportPrice = fTransportPrice + "0";
		}
	}
	document.getElementById('total_cost_transport').innerHTML = fTransportPrice;
	document.getElementById("total_cost").innerHTML = fPriceWithTransport;
	document.getElementById("transport").value = iValue;
}

function blink(id) {
	if(document.getElementById(id).style.visibility == "visible"){
		document.getElementById(id).style.visibility = "hidden";
	} else {
		document.getElementById(id).style.visibility = "visible";	
	}
	setTimeout("blink('" + id + "');", 1000);
}

function checkQuantity(iId, bPro) {
		oInp = document.getElementById((bPro ? "itm_Prom_" : "itm_") + iId);
		oInp.value = (isNaN(oInp.value) ? 0 : parseInt(oInp.value) == 0 ? 1 : parseInt(oInp.value));
}

function changePhoto(big, small) {
	var oImgCnt = document.getElementById('photoToBig');
	var oImgCnt2 = document.getElementById('photoToBigLink');
	var oImg = new Image();
	//oImgCnt.src = '/omniaCMS/gfx/loading.gif';
	oImg.onload = function() {showImg(oImg, oImgCnt, oImgCnt2, big);}
	oImg.src = small;
}

function showImg(oImg, oImgCnt, oImgCnt2, big) {
	oImgCnt.src = oImg.src;
	if (oImgCnt2) {
		if (big != '') {
			oImgCnt2.href = big;
		}
		else {
			oImgCnt2.href = 'javascript:void(0);';
		}
	}
}

function formatPrice(fPrice) {
	sPrice = fPrice.toString().replace(".", ",");
	if (sPrice.match(/^\d+$/)) {
		// dodanie zer
		return sPrice + ",00";
	}
	else if (sPrice.match(/^\d+,\d{1}$/)) {
		// dodanie tylko jednego zera
		return sPrice + "0";
	}
	return sPrice;
}

function addPayment(transport_price, total_cost, payment_id) {
	if (transport_price > 0) {
		var sum = parseInt((transport_price + total_cost) * 100) / 100;
	}
	else {
		var sum = total_cost;
	}
	document.getElementById('total_cost_transport').innerHTML = formatPrice(transport_price);
	document.getElementById('total_cost').innerHTML = formatPrice(sum);
	
	if(document.getElementById('payment_id')){
		document.getElementById('payment_id').value = payment_id;
	}
}