function GetProducts(category)
{
   if(category=='main'){
        
        sel_index=document.getElementById('main_category_select').selectedIndex;
        sel_value=document.getElementById('main_category_select').options[sel_index].innerHTML;
        category_id = document.getElementById('main_category_select').options[sel_index].value;
        
        if(sel_index!=0){
            document.getElementById('smain_category_select').innerHTML=sel_value;
        }else{
            document.getElementById('smain_category_select').innerHTML="-- összes --";
            category_id=0;
        }
        
   }
   else if(category=='sub') 
   {
      /*
      category_id = document.getElementById('sub_category_select').options[document.getElementById('sub_category_select').selectedIndex].value;
      document.getElementById('ssub_category_select').innerHTML=document.getElementById('sub_category_select').options[document.getElementById('sub_category_select').selectedIndex].innerHTML;
      if(category_id==0) category_id = document.getElementById('main_category_select').options[document.getElementById('main_category_select').selectedIndex].value;
      */
      
      sel_index=document.getElementById('sub_category_select').selectedIndex;
      sel_value=document.getElementById('sub_category_select').options[sel_index].innerHTML;
      category_id = document.getElementById('sub_category_select').options[sel_index].value;
      
      if(sel_index!=0){
          document.getElementById('ssub_category_select').innerHTML=sel_value;
      }else{
          //category_id = document.getElementById('main_category_select').options[document.getElementById('main_category_select').selectedIndex].value;
          category_id=0;
          document.getElementById('ssub_category_select').innerHTML="-- összes --";
      }
   }
   else if(category=='sub2') 
   {
      /*
      category_id = document.getElementById('sub_category_select').options[document.getElementById('sub_category_select').selectedIndex].value;
      document.getElementById('ssub_category_select').innerHTML=document.getElementById('sub_category_select').options[document.getElementById('sub_category_select').selectedIndex].innerHTML;
      if(category_id==0) category_id = document.getElementById('main_category_select').options[document.getElementById('main_category_select').selectedIndex].value;
      */
      
      sel_index=document.getElementById('sub2_category_select').selectedIndex;
      sel_value=document.getElementById('sub2_category_select').options[sel_index].innerHTML;
      category_id = document.getElementById('sub2_category_select').options[sel_index].value;
      
      if(sel_index!=0){
          document.getElementById('ssub2_category_select').innerHTML=sel_value;
      }else{
          //category_id = document.getElementById('sub_category_select').options[document.getElementById('sub_category_select').selectedIndex].value;
          category_id=0;
          document.getElementById('ssub2_category_select').innerHTML="-- összes --";
      }
   }
        
   var xmlHttp = createRequestObject();
   
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
            //alert(xmlHttp.responseText);
               splitted=xmlHttp.responseText.split('##########');
               
               //alert(splitted[0]);
               
               if(splitted[0]!='') document.getElementById('sub_category_select_div').innerHTML = splitted[0];
               document.getElementById('webshop_products').innerHTML = splitted[1];
               if(splitted[3]!='') document.getElementById('sub2_category_select_div').innerHTML = splitted[3];
               document.getElementById('epopup2').innerHTML = splitted[4];
               document.getElementById('epopup3').innerHTML = splitted[5];
               
               //if(xmlHttp.responseText.split('##########', 4)[3]!=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(splitted[2]);
               
               
               
            }
            SelectCheckboxesInArray();
            SelectCheckboxesInArrayPrefered();
            //document.getElementById('overlay').style.display = 'none';
         }else if(xmlHttp.readyState==1){
            FillLoader('webshop_products');
         }
      }

      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;
   document.getElementById('sproduct_select').innerHTML=document.getElementById('product_select').options[document.getElementById('product_select').selectedIndex].innerHTML;
   */
   
   sel_index=document.getElementById('product_select').selectedIndex;
   sel_value=document.getElementById('product_select').options[sel_index].innerHTML;
   product_id = document.getElementById('product_select').options[sel_index].value;
   
   if(sel_index!=0){
       document.getElementById('sproduct_select').innerHTML=sel_value;
   }else{
       document.getElementById('sproduct_select').innerHTML="-- összes --";
   }
   
   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((x = xmlHttp.readyState)==4)
         {
            if(xmlHttp.responseText != '')
            {
               //alert(xmlHttp.responseText);
               splitted=xmlHttp.responseText.split('##########');
               document.getElementById('webshop_products').innerHTML = splitted[0];
               document.getElementById('epopup2').innerHTML = splitted[2];
               //document.getElementById('product_parameters_div').innerHTML = xmlHttp.responseText.split('##########', 3)[2];
               eval(splitted[1]);               
            }
            SelectCheckboxesInArray();
            SelectCheckboxesInArrayPrefered();
            //document.getElementById('overlay').style.display = 'none';
         }else if(x == 1){
            //document.getElementById('webshop_products').innerHTML="["+x+"] Loading ...";
            FillLoader('webshop_products');
         }
      }
      
      xmlHttp.open("GET","webshop_ajax.php?product_id=" +
                           product_id + "&category_id=" + category_id
                           ,true);
      xmlHttp.send(null);

      
   } 
}

