/**
 * Copyright CloverWorxs Inc.
 */
var cwGlobalObject=new Object();
var cwNumberAllowedKeyCodes = new Array(8,37,38,39,40,46,48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105,229);

function cwIsContainedInArray(arrays,value){
    if("undefined"==typeof(arrays))return false;
    if("undefined"==typeof(arrays.length)){
        if(arrays==value)return true;
    }
    else{
        for(var i = 0; i < arrays.length; i++) {
            if(arrays[i]==value)return true;
        }
    }
    return false;
}

function cwOnlyKeyNumber(){
    var key = window.event.keyCode;
    if(event.ctrlKey || event.altKey || event.shiftKey || !cwIsContainedInArray(cwNumberAllowedKeyCodes,key)){
        //event.keyCode=0;
        event.returnValue=false;
        return false;
    }
    return true;
}

function cwIsFloatNumber(text) {
  var regex = /^[+|-]?\d*\.?\d*$/;
  if (!regex.test(text)){
      return false;
  }
  return true;
}

function cwIsNatureNumber(value){
    if(isNaN(value)){
        return false;
    }
    if(value<=0){
        return false;
    }
    var invalid = new Array(".","x");
    for(var i=0;i<invalid.length;i++){
        if(value.indexOf(invalid[i])>=0){
            return false;
        }
    }
    for(var i=0;i<value.length;i++){
        var c = value.charAt(i);
        var isNumber = false;
        for(var j=0;j<10;j++){
            if(c == j){
                isNumber = true;
                break;
            }
        }
        if(!isNumber) return false;
    }
    return true;
}

function is2bit(str) {
  var bit=0;
  var isDecimal=false;
  for(var i=0; i<str.length; i++){
    if (isDecimal) {
      ++bit;
    }
    if(str.charAt(i)=='.'){
        isDecimal = true;
    }
  }

  if (bit>2){
    return false;
  }
  return true;
}

function cwTrimWhiteSpace(inputString){
    var retValue = inputString;
    var whiteSpace = new Array(' ','\t','\n','\r');
    var ch = retValue.charAt(0);
    while (cwIsContainedInArray(whiteSpace,ch)) {
        retValue = retValue.substr(1, retValue.length-1);
        ch = retValue.charAt(0);
    }
    ch = retValue.charAt(retValue.length-1);
    while (cwIsContainedInArray(whiteSpace,ch)) {
        retValue = retValue.substr(0, retValue.length-1);
        ch = retValue.charAt(retValue.length-1);
    }
    return retValue;
}

function cwCheckSkillsControl(){
  var EditControlX=null;
  try{EditControlX = new ActiveXObject("EditControl.EditCtrl");}catch(e){;}
  return (EditControlX!=null);
}

function cwNotEmpty(o){
  if(typeof(o)!="undefined" && o!=null && o!="") return true;
  return false;
}

function cwIsSelectedForCheckBox(checkbox){
  if("undefined"==typeof(checkbox)) {
    return false;
  }
  if("undefined"==typeof(checkbox.length)){
    if(checkbox.disabled==false && checkbox.checked){
      return true;
    }
  }else{
    for (var i=0; i<checkbox.length; i++) {
      if(checkbox[i].disabled==false && checkbox[i].checked){
        return true;
      }
    }
  }
  return false;
}

function cwSelectCheckBox(checkbox,bSelect){
  if("undefined"==typeof(checkbox)) {
    return;
  }
  if("undefined"==typeof(checkbox.length)){
    if(checkbox.disabled==false){
      checkbox.checked = typeof(bSelect)=="undefined"?!checkbox.checked:bSelect;
    }
  }else{
    for (var i=0; i<checkbox.length; i++) {
      if(checkbox[i].disabled==false){
        checkbox[i].checked=typeof(bSelect)=="undefined"?!checkbox[i].checked:bSelect;
      }
    }
  }
}
// Added by crystal on 2005-05-05
function cwGetCheckBoxValueByChecked(oBox,id,batchAction){
  var value="";  //alert(oBox.length);  alert(batchAction  + "<<<======>>>" + id);
  if("undefined"==typeof(oBox.length)){
    if("undefined"==typeof(batchAction) || "undefined"==typeof(id) || ""==batchAction || ""==id){
      if(oBox.disabled==false){
        if(oBox.checked){
          value=oBox.value;
        }
      }
    }else{
      if(oBox.disabled==false){
        if(oBox.checked){
          var oElement=document.getElementById(id+oBox.value);
          if("audit"==batchAction && typeof(oElement.audited)!="undefined" && "true"==oElement.audited){
            value=oBox.value;
          }else if("enable"==batchAction && typeof(oElement.enabled)!="undefined" && "true"==oElement.enabled){
            value=oBox.value;
          }else if("disable"==batchAction && typeof(oElement.disabed)!="undefined" && "true"==oElement.disabed){
            value=oBox.value;
          }else if("delete"==batchAction && ((typeof(oElement.disabed)!="undefined" && "true"==oElement.disabed)
              || (typeof(oElement.audited)!="undefined" && "true"==oElement.audited))){
            value=oBox.value;
          }else{
            value="";
          }
        }
      }
    }
  }else if("undefined"==typeof(batchAction) || typeof(batchAction)==null  || ""==batchAction || "undefined"==typeof(id) || ""==id){
    for(var j=0;j<oBox.length;j++){
      if(oBox[j].checked){
        value+=oBox[j].value + ";";
      }
    }
  }else if("undefined"!=typeof(batchAction) && batchAction!="" && "undefined"!=typeof(id) && ""!=id){
    for(var j=0;j<oBox.length;j++){
      if("audit"==batchAction){
        if(oBox[j].checked){
          var oElement=document.getElementById(id+oBox[j].value);
          //alert(typeof(oElement.audited));  alert("audited====" + oElement.audited);
          if(typeof(oElement.audited)!="undefined" && "true"==oElement.audited){
            value+=oBox[j].value + ";";
          }
        }
      }else if("enable"==batchAction){
        if(oBox[j].checked){
          var oElement=document.getElementById(id+oBox[j].value);
          //alert(typeof(oElement.enabled));  alert("enabled====" + oElement.enabled);
          if(typeof(oElement.enabled)!="undefined" && "true"==oElement.enabled){
            value+=oBox[j].value + ";";
          }
        }
      }else if("disable"==batchAction){
        if(oBox[j].checked){
          var oElement=document.getElementById(id+oBox[j].value);
          //alert(typeof(oElement.disabed));  alert("disabed====" + oElement.disabed);
          if(typeof(oElement.disabed)!="undefined" && "true"==oElement.disabed){
            value+=oBox[j].value + ";";
          }
        }
      }else if("delete"==batchAction){
        if(oBox[j].checked){
          var oElement=document.getElementById(id+oBox[j].value);
          //alert(typeof(oElement.disabed));  alert("disabed====" + oElement.disabed);
          if((typeof(oElement.disabed)!="undefined" && "true"==oElement.disabed)
              || (typeof(oElement.audited)!="undefined" && "true"==oElement.audited)){
            value+=oBox[j].value + ";";
          }
        }
      }else{
        // TODO:
      }
    }
  }else{
      alert("Not found checked the checkbox!");
  }
  return value;
}
/**
 * for portal.jsp and for all block open/close
 */
function cwDisplayMenu(oBlock,owner,picture,contextPath){
    if(oBlock.style.display==""){
        oBlock.style.display="none";
        cwClosedStatus(owner,picture,contextPath);
    }else{
        oBlock.style.display="";
        cwOpenedStatus(owner,picture,contextPath);
    }
}
function cwSwitchTitleBarIcon(oBlock,owner,picture,isOver,contextPath){
    if(oBlock.style.display==""){
        if(isOver)cwClosedStatus(owner,picture,contextPath);
        else cwOpenedStatus(owner,picture,contextPath);
    }else{
        if(isOver)cwOpenedStatus(owner,picture,contextPath);
        else cwClosedStatus(owner,picture,contextPath);
    }
}
function cwOpenedStatus(owner,picture,contextPath){
    owner.className="boxtitle_icon";
    if(picture!=""){
    if(picture.indexOf("/")!=0){
      picture = "/" + picture;
    }
        owner.style.backgroundImage="url("+contextPath+picture+")";
    }
}
function cwClosedStatus(owner,picture,contextPath){
    owner.className="boxtitle_icon2";
    if(picture!=""){
    if(picture.indexOf("/")!=0){
      picture = "/" + picture;
    }
        var re = new RegExp("/replaceable/icon/", "gi");
        var picture = picture.replace(re,"/replaceable/icon/mirror/");
        owner.style.backgroundImage="url("+contextPath+picture+")";
    }
}

function cwAdjustImageSize(theImg,defWidth,defHeight){
    if(theImg.width>defWidth)theImg.style.width=defWidth;
    if(theImg.height>defHeight)theImg.style.width=(theImg.width*defHeight)/theImg.height;
}

function cwGetIEVersion(){
  if(navigator.appName == "Microsoft Internet Explorer") {
    if(navigator.appVersion.match(/MSIE 9./i)=='MSIE 7.') {
      return ('IE9');
    }else if(navigator.appVersion.match(/MSIE 8./i)=='MSIE 7.') {
      return ('IE8');
    }else if(navigator.appVersion.match(/MSIE 7./i)=='MSIE 7.') {
      return ('IE7');
    }else if(navigator.appVersion.match(/MSIE 6./i)=='MSIE 6.') {
      return ('IE6');
    }else if(navigator.appVersion.match(/MSIE 5./i)=='MSIE 5.') {
      return ('IE5');
    }else{
      return ('IE5');
    }
  }
  return null;
}

