	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 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 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";
	}
	
	var thread = 0;
  function reactThread (threadId){
     
    var reactThreadDiv = document.getElementById('reactThreadDiv');
    var submitButton   = document.getElementById('submitButton');
    
	window.location.replace( "#showDiscussionForm" );

    document.getElementById('reactThreadId').value = threadId;
    thread = threadId;
    if (threadId != 0){
      reactThreadDiv.innerHTML = "<h4 style=\"padding:0px;margin:0px;\">Reagujete na příspěvek:\n</h4>( <a href='javascript: reactThread(0)'>Vložit nový</a> )<br />"+threadsArray[threadId]+"<hr />";
      submitButton.value = "Reagovat";
    } else {
      reactThreadDiv.innerHTML = "&nbsp;";
      submitButton.value = "Vložit nový";
    }
  
    
    //alert('You are going to react thread id: '+threadId);
  }

// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function discusionReact(){
    if (document.getElementById('discusion_text').value == ''){
      alert('Vyplňte text, prosím.');
    } else {
      if (document.getElementById('discusion_username').value == ''){
        alert('Vyplňte jméno, prosím.');
      } else {
    // IF loadingDialog IS NULL THEN CREATE IT
    if (!document.getElementById('loadingDialog')){
      var objBody = document.getElementsByTagName('body').item(0);  
      var objtssDialogWindow = document.createElement("div");
      objtssDialogWindow.setAttribute('id','loadingDialog');
      objtssDialogWindow.innerHTML = '<center><img src="/admin/media/images/design/icons/loading.gif" alt="Loading" /></center>';
      objtssDialogWindow.setAttribute('class','loadingDialog');
      objBody.appendChild(objtssDialogWindow);
    } else {
      document.getElementById('loadingDialog').style.display = '';
    }
    // Urceni position ...
    var pageSize = getPageSize();
    var pageScroll = getPageScroll();
    var loadingBox = document.getElementById('loadingDialog');
    //alert(pageSize[0]);
    loadingBox.style.width  = (pageSize[0])+'px;';
//    loadingBox.style.height = (pageSize[3])+'px;';
    loadingBox.style.top    = ((pageSize[3]/2)+pageScroll[1])+'px;';
    //Ted ajax ...
        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();}
          kindHTTP.open("GET", "/admin/discusionSave.php?threadId="+thread+"&text="+document.getElementById('discusion_text').value+'&name='+document.getElementById('discusion_username').value+'&email='+document.getElementById('discusion_useremail').value+'&discusionID='+document.getElementById('discusionID').value, true);
          kindHTTP.onreadystatechange= function () { 
            if (kindHTTP.readyState == 4){
            document.getElementById('productDiscusionThreads').innerHTML = kindHTTP.responseText;
           } 
          } ;
          kindHTTP.send(null);  
       document.getElementById('loadingDialog').style.display = 'none';} }     
       document.getElementById('discusion_text').value = '';
       document.getElementById('discusion_useremail').value = '';
       document.getElementById('discusion_username').value = '';
       return false;
}

function searchingKindChange(){
        var data = '';
        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();}
          kindHTTP.open("GET", "/admin/searchKindsSelect.php?kindSelected="+document.getElementById('searchKindSelect').value, true);
          document.getElementById('searchKindsOtherParametres').innerHTML = '<center><img src="/admin/media/images/design/icons/loading.gif" alt="Loading" /></center>';
          kindHTTP.onreadystatechange= function () { 
            if (kindHTTP.readyState == 4){
            document.getElementById('searchKindsOtherParametres').innerHTML = kindHTTP.responseText
           } 
          } ;
          kindHTTP.send(null);     
    return false;
}

