﻿$(document).ready(function () {
  var myDate = new Date();
  var todayH = myDate.getHours();
  var todayM = myDate.getMinutes();
  if (todayH < 9 || (todayH >= 21)) {
    $(".btnLiveChat a").attr("class", "offline");
  } else {
    $(".btnLiveChat a").attr("class", "");
  }
  if (getCookie("UserInfor") != "") {
    var cookievalue = getCookie("UserInfor");
    $("#checkloginjs").attr("src", "http://202.170.217.49:8080/js/yh.jsp?companyId=7&style=324&keyword=2&locate=cn&username=" + cookievalue);
  }
});
//IMPORTANT
//$.cookies need to have jquery.cookies.js
function getCookie(cookieName) {
	var cookieValue = $.cookies.get(cookieName);
	if (cookieValue != null) {
	  return cookieValue;
	} else {
	  return "";
	}
}

function setCookie(cookieName, cookieValue) {
  $.cookies.set(cookieName, cookieValue);
}

function delCookie(cookieName) {
  $.cookies.del(cookieName);
}

function checklogin() {
	var myDate = new Date();
	var todayH = myDate.getHours();
	var todayM = myDate.getMinutes();
	var chatwin;
	//var path = window.location.toString().toLowerCase().indexOf('hk-loreal') > -1 ? "http://lpd.aab.zh.cn.contentmanager.hk-loreal.com/" : "http://www.luxurybeauty.com/";
	var path = window.location.toString().toLowerCase().indexOf('hk.e-loreal') > -1 ? "http://lpd.aab.zh.cn.contentmanagerhk.e-loreal.com/" : "http://www.luxurybeauty.com/";
	if (getCookie("UserInfor") == "" && 9 <= todayH && (todayH <21)) {
	  if (!chatwin || chatwin.closed) {
	    chatwin = window.open(path + "common.aspx/chat?utm_source=livechatlogo&utm_medium=website&utm_campaign=livechat", 'chatwindow', 'height=700, width=900, top=200, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');
	  } 
    else {
	    chatwin.focus();
	  }
	} 
  else {
		var cookievalue = getCookie("UserInfor");
		$("#checkloginjs").attr("src", "http://202.170.217.49:8080/js/yh.jsp?companyId=7&style=324&keyword=2&locate=cn&username=" + cookievalue);
		if (9 <= todayH && (todayH <21)) {
		  if (!chatwin || chatwin.closed)
		    open_pic_chat();
		  else
		    chatwin.focus();
		} else {
		    if (!chatwin || chatwin.closed) {
		      chatwin = window.open(path + "common.aspx/offlinechat", 'chatwindow', 'height=700, width=900, top=200, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');
	      } else {
		      chatwin.focus();
		    }
		}
	}
}