function cwGetFileValue(oFile){
  oFile.select();
  return document.selection.createRange().text;
}

/**
 * for portal.jsp and for all block popup menu
 */
var curentBlockPopupMenu;
var hiddingSelectBoxArrays = new Array("selectPortalStyle1","answersSelectBox1","selRenderBlock");
function cwLMPopUp(parentObj,menuID) {
    var selfObj = document.getElementById(menuID);
    var leftX = document.body.scrollLeft+window.event.clientX-cwGetOffsetLeftFromBody(parentObj)-5;
    if(selfObj.offsetWidth>=(document.body.clientWidth-window.event.clientX)){
        leftX = leftX-selfObj.offsetWidth+10;
    }
    var topY = document.body.scrollTop+window.event.clientY-cwGetOffsetTopFromBody(parentObj)-5;
    if(selfObj.offsetHeight>=(document.body.clientHeight-window.event.clientY)){
        topY = topY-selfObj.offsetHeight+10;
    }
    selfObj.style.left=leftX;
    selfObj.style.top=topY;
    curentBlockPopupMenu=menuID;
    cwShowMenu(selfObj.offsetLeft,selfObj.offsetTop,selfObj.offsetWidth,selfObj.offsetHeight);
    document.body.attachEvent ("onmouseup",cwHideMenu);
}
function cwShowMenu(ml,mt,mw,mh){
  document.getElementById(curentBlockPopupMenu).style.visibility = "visible";
  var tags = document.body.getElementsByTagName("SELECT");
  for(var i = 0; i < tags.length; i++) {
    if(tags[i]!=null && "undefined"!=typeof(tags[i])){
      var ox = cwGetOffsetLeft(tags[i]); oy = cwGetOffsetTop(tags[i]);
      var ow = tags[i].offsetWidth; oh = tags[i].offsetHeight;
      //alert(ox);alert(oy);//alert(ow);alert(oh);
      if(cwSuperposition(ml,mt,mw,mh,ox,oy,ow,oh)) tags[i].style.visibility = "hidden";
    }
  }
}
function cwHideMenu(){
  document.body.detachEvent("onmouseup",cwHideMenu);
  document.getElementById(curentBlockPopupMenu).style.visibility = "hidden";
  var tags = document.body.getElementsByTagName("SELECT");
  for(var i = 0; i < tags.length; i++) {
    if(tags[i]!=null && "undefined"!=typeof(tags[i]) && tags[i].style.visibility=="hidden"){
      tags[i].style.visibility = "visible";
    }
  }
}
function cwSuperposition(L1,T1,W1,H1,L2,T2,W2,H2){
  var R1=L1+W1; B1=T1+H1; R2=L2+W2; B2=T2+H2;
  var x = (L2>=L1 && L2<=R1) || (R2>=L1 && R2<=R1) || (L2<=L1 && R2>=R1);
  var y = (T2>=T1 && T2<=B1) || (B2>=T1 && B2<=B1) || (T2<=T1 && B2>=B1);
  return x&&y;
}
/*
function cwHideMenuOnOuterRange(oElement){
  var oSource = event.srcElement;
  var oTarget = event.toElement;
  if(oSource.tagName.toUpperCase()=="DIV" && oSource.id==oElement.id){
    if(!oSource.contains(oTarget)){
      cwHideMenu();
    }
  }
  if(event.clientX<=oElement.offsetLeft  || event.clientX>=oElement.offsetLeft+oElement.clientWidth
    || event.clientY<=oElement.offsetTop || event.clientY>=oElement.offsetTop+oElement.clientHeight){
    cwHideMenu();
  }
}
*/
var cwHideMenuTimer=null;
function cwShowMenuTimeout(parentObj,menuID) {
  cwLMPopUp(parentObj,menuID);
  cwHideMenuClearTimeout(parentObj);
}
function cwHideMenuStartTimeout(oElement) {
    cwHideMenuTimer = setTimeout("cwHideMenu()", 1);
}
function cwHideMenuClearTimeout(oElement) {
  if (cwHideMenuTimer){
    clearTimeout(cwHideMenuTimer);
  }
  cwHideMenuTimer = null;
}
function cwGetOffsetLeftFromBody(o){
  var pos = 0;
  var parentObj = o.parentElement;
  while(parentObj != null && typeof(parentObj) != "undefined" && parentObj.tagName.toUpperCase() != "BODY"){
    if(parentObj.style.position=='absolute' || parentObj.style.position=='relative'){pos += parentObj.offsetLeft};
    parentObj = parentObj.parentElement;
  }
  return pos;
}
function cwGetOffsetTopFromBody(o){
  var pos = 0;
  var parentObj = o.parentElement;
  while(parentObj != null && typeof(parentObj) != "undefined" && parentObj.tagName.toUpperCase() != "BODY"){
    if(parentObj.style.position=='absolute' || parentObj.style.position=='relative'){pos += parentObj.offsetTop};
    parentObj = parentObj.parentElement;
  }
  return pos;
}
function cwGetOffsetLeft(layer) {
    var value = 0;
    object = layer;
    value = object.offsetLeft;
    while (object.tagName != "BODY" && object.offsetParent) {
        object = object.offsetParent;
        value += object.offsetLeft;
    }
    return (value);
}
function cwGetOffsetTop(layer) {
    var value = 0;
    object = layer;
    value = object.offsetTop;
    while (object.tagName != "BODY" && object.offsetParent) {
        object = object.offsetParent;
        value += object.offsetTop;
    }
    return (value);
}
function cwDisplayBlockItemTR(key){
  var oPlusImg = document.getElementById("BlockItemPlusIMG_"+key);
  var oMinusImg = document.getElementById("BlockItemMinusIMG_"+key);
  if(oPlusImg != null && typeof(oPlusImg) != "undefined"){
    if( oPlusImg.style.display == ""){
      oPlusImg.style.display="none";
      oMinusImg.style.display="";
    } else {
      oPlusImg.style.display="";
      oMinusImg.style.display="none";
    }
  }
  var oTr = document.getElementsByName("BlockItemTR_"+key);
  if(oTr.length>0){
    if(oTr[0].style.display==""){
      for(var i=0;i<oTr.length;i++){
          cwCloseDescendantsTR(oTr[i].lontoo);
          oTr[i].style.display="none";
      }
    }else{
      for(var i=0;i<oTr.length;i++){
          oTr[i].style.display="";
      }
    }
  }
}
function cwCloseDescendantsTR(key){
  var oPlusImg = document.getElementById("BlockItemPlusIMG_"+key);
  var oMinusImg = document.getElementById("BlockItemMinusIMG_"+key);
  var oTr = document.getElementsByName("BlockItemTR_"+key);
  for(var i=0;i<oTr.length;i++){
    if(oPlusImg != null && typeof(oPlusImg) != "undefined"){
      oPlusImg.style.display="";
      oMinusImg.style.display="none";
    }
    if(oTr[i].style.display==""){
        cwCloseDescendantsTR(oTr[i].lontoo);
        oTr[i].style.display="none";
    }
  }
}

/**
 * for change page panel width
 */