function selectWish(){
       if (window.ActiveXObject){
          wishHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          wishHTTP = new XMLHttpRequest();}
          wishHTTP.open("GET", "/wish_select.php", true);
          $('loadingWindow').style.display = '';
          document.getElementById('loadingWindow').innerHTML = '<center><img src="/admin/media/images/design/icons/loading.gif" alt="Loading" /></center>';
          wishHTTP.onreadystatechange= function () { 
            if (wishHTTP.readyState == 4){
            document.getElementById('dialogWindow2').innerHTML = wishHTTP.responseText
            $('loadingWindow').innerHTML = '';
            $('loadingWindow').style.display = 'none';
           } } ;
          wishHTTP.send(null);    
          return false;
}

function addToCart(request,action){

        var color = "undefined";
        if ($('posy_color') != null)
          color = $('posy_color').value; 
        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();}
          kindHTTP.open("GET", "/cart.php?noshow=1&action="+action+"&"+request+"&color="+color, true);
          if (eachProductAdress == 1) {
            $('loadingWindow').style.display = '';
            document.getElementById('loadingWindow').innerHTML = '<center><img src="/admin/media/images/design/icons/loading.gif" alt="Loading" /></center>';
          }
          kindHTTP.onreadystatechange= function () { 
            if (kindHTTP.readyState == 4){
            document.getElementById('dialogWindow').innerHTML = kindHTTP.responseText
            location.replace("/cart.php");
            if (eachProductAdress == 1) {
              $('loadingWindow').innerHTML = '';
              $('loadingWindow').style.display = 'none';             
            } else {
            //setCartPriceAndCount();
            }
           } 
          } ;
          kindHTTP.send(null);    
          if (eachProductAdress == 1) {
            window.location.replace( "#" );
          } 
          ajaxRefreshPage($('request_uri').value);
          return false;

}

function closeDialog(){
  document.getElementById('dialogWindow').innerHTML = "";
  return false;
}

