function GetProducts(category)
{
   
   if(category=='main') category_id = document.getElementById('main_category_select').options[document.getElementById('main_category_select').selectedIndex].value;
   else if(category=='sub') 
   {
      category_id = document.getElementById('sub_category_select').options[document.getElementById('sub_category_select').selectedIndex].value;
      if(category_id==0) category_id = document.getElementById('main_category_select').options[document.getElementById('main_category_select').selectedIndex].value;
   }  
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               //alert(xmlHttp.responseText);
               /*if(xmlHttp.responseText.split('##########', 4)[0]!='') document.getElementById('sub_category_select_div').innerHTML = xmlHttp.responseText.split('##########', 2)[0];
               document.getElementById('webshop_products').innerHTML = xmlHttp.responseText.split('##########', 4)[1];
               document.getElementById('product_select_div').innerHTML = xmlHttp.responseText.split('##########', 4)[2];
               if(xmlHttp.responseText.split('##########', 4)[3]!=undefined) document.getElementById('product_parameters_div').innerHTML = xmlHttp.responseText.split('##########', 4)[3];
               else document.getElementById('product_parameters_div').innerHTML = '';
               alert(xmlHttp.responseText.split('##########', 4)[2]);
               eval(xmlHttp.responseText.split('##########', 4)[2]);*/
               if(xmlHttp.responseText.split('##########', 5)[0]!='') document.getElementById('sub_category_select_div').innerHTML = xmlHttp.responseText.split('##########', 5)[0];
               //alert(xmlHttp.responseText.split('##########', 5)[1]);
               //alert(document.getElementById('webshop_products').innerHTML);
               document.getElementById('webshop_products').innerHTML = xmlHttp.responseText.split('##########', 5)[1];
               if(xmlHttp.responseText.split('##########', 5)[3]!=' ') document.getElementById('product_select_div').innerHTML = xmlHttp.responseText.split('##########', 5)[3];
               if(xmlHttp.responseText.split('##########', 5)[4]!=undefined) document.getElementById('product_parameters_div').innerHTML = xmlHttp.responseText.split('##########', 5)[4];
               else document.getElementById('product_parameters_div').innerHTML = '';
               //alert(xmlHttp.responseText.split('##########', 5)[2]);
               eval(xmlHttp.responseText.split('##########', 5)[2]);
               ResizeWebshopPage();
               SelectCheckboxesInArray();
               SelectCheckboxesInArrayPrefered();
            }
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?category_id=" +
                           category_id + 
                           "&type=" + category
                           ,true);
      xmlHttp.send(null);
   } 
}

function GetProductsFromProducts()
{
   product_id = document.getElementById('product_select').options[document.getElementById('product_select').selectedIndex].value;
   if(product_id == 0)
   {
      maincategory = document.getElementById('main_category_select');
      subcategory = document.getElementById('sub_category_select');
      if(subcategory.selectedIndex!=-1) category_id = subcategory.options[subcategory.selectedIndex].value;
      else category_id = maincategory.options[maincategory.selectedIndex].value;
   }
   else
   {
      category_id = -1;
   }
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               document.getElementById('webshop_products').innerHTML = xmlHttp.responseText.split('##########', 2)[0];
               document.getElementById('product_parameters_div').innerHTML = xmlHttp.responseText.split('##########', 2)[1];
            }
            ResizeWebshopPage();
            SelectCheckboxesInArray();
            SelectCheckboxesInArrayPrefered();
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?product_id=" +
                           product_id + "&category_id=" + category_id
                           ,true);
      xmlHttp.send(null);
   } 
}

/*function PutCart(product_code_id)
{
   //alert(document.getElementById('order_' + product_code_id).value);
   product_sum = document.getElementById('order_' + product_code_id).value;  
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               //alert(xmlHttp.responseText);
               document.getElementById('cart').innerHTML = xmlHttp.responseText;
               document.getElementById('order_' + product_code_id).value = 1;
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?product_code_id=" +
                           product_code_id + 
                           "&product_sum=" + product_sum
                           ,true);
      xmlHttp.send(null);
   } 
}*/

