function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function replaceAll(oldStr,findStr,repStr) {
  var srchNdx = 0;  // srchNdx will keep track of where in the whole line
                    // of oldStr are we searching.
  var newStr = "";  // newStr will hold the altered version of oldStr.
  while (oldStr.indexOf(findStr,srchNdx) != -1)  
                    // As long as there are strings to replace, this loop
                    // will run. 
  {
    newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
                    // Put it all the unaltered text from one findStr to
                    // the next findStr into newStr.
    newStr += repStr;
                    // Instead of putting the old string, put in the
                    // new string instead. 
    srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
                    // Now jump to the next chunk of text till the next findStr.           
  }
  newStr += oldStr.substring(srchNdx,oldStr.length);
                    // Put whatever's left into newStr.             
  return newStr;
}

function move(index,to) {
	var list = document.forms[0].order;
	var total = list.options.length-1;
	
	if (index == -1) return false;
	if (to == +1 && index == total) return false;
	if (to == -1 && index == 0) return false;

	var bufferV = list.options[index].value;
	var bufferT = list.options[index].text;
	
	var bufferVN = list.options[index+to].value;
	var bufferTN = list.options[index+to].text;

	list.options[index].value = bufferVN;
	list.options[index].text = bufferTN;
	
	list.options[index+to].value = bufferV;
	list.options[index+to].text = bufferT;    
	list.selectedIndex += to;
	list.focus();
}

function submitOrder() {
	document.forms[0].setOrder.value = "";
	var c = 0;
	for (var i = 0; i <= document.forms[0].order.options.length-1 ; i++) { 
		document.forms[0].setOrder.value += c + "=" + document.forms[0].order.options[i].value;
		c++;
		document.forms[0].setOrder.value += "|";
	}
}