function closeDialog2(){
  document.getElementById('dialogWindow2').innerHTML = "";
  return false;
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

function setCartPriceAndCount(){
        if ($('cartBoxValues') != null){
          $('cartBoxValues').style.display = '';
            if ($('cartBoxNoStuff') != null) $('cartBoxNoStuff').style.display = 'none';  
        }
         
        
        
        if (window.ActiveXObject){
          countHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          countHTTP = new XMLHttpRequest();}
          countHTTP.open("GET", "/cartStuff.php?type=count", true);
          countHTTP.onreadystatechange= function () { 
            if (countHTTP.readyState == 4){
            //document.getElementById('dialogWindow').innerHTML = countHTTP.responseText
            // Uprava hodnot ... 
            if ($('cartCountDiv') != null){
              $('cartCountDiv').innerHTML = countHTTP.responseText;
            }
           } 
          } ;
          countHTTP.send(null);     

       if (window.ActiveXObject){
          priceHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          priceHTTP = new XMLHttpRequest();}
          priceHTTP.open("GET", "/cartStuff.php?type=price", true);
          priceHTTP.onreadystatechange= function () { 
            if (priceHTTP.readyState == 4){
            //document.getElementById('dialogWindow').innerHTML = priceHTTP.responseText
            // Uprava hodnot ... 
            if ($('cartPriceDiv') != null){
              $('cartPriceDiv').innerHTML = priceHTTP.responseText;
            }
           } 
          } ;
          priceHTTP.send(null);    
   return false;

}

function refreshCartPage(){
      if ($('listCart') != null){
        if (window.ActiveXObject){
          cartHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          cartHTTP = new XMLHttpRequest();}
          cartHTTP.open("GET", "/cart.php?noshow=", true);
          cartHTTP.onreadystatechange= function () { 
            if (cartHTTP.readyState == 4){
              $('listCart').innerHTML = cartHTTP.responseText;
           } 
          } ;
          cartHTTP.send(null);
       }      
}


function submitDeliveryForm(){
   var deliveryForm = $('deliveryForm');
   var delivery_addr = getSelectedRadioValue(deliveryForm.delivery_addr);
   //alert(delivery_addr);
   var delivery_addr_street_1 = decodeURI($('delivery_addr_street_1').value);

   var delivery_addr_name = $('delivery_addr_name').value;
   var delivery_wish      = $('delivery_wish').value;

   var adressID = decodeURI($('adressID').value);
   var changeA = decodeURI($('changeA').value);
   var itemID = decodeURI($('itemID').value);

   var delivery_addr_street_2 = decodeURI($('delivery_addr_street_2').value);
   var delivery_addr_city = decodeURI($('delivery_addr_city').value);
   var delivery_addr_zip = decodeURI($('delivery_addr_zip').value);
   var delivery_addr_country = decodeURI($('delivery_addr_country').value);
   var delivery_date = decodeURI($('delivery_date').value);
   var delivery_time = decodeURI($('delivery_time').value);
   var productID = $('productID').value;
   var http_referer = $('http_referer').value;
   if ($('action2') != null){
     var action = $('action2').value;
  }
  if (deliveryForm.delivery_id != undefined){
    var delivery_id = getSelectedRadioValue(deliveryForm.delivery_id);
  }
   
   var formSubmit = '1';
   var stuff = 'delivery_addr='+delivery_addr+'&delivery_addr_street_1='+delivery_addr_street_1+
               '&delivery_addr_street_2='+delivery_addr_street_2+'&delivery_addr_city='+delivery_addr_city+'&delivery_addr_zip='+delivery_addr_zip+
               '&delivery_addr_country='+delivery_addr_country+'&delivery_date='+delivery_date+'&delivery_time='+delivery_time+'&formSubmit='+formSubmit+
               '&productID='+productID+'&http_referer='+http_referer+'&js=1&action='+action+'&delivery_id='+delivery_id+'&adressID='+adressID+
               '&changeA='+changeA+'&itemID='+itemID+'&delivery_addr_name='+delivery_addr_name+'&delivery_wish='+delivery_wish;  
   //alert(stuff); 

        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();}
          $('loadingWindow').style.display = '';
          document.getElementById('loadingWindow').innerHTML = '<center><img src="/admin/media/images/design/icons/loading.gif" alt="Loading" /></center>';
          kindHTTP.open("GET", "/delivery_adress.php?"+stuff, true);
          kindHTTP.onreadystatechange= function () { 
            if (kindHTTP.readyState == 4){
            document.getElementById('dialogWindow').innerHTML = kindHTTP.responseText
            // Uprava hodnot ... 
            setCartPriceAndCount();
            refreshCartPage();
            ajaxRefreshPage($('request_uri').value);
            $('loadingWindow').innerHTML = '';
            $('loadingWindow').style.display = 'none';
           } 
          } ;
          kindHTTP.send(null);    
          window.location.replace( "#" ); 
   
   
  
   return false;
}

  function wishSelect(){
   var wishForm = $('wishForm');
   var wishText = getSelectedRadioValue(wishForm.wish);
   if ($('delivery_wish') != null){
      $('delivery_wish').value = wishText; 
   }
   closeDialog2();
   return false;
  
  }

   function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
   } // Ends the "getSelectedRadio" function

   function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
   } // Ends the "getSelectedRadioValue" function


// Posy section ....

function rosePosyNextColor(id){
    if ($("newColor"+id) != null){
      if ($("newColor"+id).checked) {
        $("posyColorItem"+(String)(id+1)).style.display = "";
      } else {
        $("posyColorItem"+(String)(id+1)).style.display = "none";      
      }
    }
    refreshPosy();
}


function ajaxRefreshPage(url){
      if (navigator.appName != "Microsoft Internet Explorer"){
      if (window.ActiveXObject){
          refreshHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          refreshHTTP = new XMLHttpRequest();}
          $('loadingWindow').style.display = '';
          var splittedUrl = url.split('?');
          if (splittedUrl.length == 2){
            url = url + '&noshow=1';
          } else {
            url = url + '?noshow=1';
          }
          refreshHTTP.open("GET", url, true);
          refreshHTTP.onreadystatechange= function () { 
            if (refreshHTTP.readyState == 4){
            // Uprava hodnot ... 
            $('mainWindow').innerHTML = refreshHTTP.responseText;
            // Refresh actual page ... ;-)
            $('loadingWindow').innerHTML = '';
            $('loadingWindow').style.display = 'none';
           } 
          } ;
          refreshHTTP.send(null);    
        } else {
          location.replace(url);
        }
}