var startXPosition=0;
var startLeftWidth=0;
var startLeft2Width=0;
var startMiddleWidth=0;
var startRightWidth=0;
function getSpacifyObjectWidth(o){
  if("undefined"!=typeof(o)){
    if("undefined"==typeof(o.length))return(o.clientWidth);
    else return(o[0].clientWidth);
  }
  return(0);
}
function setSpacifyObjectWidth(o,value){
  if(value<=0)return;
  if("undefined"!=typeof(o)){
    if("undefined"==typeof(o.length)){
      o.style.width=value;
    }else{
      for(var i=0;i<o.length;i++){o[i].style.width=value;}
    }
  }
}
function startDragAndDrop(){
    startXPosition = window.event.clientX;
    startLeftWidth = getSpacifyObjectWidth(document.all.leftPortalPanelID);
  startLeft2Width = getSpacifyObjectWidth(document.all.leftPortalPanel2ID);
    startMiddleWidth = getSpacifyObjectWidth(document.all.middlePortalPanelID);
    startRightWidth = getSpacifyObjectWidth(document.all.rightPortalPanelID);
}
function inprocessDragAndDrop(index){//1=first from left;2=second from left;3=third from left
    var offsetWidth = window.event.clientX-startXPosition;
    if(index==1 && startMiddleWidth>offsetWidth){
        setSpacifyObjectWidth(document.all.leftPortalPanelID,startLeftWidth+offsetWidth);
        setSpacifyObjectWidth(document.all.middlePortalPanelID,startMiddleWidth-offsetWidth);
    }else if(index==2 && startLeft2Width>offsetWidth){
        setSpacifyObjectWidth(document.all.leftPortalPanel2ID,startLeft2Width+offsetWidth);
        setSpacifyObjectWidth(document.all.middlePortalPanelID,startMiddleWidth-offsetWidth);
    }else if(index==3 && startRightWidth>offsetWidth){
        setSpacifyObjectWidth(document.all.middlePortalPanelID,startMiddleWidth+offsetWidth);
        setSpacifyObjectWidth(document.all.rightPortalPanelID,startRightWidth-offsetWidth);
    }

    if(typeof(document.all.portalPanelWidthDisplay)!="undefined"){
        var lWidth = getSpacifyObjectWidth(document.all.leftPortalPanelID);
    var l2Width = getSpacifyObjectWidth(document.all.leftPortalPanel2ID);
        var mWidth = getSpacifyObjectWidth(document.all.middlePortalPanelID);
        var rWidth = getSpacifyObjectWidth(document.all.rightPortalPanelID);
        document.all.portalPanelWidthDisplay.innerHTML=""+lWidth+", "+l2Width+", "+mWidth+", "+rWidth+"&nbsp;";
        window.status=""+lWidth+", "+l2Width+", "+mWidth+", "+rWidth+"";
    }
}
function endDragAndDrop(url,percent){
    // url is a whole contextpath and servlet path with its all querystring; for example:
    // "/skills/portal/portalView.do?fwcid=&layoutLWidth=%LEFTWIDTH%&layoutMWidth=%MIDDLEWIDTH%&layoutRWidth=%RIGHTWIDTH%";
    // or relative url, for example: "?fwcid=&layoutLWidth=%LEFTWIDTH%&layoutMWidth=%MIDDLEWIDTH%&layoutRWidth=%RIGHTWIDTH%";
    // replace %LEFTWIDTH% %MIDDLEWIDTH% %RIGHTWIDTH% with end value(s).
    // if percent is true, return percent value; or return absolute value.
    var leftWidth = getSpacifyObjectWidth(document.all.leftPortalPanelID);
  var left2Width = getSpacifyObjectWidth(document.all.leftPortalPanel2ID);
    var middleWidth = getSpacifyObjectWidth(document.all.middlePortalPanelID);
    var rightWidth = getSpacifyObjectWidth(document.all.rightPortalPanelID);
    if(percent=="true"){
        var endTotalWidth = leftWidth+left2Width+middleWidth+rightWidth;
        leftWidth = Math.round(100*leftWidth/endTotalWidth);
    left2Width = Math.round(100*left2Width/endTotalWidth);
        middleWidth = Math.round(100*middleWidth/endTotalWidth);
        rightWidth = Math.round(100*rightWidth/endTotalWidth);
        setSpacifyObjectWidth(document.all.leftPortalPanelID,leftWidth+"%");
    setSpacifyObjectWidth(document.all.leftPortalPanel2ID,left2Width+"%");
        setSpacifyObjectWidth(document.all.middlePortalPanelID,middleWidth+"%");
        setSpacifyObjectWidth(document.all.rightPortalPanelID,rightWidth+"%");
    }
    var re = new RegExp("%LEFTWIDTH%", "gi");
    url = url.replace(re,leftWidth);
  var re = new RegExp("%LEFT2WIDTH%", "gi");
    url = url.replace(re,left2Width);
    var re = new RegExp("%MIDDLEWIDTH%", "gi");
    url = url.replace(re,middleWidth);
    var re = new RegExp("%RIGHTWIDTH%", "gi");
    url = url.replace(re,rightWidth);
    XMLHttpObj.sendAsyncRequest("GET",url);
}

/**
 * for image outline
 */
function cwMakePictureAsOutline(o){
    var refValue=50;orgWidth=o.width;
    if(o.width>refValue){
        while(o.width!=refValue){o.style.width=refValue;}
        o.style.width=Math.min(orgWidth,o.parentElement.clientWidth);
    }
}
function cwFlexPictureByMouseWheel(o){
    var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
    return false;
}

/*
 * Created by dony on 2007-10-10
 */
var Drag={
  dragged:false,
  trdo:null,
  divo:null,
  portal:null,
  website:null,

  dragStart:function(aa,bb){
    Drag.trdo=event.srcElement;
    if((Drag.trdo.tagName=="TD")||(Drag.trdo.tagName=="TR")){
      Drag.trdo=Drag.trdo.offsetParent;
      while(typeof(Drag.trdo.dragBlock)=="undefined" && Drag.trdo.tagName.toUpperCase()!="BODY"){
        Drag.trdo=Drag.trdo.offsetParent;
      }
      Drag.trdo.style.zIndex=100;
    }else{
      return;
    }
    Drag.dragged=true;
    Drag.portal=aa;
    Drag.website=bb;
    Drag.divo=document.createElement("div");
    Drag.divo.innerHTML=Drag.trdo.outerHTML;
    Drag.trdo.style.border="1px dashed red";
    Drag.divo.style.display="block";
    Drag.divo.style.position="absolute";
    Drag.divo.style.filter="alpha(opacity=70)";
    Drag.divo.style.cursor="move";
    Drag.divo.style.border="1px solid #000000";
    Drag.divo.style.width=Drag.trdo.offsetWidth;
    Drag.divo.style.height=Drag.trdo.offsetHeight;
    Drag.divo.style.top=Drag.getInfo(Drag.trdo).top;
    Drag.divo.style.left=Drag.getInfo(Drag.trdo).left;
    document.body.appendChild(Drag.divo);
    Drag.lastX=event.clientX;
    Drag.lastY=event.clientY;
    Drag.lastLeft=Drag.divo.style.left;
    Drag.lastTop=Drag.divo.style.top;
  },



  draging:function(){//important:get mouse positon
    if(!Drag.dragged||Drag.trdo==null)return;
    var tX=event.clientX;
    var tY=event.clientY;
    Drag.divo.style.left=parseInt(Drag.lastLeft)+tX-Drag.lastX;
    Drag.divo.style.top=parseInt(Drag.lastTop)+tY-Drag.lastY;
    for(var i=0;i<parentTable.cells.length;i++){
      if(parentTable.cells[i].dragContainer!="true")continue;
      var parentCell=Drag.getInfo(parentTable.cells[i]);
      if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
        var subTables=Drag.gtbos(parentTable.cells[i]);
        if(subTables.length==0){
          if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
            parentTable.cells[i].appendChild(Drag.trdo);
          }
          break;
        }
        for(var j=0;j<subTables.length;j++){
          var subTable=Drag.getInfo(subTables[j]);
          if(tX>=subTable.left&&tX<=subTable.right&&tY>=subTable.top&&tY<=subTable.bottom){
            parentTable.cells[i].insertBefore(Drag.trdo,subTables[j]);
            break;
          }else{
            parentTable.cells[i].appendChild(Drag.trdo);
          }
        }
      }
    }
  },

  dragEnd:function(){
    if(!Drag.dragged)return;
    Drag.dragged=false;
    Drag.mm=Drag.repos(150,15);
    Drag.trdo.style.borderWidth="0px";
    Drag.trdo.style.borderTop="1px solid #3366cc";
    Drag.divo.style.borderWidth="0px";
    Drag.trdo.style.zIndex=1;
    // save the result per moving
    Drag.save();
  },

  getInfo:function(o){//get the coordinate
    var to=new Object();
    to.left=to.right=to.top=to.bottom=0;
    var twidth=o.offsetWidth;
    var theight=o.offsetHeight;
    while(o!=document.body){
      to.left+=o.offsetLeft;
      to.top+=o.offsetTop;
      o=o.offsetParent;
    }
    to.right=to.left+twidth;
    to.bottom=to.top+theight;
    return to;
  },

  gtbos:function(tdo){
    var tbls = new Array();
    var subTables=tdo.getElementsByTagName("table");
    for(var j=0;j<subTables.length;j++){
      if(typeof(subTables[j].dragBlock)!="undefined")tbls.push(subTables[j]);
    }
    return tbls;
  },

  repos:function(aa,ab){
    var f=Drag.divo.filters.alpha.opacity;
    var tl=parseInt(Drag.getInfo(Drag.divo).left);
    var tt=parseInt(Drag.getInfo(Drag.divo).top);
    var kl=(tl-Drag.getInfo(Drag.trdo).left)/ab;
    var kt=(tt-Drag.getInfo(Drag.trdo).top)/ab;
    var kf=f/ab;
    return setInterval(function(){
      if(ab<1){
        clearInterval(Drag.mm);
        Drag.divo.removeNode(true);
        Drag.trdo=null;
        return;
      }
      ab--;
      tl-=kl;
      tt-=kt;
      f-=kf;
      Drag.divo.style.left=parseInt(tl)+"px";
      Drag.divo.style.top=parseInt(tt)+"px";
      Drag.divo.filters.alpha.opacity=f;
    },aa/ab)
  },

  getPosition:function(){
    var side,positions="";
    for(var i=0;i<parentTable.cells.length;i++){
      if(parentTable.cells[i].dragContainer!="true")continue;
      if(parentTable.cells[i].id=="leftPortalPanelID")side="1";
      else if(parentTable.cells[i].id=="rightPortalPanelID")side="2";
      else if(parentTable.cells[i].id=="middlePortalPanelID")side="3";
      var subTables=Drag.gtbos(parentTable.cells[i]);
      for(var j=0;j<subTables.length;j++){
        positions += ((positions==""?"":";")+subTables[j].dragBlock+","+side+","+(j+1)+","+(subTables[j].blockVisible=="true"?"1":"0"));
      }
    }
    return positions;
  },

  save:function(){
    var positions = Drag.getPosition();
    var data = "fwcid=layout&feature=layout&action=saveLayout";
    data += "&layoutType="+Drag.portal+"&layoutObject="+Drag.website+"&mend="+positions;
    XMLHttpObj.sendSyncRequest("POST","?",data);
  },

  inint:function(){
    document.onmousemove=Drag.draging;
    document.onmouseup=Drag.dragEnd;
  }
//end of Object Drag
}

/**
 * for ajax
 */
function cwCreateXMLHTTPRequest(){
    return new ActiveXObject("MSXML2.XMLHTTP.3.0");
}