function SetHS(index,olID,pID){
    document.getElementById('sort_order_select').selectedIndex=index;
    SetOrder(document.getElementById('sort_order_select'), -1);
    links=document.getElementById(pID).parentNode.getElementsByTagName('A');
    for(i=0;i<links.length;i++){
        if(links[i].id==olID){
            links[i].className="ml_akt";
            document.getElementById('rtitle').innerHTML=links[i].innerHTML;
        }else{
            links[i].className="";
        }
    }
}

function SetUrmertek(kisid,cvalue,pID){

    links=document.getElementById(pID).parentNode.getElementsByTagName('A');
    for(i=0;i<links.length;i++){
        if(links[i].id==kisid){
            links[i].className="ml_akt";
            //document.getElementById('ktitle').innerHTML=links[i].innerHTML;
        }else{
            links[i].className="";
        }
    }
    
    var xmlHttp = createRequestObject();
    
    if(xmlHttp){
            xmlHttp.onreadystatechange=function(){
                if(xmlHttp.readyState==4){
                    splitted=xmlHttp.responseText.split('##########');
                document.getElementById('webshop_products').innerHTML = splitted[1];
                document.getElementById('epopup3').innerHTML = splitted[5];
                eval(splitted[2]);
                }else{
                   FillLoader('webshop_products');
                }
            }
            
            xmlHttp.open("GET","webshop_ajax.php?urmertek=" + cvalue, true);
            xmlHttp.send(null);
    }
    
}

function SetBrand(marka,brandid,pID){

    //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!=0) category_id = subcategory.options[subcategory.selectedIndex].value;
        else category_id = maincategory.options[maincategory.selectedIndex].value;
    */
    //}
    //else
    //{
//      category_id = -1;
    //}

    links=document.getElementById(pID).parentNode.getElementsByTagName('A');
    for(i=0;i<links.length;i++){
        if(links[i].id==brandid){
            links[i].className="ml_akt";
            //document.getElementById('ktitle').innerHTML=links[i].innerHTML;
        }else{
            links[i].className="";
        }
    }
    
    var xmlHttp = createRequestObject();
    
    if(xmlHttp){
        xmlHttp.onreadystatechange=function(){
            if(xmlHttp.readyState==4){
               splitted=xmlHttp.responseText.split('##########');
               document.getElementById('webshop_products').innerHTML = splitted[1];
               document.getElementById('epopup2').innerHTML = splitted[4];

               eval(splitted[2]);
            }else{
               FillLoader('webshop_products');
            }
        }
        
        xmlHttp.open("GET","webshop_ajax.php?brand=" + marka, true);
        xmlHttp.send(null);
    }
    
}

