var Link = window.location.pathname + window.location.search;
var LogOnUrl = "https://auth.hiliving.co.kr/M/LogOn?link=" + encodeURIComponent(Link) + "&site_url=http://m.hiliving.co.kr";
function goLogon(){
window.location.href = LogOnUrl;
}
function IsLogin(){
var result = true;
$.ajax({
type: "POST",
url: '/Common/IsLogin',
cache:false,
async: false,
success: function (data) {
result = data;
}
});
return result;
}
function mainload() {
window.location.href ="http://m.hiliving.co.kr";
}
function IsMyRoomLogin(){
var result = false;
$.ajax({
type: "POST",
url: '/Common/IsMyRoomLogin',
cache:false,
async: false,
success: function (data) {
result = data;
}
});
return result;
}
// toast 메세지 기본값을 셋팅합니다.
var toast = function (text, icon) {
iconOption = "";
switch (icon) {
case "info":
case "warning":
case "success":
case "error":
icon = icon;
break;
default:
icon = "";
break;
}
$.toast({
text: text,
icon: icon,
showHideTransition: 'fade',
hideAfter: 1500,
position: 'mid-center',
loader: false
});
}
var cookieList = function (cookieName) {
var cookie = $.cookie(cookieName);
var items = cookie ? cookie.split(/,/) : new Array();
return {
"add": function (val) {
indx = items.indexOf(val);
if (indx == -1) items.push(val);
$.cookie(cookieName, items.join(','), { expires: 30 });
},
"remove": function (val) {
indx = items.indexOf(val);
if (indx != -1) items.splice(indx, 1);
$.cookie(cookieName, items.join(','), { expires: 30 });
},
"clear": function () {
items = new Array();
$.cookie(cookieName, "");
},
"items": function () {
return items;
}
}
}
// 기획전/이벤트에서 사용되는 함수 값입니다.
function show(elementId) {
var element = document.getElementById(elementId);
if (element) {
element.style.visibility = "visible";
}
}
// 기획전/이벤트에서 사용되는 함수 값입니다.
function hide(elementId) {
var element = document.getElementById(elementId);
if (element) {
element.style.visibility = "hidden";
}
}
function post(path, params, method) {
method = method || "post"; // Set method to post by default if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
return false;
}
String.format = function () {
// The string containing the format items (e.g. "{0}")
// will and always has to be the first argument.
var theString = arguments[0];
// start with the second argument (i = 1)
for (var i = 1; i < arguments.length; i++) {
// "gm" = RegEx options for Global search (more than one instance)
// and for Multiline search
var regEx = new RegExp("\\{" + (i - 1) + "\\}", "gm");
theString = theString.replace(regEx, arguments[i]);
}
return theString;
}
//찜하기 레이어 팝업 이벤트
function wrapWindowByMask3(top) {
// 레이어 팝업을 가운데로 띄우기 위해 화면의 높이와 너비의 가운데 값과 스크롤 값을 더하여 변수로 만듭니다.
var left = ($(window).scrollLeft() + ($(window).width() - $('.window2').width()) / 2);
// css 스타일을 변경합니다.
$('.window3').css({ 'left': 0, 'top': 0, 'bottom': 0, 'position': 'fixed','z-index':'1050' });
// 레이어 팝업을 띄웁니다.
$('.window3').show("slide", { direction: "left" }, 300);
}
function goWish(goodCode, idx)
{
if (IsLogin()) {
//레이어 작동 시 스크롤 방지
$('html, body').css({ 'overflow': 'hidden', 'height': '100%' }); // 모달팝업 중 html,body의 scroll을 hidden시킴
$('body').on('scroll touchmove mousewheel', function (event) { // 터치무브와 마우스휠 스크롤 방지
event.preventDefault();
event.stopPropagation();
return false;
});
//레이어 동작
wrapWindowByMask3(0);
var data = { "goodcode": goodCode };
$.ajaxSettings.traditional = true;
$.ajax({
type: "GET"
, url: "/Common/ChoiceGoods"
, data: data
//, dataType: "json"
, success: function (data) {
$(".window3").empty();
$(".window3").append(data);
zIndex = 1050;
if (idx != null && idx > 0) {
zIndex = idx;
}
zIndex = 1050;
$(".window3").css({"height": "100%","z-index": zIndex });
$(".window3").off('scroll touchmove mousewheel'); // 터치무브 및 마우스휠 스크롤 가능
}, error: function (error, status, request) {
errorBox(request.responseText);
}
});
} else {
goLogon();
}
}
function goDetail(good_code) {
window.location.href = "/Goods/Details?goodcode="+good_code;
}
//최근 구매내역 결제하기
$("#RecentBuyList_BUY").click(function(){
var check_list = $("input[name*='buy_list_']:checked");
if(check_list.length==""){
infoBox('선택한 상품이 없습니다')
return false;
}
var goodcode =''; var good_count='';
check_list.each(function(){
goodcode+=$(this).val()+',';
good_count+='1'+','
});
goodcode = goodcode.substr(0,goodcode.length-1);
good_count = good_count.substr(0,good_count.length-1);
goOrder(goodcode,'',good_count);
});
var medicalMessage = ""
medicalMessage = medicalMessage + "본 상품코드는 자가소비용 상품코드입니다.
";
medicalMessage = medicalMessage + "의료기관에 판매 할 경우 반드시 ‘의료기기 보고용’으로 주문 해 주시기 바랍니다.
";
medicalMessage = medicalMessage + "본 상품 코드로 구매 후 의료기관에 판매 할 경우 법적 문제가 발생 할 수 있으며, 그 책임은 구입 한 회원에게 있습니다.
";
medicalMessage = medicalMessage + "동의하시겠습니까 ?
";
// 상품코드만 입력시 장바구니 등록
// 쿠폰 상품의 경우 쿠폰 코드 입력
// 수량은 1이 아닌 경우만 입력
function goCart(good_code, coupon_code, good_count, goOption,isOption, comment) {
console.log("goCart comment = " + comment);
if (IsLogin()) {
$.ajax({
type: "GET",
url: '/Goods/IsMedicalGoods',
data: { goodCode : good_code },
success: function (data) {
//console.log(" data = [" + data + "]");
confirmValue = "1";
if (data == "1") {
//console.log(medicalMessage);
confirmBox(medicalMessage, function(){ goCartAction(good_code, coupon_code, good_count, goOption,isOption); }, function(){}, "")
} else {
goCartAction(good_code, coupon_code, good_count, goOption,isOption, comment);
}
},
error: function (a, b, c) {
console.log("오류발생");
}
});
} else {
goLogon();
}
}
function goCartAction(good_code, coupon_code, good_count, goOption,isOption, comment) {
console.log("goCartAction comment = " + comment);
var cartId = "";
if (IsLogin()) {
if (isOption == "Y") {
confirmBox("해당상품은 옵션을 선택하셔야 합니다.
상세보기로 이동하시겠습니까?", callbackMethodTrue, function(){}, good_code)
function callbackMethodTrue(good_code) {
goDetail(good_code);
}
return false;
}
if (coupon_code == null) {
coupon_code == "";
}
if (good_count == null || good_count == "") {
good_count == 1;
}
if (goOption == null) {
goOption == "";
}
var data = { 'good_code': good_code, 'coupon_code': coupon_code, 'good_count': good_count, 'comment' : comment };
console.log("data = " + data);
$.ajax({
type: "GET",
url: '/Cart/AddCart',
async:false,
data: data,
success: function (data) {
if (data.Code == "200") {
if (goOption == "Y") {
post('/Order/OrderWrite', { goods_dels1: data.Data }, "post");
} else if (goOption == "N") {
cartId = data.Data;
} else {
confirmBox("장바구니에 저장되었습니다.\n장바구니로 이동하시겠습니까?", callbackMethodTrue, function(){}, "")
function callbackMethodTrue(good_code) {
location.href = "/Cart";
}
SetCartCount();
}
} else {
errorBox(data.Message);
}
},
error: function (a, b, c) {
errorBox('장바구니 추가에 실패하였습니다.');
return false;
}
});
} else {
goLogon();
}
if (goOption == "N") {
return cartId;
}
}
function SetCartCount() {
$.ajax({
type: "POST",
url: '/Cart/Count',
cache:false
})
.done(function(data){
$("#cartCount").html(data);
});
}
SetCartCount();
// 상품코드만 입력시 장바구니 등록
// 쿠폰 상품의 경우 쿠폰 코드 입력
// 수량은 1이 아닌 경우만 입력
function goOrder(good_code, coupon_code, good_count, is_option) {
if (IsLogin()) {
if (good_count == null || good_count == "") {
good_count = "1";
}
var arrGoodCode = good_code.split(",");
var arrGoodCount = good_count.split(",");
if(arrGoodCode.length > 1){
var arrCartId = [];
// 상품상세에서 여러 상품 바로구매의 경우 - 옵션상품
// 옵션상품은 쿠폰이 없다.
for(i=0;i< arrGoodCode.length ;i++){
arrCartId[i] = goCart(arrGoodCode[i], '', arrGoodCount[i], "N");
}
post('/Order/OrderWrite', { goods_dels1: arrCartId }, "post");
}else{
if (is_option == "Y") {
confirmBox("상세보기로 이동하시겠습니까?", callbackMethodTrue, function(){}, "");
function callbackMethodTrue(){
goDetail(good_code);
}
return false;
}
goCart(good_code, coupon_code, good_count, "Y");
}
} else {
goLogon();
}
}
// 본품만, 수량1, 쇼핑찜 리스트에서 사용
function goOrderMulti(good_code_comma_list){
if (IsLogin()) {
var arrCart = good_code_comma_list.split(",");
arrCart.forEach(function (ele) {
goCart(ele,'',1,'N');
});
$.ajax({
type: "POST",
url: '/Cart/CartIdList',
data: { 'GoodsCodeCommaList' :good_code_comma_list },
cache:false,
async: false,
success: function (data) {
post('/Order/OrderWrite', { goods_dels1: data }, "post");
}
});
} else {
goLogon();
}
}
function SetNewVideo() {
console.log("SetNewVideo");
$.ajax({ type: "POST", url: '/Contents/HasNewVideo', cache:false })
.done(function(data){
console.log("SetNewVideo" + data.result);
if(data.result) {
$("DIV[NAME=newVideoIcon]").show();
}else{
$("DIV[NAME=newVideoIcon]").hide();
}
});
}
SetNewVideo();
function SetNewMagazin() {
console.log("SetNewMagazin");
$.ajax({ type: "POST", url: '/Contents/HasNewMagazin', cache:false })
.done(function(data){
console.log("SetNewMagazin" + data.result);
if(data.result) {
$("DIV[NAME=newMagazinIcon]").show();
}else{
$("DIV[NAME=newMagazinIcon]").hide();
}
});
}
SetNewMagazin();
function CopyOrder(param) {
var confirmMessage = "구매 가능한 상품만 재주문이 가능하며,
쿠폰으로 구매한 상품, 증정상품은 재주문에 포함 되지 않습니다.
계속 주문 하시겠습니까?";
var url = "/Cart/Check";
$.ajax({
type: "post"
, dataType: "jsonp"
, async:false
, url: url
, data: param
, success: function (data) {
//alert(data.Code);
if (data.Code == "200") {
confirmBox(confirmMessage, CopyOrderAction, function () { }, param)
} else {
infoBox(data.Message);
}
}, error: function (request, error, status) {
errorBox(request.responseText)
}
});
}
function CopyOrderAction(param) {
var url = "/Cart/Copy";
$.ajax({
type: "post"
, dataType: "jsonp"
, async:false
, url: url
, data: param
, success: function (data) {
if (data.Code == "200") {
//infoBox(param.ordNo);
var $form = $('