var XMLHttpObj = {
    _objPool: [],
    _getInstance: function (){
        //for (var i = 0; i < this._objPool.length; i ++){
        //    if (this._objPool[i].readyState == 0 || this._objPool[i].readyState == 4){
        //        return this._objPool[i];
        //    }
        //}
        //this._objPool[this._objPool.length] = this._createObj();
        //return this._objPool[this._objPool.length - 1];
        return this._createObj();
    },

    _createObj: function (){
        if (window.XMLHttpRequest){ //Mozilla
            var objXMLHttp = new XMLHttpRequest();
        }else{                      //IE
            var MSXML = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
            for(var n = 0; n < MSXML.length; n ++){
                try{
                    var objXMLHttp = new ActiveXObject(MSXML[n]);
                    break;
                }
                catch(e){
                }
            }
         }

        if (objXMLHttp.readyState == null){
            objXMLHttp.readyState = 0;

            objXMLHttp.addEventListener("load", function (){
                    objXMLHttp.readyState = 4;
                    if (typeof objXMLHttp.onreadystatechange == "function"){
                        objXMLHttp.onreadystatechange();
                    }
                },  false);
        }
        return objXMLHttp;
    },

    sendAsyncRequest: function (method, url, callback ,parameter, data){
       this._sendRequest(method, url, true,callback ,parameter, data);
    },

    sendSyncRequest: function (method, url, data){
       return this._sendRequest(method, url, false, "", "", data);
    },

    _sendRequest: function (method, url, async, callback, parameter, data){
        var objXMLHttp = this._getInstance();
        with(objXMLHttp){
            try{//no cache
                if (url.indexOf("?") > -1){
                    url += "&randnum=" + Math.random();
                }else{
                    url += "?randnum=" + Math.random();
                }

                open(method, url, async);

                //set charset
                setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');

                if (typeof(data)!="undefined" && data!=""){
                  send(data);
                }else{
                  send();
                }

                if (typeof(callback)!="undefined" && callback!=""){
                  onreadystatechange = function (){
                      if (objXMLHttp.readyState == 4 && (objXMLHttp.status == 200 || objXMLHttp.status == 304)){
                          callback(objXMLHttp,parameter);
                      }
                  }
                }else{
                 return objXMLHttp;
                }
            }
            catch(e){
            }
        }
    }
};


/**
 * tree.js
 */

