rendered paste bodyfunction sort_up(s)
{
if (s.selectedIndex === false || s.selectedIndex == -1)
{
alert("Please select an option first");
return( false );
}
var index = s.selectedIndex, arr = s.options, temp;
if (index == 0) return;
arr = extract_options(s);
temp = s.options[index - 1];
arr[index - 1] = {value:s.options[index].value, text:s.options[index].text};
arr[index] = {value:temp.value, text:temp.text};
write_options(s, arr);
s.options[index - 1].selected = true;
return( false );
}
function sort_down(s)
{
if (s.selectedIndex === false || s.selectedIndex == -1)
{
alert("Please select an option first");
return( false );
}
var index = s.selectedIndex, arr = s.options, temp;
if (index == s.options.length - 1) return;
arr = extract_options(s);
temp = s.options[index + 1];
arr[index + 1] = {value:s.options[index].value, text:s.options[index].text};
arr[index] = {value:temp.value, text:temp.text};
write_options(s, arr);
s.options[index + 1].selected = true;
return( false );
}
function save_priority(s)
{
var f = s.form, i, len = s.options.length;
if (f.priority == undefined)
{
alert("Missing 'priority' input field");
return( false );
} else if ( !confirm("This will save the order in which these options appear on the website.\n\nOK to continue?") )
return( false );
f.priority.value = "";
for (i = 0; i < len; i++)
f.priority.value += ((f.priority.value != "") ? "," : "") + s.options[i].value;
return( true );
}
function extract_options(s)
{
var i, len = s.options.length;
var arr = [];
for (i = 0; i < len; i++)
arr.push( {value:s.options[i].value, text:s.options[i].text} );
return( arr );
}
function write_options(s, arr)
{
var i, len = arr.length;
s.options.length = 0;
for (i = 0; i < len; i++)
s.options[s.options.length] = new Option(arr[i].text, arr[i].value);
}