/*  Gmarket JavaScript Library, web real version
/*--------------------------------------------------------------------------*/
function GMKT(){
	this.version = 'web real version';
}

GMKT.prototype.onload = function(_func){
	var _oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = _func;
	}else {
		window.onload = function(){
			_oldonload();
			_func();
		}
	}
}

GMKT.prototype.onresize = function(_func){
	var _oldresize = window.onresize;
	if (typeof window.onresize != 'function'){
		window.onresize = _func;
	}else {
		window.onresize = function(){
			_oldresize();
			_func();
		}
	}
}


GMKT.prototype.onscroll = function(_func){
	var _oldscroll = window.onscroll;
	if (typeof window.onscroll != 'function'){
		window.onscroll = _func;
	}else {
		window.onscroll = function(){
			_oldscroll();
			_func();
		}
	}
}


/*
	gmkt Class

	gmkt.onload()
	gmkt.onresize()
*/
var gmkt = new GMKT();

if (!$) {
	var $ = function() {
		var results = [],element;
		for (var i = 0;i < arguments.length;i++){
			element = arguments[i];
			if(typeof element == 'string')
				element = document.getElementById(element);
			results.push(element);
		}
		return results.length < 2 ? results[0] : results;
	}
};

/*
	browser check
*/
var browser = {
	version : parseInt(navigator.appVersion),
	isNetscape : navigator.appName.indexOf("Netscape") != -1,
	isMicrosoft : navigator.appName.indexOf("Microsoft") != -1
};

