

// Trim 함수
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();
}
//-----------------------------------------------------------------------------------------------------------


// 비밀번호 입력DIV 활성화
function on_PopupPass(gflag,gidx,gimg,gdiv,gurl) {
	popFrame.flag.value = gflag
	popFrame.idx.value = gidx
	popFrame.ReturnUrl.value = gurl
	popFrame.fPopCalendar(gimg,gdiv);
}
//-----------------------------------------------------------------------------------------------------------


// 이미지 크기 조정
function Resize_Img(gobj,maxw) {
	var gwidth = gobj.width;
	var gheight = gobj.height;

	if(gwidth > maxw){
		gobj.width = maxw;
		gobj.height = maxw * (gheight/gwidth);
	}
}
//-----------------------------------------------------------------------------------------------------------



// Tab Change
function Change_Tab(gidx,gbtn,gtbl,glen) {
	for(var i=0;i<gbtn.length;i++){
		gbtn[i].src = gbtn[i].src.replace("on.gif",".gif");
		gtbl[i].style.display = "none";
	}
	gbtn[gidx].src = gbtn[gidx].src.replace(".gif","on.gif");
	gtbl[gidx].style.display = "";
}
//-----------------------------------------------------------------------------------------------------------



// 게시물 카운터 증가
function onView(gflag,gurl,gidx) {
	document.frames['frameCounter'].location.href="/inc/counter.asp?countflag="+gflag+"&countcode="+gidx+"&returnUrl="+escape(gurl);
}
//-----------------------------------------------------------------------------------------------------------



// 쿠키저장
function setCookies( name, value, expiredays ) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
//-----------------------------------------------------------------------------------------------------------



// 파일확장자 및 크기 확인. jpg/gif 이미지
function checksize(gvalue,gmsg) {
	var im = new Image();
	im.src = gvalue;
	if(im.src=="") return false;

	var arr = im.src.split('.');
	var filetype = arr[arr.length-1].toLowerCase();

	if(filetype=="jpg" || filetype=="gif"){
		if(parseInt(im.fileSize) > (10*1024*1024)){
			alert('10MB 이상의 파일은 업로드하실 수 없습니다.');
			return true;
		} else {
			return false;
		}
	} else{
		alert("["+gmsg+"] 이미지파일(jpg,gif)을 올려주세요.");
		return true;
	}

	return false;
}
//-----------------------------------------------------------------------------------------------------------



// 쿠키값
function getCookies( name )
{
        
                var nameOfCookie = name + "=";
        var x = 0;
        while ( x <= document.cookie　.length )
        {
                var y = (x+nameOfCookie.length);
                if ( document.cookie　.substring( x, y ) == nameOfCookie ) {
                        if ( (endOfCookie=document.cookie　.indexOf( ";", y )) == -1 )
                                endOfCookie = document.cookie　.length;
                        return unescape( document.cookie　.substring( y, endOfCookie ) );
                }
                x = document.cookie　.indexOf( " ", x ) + 1;
                if ( x == 0 )
                        break;
        }
        return "";

}
//-----------------------------------------------------------------------------------------------------------


// 통합검색
function onMainSearch() {
	var flag = document.getElementById('mainsearchflag').value;
	var word = document.getElementById('mainsearchword').value;
	if(word.trim()=="" || word.trim().length<2){
		alert('검색어가 너무 짧습니다');
		document.getElementById('mainsearchword').focus();
		return;
	}
	if(flag=="") location.href='/search/search.asp?mainsearchflag='+flag+'&mainsearchword='+escape(word);
	else location.href='/search/search_sub.asp?mainsearchflag='+flag+'&mainsearchword='+escape(word);
}
//-----------------------------------------------------------------------------------------------------------


// 숫자. 천단위 콤마(,) 삽입
function addComma(gNum) {
	var value = gNum.toString();
	//value = value.trim();
	value = value.replace(",","");
	var point = "";
	var returnValue = "";

	if(value.indexOf(".") > 0){
		point = value.substring(value.indexOf("."),value.length);
		value = value.substring(0,value.indexOf("."));
	}

	if(value.length > 3){
		for(z = 0; z <= value.length ;z++){
			if( ((z) % 3 == 0) && (z) != value.length &&  z != 0 ){
				returnValue =  ","+ value.charAt( value.length - (z) )+ returnValue;
			} else{
				returnValue =  value.charAt( value.length - (z) ) + returnValue; 
			}
		}
		return returnValue + point;
	}

	return value + point;
} 
//-----------------------------------------------------------------------------------------------------------



// 찜하기
function wishadd(gcode,gsale){
	document.getElementById("ifrControl").src="/inc/wishadd.asp?prod_code="+gcode+"&sale_prod_code="+gsale;
}
//-----------------------------------------------------------------------------------------------------------


