var __INCLUDE_VIRTUAL_PATH = "/Include";

//@이벤트를 바인딩시킴.
//@ $(document).ready(function(){       }); 안에
//@ SetEvent(이벤트타입, 객체이름, 바인딩시킬메소드); 
function SetEvent(eventType, objName, tarFunc)
{
	if($("#"+objName) == typeof(undefinded)) return;
	if(eventType == "click")
	{
		$("#"+objName).css("cursor","hand").click(function(){
			eval(tarFunc);
		});
	}
	else if(eventType == "change")
	{
		$("#"+objName).change(function(){
			eval(tarFunc);
		});
	}
}


//셀렉트 박스에 선택된 값 미리 선택되게함.
//@ $(document).ready(function(){       }); 안에
//@ fixSelectBox(객체이름, 선택시킬값);
function fixSelectBox(selName, values)
{	
	//var str = ("#select[@name='"+selName+"'] .option[@value='"+values+"']");
	//alert($(str).val());
	//$(str).attr("selected", "true");
	$("#"+selName).val(values);
}

function fixCheckBox(chkName,value)
{
	var obj = document.getElementsByName(chkName) ;

	for( var i = 0 ; i < obj.length ; i ++ )
	{
		if( obj[i].value == parseInt(value) )
			obj[i].checked = true ;
	}
}

function getSelectedBox(selName)
{
	return $("#"+selName+"  option:selected").val();
}

function fileDownload(path, name)
{
	location.href=__INCLUDE_VIRTUAL_PATH+"/download.asp?file="+path+"/"+name;
}

//테이블에 보더넣기
function table_design_load()
{
	var tb = document.getElementsByTagName('table');
	for (i=0;i<tb.length;i++){
		if (tb[i].className=="tb"){
			with (tb[i]){
				setAttribute('border', 1);
				setAttribute('borderColor', "#e6e6e6");
				//setAttribute('rules', 'none');
				setAttribute('cellPadding',5);
				//frame = "hsides";
				//rules = "rows";
				//cellPadding = "4";
			}
			with (tb[i].style){

				width = "100%";
				borderCollapse = "collapse";
			}
		}
	}
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}

function resize(img, maxWidth, maxHeight){
   // 원본 이미지 사이즈 저장
   var width = img.width;
   var height = img.height;

   // 가로, 세로 최대 사이즈 설정
   //var maxWidth = width * 0.5;   // 원하는대로 설정. 픽셀로 하려면 maxWidth = 100  이런 식으로 입력
   //var maxHeight = height * 0.5;   // 원래 사이즈 * 0.5 = 50%

   // 가로나 세로의 길이가 최대 사이즈보다 크면 실행  
   if(width > maxWidth || height > maxHeight){
      // 가로가 세로보다 크면 가로는 최대사이즈로, 세로는 비율 맞춰 리사이즈
      if(width > height){
         resizeWidth = maxWidth;
         resizeHeight = Math.Round((height * resizeWidth) / width);
      // 세로가 가로보다 크면 세로는 최대사이즈로, 가로는 비율 맞춰 리사이즈
      }else{
         resizeHeight = maxHeight;
         resizeWidth = Math.Round((width * resizeHeight) / height);
      }
   // 최대사이즈보다 작으면 원본 그대로
   }else{
      resizeWidth = width;
      resizeHeight = height;
   }
   // 리사이즈한 크기로 이미지 크기 다시 지정
   img.width = resizeWidth;
   img.height = resizeHeight;
}

String.prototype.ltrim = function() {
	var re = /\s*((\S+\s*)*)/;
	return this.replace(re, "$1");
}

String.prototype.rtrim = function() {
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}

String.prototype.trim = function() {
	return this.ltrim().rtrim();
}


function goButton(targetObj)
{
	var tObj = $("#"+targetObj);
	if (event.keyCode == 13)
	{
		tObj.click();
		return false; 
	}
}