function createXMLDOM(){
  var xmlDocs = ["MSXML2.DOMDocument.6.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];

  for (var i = 0; i < xmlDocs.length; i++) {

    try {

      var xmlDoc = new ActiveXObject(xmlDocs[i]);

      xmlDoc.async = false;

      return xmlDoc;

    } catch (oError){}

  }

  throw new Error("MSXML is not installed.");

}
function loadXMLText(xmlText){
  var xmlDoc = createXMLDOM();
  xmlDoc.loadXML(xmlText);
  return xmlDoc;
}
function loadXMLFile(xmlFile){
  var xmlDoc = createXMLDOM();
  xmlDoc.load(xmlFile);
  return xmlDoc;
}
function transformXML(xmlText,xslFile){
  var xmlDoc = loadXMLText(xmlText);
  var xslDoc = loadXMLFile(xslFile);
  return xmlDoc.documentElement.transformNode(xslDoc);
}

function clickOnEntity(entity){
  var fontx = document.getElementsByName('fontx');
  for(i=0; i < fontx.length; i++){
    fontx(i).style.color="black";
    fontx(i).style.background="white";
  }
  oFont = entity.childNodes(0).all["fontx"];
  if("undefined"!=typeof(oFont) && oFont!=null){
    oFont.style.color="white";
    oFont.style.background="navy";
  }

  if(entity.opened=="false")expand(entity);
  else collapse(entity);
}

function expand(entity){
  var oImage = entity.childNodes(0).all["opcol"];
  if("undefined"!=typeof(oImage)) oImage.src = entity.openedPict;
  oImage = entity.childNodes(0).all["image"];
  if("undefined"!=typeof(oImage)) oImage.src = entity.openedIcon;

  for(i=0; i < entity.childNodes.length; i++){
    if(entity.childNodes(i).tagName.toUpperCase() == "DIV"){
      entity.childNodes(i).style.display = "block";
    }
  }
  entity.opened = "true";
}

function collapse(entity){
  var oImage = entity.childNodes(0).all["opcol"];
  if("undefined"!=typeof(oImage)) oImage.src = entity.closedPict;
  oImage = entity.childNodes(0).all["image"];
  if("undefined"!=typeof(oImage)) oImage.src = entity.closedIcon;

  for(var i=0; i < entity.childNodes.length; i++){
    if(entity.childNodes(i).tagName.toUpperCase() == "DIV"){
      entity.childNodes(i).style.display = "none";
      collapse(entity.childNodes(i));
    }
  }
  entity.opened = "false";
}

function expandAll(entity){
  expand(entity);
  for(var i=0; i < entity.childNodes.length; i++){
    if(entity.childNodes(i).tagName.toUpperCase() == "DIV"){
      expandAll(entity.childNodes(i));
    }
  }
}

function cwAttachStringToTable(htmltext,oTable,index){
  /**
  ** @param htmltext is tr/td, like <tr><td>text</td></tr>;
  ** @oTable which will be attached with tr string
  ** @index insert position
  **/
  var oDiv = document.createElement("DIV");
  htmltext = htmltext.replace(/(^\s*)|(\s*$)/g, "");
  if(htmltext.indexOf("<table")!=0 && htmltext.indexOf("<TABLE")!=0) {
    oDiv.innerHTML="<TABLE>"+htmltext+"</TABLE>";
  } else {
    oDiv.innerHTML=htmltext;
  }

  //var oTRs = oDiv.getElementsByTagName("tr");
  var oTRs = oDiv.childNodes[0].childNodes[0].childNodes;
  for(var i=0; i<oTRs.length; i++){
    var oTR=oTRs[i];
    myNewRow = oTable.insertRow(index+i);
    //mergeAttributes(oTR,myNewRow);
    myNewRow.mergeAttributes(oTR,false);
    for(var j=0;j<oTR.childNodes.length;j++){
      oTD = oTR.childNodes[j];
      myNewCell = myNewRow.insertCell();
      //mergeAttributes(oTD,myNewCell);
      myNewCell.mergeAttributes(oTD);
      myNewCell.innerHTML=oTD.innerHTML;
    }
  }
}
//add by liuwei at 2007-02-01
function mergeAttributes(oSource,oTarget){
var oAttribs =oSource.attributes;
    for(var i=0;i<oAttribs.length;i++){
       var oAttrib=oAttribs[i];
       if (oAttrib.specified){
        oTarget.setAttribute(oAttrib.nodeName,oAttrib.nodeValue);
       }
    }
}

function cwGetAncestorByTagName(o,tagName){
  var found=false;
  var parent = o.parentElement;
  while(parent!=null && !found){
    if(parent.tagName.toLowerCase()==tagName.toLowerCase()){
      found=true;
      return parent;
    }
    parent = parent.parentElement;
  }
  return null;
}

function cwContainsOnSpecifiedArray(oArray, oElement){
  for(var i=0; i<oArray.length; i++){if(oArray[i]==oElement)return i;}
  return -1;
}

function cwOpenOrCloseChildNode(oTable,oTr,display){
  if(typeof(oTr.name)=="undefined" || typeof(oTr.opened)=="undefined"){
    return;
  }
  var trArray = new Array(oTr);
  var idArray = new Array(oTr.name);
  var openedArray = new Array(oTr.opened);
  var render = (display==true?"":"none");
  for(var i=oTr.rowIndex+1; i<oTable.rows.length; i++){
    var rowTr = oTable.rows(i);
    if(typeof(rowTr.parent)!="undefined"){
      var number=cwContainsOnSpecifiedArray(idArray,rowTr.parent);
      if(number != -1){
        if(typeof(rowTr.name)!="undefined" && typeof(rowTr.opened)!="undefined"){
          trArray.push(rowTr);
          idArray.push(rowTr.name);
          openedArray.push(rowTr.opened);
        }
        if(display==true){render=(openedArray[number]=="true" && trArray[number].style.display==""?"":"none");}
        rowTr.style.display=render;
      }else{
        break;
      }
    }else{
      break;
    }
  }
}

function getTreeTagPlusParameter(oTable){
  var oDivArray = oTable.parentElement.getElementsByTagName("DIV");
  for(var i=0;i<oDivArray.length;i++){
    if(oDivArray[i].id.toLowerCase()=="value"){
      return oDivArray[i].innerText;
    }
  }
  return "";
}

function cwAddDeferForScriptElement(html){
  var re = new RegExp("<script[ ]*","gi") ;
  return html.replace(re, "<script DEFER=\"true\" ");
}

function cwClickThisTreeNode(oImg,key,fwcid,feature,pid){
  beginProgress("",false,false);
  var oTable = cwGetAncestorByTagName(oImg,"TABLE");
  var curTr = cwGetAncestorByTagName(oImg,"TR");
    var url = "?fwcid="+fwcid+"&feature="+feature+"&key="+key+"&action=";
  if(curTr.opened=="true"){
    curTr.opened="false";
    if(typeof(oImg.closeIcon)!="undefined" && oImg.src!=oImg.closeIcon){oImg.src=oImg.closeIcon;}
    cwOpenOrCloseChildNode(oTable,curTr,false);//alert(url+"close");
    XMLHttpObj.sendAsyncRequest("GET",url+"close");
    endProgress();
  }else{
    curTr.opened="true";
    if(typeof(oImg.openIcon)!="undefined" && oImg.src!=oImg.openIcon){oImg.src=oImg.openIcon;}
    if(curTr.loaded=="true"){
      cwOpenOrCloseChildNode(oTable,curTr,true);//alert(url+"open");
      XMLHttpObj.sendAsyncRequest("GET",url+"open");
      endProgress();
    }else{
      url+="fetchSubtree&value="+getTreeTagPlusParameter(oTable);//alert(url);
      XMLHttpObj.sendAsyncRequest("GET",url,cwOpenCurrentTreeNodeCallback,new Array(oTable,curTr.rowIndex));
    }
  }
}

function cwOpenCurrentTreeNodeCallback(xmlHTTP,params){
  //alert(xmlHTTP.responseText);
  //document.write(xmlHTTP.responseText);
  params[0].deleteRow(params[1]);
  cwAttachStringToTable(xmlHTTP.responseText,params[0],params[1]);
  endProgress();
}

function cwSelectPopupMenu(o, key, url, pid) {
  beginProgress("",false,false);
  var oDiv = cwGetAncestorByTagName(o, "DIV");
  var oTable = cwGetAncestorByTagName(oDiv,"TABLE");
  url+="&key=" + key;
  url+="&value="+getTreeTagPlusParameter(oTable);
  XMLHttpObj.sendAsyncRequest("GET",url,cwRefreshWholeTreeNodeCallback,new Array(oTable));
}

function cwSelectPopupMenu2(o, key, url, pid) {
  var randomParam = "&dddatetttime="+new Date().getTime();
  document.location.href=url+"&key="+key+randomParam;
}

function cwChangeQuestionOrder(oldIndex, newIndex) {
  var baseURL = "?fwcid=test&feature=test&action=moveQuestion";
  baseURL += "&value=test&nodeIndex=" + oldIndex + "&nodeNewIndex=" + newIndex;
  XMLHttpObj.sendAsyncRequest("GET",baseURL);
}

function cwEditTreeNodeTitle(oInputBox,oElement, params) {
  if (oInputBox.value==''){
    return false;
  }
  beginProgress("",false,false);
  var newTitle = oInputBox.value;
  var url = params[0];
  var treeName = params[1];
  var oTable = document.getElementById(treeName);
  url+="&title="+encodeURIComponent(newTitle);
  url+="&value="+getTreeTagPlusParameter(oTable);  
  XMLHttpObj.sendAsyncRequest("GET",url,cwRefreshWholeTreeNodeCallback,new Array(oTable));

  var titleBar = document.all.treeNodeTitleInBar;
  if(titleBar!=null) {
    titleBar.innerText = newTitle;
  }
}

function cwSelectThisTreeNode(o,key,fwcid,feature,action,pid,msg){
  beginProgress("",false,false);
  var oTable = cwGetAncestorByTagName(o,"TABLE");
  var curTr = cwGetAncestorByTagName(o,"TR");
  var randomParam = "&dddatetttime="+new Date().getTime();
  var baseURL = "?fwcid="+fwcid+"&feature="+feature+"&action="+action+"&key="+key;
  if(fwcid=="contents" && typeof(msg)!="undefined"){
  baseURL = baseURL + "&classKey="+msg;
  }
  var url = baseURL+"&target=part";//alert(url);
  if(action.toUpperCase()=='OPENALL' || action.toUpperCase()=='CLOSEALL'){
    url+="&value="+getTreeTagPlusParameter(oTable);//alert(url);
    XMLHttpObj.sendAsyncRequest("GET",url,cwRefreshWholeTreeNodeCallback,new Array(oTable));
  }else if(action.toUpperCase()=='SELECT'){
    document.location.href=baseURL+randomParam;
    /*alert(cwNeedToRefreshSpecifiedFrameUI(feature));
    if(cwNeedToRefreshSpecifiedFrameUI(feature)){
      document.location.href=baseURL+randomParam;
    }else{
      cwSaveBookmarkURLOnAJAXSelect(baseURL);
      url = url + "&parentReferer="+encodeURIComponent(location);
      XMLHttpObj.sendAsyncRequest("GET",url,cwSelectThisTreeNodeCallback,new Array(oTable,curTr,key,fwcid,feature,pid));
    }//commented by dony on 2008-8-10 */
  }else if(action.toUpperCase()=='DEL'){
    if(confirm(msg)){
      XMLHttpObj.sendAsyncRequest("GET",url,cwDelCurrentTreeNodeCallback,new Array(oTable,fwcid,feature,action));
    }else{
      endProgress();
    }
  }else if (fwcid.toUpperCase()=='COURSE' && feature.toUpperCase()=='COURSE' && action.toUpperCase()=='MOVE'){
    document.location.href = "?fwcid="+fwcid+"&feature="+feature+"&action=move&key="+key+randomParam;
  }else{
    XMLHttpObj.sendAsyncRequest("GET",url,cwEditCurrentTreeNodeCallback,new Array(oTable,fwcid,feature,action,key));
  }
}

function cwNeedToRefreshSpecifiedFrameUI(feature){
  if(location.pathname.lastIndexOf("/recorder/courseView.do")>-1){
    var rightBar = document.all.rightPortaldisplayBarID;
    if((typeof(rightBar)=="undefined" && (feature=="lobject" || feature=="course"))
       ||(typeof(rightBar)!="undefined" && feature!="lobject" && feature!="course")){
      return true;
    }
  }
  return false;
}

function cwRefreshRecordContextTreeUI(feature){
  if(location.pathname.lastIndexOf("/recorder/courseView.do")>-1){
    if(feature=="lobject" || feature=="course"){
      var url = "?fwcid=contextContent&feature=contextNode&action=refresh";
      XMLHttpObj.sendAsyncRequest("GET",url,cwRefreshRecordContextTreeUICallback,new Array());
    }
  }
}

function cwRefreshRecordContextTreeUICallback(xmlHTTP,params){
  cwFillinTheTDinnerHTML(xmlHTTP.responseText,document.all.rightPortalPanelID);
}

function cwSaveBookmarkURLOnAJAXSelect(suffix){
  if(typeof(document.all.bookmarkURLInputHiddenID)!="undefined"){
    var url = location.protocol+"//"+location.host+location.pathname;
    document.all.bookmarkURLInputHiddenID.value=url+suffix;
    //alert(document.all.bookmarkURLInputHiddenID.value);
  }
}
function cwRefreshWholeTreeNode(params){
  var rootName = params[0].rows(0).name;
  if(rootName!=null && rootName!="" && typeof(rootName)!="undefined" && rootName.indexOf("treeFolderTr_")==0){
    var rootKey = rootName.substr("treeFolderTr_".length, rootName.length-1);
    var url = "?fwcid="+params[1]+"&feature="+params[2]+"&action=fetchSubtree";
    url+="&value="+getTreeTagPlusParameter(params[0])+"&key="+rootKey;
    XMLHttpObj.sendAsyncRequest("GET",url,cwRefreshWholeTreeNodeCallback,new Array(params[0]));
  }
}

function cwRefreshWholeTreeNodeCallback(xmlHTTP,params){
  while(params[0].rows.length>1)params[0].deleteRow(params[0].rows.length-2);
  cwAttachStringToTable(xmlHTTP.responseText,params[0],0);
  endProgress();
}

function cwSelectThisTreeNodeCallback(xmlHTTP,params){
  cwFillinTheTDinnerHTML(xmlHTTP.responseText);
  if(params[0].selected != params[2]){
  params[0].selected=params[2];
  cwHighLightSelectOptionCard();
  cwRefreshWholeTreeNode(new Array(params[0],params[3],params[4]));
  cwRefreshRecordContextTreeUI(params[4]);
  }
  location.href="#_topofthispage9887";// return page top.
  endProgress();
}
function cwFillinFetchHotResourceTD(xmlHTTP,params){
  cwFillinTheTDinnerHTML(xmlHTTP.responseText,document.all.fetchHotResourceTD);
}

function cwSelectCurrentTreeNodeCallback(xmlHTTP,params){//disable on 2007-8-22 by dony, replace with cwSelectThisTreeNodeCallback
  var fetchURL = "?fwcid="+params[3]+"&feature="+params[4]+"&action=fetchSubtree";
  fetchURL+="&range=self&value="+getTreeTagPlusParameter(params[0])+"&key=";
  if(typeof(params[0].selected)!="undefined" && params[0].selected!="" && params[0].selected!="null"){
    var oImage = document.getElementById("treeFolderImg_"+params[0].selected);
    var oldSelectedTr = cwGetAncestorByTagName(oImage,"TR");
    var url = fetchURL+params[0].selected; //alert(url);
    XMLHttpObj.sendAsyncRequest("GET",url,cwOpenCurrentTreeNodeCallback,new Array(params[0],oldSelectedTr.rowIndex));
  }
  if(params[1].opened=="false"){//2. if the tr is not been opened, open it and select it.
    var oImage = document.getElementById("treeFolderImg_"+params[2]);
    cwClickThisTreeNode(oImage,params[2],params[3],params[4],params[5]);
  }else{//3. if the tr is opened, then selected it.
    var url = fetchURL+params[2];//alert(url);
    XMLHttpObj.sendAsyncRequest("GET",url,cwOpenCurrentTreeNodeCallback,new Array(params[0],params[1].rowIndex));
  }
  params[0].selected=params[2];
  cwRefreshRecordContextTreeUI(params[4]);
  cwFillinTheTDinnerHTML(xmlHTTP.responseText);
  endProgress();
}

function cwFillinTheTDinnerHTML(html,oTarget){
  if(oTarget==null || oTarget=="" || typeof(oTarget)=="undefined"){
    oTarget=document.all.middlePortalPanelBodyID;
  }

  if(oTarget!=null && oTarget!="" && typeof(oTarget)!="undefined"){
    //fix bug-4717 by dony on 2007-8-29,re-fix on 2007-10-10
    var ifms = oTarget.getElementsByTagName("IFRAME");
    for(var i=0;i<ifms.length;i++){
      var objects = ifms[i].Document.body.getElementsByTagName("OBJECT");
      var tempObjects = new Array(objects.length);
      for(var k=0;k<objects.length;k++){tempObjects[k]=objects[k];}
      for(var k=0;k<tempObjects.length;k++){
        try{
         tempObjects[k].parentElement.removeChild(tempObjects[k]);
        }catch(e){}
      }
      ifms[i].removeAttribute("src",0);
    }//fix bug-4717 by dony on 2007-8-29,re-fix on 2007-10-10

    oTarget.innerHTML="";
    oTarget.innerHTML=cwAddDeferForScriptElement(html);

    /* do not remove the following comments, by dony on 2007-10-10
    var scripts = oTarget.getElementsByTagName("script");
    var tempScripts = new Array(scripts.length);
    for(var i=0;i<scripts.length;i++){tempScripts[i]=scripts[i];}
    for(var i=0;i<tempScripts.length;i++){
      tempScripts[i].parentElement.removeChild(tempScripts[i]);
      oTarget.appendChild(tempScripts[i]);
    }*/
  }else{
    document.write(html);
  }
}

function cwSelectThisLinkBar(url){
  beginProgress("",false,false);
  XMLHttpObj.sendAsyncRequest("GET",url,fillMiddleContentArea);
}
function fillMiddleContentArea(xmlHTTP){
  cwFillinTheTDinnerHTML(xmlHTTP.responseText);
  endProgress();
}

function cwEditCurrentTreeNodeCallback(xmlHTTP,params){//oTable,fwcid,feature
  cwFillinTheTDinnerHTML(xmlHTTP.responseText);
  if(params[3]=="move"){
    cwEditCurrentTreeNodeApply();
  }else{
    cwGlobalObject.table=params[0];
    cwGlobalObject.fwcid=params[1];
    cwGlobalObject.feature=params[2];
  }
  endProgress();
}
function cwEditCurrentTreeNodeApply(){
  cwRefreshWholeTreeNode(new Array(cwGlobalObject.table,cwGlobalObject.fwcid,cwGlobalObject.feature));
}
function cwDelCurrentTreeNodeCallback(xmlHTTP,params){//oTable,fwcid,feature,action
  cwFillinTheTDinnerHTML(xmlHTTP.responseText);
  if(params[3]=="del"){
    cwDelCurrentTreeNodeApply(params);
  }
  endProgress();
}
function cwDelCurrentTreeNodeApply(params){//oTable,fwcid,feature,action
  var table=params[0];
  var fwcid=params[1];
  var feature=params[2];
  var rootName = table.rows(0).name;
  if(rootName!=null && rootName!="" && typeof(rootName)!="undefined" && rootName.indexOf("treeFolderTr_")==0){
    var rootKey = rootName.substr("treeFolderTr_".length, rootName.length-1);
    var url = "?fwcid="+fwcid+"&feature="+feature+"&action=fetchSubtree";
    url+="&value="+getTreeTagPlusParameter(table)+"&key="+rootKey;//alert("url="+url);
    XMLHttpObj.sendAsyncRequest("GET",url,cwRefreshWholeTreeNodeCallback,new Array(table));
    cwSelectThisTreeNode(table.rows(0),rootKey,"testContents","test","select",0);
  }
}
function cwMoveCheckCurrentTreeNodeCallback(xmlHTTP,params){//oTable,fwcid,feature,action,key,msg
  var table=params[0];
  var fwcid=params[1];
  var feature=params[2];
  var action=params[3];
  var key=params[4];
  var msg=params[5];
  var randomParam = "&dddatetttime="+new Date().getTime();
  var url="?fwcid="+fwcid+"&feature="+feature+"&action="+action+"&key="+key+randomParam;
  var result=xmlHTTP.responseText;
  if (result=='success'){
    document.location.href=url;
  }else if (result==''){ //invalidConstrainedMove
    if(confirm(msg)){
      document.location.href=url;
    }else{
      endProgress();
    }
  }else{ //runtime exception
    alert("runtime exception");
    endProgress();
  }
}

function cwBackgroundSubmitWithoutIframe(url,theForm,refreshTree,fillinTarget){
  var data = Form.serialize(theForm);
  XMLHttpObj.sendAsyncRequest("POST",url,cwFillInContent,new Array(refreshTree,fillinTarget),data);
}
function cwFillInContent(xmlHTTP,params){
  var refreshTree = params[0];
  var fillinTarget = params[1];
  var oTarget;
  if(typeof(fillinTarget)!="undefined" && fillinTarget !=""){
    oTarget = document.getElementById(fillinTarget);
  }
  cwFillinTheTDinnerHTML(xmlHTTP.responseText,oTarget);
  if(typeof(refreshTree)!="undefined" && refreshTree){cwEditCurrentTreeNodeApply();}
}

function cwBackgroundSubmitWithIframe(theForm,refreshTree,fillinTarget){
  var oIFrame = document.getElementById("backgroundSubmittedIFrameID");
  if(oIFrame==null || oIFrame=="" || typeof(oIFrame)=="undefined"){
    theForm.target="_self";
  }else{
    oIFrame.loaded="true";
    if(typeof(refreshTree)!="undefined" && refreshTree){oIFrame.apply="true";}
    if(typeof(fillinTarget)!="undefined"){oIFrame.fillinTarget=fillinTarget;}
    theForm.target=oIFrame.name;
  }
  theForm.submit();
}
function cwLoadContentByIframe(theIFrame){
  if(theIFrame.loaded=='true'){
    theIFrame.loaded='false';
    if("undefined"!=typeof(theIFrame.contentWindow.document.all.middlePortalPanelBodyID)){
      window.location=theIFrame.contentWindow.location;
    }else{
     if(theIFrame.fillinTarget != ""){
       cwFillinTheTDinnerHTML(theIFrame.contentWindow.document.body.innerHTML,document.getElementById(theIFrame.fillinTarget));
     } else {
      cwFillinTheTDinnerHTML(theIFrame.contentWindow.document.body.innerHTML);
     }
     if(typeof(theIFrame.apply)!="undefined" && theIFrame.apply=="true"){cwEditCurrentTreeNodeApply();}
    }
    endProgress();
  }
}

function cwMeasureLength(string){
  var length=0;
  for(var i=0;i<string.length;i++){
    var code = string.charCodeAt(i);
    length += (code*1<256?1:2);
  }
  return length;
}
function cwGetFunctionName(func){
  var string = func.toString();
  //var start = string.indexOf("function")+"function".length;alert(start);
  var end = string.indexOf("(");
  string = string.substring(8,end);
  string = string.replace(new RegExp(" ", "gi"), "");
  string = string.replace(new RegExp("\\r", "gi"), "");
  string = string.replace(new RegExp("\\n", "gi"), "");
  return string;
}

/****
@param oElement is a xhtml object, it contains the text string;
@param size is a integer number, it is the input box's size, if (-1) unlimited;
@param maxlength is a integer number, it is the input box's maxlength, if (-1) unlimited;
@param callback is a function object, it is callback function;
@param args is a array object, it can contains string data only;
****/
function cwText2InputBox(oElement,size,maxlength,callback,args){
  if(oElement.hasChildNodes()
    && oElement.childNodes.length>0
    && typeof(oElement.childNodes[0].tagName)!="undefined"
    && oElement.childNodes[0].tagName.toUpperCase()=="INPUT"){
    return;
  }
  var oldText = oElement.innerHTML;
  oElement.original = oldText;
  var randomx=(Math.round(Math.random()*9999999999));
  if(oElement.id=="")oElement.id="CloverWorxs"+randomx;
  var inputBox = '<input type="text"';
  inputBox += ' id="DascomApp'+randomx+'"';
  inputBox += ' class="border" style="cursor:text;"';
  if(size<=0){
    inputBox += ' size="'+(cwMeasureLength(oldText)*1+1)+'"';
    inputBox += ' onkeydown="this.size=cwMeasureLength(this.value)+1;';
    inputBox += ' if(event.keyCode==13){this.blur();}"';
  }else{
    inputBox += ' size="'+((cwMeasureLength(oldText)*1+1)>size?size:cwMeasureLength(oldText)*1+1)+'"';
    inputBox += ' onkeydown="if(this.size<'+size+')this.size=cwMeasureLength(this.value)+1;';
    inputBox += ' if(event.keyCode==13){this.blur();}"';
  }
  inputBox += ' onblur="javascript:cwSaveThisInputDataIfFinish(this,\''+oElement.id+'\',\''+cwGetFunctionName(callback)+'\'';
  if(typeof(args)!="undefined"){
    var values = "";
    for(var k=0;k<args.length;k++){
      var value = args[k];
      value = value.replace(new RegExp("%", "gi"), "25%");
      value = value.replace(new RegExp("'", "gi"), "39%");
      value = value.replace(new RegExp('"', "gi"), "34%");
      value = value.replace(new RegExp("#", "gi"), "23%");
      values += value+"#";
    }
    inputBox += ',\''+(values.length>0?values.substr(0,values.length-1):values)+'\'';
  }
  inputBox += ' );"';
  inputBox += ' value="'+oldText+'"';
  if(maxlength>0)inputBox += ' maxlength="'+maxlength+'"';
  inputBox += '>';
  oElement.innerHTML="";
  oElement.innerHTML=inputBox;
  var oInputBox = document.getElementById("DascomApp"+randomx);
  if(oInputBox!=null){
    oInputBox.attachEvent ("onclick",cwCancelBubble);
    oInputBox.select();oInputBox.focus();
  }
}
function cwCancelBubble(){
  window.event.cancelBubble = true;
}
function cwSaveThisInputDataIfFinish(oInputBox,oElementID,callbackFunc,arrayString){
  var oElement = document.getElementById(oElementID);
  if(oElement==null)return;
  if(oElement.original!=oInputBox.value){
    oInputBox.value =cwTrimWhiteSpace(oInputBox.value);
    var callback = eval(callbackFunc);
    if(typeof(callback)=="function"){
      var result = false;
      if(typeof(arrayString)=="undefined"){
        result = callback(oInputBox,oElement);
      }else{
        var args = new Array();
        if(arrayString.length>0){
          args = arrayString.split("#");
          for(var k=0;k<args.length;k++){
            var value = args[k];
            value = value.replace(new RegExp("23%", "gi"), "#");
            value = value.replace(new RegExp("34%", "gi"), '"');
            value = value.replace(new RegExp("39%", "gi"), "'");
            value = value.replace(new RegExp("25%", "gi"), "%");
            args[k] = value;
          }
        }
        result = callback(oInputBox,oElement,args);
      }
      if(result==false){
        oInputBox.select();oInputBox.focus();
        return;
      }
    }
  }
  oElement.innerHTML = "";
  oElement.innerHTML = oInputBox.value;
}

/****
highlight tr for the specified table when mouse move on it.
@param oTable the specified table object;
@index from the 'index' row;
@hltClassName highlight style-class name;
****/
function cwHighlightForMouseMove(oTable,index,hltClassName){
  if(typeof(hltClassName)=="undefined"){
    hltClassName = "listHlt";
  }
  for(var i=index; i<oTable.rows.length; i++){
    var rowTr = oTable.rows(i);
    if(typeof(rowTr.onmouseover)!="function"){
      rowTr.originalClassName=rowTr.className;
      rowTr.onmouseover = function(){
        //this.style.backgroundColor = "red";
        this.className=hltClassName
      }
      rowTr.onmouseout = function(){
        //this.style.backgroundColor = "";
        this.className=this.originalClassName;
      }
    }
  }
}

/****
select option card common function
@function beforeThisOptionCard(OCKey) call it before select;
@function afterThisOptionCard(OCKey) call it after select;
****/
function G(objId){
  return document.getElementById(objId);
}
function cwSelectThisOptionCard(OCKey,selectedIndex){
  var result=true;
  // 1. before call
  if(typeof(beforeThisOptionCard)=="function"){
    result=beforeThisOptionCard(OCKey);
  }
  // 2. handle it
  if(result){
    var tr_optionCardLine = G("SSTabOptionCardLine1");
    if(tr_optionCardLine!=null && tr_optionCardLine.hasChildNodes() && tr_optionCardLine.childNodes.length>0){
      var endCardIndex = tr_optionCardLine.childNodes.length-1;
      for(var i=0;i<=endCardIndex;i++){
        var td_optionCard = tr_optionCardLine.childNodes[i];
        var span_optionCard = td_optionCard.childNodes[0];
        if(i==selectedIndex){
          if(i==endCardIndex){
            td_optionCard.className="tab_5";
          }else{
            td_optionCard.className="tab_1";
          }
          span_optionCard.className="tab_alt";
        }else{
          if(i==endCardIndex){
            td_optionCard.className="tab_4";
          }else if(i+1==selectedIndex){
            td_optionCard.className="tab_3";
          }else{
            td_optionCard.className="tab_2";
          }
          span_optionCard.className="tab";
        }
      }
    }
    // 3. after call
    if(typeof(afterThisOptionCard)=="function"){
      result=afterThisOptionCard(OCKey);
    }
  }
}
function cwDisplayHiddenBackOptionCard(){
  var tr_optionCardLine = G("SSTabOptionCardLine1");
  if(tr_optionCardLine!=null && tr_optionCardLine.hasChildNodes() && tr_optionCardLine.childNodes.length>0
    && document.all.SSTabSubDiv1.offsetWidth>document.all.SSTabMainDiv1.offsetWidth){
    for(var i=0;i<tr_optionCardLine.childNodes.length;i++){
      var td_optionCard = tr_optionCardLine.childNodes[i];
      if(td_optionCard.style.display==""){
        td_optionCard.style.display="none";
        break;
      }
    }
  }
}
function cwDisplayHiddenFrontOptionCard(){
  var tr_optionCardLine = G("SSTabOptionCardLine1");
  if(tr_optionCardLine!=null && tr_optionCardLine.hasChildNodes() && tr_optionCardLine.childNodes.length>0
    && tr_optionCardLine.childNodes[0].style.display=="none"){
    for(var i=tr_optionCardLine.childNodes.length-1;i>=0;i--){
      var td_optionCard = tr_optionCardLine.childNodes[i];
      if(td_optionCard.style.display=="none"){
        td_optionCard.style.display="";
        break;
      }
    }
  }
}
function cwHighLightSelectOptionCard(){
  var tr_optionCardLine = G("SSTabOptionCardLine1");
  if(tr_optionCardLine!=null && tr_optionCardLine.hasChildNodes() && tr_optionCardLine.childNodes.length>0
    && document.all.SSTabSubDiv1.offsetWidth>document.all.SSTabMainDiv1.offsetWidth){
    var td_optionCard_selected=null;
    for(var i=0;i<tr_optionCardLine.childNodes.length;i++){
      var td_optionCard = tr_optionCardLine.childNodes[i];
      if(td_optionCard.selected=="true"){
        td_optionCard_selected=td_optionCard;
        break;
      }
    }
    if(td_optionCard_selected!=null){
      var offsetRight=td_optionCard_selected.offsetLeft+td_optionCard_selected.offsetWidth;
      //alert(offsetRight);alert(document.all.SSTabMainDiv1.offsetWidth);
      for(var i=0;i<tr_optionCardLine.childNodes.length && offsetRight>document.all.SSTabMainDiv1.offsetWidth;i++){
        var td_optionCard = tr_optionCardLine.childNodes[i];
        if(td_optionCard.selected=="true"){
          td_optionCard_selected=td_optionCard;
          break;
        }
        td_optionCard.style.display="none";
        offsetRight=td_optionCard_selected.offsetLeft+td_optionCard_selected.offsetWidth;
      }
    }
  }
}
function cwSetCookie(sName, sValue){
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + ";"
}
function cwGetCookie(sName){
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++){
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return unescape(aCrumb[1]);
  }
  return null;
}