function refreshRosePosy(){
    var posyColorsCount    = -1;
    if ($('posyColorsCount') != null)    var posyColorsCount    = $('posyColorsCount').value;    

  var error = "";
  
  if (posyColorsCount != null){
    for (var x = 0; x < posyColorsCount; x++){
      if ($('newColor'+(String)(x-1))!=null){
        if ($('newColor'+(String)(x-1)).checked){
          if($('posy_color'+(String)(x)).value == 0){
            alert('U '+(String)(x+1)+'. položky musíte vybrat barvu');
            return false;
          }
        }
      }
      if (x == 0){
          if($('posy_color'+(String)(x)).value == 0){
            alert('U '+(String)(x+1)+'. položky musíte vybrat barvu');
            return false;
          }
      }
    }
  }
}

function addToCartP(request,action,pID){
    var posy_linkage       = -1;
    var posy_embellishment = -1;
    var posy_decoration    = -1;
    var posy_dominant      = -1;
    var posy_color         = -1;
    var posyID             = 0;
    // roses check ... 
    var posyColorsCount    = -1;
    
    
    if ($('posy_linkage') != null)       var posy_linkage       = $('posy_linkage').value;
    if ($('posy_embellishment') != null) var posy_embellishment = $('posy_embellishment').value;
    if ($('posy_decoration') != null)    var posy_decoration    = $('posy_decoration').value;
    if ($('posy_color') != null)         var posy_color         = $('posy_color').value;
    if ($('posy_dominant') != null)      var posy_dominant      = $('posy_dominant').value;
    if ($('posyColorsCount') != null)    var posyColorsCount    = $('posyColorsCount').value;    

  var error = "";
  
  if (posyColorsCount != -1){
    for (var x = 0; x < posyColorsCount; x++){
      if ($('newColor'+(String)(x-1))!=null){
        if ($('newColor'+(String)(x-1)).checked){
          if($('posy_color'+(String)(x)).value == 0){
            alert('U '+(String)(x+1)+'. položky musíte vybrat barvu');
            return false;
          }
        }
      }
      if (x == 0){
          if($('posy_color'+(String)(x)).value == 0){
            alert('U '+(String)(x+1)+'. položky musíte vybrat barvu');
            return false;
          }
      }
    }
  }
  
  
  if (posy_linkage == "0"){
    alert("Vyberte vazbu, prosím.");
    return false; 
  }

  if (posy_dominant == "0"){
    alert("Vyberte dominantni kvetinu, prosím.");
    return false; 
  }

  if (posy_color == "0"){
    alert("Vyberte barvu, prosím.");
    return false; 
  }


  if (posy_embellishment == "0"){
    alert("Vyberte přízdobu, prosím.");
    return false; 
  }

  if (posy_decoration == "0"){
    alert("Vyberte dekoraci, prosím.");
    return false; 
  }

        var stuff = "action=aToC&posyID="+pID;
        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();}
          //$('loadingWindow').style.display = '';
          //document.getElementById('loadingWindow').innerHTML = '<center><img src="/admin/media/images/design/icons/loading.gif" alt="Loading" /></center>';
          kindHTTP.open("GET", "/posy_handler.php?"+stuff, true);
          kindHTTP.onreadystatechange= function () { 
            if (kindHTTP.readyState == 4){
              $('loadingWindow').innerHTML = '';
              $('loadingWindow').style.display = 'none';
              return addToCart(request,action);
           } 
          } ;
          kindHTTP.send(null); 
   return false;   
}

