var CONTEXT_NAME;

function getContextName(){
    // TODO cookie를 안쓸 경우엔 무조건 값이 "" 이 되어 버림.
    if (CONTEXT_NAME == null){
    	CONTEXT_NAME = getCookie("j_context_name");
    }
    return CONTEXT_NAME;
}

var global = new JGlobal();

var messages = new JMessage();

function JGlobal() {
    this.pageNo = 1;    
    this.help;
    this.query;
    this.orderIndex;
    this.orderTheadIndex;
    this.orderMode;
    this.orderColumn;
}

function JMessage() {
    this.init;
    this.messages;
    
    this.get = function(id, args) {
                   if (!this.init) {
                       this.messages = new Array();
                       this.messages["JSM-1001"] = "저장하시겠습니까?";
                       this.messages["JSM-1002"] = "체크박스";
                       this.messages["JSM-1003"] = "삭제하시겠습니까?";
                       this.messages["JSM-1004"] = "{0} 입력해야 합니다.";
                       this.messages["JSM-1005"] = "{0}의 크기는 {1}이여야 합니다";
                       this.messages["JSM-1006"] = "{0}의 크기는 {1}과 {2} 사이여야 합니다";
                       this.messages["JSM-1007"] = "{0}에는 다음(', ., \") 특수 문자는 입력할 수 없습니다";
                       this.messages["JSM-1008"] = "{0}에는 숫자만을 입력해야 합니다";
                       this.messages["JSM-1009"] = "{0}의 숫자는 {1}이여야 합니다";
                       this.messages["JSM-1010"] = "{0}의 숫자는 {1} {2} 사이여야 합니다";
                       this.messages["JSM-1011"] = "{0} 선택해야 합니다";
                       this.messages["JSM-1012"] = "선택할 수 있는 {0}의 수는 {1} 입니다";
                       this.messages["JSM-1013"] = "선택할 수 있는 {0}의 수는 {1} {2} 사이여야 합니다";
                       this.messages["JSM-1014"] = "{0}의 금액은 {1}이여야 합니다";
                       this.messages["JSM-1015"] = "{0}의 금액는 {1} {2} 사이여야 합니다";
                       this.messages["JSM-1016"] = "{0} 올바르게 입력하여 주십시오";
                       this.messages["JSM-1017"] = "입력하신 {0} 전자우편주소로 유효하지 않습니다. 다시 입력하여 주십시오!";
                       this.messages["JSM-1018"] = "입력하신 {0} 날짜로 유효하지 않습니다. 다시 입력하여 주십시오!";
                       this.messages["JSM-1019"] = "{0}의 날짜는 {1} 이전 이어야 합니다";
                       this.messages["JSM-1020"] = "{0}의 날짜는 {1} 이후 이어야 합니다";
                       this.messages["JSM-1021"] = "선택할 수 있는 {0}의 날짜는 {1} {2} 사이여야 합니다";
                       this.messages["JSM-1022"] = "올바른 파일명이 아닙니다. 파일을 다시 입력해 주시기 바랍니다";
                       this.messages["JSM-1023"] = "{0}에 대한 파일을 첨부해야 합니다";
                       this.messages["JSM-1024"] = "{0}에 대한 첨부 가능한 파일의 확장자는 {1} 입니다";
                       this.messages["JSM-1025"] = "{0}에 대하여 확장자가 {1}인 파일은 첨부가 금지되어 있습니다";
                       this.messages["JSM-1026"] = "입력하신 {0} Crontab 표현식으로 유효하지 않습니다. 다시 입력하여 주십시오!";
                       this.messages["JSM-1027"] = "{0}의  {1} 올바른 속성 표현식이 아닙니다";
                       this.messages["JSM-1028"] = "{0}의 속성  {1} 필요합니다";
                       this.messages["JSM-1029"] = "관련 답글도 함께 삭제됩니다. 삭제하시겠습니까?";
                       this.messages["JSM-1030"] = "수정하시겠습니까?";
                       this.messages["JSM-1031"] = "파일을 삭제 하시겠습니까?";
                       this.messages["JSM-1032"] = "진행중인 작업을 완료하셔야 합니다.";
                       this.messages["LIMS-001"] = "접수를 취소 하시겠습니까?";
                       this.messages["LIMS-002"] = "시험성적서 발송완료 처리를 하시겠습니까?";
                       this.messages["LIMS-003"] = "취소된 내역은 발송완료처리 할 수 없습니다.";
                       this.messages["LIMS-004"] = "이미 발송완료된 내역입니다.";
                       this.messages["LIMS-005"] = "처리가 완료되지 않은 내역은 발송완료처리 할 수 없습니다.";
                       this.messages["LIMS-006"] = "이미 취소된 내역입니다.";
                       this.messages["LIMS-007"] = "시험중인 내역은 담당팀에서만 취소를 할 수 있습니다.";
                       this.messages["LIMS-008"] = "시험을 취소 하시겠습니까?";
                       this.messages["LIMS-009"] = "시험전인 내역은 접수실을 통해서만 취소 할 수 있습니다.";
                       this.messages["LIMS-010"] = "처리가 완료된 내역은 취소를 할 수 없습니다.";
                       this.messages["LIMS-011"] = "체크박스";
                       this.messages["LIMS-012"] = "이미 확인된 내역입니다.";
                       this.messages["LIMS-013"] = "시험이 완료되지 않았습니다.";
                       this.messages["LIMS-014"] = "이미 처리 완료된 내역입니다.";
                       this.messages["LIMS-015"] = "이미 시험 완료된 내역입니다.";
                       this.messages["LIMS-016"] = "이미 접수가 완료되거나 시험중인 내역이 포함되어있습니다.";
                       this.messages["LIMS-017"] = "접수완료 처리를 하겠습니까?";
                       this.init = true;
                   }
                   var message = this.messages[id];
                   if (!message) {
                       return id;
                   }
                   if (args) {
                       if (typeof args == "object" && args.length) {
                           for (var i = 0; i < args.length; i++) {
                               var pattern = new RegExp("\\{" + i + "\\}", "g"); 
                               message = message.replace(pattern, args[i]);
                           }
                       } else {
                           message = message.replace(/\{0\}/g, args);
                       }
                   }
                   return message;
               };

    this.alert = function(id, args) {
                     alert(this.get(id, args));
                 }
}

