/**
 * prevent no console error
 */
if (!console) {
	var console = {
		log: function () { }
	}
}
/*
 * Prototypes
 */
String.prototype.trim = function()
{
	return this.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '');
}
/**
 * @added by eseom
 * Makeshop EC solution script constructor
 */
function Makeshop() {}
var makeshop = new Makeshop();
Makeshop.prototype.setVariable = function (obj) {
	for (var i in obj) {
		this[i] = obj[i];
	}
}
Makeshop.prototype.createFlash = function (movie, w, h, ids, flashvars) {
	var strflash = '<object id="' + ids + '" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" height="' + h + '" width="' + w + '" align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">';
	strflash += '<param name="_cx" value="25400">';
	strflash += '<param name="_cy" value="9260">';
	strflash += '<param name="flashvars" value="' + flashvars + '">';
	strflash += '<param name="movie" value="'+movie+'">';
	strflash += '<param name="src" value="'+movie+'">';
	strflash += '<param name="wmode" value="transparent">';
	strflash += '<param name="play" value="-1">';
	strflash += '<param name="loop" value="-1">';
	strflash += '<param name="quality" value="high">';
	strflash += '<param name="salign" value="">';
	strflash += '<param name="menu" value="-1">';
	strflash += '<param name="base" value="">';
	strflash += '<param name="allowscriptaccess" value="samedomain">';
	strflash += '<param name="scale" value="showall">';
	strflash += '<param name="devicefont" value="0">';
	strflash += '<param name="embedmovie" value="0">';
	strflash += '<param name="bgcolor" value="">';
	strflash += '<param name="swremote" value="">';
	strflash += '<param name="moviedata" value="">';
	strflash += '<param name="seamlesstabbing" value="1">';
	strflash += '<param name="profile" value="0">';
	strflash += '<param name="profileaddress" value="">';
	strflash += '<param name="profileport" value="0">';
	strflash += '<embed src="' + movie + '" quality="high" wmode="transparent" width="' + w+'" height="'+h+'" name="'+ids+'" align="middle" allowscriptaccess="samedomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	strflash += '</object>';
	document.write(strflash);
}
Makeshop.prototype.bookmarksite = function(title,url) {
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url, "");
	} else if(window.opera && window.print)  { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) {
		window.external.AddFavorite(url, title);
	}
}
Makeshop.prototype.popupIt = function (obj) {
	var popupHeight = parseInt(obj.height, 10) + 21;
	/**
     * popup
     */
	if (obj.type == 'P') {
		var popup = window.open('/Popup/'+this.lang+'/view/idx/'+obj.idx, 'popup'+obj.code, 'width='+obj.width+',height='+popupHeight+',scrollbars='+(obj.scroll == 1 ? 'auto' : 'no')+',resizable='+(obj.resizable == 'T' ? 'yes' : 'no')+',status=yes,top='+obj.top+',left='+obj.left);
		if (popup) {
			popup.focus();
		}
	}
	/**
     * layer
     */
	if (obj.type == 'L') {
		var otherWidth = $(window).width() - 945;
		var autoLeft = parseInt(obj.left) + (otherWidth / 2);
		$('body').append('<div id="code'+obj.code+'" class="bindPopup" style="z-index: '+obj.code+'; position: absolute; top: '+obj.top+'px; left: '+autoLeft+'px; width: '+obj.width+'px; height: '+popupHeight+'px;"></div>');
		if (obj.scroll == 1) {
			$('#code'+obj.code).css('overflow', 'auto');
		}
		var thisLIP = this.LIP;
		$.ajax({
			url: '/Popup/'+this.lang+'/view/idx/'+obj.idx,
			type: 'post',
			data: {
				post: true
			},
			dataType: 'html',
			success: function(response) {
				$('#code'+obj.code).html('<div style="width: '+obj.width+'px; height: '+obj.height+'px;">'+response+'</div>');
				var closeHtml = '';
				closeHtml += '<div style="text-align: right; background-color: #313031; margin: 0 0 0 0; height: 21px;">';
				if (obj.expire > 0) {
					closeHtml += '<span style="font-size: 12px; color: rgb(255, 255, 255);">창을 '+obj.expire+'일 동안 열지 않음</span>';
					closeHtml += '<input type="checkbox" name="closeCheck" style="visibility: visible; margin-bottom: -1px;">';
				}
				closeHtml += '<a href="#" class="bindClose"><img border="0" src="'+thisLIP+'/btn_close.gif" style="margin: 0px 6px -2px 2px;"></a>';
				closeHtml += '</div>';
				$('#code'+obj.code).append(closeHtml);

				$('#code'+obj.code+' a.bindClose').click(function() {
					if (obj.expire == 0) {
						makeshop.popupCookie(obj.code, 365);
					} else if (obj.expire > 0) {
						if ($('input[name=closeCheck]').is(':checked')) {
							makeshop.popupCookie(obj.code, obj.expire);
						}
					}
					$(this).parents('div.bindPopup').remove();

					return false;
				});
			}
		});
		
		
	}
}
Makeshop.prototype.popupCookie = function(code, expire) {
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate()+expire);
	var expireTime = todayDate.getTime();

	var cookieContents = makeshop.getCookie('popupInformation');
	if (!cookieContents) {
		var popupObject = {};
	} else {
		var popupObject = unserialize(cookieContents);
	}

	popupObject[code] = expireTime;
	var popupString = serialize(popupObject);
	makeshop.setCookie('popupInformation', popupString, 365);
}
Makeshop.prototype.getCookie = function(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}

	return unescape(dc.substring(begin + prefix.length, end));
}
Makeshop.prototype.setCookie = function(name,value,expiredays) {
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate()+expiredays);
	document.cookie = name+"="+escape(value)+"; path=/; expires=" + todayDate.toGMTString() + ";";
}


