//$Id: linkedlist.js,v 1.5 2007/10/24 17:00:31 steve Exp $
function primaryOnChange(oList,oList2){
  	clearCombo(oList2); // clear the downstream list
  	try {
		if (assocArray) {
	  		var newvalue = oList.name + "=" + oList.options[oList.selectedIndex].value;
		  	fillCombo(oList2, newvalue); // fill the downstream list
		}
  	}catch (e) {
  		//nothing
  	}
}
function primaryOnChange2(oList,oList2,oList3){
	primaryOnChange(oList,oList2);
	var newvalue = oList.name + "=" + oList.options[oList.selectedIndex].value;
	if (isFinite(assocArray2[newvalue])) {
		var arrX = assocArray2[newvalue];
		switch (arrX) {
			case 0:
			case 1:
				oList3.style.visibility = "hidden";
				oList3.value = 1;
				break;
			case 2:
				oList3.options(0).selected = true;
				oList3.style.visibility = "visible";
				break;
		}
	}
}

function clearCombo(oList){
  for (var i = oList.options.length - 1; i >= 0; i--){
    oList.options[i] = null;
  }
  oList.selectedIndex = -1;
}
function fillCombo(oList, vValue){
  if (vValue != "" && assocArray[vValue]){
    var arrX = assocArray[vValue];
    for (var i = 0; i < arrX.length; i = i + 2){
      oList.options[oList.options.length] = new Option(arrX[i + 1], arrX[i]);
      if (oList.multiple == true) {
      	oList.options[oList.options.length-1].selected = true
      }
    }
  } else oList.options[0] = new Option("<-Select", "");
  if (!(oList.onchange == null)) {
  	oList.onchange();
  }
}
var oChgObj;
function topicChangeNew(sList,sList2,iComp,iUid){
	var oList = document.getElementById(sList);
	oChgObj = getFormItem(oList.form,sList2);
	clearCombo(oChgObj);
	var iId = oList.options[oList.selectedIndex].value ;

	var sSid = getSessionId();
	var msg = new XMLRPCMessage();
	msg.setMethod("perms");
	msg.addParameter(escape(sSid));
	msg.addParameter(escape(iId));
	msg.addParameter(escape(iComp));
	msg.addParameter(escape(iUid));
	output = escape(msg.xml());
	jsrsExecute("rpc.php", fillPerm, "doRPC", output);
	return(true);
}

function getFormItem(oForm,sId){
	if (oForm == null) {
		return null
	}else{
		if (document.all) {
			return(oForm.elements.item(sId));
		}else{
			elements = oForm.elements;
			for (i in elements) {
				if (oForm.elements.item(i).id == sId){
					return(oForm.elements.item(i));
				}
			}
			return(null);
		}
	}
}

//oList is the perm list object
//sValue is the topic
//icomp is the component
function fillPerm(optshtml){
	xmldoc=new rpcXMLDocument(optshtml);
	var vals = xmldoc.params[1].split("|");
	var ids = xmldoc.params[2].split("|");
	fillSelObjectSeld( oChgObj,vals,ids,xmldoc.params[0]);
	return;
}

function checkall(sList,bValue){
	//if (document.all) {
    //    var oList = document.all.item(sList);
   	//}else{
    	var oList = document.getElementsByName(sList)[0];
    //}
    for (var i = 0; i < oList.options.length; i = i + 1){
    	oList.options[i].selected = bValue;
    }   	   
    //oList.disabled = bValue;
    return false;
}

function checkpre(sList,sSel,bValue){
	var tVal = document.getElementsByName(sSel)[0].value;
	var oList = document.getElementsByName(sList)[0];
	var start = false;
	var end = false;
	for (var i = 0; i < oList.options.length; i = i + 1){
		if (!end && oList.options[i].value.substr(0,2) == tVal){
			if (!start){
				start = true;
			}
			oList.options[i].selected = bValue;
		}else{
			if (start){
				end = true;
			}
		}
	} 
	return false;
}

function checkcert(sList,bValue){
	//if (document.all) {
    //    var oList = document.all.item(sList);
   	//}else{
    	var oList = document.getElementsByName(sList)[0];
    //}
    for (var i = 0; i < oList.options.length; i = i + 1){
		var tmpstr = getInnerText(oList.options[i]);
    	if (tmpstr) {
	    	if (tmpstr.substr(tmpstr.length-3,3) == "(C)") {
		    	oList.options[i].selected = bValue;
		    }else{
		    	oList.options[i].selected = !(bValue);
		    }
    	}
    }   	   
    return false;
}