/*******************************************************************************
	DHTML °ü·Ã °øÅë À¯Æ¿¸®Æ¼

	Author: Kim Kyoung shil
*******************************************************************************/

var browserType			= checkBrowserType();	// »ç¿ëÀÚ ºê¶ó¿ìÁ® Å¸ÀÔ


/**
 * »ç¿ëÀÚ ºê¶ó¿ìÁ® Ã¼Å©
 */
function checkBrowserType() {
	var brType = "IE";
	if (document.all){
		brType = "IE";
	}
	else if (document.getElementById){
		brType = "NE";
	}
	else if (document.layers){
		brType = "NE4";
	}
	return brType;
}


/**
 * ¸¶¿ì½º X À§Ä¡
 */
function checkMouseX(evt) {
	var xCoord = 0;
	if (browserType == "IE"){
		xCoord = event.clientX;
	}
	else if (browserType == "NE"){
		xCoord = evt.pageX;
	}
	return xCoord;
}


/**
 * ¸¶¿ì½º Y À§Ä¡
 */
function checkMouseY(evt) {
	var yCoord = 0;
	if (browserType == "IE"){
		yCoord = event.clientY;
	}
	else if (browserType == "NE"){
		yCoord = evt.pageY;
	}
	return yCoord;
}


/**
 * ¸¶¿ì½º ¹öÆ°°ª ±¸ÇÏ±â
 * @return left,center,right
 */
function getMouseButton(evt) {
	var button 		= "left";
	var mouseKey	= 1;
	if (browserType == "IE") {
		mouseKey = event.button
		if (mouseKey == 1) {
			button = "left";
		}
		else if (mouseKey == 2) {
			button = "right";
		}
		else if (mouseKey == 4) {
			button = "center";
		}
	}
	else {
		mouseKey = evt.which;
		if (mouseKey == 1) {
			button = "left";
		}
		else if (mouseKey == 2) {
			button = "center";
		}
		else if (mouseKey == 3) {
			button = "right";
		}
	}
	return button;
}


/**
 * °´Ã¼ÀÇ ³ÐÀÌ ±¸ÇÏ±â
 */
function getWidth(obj) {
	if (obj) {
		var objWidth = obj.offsetWidth;
		return objWidth;
	}
}


/**
 * °´Ã¼ÀÇ ³ôÀÌ ±¸ÇÏ±â
 */
function getHeight(obj) {
	if (obj) {
		var objHeight = obj.offsetHeight;
		return objHeight;
	}
}


/**
 * À©µµ¿ì ³ÐÀÌ ±¸ÇÏ±â
 */
function getWindowWidth() {
	var winWidth = 0;
	if (browserType == "IE") {
		winWidth = document.body.offsetWidth;
	}
	else if (browserType == "NE") {
		winWidth = window.innerWidth;
	}
	return winWidth;
}


/**
 * À©µµ¿ì ³ôÀÌ ±¸ÇÏ±â
 */
function getWindowHeight() {
	var winHeight = 0;
	if (browserType == "IE") {
		winHeight = document.body.offsetHeight;
	}
	else if (browserType == "NE") {
		winHeight = window.innerHeight;
	}
	return winHeight;
}
    

/**
 * ½ºÅ©·Ñ°ª(X) ±¸ÇÏ±â
 */
function getScrollX() {
	var scrollX		= 0;

    if (browserType == "NE") {
        scrollX		= window.pageXOffset;
    }
    else {
        scrollX		= document.body.scrollLeft;
    }

	return scrollX;
}


/**
 * ½ºÅ©·Ñ°ª(Y) ±¸ÇÏ±â
 */
function getScrollY() {
	var scrollY		= 0;
    
	if (browserType == "NE") {
        scrollY		= window.pageYOffset;
    }
    else {
        scrollY		= document.body.scrollTop;
    }

	return scrollY;
}


/**
 * °´Ã¼ °¡Á®¿À±â
 * @param objName(°´Ã¼¸í)
 */
function getObject(objName) {
	/*
	var returnObj = null;
	if (browserType == "IE") {
		//returnObj = eval("document.all."+objName);
		returnObj = document.getElementById(objName);
	}
	else if (browserType == "NE") {
		returnObj = document.getElementById(objName);
	}
	
	return returnObj;
	*/
	return document.getElementById(objName);
}


/**
 * °´Ã¼ DISPLAY º¯°æ
 */
function changeDisplay(obj) {
	if (obj) {
		var displayStyle = obj.style.display;
		if (displayStyle == "block") {
			offDisplay(obj);
		}
		else if (displayStyle == "none") {
			onDisplay(obj);
		}
	}
}