var webshop_timer;
function PutCart(product_code_id)
{
   //alert(document.getElementById('order_' + product_code_id).value);
   if(document.getElementById('order_' + product_code_id)) product_sum = document.getElementById('order_' + product_code_id).value;  
   else product_sum = 1; 
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               document.getElementById('cart_wrapper').style.display = 'block';
               cart_summa = xmlHttp.responseText.split('##########', 2)[0];
               menu_cart = xmlHttp.responseText.split('##########', 2)[1];
               if(document.getElementById('cart_link')) 
               {
                    document.getElementById('cart_link').innerHTML = menu_cart;
                    if(is_ie6)
                    {
                        document.getElementById('kosar_div').style.height = (document.getElementById('cart_wrapper').offsetHeight - 20) + 'px'; 
                        oHeight = document.getElementById('cart_wrapper').offsetHeight - 20;
                    } 
                    else
                    {                        
                        if(document.getElementById('kosar_div')){
                        oHeight = document.getElementById('kosar_div').offsetHeight;
                        }
                        else if (document.layers){
                        oHeight = document.layers['kosar_div'].clip.height;
                        }
                        
                    }
                    var i=parseInt(oHeight);
                    document.getElementById('kosar_img').style.margin = ((i-20)/2) - 21 + 'px 0px 0px 0px';  
               }   
               
               if(document.getElementById('cart')) document.getElementById('cart').innerHTML = cart_summa;
               if(document.getElementById('order_' + product_code_id)) document.getElementById('order_' + product_code_id).value = 1;
               
               var arrayPageSize = getPageSize();
               var arrayPageScroll = getPageScroll();
               if(document.getElementById('overlay2'))
               {
                  document.getElementById('overlay2').style.display = 'block';
                  document.getElementById('overlay2').style.height = arrayPageSize[1] + 'px';
                  //document.getElementById('cart_message').style.margin = arrayPageScroll[1] + (arrayPageSize[3] / 4) + 'px auto 0px auto';
                  document.getElementById('cart_message').style.position = 'fixed';
                  document.getElementById('cart_message').style.top = arrayPageSize[3] / 4 + 'px';
                  document.getElementById('cart_message').style.left = ((arrayPageSize[2]/2)-150) + 'px';
                  document.getElementById('cart_message').style.width = '300px';
                  document.getElementById('cart_message').style.height = '80px';
                  document.getElementById('cart_message').style.backgroundColor = '#eee';
                  document.getElementById('cart_message').style.border = '1px solid #7b858f';
                  document.getElementById('cart_message').innerHTML = '<div style="height: 10px; width: 100%; border-bottom: 1px solid #7b858f; text-align: center; background: #fff; padding: 5px 0px 5px 0px;">Kosár</div>' + 
                                            '<div style="height: 55px; width: 100%; text-align: center; background: transparent; padding-top: 5px;">' + product_sum + ' db termék került a kosárba!' +
                                            '<div style="margin: 10px auto 10px auto;"><input type="button" value="Tovább" onclick="clearTimeout(webshop_timer); document.getElementById(\'overlay2\').style.display = \'none\';" />&nbsp;&nbsp;&nbsp;<input type="button" value="Részletes kosár" onclick="JumpToCart();" /></div></div>';
               }
               else
               {
                  var objOverlay = document.createElement("div");
                  objOverlay.setAttribute('id','overlay2');
                  //objOverlay.setAttribute('style','height: ' + arrayPageSize[1] + 'px');
                  objOverlay.style.display = 'block';
                  objOverlay.style.height = arrayPageSize[1] + 'px';

                  var objMessageDiv = document.createElement('div');
                  objMessageDiv.setAttribute('id','cart_message');
                  objMessageDiv.setAttribute('style','border: 1px solid #7b858f; width: 300px; font-weight: bold; height: 80px; position: fixed; top: ' + arrayPageSize[3] / 4 + 'px; left: ' + ((arrayPageSize[2]/2)-150) + 'px;  background: #eee;');
                  objMessageDiv.style.position = 'fixed';
                  objMessageDiv.style.top = arrayPageSize[3] / 4 + 'px';
                  objMessageDiv.style.left = ((arrayPageSize[2]/2)-150) + 'px';
                  objMessageDiv.style.width = '300px';
                  objMessageDiv.style.height = '80px';
                  objMessageDiv.style.backgroundColor = '#eee';
                  objMessageDiv.style.border = '1px solid #7b858f';
                  
                  objMessageDiv.innerHTML = '<div style="height: 10px; width: 100%; border-bottom: 1px solid #7b858f; text-align: center; background: #fff; padding: 5px 0px 5px 0px;">Kosár</div>' + 
                                            '<div style="height: 55px; width: 100%; text-align: center; background: transparent; padding-top: 5px;">' + product_sum + ' db termék került a kosárba!' +
                                            '<div style="margin: 10px auto 10px auto;"><input type="button" value="Tovább" onclick="clearTimeout(webshop_timer); document.getElementById(\'overlay2\').style.display = \'none\';" />&nbsp;&nbsp;&nbsp;<input type="button" value="Részletes kosár" onclick="JumpToCart();" /></div></div>';
               
                  document.getElementsByTagName('BODY').item(0).appendChild(objOverlay);
                  objOverlay.appendChild(objMessageDiv);
               }
               /*document.getElementById('overlay2').style.display = 'none'*/
               webshop_timer = setTimeout("document.getElementById('overlay2').style.display = 'none';", 4000);
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?product_code_id=" +
                           product_code_id + 
                           "&product_sum=" + product_sum
                           ,true);
      xmlHttp.send(null);
   } 
}

function OnlyNumForWebshop(e, cart_id)
{
   var keynum;
   var keychar;
   var numcheck;

   if(window.event) // IE
   {
           keynum = e.keyCode;
   }
   else if(e.which) // Netscape/Firefox/Opera
   {
           keynum = e.which;
   }
   if(keynum==13)
   {
      ChangeCart(cart_id);
      document.getElementById('cart_' + cart_id).blur();
   }
   if(keynum!=8 && keynum!=9 && keynum!=46 && keynum!=37 && keynum!=39 && keynum!=96 && keynum!=97 && 
      keynum!=98 && keynum!=99 && keynum!=100 && keynum!=101 && keynum!=102 && keynum!=103 && 
      keynum!=104 && keynum!=105)
   {   
      keychar = String.fromCharCode(keynum);
      numcheck = /\d/;
      return numcheck.test(keychar);
   }   
}

