function displayStrings() {
	
	var index = document.getElementById('display_strings').options.selectedIndex;
	var id = document.getElementById('display_strings').options[index].value; 
	index = document.getElementById('display_strings_mode').options.selectedIndex;
	var mode = document.getElementById('display_strings_mode').options[index].value; 
	location.href = 'index.php?action=edit_build&mode=' + mode + '&id=' + id;
	return true;
	
}

function showDiffrences() {
	
	var index = document.getElementById('diff_1').options.selectedIndex;
	var id = document.getElementById('diff_1').options[index].value; 
	index = document.getElementById('diff_2').options.selectedIndex;
	var id2 = document.getElementById('diff_2').options[index].value; 
	location.href = 'index.php?action=show_diffs&from=' + id + '&to=' + id2;
	
}

function downloadFile(lang) {
	
	var index = document.getElementById('download').options.selectedIndex;
	var id = document.getElementById('download').options[index].value; 
	location.href = 'index.php?action=download&id=' + id + '&lang=' + lang;
	
}

function downloadLink(lang) {
	
	var index = document.getElementById('download').options.selectedIndex;
	var id = document.getElementById('download').options[index].value; 
	var p = prompt('Copy this link:', 'http://utorrent.com/translate/index.php?action=download&id=' + id + '&lang=' + lang);
	
}

function uploadLngFile() {
	
	var index = document.getElementById('upload').options.selectedIndex;
	var id = document.getElementById('upload').options[index].value; 
	location.href = 'index.php?action=upload_lngfile&id=' + id;
	
}

function showStatus() {
	
	var index = document.getElementById('status').options.selectedIndex;
	var id = document.getElementById('status').options[index].value; 
	location.href = 'index.php?action=status&id=' + id;
	
}

function packGenerate() {
	
	var index = document.getElementById('pack_generate').options.selectedIndex;
	var id = document.getElementById('pack_generate').options[index].value; 
	location.href = 'index.php?action=generate_pack&id=' + id;
	
}

function uploadWebsite() {

	var index = document.getElementById('website_upload_number').options.selectedIndex;
	var n = document.getElementById('website_upload_number').options[index].value; 
	location.href = 'index.php?action=website_upload&n=' + n;
	
}

function checkEnter(evt, obj) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
	var nextinput = obj.form[(getIndex(obj)+2) % obj.form.length];
	if (getIndex(obj)+2 < obj.form.length) {
		nextinput.focus();	
	}
	else {
		document.getElementById('submit_button').focus();
	}
	if (evt.stopPropagation) evt.stopPropagation();
	if (evt.preventDefault) evt.preventDefault();
	evt.cancelBubble = true;
	evt.returnValue = false;
        return false;
    } else {
        return true;
    }
}

function selectAll(obj) {
	if(document.all) {
		obj.select();
	}
	else {
		obj.selectionStart = 0;
		obj.selectionEnd = obj.value.length;
	}
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
}

function question(url) {
	q = confirm("Do you really want to do this ?");
	if (q != 0) {
		location.href = url;
	}
}

function search(mode, id, page) {
	var query = 
	top.location.href = 'index.php?action=edit_build&mode=' + mode + '&id=' + id + '&page=' + page + '&search=' + document.getElementById('search').value;
}

function searchWebsite(page) {
	var query = 
	top.location.href = 'index.php?action=website_edit&page=' + page + '&search=' + document.getElementById('search').value;
}

function checkEnterSearch(evt, mode, id, page) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
    	if(id != 0) {
		search(mode, id, page);
	}
	else {
		searchWebsite(page);
	}
        return false;
    } else {
        return true;
    }
}

function searchScroll(stringid) {
	window.onload = function() {
		var o = document.getElementById('string_' + stringid);
		var t = getOffsetTop(o);
		window.scrollTo(0, t);
	}
}

function getOffsetTop(obj)
{
	var y = 0;
	while(obj)
	{
		y += parseInt(obj.offsetTop);
		obj = obj.offsetParent;
	}
	return y;
}