function JAdd() {
    this.params;

    this.param = jcontrol_param;
    
    this.addParam = jcontrol_addParam;

    this.run = function() {
                   var nextPage = jcontrol_getJspName() + "Form.jsp";
                   var query = jcontrol_getQueryString();
                   if (query != "") {
                       nextPage += "?" + query;
                   }
                   if (this.params) {
                       if (query != "") {
                           nextPage += "&" + this.params;
                       } else {
                           nextPage += "?" + this.params;
                       }
                   }
                   
                   //TODO 
                   var part = jcontrol_getSkipPage();
                   
                   if (nextPage.indexOf("?") < 0 ) {
                       window.location.href = encodeURI(nextPage + "?" + part.replace(/^&/, ""));
                   } else {
                       window.location.href = encodeURI(nextPage + "&" + part.replace(/^&/, ""));
                   }
               };

}

function JAjax() {
    this.params;
    
    this.addParam = jcontrol_addParam;

    this.mode = function(mode) {
                    return this.addParam("mode", mode);
                };

    this.run = function(element, url, params) {
                   JLoadingMessage.show(element);
                   if (params) {
                       var callback = params.onComplete;
                       params.onComplete = function(originalRequest) {
                                            JLoadingMessage.hide();
                                            if (callback) {
                                                callback(originalRequest);
                                            }
                                        };
                       if (this.params) {
                           params.parameters = this.params;
                       }
                   } else if (this.params) {
                       params = {parameters: this.params, onComplete: JLoadingMessage.hide};
                   }
                   new Ajax.Request(url, params);
               };


    this.update = function(element, url, target, params) {
                      JLoadingMessage.show(element);
                      if (params) {
                          var callback = params.onComplete;
                          params.onComplete = function(originalRequest) {
                                                  JLoadingMessage.hide();
                                                  if (callback) {
                                                      callback(originalRequest);
                                                  }
                                              };
                          if (this.params) {
                              params.parameters = this.params;
                          }
                      } else if (this.params) {
                          params = {parameters: this.params, onComplete: JLoadingMessage.hide};
                      }
                      new Ajax.Updater(target, url, params);
                  };
}

