function sendrating(){
        var xmlHttp = createRequestObject();
           if(xmlHttp)
           {
              xmlHttp.onreadystatechange=function()
              {
                 if(xmlHttp.readyState==4)
                 {
                         get_ratinglist();
                         document.getElementById('dialog_text').innerHTML=xmlHttp.responseText;
                         equalCols(0,'left_bottom','div','main_bottom','div','right_bottom','div');
                 }
              }
              xmlHttp.open("GET","ajax_rating.php?action=sendrating&product_code_id=" +
                                   document.getElementById('product_code_id').value +
                                   "&rate="+
                                   document.getElementById('rate').value+
                                   "&comment="+
                                   document.getElementById('comment').value
                                   ,true);
              xmlHttp.send(null);
           }
}

function get_ratinglist(){
        var xmlHttp = createRequestObject();
           if(xmlHttp)
           {
              xmlHttp.onreadystatechange=function()
              {
                 if(xmlHttp.readyState==4)
                 {
                         document.getElementById('rating_list_div').innerHTML=xmlHttp.responseText;
                         
                         equalCols(0,'left_bottom','div','main_bottom','div','right_bottom','div');
                 }
              }
              xmlHttp.open("GET","ajax_rating.php?action=get_ratinglist&product_code_id=" +
                                   document.getElementById('product_code_id').value
                                   ,true);
              xmlHttp.send(null);
           }
}

function arrayCheck(action){
        for(i=0;i<rating_id_array.length;i++){
                if(rating_id_array[i]!=undefined){
                        if(action=='checkall'){
                                rating_id_array[i]=1;
                        }else if(action=='uncheckall'){
                                rating_id_array[i]=0;
                        }else if(action=='toggle'){
                                if(rating_id_array[i]==1){
                                        rating_id_array[i]=0;
                                }else{
                                        rating_id_array[i]=1;
                                }
                        }
                }
        }
}

function refreshCheckboxes(name){
        $("INPUT[name^='" + name + "'][type='checkbox']").each(function(i){
                if(rating_id_array[this.value]!=undefined && rating_id_array[this.value]==1){
                        $(this).attr('checked',true);
                }
        });
}

function jqCheck(name,action)
{
   if (action == 'checkall'){
          var cb=$("INPUT[name^='" + name + "'][type='checkbox']");
          cb.attr('checked', true);
          arrayCheck('checkall');
   }
   else if(action == 'uncheckall'){
      var cb=$("INPUT[name^='" + name + "'][type='checkbox']");
      cb.attr('checked', false);
      arrayCheck('uncheckall');
   }else if(action == 'toggle'){
          var checked=$("INPUT[name^='" + name + "'][type='checkbox']:checked");
          var no_checked=$("INPUT[name^='" + name + "'][type='checkbox']:not(:checked)");
          checked.attr('checked', false);
          no_checked.attr('checked', true);
          arrayCheck('toggle');
          $("INPUT[name=select_all]").attr('checked',false);
   }
}

function jqCheckOne(o){
        $("INPUT[name=select_all]").attr('checked',false);
         if($(o).attr('checked')==true){
                 rating_id_array[o.value] = 1;
         }else{
                 rating_id_array[o.value] = 0;
         }
}

function set_status(status){
        $("FORM#hidden_form INPUT[name=action]").val('set_status');
        $("FORM#hidden_form INPUT[name=status]").val(status);
        
        var send_id_array=new Array();
        
        k=0;
        for(i=0;i<rating_id_array.length;i++){
                if(rating_id_array[i]!=undefined && rating_id_array[i]==1){
                        send_id_array[k]=i;
                        k++;
                }
        }
        
        if(send_id_array.length!=0){
        
                $("FORM#hidden_form INPUT[name=idstring]").val(send_id_array.join(';'));
                
                $('FORM#hidden_form').submit();
        }else{
                alert('Nincs kijelölt sor!');
        }
}

function set_status_one(id,status){
        $("FORM#hidden_form INPUT[name=action]").val('set_status');
        $("FORM#hidden_form INPUT[name=status]").val(status);
        $("FORM#hidden_form INPUT[name=idstring]").val(id);
        $('FORM#hidden_form').submit();
}