function AddToCart(cart_id)
{
   cart_sum = document.getElementById('cart_' + cart_id).value;   
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               document.getElementById('cart_wrapper').style.display = 'block';
               cart_summa = parseInt(xmlHttp.responseText.split('##########', 2)[0]);
               menu_cart = xmlHttp.responseText.split('##########', 2)[1];

               if(document.getElementById('cart_link')) 
               {
                  document.getElementById('cart_link').innerHTML = menu_cart;
                    if(is_ie6)
                    {
                        document.getElementById('kosar_div').style.height = (document.getElementById('cart_wrapper').offsetHeight - 20) + 'px'; 
                        oHeight = document.getElementById('cart_wrapper').offsetHeight - 20;
                    } 
                    else
                    {                  
                      if(document.getElementById('kosar_div')){
                      oHeight = document.getElementById('kosar_div').offsetHeight;
                      }
                      else if (document.layers){
                      oHeight = document.layers['kosar_div'].clip.height;
                      }    
                    }
                    var i=parseInt(oHeight);
                    document.getElementById('kosar_img').style.margin = ((i-20)/2) - 21 + 'px 0px 0px 0px';
               }   
               
               document.getElementById('cart_' + cart_id).value = cart_summa;
               document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * cart_summa;
               
               var full_sum = 0;
               var inputs = document.getElementById('cart_table').getElementsByTagName('input');
               for(i=0; i<inputs.length; i++)
               {
                  if(inputs[i].id.search('sum_')!=-1)
                  {
                     full_sum = full_sum + parseInt(inputs[i].value);
                  }
               } 
               document.getElementById('full_price').value = full_sum; 
               document.getElementById('product_sum_text').value = parseInt(document.getElementById('product_sum_text').value) + 1;
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?cart_id=" +
                           cart_id +
                           "&action=add"
                           ,true);
      xmlHttp.send(null);
   } 
}

function RemoveFromCart(cart_id)
{
   //alert(document.getElementById('order_' + product_code_id).value);
   cart_sum = document.getElementById('cart_' + cart_id).value;
   if(cart_sum==1) DeleteFromCart(cart_id);
   if(cart_sum>1)
   {
      var xmlHttp = createRequestObject();
      if(xmlHttp)
      {
         xmlHttp.onreadystatechange=function()
         {
            if(xmlHttp.readyState==4)
            {
               if(xmlHttp.responseText != '')
               {
                  cart_summa = parseInt(xmlHttp.responseText.split('##########', 2)[0]);
                  menu_cart = xmlHttp.responseText.split('##########', 2)[1];
                  if(document.getElementById('cart_link')) 
                  {
                     document.getElementById('cart_link').innerHTML = menu_cart;
                    if(is_ie6)
                    {
                        document.getElementById('kosar_div').style.height = (document.getElementById('cart_wrapper').offsetHeight - 20) + 'px';
                        oHeight = document.getElementById('cart_wrapper').offsetHeight - 20;                        
                    } 
                    else
                    {
                         if(document.getElementById('kosar_div')){
                         oHeight = document.getElementById('kosar_div').offsetHeight;
                         }
                         else if (document.layers){
                         oHeight = document.layers['kosar_div'].clip.height;
                         }
                    }
                    var i=parseInt(oHeight);
                    document.getElementById('kosar_img').style.margin = ((i-20)/2) - 21 + 'px 0px 0px 0px'; 
                  }   
                  document.getElementById('cart_' + cart_id).value = cart_summa;
                  document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * cart_summa;
                  
                  var full_sum = 0;
                  var inputs = document.getElementById('cart_table').getElementsByTagName('input');
                  for(i=0; i<inputs.length; i++)
                  {
                     if(inputs[i].id.search('sum_')!=-1)
                     {
                        full_sum = full_sum + parseInt(inputs[i].value);
                     }
                  } 
                  document.getElementById('full_price').value = full_sum;  
               }            
            }
         }
         xmlHttp.open("GET","webshop_ajax.php?cart_id=" +
                              cart_id + 
                              "&action=remove"
                              ,true);
         xmlHttp.send(null);
      }
   }
}

function DeleteFromCart(cart_id)
{
   //alert(document.getElementById('order_' + product_code_id).value);
   cart_sum = document.getElementById('cart_' + cart_id).value;  
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               cart_summa = xmlHttp.responseText.split('##########', 2)[0];
               menu_cart = xmlHttp.responseText.split('##########', 2)[1];
               
               document.getElementById('cart').innerHTML = cart_summa;   
               if(document.getElementById('cart_link')) 
               {
                  document.getElementById('cart_link').innerHTML = menu_cart;
                    if(is_ie6)
                    {
                        document.getElementById('kosar_div').style.height = (document.getElementById('cart_wrapper').offsetHeight - 20) + 'px'; 
                        oHeight = document.getElementById('cart_wrapper').offsetHeight - 20;
                    } 
                    else
                    {
                          if(document.getElementById('kosar_div')){
                          oHeight = document.getElementById('kosar_div').offsetHeight;
                          }
                          else if (document.layers){
                          oHeight = document.layers['kosar_div'].clip.height;
                          }            
                    }
                    var i=parseInt(oHeight); 
                    document.getElementById('kosar_img').style.margin = ((i-20)/2) - 21 + 'px 0px 0px 0px';
               }   
               ShowFullCart();
               if(document.getElementById('product_sum_text').value==0) document.getElementById('cart_wrapper').style.display = 'none';
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?cart_id=" +
                           cart_id + 
                           "&action=delete"
                           ,true);
      xmlHttp.send(null);
   } 
}