function JBehind() {
    this.formIndex = 0;

    this.form = jcontrol_form;

    this.run = function(mode) {
                   if (window.validate && !validate(mode)) {
                       return;
                   }
                   var form = document.forms[this.formIndex];
                   form.action = form.action + jcontrol_getQuery();
                   jcontrol_addMode(form, mode);
                   form.submit();
               };
}

function JClose() {
    this.run = function() {
                   window.close();
               };
}

//TODO after 함수에 기본적으로 적용될 파라미터는?
//TODO firefox가 modal 창을 IE처럼 지원하지 않아 편법을 썼음. 리팩토링의 여지가 있음. 이와 관련 참고 참고 : http://www.gtalbot.org/BugzillaSection/Bug195867GDR_WindowOpen.html

var jcontrol_tempDatePopupMethod = null;

function JDatePopup() {
    this.after;
    this.popup = function(event, element, after) {
                     var url = getContextName() + "/popup/DatePopup.jsp";
                     var xfield = element.previousSibling;
                     /* IE */
                     if (window.showModalDialog) {
                         var ws = jcontrol_formatModalWindow(Event.pointerX(event) + window.screenLeft - 105,
                                                    Event.pointerY(event) + window.screenTop + 10,
                                                    250, 230);
                         var dt = showModalDialog(url, window, ws);
                         if (dt != null) {
                             if (dt.year == "") {
                                 xfield.value = "";
                             } else {
                                 xfield.value = dt.year + "-" + dt.month + "-" + dt.day;
                             }
                         }
                         if (after) after();
                     } else {
                         var ws = jcontrol_formatModalWindow(Event.pointerX(event) + window.screenX,
                                                    Event.pointerY(event) + window.screenY,
                                                    250, 230);
                         url += "?formName=" + xfield.form.getAttribute("name") + "&fieldName=" + xfield.name;
                         var win1 = window.open(url, "date", ws);
                         jcontrol_tempDatePopupMethod = after;
                     }
                 };
}

function addEvent(obj, evType, fn){
try{
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
 }catch(e){alert("catch");}
}

function JDelete() {
    this.formIndex = 0;
    this.idValue = "id";

    this.form = jcontrol_form;

    this.id = function(id) {
                  this.idValue = id;
                  return this;
              };

    this.run = function() {
                   var form = document.forms[this.formIndex];
                   //TODO 입력값에 대한 유효성 체크가 checkbox, radio 타입만 지원하는 부분을 
                   //TODO text, hidden 타입도 지원하도록 로직 수정
                   if (form[this.idValue].type == "text" || form[this.idValue].type == "hidden") {
                       if (new JText(messages.get("JSM-1002"), form[this.idValue]).validate()
                               && confirm(messages.get("JSM-1003"))) {
                           jcontrol_addMode(form, "delete");
                           form.action = form.action + jcontrol_getQuery();
                           form.submit();
                       }
                   } else {
                       if (new JCheck(messages.get("JSM-1002"), form[this.idValue]).validate()
                               && confirm(messages.get("JSM-1003"))) {
                           jcontrol_addMode(form, "delete");
                           form.action = form.action + jcontrol_getQuery();
                           form.submit();
                       }
                   }
               };
}

function JExcel() {
    this.formIndex = 0;

    this.form = jcontrol_form;

    this.run = function(mode) {
                   if (!mode) {
                       mode = "excel";
                   }
                   var form = document.forms[this.formIndex];
                   var input = jcontrol_addMode(form, mode);
                   form.submit();
                   form.removeChild(input);
               };
}

function JHelp() {
    this.targetValue;

    this.target = function(target) {
                      this.targetValue = target;
                      return this;
                  };

    this.run = function(id) {
                   var target = "help-message";
                   if (this.targetValue) {
                       target = this.targetValue;
                   }
                   if (!$(target)) {
                       alert(target + "를 아이디로 하는 태그가 없습니다.");
                       return;
                   }
                   if (global.help == null || global.help != id) {
                       global.help = id;
                       var onComplete = function() {
                                            $(target).style.display = "block";
                                        }
                       new Ajax.Updater(target,
                                        getContextName() + "/HelpAjax.do?id=" + id,
                                        {asynchronous:true, onComplete:onComplete});
                   } else {
                       if ($(target).style.display == "block") {
                           $(target).style.display = "none";
                           global.help =  null;
                           return;
                       }
                   }
               };
}

