	function switch_line(show_mode,detail_id,line_id,nav_arrow_prev,nav_arrow_next,cur_pos_el,in_line,classname)
	{
		//-------------Инициализация--------------------------------------------
		this.elements=new Array();
		this.selected=0;
		this.mode=0;
		this.name=classname;
		if(in_line>0)
		{
			this.max=in_line;
		}
		else
		{
			this.max=6;
		}
		this.max=5;
		if(typeof(nav_arrow_next)!=='undefined')
		{
			this.arrow_next=document.getElementById(nav_arrow_next);
		}
		if(typeof(cur_pos_el)!=='undefined')
		{
			this.current_pos_el=document.getElementById(cur_pos_el);
		}
		if(typeof(nav_arrow_prev)!=='undefined')
		{
			this.arrow_prev=document.getElementById(nav_arrow_prev);
		}
		if(typeof(detail_id)!=='undefined')
		{
			this.detail=document.getElementById(detail_id);
		}
		if(typeof(line_id)!=='undefined')
		{
			this.line=document.getElementById(line_id);
		}
		if(show_mode!="S" && show_mode!="E")
		{
			this.mode="S";
		}
		else
		{
			this.mode=show_mode;
			if (this.mode=="E")
			{
				this.start_set=false;
			}
		}
        //-------------Инициализация-Конец--------------------------------------



		this.set_selected = function(number)
		{
              this.selected=number;
              if(!this.start_set && this.mode=="E")
              {
              	 this.start_set=true;
              	 this.selected=this.start=number;
              	 this.chosen=true;
              }
		}

		this.choose = function(number)
		{
              this.selected=number;
              this.chosen=true;
			  this.draw();
		}

		//Добавить элемент
		this.add_to_line = function(full,preview)
		{
              if(this.mode=='S')
              {
                  this.elements[this.elements.length]=full;
              }
              else
              {
              	  this.elements[this.elements.length]=new Array(preview,full);
              }
		}

		//Вывод фотографии и прокрутки
		this.draw=function()
		{
			if(this.mode=="S")
			{
                this.set_nav_arrows();
                if(typeof(this.elements[this.selected])!=="undefined")
                {
					this.detail.innerHTML=this.elements[this.selected];
				}
				if(typeof(this.current_pos_el)!=="undefined")
				{
					this.show_position_info();
				}
			}
			if(this.mode=="E")
			{
				this.line.innerHTML="";
				this.set_nav_arrows();
				if(this.chosen)
				{
					this.detail.innerHTML=this.elements[this.selected][1];
					this.chosen=false;
				}
				var limit = this.elements.length>(this.start+this.max) ? this.start+this.max : this.elements.length;
				make_lap=false;
				if(limit==this.elements.length)
				{
					make_lap=true;
				}
				for(i=this.start;i<limit;i++)
				{
					if(i!=this.selected)
					{
						this.line.innerHTML+="<span onclick='"+this.name+"."+"choose("+i+")'>" + this.elements[i][0] + "</span>";
					}
					else
					{
						this.line.innerHTML+="<span class='active_item'>"+this.elements[i][0]+"</span>";
					}
				}
				if(make_lap)
				{
					additional_start=i-this.start;
					additional_limit=this.max-additional_start;
					for(j=0;j<additional_limit;j++)
					{
						if(j!=this.selected)
						{
							this.line.innerHTML+="<span onclick='"+this.name+"."+"choose("+j+")'>" + this.elements[j][0] + "</span>";
						}
						else
						{
							this.line.innerHTML+="<span class='active_item'>"+this.elements[j][0]+"</span>";
						}
					}
				}
			}
		}


		this.show_position_info=function()
		{
			 this.current_pos_el.innerHTML=(this.selected+1) + " из " + this.elements.length;
		}

		//Установка стрелок вправо/влево
		this.set_nav_arrows=function()
		{
			/*if(this.mode=="E")
			{
				if(this.start===0)
				{
						this.arrow_prev.style.display="none";
				}
				else
				{
					    this.arrow_prev.style.display="inline";
				}
				if((this.start+this.max)>=(this.elements.length) || this.elements.length===0)
				{
						this.arrow_next.style.display="none";
				}
				else
				{
						this.arrow_next.style.display="inline";
				}
			}
			if(this.mode=="S")
			{
				if(this.selected===0)
				{
						this.arrow_prev.style.display="none";
				}
				else
				{
						this.arrow_prev.style.display="inline";
				}
				if(this.selected===(this.elements.length-1) || this.elements.length===0)
				{
						this.arrow_next.style.display="none";
				}
				else
				{
						this.arrow_next.style.display="inline";
				}
			}*/
		}


  		//Показать следующий / предыдущий
		this.show_prev=function()
		{
			if(this.mode=="S")
			{
				if(this.selected>0)
				{
					this.selected--;
				}
				else
				{
					this.selected=this.elements.length-1;
				}
			}
			if(this.mode=="E")
			{
				if(this.start>0)
				{
					this.start--;
				}
				else
				{
					this.start=this.elements.length-1;
				}
			}
			this.draw();
		}

		this.show_next=function()
		{
			if(this.mode=="S")
			{
				if(this.selected<(this.elements.length-1)>0)
				{
					this.selected++;
				}
				else
				{
					this.selected=0;
				}
			}
			if(this.mode=="E")
			{
				if(this.start<(this.elements.length-1))
				{
					this.start++;
				}
				else
				{
					this.start=0;
				}
			}
			this.draw();
		}


		this.debug=function()
		{
			alert(this.elements);
		}
	}



