ns = (document.layers)? true:false 
ie = (document.all)? true:false 

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

/////////////////  Scripts for handling Radio Buttons

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

/////////////////  Scripts for handling CheckBoxes

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

function CheckAll(CbList)
{
    for (i = 1; i < CbList.length; i++) {
          CbList[i].checked = CbList[0].checked;
    }
}

function setCheckboxGroupValue(CbList)
{
    var out = "" ;

    for (i = 1; i < CbList.length; i++) {
	if (CbList[i].checked && CbList[i].value != "")
	{
          out += CbList[i].value + ",";
	}	
    }
    if (out.charAt(out.length-1) == ",") out = out.substring(0, out.length-1); 
    CbList[0].value = out;
}

function confirmSubmitCheckboxGroup(form, CbList, action)
{
 if(confirm("Are you sure to "+action+" the selected items ?"))
  {
     setCheckboxGroupValue(CbList);
     if (CbList[0].value == "") 
       alert("No item selected !"); 
     else
       form.submit();
  }
}

/////////////////  Scripts for handling List/Menu

function getSelectedListValue(CONTROL) {
	if (CONTROL==null) return "";
	var list_values = "";
	for (var i=0;i<CONTROL.length;i++) {
		if (CONTROL.options[i].selected) {
			if (list_values!="") list_values += ",";
			list_values += CONTROL.options[i].value;
		}
	}
	return list_values;
}

function selectAllList(CONTROL){
   for(var i = 0;i < CONTROL.length;i++){
      CONTROL.options[i].selected = true;
   }
}

function deselectAllList(CONTROL){
   for(var i = 0;i < CONTROL.length;i++){
      CONTROL.options[i].selected = false;
   }
}

function confirmSubmit(form, action)
{
  if(confirm("Are you sure to "+action+" the selected items ?")) form.submit();
}

/////////////////  Other Scripts

function gotoAnchor(sAnchor) {
 if (sAnchor.length > 0) {
 	if (ns) window.scrollTo(0, document.anchors[sAnchor].y);

 	if (ie) eval('document.all.' + sAnchor + '.scrollIntoView()');

 }

}

function popupResize(url, width, height, scrollbars)
{
     scrollbars = (scrollbars == 1) ? "yes" : "no";
     var d = new Date();
     var win = window.open(url,d.getHours()+d.getMinutes()+d.getSeconds(),"resizable=yes,height="+height+",width="+width+",scrollbars="+scrollbars);
     win.focus();
}

function popupFix(url, width, height)
{
     popupFix(url, width, height, 1)
}

function popupFix(url, width, height, scrollbars)
{
     scrollbars = (scrollbars == 1) ? "yes" : "no";
     var d = new Date();
     var win = window.open(url,d.getHours()+d.getMinutes()+d.getSeconds(),"resizable=no,height="+height+",width="+width+",scrollbars="+scrollbars);
     win.focus();
}

function replaceString(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

function checknumber(x){
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
testresult=false
}
return (testresult)
}

function checkChin(str) {
      hasChin = false;
      i = 0;
      while (((letter=str.charAt(i))!="")&&(!hasChin)) {
            num=escape(letter);
      	    if ((num1=num.substring(1,3)) > '7F' ) {
               hasChin = true;
            }
            i++;
      }
      return hasChin;
}

function extractFilename(filepath, seperator) {
   var temp=filepath.split(seperator);
   return temp[temp.length-1];
}

function expandcontent(cid){
	if (typeof ccollect!="undefined"){
		contractcontent(cid)
		document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
		selectedItem=cid+"|"+document.getElementById(cid).style.display
	}
}