/**
 * DISPLAY on
 */
function onDisplay(obj) {
	if (obj) {
		obj.style.display = "block";
	}
}


/**
 * DISPLAY off
 */
function offDisplay(obj) {
	if (obj) {
		obj.style.display = "none";
	}
}


/**
 * °´Ã¼ º¸ÀÌ±â
 */
function visibleObject(obj) {
	if (obj) {
		obj.style.visibility = "visible";
	}
}


/**
 * °´Ã¼ ¼û±â±â
 */
function hiddenObject(obj) {
	if (obj) {
		obj.style.visibility = "hidden";
	}
}


/**
 * °´Ã¼ ¼±ÅÃ½Ã »ö»ó ¹ÝÀü
 */
function onSelectColor(obj) {
	if (obj) {
		obj.style.backgroundColor	= "highlight";
		obj.style.color				= "highlighttext";
	}
}


/**
 * °´Ã¼ ¼±ÅÃ ºñÈ°¼º »ö»ó º¹¿ø
 */
function offSelectColor(obj, color, bgColor) {
	if (obj) {
		if (color == null) {
			color = "";
		}
		if (bgColor == null) {
			bgColor = "";
		}
		obj.style.color				= color;
		obj.style.backgroundColor	= bgColor;
	}
}


/*
 * °´Ã¼ »çÀÌÁî ¼³Á¤
 */
function resizeObject(obj, newWidth, newHeight) {
	if (obj) {
		if (nullToEmpty(newWidth) != "") {
			obj.style.width = newWidth+"px";
		}
		if (nullToEmpty(newHeight) != "") {
			obj.style.height = newHeight+"px";
		}
	}
}


/**
 * °´Ã¼ ³ÐÀÌ ¼³Á¤
 */
 function resizeWidth(obj, newWidth) {
 	if (obj) {
		obj.style.width		= newWidth+"px";
	}
 }


/**
 * °´Ã¼ ³ôÀÌ ¼³Á¤
 */  
function resizeHeight(obj, newHeight) {
	if (obj) {
		obj.style.height	= newHeight+"px";
	}
}


/**
 * °´Ã¼ ÀÌµ¿ ¼³Á¤ (À§Ä¡)
 */
function moveObject(obj, topPosition, leftPosition) {
	if (obj) {
		if (nullToEmpty(topPosition) != "") {
			obj.style.top       = topPosition+"px";
		}
		if (nullToEmpty(leftPosition) != "") {
			obj.style.left      = leftPosition+"px";
		}
	}
}


/**
 * °´Ã¼ÀÇ À§Ä¡ (document ³»¿¡¼­ Àý´ëÀûÀÎ À§Ä¡)
 */
function getPosition(obj) {
	var pos = { x:0, y:0 };
	
	if ( document.layers ) {
		pos.x = obj.x;
		pos.y = obj.y;
	}
	else {
		do { 
			pos.x += parseInt( obj.offsetLeft );
			pos.y += parseInt( obj.offsetTop );
			obj = obj.offsetParent;
		} while (obj);
	}
	return pos;
}


/**
 * °´Ã¼ÀÇ ¿ÞÂÊ À§Ä¡ (»ó´ëÀ§Ä¡)
 */
function getLeftPosition(obj) {
	var value = 0;
	if (obj) {
		if (browserType == "IE") {
			if (obj.currentStyle.left == "auto") {
				value = 0;
			}
			else {
				value = parseInt(obj.currentStyle.left);
			}
		}
		else {
			value = parseInt(obj.style.left);
		}
	}
	return value;
}


/**
 * °´Ã¼ À§ÂÊ À§Ä¡ (»ó´ëÀ§Ä¡)
 */
function getTopPosition(obj) {
	var value = 0;
	if (obj) {
		if (browserType == "IE") {
			if (obj.currentStyle.top == "auto") {
				value = 0;
			}
			else {
				value = parseInt(obj.currentStyle.top);
			}
		}
		else {
			value = parseInt(obj.style.top);
		}
	}
	return value;
}


/**
 * °´Ã¼ÀÇ ¼Ó¼º°ª ±¸ÇÏ±â
 */
function getObjectAttribute(obj, attrName) {
	var attrValue	= null;

	if (obj) {
		attrValue = obj.getAttribute(attrName);
	}
	return attrValue;
}


/**
 * °´Ã¼ID ±¸ÇÏ±â
 */
function getObjectId(obj) {
	var objectId = getObjectAttribute(obj, "id");
	return objectId;
}


/**
 * °´Ã¼¸¦ ¸Ç À§·Î À§Ä¡ÇÏ±â
 */