/****
replace link for some specified situation.
@function perviewPortalWithoutLinks(vStyleFile) for iframe disable link;
@function tempAddDatetimeParameterForLinks() for ajax link add random number;
****/
function perviewPortalWithoutLinks(vStyleFile){
  var vStyleText = vStyleFile.substr(0, vStyleFile.length-4);
  var re = new RegExp("/skin[0-9]*/", "g");
  var tagArray = new Array("IMG","A");
  for(var n=0;n<tagArray.length;n++){
    var tags = document.body.getElementsByTagName(tagArray[n].toUpperCase());
    for(var i=0;i<tags.length;i++){
      if(tags[i].tagName.toUpperCase()=='A'){
        tags[i].href="?cssFile="+vStyleFile;
      }
      else if(tags[i].tagName.toUpperCase()=='IMG' && vStyleText!=""){
        tags[i].src=tags[i].src.replace(re,"/"+vStyleText+"/");
      }
      else{//TODO
      }
    }
  }
}
function tempAddDatetimeParameterForLinks(){
  var tagArray = new Array("A");
  for(var n=0;n<tagArray.length;n++){
    var tags = document.body.getElementsByTagName(tagArray[n].toUpperCase());
    for(var i=0;i<tags.length;i++){
      if(tags[i].tagName.toUpperCase()=='A'){
        var excess="dddatetttime="+new Date().getTime();
        var href=tags[i].href;
        var text=tags[i].innerHTML;
        if(href.toLowerCase().indexOf("#?")==-1
          && href.toLowerCase().indexOf("javascript")==-1
          && href.toLowerCase().indexOf("dddatetttime=")==-1
          && href.toLowerCase().indexOf("?")!=-1){
          tags[i].href=href+(href.indexOf("?")==-1?"?":"&")+excess;
          tags[i].innerHTML=text
        }
      }
      else{//TODO
      }
    }
  }
}
function cwPrebrowseBlockItem(url){
  var xmlHttpReq = XMLHttpObj.sendSyncRequest("GET",url);
  var result = xmlHttpReq.responseText;
  var results = result.split("|");//alert(results[0]);
  if("_blank"==results[0]){window.open(results[1]);}
  else{window.location.href=results[1];}
}


