function switch_pls_min(oPM, oEM){
	var oBlock = document.getElementById(oPM);
	var oLi = document.getElementById(oEM);
	
	if(oBlock.className=='pls'){
		oBlock.className='minus';
		//oLi.className += ' selected';
	} else{
		//oLi.className='padd';
		oBlock.className='pls';
	}
}
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 toggleActivity3(oCheckbox, sLayer) {
	oLayer = document.getElementById(sLayer);
	//oLayer.style.display = 'none';
	if (oLayer.style.display == 'none') {
		oLayer.style.display='block';
	}
	else {
		oLayer.style.display='none';
	}
}

function toggleActivity(oCheckbox, sLayer) {
	if (oCheckbox.checked) {
		$(sLayer).show();
	}
	else {
		$(sLayer).hide();
	}
}
/**
 * Funkcja synchronizuje nazwe symbol strony z jej nazwa usuwajac
 * znaki narodowe oraz zamieniajac duze litery na male i spacje na '_'
 */
function synchronizeSymbol() {
	var sName = document.getElementById('company').value.toLowerCase().replace(/^\s+|\s+$/g, '');
	var aFind = new Array(' ', "ą", "ż", "ś", "ź", "ę", "ć", "ń", "ó", "ł", "á", "ä", "č", "ď", "é", "í", "ľ", "ô", "š", "ť", "ú", "ý", "ž");
	var aReplace = new Array("-", "a",  "z",  "s",  "z",  "e",  "c",  "n",  "o", "l", "a", "a", "c", "d", "e", "i", "l", "o", "s", "t", "u", "y", "z");
		// usuniecie znacznikow HTML
		sName = sName.replace(/<[^>]*>/g, '');
		// usuniecie znakow narodowych
		PCRE = /[^a-z0-9_]/g;
		for(i=0; i < aFind.length; i++) {
			PCRE.compile(aFind[i], "g");
			sName = sName.replace(PCRE, aReplace[i]);
		}
		// usuniecie wszystkich znakow spoza dozwolonego zestawu
		sOthers = /[^a-z0-9_-]/g;
		sMultiples = /-{2,}/g;
		sName = sName.replace(sOthers, '').replace(sMultiples, '-');
		
		// skrocenie do 255 znakow
		sName = sName.substr(0, 255);
		document.getElementById('symbol').value = sName;
}

function toggleAnnTypeActivity(oSel) {
	if (oSel.attr('selectedIndex') > 0) {
	    // aktywowanie pol wyboru typu ogloszenia
	    $('#type_ann_n').removeAttr('disabled');
	    $('#type_ann_p').removeAttr('disabled');
	}
	else {
	    // dekatywowanie pol wyboru typu ogloszenia
	    $('#type_ann_n').attr('disabled', 'disabled');
	    $('#type_ann_p').attr('disabled', 'disabled');
	    // uusniecie zaznaczenia
	    $('#type_ann_n').removeAttr('checked');
	    $('#type_ann_p').removeAttr('checked');
	    // ukrycie formularza platnego ogloszenia
	    togglePayFormVisibility(oSel, false);
	}
}

function togglePayFormVisibility(oSel, bShow) {
    if (oSel.attr('selectedIndex') > 0) {
	// formularz platnego ogloszenia moze byc widoczny
	if (bShow) {
	    $('#payForm').show();
	}
	else {
	    // wyczyszczenie pola na kod
	    $('#pay_code').val('');
	    $('#payForm').hide();
	}
    }
    else {
		// formularz platnego ogloszenia nie moze byc widoczny
		// wyczyszczenie pola na kod
		$('#pay_code').val('');
		$('#payForm').hide();
    }
}


function displayAmountInfo(oSel) {
	if (oSel.attr('selectedIndex') > 0) {
		$('#smsContent').html(aPeriods[oSel.val()][0]);
		$('#smsNumber').html(aPeriods[oSel.val()][1]);
		$('#smsValueNetto').html(formatPrice(aPeriods[oSel.val()][0]));
		$('#smsValueBrutto').html(formatPrice(aPeriods[oSel.val()][0] * 1.22));
		$('#smsPeriod').html(oSel.val());
		$('#smsPeriod2').html(oSel.val());
	}
}

function formatPrice(fPrice) {
	return fPrice.toFixed(2).replace('.', ',');
}

function addNextPhoto() {
	// okreslenie nastepnego numeru zdjecia
	var i = parseInt($('#hide_foto_count').val()) + 1;
	
	// sprawdzenie czy istnieje wieksza liczba pol
	if ($('#form_img_' + i).length > 0) {
		// wyswietlenie pola na nastepne zdjecie
		$('#form_img_' + i).show();
		// zwiekszenie licznika zdjec
		$('#hide_foto_count').val(i);
		
		// sprawdenie czy jest sens nadal wyswietlac przycisk 'Dodaj zdjecie'
		if (($('#form_img_' + (i + 1)).length == 0)) {
			// nie ma juz wiecej pol na zdjecia
			$('#infoImgCount').hide();
		}
	}
}