function EmptyCart()
{
   //alert(document.getElementById('order_' + product_code_id).value);
   //cart_sum = document.getElementById('cart_' + cart_id).value;  
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               document.getElementById('cart_wrapper').style.display = 'none';
               cart_summa = xmlHttp.responseText.split('##########', 2)[0];
               menu_cart = xmlHttp.responseText.split('##########', 2)[1];
               
               document.getElementById('cart').innerHTML = cart_summa;   
               if(document.getElementById('cart_link')) 
               {
                  document.getElementById('cart_link').innerHTML = menu_cart;
                  if(document.getElementById('kosar_div')){
                  oHeight = document.getElementById('kosar_div').offsetHeight;
                  }
                  else if (document.layers){
                  oHeight = document.layers['kosar_div'].clip.height;
                  }
                  var i=parseInt(oHeight);
                  document.getElementById('kosar_img').style.margin = ((i-20)/2) - 21 + 'px 0px 0px 0px';                  
               }    
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?emptycart=yes"
                           ,true);
      xmlHttp.send(null);
   } 
}

function ChangeCart(cart_id)
{
   cart_sum = document.getElementById('cart_' + cart_id).value;
   if(cart_sum==0) DeleteFromCart(cart_id);
   else if(cart_sum>0)
   {
      var xmlHttp = createRequestObject();
      if(xmlHttp)
      {
         xmlHttp.onreadystatechange=function()
         {
            if(xmlHttp.readyState==4)
            {
               if(xmlHttp.responseText != '')
               {
                  document.getElementById('cart_wrapper').style.display = 'block';
                  cart_summa = parseInt(xmlHttp.responseText.split('##########', 2)[0]);
                  menu_cart = xmlHttp.responseText.split('##########', 2)[1];

                  if(document.getElementById('cart_link')) 
                  {
                     document.getElementById('cart_link').innerHTML = menu_cart;
                     if(document.getElementById('kosar_div')){
                     oHeight = document.getElementById('kosar_div').offsetHeight;
                     }
                     else if (document.layers){
                     oHeight = document.layers['kosar_div'].clip.height;
                     }
                     var i=parseInt(oHeight);
                     document.getElementById('kosar_img').style.margin = ((i-20)/2) - 21 + 'px 0px 0px 0px';                  
                  }   
                  
                  document.getElementById('cart_' + cart_id).value = cart_summa;
                  document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * cart_summa;
                  
                  var full_sum = 0;
                  var inputs = document.getElementById('cart_table').getElementsByTagName('input');
                  for(i=0; i<inputs.length; i++)
                  {
                     if(inputs[i].id.search('sum_')!=-1)
                     {
                        full_sum = full_sum + parseInt(inputs[i].value);
                     }
                  } 
                  document.getElementById('full_price').value = full_sum;  
                  document.getElementById('cart_' + cart_id).readonly = true;
               }            
            }
         }
         xmlHttp.open("GET","webshop_ajax.php?cart_id=" +
                              cart_id + 
                              "&action=set&cart_number=" +
                              cart_sum
                              ,true);
         xmlHttp.send(null);
      }
   }
   else DeleteFromCart(cart_id);
}

function NotEmpty()
{
   if(document.getElementById('transit_address_id'))
   {
      if(document.getElementById('transit_address_id').selectedIndex>0) return true;
   }   
   var notempty = true;
   for(i=0;i<(arguments.length/2);i++)
   {
      var key = ((arguments.length/2)+i);
      notempty = !isempty_onerow('chest_table',arguments[i],arguments[key]) && notempty;
   }
   
   return notempty;
}

/******** athozott********/
function SelectProductCodes(checked, type)
{
   //alert(type);
   if(type=='full')
   {
      var i=0;
      if(checked)
      {
         for(x in full_product_array)
         {
            product_code_array[x] = 1;
         }
      }
      else
      {
         for(x in full_product_array)
         {
            product_code_array[x] = 0;
         }         
      }
   }   
   else if(type=='page')
   {
      var page_checkboxes = document.getElementById('webshop_products_inner').getElementsByTagName('INPUT');
      if(checked)
      {
         for(x=0;x<page_checkboxes.length;x++)
         {
            if(page_checkboxes[x].type=="checkbox" && page_checkboxes[x].id.split('_', 2)[0]=='pc')
            {
               key = page_checkboxes[x].id.split('_', 2)[1];
               product_code_array[key] = 1;
               //alert(product_code_array[key]);
            }   
         }
      }        
      else
      {
         for(x=0;x<page_checkboxes.length;x++)
         {
            if(page_checkboxes[x].type=="checkbox" && page_checkboxes[x].id.split('_', 2)[0]=='pc')
            {
               key = page_checkboxes[x].id.split('_', 2)[1];
               product_code_array[key] = 0;
            }   
         }
      }   
   }
   /*var str = '';
   for(x in full_product_array)
   {
      str += "full_product_array[" + x + "] = " +  full_product_array[x] + "\n";
   }
   alert(str);*/
   SelectCheckboxesInArray();
}