//============================================
//======          add js code           ======
//======      pagation page method      ======
//======  added by crystal on 2006-8-9  ======
//============================================
function onFirst(id){
    var otable = document.getElementById(id);
    if(otable.isfirst=="true"){
        alert(otable.msg1);
    }
    service(id,3);
    otable.isfirst="true";
    otable.islast="false";
}

function onPrev(id){
    var otable = document.getElementById(id);
    service(id,1);
    otable.isfirst="false";
    otable.islast="false";
}

function onNext(id){
    var otable = document.getElementById(id);
    service(id,2);
    otable.isfirst="false";
    otable.islast="false";
}

function onLast(id){
    var otable = document.getElementById(id);
    if(otable.islast=="true"){
        alert(otable.msg2);
    }
    service(id,4);
    otable.isfirst="false";
    otable.islast="true";
}

function service(id,flag){
    var otable = document.getElementById(id);
    //alert("otable1 curpage == " + otable.curpage);
    var pageRows = otable.pageRows;
    //alert("otable2 pageRows == " + pageRows);
    var len = otable.rows.length;
    var pageCount = Math.ceil(len / pageRows);

    if(flag == 1) otable.curpage -= 1;
    if(flag == 2) otable.curpage += 1;

    if(flag==2){
        if(otable.curpage<=0){
            otable.curpage=1;
        }
        if(otable.curpage>pageCount-1){
            otable.curpage=0;
        }
    }
    if(flag==1){
        if(otable.curpage<0){
            otable.curpage=pageCount-1;
        }
        if(otable.curpage==pageCount){
            otable.curpage=0;
        }
    }
    //alert("otable3 curpage == " + otable.curpage);
    if(otable.curpage == '01'){
        otable.curpage=1;
    }

    if(flag==3){
        otable.curpage=0;
    }

    //alert("pageCount == " + pageCount);
    if(flag==4){
        if(pageCount>0){
            otable.curpage=pageCount-1;
        }else{
            otable.curpage=0;
        }
    }

    for(var i=0; i<len; i++){
        var curTr = otable.rows(i);
        if(i<pageRows*otable.curpage || i>(pageRows*(otable.curpage+1)-1)){
            curTr.style.display="none";
        }else{
            curTr.style.display="";
        }
    }
}