function SetOrder(obj1, obj2)
{
    //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!=0) category_id = subcategory.options[subcategory.selectedIndex].value;
        else category_id = maincategory.options[maincategory.selectedIndex].value;
        */
    //}
    //else
    //{
//      category_id = -1;
    //}
    if(obj2==-1)
    {
        order = obj1.options[obj1.selectedIndex].value;
    }
    else if(obj1==-1)
    {
        if(obj2.src.substr((obj2.src.length-7), 7)=='asc.png')
        {
            obj2.src = './data/pics/sort_desc.png';
            sort_type = 'DESC';
        }
        else
        {
            obj2.src = './data/pics/sort_asc.png';
            sort_type = 'ASC';        
        }
    }
    
    var xmlHttp = createRequestObject();    
    
    if(xmlHttp)
    {
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState==4)
            {
            //alert(xmlHttp.responseText);
               splitted=xmlHttp.responseText.split('##########');
               document.getElementById('webshop_products').innerHTML = splitted[1];

               eval(splitted[2]);              
            }else{
                FillLoader('webshop_products');
            }
            //Onload_IntervalLinks();
            SelectCheckboxesInArray();
            SelectCheckboxesInArrayPrefered();
            //document.getElementById('overlay').style.display = 'none';
        }
        
        //alert("webshop_ajax.php?product_id=" + product_id + "&category_id=" + category_id + "&sort_type=" + sort_type);
        if(obj2==-1)
        {
            xmlHttp.open("GET","webshop_ajax.php?order_by=" + order, true);
        }
        else if(obj1==-1)
        {
            xmlHttp.open("GET","webshop_ajax.php?sort_type=" + sort_type, true);
        }
        
        xmlHttp.send(null);
    }    
}