function AddToProductsDiscountArray(checked, product_code_id)
{
   if(checked) product_code_array[product_code_id] = 1;
   else product_code_array[product_code_id] = 0;
   /*var str = '';
   for(x in product_code_array)
   {
      str += "product_code_array[" + x + "] = " +  product_code_array[x] + "\n";
   }
   alert(str);*/
}

function SelectCheckboxesInArray()
{
   //alert(document.getElementById('webshop_products_inner'));
   if(document.getElementById('webshop_products_inner'))
   {
      var page_checkboxes = document.getElementById('webshop_products_inner').getElementsByTagName('INPUT');
      for(x=0;x<page_checkboxes.length;x++)
      {
         
         if(page_checkboxes[x].type=="checkbox" && page_checkboxes[x].id.split('_', 2)[0]=='pc' && product_code_array[page_checkboxes[x].id.split('_', 2)[1]]==1)
         {
            page_checkboxes[x].checked = true;
         }
         if(page_checkboxes[x].type=="checkbox" && page_checkboxes[x].id.split('_', 2)[0]=='pc' && product_code_array[page_checkboxes[x].id.split('_', 2)[1]]==0)
         {
            page_checkboxes[x].checked = false;
         } 
      }
   }   
}

function SelectCheckboxesInArrayPrefered() //preferált termékek kiválasztása
{
   if(document.getElementById('webshop_products_inner'))
   {
      var page_checkboxes = document.getElementById('webshop_products_inner').getElementsByTagName('INPUT');
      for(x=0;x<page_checkboxes.length;x++)
      {    
         if(page_checkboxes[x].type=="checkbox" && page_checkboxes[x].id.split('_', 2)[0]=='pref' && prefered_product_array[page_checkboxes[x].id.split('_', 2)[1]]==1)
         {
            page_checkboxes[x].checked = true;
         }
         if(page_checkboxes[x].type=="checkbox" && page_checkboxes[x].id.split('_', 2)[0]=='pref' && prefered_product_array[page_checkboxes[x].id.split('_', 2)[1]]==0)
         {
            page_checkboxes[x].checked = false;
         } 
      }
   }   
}

function DiscountSubmit()
{
   for(x in product_code_array)
   {
      if(product_code_array[x]==1)
      {
         document.getElementById('product_code_ids').value += x + ','; 
      }   
      
   }
   //alert(document.getElementById('product_code_ids').value);
   document.getElementById('discount_form').submit();
}

function DiscountSubmit_in_update()
{
   var form_elements = document.getElementById("discount_update_table").getElementsByTagName('INPUT');
   for(x=0;x<form_elements.length;x++)
   {
      if(form_elements[x].type=="checkbox" && form_elements[x].id.split("_",2)[0]=='pc' && form_elements[x].checked)
      {
         document.getElementById('product_code_ids').value += form_elements[x].id.split("_",2)[1] + ",";
      }
   }
   document.getElementById('discount_update_form').submit();
}

function AddToPreferedProducts(checked, product_code_id)
{
   if(checked) action = 'add';
   else action = 'remove';
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != 'OK')
            {
               alert('Hiba! Nem sikerült a terméket felvenni a kiemelt termékek közé!');
            }
            else
            {
               if(action=='add') prefered_product_array[product_code_id] = 1;
               else if(action=='remove') prefered_product_array[product_code_id] = 0;
            }
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?prefered_id=" +
                           product_code_id + 
                           "&action=" +
                           action
                           ,true);
      xmlHttp.send(null);
   }
}

function NotEmptyComp()
{ 
   var notempty = true;
   for(i=0;i<(arguments.length/2);i++)
   {
      var key = ((arguments.length/2)+i);
      notempty = !isempty_onerow('chest_company_table',arguments[i],arguments[key]) && notempty;
   }
   
   return notempty;
}

function NotEmptyTel()
{
   var notempty = true;
   var text1 = document.getElementById('order_tel_1').value;
   var text2 = document.getElementById('order_tel_2').value;
   notempty = (text1.length > 0) && (text2.length >= 6) && notempty;      

   var x = document.getElementById('chest_table').rows[2].cells;
   if(!notempty)
   {
      x[2].innerHTML="<img src='./data/pics/notok.png' />";
      x[0].style.background = x[1].style.background = x[2].style.background = "#ffdddd";
   }   
   else
   {
      x[2].innerHTML="<img src='./data/pics/ok.png' />";
      x[0].style.background = x[1].style.background = x[2].style.background = "#dddddd";
   }
   
   return notempty;
}