// 상품 이미지 확대보기
Makeshop.prototype.zoom = function (ref, title, w, h) {
	var window_left = (screen.width-640)/2;
	var window_top = (screen.height-550)/2;
	zoom_popup=window.open(ref,title,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=' + w + ',height=' + h + ',top=' + window_top + ',left=' + window_left + '');
	zoom_popup.focus();
}

Makeshop.prototype.addfavorite = function (href, title) {
	browserName = navigator.appName;
	browserVer = parseInt(navigator.appVersion);
	if (browserName == "Microsoft Internet Explorer" && browserVer >= 4) {
		window.external.AddFavorite(href, title);
	}
}

Makeshop.prototype.commPopupOpen = function (ret, name, w, h) {
	var window_left = (screen.width-750)/2;
	var window_top = (screen.height-850)/2;
	name = window.open(ret,name,'width=' + w + ', height=' + h + ', scrollbars=yes, resizable=no, status=no,top=' + window_top + ',left=' + window_left + '');
	name.focus();
}

Makeshop.prototype.downloadCoupon = function (cid) {
	var parentobject = this;
	$.ajax({
		url : '/Product/Detail/Ajax/' + this.lang + '/XHRdownloadCoupon/cid/' + cid,
		type : 'post',
		success : function( ret ) {
			switch ( ret ) {
				case 'NOT_LOGIN' :
					alert('로그인을 해주세요.');
					location.replace('/Member/Auth/' + parentobject.lang + '/login' + window.location.href.replace(/http\:\/\/(.*?)\//, '/'));
					return false;
					break;
				case 'INVALID' :
					alert('유효하지 않은 쿠폰입니다.');
					return false;
					break;
				case 'EXIST' :
					alert('이미 존재하는 쿠폰입니다.');
					return false;
					break;
				default :
					eval('ret = (' + ret + ')');

					if ( ret.coupon_idx == cid ) {
						alert('쿠폰이 발급되었습니다.');
					} else {
						alert('쿠폰 발급에 실패했습니다.');
					}
					break;
			}
		}
	});
}