// 문자열의 길이를 반환함. 영어=1, 한글=2
function Byte_Length(lvStr){
    var resultSize = 0;
    if (lvStr == null) return 0;
    for(var i=0; i<lvStr.length; i++){
        var c = escape(lvStr.charAt(i));
        if(c.length == 1) resultSize ++;
        else if(c.indexOf("%u") != -1) resultSize += 2;
        else if(c.indexOf("%") != -1) resultSize += c.length/3;
    }
    return resultSize;
}
//-----------------------------------------------------------------------------------------------------------


// 리스트로 이동
function onListCommon(gform,gurl) {
	gform.action=gurl;
	gform.submit();
}
//-----------------------------------------------------------------------------------------------------------



// 첨부파일 다운로드
function onDownload(gpath,gfile) {
	location.href="/inc/downloader.asp?filepath="+escape(gpath)+"&filename="+escape(gfile);
}
//-----------------------------------------------------------------------------------------------------------


// 링크점선한방에 안보이기
function bluring(){ 
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
document.onfocusin=bluring; 
//-----------------------------------------------------------------------------------------------------------


// 화면 정중앙에 팝업창 띄우기
function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
  var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
  var int_windowTop = (screen.height - a_int_windowHeight) / 2;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
    }
}

//	<a href="http://www.blueb.co.kr/" onclick="newWindow(this.href, 'popup', 300, 300, 1, 1, 1, 0, 0, 1, 0); return false;" target="_blank">화면 정중앙에 팝업창 띄우기</a>
//	- 옵션값 -
//	가로사이즈설정 
//	세로사이즈설정 
//	스크롤바 :1,보이기 0,안보이기
//	리사이즈 :1,가능 0,불가능
//	메뉴바 : 1,보이기 0,안보이기
//	툴바 : 1,보이기 0,안보이기
//	주소창 : 1,보이기 0,안보이기
//	상태바 : 1, 보이기 0,안보이기
//	풀스크린 : 1,풀스크린 0,일반팝업 
//-----------------------------------------------------------------------------------------------------------


// <div>로 지정된 영역만 출력
var win=null;
function printIt(printThis)  {
	win = window.open();
	self.focus();
	win.document.open();
	win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
	win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
	win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
	win.document.write('<'+'link href="'+'/'+'style'+'/'+'style.css" rel="stylesheet" type="text'+'/'+'css"'+'>');
	win.document.write(printThis.innerHTML);
	win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
	win.document.close();
	win.print();
	win.close();
}
//-----------------------------------------------------------------------------------------------------------


function on_ChangePage(gurl, gnum) {
	frm.spcnt.value = gnum;
	frm.action=gurl;
	frm.submit();
}


// Div 팝업 Control
function move_box(an, box, gleft) {
//링크된 위치에서 부터의 설정값 지정
  var cleft = 20;  //왼쪽마진  
  var ctop = -4;  //상단마진
  var obj = an;
  while (obj.offsetParent) {
    cleft += obj.offsetLeft;
    ctop += obj.offsetTop;
    obj = obj.offsetParent;
  }
  box.style.left = gleft=='none'?0:(cleft-60) + 'px';
  ctop += an.offsetHeight + 10;
  if (document.body.currentStyle &&
    document.body.currentStyle['marginTop']) {
    ctop += parseInt(
      document.body.currentStyle['marginTop']);
  }
  box.style.top = ctop + 'px';
}

function show_hide_box(an, gid, width, height, gleft, borderStyle) {
  var href = an.href;
  var boxdiv = document.getElementById(gid);

//  if (boxdiv != null) {
//		removeChild(boxdiv);
//  }

  if (boxdiv != null) {
    if (boxdiv.style.display=='none') {
      move_box(an, boxdiv, gleft);
      boxdiv.style.display='block';
    } else
alert(href);
		boxdiv.removeChild(boxdiv.children(gid))
//      boxdiv.style.display='none';
//    return false;
  }

  boxdiv = document.createElement('div');
  boxdiv.setAttribute('id', gid);
  boxdiv.style.display = 'block';
  boxdiv.style.position = 'absolute';
  boxdiv.style.width = width + 'px';
  boxdiv.style.height = height + 'px';
  boxdiv.style.border = borderStyle;
  boxdiv.style.backgroundColor = '#fff';

  var contents = document.createElement('iframe');
  contents.scrolling = 'yes';
  contents.frameBorder = '0';
  contents.style.width = width + 'px';
  contents.style.height = height + 'px';
  contents.src = href;

  boxdiv.appendChild(contents);
  document.body.appendChild(boxdiv);
  move_box(an, boxdiv, gleft);
  return false;
}
//-----------------------------------------------------------------------------------------------------------


