// live chat funkcijos
var secs = 0
var trukme = 5
var timerioID = null
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    StartTheTimer()
    secs = trukme
}

function StartTheTimer()
{
    if (secs==0)
    {
		secs = trukme;
        mainFrame('gauti_chat_zinutes', '', '', {target: 'live_chat_window'})
        StartTheTimer()
    }
    else
    {
        secs = secs - 1
        timerioID = self.setTimeout("StartTheTimer()", delay)
    }
}

// live chat funkcijos
var secs2 = 0
var trukme2 = 5
var timerioID2 = null
var delay2 = 1000

function InitializeTimer2()
{
    // Set the length of the timer, in seconds
    StartTheTimer2()
    secs2 = trukme2
}

function StartTheTimer2()
{
    if (secs2==0)
    {
		secs2 = trukme2;
        mainFrame('siuo_metu', '', '', {target: 'last_events_window'})
        StartTheTimer2()
    }
    else
    {
        secs2 = secs2 - 1
        timerioID2 = self.setTimeout("StartTheTimer2()", delay)
    }
}

// kitos funkcijos

function showRules(path, lan) {
	window.open(path+"files/rules.php", "myWindow", "height = 600, width = 400, resizable = 0, scrollbars=auto, toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0" );
}

function attach_picture(quantity) {
	if (quantity=='') quantity=3;
	document.getElementById('add_picture').style.display = 'none';
	document.getElementById('add_another_picture').style.display = 'none';
	for (var i=0; i<quantity; i++) {
		if (document.getElementById('div_picture_'+i).style.display == 'none') {
			document.getElementById('div_picture_'+i).style.display = '';
			break;
		}
	}
	for (var i=0; i<quantity; i++) {
	  	if (document.getElementById('div_picture_'+i).style.display == 'none') {
		  	document.getElementById('add_another_picture').style.display = '';
		  	break;
		}
	}
}

function deattach_picture(id, quantity) {
	if (quantity=='') quantity=3;
	document.getElementById('picture_'+id).value = '';
	document.getElementById('span_input_'+id).innerHTML="<input id=\"picture_"+id+"\" name=\"picture_"+id+"\" type=\"file\">";
	document.getElementById('div_picture_'+id).style.display = 'none';
	var i;
	for (i=0; i<quantity; i++) {
		if (document.getElementById('div_picture_'+i).style.display == '') break;
	}

	if (i != quantity-1) {
		document.getElementById('add_picture').style.display = '';
		document.getElementById('add_another_picture').style.display = 'none';
	}
	if (i == 0) {
		document.getElementById('add_picture').style.display = 'none';
		document.getElementById('add_another_picture').style.display = '';
	}
}

function delete_picture(id, pic_id)
{
	document.getElementById('hidden_input_delete').value += pic_id+',';
	document.getElementById('span_input_'+id).style.display = 'none';
	document.getElementById('span_standard_'+id).style.display = '';

	//document.getElementById('div_picture_'+id).value = "<img src=\"images/paperclip.gif\" style=\"margin-right:2px;\"><span id=\"span_input_"+id+"\"><input type=\"radio\" name=\"main_photo\" value=\""+id+"\"><input id=\"picture_"+id+"\" name=\"picture_"+id+"\" type=\"file\"></span>&nbsp;<a href=\"javascript:;\" onClick=\"deattach_picture('"+id+"',4);\">trinti</a>";
}

/**
 *
 * @access public
 * @return void
 **/
function apkalba_vote(apkID, curr, balas)
{
	for (var i=1; i<=5; i++)
	{
		if (curr!='' && i<=curr) {
			document.getElementById('v_'+apkID+'_'+i).className = 'votes_active';
			var vertinimai = new Array("Visiška nesamonė","Nieko ypatingo","Verta dėmesio","Įdomi","Labai įdomi");
			document.getElementById('vertinimas_tekstas').innerHTML = vertinimai[i-1];
    } else if (balas!='' && i<=balas) {
			document.getElementById('v_'+apkID+'_'+i).className = 'votes_active';
			document.getElementById('vertinimas_tekstas').innerHTML = '';
		} else {
			document.getElementById('v_'+apkID+'_'+i).className = 'votes';
		}
	}
}
/**
 *
 * @access public
 * @return void
 **/
function cituoti(data, vardas, komentaras){
	document.getElementById('f_komentaras').value = '[citata]'+'[b]'+vardas+'[/b] '+data+' rašė: \n'+Base64.decode(komentaras)+'[/citata]'+'\n';
}

function emotion(myValue, myField) {
	//IE support
	if (document.selection) {
		document.getElementById(myField).focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (document.getElementById(myField).selectionStart || document.getElementById(myField).selectionStart == 0) {
		var startPos = document.getElementById(myField).selectionStart;
		var endPos = document.getElementById(myField).selectionEnd;
		var smile_lenght = myValue.length;
		var startMain = startPos+smile_lenght;
		document.getElementById(myField).value = document.getElementById(myField).value.substring(0, startPos) + myValue	+ document.getElementById(myField).value.substring(endPos, document.getElementById(myField).value.length);
		setSelectionRange(document.getElementById(myField), startMain, startMain);
	} else {
		document.getElementById(myField).value += myValue;
		setSelectionRange(document.getElementById(myField), startMain, startMain);
	}
}

function setSelectionRange(input, selectionStart, selectionEnd) {
	if (input.createTextRange) {
		var range = input.createTextRange();
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}
	else if (input.setSelectionRange) {
		input.focus();
		input.setSelectionRange(selectionStart, selectionEnd);
	}
}

function CreateBookmarkLink(url, title)
{
	if (window.sidebar)
	{
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external )
	{
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print)
	{
		// Opera Hotlist
		return true;
	}
}

function active_tab(tabID){
	document.getElementById('tab_1').style.display = 'none';
	document.getElementById('tab_2').style.display = 'none';
	document.getElementById('tab_3').style.display = 'none';
	document.getElementById(tabID).style.display = '';
}