function NotEmptyTaxInvoice()
{ 
   var notempty = true;
   var text1 = document.getElementById('order_tax_invoice_first').value;
   var text2 = document.getElementById('order_tax_invoice_second').value;
   var text3 = document.getElementById('order_tax_invoice_third').value;  
   notempty = (text1.length == 8) && (text2.length == 1) && (text3.length == 2) && notempty;      
   
   var x = document.getElementById('chest_company_table').rows[5].cells;
   if(!notempty)
   {
      x[2].innerHTML="<img src='./data/pics/notok.png' />";
      x[0].style.background = x[1].style.background = x[2].style.background = "#ffdddd";
   }   
   else
   {
      x[2].innerHTML="<img src='./data/pics/ok.png' />";
      x[0].style.background = x[1].style.background = x[2].style.background = "#dddddd";
   }
   
   if(!notempty) return false;
   else
   {
      var check_sum = (parseInt(text1.charAt(0))*9)+(parseInt(text1.charAt(1))*7)+(parseInt(text1.charAt(2))*3)+(parseInt(text1.charAt(3))*1)+(parseInt(text1.charAt(4))*9)+(parseInt(text1.charAt(5))*7)+(parseInt(text1.charAt(6))*3);
      if(10-(check_sum%10)!=parseInt(text1.charAt(7))) var err_text1 = "Az adószám első 8 számjegyében hiba van!\n";
      else var err_text1 = '';
      
      if(parseInt(text2)>3 || parseInt(text2)<1) var err_text2 = "Az adószám 9. számjegye 1,2,3 lehet!";
      else var err_text2 = '';    

      if((parseInt(text3)>=22 && parseInt(text3)<=44) || parseInt(text3)==51 || (parseInt(text3)>=10 && parseInt(text3)<=20) ||
         text3=='09' || text3=='08' || text3=='07' || text3=='06' || text3=='05' || 
         text3=='04' || text3=='03' || text3=='02')
      {
         var err_text3 = '';
      } 
      else var err_text3 = "Az utolsó két számjegy hibás!";
      var alert_string = err_text1 + err_text2 + err_text3;
      if(alert_string!='') 
      {
         x[2].innerHTML="<img src='./data/pics/notok.png' />";
         x[0].style.background = x[1].style.background = x[2].style.background = "#ffdddd";      
         alert(alert_string);
         return false;
      }   
      else
      {
         var err_text2 = "";
         x[2].innerHTML="<img src='./data/pics/ok.png' />";
         x[0].style.background = x[1].style.background = x[2].style.background = "#dddddd";
         return true;
      }   
   }   
}

function ResetAddressSelect(select_id)
{
   if(document.getElementById(select_id))
   {
      document.getElementById(select_id).selectedIndex = 0;
   }   
}

function ResetAddressDatas()
{
   var address_string = document.getElementById('transit_address_id').options[document.getElementById('transit_address_id').selectedIndex].text;
   if(document.getElementById('transit_address_id').selectedIndex!=0)
   {
      var postcode = address_string.substr(0,4);
      var first = address_string.search(',');
      var second = address_string.search('Tel.:');
      var city = address_string.substring(5, first);
      var address = address_string.substring((first)+2, second);
      var tel = address_string.substr((second)+6);
      if(tel.length==9 || tel.length==8) 
      {
         tel_1 = tel.substr(0,2);
         tel_2 = tel.substr(2);
      }      
      else
      {
         tel_1 = tel.substr(0,1);
         tel_2 = tel.substr(1);
      }
      //alert (first + "//" + second + "\n"+ address_string + '\n' + postcode + "\n" +city + "\n" +address + "\n" +tel + "\n");
      document.getElementById('order_postcode').value = postcode;
      document.getElementById('order_city').value = city;
      document.getElementById('order_address').value = address;
      document.getElementById('order_tel_1').value = tel_1;
      document.getElementById('order_tel_2').value = tel_2;
      document.getElementById('order_comment').value = '';
      GetCities('order_postcode', 'order_city_div');
   }
}
function ResetBillingAddressDatas()
{
   var address_string = document.getElementById('billing_address_id').options[document.getElementById('billing_address_id').selectedIndex].text;
   if(document.getElementById('billing_address_id').selectedIndex!=0)
   {
      var first = address_string.search(';');
      var comp_name = address_string.substr(0,first);
      var postcode = address_string.substr(first+2,4);
      var second = address_string.search(',');
      var city = address_string.substring(first+7,second);
      var address = address_string.substring(second+2);
      //alert(comp_name + '//' + postcode + '//' + city + '//' + address);
      //alert (first + "//" + second + "\n"+ address_string + '\n' + postcode + "\n" +city + "\n" +address + "\n" +tel + "\n");
      document.getElementById('comp_order_postcode').value = postcode;
      document.getElementById('comp_order_city').value = city;
      document.getElementById('comp_order_address').value = address;
      document.getElementById('order_company_name').value = comp_name;
      document.getElementById('order_tax_invoice_first').value = tax_array[document.getElementById('billing_address_id').options[document.getElementById('billing_address_id').selectedIndex].value].substr(0,8);
      document.getElementById('order_tax_invoice_second').value = tax_array[document.getElementById('billing_address_id').options[document.getElementById('billing_address_id').selectedIndex].value].substr(8,1);
      document.getElementById('order_tax_invoice_third').value = tax_array[document.getElementById('billing_address_id').options[document.getElementById('billing_address_id').selectedIndex].value].substr(9);
   }
}

