var seList = [];

function loadList()
{
	var urlList = [];   		

	urlList[0] = ["1002", "", "на ММВБ", "http://www.micex.ru/search/?ul=http%3A%2F%2Fwww.micex.ru&q=", "", "", ""]
	urlList[1] = ["1001", "", "в Яндексе", "http://yandex.ru/yandsearch?stype=&nl=0&text=", "", "", ""]
	urlList[2] = ["1006", "", "в Рамблере", "http://search.rambler.ru/srch?words=", "&where=1", "", ""]
	urlList[3] = ["1007", "", "в Апорте", "http://sm.aport.ru/scripts/template.dll?That=std&r=", "", "", ""]
	urlList[4] = ["1005", "unicode", "в Google", "http://www.google.com/search?hl=ru&q=", "&lr=", "", ""]
	urlList[5] = ["1009", "", "в ФСФР", "http://www.fcsm.ru/search.asp?context=", "&contextcond=phrase", "", ""]
	urlList[6] = ["1010", "", "в ЦБ РФ", "http://www.cbr.ru/search/main.asp?Direct=Submit&SearchString=", "&SortBy=rank&FMRecNum=10", "", ""]
	urlList[7] = ["1011", "", "в Минфин РФ", "http://search.minfin.ru/search.asp?wci=rcresult&is=minfin&pool_size=10&context=", "&contextcond=phrase&title=1&body=1&orderby=%24sysdate&doc_per_page=10&output=full", "", ""]
	urlList[8] = ["1003", "", "в НДЦ", "http://www.ndc.ru/ru/search/?ul22=http%3A%2F%2Fwww.ndc2.ru%2F&q22=", "", "", ""]
	urlList[9] = ["1013", "", "в РТС", "http://rts.ru/index.cfm?id=5400&MatText=", "", "", ""]
	urlList[10] = ["1008", "", "Перевод", "http://www.multitran.ru/c/m.exe?HL=2&L1=1&L2=2&EXT=0&s=", "", "", ""]
	urlList[11] = ["1004", "", "в И-Стоке", "http://www.e-stock.ru/support/search/?search_string=", "", "", ""]
    urlList[12] = ["1013", "", "в ДКК", "", "", "post", "DCC"]	
	urlList[13] = ["1012", "unicode", "в МЭРТ РФ", "http://www.economy.gov.ru/wps/portal/!ut/p/_s.7_0_A/7_0_9D/.cmd/ad/.ar/sa.search/.c/6_0_69/.ce/7_0_2ES/.p/5_0_1BV/.d/2/_th/J_0_IP/_mx.6_0_69/7_0_2ES/_s.7_0_A/7_0_9D/_ps.7_0_2ES/X?mode=search&query_string=", "&sources_count=1&sort_order=date&limit=10", "", ""]
	
	


	for ( var i in urlList)
	{
        seList[i] = new searchEngine(urlList[i]);
	}

    document.seForm.seListOpt.options.length = 1;

    document.seForm.seListOpt.options[0].text = "Выберите сайт";
  	document.seForm.seListOpt.options[0].value = 0;
  	
  	//document.seForm.seListOpt.options.length = 1;
  		
    for (i=0; i < seList.length; i++)
	{ 		
        document.seForm.seListOpt.length++;
  		document.seForm.seListOpt.options[i+1].text = seList[i].name;
  		document.seForm.seListOpt.options[i+1].value = seList[i].id;
  		
  		
	}

	document.seForm.seListOpt.selectedIndex = 1;

	return true;
}


function searchEngine(list)
{
	this.id = list[0];		
	this.is_unicode = list[1];
	this.name = list[2];
	this.strBefore = list[3];
	this.strAfter = list[4];		
	this.is_post = list[5];
   	this.form_id = list[6];

}

searchEngine.prototype.buildSearchURL = function(q)
{
    return this.strBefore+q+this.strAfter;
}


function doSearch()
{
	if (!document.seForm.seListOpt.selectedIndex) return false;

    if (document.seForm.q.value.length>0)
    {

        var se = seList[document.seForm.seListOpt.selectedIndex-1];

		//encodeURIComponent
        var seWord = document.seForm.q.value;
  		
  		//seWord = encodeURIComponent(document.seForm.q.value);

  		if (se.is_unicode)
  		{
  			seWord = encodeURI(seWord);
  		}



        if (se.is_post)
        {
			frm = document.getElementById(se.form_id);
			frm.search.value = seWord;
			frm.submit();

        }
        else
        {

            seWord = replaceSymbols(seWord);

			document.location.href = se.buildSearchURL(seWord);

		}



		return false;
    }
    else
    {
    	return false;
    }

}

function doChangeSeq()
{
	var s = "Введите название...";
	s = "";
	
	if (document.seqForm.seqListOpt.selectedIndex)
	{
		s = document.seqForm.seqListOpt.options[document.seqForm.seqListOpt.selectedIndex].value;
		re = new RegExp(".{2,3}_(.+)", "i");
		r = s.match(re);                  
   		s = r[1];   
   		//alert(r);
		//s = document.seqForm.seqListOpt.options[document.seqForm.seqListOpt.selectedIndex].value.split('_')[1];
		//document.seqForm.seq.disabled = false;	
		
	}
	else
	{
		//document.seqForm.seq.disabled = true;	
		
	}
	
	
	document.seqForm.seq.value = s;
}

function replaceSymbols(seWord)
{

	seWord = seWord.replace("&", "%26");
    seWord = seWord.replace("?", "%3F");
	    	
	return seWord;
}