var webshop_timer;
function PutCart2(product_code_id,rel_type,rel_id_type,rel_id)
{
   //alert(document.getElementById('order_' + product_code_id).value);
   if(rel_type == 0){
    o = document.getElementById('order_' + product_code_id);
   }else if(rel_type == 1){
    o = document.getElementById('order_' + product_code_id + '_' + rel_id_type + '_' + rel_id);
   }else if(rel_type == 2){
    o = document.getElementById('prpage_order_' + product_code_id);
   }
   if(o) product_sum = o.value;  
   else product_sum = 1;
   var xmlHttp = createRequestObject();
   if(xmlHttp)
   {
      xmlHttp.onreadystatechange=function()
      {
         if(xmlHttp.readyState==4)
         {
            if(xmlHttp.responseText != '')
            {
               //alert(xmlHttp.responseText);
               cart_summa = xmlHttp.responseText.split('##########', 2)[0];
               menu_cart = xmlHttp.responseText.split('##########', 2)[1];

               if(document.getElementById('cart_menu_div')) document.getElementById('cart_menu_div').innerHTML = menu_cart;
               
               if(document.getElementById('cart')) document.getElementById('cart').innerHTML = cart_summa;
               // if(o) o.value = 1; //nem biztos hogy jó, ha 1-re ugrik vissza, lehet hogy az upsale-nél a minimum kosárba tehető érték nagyobb mint 1.
                
                  if(!document.getElementById('dialog')){
                  var objMessageDiv = document.createElement('div');
                  objMessageDiv.setAttribute('id','dialog');
                  objMessageDiv.setAttribute('title','Kosár');
                  //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';
                  document.getElementsByTagName('BODY').item(0).appendChild(objMessageDiv);
                  }else{
                    objMessageDiv=document.getElementById('dialog');
                  }
                  objMessageDiv.innerHTML = '<p style="margin-top:20px">' + product_sum + ' db termék került a kosárba!</p>';
                    

                  var t;
                  $(function() {
                                 $("#dialog").dialog({
                                     bgiframe: true,
                                     modal: true,
                                     width:300,
                                     buttons: {
                                         Bezárás: function() {
                                             $(this).dialog('close');
                                             clearTimeout(t);  
                                         }
                                     },
                                     open: function(){
                                         t=setTimeout('$("#dialog").dialog(\'destroy\')',5000);
                                     },
                                     close: function(){
                                           $(this).dialog('destroy');
                                     }
                                 });
                             });
                  
                equalCols(0,'o1','div','o2','div');
               /*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 +
                           "&rel_type=" + rel_type +
                           "&rel_id_type=" + rel_id_type +
                           "&rel_id=" + rel_id
                           ,true);
      xmlHttp.send(null);
   } 
}
function PutCart(product_code_id){
    PutCart2(product_code_id,0,undefined,undefined);
}

function PutCartPrPage(product_code_id){
    PutCart2(product_code_id,2,undefined,undefined);
}

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)
{
   //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_' + cart_id).value = xmlHttp.responseText;
               document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * xmlHttp.responseText;
               
               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').innerHTML = xmlHttp.responseText.split('##########')[0];
               document.getElementById('cart_menu_div').innerHTML = xmlHttp.responseText.split('##########')[1];
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?cart_id=" +
                           cart_id +
                           "&action=add"
                           ,true);
      xmlHttp.send(null);
   } 
}

function AddToCartIC(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 != '')
            {
/*               document.getElementById('cart_' + cart_id).value = xmlHttp.responseText;
               document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * xmlHttp.responseText;
               
               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').innerHTML = xmlHttp.responseText.split('##########')[0];
               document.getElementById('cart_menu_div').innerHTML = xmlHttp.responseText.split('##########')[1];
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?where=chart&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 != '')
               {
/*                  document.getElementById('cart_' + cart_id).value = xmlHttp.responseText;
                  document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * xmlHttp.responseText;
                  
                  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').innerHTML = xmlHttp.responseText.split('##########')[0];
               document.getElementById('cart_menu_div').innerHTML = xmlHttp.responseText.split('##########')[1];
               }            
            }
         }
         xmlHttp.open("GET","webshop_ajax.php?cart_id=" +
                              cart_id + 
                              "&action=remove"
                              ,true);
         xmlHttp.send(null);
      }
   }
}

function RemoveFromCartIC(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 != '')
               {
/*                  document.getElementById('cart_' + cart_id).value = xmlHttp.responseText;
                  document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * xmlHttp.responseText;
                  
                  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').innerHTML = xmlHttp.responseText.split('##########')[0];
               document.getElementById('cart_menu_div').innerHTML = xmlHttp.responseText.split('##########')[1];
               }            
            }
         }
         xmlHttp.open("GET","webshop_ajax.php?where=chart&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 != '')
            {
               document.getElementById('cart').innerHTML = xmlHttp.responseText.split('##########')[0];
               document.getElementById('cart_menu_div').innerHTML = xmlHttp.responseText.split('##########')[1];
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?cart_id=" +
                           cart_id + 
                           "&action=delete"
                           ,true);
      xmlHttp.send(null);
   } 
}

function DeleteFromCartIC(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 != '')
            {
               document.getElementById('cart').innerHTML = xmlHttp.responseText.split('##########')[0];
               document.getElementById('cart_menu_div').innerHTML = xmlHttp.responseText.split('##########')[1];
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?where=chart&cart_id=" +
                           cart_id + 
                           "&action=delete"
                           ,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_' + cart_id).value = xmlHttp.responseText;
                  document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * xmlHttp.responseText;
                  
                  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; */
               document.getElementById('cart').innerHTML = xmlHttp.responseText.split('##########')[0];
               document.getElementById('cart_menu_div').innerHTML = xmlHttp.responseText.split('##########')[1];
               }            
            }
         }
         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 ChangeCartIC(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_' + cart_id).value = xmlHttp.responseText;
                  document.getElementById('sum_' + cart_id).value = document.getElementById('one_' + cart_id).value * xmlHttp.responseText;
                  
                  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; */
               document.getElementById('cart').innerHTML = xmlHttp.responseText.split('##########')[0];
               document.getElementById('cart_menu_div').innerHTML = xmlHttp.responseText.split('##########')[1];
               }            
            }
         }
         xmlHttp.open("GET","webshop_ajax.php?where=chart&cart_id=" +
                              cart_id + 
                              "&action=set&cart_number=" +
                              cart_sum
                              ,true);
         xmlHttp.send(null);
      }
   }
   else DeleteFromCartIC(cart_id);
}

