function set_active_top(lang)
{
	if (lang=='rus')
	{
		document.getElementById("top_ref_ukr").style.display = 'none';
		document.getElementById("top_ref_rus").style.display = 'block';
		//document.getElementById("url_top_ref_rus").style.fontWeight = 'bold';
		//document.getElementById("url_top_ref_ukr").style.fontWeight = 'normal';
		document.getElementById("url_top_ref_rus").className='active';
		document.getElementById("url_top_ref_ukr").className='';
	}
	else
	{
		document.getElementById("url_top_ref_rus").innerHTML='Русские рефераты';
		document.getElementById("top_ref_ukr").style.display = 'block';
		document.getElementById("top_ref_rus").style.display = 'none';
		//document.getElementById("url_top_ref_rus").style.fontWeight = 'normal';
		//document.getElementById("url_top_ref_ukr").style.fontWeight = 'bold';
		document.getElementById("url_top_ref_ukr").className='active';
		document.getElementById("url_top_ref_rus").className='';
	}
}

function set_ref_lang(lang_name)
{
	if (lang_name=='ua')
	{
		document.getElementById("ref_ukr").className='';
		document.getElementById("ref_rus").className='h';
	}
	else
	{
		document.getElementById("ref_ukr").className='h';
		document.getElementById("ref_rus").className='';
	}
}