function refreshPosy(){
    var posy_linkage       = 0;
    var posy_embellishment = 0;
    var posy_decoration    = 0;
    var posyID             = 'null';
    var posyType           = 1;
    var posy_dominant      = 0;
    var posy_color         = 0;
    var posy_price         = 0; 
    // roses posy ...
    var posyColorsCount    = 0;
    var newColor           = '';
    var posy_count         = '';
    
    
    if ($('posy_linkage') != null)       var posy_linkage       = $('posy_linkage').value;
    if ($('posy_embellishment') != null) var posy_embellishment = $('posy_embellishment').value;
    if ($('posy_decoration') != null)    var posy_decoration    = $('posy_decoration').value;
    if ($('formSubmit_r') != null)       var submit             = $('formSubmit_r').value;
    if ($('posyID_r') != null)           var posyID             = $('posyID_r').value;
    if ($('posyType') != null)           var posyType           = $('posyType').value; 
    if ($('posy_dominant') != null)      var posy_dominant      = $('posy_dominant').value;
    if ($('posy_color') != null)         var posy_color         = $('posy_color').value;
    if ($('posy_price') != null)         var posy_price         = $('posy_price').value;    
    if ($('posyColorsCount') != null)    var posyColorsCount    = $('posyColorsCount').value;    
    
    // roses posy ...
    if (posyType == 3){
      posy_color = '';
      for (var x = 0; x < posyColorsCount; x++){
        if ($('newColor'+(String)(x)) != null){
          if (x != 0) newColor = newColor + '|';
          var value = '0';
          if ($('newColor'+(String)(x)).checked) value = '1'; 
          newColor = newColor + value;          
        }
        if ($('newColor'+(String)(x-1)) != null)
          if (!$('newColor'+(String)(x-1)).checked) $('posy_color'+(String)(x)).value = '0'; 
        if ($('posy_color'+(String)(x)) != null){
          if (x != 0) posy_color = posy_color + '|';
          posy_color = posy_color + $('posy_color'+(String)(x)).value;  
        }
        if ($('newColor'+(String)(x-1)) != null)
          if (!$('newColor'+(String)(x-1)).checked) $('posy_count'+(String)(x)).value = '0'; 
        if ($('posy_count'+(String)(x)) != null){
          if (x != 0) posy_count = posy_count + '|';
          posy_count = posy_count + $('posy_count'+(String)(x)).value;;          
        }        
      }    
    }
        
       
    var stuff="posy_linkage="+posy_linkage+"&posy_embellishment="+posy_embellishment+'&posy_decoration='+posy_decoration+'&posyID='+posyID+'&js=1&formSubmit='+submit+'&posyType='+posyType+'&posy_dominant='+posy_dominant+'&posy_color='+posy_color+'&posy_price='+posy_price+'&newColor='+newColor+'&posy_count='+posy_count;
    //alert(stuff);
        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();}
          $('loadingWindow').style.display = '';
          document.getElementById('loadingWindow').innerHTML = '<center><img src="/admin/media/images/design/icons/loading.gif" alt="Loading" /></center>';
          kindHTTP.open("GET", "/posy_handler.php?"+stuff, true);
          kindHTTP.onreadystatechange= function () { 
            if (kindHTTP.readyState == 4){
            //alert(kindHTTP.responseText);
            ajaxRefreshPage($('request_uri').value);
            $('loadingWindow').innerHTML = '';
            $('loadingWindow').style.display = 'none';
           } 
          } ;
          kindHTTP.send(null);    
     
}

function addToPosy(productID){
        var count = $('count_'+productID).value;
        var productID = productID;
        var posyID = $('posyID_'+productID).value; 
        var submit = $('addToPosy_'+productID).value;
        var stuff="count="+count+"&productID="+productID+'&posyID='+posyID+'&js=1&formSubmit='+submit+'&action=add';
        //alert(stuff);        
        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();}
          $('loadingWindow').style.display = '';
          document.getElementById('loadingWindow').innerHTML = '<center><img src="/admin/media/images/design/icons/loading.gif" alt="Loading" /></center>';
          kindHTTP.open("GET", "/posy_handler.php?"+stuff, true);
          kindHTTP.onreadystatechange= function () { 
            if (kindHTTP.readyState == 4){
            // Uprava hodnot ... 
            // Refresh actual page ... ;-)
            ajaxRefreshPage($('request_uri').value);
            //alert('Done');
            $('loadingWindow').innerHTML = '';
            $('loadingWindow').style.display = 'none';
           } 
          } ;
          kindHTTP.send(null);    


  return false;
}