function GetCities(input_id)
{
   var postcode = document.getElementById(input_id).value
   //if(input_id=='postcode') input_city = 'city';
   //else if(input_id=='comp_order_postcode') input_city = 'comp_order_city';
   var xmlHttp = createRequestObject();
   if(postcode.length==4)
   {
      if(xmlHttp)
      {
         xmlHttp.onreadystatechange=function()
         {
            if(xmlHttp.readyState==4)
            {
               if(xmlHttp.responseText != '')
               {
                  document.getElementById('city').value = xmlHttp.responseText;
               }
               else
               {
                  alert('Nem ismert település! Kérjük ellenőrizze az irányítószámot, amennyiben az helyes adja meg a telülés nevét!');
                  document.getElementById('city').readOnly = false;                 
               }
            }
         }
         xmlHttp.open("GET","webshop_ajax.php?postcode=" + postcode,true);
         xmlHttp.send(null);
      }
   }
}

function GetDeliveryPrice()
{
   //alert(document.getElementById('delivery_method').options[document.getElementById('delivery_method').selectedIndex].value);
   //alert(document.getElementById('payment_method').options[document.getElementById('payment_method').selectedIndex].value);
   if(document.getElementById('delivery_method').options[document.getElementById('delivery_method').selectedIndex].value == '0')
   {
      document.getElementById('order_postcode').value = '0000';
      document.getElementById('order_city').value = '-';
      document.getElementById('order_address').value = '-';
      document.getElementById('transit_address_id').selectedIndex = 0;      
   }
   else if((document.getElementById('delivery_method').options[document.getElementById('delivery_method').selectedIndex].value != '0') && 
            document.getElementById('order_postcode').value=='0000')
   {
      document.getElementById('order_postcode').value = '';
      document.getElementById('order_city').value = '';
      document.getElementById('order_address').value = '';
      document.getElementById('transit_address_id').selectedIndex = 0;       
   }
   /*var price_table = Array();
   price_table[0] = Array();
   price_table[0][0] = '0 Ft';
   price_table[0][1] = '2500 Ft';
   price_table[0][2] = '1500 Ft';
   price_table[0][3] = '2500 Ft';   
   price_table[1] = Array();
   price_table[1][0] = '0 Ft';
   price_table[1][1] = '1300 Ft';
   price_table[1][2] = '1000 Ft';
   price_table[1][3] = '2000 Ft';*/
   var delivery_id = document.getElementById('delivery_method').options[document.getElementById('delivery_method').selectedIndex].value;
   var payment_id = document.getElementById('payment_method').options[document.getElementById('payment_method').selectedIndex].value;
   document.getElementById('receive_price_div').innerHTML = price_table[payment_id][delivery_id];
   if(document.getElementById('delivery_method').options[document.getElementById('delivery_method').selectedIndex].value==3)
   {
      document.getElementById('express_warning_div').innerHTML="Csak a hétközben délután kettőig (14:00) érvényesített rendelések szállítását tudjuk teljesíteni. Kérjük vegye fel a kapcsolatot ügyfélszolgálatunkkal. Hotline: +3614350430.";
   }
   else if(document.getElementById('express_warning_div'))
   {
      document.getElementById('express_warning_div').innerHTML="";
   }

}

function CheckPrice_Submit()
{
   var prices = document.getElementById('price_table').getElementsByTagName('INPUT');
   var bool_price = true;
   for(i=0; i<prices.length; i++)
   {
      if(prices[i].type=="text" && prices[i].className == "szam")
      {
         bool_price = (prices[i].value.length>0) && bool_price;
      } 
   } 
   if(bool_price) document.getElementById('price_manager_form').submit();
   else alert('A termékek ára nem lehet üres!');
}

function ShowFullCart()
{
   if(document.getElementById('show_cart_img_id').src.search('data/pics/plus.png')!=-1)
   {
      document.getElementById('cart_inner_div').style.display='block';
      document.getElementById('show_cart_img_id').src = 'data/pics/minus.png';
   }
   else if(document.getElementById('show_cart_img_id').src.search('data/pics/minus.png')!=-1)
   {
      document.getElementById('cart_inner_div').style.display='none';
      document.getElementById('show_cart_img_id').src = 'data/pics/plus.png';
   }   
   ResizeWebshopPage();
}   

function ContinueTyping(myobject, target_id)
{
   if(myobject.value.length == myobject.maxLength)
   {
      document.getElementById(target_id).focus();
   }
}

function RedirectWebshop(category_id)
{
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               location.href = "webshop&inner=1#start";
            }
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?category_id=" + category_id + "&redirect=1"
                           ,true);
      xmlHttp.send(null);
   }
}

function Checktel()
{
   var korzet = document.getElementById('order_tel_1').value
   if(korzet=='20' || korzet=='30' || korzet=='70')
   {
      document.getElementById('order_tel_2').maxLength = 7;
   }
   else
   {
      document.getElementById('order_tel_2').maxLength = 6;
   }
}

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;
        }


        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
        return arrayPageSize;
}

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 JumpToCart()
{
   clearTimeout(webshop_timer); 
   document.getElementById('overlay2').style.display = 'none';
   location.href = "webshop#cart_details";
   ShowFullCart();
}