function makeRequest(url, parameters) 
{
   if(document.getElementById('product_select').selectedIndex>-1)  //van termék kiválsztva
   { 
      product = true;
      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;
      }
      add_get = "product_id=" + product_id + "&category_id=" + category_id;
   }   
   else if(document.getElementById('sub_category_select').selectedIndex>-1)
   {
      product = false;
      category_id = document.getElementById('sub_category_select').options[document.getElementById('sub_category_select').selectedIndex].value;
      add_get = "category_id=" + category_id + "&type=sub";
   }
   else
   {
      product = false;
      category_id = document.getElementById('main_category_select').options[document.getElementById('main_category_select').selectedIndex].value;
      add_get = "category_id=" + category_id + "&type=main";
   }
   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);
               if(product)
               {
                  //alert("product");
                  document.getElementById('webshop_products').innerHTML = xmlHttp.responseText.split('##########', 3)[0];
                  document.getElementById('product_parameters_div').innerHTML = xmlHttp.responseText.split('##########', 3)[2];
                  eval(xmlHttp.responseText.split('##########', 3)[1]); 
               }
               else
               {
                  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];
                  document.getElementById('product_select_div').innerHTML = xmlHttp.responseText.split('##########', 5)[3];
                  if(xmlHttp.responseText.split('##########', 4)[3]!=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);
}

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) + "&";
            }
         }
      }
      //alert(getstr);
      makeRequest('webshop_ajax.php', getstr);
   }
}

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').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'));
      var page_checkboxes = document.getElementById('webshop_products').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
{
      var page_checkboxes = document.getElementById('webshop_products').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 + ','; 
      }   
   }
   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 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 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';
   }   
}   

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 != '')
            {
               cart_summa = xmlHttp.responseText.split('##########', 2)[0];
               menu_cart = xmlHttp.responseText.split('##########', 2)[1];
               
               document.getElementById('cart').innerHTML = cart_summa;   
               if(document.getElementById('cart_menu_div')) document.getElementById('cart_menu_div').innerHTML = menu_cart; 
            }            
         }
      }
      xmlHttp.open("GET","webshop_ajax.php?emptycart=yes"
                           ,true);
      xmlHttp.send(null);
   } 
}

function GetCities(input_id)
{
   var postcode = document.getElementById(input_id).value
   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(currency_code)
{
    if(document.getElementById('delivery_method').options[document.getElementById('delivery_method').selectedIndex].value == '0')
    {
        document.getElementById('install_div').style.display = 'block';
        document.getElementById('payment_method').options[1].text = 'Készpénz';
    }
    else
    {
        document.getElementById('install_div').style.display = 'none';
        document.getElementById('payment_method').options[1].text = 'Utánvét';
    }
    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;
    if(payment_id==-1 || delivery_id==-1) 
    {
        document.getElementById('receive_price_div').innerHTML = '0 ' + currency_code;
    }
    else
    {
        document.getElementById('receive_price_div').innerHTML = price_table[payment_id][delivery_id] + " " + currency_code;
    }
   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 mynumberformat(rep){
    var dp = ",";
    var ts = " ";
    var str = Math.round(rep) + "";
    var i = (str.length + 3) % 3;
    var out = "";
    for(j = 0; j != str.length; ++j){
        out += str.charAt(j);
        if(j + 1 == str.length){
        }else if(((3 + j - i) % 3) == 2) out += ts;
    }
    return out;
}

var array_product = [];
var array_product_code = [];

function regenPicList(){
	 var xmlHttp = createRequestObject();
     xmlHttp.open("GET","gen_product_pictures.php?action=list",false);
     xmlHttp.send(null);
     //kitölti az array_product és array_product_code tömböket
     eval(xmlHttp.responseText);
}

function regenPictures(){
	regenPicList();
	var gen_echo = document.getElementById('gen_echo');
	gen_echo.innerHTML= "product képek: " + array_product.length + "<br/>product_code képek: " + array_product_code.length;
	var xmlHttp;
	for(i in array_product){
		 xmlHttp = createRequestObject();
	     xmlHttp.open("GET","gen_product_pictures.php?action=gen_product&id="+array_product[i],false);
	     xmlHttp.send(null);
	     gen_echo.innerHTML= "product képek: " + (array_product.length - i-1) + "<br/>product_code képek: " + array_product_code.length;
	}
	
	for(i in array_product_code){
		 xmlHttp = createRequestObject();
	     xmlHttp.open("GET","gen_product_pictures.php?action=gen_product_code&id="+array_product_code[i],false);
	     xmlHttp.send(null);
	     gen_echo.innerHTML= "product képek: 0<br/>product_code képek: " + (array_product_code.length-i-1);
	}
	
	gen_echo.innerHTML="Kész!";
}
