/**
 * jQuery Common 1.0
 * 
 * Copyright (c) 1999~2009 DoubleU Two Communications Inc.
 * 
 * http://www.w2.co.kr, www.w2dev.net
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *   
 * Last Update 2009-10-26
 * 
 */


/**
 * w2dev utility
 */
(function($){
	
	// 해당  js load
	//$.getScript('/js/link.js');
	$.getScript('/js/jquery-ui.js');
	//$.getScript('/js/scroll.js');
	/**
	 * cookie
	 * get : $.cookie(key)
	 * set : $.cookie(key, value, [options])
	 */
	$.cookie = function(key, value, options) {
		if (arguments.length > 1) {
			var o = $.extend({}, $.cookieOptions, options);
	        if (value === null || value === undefined) {
	            value = '';
	            o.expires = -1;
	        }
	        if (o.expires.constructor != Date) {
				var today = new Date();
				today.setDate(today.getDate() + o.expires);
				o.expires = today;
			}
			// Create the cookie string
			document.cookie = 
				key + '=' + value +
				'; expires=' + o.expires.toUTCString() +
				(o.path? '; path=' + (o.path) : '') +
				(o.domain? '; domain=' + (o.domain) : '') +
				(o.secure? '; secure' : '');
		} else {
			if (result = new RegExp(key + '=(.*?)(?:;|$)').exec(document.cookie))
				return decodeURIComponent(result[1]);
			return '';
		}
	};
	$.cookieOptions = {
		expires: 365,
		path: '/'
	};

	/**
	 * return $.screen.width = number, $.screen.height = number
	 */
	$.screen = function() {
		var x = window.innerWidth + window.scrollMaxX || document.body.scrollWidth || document.body.offsetWidth;
		var y = window.innerHeight + window.scrollMaxY || document.body.scrollHeight || document.body.offsetHeight;
		var w = document.documentElement.clientWidth || document.body.clientWidth;
		var h = document.documentElement.clientHeight || document.body.clientHeight;
		return { width: (x < w) ? x : w, height: (y < h) ? h : y };
	};

	
	/**
	 * String prototype extend
	 */
	var stringPrototype = {
		trim: function() {
			return this.replace(/(^\s+)|(\s+$)/g, '');
		},
		
		num: function() {
			return this.trim().replace(/[^0-9]/g, '');
		},
		
		money: function() {
			var num = this.trim();
			while(/(-?[0-9]+)([0-9]{3})/.test(num)) {
				num = num.replace(/(-?[0-9]+)([0-9]{3})/, '$1,$2');
			}
			return num;
		},
		
		isNum: function() {
			return (/[0-9]/g).test(this);
		},
		
		isEmail: function() {
			return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(this.trim());
		},
		
		isPhone: function(dash) {
			var dash = dash || '';
			return eval("(/(02|0[1|3-9]{1}[0-9]{1})" + dash + "[1-9]{1}[0-9]{2,3}" + dash + "[0-9]{4}$/).test(this)");
		}
	};
	
	$.extend(String.prototype, stringPrototype);
	
	/**
	 * 숫자만 입력 받기
	 */
	$.fn.onlyNum = function() {
		return this.each(
			function() {
				$(this).css({imeMode: 'disabled'}).keypress(
					function(e) {
						if(e.keyCode < 48 || e.keyCode > 57) {
							e.preventDefault();
						}
					}
				);
			}
		);
	};
	
	/**
	 * 전화번호 형식으로 변환하기
	 */
	$.fn.replacePhone = function() {
		return this.each(
			function() {
				if(/(02|[0-9]{3})([0-9]{3,4})([0-9]{4})/.test($(this).text())) {
					$(this).text($(this).text().replace(/(02|[0-9]{3})([0-9]{3,4})([0-9]{4})/, '$1-$2-$3'));
				}
			}
		);
	};

	/**
	 * iframe upload
	 */
	$.fn.fileUpload = function(url) {
		return $(this).each(function() {
			var frame = $('<iframe frameborder="0" name="file" src="' + url + '"></iframe>');
			frame.insertAfter($(this)).css({
				width: $(this).width(),
				height: $(this).height(),
				overflow: 'hidden',
				zIndex: 99,
				position: 'absolute',
				marginLeft: -($(this).width()),
				opacity: 0
			});
		});
	}


	
})(jQuery);