//TODO 이전페이지로 돌아가는 함수 추가
function JLink() {
    this.newPage;
    this.nextPage;
    this.backFlag;
    this.linkFlag;
    this.params;

    this.page = function(page) {
                    this.newPage = page;
                    return this;
                }
                
    this.next = function(page) {
                    this.nextPage = page;
                    return this;
                }

    this.back = function(back) {
    				if(back == null){
    					back = true;
    				}
                    this.backFlag = back;
                    return this;
                }
                
    this.isSelect = function(id) {
                    if (id != "") {
                        this.linkFlag = true;
                    }
                    return this;
                }
                
    this.param = jcontrol_param;

    this.addParam = jcontrol_addParam;

    this.run = function(id) {
                   if (this.newPage != null) { //TODO
                       window.location.href = encodeURI(this.newPage);
                       return true;
                   }
                   if (this.linkFlag) {
                       alert(new JMessage().get("JSM-1032"));
                       return true;
                   }
                   if (!this.nextPage) {
                       this.nextPage = jcontrol_getJspName() + "Form.jsp";
                   }
                   var part = "";
                   var pids = ""; //TODO
                   if (arguments.length == 1) {
                       part += "p_id=" + id;
                       pids += "p_id=";
                   } else {
                       for (var i = 0; i < arguments.length; i++) {
                           part += "&p_id" + (i + 1) + "=" + arguments[i];
                           pids += "p_id" + (i + 1) + "=|";
                       }
                   }
                   if (this.params) {
                       part += "&" + this.params;
                   }
                   
                   //TODO
                   var url = decodeURI(window.document.URL);
                   if (url.indexOf(this.nextPage) > 0) {
                        query = jcontrol_getQueryString(true, pids);
                   } else {
                        query = jcontrol_getQueryString();
                   }
                   if (query != "") {
                       part += "&" + query;
                   }

                   //TODO
                   if (part.indexOf(this.nextPage) < 0) {
                        if (part == "" || part.substr(part.length, 1) != "&") part += "&";
                        part += jcontrol_getSkipPage();
                   }

                   if (this.backFlag == true) {
                        var url = decodeURI(window.document.URL);
                        part = url.substr(url.indexOf("url="),url.length).replace("url=","");
                        part = part.replace(/@/g,"&");
                        window.location.href = encodeURI(part.replace(/^&/, ""));
                   } else {
                        window.location.href = encodeURI(this.nextPage + "?" + part.replace(/^&/, ""));
                   }

               };
}

function JList() {
    this.run = function() {
                   var nextPage = jcontrol_getJspName() + "List.jsp";
                   window.location.href = nextPage + jcontrol_getQuery();
               };
}

function JLoad() {
    this.formIndex = 0;

    this.form = jcontrol_form;

    this.run = function() {
                   var query = window.location.search;
                   query = decodeURI(query);
                   query = query.replace(/^\?(&)*/, "");
                   query = query.split("&");
                   var form = document.forms[this.formIndex];
                   for (var i = 0; i < query.length; i++) {
                       var index = query[i].indexOf("=");
                       var name = query[i].substring(0, index);
                       var value = query[i].substring(index + 1);
                       if (name.substring(0, 2) == "q_") {
                           if (form[name]) {
                               if (form[name].length){ // 배열로 전달되면
                                   for (var j = 0; j < form[name].length; j++) {
                                       if (form[name][j].value == value) {
                                           if (form[name][0].nodeName.toLowerCase() == "option") {
                                               form[name][j].selected = true;
                                           } else {
                                               form[name][j].checked = true;
                                           }
                                       }
                                   }
                               } else { // 배열이 아닌 input이면
                                   form[name].value = value;
                               }
                           } // if (form[name])
                       } else {
                           if (name == "orderIndex") {
                               global.orderIndex = value;
                           } else if (name == "orderTheadIndex") {
                               global.orderTheadIndex = value;
                           } else if (name == "orderBy") {
                               global.orderColumn = value;
                           } else if (name == "orderMode") {
                               global.orderMode = value;
                           } else if (name == "pageNo") {
                               global.pageNo = value;
                           }
                       }
                   }
                   jcontrol_sortToggle();
               };
}