function addfoto() {
	var i = $('#hide_foto_count').val();
	if(i >= 5) i=5;
	i++;
	$('#hide_foto_count').val(i);
	if(i == 1){
		$('#form_img_one').show();
	}
	if(i == 2){
		$('#form_img_two').show();
	}
	if(i == 3){
		$('#form_img_tree').show();
	}
	if(i == 4){
		$('#form_img_four').show();
	}
	/*
	if(i == 5){
		$('#form_img_five').show();
	}
	if(i == 6){
		$('#form_img_six').show();
	}	
	*/
	if(i >= 5){
		$('#infoImgCount').text('Nie można dodać więcej zdjęć.');
		$('#hide_foto_count').val('5');
	}
}

function addfotoCard(){
	var i = $('#hide_foto_count').val();
	if(i >= 7) i=7;
	i++;
	$('#hide_foto_count').val(i);
	if(i == 1){
		$('#form_img_one').show();
	}
	if(i == 2){
		$('#form_img_two').show();
	}
	if(i == 3){
		$('#form_img_tree').show();
	}
	if(i == 4){
		$('#form_img_four').show();
	}

	if(i == 5){
		$('#form_img_five').show();
	}
	if(i == 6){
		$('#form_img_six').show();
	}	
	
	if(i >= 7){
		$('#infoImgCount').text('Nie można dodać więcej zdjęć.');
		$('#hide_foto_count').val('7');
	}
}
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);
	oMbj = document.getElementById(oA);
	//oObj.style.display = oMbj.style.display ? 'block' : 'none';
	if(oMbj.style.display == 'none')
		oObj.style.display = 'block';
	else
		oObj.style.display = 'none';
}

function toggleFormGroup(oObj) {
	
	if (aVisPoll[oObj.name]) {
		oCurrVis = document.getElementById('dep_' + aVisPoll[oObj.name]);
		oCurrVis.style.display = 'none';

	}
	
	iId=oObj.options[oObj.selectedIndex].value;

	oBlock = document.getElementById('dep_' + iId);
	if(oBlock){
		oBlock.style.display = 'block';
		aVisPoll[oObj.name] = iId;
	}
}

function RadioToggleFormGroup(oObj) {
	
	if (aVisPoll[oObj.name]) {
		oCurrVis = document.getElementById('dep_' + aVisPoll[oObj.name]);
		oCurrVis.style.display = 'none';

	}
	
	iId=oObj.value;

	oBlock = document.getElementById('dep_' + iId);
	if(oBlock){
		oBlock.style.display = 'block';
		aVisPoll[oObj.name] = iId;
	}
}

function hideFormGroup(iField) {

	if (aVisPoll[iField]) {

		oCurrVis = document.getElementById('dep_' + aVisPoll[iField]);

		oCurrVis.style.display = '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 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 changeDest(oForm){
	dest = oForm.value;

	if ( dest == "1" ){
		document.getElementById("adv").value = "0";
		document.getElementById("showAdv").style.display = "block";
	} else {
		document.getElementById("adv").value = "0";
		document.getElementById("showAdv").style.display = "none";	
		document.getElementById("advanced").style.display = "none";
	}
}

function checkPayment(oForm){
	var bSelected = false;
	
	if(oForm.payment_type){
		for ( var i = 0; i < oForm.payment_type.length ; i++ ){
			if (oForm.payment_type[i].checked) bSelected = true;
		}
		if (bSelected == false && oForm.payment_type.length > 1){
			alert('Musisz wybrać formę płatności');
			return false;
		}
	}
	return true;
}

function cart_transport(fTransportPrice){
	var fPrice = document.getElementById("total_price_brutto").innerHTML;
	fPrice = fPrice.replace(',','.');
	fPrice = parseFloat(fPrice);
	var fTotal = fTransportPrice + fPrice;
	fTotal = String(fTotal);
	fTotal = fTotal.replace('.',',');
	if(fTotal.indexOf(",") == -1){
		fTotal = fTotal + ",00";
	} else {
		aTab = fTotal.split(",");
		if(aTab[1].length == 1){
			fTotal = fTotal + "0";
		}
	}

	document.getElementById("total_cost").innerHTML = fTotal;
}

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;
	oImgCnt2.href = big;
}
function pokaz (oA, id) {
	obj = document.getElementById(id);
	if(obj.style.display == "none") {
		obj.style.display="block";
		oA.className = 'rozwinieta';
	}
	else {
		obj.style.display="none";
		oA.className = 'zwinieta';
	}
}

function doRedirect(sHref) {
	window.location.href = sHref;
}