var objPosition = function(obj){
	var results={top:0,left:0};
	while (obj.offsetParent){
		results.top = results.top + obj.offsetTop;
		results.left = results.left + obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return results;
};


/* standard table offsetTop, offserLeft  */
function fnStandardPosition(){
	var standard_table = $("standard_table").lastChild;
	return objPosition(standard_table);
}

/*
	getElementsByName alternative
	1 parameter
*/

var $n = function(){
	var element;
	element = document.getElementsByName(arguments[0]);
	return element;
};


String.prototype.byte = function(){

	var cnt = 0;
	var chr = "";

	for( var i = 0; i < this.length; i++)
	{
		chr = this.charAt(i);
		if( escape( chr ).length > 4 ){
			cnt += 2;
		}else{
			cnt++;
		}
	}

	return cnt;
}

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 autoNextTextFocus(beforeText, sLength, afterText) {
	if (beforeText.value.length == sLength) {
		document.getElementsByName(afterText)[0].focus();
	}
}

function changeFormatToNum(sValue)
{
	return sValue.replace(/,/gi, "");
}

function changeFormatToComma(num){
	var isNegative, i, strNum, strReturn;

	strNum = num.toString();
	strReturn = "";

	isNegative = false;
	
	if (strNum.substr(0, 1) == "-") {
		isNegative = true;
		strNum = strNum.substr(1);
	}
	
	if (strNum.length >= 3) {
		for (i = parseInt((strNum.length - 1) / 3); i >= 0 ; i--) {

			if (strNum.length >= 3){
				strReturn = "," + strNum.substr(strNum.length - 3) + strReturn;	
				strNum = strNum.substring(0, strNum.length - 3);
			}
			else {
				strReturn = "," + strNum + strReturn;	
				strNum = "";
			}
		}
		strReturn = strReturn.substr(1);
	}
	else {
		strReturn = strNum;
	}

	if (isNegative) {
		strReturn = "-" + strReturn;
	}

	return strReturn;
}

/* Add Bookmarkt(IE, FF, Opera) */
function addBookmark(title,url) {
	if (window.sidebar) // firefox 
	   window.sidebar.addPanel(title, url, ""); 
	else if(document.all) // ie
		window.external.AddFavorite(url, title);
	else 
		alert("Press Ctrl - D to bookmark");
}

/* dynamic resizing for popup window */
function popupWindowResize()
{
	var clientAgent = getUserAgentName();
	/* for IE */
	/*@cc_on @*/
	/*@if (@_win32)
		var winBody = self.document.body;
		var marginHeight = parseInt(winBody.topMargin) + parseInt(winBody.bottomMargin);
		var marginWidth = parseInt(winBody.leftMargin) + parseInt(winBody.rightMargin);
		var thisWidth = winBody.scrollWidth + (winBody.offsetWidth - winBody.clientWidth) + marginWidth -2;
		var thisHeight = winBody.scrollHeight + (winBody.offsetHeight - winBody.clientHeight) + marginHeight + 20;

	@else @*/
		if( clientAgent == "FF" ){
			var marginHeight = 0;
			var marginWidth = 0;
			var thisWidth = self.document.documentElement.childNodes.item(1).scrollWidth + 9;//window.screen.availHeight;
			var thisHeight = self.document.documentElement.childNodes.item(1).scrollHeight;
		}else if( clientAgent == "OP" ){
			var marginHeight = 0;
			var marginWidth = 0;
			var thisWidth = self.document.documentElement.scrollWidth + 25;//window.screen.availHeight;
			var thisHeight = self.document.documentElement.scrollHeight + 30;
		}
	/*@end @*/

	self.resizeTo(thisWidth, thisHeight);
}

/*--------------------------------------------------------------------------*/
// gInitHelper Class (for onload event queuing)
/*
(example)

gInitHelper().addHandler(function()
{
	document.getElementById("test").innerText = "document loading completed...";
});
*/
/*--------------------------------------------------------------------------*/
(function(window, undefined)
{
	// Define a local copy of gInitHelper
	var gInitHelper = function()
	{
		return gInitHelper.fn.init();
	},

	document = window.document,

	_singleton,

	// Has the ready events already been bound?
		readyBound = false,

	// The functions to execute on DOM ready
		readyList = [],

	// The ready event handler
	DOMContentLoaded;

	gInitHelper.fn = gInitHelper.prototype =
	{
		init: function()
		{
			return this;
		},

		addHandler: function(fn)
		{
			// Attach the listeners
			this.bindReady();

			// If the DOM is already ready
			if (_singleton.isReady)
			{
			// Execute the function immediately
			fn.call(document);

			// Otherwise, remember the function for later
			} else if (readyList)
			{
				// Add the function to the wait list
				readyList.push(fn);
			}

			return this;
		},

		// Handle when the DOM is ready
		ready: function()
		{
			// Make sure that the DOM is not already loaded
			if (!_singleton.isReady)
			{
				// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
				if (!document.body)
				{
					return setTimeout(_singleton.ready, 13);
				}

				// Remember that the DOM is ready
				_singleton.isReady = true;

				// If there are functions bound, to execute
				if (readyList)
				{
					// Execute all of them
					var fn, i = 0;
					while ((fn = readyList[i++]))
					{
						fn.call(document);
					}

					// Reset the list of functions
					readyList = null;
				}
			}
		},

		bindReady: function()
		{
			if (readyBound)
			{
			return;
			}

			readyBound = true;

			// Catch cases where $(document).ready() is called after the
			// browser event has already occurred.
			if (document.readyState === "complete")
			{
			return _singleton.ready();
			}

			// Mozilla, Opera and webkit nightlies currently support this event
			if (document.addEventListener)
			{
			// Use the handy event callback
			document.addEventListener("DOMContentLoaded", DOMContentLoaded, false);

			// A fallback to window.onload, that will always work
			window.addEventListener("load", _singleton.ready, false);

			// If IE event model is used
			}
			else if (document.attachEvent)
			{
			// ensure firing before onload,
			// maybe late but safe also for iframes
			document.attachEvent("onreadystatechange", DOMContentLoaded);

			// A fallback to window.onload, that will always work
			window.attachEvent("onload", _singleton.ready);

			// If IE and not a frame
			// continually check to see if the document is ready
			var toplevel = false;

			try
			{
				toplevel = window.frameElement == null;
			} catch (e) { }
			}
		}
	};

	// All gInitHelper objects should point back to these
	_singleton = gInitHelper();

	// Cleanup functions for the document ready method
	if (document.addEventListener)
	{
		DOMContentLoaded = function()
		{
			document.removeEventListener("DOMContentLoaded", DOMContentLoaded, false);
			_singleton.ready();
		};

	} else if (document.attachEvent)
	{
		DOMContentLoaded = function()
		{
			// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
			if (document.readyState === "complete")
			{
			document.detachEvent("onreadystatechange", DOMContentLoaded);
			_singleton.ready();
			}
		};
	}

	window.gInitHelper = gInitHelper;

})(window);