var JLoadingMessage = {
    show : function(target) {
               var id = "loading-message";
               if (!$(id)) {
                   var div = document.createElement('div');
                   div.id = id;
                   document.body.appendChild(div);
                   Element.hide(id);
                   new Insertion.Bottom(id, "<img src='" + getContextName() + "/ext/image/loading.gif'/>");
                   $(id).style.position = "absolute";
               }
               var dim = Element.getDimensions(id);
               var targetDim = Element.getDimensions(target);
               var offsetTop, offsetLeft;
               offsetTop = (targetDim.height - dim.height) / 2;
               offsetLeft = (targetDim.width - dim.width) / 2;

               Position.clone(target,id,
                              {setLeft: true,
                               setTop: true,
                               setWidth: false,
                               setHeight: false,
                               offsetTop: offsetTop,
                               offsetLeft: offsetLeft
                              });
               Element.show(id);
           },

    hide: function() {
              var id = "loading-message";
              if ($(id)) {
                  Element.hide(id);
                  jcontrol_sortToggle();
              }
          }
};

function JNavigation() {
    this.params;

    this.run = function(pageNo, params, fromJSave) {
                   global.pageNo = pageNo;
                   if (params && params.pageNo) {
                       document.forms[0][params.pageNo].value = pageNo;
                   }
                   var nextPage = JNavigation.nextPage ? JNavigation.nextPage + "?" : 
                                                         jcontrol_getJspName() + "List.jsp?";
                   
                   //TODO                                       
                   var url = decodeURI(window.document.URL);
                   if (url.indexOf(nextPage.substr(0,nextPage.length-1)) > 0) fromJSave = true;
                   
                   global.query = nextPage + jcontrol_getQueryString(fromJSave);
                   if (isAjax) {
                       var target = "list";
                       var mode = "&mode=ajaxList";
                       if (params) {
                           if (params.target) {
                               target = params.target;
                           }
                           if (params.param) {
                               global.query += ("&" + params.param);
                           }
                           if (params.mode) {
                               mode = "&mode=" + params.mode;
                           }
                       }
                       JLoadingMessage.show(target);
                       new Ajax.Updater(target, encodeURI(global.query + mode), {asynchronous:true, onComplete:JLoadingMessage.hide});
                   } else {
                       if (params) {
                           if (params.param) {
                               global.query += ("&" + params.param);
                           }
                       }
                       window.location.href = encodeURI(global.query);
                   }
               };
}

function JSave() {
    this.formIndex = 0;

    this.form = jcontrol_form;

    this.run = function() {
                   if (window.validate && !validate("SAVE")) {
                           return;
                   }
                   if (confirm(messages.get("JSM-1001"))) {
                       var form = document.forms[this.formIndex];
                       form.action = form.action + jcontrol_getQuery();
                       var mode = "create";
                       if (window.location.search.indexOf("p_id") > 0 || 
                               form.getElementsByTagName("input")[0].type == "hidden") {
                           mode = "update";
                       }
                       jcontrol_addMode(form, mode);
                       form.submit();
                   }
               };
}

//TODO mode(create/update)를 직접 설정해서 사용할 수 있도록 함
//TODO Ajax를 이용해 등록/수정을 할 경우를 위해 추가
function JAjaxSave(mode) {
    this.formIndex = 0;

    this.form = jcontrol_form;

    this.run = function() {
                   if (window.validate && !validate("SAVE")) {
                           return;
                   }
                   if (confirm(messages.get("JSM-1001"))) {
                       var form = document.forms[this.formIndex];
                       form.action = form.action + jcontrol_getQuery();
                       jcontrol_addMode(form, mode);
                       form.submit();
                   }
               };
}

function JSearch() {
    this.run = function(params) {
                   new JNavigation().run(1, params, true);
               };
}