var sMenu1="<DIV class='popupMenuDiv' style='position:absolute;left:0;top:0;width:133;z-index:1;'><TABLE border=0 cellpadding=2 cellspacing=0 class=popupMenuTable style='table-layout:fixed;' width=100% height=100% onmouseout=\"parent.hiddenPopuMenu(event);\">";
var sMenu2="<\/TABLE></DIV>";
function menuHeader(cssFile){
  var styleMenuHeader = "<head><link rel=\"stylesheet\" type=\"text/css\" ";
  styleMenuHeader += "href='" + cssFile + "'/>";
  styleMenuHeader +="</head><body scroll=\"no\" onConTextMenu=\"event.returnValue=false;\" style='margin:0px;border:0px;background:white url() no-repeat top center;'>";
  return styleMenuHeader;
}
function getMenuRow(s_Event, s_Link, s_Html) {
    var s_MenuRow = "";
    s_MenuRow = "<tr class=popupMenuMouseOut onMouseOver=this.className='popupMenuMouseOver'; onMouseOut=this.className='popupMenuMouseOut';><td valign=middle height=20; nowrap style='width:100%; overflow:hidden;text-overflow: ellipsis;'";
    if (s_Event!=""){
        s_MenuRow += " onclick=\"parent."+s_Event+";parent.oPopupMenu.hide();\"";
    } else if (s_Link!=""){
        s_MenuRow += " onclick=\"parent.location.href='"+s_Link+"';parent.oPopupMenu.hide();\"";
    }
    s_MenuRow += ">"
    s_MenuRow += s_Html+"<\/td><\/tr>";

    return s_MenuRow;
}
function showMenuItem(cssFile, menuItem, sMenu, width, height){
    var oPopDocument = oPopupMenu.document;
    var oPopBody = oPopupMenu.document.body;
    oPopDocument.open();
    oPopDocument.write(menuHeader(cssFile) + sMenu);
  oPopDocument.close();
    height+=4;

    var lefter = cwGetOffsetLeft(menuItem)-document.body.scrollLeft;
    var topper = cwGetOffsetTop(menuItem)-document.body.scrollTop + 20;
    if(lefter < 0){
        lefter = 0;
    } else if(lefter+width>document.body.clientWidth){
        lefter = document.body.clientWidth - width;
    }

    oPopupMenu.show(lefter, topper, width, height, document.body);
}

function hiddenMenuItem(menuItem){
  var eventX = window.event.clientX;
    var eventY = window.event.clientY;
  if(eventX == -1 || eventY == -1) return;
  var lefter = cwGetOffsetLeft(menuItem)-document.body.scrollLeft;
    var topper = cwGetOffsetTop(menuItem)-document.body.scrollTop;
    if(eventX<lefter+2 || eventX>lefter+menuItem.scrollWidth || eventY<topper || eventY>topper+20){
    //alert("x:"+eventX + " y:"+eventY +" left:"+lefter +" top:"+topper);
    oPopupMenu.hide();
  }
}

function hiddenPopuMenu(event){
  if(event.clientX == -1 || event.clientY ==-1){
  oPopupMenu.hide();
  }
}

function cwSelectCourseResource(url,key,type,edit,message){
  XMLHttpObj.sendAsyncRequest("GET",url+"&type="+type,cwEnterCourseResource,new Array(key,type,edit,message));
}
function cwEnterCourseResource(xmlHTTP,params){
  var result = xmlHTTP.responseText;
  if(result == "unsuccess"){
    alert(params[3]);
  } else if(result == "success"){
    //var url ="../portal/assetView.do?resourceBankKey=" + resourceKey + "&comeFrom="+params[0]+"&flag="+params[1];
    location.href = "../solver/classView.do?fwcid=classPortal&feature=courseResource&action=list&navKey="+params[0]+"&navType="+params[1];
  } else {
    showModalDialog("../common/errorMessageBox.jsp",result,"dialogWidth:550px; dialogHeight:400px;help:no;scroll:no;status:no");
  }
}

function cwCheckFileExt(filename,filterExt){
  if(cwTrimWhiteSpace(filename) != ""){
    var suffix = filename.substring(filename.lastIndexOf(".") +1).toLowerCase();
    if(suffix != "" && filterExt.toLowerCase().indexOf(suffix)!=-1){
      return true;
    }
  }
  return false;
}

function cwSwithUserRole(portal,selRole,redirectURI){
  var url = "../portal/portalView.do?fwcid=portal&feature=userConfig&action=switchRole&portalId="+portal+"&roleURI="+selRole;
  XMLHttpObj.sendAsyncRequest("GET",url,endSwithUserRole,redirectURI);
}
function endSwithUserRole(xmlHTTP,redirectURI){
  if(redirectURI==null || typeof(redirectURI)=="undefined" || redirectURI=="") {
    reloadWindow();
  } else {
    location.href=redirectURI;
  }
}

function cwCheckBeginAndEndDate(beginDate,endDate,isChceckCurrentDate){

  var _beginDate=beginDate.split("-");
  var d1 = Date.UTC(_beginDate[0]*1, _beginDate[1]*1 - 1, _beginDate[2]*1);

  if(isChceckCurrentDate && new Date(d1)<new Date()){
    return 1;
  }

  var _endDate=endDate.split("-");
  var d2 = Date.UTC(_endDate[0]*1, _endDate[1]*1 - 1, _endDate[2]*1);

  if( d2<d1){
    return 2;
  }

  return 0;
}

function getDatetimeInstance(date,hour,minute){
  var arrays = date.split("-");
  var year = parseInt(arrays[0],10);
  var month = parseInt(arrays[1],10)-1;
  var day = parseInt(arrays[2],10);
  return new Date(year,month,day,parseInt(hour,10),parseInt(minute,10),0);
}

//select option opertion
function cwMoveSelected(oSourceSel,oTargetSel){
  var oTargetSelLength = oTargetSel.options.length;
  for(var i=0; i<oSourceSel.options.length; i++){
   if(oSourceSel.options[i].selected) {
  var existValue = false;
  for(var j=0; j<oTargetSelLength; j++){
    if(oTargetSel.options[j].value==oSourceSel.options[i].value){
    existValue = true;
    break;
    }
  }
  if(!existValue){
    var oOption = document.createElement("OPTION");
    oOption.text = oSourceSel.options[i].text;
      oOption.value = oSourceSel.options[i].value;
    oTargetSel.add(oOption);
  }
   }
  }
}

function cwDeleteSelectItem(oSelect){
 if(oSelect.length<=0) return;
 if(oSelect.selectedIndex >= 0){
   oSelect.remove(oSelect.selectedIndex);
 }
}

function cwSearchPagingOrder(curPage,pageSize,order,refreshPart,callback){
 var qForm = document.searchPageForm;
 if(typeof(curPage)!="undefined" && curPage!=null && curPage!=""){
  qForm.currentPage.value=curPage;
 }
 if(typeof(pageSize)!="undefined" && pageSize!=null && pageSize!=""){
  qForm.rowPerPage.value=pageSize;
 }
 if(typeof(order)!="undefined" && order!=null && order!=""){
  qForm.orderBy.value=order;
  var ascend = qForm.ascending.value;
  //alert(ascend);
  if("true"==ascend){
    ascend = "false";
  } else {
    ascend = "true";
  }
  qForm.ascending.value = ascend;
 }

 if(typeof(refreshPart)!="undefined" && refreshPart){
    if (typeof(callback)!="undefined" && typeof(callback)=="function"){
      callback(qForm);
    } else {
      cwBackgroundSubmitWithoutIframe("?",qForm);
    }
 } else {
   location.href = qForm.attributes['action'].value+"&"+Form.serialize(qForm) + "&dddatetttime="+new Date().getTime();
 }
}
