﻿
////////////////////  AAB JavaScript Library  ////////////////////
//Please contact PeterZ if have any question, problem or suggestion.

//Global Variable
var AAB = AAB || {};
AAB.temp = AAB.temp || {};


//string
AAB.str = AAB.str || {};
AAB.str.cny = AAB.str.rmb = '\xA5';
AAB.str.formatPrice = function(s) {return jQuery.trim(s.replace(/,/g, '').replace('\xA5', ''));}  //'\xA5' means CNY (RMB) symbol.
AAB.str.priceToNumber = function(s) {return parseFloat(s.replace(/,/g, '').replace('\xA5', ''));}
AAB.str.numberToPrice = function(n) {return AAB.str.cny + ' ' + n.toFixed(2);}
AAB.str.ifHas = function(sA, sB) {return (sA.indexOf(sB) > -1)}
AAB.str.ifStartsWith = function(sA, sB) {return (sA.indexOf(sB) === 0)}


//URL Constants and Fn
AAB.url = AAB.url || {};
AAB.url.str = window.location.href;
AAB.url.returnUrl = encodeURIComponent(window.location.href);
AAB.url.host = window.location.host;
AAB.url.path = window.location.pathname.replace(/\/contentmanagerdata\/sites\/aspnet/i, '');
AAB.url.query = window.location.search.slice(1).replace(/&+$/g, '');
AAB.url.param = null;

AAB.url.platform = '';  //integration, development, production
AAB.url.siteType = '';  //lb, ss
AAB.url.brand = '';  //[lb] luxurybeauty. [ss] biotherm, lancome, armani, kiehls, shuuemura, hr
AAB.url.lbBrand = '';  //[lb] biotherm, lancome, armani, kiehls, shuuemura, hr
AAB.url.bioVisual = '';  //women, men
//AAB.url.isIntegration = false;
//AAB.url.isProduction = false;

if (AAB.str.ifHas(AAB.url.host, 'contentmanager')) {
	AAB.url.platform = 'integration';
	AAB.url.siteType = 'lb';
} else if (AAB.str.ifHas(AAB.url.host, 'catalog')) {
	AAB.url.platform = 'integration';
	AAB.url.siteType = 'ss';
} else {
	AAB.url.platform = 'production';
	if (AAB.str.ifHas(AAB.url.host, 'luxurybeauty.com')) {
		AAB.url.siteType = 'lb';
	} else {
		AAB.url.siteType = 'ss';
	}
}
if (AAB.str.ifHas(AAB.url.host, 'biotherm')) {
	AAB.url.brand = 'biotherm';
	AAB.url.bioVisual = (AAB.str.ifHas(AAB.url.query.toLowerCase(), 'visual=men') || AAB.str.ifHas(AAB.url.path.toLowerCase(), '/_zh/_cn/men/')) ? 'men' : 'women';
} else if (AAB.str.ifHas(AAB.url.host, 'lancome')) {
	AAB.url.brand = 'lancome';
} else if (AAB.str.ifHas(AAB.url.host, 'armani')) {
	AAB.url.brand = 'armani';
} else if (AAB.str.ifHas(AAB.url.host, 'kiehls')) {
	AAB.url.brand = 'kiehls';
} else if (AAB.str.ifHas(AAB.url.host, 'shuuemura')) {
	AAB.url.brand = 'shuuemura';
} else if (AAB.str.ifHas(AAB.url.host, 'shuuemura')) {
	AAB.url.brand = 'shuuemura';
} else if (AAB.str.ifHas(AAB.url.host, 'hr.') || AAB.str.ifHas(AAB.url.host, 'helena-rubinstein') || AAB.str.ifHas(AAB.url.host, 'helenarubinstein')) {
	AAB.url.brand = 'hr';
}else if (AAB.str.ifHas(AAB.url.host, 'kerastase')) {
	AAB.url.brand = 'kerastase';
} else {
	AAB.url.brand = 'unknown';
}
if (AAB.url.siteType === 'lb') {
	AAB.url.lbBrand = AAB.url.brand;
	AAB.url.brand = 'luxurybeauty';
}

if (AAB.url.platform === 'integration') {
	if (AAB.url.siteType === 'lb' && AAB.str.ifHas(AAB.url.host, 'arvato')) {
		AAB.url.platform = 'development';
	} else if (AAB.url.siteType === 'ss' && AAB.str.ifHas(AAB.url.host, 'catalog.')) {
		AAB.url.platform = 'development';
	}
}

