



   /**
    * 删除字符串两侧的空格,返回的是删除两侧空格的字符串
    * @param str 待处理的字符串
    */

   function trim(str){
     if(str==null||str=="") return "";
     return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
   };

   /**
    * 把目标字符串，根据指定的分割符分解为字符串数组
    * @param targetString 目标字符串
    * @param seperator 分割符
    * @parem return  Array 被分割的字符串数组
    */

   function splitString(targetString,seperator) {
    if(targetString == null || trim(targetString)=="") {
      return new Array();
    }

    var resultStrs = new Array();
    var singleStatement = "";
    var fromIndex = 0;
    var endIndex = 0;
    var breakFor = false;
    while(fromIndex<targetString.length) {
      endIndex = targetString.indexOf(seperator,fromIndex);
      if(endIndex == -1) {
        endIndex = targetString.length;
        breakFor = true;
      }
      singleStatement = targetString.substring(fromIndex,endIndex);
      if(singleStatement != null && !trim(singleStatement)=="") {
        resultStrs[resultStrs.length] = singleStatement;
      }
      fromIndex = endIndex + 1;
      if(breakFor) {
        break;
      }
    }
    return resultStrs;
  };

    function preprocessURL(url,conditions)  {
    if(conditions==null||conditions.length==0) return url;
    var beginIndex = 0;
    var endIndex = url.indexOf("?",beginIndex);
    if(endIndex>0){
      var newURL = "";
      newURL+=url.substring(beginIndex, endIndex);
      newURL+="?";
      for(var i=0;i<conditions.length;i++){
        var condition = conditions[i];
        var conditionValue = condition;
        if(/^[&\$]/.test(condition)){
          condition = condition.substring(1,condition.length);

          var conditionObj = document.all(condition);
          if(conditionObj == null){
            alert("Condition identified by '" + conditions[i] + "' not exist!");
            continue;
          }
          conditionValue = conditionObj.value;
        }
        beginIndex = endIndex+1;
        endIndex = url.indexOf("?",beginIndex);
        if(endIndex<0)
          break;
        newURL += url.substring(beginIndex, endIndex);
        newURL +=conditionValue;
      }
      return newURL;
    }else{
      return url;
    }
  };



/**
* 打开模式窗口，窗口居中
* @param:sURL 打开窗口对应的URI，该路径为不包括contextroot的绝对路径
* @param:sWidth 打开窗口的宽度
* @param:sHeight 打开窗口的高度
* @param:obj 参数对象，用来向弹出窗口传递参数
* @param:sStyle 窗口宽度、高度等属性字符串
* @param:returnValueDelimiter 返回数值的分割符
* @param:targets 返回数值的需要填充的目标
* @param: conditions 客户端的检索条件，为以，号分割字符串
*
*/

	function openModalDialog(sUrl,sWidth,sHeight,obj,sStyle,seperatorOrReturnValueProperty,targets,conditions){

          if(sUrl==null||sUrl=="")
           alert("传入的参数sUrl不能为空值");
                   sUrl = preprocessURL(sUrl,splitString(conditions,","));

	  if(sStyle==null||sStyle=="") {
            if(sWidth == null||sWidth == "")
              sWidth = "280px";
            if(sHeight == null||sHeight == ""){
              sHeight = "100px";
            }
            sStyle = "scroll:no;dialogWidth:" + sWidth + ";dialogHeight:" + sHeight + ";status:no;center:yes;resizable:no;";
	  }

	  if(obj==null) obj = "";

	   sUrl = sUrl.replace("?","%3f");
	  sUrl = sUrl.replace(/\&/g,"%26");
	  sUrl = sUrl.replace(/\=/g,"%3d");


	  var prefix =  sUrl.substring(0,1);
	  if(prefix != "/"&&prefix!="\\"){
	  	sUrl = "/"+sUrl;
	  }


	  var sValue = showModalDialog("/jntax/js/dialogWrapper.jsp?url=/jntax"+sUrl,obj,sStyle);
          populateValueToTarget(sValue,targets,seperatorOrReturnValueProperty);
	  return sValue;
	}

        function populateValueToTarget(value,targets,seperatorOrReturnValueProperty){

         if(targets==null||value==null)
           return;

         var splitValues = null;
         var splitTargets = targets.split(",");
         if(value instanceof String || typeof(value)=='string'){ //如果返回值为字符串
           if(seperatorOrReturnValueProperty==null||seperatorOrReturnValueProperty=='')
             seperatorOrReturnValueProperty=",";
           splitValues = splitString(value,seperatorOrReturnValueProperty);
         }else{ //如果返回值为js对象

           splitValues = new Array();

           if(seperatorOrReturnValueProperty==null||seperatorOrReturnValueProperty==''){
              for (var aProperty in value){
               splitValues[splitValues.length] = value[aProperty];
              }
           }else{
             var properties = seperatorOrReturnValueProperty.split(",");
             for(var i=0;i<properties.length;i++){
               splitValues[splitValues.length] = value[properties[i]];
             }
           }
         }
         if(splitValues==null||splitTargets==null)
           return;

         var length = splitValues.length > splitTargets.length? splitTargets.length:splitValues.length;
         for(var i=0;i<length;i++){
           if(splitTargets[i] == "#")
             continue;
           var element = document.all(splitTargets[i]);
           if(element==null){
             alert("Element identified by " + splitTargets[i]  + " not exist!");
           }
           document.all(splitTargets[i]).value = splitValues[i];
           //触发数据变化的处理

         }
          for(var i=0;i<length;i++){
           var htmlElement = document.all(splitTargets[i]);
           if(htmlElement.onchange!="undefined"&&htmlElement.onchange!=null)
              htmlElement.onchange();
         }
        }


	function openWindow(sUrl,sWidth,sHeight,winName, sStyle){
         if(sUrl==null||sUrl=="")
           alert("传入的参数sUrl不能为空值");

         var prefix =  sUrl.substring(0,1);

         if(prefix != "/"&&prefix!="\\"){
	  	sUrl = "/"+sUrl;
	 }
         if(sStyle==null||sStyle==""){
           if(sWidth == null||sWidth == "")
              sWidth = screen.availWidth;
           if(sHeight == null||sHeight == ""){
              sHeight = screen.availHeight;
           }
		   sStyle="location=no,menubar=no,resizable=yes,top=0b,left=0,toolbar=no,height="+sHeight+",width="+sWidth;
          }
	  sUrl = "/jntax"+sUrl;
	  window.open(sUrl,winName, sStyle);
      }