function get(obj, mode) 
{
   if(mode=='reset') makeRequest('webshop_ajax.php', '');
   else
   {
      var getstr = "&";
      var inputs = obj.getElementsByTagName('INPUT');
      for(i=0; i<inputs.length; i++)
      {
         if(inputs[i].type=="text")
         {
            getstr += inputs[i].name + "=" + encodeURIComponent(inputs[i].value) + "&";
         }         
         if(inputs[i].type=="hidden")
         {
            getstr += inputs[i].name + "=" + encodeURIComponent(inputs[i].value) + "&";
         }
         if(inputs[i].type=="checkbox")
         {
            if(inputs[i].checked)
            {
               getstr += inputs[i].name + "=" + encodeURIComponent(inputs[i].value) + "&";
            }  
         }
         if(inputs[i].type=="radio")
         {
            if(inputs[i].checked)
            {
               getstr += inputs[i].name + "=" + encodeURIComponent(inputs[i].value) + "&";
            }
         }         
      }
      var inputs = obj.getElementsByTagName('SELECT');
      for(i=0; i<inputs.length; i++)
      {
         getstr += inputs[i].name  + "=" + inputs[i].options[inputs[i].selectedIndex].value + "&";
      }
      //alert(getstr);
      makeRequest('webshop_ajax.php', getstr);
   }
}

function makeRequest(url, parameters) 
{
   maincategory = document.getElementById('main_category_select');
   subcategory = document.getElementById('sub_category_select');
   /*sub2category = -1;
   if(sub2category.selectedIndex!=-1) 
   {
      category_id = sub2category.options[sub2category.selectedIndex].value;
      add_get = "category_id=" + category_id + "&type=sub2";
        link2 = document.getElementById('sub_category_select');
        if(document.getElementById('permalink')) document.getElementById('permalink').style.display = 'block';
        if(document.getElementById('reallink')) document.getElementById('reallink').innerHTML = link2 + '/' + category_id;
   }   */
   if(subcategory.selectedIndex!=-1) 
   {
      category_id = subcategory.options[subcategory.selectedIndex].value;
      add_get = "category_id=" + category_id + "&type=sub";
        if(document.getElementById('permalink')) document.getElementById('permalink').style.display = 'block';
        if(document.getElementById('reallink')) document.getElementById('reallink').innerHTML = category_id;
   }
   else 
   {
      category_id = maincategory.options[maincategory.selectedIndex].value;
      add_get = "category_id=" + category_id + "&type=main";
      if(document.getElementById('permalink')) document.getElementById('permalink').style.display = 'none';
   }
   var xmlHttp = createRequestObject();
   
   var arrayPageSize = getPageSize();
   var arrayPageScroll = getPageScroll();
   
   if(document.getElementById('overlay'))
   {
      document.getElementById('overlay').style.display = 'block';
      document.getElementById('overlay').style.height = arrayPageSize[1] + 'px';
      document.getElementById('loading_img').style.margin = arrayPageScroll[1] + (arrayPageSize[3] / 2) + 'px auto 0px auto';
   }
   else
   {
      var objOverlay = document.createElement("div");
      objOverlay.setAttribute('id','overlay');
      objOverlay.setAttribute('style','height: ' + arrayPageSize[1] + 'px');
      objOverlay.style.display = 'block';
      
      var objLoadingImage = document.createElement("img");
      objLoadingImage.setAttribute('src', './data/pics/loading.gif');
      objLoadingImage.setAttribute('class', 'loading_img');
      objLoadingImage.setAttribute('id', 'loading_img');
      objLoadingImage.setAttribute('style','margin: ' + arrayPageScroll[1] + (arrayPageSize[3] / 2) + 'px auto 0px auto');
      
      document.getElementsByTagName('BODY').item(0).appendChild(objOverlay);
      objOverlay.appendChild(objLoadingImage);
   }  
   
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               //alert(xmlHttp.responseText.split('##########', 5)[3]);
               document.getElementById('overlay').style.display = 'none';
               if(xmlHttp.responseText.split('##########', 5)[0]!='') document.getElementById('sub_category_select_div').innerHTML = xmlHttp.responseText.split('##########', 2)[0];
               document.getElementById('webshop_products').innerHTML = xmlHttp.responseText.split('##########', 5)[1];
               if(xmlHttp.responseText.split('##########', 5)[3]!=' ') document.getElementById('sub2_category_select_div').innerHTML = xmlHttp.responseText.split('##########', 5)[3];
               if(xmlHttp.responseText.split('##########', 5)[4]!=undefined) document.getElementById('product_parameters_div').innerHTML = xmlHttp.responseText.split('##########', 5)[4];
               else document.getElementById('product_parameters_div').innerHTML = '';
               eval(xmlHttp.responseText.split('##########', 5)[2]);  
               SelectCheckboxesInArray();
               SelectCheckboxesInArrayPrefered();
               document.getElementById('overlay').style.display = 'none';
            }            
         }
      }
   }
   //alert(url + parameters);
   //alert(add_get);
   xmlHttp.open("GET",url + "?" +  add_get + parameters,true);
   xmlHttp.send(null);   
}   