var formChanged=0;
var defaultDDIndex=0;
function initSelectContent(){
	defaultDDIndex = document.nSortForm.nMainCat.selectedIndex;
}
function changeSelectContent(nDropDownObj){
	if(formChanged!=0){
		var approved = confirm("You will lose any unsaved changes to your current Sort Order.\nDo you want to continue?");
	}
	if (approved==true || formChanged==0) {  //if user pressed OK
		gotoHref(nDropDownObj);
	} else {
		nDropDownObj.selectedIndex=defaultDDIndex;
	}
}
function copyBoxToField(nSelBoxObj,nTextFieldObj){
	// reset text field
	nTextFieldObj.value="";
	// fill text field one by one with select box values
	for (var i = 0; i < nSelBoxObj.length; i++) {
		var nHiddenBoxBuff = nTextFieldObj.value;
		if(nHiddenBoxBuff) {
			nTextFieldObj.value = nHiddenBoxBuff+"~"+nSelBoxObj.options[i].text+"_"+nSelBoxObj.options[i].value;
		} else {
			nTextFieldObj.value = nSelBoxObj.options[i].text+"_"+nSelBoxObj.options[i].value;
		}
	}
}
function moveSelected(nDirection,selectObj,nJustSwitchText){
	// set default val
	if(nJustSwitchText==undefined){ nJustSwitchText = 1; }
	
	var nMoveMe=0;
	if(nDirection=="up"){ nMoveMe=1; }
	if(nDirection=="down"){ nMoveMe=-1; }
	// if something was selected, otherwise inform user...
	if(selectObj.selectedIndex!=-1 && nMoveMe!=0){
		// if selected item is not the uppermost item, then we can move it up...
		if((nDirection=="up" && selectObj.selectedIndex-1>=0) || (nDirection=="down" && selectObj.selectedIndex+1<=(selectObj.length-1))){
			// mark that the current form has changed
			formChanged=1;
			// get current selection as object
			var currOptionSel="";
			currOptionSel = selectObj.options[selectObj.selectedIndex];
			// get selection to switch current with as object
			var optionToSwitchWith="";
			optionToSwitchWith = selectObj.options[(selectObj.selectedIndex-nMoveMe)];
			if(nJustSwitchText==1){
				// Perform the switch (just on the texts)
				currOptionSelTextBuff = currOptionSel.text
				currOptionSel.text=optionToSwitchWith.text;
				optionToSwitchWith.text=currOptionSelTextBuff;
			} else {
				// Perform the switch on text & value
				currOptionSelTextBuff = currOptionSel.text
				currOptionSel.text=optionToSwitchWith.text;
				optionToSwitchWith.text=currOptionSelTextBuff;
				currOptionSelValueBuff = currOptionSel.value
				currOptionSel.value=optionToSwitchWith.value;
				optionToSwitchWith.value=currOptionSelValueBuff;
			}
			// Move selection
			selectObj.selectedIndex = selectObj.selectedIndex-nMoveMe;
		}
	} else {
		alert("Please select an item from the list to move first.");
	}
}