
	function MM_preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_swapImgRestore() { //v3.0
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_findObj(n, d) { //v4.01
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
			d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
		var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
			if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function foto(dir,id) {
		window.open('foto.php?dir='+dir+'&id='+id,'','width=800,height=600,left=50,top=50');
	}

	function showProductsPicture( imgFile, imgName, productID, optionID, showOptionPicture ) {
		window.open( '/showPictureBig.php?imgFile=' + imgFile + '&imgName=' + imgName + '&productID=' + productID + '&optionID=' + optionID + '&showOptionPicture=' + showOptionPicture, 'showProductsPicture', 'width=480, height=540, left=50, top=50' );
	}
	
	function showPhoto( imgFile, imgName, imgDesc, photoID ) {
		window.open( '/showPicturePhotoBig.php?imgFile=' + imgFile + '&imgName=' + imgName + '&imgDesc=' + imgDesc + '&photoID=' + photoID, 'showPhoto', 'width=480, height=540, left=50, top=50' );
	}

	function showDocument( docId ) {
		window.open( '/showDocument.php?docId=' + docId ,'showDocument', 'scrollbars=yes,width=600,height=550,left=50,top=50' );
	}

	function showDocumentSmall( docId ) {
		window.open( '/showDocument.php?docId=' + docId ,'showDocument', 'scrollbars=yes,width=300,height=550,left=50,top=50' );
	}

	function showParameterDescription( pId ) {
		window.open( '/showParameterDescription.php?p=' + pId ,'showParameterDescription', 'scrollbars=yes,width=300,height=550,left=50,top=50' );
	}

	function foto2(dir,id,pripona) {
		window.open('foto_upload.php?dir='+dir+'&id='+id+'&pripona='+pripona,'foto','width=500,height=395,left=50,top=50,scrollbars=0');
	}



	function productShow(id){
		productStart(0);
		var table		= document.getElementById('productTable_'+id);
		var images		= document.getElementById('productImages_'+id);
		table.style.display	= 'block';
		images.style.display	= 'block';
		return false;
	}
  
	function productStart(from) {
		for ( var x = from; x < defProductsCount; x++ ){
			var table		= document.getElementById('productTable_'+x);
			var images		= document.getElementById('productImages_'+x);
			table.style.display	= 'none';
			images.style.display	= 'none';
		}
	}
  
    function littleProductShow(id){
    littleProductStart(0);
     for (var i=0;i<defProductsCount;i++){
      var div = document.getElementById('littleProducts_'+i+'_'+id);
      var a   = document.getElementById('AlittleProducts_'+i+'_'+id);
      //alert('littleProducts_'+i+'_'+id);
      //alert(div);
      div.style.display = '';
      //alert(a);
      a.className = 'active';
      }      
    }
  
    function littleProductStart(from){
    for (var x=0;x<defProductsCount;x++){
     for (var i=from;i<defAllProductsCount;i++){
      var div = document.getElementById('littleProducts_'+x+'_'+i);
      var a   = document.getElementById('AlittleProducts_'+x+'_'+i);
      //alert(div);
      div.style.display = 'none';
      a.className = '';
      }
    }
    }
    
  function processRequest(_id,httpRequest)
  {
    if (httpRequest.readyState == 4){
      if(httpRequest.status == 200){
        var mistoZobrazeni = document.getElementById(_id);
        mistoZobrazeni.innerHTML = httpRequest.responseText;
        mistoZobrazeni.style.display = '';
        setTimeout('hideBasket()',10000);
       }else{
          alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
      }
    }
  }
  
  function chooseAjax(url,_id)
  {if (url != 0)
     {if (window.ActiveXObject){
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          httpRequest = new XMLHttpRequest();}
        httpRequest.open("GET", url, true);
        document.getElementById(_id).innerHTML = "Loading ...";
        httpRequest.onreadystatechange= function () {processRequest(_id,httpRequest); } ;
        httpRequest.send(null);
      }
      else{document.getElementById(_id).innerHTML = "";}
      return false;
    }
    
  function chooseAjax1(url,_id)
  {if (url != 0)
     {if (window.ActiveXObject){
          httpRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          httpRequest1 = new XMLHttpRequest();}
        httpRequest1.open("GET", url, true);
        //document.getElementById(_id).innerHTML = "Loading ...";
        httpRequest1.onreadystatechange= function () {processRequest(_id,httpRequest1); } ;
        httpRequest1.send(null);
      }
      else{document.getElementById(_id).innerHTML = "";}
      return false;
    }

  function chooseAjax2(url,_id)
  {if (url != 0)
     {if (window.ActiveXObject){
          httpRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          httpRequest2 = new XMLHttpRequest();}
        httpRequest2.open("GET", url, true);
        //document.getElementById(_id).innerHTML = "Loading ...";
        httpRequest2.onreadystatechange= function () {processRequest(_id,httpRequest2); } ;
        httpRequest2.send(null);
      }
      else{document.getElementById(_id).innerHTML = "";}
      return false;
    }

    function hideBasket(){
     var selects = document.getElementsByTagName('select');
     //alert (selects.length);
     for (x=0;x<selects.length;x++)
       selects[x].style.visibility = 'visible';
     var mistoZobrazeni = document.getElementById('addToBasketInfoBox');
     mistoZobrazeni.style.display = 'none';
   } 

   function addToBasket(product){
    
    
    var count = document.getElementById('count').value;
    var price = document.getElementById('price').value;
    var show = true;
   
    if (count <= 0){
      show = false;
    }
    
    if (show){ 
    
     var selects = document.getElementsByTagName('select');
     for (x=0;x<selects.length;x++)
       selects[x].style.visibility = 'hidden';
     chooseAjax('/addToBasket.php?iProductId='+product+'&optionId=&size=&count='+count,'addToBasketInfoBox');
     chooseAjax2('/cartStuff.php?type=price','stuffPrice');     
    }
    
    //alert("Ajax");
    return false;
   } 

  function popUp(theURL,winName,features) { 
    var winObj;
    winObj = window.open(theURL,winName,features);//return winObj
  } 



	function showNextPicture( defMax ) {
		defActiveItemID	= parseInt( document.getElementById('activeItem').value );
		defActiveItem	= 'pictureItem_' + defActiveItemID;
		defNextItemID	= defActiveItemID + 1;
		defNextItem	= 'pictureItem_' + defNextItemID;
		document.getElementById(defActiveItem).style.display			= 'none';
		document.getElementById(defNextItem).style.display			= 'block';
		document.getElementById('activeItem').value				= defNextItemID;
		if ( defNextItemID == 0 ) {
			document.getElementById('linkPrevious').style.display		= 'none';
		} else {
			document.getElementById('linkPrevious').style.display		= 'block';
		}
		if ( defNextItemID == defMax ) {
			document.getElementById('linkNext').style.display		= 'none';
		} else {
			document.getElementById('linkNext').style.display		= 'block';
		}
	}


	function showPreviousPicture( defMax ) {
		defActiveItemID	= parseInt( document.getElementById('activeItem').value );
		defActiveItem	= 'pictureItem_' + defActiveItemID;
		defNextItemID	= defActiveItemID - 1;
		defNextItem	= 'pictureItem_' + defNextItemID;
		document.getElementById(defActiveItem).style.display			= 'none';
		document.getElementById(defNextItem).style.display			= 'block';
		document.getElementById('activeItem').value				= defNextItemID;
		if ( defNextItemID == 0 ) {
			document.getElementById('linkPrevious').style.display		= 'none';
		} else {
			document.getElementById('linkPrevious').style.display		= 'block';
		}
		if ( defNextItemID == defMax ) {
			document.getElementById('linkNext').style.display		= 'none';
		} else {
			document.getElementById('linkNext').style.display		= 'block';
		}
	}



	function hideErrorMsg () {
		document.getElementById('showError').style.display			= "none";
	}

  function reactThread (threadId){
     
    var reactThreadDiv = document.getElementById('reactThreadDiv');
    var submitButton   = document.getElementById('submitButton');
    
	window.location.replace( "#showDiscussionForm" );

    document.getElementById('reactThreadId').value = threadId;
    
    if (threadId != 0){
      reactThreadDiv.innerHTML = "<h4>Reagujete na příspěvek: \n</h4>"+threadsArray[threadId]+"<hr />";
      submitButton.value = "Reagovat";
    } else {
      reactThreadDiv.innerHTML = "&nbsp;";
      submitButton.value = "Vložit nový";
    }
  
    
    //alert('You are going to react thread id: '+threadId);
  }


	function checkProductExtras( defProductID ) {

		defItems	= document.getElementsByName("addProductExtra[]");
		defPrice	= 0;

		if ( document.getElementById("price") ) {
			defPrice	= parseFloat( document.getElementById("price").value );
		} else {
			defOptions	= document.getElementsByName("addProductOption["+defProductID+"]");
			for ( x = 0; x < defOptions.length; x++ ) {
				if ( defOptions[x].checked == true ) {
					defPriceItem	= "priceOption_" + defOptions[x].value;
					defPrice	= parseFloat( document.getElementById( defPriceItem ).value );
				}
			}
		}

		for ( x = 0; x < defItems.length; x++ ) {

			if ( defItems[x].checked == true ) {
				defPriceItem	= "price_" + defItems[x].value;
				defPrice	+= parseFloat( document.getElementById( defPriceItem ).value );
			}

		}

		document.getElementById("showCurrentPrice").innerHTML = defPrice;

	}



	function showMenu( showMenuID ) {
		document.getElementById("showMenuCategories").style.display	= "none";
		document.getElementById("showMenuProducers").style.display	= "none";
		document.getElementById("menuCategories").className		= "";
		document.getElementById("menuProducers").className		= "";
		document.getElementById("showMenu"+showMenuID).style.display	= "block";
		document.getElementById("menu"+showMenuID).className		= "active";
	}


	function checkMinOrder() {
		defMinOrder	= parseFloat( document.getElementById("productMinOrder").value );
		defQuantity	= parseFloat( document.getElementById("productQuantity").value );
		if ( defMinOrder > 0 ) {
			if ( defQuantity < defMinOrder ) {
				alert( "Zadané množství je malé, minimální počet pro objednání tohoto produktu je " + defMinOrder );
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
	}


  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";
		}
	}




    /**
     *  Funkce pro zjisteni nastaveni aktualne vybrane dopravy
     */

    function checkOrderDelivery() {

        aItem       = $("input[name*='order_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;

    }



    /**
     *  Funkce pro zjisteni nastaveni aktualne vybraneho druhu platby
     */

    function checkOrderPayment() {

        aItem       = $("input[name*='order_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;

    }



    /**
     *  Funkce pro nacteni ceny podle aktualniho vyberu dopravy a zpusobu platby
     */

    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) );

    }



    /**
     *  Funkce pro nastaveni externich linku
     */

    function externalLinks() {
        $("a[rel='external']")
            .attr({'target':'_blank'})
            .addClass('extLink');
        $("a[rel='extLink']")
            .attr({'target':'_blank'})
            .addClass('extLink');
    }



    $(document).ready(function() {
        externalLinks();
    });
