



mas_element_vote={};
processing_num_element_vote=0;
operLoad=false;


function add_vote_element(num_element,rating,is_voting)
  {
   mas_element_vote[num_element]={"rating":rating,"is_voting":is_voting};
   
   set_rating_img_vote(num_element,rating);
   
  }


function set_rating_img_vote(num_element,rating)
  {
   var n=1;
   
   for ( n=1; n <= 5;n++ )
     {
      set_status_one_img_vote(num_element,n,0);
      
     }
   
   for ( n=1; n <= rating;n++ )
     {
      set_status_one_img_vote(num_element,n,1);
      
     }
   
  }


function set_status_one_img_vote(num_element,num_image,num_status)
  {
   var obj = document.getElementById("img_vote_num_"+num_image+"_"+num_element);
   if ( obj )
     {
      var src_image="";
      if ( num_status )
        src_image="i_vote_star_2.gif";
       else
         src_image="i_vote_star.gif";
      
      obj.src=dir_http+"images/"+src_image;
      
     }
   
   
  }


function set_info_one_element_vote(num_element,num_type,text)
  {
   var obj1=document.getElementById("block_info_one_element_vote_1_"+num_element);
   var obj2=document.getElementById("block_info_one_element_vote_2_"+num_element);
   var obj3=document.getElementById("block_info_one_element_vote_3_"+num_element);
   
   switch ( num_type )
     {
      case (1):
        obj1.style.display="inline";
        obj2.style.display="none";
        obj3.style.display="none";
        break;
      case (2):
        obj1.style.display="none";
        obj2.style.display="inline";
        obj3.style.display="none";
        break;
      case (3):
        obj1.style.display="none";
        obj2.style.display="none";
        obj3.style.display="inline";
        obj3.innerHTML=text;
        break;
      
      
     }
   
  }


function over_one_img_vote(num_element,num_image)
  {
   if ( !mas_element_vote[num_element] ) return;
   
   switch ( mas_element_vote[num_element]["is_voting"] )
     {
      case ("registr"): 
        
        break;
      case ("on_vote"): 
        
        break;
      case ("access_vote"): 
        set_rating_img_vote(num_element,num_image);
        set_info_one_element_vote(num_element,3,"оценка "+num_image);
        break;
      
     }
   
  }


function out_one_img_vote(num_element,num_image)
  {
   
   if ( !mas_element_vote[num_element] ) return;
   
   switch ( mas_element_vote[num_element]["is_voting"] )
     {
      case ("registr"): 
        
        break;
      case ("on_vote"): 
        
        break;
      case ("access_vote"): 
        set_rating_img_vote(num_element,mas_element_vote[num_element]["rating"]);
        set_info_one_element_vote(num_element,1,"");
        break;
      
     }
   
   
  }


function click_one_img_vote(num_element,num_image)
  {
   if ( !mas_element_vote[num_element] ) return;
   
   if ( mas_element_vote[num_element]["is_voting"] == "access_vote" )
     {
      
      if ( operLoad )
        {
         alert("Пожалуйста подождите, идет соединение с сервером!");
         return;
        }
      //alert(num_image);
      
      var url=dir_http+"cms/mod/vote/vote_ajax.php";
      var query="";
      
      query="nelem="+num_element+"&nrating="+num_image;
      processing_num_element_vote = num_element;
      loadHTTPjc(url,obr_set_rating_vote_server,query);
      operLoad=true;
     }
   
   
  }

function obr_set_rating_vote_server(rez_query)
  {
   operLoad=false;
   if ( rez_query.status_operation && rez_query.status_operation == 1 )
     {
      
      //window.opener.location.reload();
      //close_enter_ajax();
      //window.location.href=window.location.href;
      
      //mas_element_vote[processing_num_element_vote]["rating"]=rez_query.num_image;
      //mas_element_vote[processing_num_element_vote]["is_voting"]="on_vote";
      
      add_vote_element(processing_num_element_vote,rez_query.num_image,"on_vote")
      
      var obj1=document.getElementById("block_info_one_element_vote_1_"+processing_num_element_vote);
      var t="";
      t+=rez_query.rating+" / 5("+rez_query.vsego_user+" голосов)";
      obj1.innerHTML=t;
      
      set_info_one_element_vote(processing_num_element_vote,1,"");
      
      alert("Ваш голос принят!");
      
     }
   
  }




function over_one_block_vote(num_element)
  {
   if ( !mas_element_vote[num_element] ) return;
   
   if ( mas_element_vote[num_element]["is_voting"] == "registr" )
     {
      
      set_info_one_element_vote(num_element,2,"");
      
     }
   
   
  }


function out_one_block_vote(num_element)
  {
   if ( !mas_element_vote[num_element] ) return;
   
   if ( mas_element_vote[num_element]["is_voting"] == "registr" )
     {
      
      set_info_one_element_vote(num_element,1,"");
      
     }
   
   
  }