//TODO 
function JSort() {
    this.linkFlag;

    this.isSelect = function(id) {
                    if (id != "") {
                        this.linkFlag = true;
                    }
                    return this;
                }
                
    this.run = function(columnName, element, params) {
                   if (this.linkFlag) {
                       alert(new JMessage().get("JSM-1032"));
                       return true;
                   }
                   var row = element.parentNode.parentNode;
                   var elements = row.getElementsByTagName("th");
                   for (var i = 0; i < elements.length; i++) {
                       if (element.parentNode == elements[i]) {
                           global.orderIndex = i;
                           break;
                       }
                   }
                   var thead = row.parentNode;
                   elements = document.getElementsByTagName("thead");
                   for (var i = 0; i < elements.length; i++) {
                       if (thead == elements[i]) {
                           global.orderTheadIndex = i;
                           break;
                       }
                   }
                   global.orderColumn = columnName;
                   if (global.orderMode) {
                       global.orderMode = (global.orderMode == "ASC") ? "DESC" : "ASC";
                   } else {
                       //TODO 기본정렬이 DESC이기 때문에 변경함
                       global.orderMode = "ASC";
                   }
                   if (!global.pageNo) {
                       global.pageNo = 1;
                   }
                   new JNavigation().run(global.pageNo, params);
               };
}

function jcontrol_addMode(form, mode) {
    if (!form.mode) {
        var input = document.createElement("input");
        input.name = "mode";
        input.type = "hidden";
        input.value = mode;
        form.appendChild(input); // MS IE에서는 추가된 INPUT에 바로 접근할 수 없음.
        return input;
    } else {
        form.mode.value = mode;
        return form.mode;
    }
}

function jcontrol_addParam(name, value) {
    if (this.params) {
        this.params += "&";
    } else {
        this.params = "";                            
    }
    this.params += (name + "=" + value);
    return this;
}

/*
*
* 수정일자 : 2010/01/05
* 수정자  : 서영재
*
*/
function jcontrol_addFormParam(form, paramName, paramValue) {
    if (!form.paramName) {
        var input = document.createElement("input");
        input.name = paramName;
        input.type = "hidden";
        input.value = paramValue;
        form.appendChild(input); // MS IE에서는 추가된 INPUT에 바로 접근할 수 없음.
        return input;
    } else {
        form.paramName.value = paramValue;
        return form.paramName;
    }
}

function jcontrol_form(index) {
    this.formIndex = index;
    return this;
}

function jcontrol_formatModalWindow(left, top, width, height) {
    if (window.showModalDialog) {
        return "status:no; dialogLeft:" + left + "px; dialogTop:" + top + 
               "px; dialogWidth:" + width + "px; dialogHeight:" + height + "px";
    } else {
        return "modal=yes, left=" + left + "px, top=" + top + ", width=" + width + "px, height=" + height + "px";
    }
}

function jcontrol_getJspName() {
    var path = window.location.pathname;
    if (path.indexOf("Popup.jsp") > 0) {
        return path.replace("Popup.jsp", "Popup");
    } else if (path.indexOf("List.jsp") > 0) {
        return path.replace("List.jsp", "");
    } else if (path.indexOf("Form.jsp") > 0) {
        return path.replace("Form.jsp", "");
    } else if (path.indexOf("Detail.jsp") > 0) {
        return path.replace("Detail.jsp", "");
    }
    return path;
}

function jcontrol_getQuery() {
    var result = "";
    var query = window.location.search;
    if (!query || query.length == 0) {
        return result;
    }
    
    query = query.replace(/^\?(&)*/, "");
    query = query.split("&");
    for (var i = 0; i < query.length; i++) {
        if (query[i].substring(0, 2) != "p_") {
            if (result != "") {
                result += "&";
            } else {
                result += "?";
            }
            result += query[i];
        }
    }
    return result;
}

