function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function setCookie( name, value, expiredays ) { 
	var todayDate = new Date(); 
	todayDate.setDate( todayDate.getDate() + expiredays ); 
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
} 
function getCookie( 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 ""; 
} 

/* 
	2007.07.13 김진희 탭이미지관련 최초생성
	2007.07.15 정정훈 공통적으로 사용가능하게 전면수정 
	해당페이지에 thisTabBtn 의 초기값을 입력해주어야 한다.
	name: 이미지객체 이름
*/
var thisTabImgBtn;
function tabImgBtn( name ) {
	var img = document.getElementById(name);
	var src = img.src;

	if( src.indexOf("off") ) {
		img.src = (img.src).replace("off", "on");
	}

	//이전버튼 off상태로 돌리기
	if( thisTabImgBtn && thisTabImgBtn != name ) {
		img = document.getElementById(thisTabImgBtn);
		src = img.src;
		img.src = (img.src).replace("on", "off");
	}
	
	thisTabImgBtn = name;

}

var name_old;
function tabImgBtn_over( name ) {
	var img = document.getElementById(name);
	var src = img.src;

	if (name_old == name)
	{
		img.src = (img.src).replace("on", "off");
	} else {
		if( src.indexOf("off") > 0 ) {
			name_old	= name;
			img.src = (img.src).replace("off", "on");
		}
	}
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

/* 회원관련 */
function OpenZipcode( pwd, fname, z1, z2, ad, ad1) {
	var url = '/2007/common/do/postCode/search.php?form='+fname+'&zip1='+z1+'&zip2='+z2+'&address='+ad+'&address1='+ad1;
	window.open(url,'zip_win','width=460,height=270,statusbar=no,scrollbars=yes,toolbar=no');
}

/* 숫자관련 */
//add commas
function addComma( nStr ) {
	if( nStr ) {
		nStr = delComma(nStr);
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	return "";
}

function delComma( nStr ) {
	if( /,/.test(nStr) ) {
		if( nStr ) return nStr.replace(/\,/g, "");
	} else {
		return nStr;
	}
}

/* resize */
function getObj(name){
    if (document.getElementById){
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
    }
    else if (document.all){
        this.obj = document.all[name];
        this.style = document.all[name].style;
    }
}

function getWinSize(){
   var iWidth = 0, iHeight = 0;

   if (document.documentElement && document.documentElement.clientHeight){
       iWidth = parseInt(window.innerWidth,10);
       iHeight = parseInt(window.innerHeight,10);
   }
   else if (document.body){
       iWidth = parseInt(document.body.offsetWidth,10);
       iHeight = parseInt(document.body.offsetHeight,10);
   }

   return {width:iWidth, height:iHeight};
}

function resize_id(obj) {
    var oContent = new getObj(obj);
    var oWinSize = getWinSize();
    if ((oWinSize.height - parseInt(oContent.obj.offsetTop,10))>0)
        oContent.style.height = (oWinSize.height - parseInt(oContent.obj.offsetTop,10));
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function openWin(url, name, width, height) {
	var win = window.open(url, name, 'width='+width+',height='+height);
	win.focus();
}