// flashWrite(파일경로, 가로, 세로, 아이디, 배경색, 변수, 윈도우모드)
function flashWrite(url,w,h,id,bg,vars,win){
	var flashStr = 
		"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
		"<param name='allowScriptAccess' value='sameDomain' />"+
		"<param name='allowFullScreen' value='false' />"+
		"<param name='movie' value='"+url+"' />"+
		"<param name='wmode' value='"+win+"' />"+
		"<param name='quality' value='high' />"+
		"<param name='bgcolor' value='#ffffff' />"+
		"<embed wmode='"+win+"' src='"+url+"' quality='high' bgcolor='#ffffff' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
		"</object>";
	document.write(flashStr);

}

function flashMenu(url,w,h,id,bg,vars,win){
	return "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
		"<param name='allowScriptAccess' value='sameDomain' />"+
		"<param name='allowFullScreen' value='false' />"+
		"<param name='movie' value='"+url+"' />"+
		"<param name='wmode' value='"+win+"' />"+
		"<param name='quality' value='high' />"+
		"<param name='bgcolor' value='#ffffff' />"+
		"<embed wmode='"+win+"' src='"+url+"' quality='high' bgcolor='#ffffff' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
		"</object>";
}

function goTop(orix,oriy,desx,desy) {
	var Timer;
	var winHeight = document.body.scrollTop;
	if(Timer) clearTimeout(Timer);
	startx = 0;
	starty = winHeight;
	if(!orix || orix < 0) orix = 0;
	if(!oriy || oriy < 0) oriy = 0;
	var speed = 7;
	if(!desx) desx = 0 + startx;
	if(!desy) desy = 0 + starty;
	desx += (orix - startx) / speed;
	if (desx < 0) desx = 0;
	desy += (oriy - starty) / speed;
	if (desy < 0) desy = 0;
	var posX = Math.ceil(desx);
	var posY = Math.ceil(desy);
	window.scrollTo(posX, posY);
	if((Math.floor(Math.abs(startx - orix)) < 2) && (Math.floor(Math.abs(starty - oriy)) < 2)){
		clearTimeout(Timer);
		window.scroll(orix,oriy);
	}else if(posX != orix || posY != oriy){
		Timer = setTimeout("goTop("+orix+","+oriy+","+desx+","+desy+")",15);
	}else{
		clearTimeout(Timer);
	}
}

function writeObjMovie(f_uri,f_width,f_height,lan){
	document.write("<object name='MediaPlayer1' id='MediaPlayer1' width='"+f_width+"' height='"+f_height+"' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=6,4,7,1112' standby='loading windows media player components...' type='application/x-oleobject'>");
	document.write("<param name='URL' value='"+f_uri+"'>");
	document.write("<param name='uiMode'   value='none' >");
	document.write("<param name='AutoStart' value='True'>");
	document.write("<param name='showstatusbar' value='True'>");
	document.write("<EMBED TYPE='application/x-mplayer2' SRC='"+f_uri+"' NAME='mplay1' WIDTH='"+f_width+"' HEIGHT='"+f_height+"'></EMBED>");
	document.write("</object>");
}

function writeObjMovie1(f_uri,f_width,f_height,lan){
	document.write("<object name='MediaPlayer1' id='MediaPlayer1' width='"+f_width+"' height='"+f_height+"' classid='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=6,4,7,1112' standby='loading windows media player components...' type='application/x-oleobject'>");
	document.write("<param name='filename' value='"+f_uri+"'>");
	document.write("<param name='autostart'   value='true' >");
	document.write("<param name='showcontrols' value='0'>");
	document.write("<param name='showstatusbar' value='1'>");
	document.write("<param name='enablecontextmenu' value='false'>");
	document.write("<param name='transparentatstart' value='true'>");
	document.write("<param name='transparentonstop' value='true'>");
	document.write("<EMBED TYPE='application/x-mplayer2' SRC='"+f_uri+"' NAME='mplay1' WIDTH='"+f_width+"' HEIGHT='"+f_height+"'></EMBED>");
	document.write("</object>");
}

function goPrint() {
	window.open("/kor/06util/page_print.jsp","_print","resizable=no, width=762, height=745, top=50, left=50 ,scrollbars=yes");
}

function resizeIframe() {
    	$('#extContent').css('height',$('#extContent').contents().find('.product_box_contents_area').height());
};