//TODO 수정전 원본 백업
/*function jcontrol_getQueryString(fromJSave) {
    var result = "";
    var queryTags = document.getElementsByTagName("input");

    if(fromJSave) {
        for (var i = 0; i < queryTags.length; i++) {
    
            var name = queryTags[i].name;
            var type = queryTags[i].type;
            var checked = queryTags[i].checked;
            
            if (name && name.substring(0, 2) == "q_") {
                if (!((type == "checkbox" || type == "radio") && checked == false)){                        
                    if (queryTags[i].value != null && queryTags[i].value != "") {
                        result += "&" + name + "=" + queryTags[i].value;
                    }           
                }  
            }     
        }
    
        queryTags = document.getElementsByTagName("select");
        for (var i = 0; i < queryTags.length; i++) {
            var name = queryTags[i].name;
            if (name && name.substring(0, 2) == "q_") {
                if (queryTags[i].value != null && queryTags[i].value != "") {
                    result += "&" + name + "=" + queryTags[i].value;
                }
            }
        }
    }
    
    if (global.pageNo != 1) {
        result += "&pageNo=" + global.pageNo;
    }
    
    if (global.orderColumn) {
        result += "&orderBy=" + global.orderColumn +
                      "&orderMode=" + global.orderMode +
                          "&orderIndex=" + global.orderIndex +
                          "&orderTheadIndex=" + global.orderTheadIndex;
    }
    return result != "" ? result.replace(/^&/, "") : result;
}/*/
//TODO 네비게이션 태그 및 JSearch 함수의 비정상 동작 수정
function jcontrol_getQueryString(fromJSave, idList) {
    var result = "";
    var url = ""; //TODO
    
    if(fromJSave) { 
    
        var queryTags = document.getElementsByTagName("input");
        for (var i = 0; i < queryTags.length; i++) {
            var name = queryTags[i].name;
            var type = queryTags[i].type;
            var checked = queryTags[i].checked;
            if (name && name.substring(0, 2) == "q_") {
                if (!((type == "checkbox" || type == "radio") && checked == false)){                        
                    //if (queryTags[i].value != null) {
                    if (queryTags[i].value != null && queryTags[i].value != "") {
                        result += "&" + name + "=" + queryTags[i].value;
                    }           
                }  
            }     
        }
        
        queryTags = document.getElementsByTagName("select");
        for (var i = 0; i < queryTags.length; i++) {
            var name = queryTags[i].name;
            if (name && name.substring(0, 2) == "q_") {
                //if (queryTags[i].value != null) {
                if (queryTags[i].value != null && queryTags[i].value != "") {
                    result += "&" + name + "=" + queryTags[i].value;
                }
            }
        }
        
        //TODO
        var query = window.location.search; 
        query = decodeURI(query);
        query = query.replace(/^\?(&)*/, "");
        query = query.split("&");
        for (var i = 0; i < query.length; i++) { 
            if (query[i].substring(0, 2) == "p_") {
                if (idList != null) {
                    if (idList.indexOf(query[i].substring(0, query[i].indexOf("=")+1)) < 0) {
                        result += "&" + query[i];
                    }
                } else {
                    result += "&" + query[i];
                }
            } else if(query[i].indexOf("url=") >= 0) {
                url += "&" + query[i];
            }
        }
    } else {
        var query = window.location.search;
        query = decodeURI(query);
        query = query.replace(/^\?(&)*/, "");
        query = query.split("&");
        for (var i = 0; i < query.length; i++) { 
            if (query[i] != "" && query[i].substring(0, 2) != "q_" &&
                query[i].indexOf("url=") < 0 && query[i].indexOf("pageNo=") < 0 && 
                query[i].indexOf("orderBy=") < 0 && query[i].indexOf("orderMode=") < 0 &&
                query[i].indexOf("orderIndex=") < 0 && query[i].indexOf("orderTheadIndex=") < 0) {
                result += "&" + query[i];
            }
        }
        
        global.pageNo = 1;
        global.orderColumn = "";
    }
    
    if (global.pageNo != 1) {
        result += "&pageNo=" + global.pageNo;
    }
    
    if (global.orderColumn) {
        result += "&orderBy=" + global.orderColumn +
                      "&orderMode=" + global.orderMode +
                          "&orderIndex=" + global.orderIndex +
                          "&orderTheadIndex=" + global.orderTheadIndex;
    }
    
    //TODO
    if (url != "") result += url;
    return result != "" ? result.replace("?&","?").replace(/^&/, "") : result;
}

function jcontrol_param() {
    for (var i = 0 ; i < arguments.length; i++) {
        if (i == 0) {
            if (!this.params) {
                this.params = "";
            }
        }
        this.params += "&p_value" + (i + 1) + "=" + arguments[i];
    }
    return this;
}

function jcontrol_sortToggle() {
    if (global.orderColumn) {
        var thead = document.getElementsByTagName("thead")[global.orderTheadIndex];
        if (thead) {
            var elements = thead.getElementsByTagName("th");
            if (global.orderMode == "DESC") {
                elements[global.orderIndex].className = "desc";
            } else {
                elements[global.orderIndex].className = "asc";
            }
        }
    }
}

//TODO 이전페이지 
function jcontrol_getSkipPage() {
    return "url=" + decodeURI(window.document.URL).replace(/&/g,"@");
}