swapbox.js
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:7k
- // This is the form name on the HTML page
- var formName = "faqform";
- // The select box on the left side
- var fromSelect = "selectFrom";
- // The select box on the right side
- var toSelect = "selectInto";
- // The name fo the text box where the article 'trail' is displayed
- var textTrail = "displayTrail";
- function addCategory(catIndex,sb1)
- {
- if(categoryArray[catIndex][1] != -1)
- {
- addCategory(categoryArray[catIndex][1],sb1);
- }
- if(sb1 == fromSelect)
- {
- if(categoryArray[catIndex][3] == 0)
- {
- document.forms[formName].elements[sb1].options[document.forms[formName].elements[sb1].options.length] = new Option(getCategoryDepth(catIndex) + categoryArray[catIndex][0],"",false,false);
- document.forms[formName].elements[sb1].options[document.forms[formName].elements[sb1].options.length - 1].style.backgroundColor = "#cccccc";
- categoryArray[catIndex][3] = 1;
- }
- }
- else
- {
- if(categoryArray[catIndex][2] == 0)
- {
- document.forms[formName].elements[sb1].options[document.forms[formName].elements[sb1].options.length] = new Option(getCategoryDepth(catIndex) + categoryArray[catIndex][0],"",false,false);
- document.forms[formName].elements[sb1].options[document.forms[formName].elements[sb1].options.length - 1].style.backgroundColor = "#cccccc";
-
- categoryArray[catIndex][2] = 1;
- }
- }
- }
- function addArticle(artIndex)
- {
- document.forms[formName].elements[articleArray[artIndex][3]].options[document.forms[formName].elements[articleArray[artIndex][3]].options.length] = new Option(getArticleDepth(artIndex) + articleArray[artIndex][0],articleArray[artIndex][1],false,false);
- document.forms[formName].elements[articleArray[artIndex][3]].options[document.forms[formName].elements[articleArray[artIndex][3]].options.length - 1].style.backgroundColor = "#cccfff";
-
- }
- function shiftArticle(fromSelectName, toSelectName)
- {
- var tempSelected = document.forms[formName].elements[fromSelectName].selectedIndex;
- if(document.forms[formName].elements[fromSelectName].selectedIndex == -1)
- {
- alert('You must select an article to move!');
- return false;
- }
- else if(document.forms[formName].elements[fromSelectName].options[tempSelected].value == "")
- {
- alert('You must select an article to move!');
- return false;
- }
- else
- {
- var tempValue = document.forms[formName].elements[fromSelectName].options[tempSelected].value;
- var tempIDStart = tempValue.indexOf(";");
- var tempIDEnd = tempValue.lastIndexOf(";");
- var tempIndex = tempValue.substring(tempIDStart + 1, tempIDEnd);
- if(document.all == null)
- {
- document.forms[formName].elements[fromSelectName].options[tempSelected] = null;
- }
- else
- {
- document.forms[formName].elements[fromSelectName].options.remove(tempSelected);
- }
- articleArray[tempIndex][3] = toSelectName;
- clearSelectBox(toSelectName);
- fillSelectBox(-1,toSelectName);
- }
-
- if(document.forms[formName].elements[fromSelectName].selectedIndex != -1)
- {
- shiftArticle(fromSelectName, toSelectName);
- }
- else
- {
- clearSelectBox(fromSelectName);
- fillSelectBox(-1,fromSelectName);
- document.forms[formName].elements[textTrail].value = "";
- }
- }
- function fillSelectBox(catIndex,selectBox)
- {
- for(var i = 0; i < categoryArray.length; i++)
- {
- if(categoryArray[i][1] == catIndex)
- {
- addCategory(i,fromSelect);
- fillSelectBox(i,selectBox);
- for(j = 0; j < articleArray.length; j++)
- {
- if(articleArray[j][2] == i && (articleArray[j][3] == selectBox || selectBox == ""))
- {
- if(selectBox == "")
- {
- addCategory(i,articleArray[j][3]);
- }
- else
- {
- addCategory(i,selectBox);
- }
- addArticle(j);
- }
- }
- }
- }
- if(catIndex == -1)
- {
- for(x = 0; x < articleArray.length; x++)
- {
- if(articleArray[x][2] == catIndex && (articleArray[x][3] == selectBox || selectBox == ""))
- {
- addArticle(x);
- }
- }
- }
- }
- function getCategoryDepth(catIndex)
- {
- if(categoryArray[catIndex][1] == -1)
- {
- return "";
- }
- else
- {
- return document.forms[formName].whitespace.value + getCategoryDepth(categoryArray[catIndex][1]);
- }
- }
- function getArticleDepth(artIndex)
- {
- if(articleArray[artIndex][2] == -1)
- {
- return "";
- }
- else
- {
- return getCategoryDepth(articleArray[artIndex][2]) + "- ";
- }
- }
- function clearSelectBox(selectBox)
- {
- for(j = document.forms[formName].elements[selectBox].options.length; j >= 0; j--)
- {
- if(document.all == null)
- {
- document.forms[formName].elements[selectBox].options[j] = null;
- }
- else
- {
- document.forms[formName].elements[selectBox].options.remove(j);
- }
- }
- for(i = 0; i < categoryArray.length; i++)
- {
- if(selectBox == toSelect)
- {
- categoryArray[i][2] = 0;
- }
- else
- {
- categoryArray[i][3] = 0;
- }
- }
- }
- function selectBoxToString(selectBox, hiddenInput)
- {
- var tempString = "";
- for(j = 0; j < document.forms[formName].elements[selectBox].options.length; j++)
- {
- if(document.forms[formName].elements[selectBox].options[j].value == "")
- {
- // Skip it
- }
- else
- {
- var tempValue = document.forms[formName].elements[selectBox].options[j].value;
- var tempIDStart = tempValue.indexOf(";");
- tempString = tempString + tempValue.substring(0, tempIDStart) + ";";
- }
- }
- document.forms[formName].elements[hiddenInput].value = tempString;
- }
- function getCategoryTrail(catIndex)
- {
- if(categoryArray[catIndex][1] == -1)
- {
- return categoryArray[catIndex][0];
- }
- else
- {
- return getCategoryTrail(categoryArray[catIndex][1]) + " >> " + categoryArray[catIndex][0];
- }
- }
- function getArticleTrail(selectIndex,selectBox)
- {
- var tempValue = document.forms[formName].elements[selectBox].options[selectIndex].value;
- if(tempValue == "")
- {
- return "";
- }
- var tempIDStart = tempValue.indexOf(";");
- artIndex = tempValue.substring(tempIDStart + 1, tempValue.length - 1);
- if(articleArray[artIndex][2] == -1)
- {
- return articleArray[artIndex][0];
- }
- else
- {
- return getCategoryTrail(articleArray[artIndex][2]) + " >> " + articleArray[artIndex][0];
- }
- }
- function moveSelectDown(sb1)
- {
- var tempIndex = document.forms[formName].elements[sb1].options.selectedIndex;
- if(tempIndex != -1)
- {
- if(tempIndex != document.forms[formName].elements[sb1].options.length - 1)
- {
- document.forms[formName].elements[sb1].options[tempIndex].selected = false;
- document.forms[formName].elements[sb1].options[tempIndex + 1].selected = true;
- return true;
- }
- }
- return false;
- }
- function moveSelectUp(sb1)
- {
- var tempIndex = document.forms[formName].elements[sb1].options.selectedIndex;
- if(tempIndex != -1)
- {
- if(tempIndex != 0)
- {
- document.forms[formName].elements[sb1].options[tempIndex].selected = false;
- document.forms[formName].elements[sb1].options[tempIndex - 1].selected = true;
- return true;
- }
- }
- return false;
- }