function orderSurchargeTimeChange(){
	
	if ($("productSurcharge_ID") != null){
		var surchargeIDs = $("productSurcharge_ID").innerHTML;
		var productIDs = surchargeIDs.split("|");
		/*for( var i = 0; i < productIDs.length; i++ ){
			productIDs[i] = parseInt( productIDs[i] );
		}*/
	}
	
	var delivery_date = $("delivery_date").value;
	
	var stuff = "delivery_date="+delivery_date+"&productIDs="+productIDs;	  
	if (window.ActiveXObject){
		kindHTTPSurcharge = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		kindHTTPSurcharge = new XMLHttpRequest();}
		kindHTTPSurcharge.open("GET", "/surchargePriceAjax.php?"+stuff, true);
		kindHTTPSurcharge.onreadystatechange= function () { 
		if (kindHTTPSurcharge.readyState == 4){
			// Uprava hodnot ... 
			//alert(kindHTTPSurcharge.responseText);
			var price = kindHTTPSurcharge.responseText.split("|");
			
			if( price[0] != 0  ){
				var res = (String)((Number)(price[0]));
				var p = res.split(".");
				
				if (p.length == 1){
              				res = res + '.00';
            			} else {
              				p = p[1];
              				if (p.length == 1){
                				res = res + '0';
              				}
            			}
				
				if( $("showPriceSurcharge") != null ){
					$("showPriceSurcharge").innerHTML = res;
				}else{
					$("price_surcharge").value = res;
				}			
										
				$("totalSurchargeLabel").innerHTML = price[1];
				$("labelForSurcharge").value = price[1];
				$("totalSurcharge").style.display = "block";				
				

				document.getElementById("price_total").value	= setTotalPrice();
			}else{
				if( $("showPriceSurcharge") != null ){
					$("showPriceSurcharge").innerHTML = 0;
				}else{
					$("price_surcharge").value = 0;
				}			
										
				$("totalSurchargeLabel").innerHTML = "Přirážka";
				$("labelForSurcharge").value = "Přirážka";
				
				$("totalSurcharge").style.display = "none";
			}

		}
	}
	
	kindHTTPSurcharge.send(null);    

	return false;
	
}


function changeAdministrationCosts(){
        
        var defCountry = $("customer_supply_country").value;
        var stuff = "country="+defCountry;
        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();}
          kindHTTP.open("GET", "/administrationPriceAjax.php?"+stuff, true);
          kindHTTP.onreadystatechange= function () { 
            if (kindHTTP.readyState == 4){
            // Uprava hodnot ... 
            var price = kindHTTP.responseText.split("|"); 
            //$("price_administration").value = price[1];
            var res = (String)((Number)(price[1]));
            var res2 = (String)((Number)($("price_goods").value) + (Number)($("price_delivery").value) + (Number)(price[1]));
	    var p = res.split(".");
            if (p.length == 1){
              res = res + '.00';
            } else {
              p = p[1];
              if (p.length == 1){
                res = res + '0';
              }
            }
            var p2 = res2.split(".");
            if (p2.length == 1){
              res2 = res2 + '.00';
            } else {
              p2 = p2[1];
              if (p2.length == 1){
                res2 = res2 + '0';
              }
            }            
            
            if( res == "0.00" ){
            	document.getElementById("priceAdministration").style.display = "none";
	    }else{
	    	document.getElementById("priceAdministration").style.display = "block";
	    }
            
            $("price_administration").value = res;
            
            orderSurchargeTimeChange();
  
            $("price_total").value = setTotalPrice();

           } 
          } ;
          kindHTTP.send(null);    
  return false;
}