AAB.temp.urlLib = {
	luxurybeauty: {
		development: {
			checkoutSrv: 'http://lpd.aab.zh.cn.arvato.contentmanagerhk.e-loreal.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'aab.zh.cn.arvato.contentmanagerhk.e-loreal.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/Customer.aspx/Login'
		},
		integration: {
			checkoutSrv: 'http://lpd.aab.zh.cn.contentmanagerhk.e-loreal.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'aab.zh.cn.contentmanagerhk.e-loreal.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/Customer.aspx/Login'
		},
		production: {
			gaAccount: 'UA-16436710-5',
			checkoutSrv: 'http://www.luxurybeauty.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'luxurybeauty.com',
			ajaxAddSample: '/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/Customer.aspx/Login'
		}
	},
	biotherm: {
		development: {
			hotline: '800-820-5012',
			checkoutSrv: 'http://lpd.biotherm.stratdgds.com',
			checkoutStep2Path: '/biothermcheckout.aspx/stepthree',
			rootDomain: 'biotherm.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/BiothermAccount.aspx/Register'
		},
		integration: {
			hotline: '800-820-5012',
			gaAccount: 'UA-19617523-3',
			checkoutSrv: 'http://lpd-standalone.biotherm.stratdgds.com',
			checkoutStep2Path: '/biothermcheckout.aspx/stepthree',
			rootDomain: 'biotherm.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/BiothermAccount.aspx/Register'
		},
		production: {
			hotline: '800-820-5012',
			gaAccount: 'UA-19617523-1',
		    checkoutSrv: 'http://user.biotherm.com.cn',
			checkoutStep2Path: '/biothermcheckout.aspx/stepthree',
			rootDomain: 'biotherm.com.cn',
			ajaxAddSample: '/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/BiothermAccount.aspx/Register'
		}
	},
	shuuemura: {
		development: {
			checkoutSrv: 'http://lpd.shuuemura.stratdgds.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'shuuemura.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/ShuuemuraAccount.aspx/Register'
		},
		integration: {
			checkoutSrv: 'http://lpd-standalone.shuuemura.stratdgds.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'shuuemura.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/ShuuemuraAccount.aspx/Register'
		},
		production: {
			gaAccount: 'UA-22413153-1',
			checkoutSrv: 'http://user.shuuemura.com.cn',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'shuuemura.com.cn',
			ajaxAddSample: '/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/ShuuemuraAccount.aspx/Register'
		}
	},
	kiehls: {
		development: {
			hotline: '400-820-5433',
			checkoutSrv: 'http://lpd.kiehls.stratdgds.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'kiehls.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/KiehlsAccount.aspx/Register'
		},
		integration: {
			hotline: '400-820-5433',
			checkoutSrv: 'http://lpd-standalone.kiehls.stratdgds.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'kiehls.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/KiehlsAccount.aspx/Register'
		},
		production: {
			hotline: '400-820-5433',
			gaAccount: 'UA-19369968-2',
			checkoutSrv: 'http://user.kiehls.com.cn',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'kiehls.com.cn',
			ajaxAddSample: '/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/KiehlsAccount.aspx/Register'
		}
	},
	armani: {
		development: {
			checkoutSrv: 'http://lpd.armani.stratdgds.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'armani.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/ArmaniAccount.aspx/Register'
		},
		integration: {
			checkoutSrv: 'http://lpd-standalone.armani.stratdgds.com',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'armani.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/ArmaniAccount.aspx/Register'
		},
		production: {
			gaAccount: 'UA-19369436-2',
			checkoutSrv: 'http://user.giorgioarmanibeauty.cn',
			checkoutStep2Path: '/shoppingcart.aspx/checkout',
			rootDomain: 'giorgioarmanibeauty.cn',
			ajaxAddSample: '/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/ArmaniAccount.aspx/Register'
		}
	},
	hr: {
		integration: {
			hotline: '400-821-0811',
			gaAccount: 'UA-22934897-1',
			checkoutSrv: 'http://lpd-standalone.hr.stratdgds.com',
			checkoutStep2Path: '/hrcheckout.aspx/stepthree',
			rootDomain: 'hr.stratdgds.com',
			ajaxAddSample: '/ContentManagerData/Sites/aspnet/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/HrAccount.aspx/Login'
		},
		production: {
			hotline: '400-821-0811',
			gaAccount: 'UA-22934897-2',
			checkoutSrv: 'http://user.helenarubinstein.cn',
			checkoutStep2Path: '/hrcheckout.aspx/stepthree',
			rootDomain: 'helenarubinstein.cn',
			ajaxAddSample: '/Armani/ws/ajax/ShoppingCart.asmx/AddSampleItemByCategory',
			ajaxSubscrEdmPath: '/Home.aspx/AddNewsletterAjax',
			loginPath: '/HrAccount.aspx/Login'
		}
	}
};

jQuery.extend(AAB.url, AAB.temp.urlLib[AAB.url.brand][AAB.url.platform]);
delete AAB.temp.urlLib;

AAB.url.gaAccount	= AAB.url.gaAccount || '';
AAB.url.hotline		= AAB.url.hotline || '400-820-4888';
AAB.url.loginInShoppingCart = AAB.url.checkoutSrv + AAB.url.loginPath + ((AAB.url.siteType === 'lb') ? '?step=1' : '?ReturnUrl=' + AAB.url.returnUrl);
AAB.url.toPost = AAB.url.ajaxAddSample;  /** backward compatibility **/


//cookie
AAB.cookie = AAB.cookie || {};
AAB.cookie.set = function(sName, sValue, nLiveDays) {
	var sCookieDate = '';
	if (nLiveDays !== undefined) {
		var oDate = new Date();
		oDate.setDate(oDate.getDate() + nLiveDays);
		sCookieDate = ';expires=' + oDate.toGMTString();
	}
	document.cookie = sName + '=' + escape(sValue) + sCookieDate + ';path=/;domain=' + AAB.url.rootDomain;
}
AAB.cookie.get = function(sName) {
	var sCookie = document.cookie;
	var sValue = '';
	if (sCookie.length > 0) {
		var nStart = sCookie.indexOf(sName + '=');
		var nEnd;
		if (nStart > -1) {
			nStart = nStart + sName.length + 1;
			nEnd = sCookie.indexOf(';', nStart);
			if (nEnd < 0) nEnd = sCookie.length;
			sValue = unescape(sCookie.substring(nStart, nEnd));
		}
	}
	return sValue;
}
AAB.cookie.del = function(sName) {
	var sV = AAB.cookie.get(sName);
	if (sV) {
		AAB.cookie.set(sName, 'null', -1);
	}
}


//tools
AAB.tool = AAB.tool || {};



//end.
