/**
 * ÆäÀÌÁö°¡ ·ÎµåµÈ ÈÄ¿¡ ¼öÇàµÇ´Â °øÅë ·ÎÁ÷À» ´ã°í ÀÖ´Ù.
 */
function JLoad() {
    this.run = function() {
                   var query = window.location.search;
                   query = query.replace(/^\?(&)*/, "");
                   query = query.split("&");
                   var form = document.forms[0];
                   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]) {
                              form[name].value = value;
                          }
                      }
                   }
                   var records = document.getElementById("records");
                   if (records) {
                       records = records.getElementsByTagName("tr");
                       for (var i = 0; i < records.length; i++) {
                           if (i % 2 == 1) {
                               records[i].style.backgroundColor = "#e9f1f9";
                           }
                       }
                   }
               };
}

/**
 * °øÅë ¸µÅ© ±â´ÉÀ» ±¸ÇöÇÑ´Ù. ±âº»ÀûÀ¸·Î´Â ÆË¾÷Ã¢À» ÀÌ¿ëÇÑ´Ù.
 */
function JLink() {
    
    this.nextPage;
    this.isPopup = true;
    this.isScroll = false;
    this.isResize = true;
    this.width;
    this.height;
    this.params;
    this.winTarget;
    this.separate = '?'; // -
   
    this.next = function(page) {
                    this.nextPage = page;
                    
                    // - 
                    if (this.nextPage.indexOf ("?") > -1 || this.nextPage.indexOf ("&") > -1) {
                    	this.separate = '&';
                    }
                    
                    return this;
                }

    this.noPopup = function() {
                       this.isPopup = false;
                       return this;
                   }

   //return p_value1, p_value2, ...
    this.param = function() {   
                     for (var i = 0 ; i < arguments.length; i++) {
                         if (i == 0) {
                             this.params = "";
                         }
                         this.params += "&p_value" + (i + 1) + "=" + arguments[i];
                     }
                     return this;
                 }

   this.size = function(width, height) {
               this.width=width;
               this.height=height;
               
               return this;
   }
            
   this.scroll = function() {
               this.isScroll = true;
               return this;
            }
            
   this.target = function(target) {
               this.winTarget = target;
               return this;
            }
            
    this.resize = function(resize) {
    	this.isResize = resize;
    	return this;
    }
            
    this.run = function(id) {
                   if (!this.nextPage) {
                       this.nextPage = jprivate_getPath();
                   }
                   
                   this.nextPage += this.separate; // -
                   
                   if (arguments.length == 1) {
                       this.nextPage += "p_id=" + id;
                   } else {
                       for (var i = 0; i < arguments.length; i++) {
                           this.nextPage += "p_id" + (i + 1) + "=" + arguments[i] + "&";
                       }
                   }
                   if (this.params) {
                       this.nextPage += this.params;
                   }
                   if (!this.winTarget) {
                         this.winTarget = "";
                   }
                   
                   if(this.isPopup) {
                       if(this.width) {
                            if(this.isScroll) {
                            	this.width = parseInt(this.width) + 30;
                                jprivate_open_size_scroll(this.nextPage, this.width, this.height, this.winTarget);
                            } else {
                            	if (this.isResize) {
                               		jprivate_open_size(this.nextPage, this.width, this.height, this.winTarget);
                               	}else {
	                               	jprivate_open_noresize(this.nextPage, this.width, this.height, this.winTarget);
                               	}
                          }
                         } else {
                           jprivate_open(this.nextPage);
                     }
                 } else {
                     window.location.href = this.nextPage;
                 }
               };
}



/**
 * ³×ºñ°ÔÀÌ¼Ç ¹Ù¸¦ ÀÌ¿ëÇÏ¿© ÀÌµ¿ÇÏ´Â ±â´ÉÀ» ±¸ÇöÇÑ´Ù.
 */