function startTicker()
{
	// Define run time values
	theCurrentStory     = -1;
	theCurrentLength    = 0;
	// Locate base objects
	if (document.getElementById) {	
		    theAnchorObject     = document.getElementById("tickerAnchor");
			runTheTicker();   	
		 }
	else {
            document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
            return true;
	}
}
function runTheTicker()
{
	var myTimeout;  
	// Go for the next story data block
	if(theCurrentLength == 0)
	{
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');		
		theTargetLink        = theSiteLinks[theCurrentStory];
		theAnchorObject.href = theTargetLink;
		thePrefix 	     = "<span class=\"tickls\">" + theLeadString + "</span>";
	}
	// Stuff the current ticker text into the anchor
	theAnchorObject.innerHTML = thePrefix + 
	theStorySummary.substring(0,theCurrentLength) + whatWidget();
	// Modify the length for the substring and define the timer
	if(theCurrentLength != theStorySummary.length)
	{
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else
	{
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}
function whatWidget()
{
	if(theCurrentLength == theStorySummary.length)
	{
		return theWidgetNone;
	}
 
	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}
var theCharacterTimeout = 50;
var theStoryTimeout = 5000;
var theWidgetOne = "_";
var theWidgetTwo = "-";
var theWidgetNone = "";
var theLeadString = "&nbsp;";
var theSummaries = new Array();
var theSiteLinks = new Array();
var theItemCount = 6;
theSummaries[0] = "Книги по любым темам";
theSiteLinks[0] = "http://refbase.com.ua/books/";
theSummaries[1] = "Русские и украинские сочинения";
theSiteLinks[1] = "http://refbase.com.ua/essay/";
theSummaries[2] = "Биографии писателей и поэтов";
theSiteLinks[2] = "http://refbase.com.ua/biography/";
theSummaries[3] = "Средние и высшие учебные заведения";
theSiteLinks[3] = "http://refbase.com.ua/vuz/";
theSummaries[4] = "База преподавателей";
theSiteLinks[4] = "http://refbase.com.ua/biography/";
theSummaries[5] = "Русские и укринские рефераты";
theSiteLinks[5] = "http://refbase.com.ua/referats/";


function goto_url(url)
{
	document.location.href=url; 
}

//// VOTE ////
function addCookie(Name,Value)
{
var dtExpires=new Date();
var dtExpiryDate="";
dtExpires.setTime(dtExpires.getTime()+100*24*60*60*1000);
dtExpiryDate = dtExpires.toGMTString();
document.cookie=Name+"="+Value+"; expires="+dtExpiryDate+"; path=/;";
//alert("Добавлено: "+Name+" = "+Value);
}
function submitvote()
{
var rnd = Math.round(Math.random() * 1000000000);
var v = null;
var vote_id=document.vote_form.vote_id.value;

	for (i=0; i<document.vote_form.vote_option.length; i++)
	{
		if (document.vote_form.vote_option[i].checked) 
		{
			v = i;
			option_id=document.vote_form.vote_option[i].value;
		}
	}
if ((v == null)) 
	{
		alert('Не выбран ответ!');
	}		
		//document.getElementById(to_obj).disable=true;
		document.getElementById("vote").innerHTML='<img border="0" src="/img/working.gif">';
        JsHttpRequest.query(
            '/jshttprequest/vote.php?rnd='+rnd, // backend
            {
               // pass a text value 
                'option_id': option_id,  
                // path a file to be uploaded
                //'upl': document.getElementById("myupl")
				'vote_id': vote_id
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors; 
				
                // Write the answer.
                if (result) 
				{
					addCookie('vote_'+vote_id,'yes');
					document.getElementById("vote").innerHTML = result; 	
					
                }
				else
				{
					//document.getElementById(from_obj).innerHTML = ''; 				
				}
            },
            false  // do not disable caching
        );
    }

//// VOTE ////


// COMMENTS
function add_comment(id,lang)
{
var rnd = Math.round(Math.random() * 1000000000);
var name=document.getElementById("name").value;
var message=document.getElementById("message").value;
var securityCode=document.getElementById("securityCode").value;
var comment_title=document.getElementById("comment_title").value;
var parent_id=document.getElementById("parent_id").value;
//document.getElementById("comments").innerHTML='<img border="0" src="/img/working.gif">';
		//document.getElementById(to_obj).disable=true;
        JsHttpRequest.query(
            '/jshttprequest/comments.php?rnd='+rnd, // backend
            {
               // pass a text value 
                'id': id,
				'name' : name,
				'message' : message,
				'lang' : lang,
				'securityCode' : securityCode,
				'parent_id' : parent_id,
				'comment_title' : comment_title,
				'url' : document.location.href,
				'action' : 'add'
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
                
				
                // Write the answer.
                if (result=='true') 
				{
					show_comments(id,lang);
					cancel_comment();
                }
				else
				{
					alert(result);
				}
            },
            false  // do not disable caching
        );
}
function show_comments(id,lang)
{
var rnd = Math.round(Math.random() * 1000000000);
document.getElementById("comments").innerHTML='<img border="0" src="/images/working.gif">';
		//document.getElementById(to_obj).disable=true;
        JsHttpRequest.query(
            '/jshttprequest/comments.php?rnd='+rnd, // backend
            {
               // pass a text value 
                'id': id,
				'lang' : lang,
				'action' : 'show'
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
                // Write the answer.
                if (result) 
				{
					document.getElementById("comments").innerHTML = result; 
                }
            },
            false  // do not disable caching
        );
}
if (document.getElementById("c0"))
{
	var active_answer=0;
	var comment_form=document.getElementById("c0").innerHTML;
	document.getElementById("c0").innerHTML='';
	document.getElementById("c0").style.display = 'block'
}
function cancel_comment()
{
	document.getElementById('c'+active_answer).innerHTML='';
}
function show_comment_form(id)
{
	if (document.getElementById('c'+id).innerHTML=='') 
	{
		document.getElementById('c'+id).innerHTML=comment_form;
		if (id!=active_answer) document.getElementById('c'+active_answer).innerHTML='';
	}
	else
	{
		document.getElementById('c'+id).innerHTML='';
	}
	document.getElementById("parent_id").value=id;
	active_answer=id;
}
function security_img()
{
document.getElementById('security_img').src=document.getElementById('security_img').src+'&'+ Math.random();
}
// COMMENTS

function load_select(value,from_obj,to_obj) {
		document.getElementById(to_obj).options[0].selected=true;
		document.getElementById(to_obj).disabled=true;
		document.getElementById(to_obj).options[0].value = '';
		document.getElementById(to_obj).options[0].text = '- загрузка -';
        JsHttpRequest.query(
            '/jshttprequest/load.php', // backend
            {
               // pass a text value 
                'q': value,  
                // path a file to be uploaded
                //'upl': document.getElementById("myupl")
				'from_obj': from_obj
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
				document.getElementById(to_obj).disabled=false;
                //document.getElementById("debug").innerHTML = errors; 
				
				// ОЧИСТКА ОБЪЕКТА
				var i=document.getElementById(to_obj).length;
				while (i>0) //(i=opt_count; i>0; i--) 
				{
					i=i-1;
					document.getElementById(to_obj).options[i] = null;
				}
				// ОЧИСТКА ОБЪЕКТА
				
                // Write the answer.
                if (result) 
				{
					var arr_count=result.length;
					for (i=0; i<arr_count; i++) 
					{
						document.getElementById(to_obj).options[i] = new Option();
						str=result[i].split('#');
						document.getElementById(to_obj).options[i].value = str[0];
						document.getElementById(to_obj).options[i].text = str[1];
					}						
                }
				 else // если даннх для загрузки нет
				{
					document.getElementById(to_obj).options[0] = new Option();
					document.getElementById(to_obj).options[0].value = '0';
					document.getElementById(to_obj).options[0].text = 'нет данных';
				}
            },
            false  // do not disable caching
        );
    }