var makeOnTopCount = 0; 
function makeOnTop(obj) {
	if (obj) {
		var daiz;
		var max = 0;
		var da = null;
		if (browserType == "IE") {
			da = document.all;
		}
		else if (browserType == "NE") {
			da = document.getElementsByTagName("div");
		}

		makeOnTopCount += 1;
		obj.style.zIndex  = da.length + makeOnTopCount;
	}
}


/**
 * AttributeÀÇ Value ÃßÃâ (name=value ¿¡¼­ value ÃßÃâ
 */
function getAttributeValue(attr, name) {
	attr = nullToEmpty(attr).toLowerCase();
	var value = "";
	if (attr.length > 1) {
		var idx1 = attr.indexOf(name);
		if (idx1 != -1) {
			var idx2 = attr.indexOf("=",idx1);
			if (idx2 != -1) {
				var idx3 = attr.indexOf(",",idx2);
				var oValue = "";
				if (idx3 == -1) {
					oValue = attr.substring(idx2+1);
				}
				else {
					oValue = attr.substring(idx2+1,idx3);
				}
				for (var i = 0; i < oValue.length; i++) {
					if (oValue.charCodeAt(i) != 32) {
						value += oValue.charAt(i);
					}
				}

			}
		}
		
	}
	return value;
}


/**
 * ÀÌ¹ÌÁö º¯°æ
 */
function changeImage(imgObj, imgSrc) {
	imgObj.src = imgSrc;
}


/**
 * ¹®ÀÚ¿­¿¡¼­ ±¸ºÐÀÚ·Î ºÐÀÚ¿­ ºÐ¸®ÇÏ±â
 * @param str		¹®ÀÚ¿­
 * @param idx		±¸ºÐÀÚ¸¦ ±âÁØÀ¸·Î n¹øÂ° ¹®ÀÚ¿­ ÃßÃâ
 * @param divideStr ±¸ºÐ¹®ÀÚ
 */
function getDivideString(str, idx, divideChar) {
	var result = "";
	if (nullToEmpty(str) != "") {
		var strArr = str.split(divideChar);
		result = strArr[idx-1];
	}

	if (!result) {
		result = "";
	}
	
	return result;
}


/**
 * null °ªÀ» ""À¸·Î º¯È¯
 */
function nullToEmpty(value) {
	if (value == null) {
		value = "";
	}
	return value;
}


/**
 * URL ¿£ÄÚµù
 */
function getUrlEncode(url) {
	var result = "";
	if (nullToEmpty(url) != "") {
		result = encodeURIComponent(url);
		result = result.replace(/\%/g,'*');
	}
	return result;
}


/**
 * URL µðÄÚµù
 */
function getUrlDecode(url) {
	var result = "";
	if (nullToEmpty(url) != "") {
		result = url.replace(/\*/g,'%');
		result = decodeURIComponent(result);
	}
	return result;
}


/**
 * ÆÄÀÏÀÇ È®Àå¸í ¹ÝÈ¯
 */
function getFileExtention(fileName) {
	var ext = "";
	
	if (nullToEmpty(fileName) != "") {
		var idx = fileName.lastIndexOf(".");
		if (idx > -1) {
			ext = (fileName.substring(idx+1)).toLowerCase();
		}
	}
	
	return ext;
}

/**
 * ÀÌ¹ÌÁö width º¯°æ
 * È£Ãâ¹æ¹ý
	onload = goComplete;
	var imgObjId = "attach_picture";
	var maxImgWidth = 675;
	function goComplete() {
		imgReSize();
	}
 */
function imgReSize(imgObj, maxImgWidth) {
	while(true) {
		if(imgObj.length) {
			for(var i=0; i<imgObj.length; i++) {
				var imgPerObj = imgObj[i];
				if(imgPerObj == null) {
					setTimeout("imgReSize", 500);
				} else {
					if(imgPerObj.width >= maxImgWidth) {
						imgPerObj.width = maxImgWidth;
					}
				}
			}
			break;
		} else {
			if(imgObj == null) {
				setTimeout("imgReSize", 500);
			} else {
				if(imgObj.width >= maxImgWidth) {
					imgObj.width = maxImgWidth;
				}
				break;
			}		
		}
	}
}

/**
* ÄíÅ°°ª Ã³¸®
*/
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if(endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen) {
		var j = i + alen;
		if(document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0) {
			break;
		}
	}
	return null;
}
/*
function SetCookie(name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}*/
function setCookie(name, value, expiredays) {
		var todayDate = new Date();
		todayDate.setDate(todayDate.getDate() + expiredays);
		document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
	}