function setTotalPrice() {
  var priceAdministration = parseFloat( document.getElementById("price_administration").value, 100 );
	var priceGoods	= ( parseFloat( document.getElementById("price_goods").value, 100 ) * 100 ) / 100;
  var priceDelivery	= parseFloat( document.getElementById("price_delivery").value, 100 );
  var priceCod	= parseFloat( document.getElementById("price_cod").value, 100 );
  var priceSurcharge = parseFloat( document.getElementById("price_surcharge").value, 100 );  
  
	var decimalPlaces = document.getElementById("price_decimal_places").value;
	if (decimalPlaces == 0) {
    var decimalNumber = 1;
  } else if (decimalPlaces == 1) {
    var decimalNumber = 10;
  } else if (decimalPlaces == 2) {
    var decimalNumber = 100;
  } else {
    var decimalNumber = pow(10, decimalPlaces);
  }
 
  
  //var percentSale = document.getElementById("price_sale_percent").value;
  //var priceGoodsWithSale = Math.round((priceGoods / 100) * (100 - percentSale) * decimalNumber) / decimalNumber;  

  var priceTotal	= priceGoods + priceDelivery + priceAdministration + priceCod + priceSurcharge;
  
  if( document.getElementById("price_saleCoupon") != null ){  	
  	var priceDiscountCoupon = parseFloat( document.getElementById("price_saleCoupon").value, 100 );  		
  	priceTotal = priceTotal + priceDiscountCoupon;  	
  }
    
	//var priceSale = - (priceTotal - priceGoods - priceDelivery - priceAdministration - priceCod);
	
	priceTotal = (Math.round(priceTotal * decimalNumber) / decimalNumber);
	//priceSale = (Math.round(priceSale * decimalNumber) / decimalNumber);
	
	priceTotal = (String)(priceTotal);
	//priceSale = (String)(priceSale);
	
  var p = priceTotal.split(".");
  if (p.length == 1){
    priceTotal = priceTotal + '.00';
  } else {
    p = p[1];
    if (p.length == 1){
      priceTotal = priceTotal + '0';
    }
  }
  /*
  var p2 = priceSale.split(".");
  if (p2.length == 1){
    priceSale = priceSale + '.00';
  } else {
    p2 = p2[1];
    if (p2.length == 1){
      priceSale = priceSale + '0';
    }
  }
  */
  //document.getElementById("price_sale").value = (String)(priceSale);
  
  return priceTotal;
}


function setPriceTotal() {
	setTotalPrice();
}


function orderDateTimeChange( cartID ){

	var delivery_date = $("delivery_date").value;

	if ($("delivery_time") != null){
		var delivery_time = $("delivery_time").value;
	} else {
		return;
	}

	if ($("price_goods") != null){
		var price_goods   = $("price_goods").value;
	} else {
		return;
	} 

	var stuff = "delivery_date="+delivery_date+"&delivery_time="+delivery_time+"&price_goods="+price_goods+"&country="+defCountry;
	$("pDelivery").innerHTML = "načítám ... ";  
	if (window.ActiveXObject){
		kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		kindHTTP = new XMLHttpRequest();}
		kindHTTP.open("GET", "/deliveryPriceAjax.php?"+stuff, true);
		kindHTTP.onreadystatechange= function () { 
		if (kindHTTP.readyState == 4){
			// Uprava hodnot ... 
			var price = kindHTTP.responseText.split("|"); 
			$("pDelivery").innerHTML = price[0];
			$("price_delivery").value = price[1];
			$("price_surcharge").value = price[2];
			
			var res = (String)((Number)($("price_goods").value) + (Number)(price[1]) + (Number)($("price_administration").value));
			var p = res.split(".");
			if (p.length == 1){
				res = res + '.00';
			} else {
				p = p[1];
				if (p.length == 1){
					res = res + '0';
				}
			}

			changeAdministrationCosts();

			// $("price_total").value = res; 
			// Refresh actual page ... ;-)

			document.getElementById("price_total").value	= setPriceTotal();

		} 

	}

	kindHTTP.send(null);    

	return false;

}




