/*
* This script switchs between single and multiline input in some screens.
*
* NOTE!!!
* This file is in UTF-8 encoding and when included in the html should be specified.
*
* Copyright Slovored.com (c) 2009
*/

var singleLine = true;


function toggleMultiLine(link, word, multiLine) {
singleLine = !singleLine;
var w = document.getElementById(word);
var ml = document.getElementById(multiLine);
if (singleLine) {
document.forms.search.method = "GET";
link.innerHTML = "+";
w.style.display = "inline";
w.disabled = false;
ml.style.display = "none";
ml.disabled = true;
w.value = getFirstLine(ml.value, 100);
w.focus();
} else {
document.forms.search.method = "POST";
link.innerHTML = "-";
w.style.display = "none";
w.disabled = true;
if (isChrome) {
// We need to make width with 2px less because seems that is the
// difference between input and textarea with the same width.
ml.style.width = "448px";
}
ml.style.display = "inline";
ml.disabled = false;
if (ml.value == "" && w.value != "") {
ml.value = w.value;
}
ml.focus();
}
return false;
}

function getFirstLine(value, maxChars) {
if (value.length > maxChars) {
value = value.substr(0, maxChars);
pos = value.lastIndexOf(" ");
if (pos > 0) {
value = value.substr(0, pos);
}
}
var pos = value.indexOf("\n");
if (pos > 0) {
return value.substr(0, pos);
}
return value;
}