function JNavigation(pageNo) {
    this.run = function() {
                   window.location.href = 
                       window.location.pathname + "?pageNo=" + pageNo + 
                       jprivate_getQuery(true).replace(/(&)*pageNo=(\d)*/gi, "");
               };
}

/**
 * °Ë»ö ¹öÆ° ¼öÇà½ÃÀÇ µ¿ÀÛÀ» ±¸ÇöÇÑ´Ù.
 */
function JSearch() {

	this.month;
    this.term = function(month) {
                this.month=month;
                return this;
             }
    this.nullCheck = true;
    this.nullable = function() {
			    this.nullCheck = false;
			    return this;
             }
            
    this.run = function() {
                  if (window.validate) {
                       if (!validate("SEARCH")) {
                           return;
                       }
                   }
                   
  
                   var listNo = document.forms[0].q_listNo;
                   if (listNo) {
                       if (isNaN(listNo.value)) {
                           alert("¶óÀÎ¼ö¿¡´Â ¼ýÀÚ¸¸À» ÀÔ·ÂÇÒ ¼ö ÀÖ½À´Ï´Ù.");
                           listNo.focus();
                           listNo.select();
                           return;
                       }
                       if (listNo.value > 800) {
                           alert("¶óÀÎ¼öÀÇ °ªÀº 800 ÀÌÇÏ¿©¾ß ÇÕ´Ï´Ù.");
                           listNo.focus();
                           listNo.select();
                           return;
                       }
                   }
                   
                   
                   if(document.forms[0].q_sdate) {
                   	   if(this.nullCheck) {
		                   if(document.forms[0].q_sdate.value == "" && document.forms[0].q_edate.value == "") {
		                   	   alert("Á¶È¸ ½Ã Á¶È¸±â°£Àº ¹Ýµå½Ã ÀÔ·ÂÇØ¾ß ÇÕ´Ï´Ù");
		                   	   return;
		                   }                   
		                   if(document.forms[0].q_sdate.value == "") {
		                   	   alert("½ÃÀÛÀÏÀÚ¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
		                   	   return;
		                   }
		                   if(document.forms[0].q_edate.value == "") {
		                   	   alert("Á¾·áÀÏÀÚ¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
		                   	   return;
		                   }
	                   }
	                   
	                   // Á¾·áÀÏÀÌ ½ÃÀÛÀÏ º¸´Ù ÀÛÀºÁö check
					   if (document.forms[0].q_sdate.value != "" ){
	                       if (document.forms[0].q_edate.value != "" ){
							   if (!dateBetween(document.forms[0].q_sdate.value, document.forms[0].q_edate.value)){
								   //document.forms[0].q_sdate.value = "";
								   //document.forms[0].q_edate.value = "";
							       return;
							   }
							}else{
							    alert("Á¾·áÀÏÀÚ¸¦ ÀÔ·ÂÇÏ¼¼¿ä");
							    document.forms[0].q_edate.focus();
							    return;
							}
	                   } else if (document.forms[0].q_edate.value != "" ) {
	                       alert("½ÃÀÛÀÏÀÚ¸¦ ÀÔ·ÂÇÏ¼¼¿ä");
	                       document.forms[0].q_sdate.focus();
	                       return;
	                   }                   
                   }
                   
                   // °Ë»ö±â°£ °Ë»ç - 6°³¿ù ÀÌ³»
                   if(document.forms[0].q_sdate && this.month) {

                       var eDate = new Date();
                       var sDate = new Date();
	                   var preDate = new Date();
	                   var from;
	                   var arrEDate = document.forms[0].q_edate.value.split("-");
	                   var arrSDate = document.forms[0].q_sdate.value.split("-");
	                   
	                   eDate.setYear(arrEDate[0]);
	                   eDate.setMonth(eval(arrEDate[1])-1);
	                   eDate.setDate(arrEDate[2]);
	                   
	                   sDate.setYear(arrSDate[0]);
	                   sDate.setMonth(eval(arrSDate[1])-1);
	                   sDate.setDate(arrSDate[2]);

					   preDate.setYear(arrEDate[0]);
					   preDate.setMonth(eval(arrEDate[1])-1);
					   preDate.setDate(arrEDate[2]);
					   
	                   from = eval(eDate.getMonth()) - eval(this.month);
	                   preDate.setMonth(from);
	                   
	                   if(sDate < preDate) {
	                       alert("°Ë»ö±â°£À» " + this.month + "°³¿ù ÀÌ³»·Î ÇØÁÖ¼¼¿ä.");
	                       return;
	                   }
                   }
				   
                   window.location.href = window.location.pathname + "?isQuery=true&" + getQueryString();
               };
}

/**
 * BehindÀÇ Å¬·¡½ºÀÇ Æ¯Á¤ ¸Þ¼Òµå¸¦ È£ÃâÇÑ´Ù.
 */
function JBehind() {
    this.run = function(mode) {
                   if (window.validate) {
                       if (!validate(mode)) {
                           return;
                       }
                   }
                   var form = document.forms[0];
                   if (!form.mode) {
                       var input = document.createElement("input");
                       input.name = "mode";
                       input.type = "hidden";
                       input.value = mode;
                       form.appendChild(input); // MS IE¿¡¼­´Â Ãß°¡µÈ INPUT¿¡ ¹Ù·Î Á¢±ÙÇÒ ¼ö ¾øÀ½.
                       
                       var urlStr = "";
                       var text = jprivate_getQuery(true)
                       text = text.replace(/^\?(&)*/, "");
                       text = text.split("&");
                       
                       for (var i = 0; i < text.length; i++) {
                            var index = text[i].indexOf("=");
                            var name = text[i].substring(0, index);
                            var value = text[i].substring(index + 1);
                            
                            if (name != "") {
                               if (urlStr != "") {
                                  urlStr = urlStr +"&"+ text[i];
                               } else {
                                  urlStr = text[i];
                               }
                            }
                       }
                   } else {
                       form.mode.value = mode;
                   }
                   form.action = window.location.pathname + "?" + urlStr;
                   form.submit();

                   try {
	                   form.target = "_self";
	               }catch(e) {
	               }
               };
}

/**
 * ÀÔ·ÂÈ­¸éÀ¸·Î ÀÌµ¿ÇÏ´Â ±â´ÉÀ» ±¸ÇöÇÑ´Ù. ±âº»ÀûÀ¸·Î´Â ÆË¾÷Ã¢À» ÀÌ¿ëÇÑ´Ù.
 */
function JAdd() {
    this.nextPage;
    this.isPopup = true;
    this.width;
    this.height;

    this.next = function(page) {
                    this.nextPage = page;
                    return this;
                }

    this.noPopup = function() {
                       this.isPopup = false;
                       return this;
                   }

	/**
	 * ÆË¾÷Ã¢ÀÇ »çÀÌÁî Á¶ÀýÀ» À§ÇØ Ãß°¡ÇÔ.
	 * 2007-01-24
	 * Áø¿µ¼®
	 */                   
	this.size = function(width, height) {
		this.width=width;
		this.height=height;
		return this;
	}

	/**
	 * 
	 * ÆË¾÷Ã¢ÀÇ »çÀÌÁî Á¶ÀýÀ» À§ÇØ ¼öÁ¤ÇÔ.
	 * 2007-01-24
	 * Áø¿µ¼®
	 * 
    this.run = function() {
                   if (!this.nextPage) {
                       this.nextPage = jprivate_getPath();
                   }
                   
                   this.isPopup ? jprivate_open(this.nextPage) : window.location.href = this.nextPage;
               };
    */
            
    this.run = function() {
                   if (!this.nextPage) {
                       this.nextPage = jprivate_getPath();
                   }
                   
                   if (this.isPopup) {
                   		if (this.width) {
                   			jprivate_open_size_scroll(this.nextPage, this.width, this.height, "");
                   		}else {
                   			jprivate_open(this.nextPage);
                   		}
                   }else {
                   		window.location.href = this.nextPage;
                   }
               };
}

/**
 * ÆË¾÷Ã¢À» ´Ý´Â´Ù.
 */
function JClose() {
    this.run = function() {
                   if (window.history.length > 0) {
                       opener.location.reload();
                   }
                   window.close();
               }
}

/**
 * ÀúÀå ±â´ÉÀ» ±¸ÇöÇÑ´Ù.
 */
function JSave() {
    this.run = function() {
                   if (window.validate) {
                       if (!validate("SAVE")) {
                           return;
                       }
                   }
                   if (confirm("ÀúÀåÇÏ½Ã°Ú½À´Ï±î?")) {
                      var form = document.forms[0];
                      form.action = form.action + jprivate_getQuery();
                      var mode = "create";
                      if (window.location.search.indexOf("p_id") > 0) {
                          mode = "update";
                      } else if (form.getElementsByTagName("input")[0].type == "hidden") {
                          mode = "update";
                      }
                      if (!form.mode) {
                          var input = document.createElement("input");
                          input.name = "mode";
                          input.type = "hidden";
                          input.value = mode;
                          form.appendChild(input); // MS IE¿¡¼­´Â Ãß°¡µÈ INPUT¿¡ ¹Ù·Î Á¢±ÙÇÒ ¼ö ¾øÀ½.
                      } else {
                          form.mode.value = mode;
                      }
                     
                      form.submit();
                  }
               };
}

/**
 * »èÁ¦ ±â´ÉÀ» ±¸ÇöÇÑ´Ù.
 */
function JDelete() {
    this.run = function() {
                   if (confirm("»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) {
                      var form = document.forms[0];
                      if (!form.mode) {
                          var input = document.createElement("input");
                          input.name = "mode";
                          input.type = "hidden";
                          input.value = "delete";
                          form.appendChild(input); // MS IE¿¡¼­´Â Ãß°¡µÈ INPUT¿¡ ¹Ù·Î Á¢±ÙÇÒ ¼ö ¾øÀ½.
                      } else {
                          form.mode.value = "delete";
                      }
                      form.submit();
                   }
               };
}

/**
 * ¿¢¼¿ ´Ù¿î·Îµå ±â´ÉÀ» ±¸ÇöÇÑ´Ù.
 */
function JExcel() {
    this.run = function() {
                   var form = document.forms[0];
                   form.action = form.action + jprivate_getQuery();
                   var input;
                   if (!form.mode) {
                       input = document.createElement("input");
                       input.name = "mode";
                       input.type = "hidden";
                       input.value = "excel";
                       form.appendChild(input); // MS IE¿¡¼­´Â Ãß°¡µÈ INPUT¿¡ ¹Ù·Î Á¢±ÙÇÒ ¼ö ¾øÀ½.
                    } else {
                       form.mode.value = "excel";
                    }
                    form.submit();
                    form.removeChild(input); // MS IE ¹ö±× Ã³¸®
               };
}

/**
 * ¸®½ºÆ® Á¤·Ä ±â´ÉÀ» ±¸ÇöÇÑ´Ù.
 */
function JSort(columnName) {
    this.run = function() {
                   if (window.location.search.indexOf("isQuery=true") == -1) {
                       alert("°Ë»öÀ» ¸ÕÀú ÇØ¾ß ÇÕ´Ï´Ù.");
                       return;
                   }
                   var orderMode = "DESC";
                   if (window.location.search.indexOf("orderMode=DESC") > 0) {
                       orderMode = "ASC";
                   }
                   window.location.href = 
                       window.location.pathname + "?orderBy=" + columnName + 
                       "&orderMode=" + orderMode + 
                       jprivate_getQuery(true).replace(/orderBy=(.)*&orderMode=[^&]*/gi, "");
               };
}

// À©µµ¿ì »çÀÌÁî ¹Ù²Ù±â
function JResize(nWidth, nHeight)
{
	window.resizeTo(nWidth, nHeight);
}

function jprivate_getPath() {
    var path = window.location.pathname;
    if (path.indexOf("mapas") > 0) {
        return path.replace("mapas", "mapaf");
    } else if (path.indexOf("mapss") > 0) {
        return path.replace("mapss", "mapsf");
    } else if (path.indexOf("mapfs") > 0) {
        return path.replace("mapfs", "mapff");
    }
    return path;
}

function jprivate_getQuery(isNotStart) {
    var result = window.location.search;
    if (!result || result.length == 0) {
        result = "";
    } else if (isNotStart) {
        result = "&" + result.substring(1);
    }
    return result;
}

function jprivate_open(url) {
    var win = window.open(url, "", "width=860, height=500, left=10, top=10, toolbar=no, location=no, directorys=no, status=no, menubar=no, scrollbars=yes, resizable=yes");
    if (win != null) {
	    win.focus();
	}
}

function jprivate_open_size(url, width, height, target) {
    var win = window.open(url, target, "width=" + width + ", height=" + height + ", left=10, top=10, toolbar=no, location=no, directorys=no, status=no, menubar=no, scrollbars=auto, resizable=yes");
    if (win != null) {
	    win.focus();
	}
}

function jprivate_open_noresize(url, width, height, target) {
    var win = window.open(url, target, "width=" + width + ", height=" + height + ", left=10, top=10, toolbar=no, location=no, directorys=no, status=no, menubar=no, scrollbars=auto, resizable=no");
    if (win != null) {
	    win.focus();
	}
}

function jprivate_open_size_scroll(url, width, height, target) {
    var win = window.open(url, target, "width=" + width + ", height=" + height + ", left=10, top=10, toolbar=no, location=no, directorys=no, status=no, menubar=no, scrollbars=yes, resizable=yes");
    if (win != null) {
	    win.focus();
	}
}

function dateBetween(startDate, endDate){

	startDate = startDate.substring(0,4)+ startDate.substring(5,7)+ startDate.substring(8,10);
	endDate = endDate.substring(0,4)+ endDate.substring(5,7)+ endDate.substring(8,10);
	
	var dateBetween = daysBetween(startDate, endDate);
	
	if (dateBetween <= -1){
		alert("½ÃÀÛÀÏÀÌ Á¾·áÀÏº¸´Ù Å®´Ï´Ù.\n³¯Â¥¸¦ ´Ù½ÃÀÔ·ÂÇÏ¼¼¿ä.");
		
		return false;
	}else{
		return true;
	}

}

/*************************************************
 * ÀÌ¹ÌÁö¸¦ Å¬¸¯½Ã ÀÌ¹ÌÁö Å©±â¿¡ ¸Â°Ô »õÃ¢»çÀÌÁî¸¦ Á¶ÀýÇÏ´Â ÇÔ¼ö 
 *************************************************/

	function image_open(img)
	{ 
		foto1 = new Image(); 
		foto1.src = (img); 
		contImg(img); 
	}

	function contImg(img)
	{ 
		if((foto1.width != 0) && (foto1.height != 0)){ 
			viewImg(img); 
		}else{ 
			funzione = "contImg('"+ img +"')"; 
			intervallo = setTimeout(funzione, 20); 
		} 
	}

	function viewImg(img)
	{ 
		var sv = "no"; 
		var imgW = foto1.width; 
		var imgH = foto1.height; 
		if(imgW > screen.width - 10){
			imgW = screen.width - 10
			imgH = imgH + 20;
			sv = "yes";
		}
		if(imgH > screen.height - 30){
			imgW = imgW + 20;
			imgH = screen.height - 30;
			sv = "yes";
		}
		stringa = "scrollbars="+ sv +", resizable=yes, width="+ imgW +", height="+ imgH +", left=0, top=0"; 
		finestra = window.open("/web/popup/viewImage.jsp?image="+ img, "", stringa); 
	}
	
/*************************************************/