





function isEmpty(val) {
    if(val == null || val == '' || val == undefined || val == 'undefined')
        return true;

    return false;
}

function login() {
    var returnUrl = (document.location.href).substr(0,(document.location.href).indexOf('#'))
    var kyoboLoginUrl = 'http://www.kyobobook.co.kr/login/LoginHot.jsp?returnUrl=' + escape(returnUrl);
    
    document.location.href = kyoboLoginUrl;
}

function needLogin() {
    if (confirm('로그인하셔야합니다. 로그인하시겠습니까?')) {
        var kyoboLoginUrl = 'http://www.kyobobook.co.kr/login/LoginHot.jsp?returnUrl=' + escape(document.location.href);
        document.location.href = kyoboLoginUrl;
            
        return true;
    } else {
        return false;
    }
}

function goTopBooklog() {
    
    
    alert('먼저 로그인 하셔야 합니다.');
    
}

function clickFloatingEvent(eventId, iconSequence, urlHash) {
    
        if (needLogin()) {
            $('img#eventFloatingIcon').hide();
        }
    
    
}

function productPreview(barcode, ctgrId) {
    var url = "/ht/product/popupDetail?barcode=" + barcode;
    if (isEmpty(ctgrId) == false) {
        url += "&ctgrId="+ctgrId;
    }
    
    window.open(url, "", "width=800, height=600, scrollbars=yes");
}

function productSimpleViewRecord(sellPrdtBcode) {
    var url = "/ht/product/productSimpleViewRecord/"+sellPrdtBcode;

    window.open(url, "", "width=800, height=437, scrollbars=yes");
}

function productSimpleViewDvd(sellPrdtBcode) {
    var url = "/ht/product/productSimpleViewDvd/"+sellPrdtBcode;
   
    window.open(url, "", "width=800, height=520, scrollbars=yes");
}

function price_format(val){
    val = $.trim(val+"");
    if(val == ''){ return val; }
    if(isNaN(val)){ return val; }

    var rv = "", idx = 0;
    for(var i = val.length-1 ; i >= 0 ; i--){
        rv = ((idx != 0 && idx%3 == 0) ? val.substring(i, i+1) + "," : val.substring(i, i+1)) + rv;
        idx++;
    }
    
    return rv;
}

jQuery(function($) {
    $('input.inputNumberText').keypress(function(event) {
        if (event.which != 13) {
            if (event.which < 48 || event.which > 57) {
                event.preventDefault();
            }
        }
    });
    
    $("a.goIEClipboard").each(function(){
        if(navigator.userAgent.toLowerCase().indexOf('msie')!=-1){
            $("a.goIEClipboard").show();
        }else{
            $("a.goIEClipboard").hide();
        }
    });
});

function goTwitter(msg,url) {
    var href = "http://twitter.com/home?status=" + encodeURIComponent(msg) + " " + encodeURIComponent(url);
    window.open(href, 'twitter', '');
}

function goFaceBook(msg,url) {
    var href = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(url) + "&t=" + encodeURIComponent(msg);
    window.open(href, 'facebook', '');
}

function goIEClipboard(msg) {
    if (window.clipboardData){
        var result = window.clipboardData.setData('text', msg);
        if(result){ 
            alert("복사되었습니다.\n붙여넣기(Ctrl+V)하여 사용하세요.");
        }
    }
}

function coupondown(couponId) {
    $.ajax({
        type: "POST"
        ,url:"/ht/coupon/productCouponDown"
        ,dataType: 'json'
        ,data : {couponId : couponId}
        ,success: function(data) {
            if (data.save) {
                alert("쿠폰이 다운로드 되었습니다.");
            } else {
                alert(data.errorMessage);
            }
        }
        ,error: function() {
            alert('시스템 오류가 발생 했습니다. 관리자에게 문의 하세요.');
        }
    });
}

function goValidEscrow(mertid){
 var strMertid = mertid; 
 window.open("https://pgweb.dacom.net/pg/wmp/mertadmin/jsp/mertservice/s_escrowYn.jsp?mertid="+strMertid,"check","width=339, height=263, scrollbars=no, left = 200, top = 50");  
}

var sslHost = "https://www.hottracks.co.kr";
function buyMusicGiftForDownload(prdtBcode, prdtCount){
	if(typeof prdtCount == "undefined" || prdtCount == 0) {
		prdtCount = 1;
	}
	
    // 바로 주문
	$.ajax({
        type: "POST"
        ,url: "/ht/order/quickOrder"
        ,dataType: "json"
        ,data : {
        	sellPrdtBcode : prdtBcode
        	, prdtCount : prdtCount
        }
        ,success : function(data){
            if(data.save) {
            	location.href= sslHost + "/ht/order/musicOrderSheet";
            } else {
                var errorMessages = data.errorMessages;
                alert(errorMessages.join("\n"));
            }
        } 
        ,error: function(data) {
            alert('시스템 오류가 발생 했습니다. 관리자에게 문의 하세요.');
        }
    });
}

