	function hideErrorMsg () {
		document.getElementById('showError').style.display			= "none";
	}


  function showSearchDocuments() {
    document.getElementById("showSearchDocuments").style.display = "none";
    document.getElementById("hideSearchDocuments").style.display = "inline";
    document.getElementById("searchDocuments").style.display = "block";
  }

  function hideSearchDocuments() {
    document.getElementById("showSearchDocuments").style.display = "inline";
    document.getElementById("hideSearchDocuments").style.display = "none";
    document.getElementById("searchDocuments").style.display = "none";
  }


function in_array (needle, haystack)
{
  var found = false;
  for (var i = 0, z = haystack.length; i < z; ++i)
  {
    if (needle != haystack[i])
      continue;
    else
    {
      found = true;
      break;
    }
  }
  return found;
}


	function checkSupplyAddress() {
		if ( document.getElementById("order_address_supply").checked == true ) {
			document.getElementById("formAddressSupply").style.display	= "block";
		} else {
			document.getElementById("formAddressSupply").style.display	= "none";
		}
	}




/**
 * Check selected delivery option
 */
function checkOrderDelivery() {

    aItem       = $("input[name*='id_setup_delivery']:checked");
    aItemInfo   = new Array;

    if ( aItem.length == 1 ) {
        aItemInfo["id"]         = parseInt( aItem.val() );
        aItemInfo["rate"]       = aDeliveryRate[ aItemInfo["id"] ];
        aItemInfo["discount"]   = aDeliveryDiscount[ aItemInfo["id"] ];
    } else {
        aItemInfo["id"]         = 0;
        aItemInfo["rate"]       = 0;
        aItemInfo["discount"]   = 0;
    }

    return aItemInfo;

}


/**
 * Check selected payment option
 */
function checkOrderPayment() {

    aItem       = $("input[name*='id_setup_payment']:checked");
    aItemInfo   = new Array;

    if ( aItem.length == 1 ) {
        aItemInfo["id"]         = parseInt( aItem.val() );
        aItemInfo["rate"]       = aPaymentRate[ aItemInfo["id"] ];
        aItemInfo["discount"]   = aPaymentDiscount[ aItemInfo["id"] ];
    } else {
        aItemInfo["id"]         = 0;
        aItemInfo["rate"]       = 0;
        aItemInfo["discount"]   = 0;
    }

    return aItemInfo;

}


/**
 * Check rates for delivery and payment
 */
function checkOrderRates() {

    aDelivery           = checkOrderDelivery();
    aPayment            = checkOrderPayment();

    iAmountGoods        = parseFloat( $("#priceGoods").val() );
    iAmountDelivery     = aDelivery["rate"];
    iAmountPayment      = aPayment["rate"];

    iDiscountDelivery   = Math.ceil( iAmountGoods * ( aDelivery["discount"] / 100 ) );
    iDiscountPayment    = Math.ceil( iAmountGoods * ( aPayment["discount"] / 100 ) );

    iAmountDiscount     = iDiscountDelivery + iDiscountPayment;
    iAmountTotal        = iAmountGoods + iAmountDelivery + iAmountPayment + iAmountDiscount;

    $("#priceDelivery").val( iAmountDelivery.toFixed(2) );
    $("#pricePayment").val( iAmountPayment.toFixed(2) );
    $("#priceDiscount").val( iAmountDiscount.toFixed(2) );
    $("#priceTotal").val( iAmountTotal.toFixed(2) );

}


/**
 * Set external links
 */

function externalLinks() {
    $("a[rel='external']")
        .attr({'target':'_blank'})
        .addClass('extLink');
    $("a[rel='extLink']")
        .attr({'target':'_blank'})
        .addClass('extLink');
}

/**
 * Send question
 */
function sendForm(form)
{
    $('#' + $(form).attr('id') + ' #sendFormJS').val('LIME');
    $.post(
        $(form).attr('action'),
        $(form).formSerialize(),
        function(msg){
            msg = eval(msg);
            if (msg['status'] == true) {
                $(form).resetForm();
                alert('Zpráva byla úspěšně odeslána.');
            } else {
                if (msg['status'] == 'error') {
                    alert('Vyplňte prosím všechny povinné položky a odešlete formulář znovu.');
                } else {
                    alert('Zpráva nebyla odeslána, kontaktujte nás prosím e-mailem nebo telefonicky.');
                }
            }
        },
        'json'
    );
    return false;
}


/**
 * Set onload functions
 */
$(document).ready(function() {
    externalLinks();
    $("a[rel*='lightbox']").lightbox();
    $(".product-tabs").tabs();
    $("#formQuestion").bind('submit', function(){
        return sendForm(this);
    });
});