var xmlhttp_vote;
var ALL_COMP;
var COMP_LINE;
var CURRENT_INPUT;

function SetInput(id,val,parent)
{
	 input = document.getElementById("COMPANY_"+id);
	 input.value = val;
	 parent.innerHTML="";
}

function hide_table(el)
{
	el.innerHTML = "";
}



function XMLHTTP_VOTING(ALL_COMPANIES_ID,RATING_ID)
{
	//----------XMLHTTPREQUEST---------------------------
	try
	{
	  	  this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		  try
		  {
		    this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  catch (e2)
		  {
		    this.xmlHttp = false;
		  }
	}
	if (!this.xmlHttp && typeof XMLHttpRequest != 'undefined')
	{
	  	  this.xmlHttp = new XMLHttpRequest();
	}
	//----------/XMLHTTPREQUEST--------------------------

    this.params="";
    if(typeof(ALL_COMPANIES_ID)!=='undefined')
	{
		ALL_COMP=document.getElementById(ALL_COMPANIES_ID);
	}
	this.RATING_ID=RATING_ID;


	this.show_companies = function(url,filter,cur)
	{
		   if(typeof(filter)!=='undefined' && filter.length>0)
		   {
		   		url+="?LETTERS="+(filter)+"&RATING_ID="+this.RATING_ID;
		   		COMP_LINE=document.getElementById("BLOCK_"+cur);
                COMP_LINE_INPUT=COMP_LINE.parentNode.getElementsByTagName('input')[0];
		   		this.callServer(url,"NOT_ALL");
		   }
		   else
		   {
		   		url+="?RATING_ID="+this.RATING_ID;
           		this.callServer(url,"ALL");
           }
           CURRENT_INPUT=cur;
	}



	this.draw_all=function()
	{
/* <table class='title_plate margin10'><tr><td class='iePNG left'></td><td class='main' align='left'>Выберите компанию из списка</td><td id='close_drop_list'></td><td class='iePNG right'></td></tr></table> */
          if (xmlhttp_vote.readyState == 4)
		  {
			    text=xmlhttp_vote.responseText;
                company_array = text.split("|");
                result_str="<!--[if ie 6]><iframe></iframe><![endif]--><table><td class='ugl_top_left'></td><td class='horiz_line'></td><td class='ugl_top_right'></td></tr><tr><td class='vert_line'></td><td class='drop_block_cell'><div id='rating_drop_list'><table class='title_plate margin10'><tr><td class='iePNG left'></td><td class='main' align='left'>Выберите компанию из списка</td><td onclick='hide_table(ALL_COMP)' id='close_drop_list'></td><td class='iePNG right'></td></tr></table><ul>";
                for(i=0;i<company_array.length;i++)
                {
                	if(company_array[i].length>0)
                	{
                		result_str+="<li><a href='javascript:void(0)' onclick='SetInput(CURRENT_INPUT,"+'"'+company_array[i]+'"'+",ALL_COMP)'>"+company_array[i]+"</a></li>";
                	}
                }
           result_str+="</ul></div></td><td class='vert_line' style='background-position: right;'></td></tr><tr height='6px'><td class='ugl_bottom_left'></td><td class='horiz_line' style='background-position: bottom;'></td><td class='ugl_bottom_right'></td></tr></table>";

          ALL_COMP.innerHTML = result_str;
          }
	}

	this.draw_line=function()
	{
 		  if (xmlhttp_vote.readyState == 4)
		  {
				text=xmlhttp_vote.responseText;
				company_array = text.split("|");
                if (company_array.length - 1) {
                  result_string = "<div><ul>";
                  for(i=0;i<company_array.length;i++)
                    {
                    	if(company_array[i].length>0)
                    	{
                    		result_string += "<li><a href='javascript:void(0)' onclick='SetInput(CURRENT_INPUT,"+'"'+company_array[i]+'"'+",COMP_LINE)'>"+company_array[i]+"</a></li>";
                    	}
                    }
                  result_string += "</ul></div>";
                  //COMP_LINE.style.display = 'block';
                  COMP_LINE.innerHTML = result_string;
                } else {
                COMP_LINE.innerHTML = "";
                }

                //COMP_LINE_INPUT.onblur = function() {COMP_LINE.style.display = 'none';}
   		  }
	}
    /*
    COMP_LINE.style.display = 'block';
                  COMP_LINE.innerHTML = result_string;
                } else {
                COMP_LINE.innerHTML = "";
                }
                COMP_LINE_INPUT.onblur = function() {COMP_LINE.style.display = 'none';}


                COMP_LINE_INPUT.onblur = function() {setTimeOut('COMP_LINE.innerHTML = ""', 1000);}
    */
	this.callServer=function(url,type) {
		   this.xmlHttp.open("GET", url, true);
		   if(type=="ALL") {
		   		this.xmlHttp.onreadystatechange = this.draw_all;
		   } else {
		   		this.xmlHttp.onreadystatechange = this.draw_line;
		   }
		   xmlhttp_vote=this.xmlHttp;
     	   this.xmlHttp.send(null);
		   //xmlHttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	}
}