// EOF POSY


function tssAddLoadEvent(func)
{	
  var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}



// AJAX modul ....

var axmDivs = Array();

function setInfo(text){
  $("ajaxModulInfoBar").innerHTML = text;
}

function unsetInfo(){
  $("ajaxModulInfoBar").innerHTML = 'Jste přihlášen do administrace, AJAX modul je aktivní.<br />Po najetí na určité části se yde objeví info co můžete dělat.';
}

function ajaxDivOver(what){
  what.style.border = '1px solid red';
  what.style.padding = '2px';
}

function ajaxDivOut(what){
  what.style.border = '0px';
  what.style.padding = '0px';
}

function initializeAjaxModul(){
  if ($("ajaxModulInfoBar") != null){
    // ** info panel
    window.onscroll = function(){
      if ($("ajaxModulInfoBar") != null){
        var pageScroll = getPageScroll();
        $("ajaxModulInfoBar").style.top = String(pageScroll[1] + 10)+'px';
      }
    }
    // eol ** info panel
    axmDivs = Array();
    var Adivs = document.getElementsByTagName('div');
    for (var x = 0; x < Adivs.length; x++)
     if ( Adivs[x].getAttribute('rel') == 'ajaxModul') axmDivs.push(Adivs[x]);
       
    for (var x = 0; x < axmDivs.length; x++){
      //axmDivs[x].style.border = '1px solid #CCCCCC'; 
      //axmDivs[x].style.padding = '1px';
      axmDivs[x].style.cursor = 'hand';
      axmDivs[x].onmouseout  = function (){if(this != oldObject){ajaxDivOut(this);unsetInfo();}};
      axmDivs[x].onmouseover = function (){if(this != oldObject){ajaxDivOver(this);setInfo($(this.id+'_info').value);}};
      axmDivs[x].onclick     = function (){if(this != oldObject){ajaxClick(this,ajaxCreateObject($(this.id+'_input').value));}};
   }          
  }
}

var oldInnerHTML = '';
var oldObject    = null;


function ajaxClick(what,Cdata){
  if (oldObject != null){
   ajaxDivOut(oldObject);
   oldObject.innerHTML = oldInnerHTML;
  }
  oldObject    = what;
  oldInnerHTML = what.innerHTML;
  what.innerHTML = '<input id="newValue" type="'+Cdata.type+'" value="'+Cdata.value+'" style="'+Cdata.style+'" />';
  $('newValue').focus();
}

function ajaxCreateObject(data){
  var rdata = Object();
  data = data.split(',');
  for (var x = 0; x < data.length; x++){
    var att = data[x].split('->');
    rdata[att[0]] = att[1];
  }
  return rdata;
}


function checkGuestForm(){
  var err_string = "";
  if ($('message_user').value == ""){
    err_string = "Musíte vyplnit jméno!";
  }
  if ($('message_text').value == ""){
    if (err_string != "") err_string = err_string + "\n";
    err_string = err_string + "Musíte vyplnit text!";
  }
  if (err_string != ""){
    alert(err_string);
    return false;
  }
  return true;
}


tssAddLoadEvent(initializeAjaxModul);
	
function checkStuff(){
  if ($("posy_color") != null){
    if ($("posy_color").value == ""){
      alert("Vyberte barvu prosím.");
      return false;
    } 
  }
  return true;
}

function checkSpecialCat( prodID ){
	
	var result = "";
         
        if (window.ActiveXObject){
          kindHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          kindHTTP = new XMLHttpRequest();
	}
	
	kindHTTP.open("GET", "/checkSpecialCat.php?sProdID="+prodID, true);
        
        kindHTTP.onreadystatechange= function () { 
        if (kindHTTP.readyState == 4){
        	$backSpecCat = kindHTTP.responseText;
		if( $backSpecCat == 1 ){
			result = true;
		}else{
			result = false;
		}
        } 
        } ;
        
        return result;
          
}

