var winCommon = {
	shopTitle : "",

	changeLanguage : function(obj){
		setCookie("LangType", obj.value, 1);
		location.reload();
	},

	setLanguage : function(){
		var lang = getCookie("LangType");

		if (lang == "us" || lang == "kr" || lang == "cn"){
			//$('selector').value = lang;
		}
		setCookie("LangType", "us", 1);
		$('selector').value = "us";
	},

	setMainNavClass : function(){
		var path = location.href;

		try{
			if (path.indexOf("/replicate_site/shop/") > 0){
				$('navItem21').className = "navItem_ck";
			}
			if (path.indexOf("/replicate_site/company/") > 0){
				$('navItem22').className = "navItem_ck";
			}
			if (path.indexOf("/replicate_site/products/") > 0){
				$('navItem23').className = "navItem_ck";
			}
			if (path.indexOf("/replicate_site/opportunity/") > 0){
				$('navItem24').className = "navItem_ck";
			}

			if (path.indexOf("/mybusiness/") > 0){
				$('navItem1').className = "navItem_ck";
			}
			if (path.indexOf("/shop/") > 0){
				$('navItem2').className = "navItem_ck";
			}
			if (path.indexOf("BoardID=News") > 0){
				$('navItem3').className = "navItem_ck";
			}
			if (path.indexOf("BoardID=Events") > 0){
				$('navItem4').className = "navItem_ck";
			}
			if (path.indexOf("/library/") > 0){
				$('navItem5').className = "navItem_ck";
			}
		}catch(e){
		}
	},

	setShopNavClass : function(){
		var path = location.href;
		var title = "";

		if (path.indexOf("/shop/shoplist_l.asp") > 0){
			try{
				if (path.indexOf("&CatCode=") == -1){
					$('navShop3').className = "txt_mhotlink_ck";
				}else{
					if (path.indexOf("&CatCode=AAAA") > 0){
						$('navShop2').className = "txt_mhotlink_ck";
						title = "<li><div style='float:right; margin-right:80px;'><div style='float:left; font-weight:bold; border:2px solid; border-color:#0F0F0F; padding:3px 3px 3px 3px;'>Pack contents maybe different from the pictures shown. Please refer to <br>latest IBO Application under 'Library' to see current contents of each pack.</div></div><h4>"+_("leftm_shop_02")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_02")+"</span> </li>";
					}else if (path.indexOf("&CatCode=BAAA") > 0 && path.indexOf("/replicate_site/shop/") > 0){
						$('navShop4').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > </li>";
					}else if (path.indexOf("&CatCode=BAAA") > 0){
						$('navShop4').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > G20 <span class='prdbx'>&nbsp;G2O is now a Builder Pack.  You will get same benefits as with regular Builder Pack.&nbsp;</span></li>";
					}else if (path.indexOf("&CatCode=BBAA") > 0){
						$('navShop5').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_04")+"</li>";
					}else if (path.indexOf("&CatCode=BCAA") > 0){
						$('navShop6').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_05")+"</li>";
					}else if (path.indexOf("&CatCode=BDAA") > 0){
						$('navShop7').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_06")+"</li>";
					}else if (path.indexOf("&CatCode=BEAA") > 0){
						$('navShop8').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_07")+"</li>";
					}else if (path.indexOf("&CatCode=BFAA") > 0){
						$('navShop9').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_08")+"</li>";
					}else if (path.indexOf("&CatCode=BGAA") > 0){
						$('navShop10').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_09")+"</li>";
					}else if (path.indexOf("&CatCode=BHAA") > 0){
						$('navShop11').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_10")+"</li>";
					}else if (path.indexOf("&CatCode=BIAA") > 0){
						$('navShop12').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_11")+"</li>";
					}else if (path.indexOf("&CatCode=BJAA") > 0){
						$('navShop13').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_12")+"</li>";
					}else if (path.indexOf("&CatCode=BKAA") > 0){
						$('navShop14').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span> > "+_("leftm_shop_16")+"</li>";
					}else if (path.indexOf("&CatCode=BXAA") > 0){
						$('navShopBulk').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_14")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_14")+"</span> </li>";
					}else{
						$('navShop3').className = "txt_mhotlink_ck";
						title = "<li><h4>"+_("leftm_shop_03")+"</h4></li><li><span class='txt_hot'>"+_("leftm_shop_03")+"</span></li>";
					}

				}
			}catch(e){
			}

		}
		if (path.indexOf("/shop/mycart.asp") > 0){
			$('navShop19').className = "txt_mhotlink_ck";
		}

		winCommon.shopTitle = title;
	},

	setMyNavClass : function(){
		var path = location.href;

		if (path.indexOf("/mybusiness/mypersonal_info.asp") > 0){
			$('navMy1').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/commission_report.asp") > 0 || path.indexOf("/mybusiness/commission_detail.asp") > 0){
			$('navMy2').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/genealogy_") > 0){
			$('navMy3').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/sale_realtime.asp") > 0){
			$('navMy4').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/Sales_week.asp") > 0 || path.indexOf("/mybusiness/Sales_3week.asp") > 0){
			$('navMy5').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/Sales_monthly.asp") > 0){
			$('navMy6').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/signup_newmember.asp") > 0){
			$('navMy7').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/auto_ship_order.asp") > 0){
			$('navMy8').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/replicated_site_setup.asp") > 0){
			$('navMy9').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/orderhistory.asp") > 0){
			$('navMy11').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/mybusiness/Sales_All.asp") > 0){
			$('navMy12').className = "txt_mhotlink_ck";
		}
	},

	setLibNavClass : function(){
		var path = location.href;

		if (path.indexOf("BoardID=ComPlan") > 0){
			$('navLib1').className = "txt_mhotlink_ck";
		}else if (path.indexOf("BoardID=NewsLetter") > 0){
			$('navLib2').className = "txt_mhotlink_ck";
		}else if (path.indexOf("BoardID=ProdInfo") > 0){
			$('navLib3').className = "txt_mhotlink_ck";
		}else if (path.indexOf("BoardID=Forms") > 0){
			$('navLib4').className = "txt_mhotlink_ck";
		}else if (path.indexOf("BoardID=Policy") > 0){
			$('navLib5').className = "txt_mhotlink_ck";
		}else if (path.indexOf("BoardID=Power") > 0){
			$('navLib6').className = "txt_mhotlink_ck";
		}else if (path.indexOf("BoardID=Products") > 0){
			$('navLib7').className = "txt_mhotlink_ck";
		}else if (path.indexOf("BoardID=Promotions") > 0){
			$('navLib8').className = "txt_mhotlink_ck";
		}else{
			$('navLib1').className = "txt_mhotlink_ck";
		}
	},

	setNewsNavClass : function(){
		var path = location.href;

		if (path.indexOf("BoardID=News") > 0){
			$('navNews1').className = "txt_mhotlink_ck";
		}else if (path.indexOf("BoardID=Events") > 0){
			$('navNews2').className = "txt_mhotlink_ck";
		}
	},

	setCompanyNavClass : function(){
		var path = location.href;

		if (path.indexOf("/KendallCho.asp") > 0){
			$('navCompany1').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/GivingBack.asp") > 0){
			$('navCompany2').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/Worldwide.asp") > 0){
			$('navCompany3').className = "txt_mhotlink_ck";
		}
	},

	setProductNavClass : function(){
		var path = location.href;

		if (path.indexOf("/Fermena.asp") > 0){
			$('navProduct1').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/FermenaPlus.asp") > 0){
			$('navProduct2').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/Ten.asp") > 0){
			$('navProduct3').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/Gratitude.asp") > 0){
			$('navProduct4').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/PassionTonic.asp") > 0){
			$('navProduct5').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/G2O.asp") > 0){
			$('navProduct6').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/Enzina.asp") > 0){
			$('navProduct7').className = "txt_mhotlink_ck";
		}
	},

	setOpportunityNavClass : function(){
		var path = location.href;

		if (path.indexOf("/FiveWays.asp") > 0){
			$('navOpportunity1').className = "txt_mhotlink_ck";
		}else if (path.indexOf("/PlanOverview.asp") > 0){
			$('navOpportunity2').className = "txt_mhotlink_ck";
		}
	},

	getServerTime : function(){
		var url = '/index.asp';
		var pars = "";
		loadAjaxXML(url, null, winCommon.setServerTime, null);
	},

	setServerTime : function(originalRequest){
		//var time = originalRequest.getResponseHeader("Date");
		//var time_fix = new Date(time);
		var time_fix = new Date();
		var tzOffset = -8;
		var tz = time_fix.getTime() + (time_fix.getTimezoneOffset() * 60000) + (tzOffset * 3600000);
		time_fix.setTime(tz);

		var month=new Array(12);
		month[0]="Jan";
		month[1]="Feb";
		month[2]="Mar";
		month[3]="Apr";
		month[4]="May";
		month[5]="Jun";
		month[6]="Jul";
		month[7]="Aug";
		month[8]="Sep";
		month[9]="Oct";
		month[10]="Nov";
		month[11]="Dec";

		year = time_fix.getFullYear();
		month = month[time_fix.getMonth()];
		date = leadingZeros(time_fix.getDate(), 2);
		hour = leadingZeros(time_fix.getHours(), 2);
		min = leadingZeros(time_fix.getMinutes(), 2);
		sec = leadingZeros(time_fix.getSeconds(), 2);
		//day = time_fix.getDay();

		if (getCookie("LangType") == "kr"){
			month = time_fix.getMonth()+1;

			if (month < 10){
				month = "0" + month
			}
		}

		$('rightDay').innerHTML = date + "-" + month + "-" + year;
		$('rightTime').innerHTML = hour + ":" + min + ":" + sec;
	},

	setRightbn : function(){
		var url = '/inc/setRightbn.asp';
		var pars = "";
		loadAjaxXML(url, null, null, null);
	}

}

var StickerAnimation = function(){};
StickerAnimation.prototype = {
	duration : null,
	obj : null,
	from : null,
	to : null,
	timer : 0,
	step : 0,
	start : function(obj, from, to, duration, type){
		var self = this;
		this.obj = obj;
		this.from = from;
		this.to = to;
		this.now = new Date;
		this.duration = duration || 1000;
		this._delta = this['_delta' +(type || 'Elastic')];

		if(this.timer)
			this.stop();

		this.timer = setInterval(function(){self.run();}, 10);
	},

	run : function(){
		var time = ((new Date) - this.now) / this.duration;
		var delta = this._delta(time);

		var step = Math.pow(2, this.step);
		var dep_x = (this.to.x - this.from.x) * delta;
		var dep_y = (this.to.y - this.from.y) * delta;

		if(time > 1){
			this.stop();
			this.end();
		}else{

			this.obj.style.marginLeft = this.from.x + dep_x + "px";
			this.obj.style.marginTop = this.from.y + dep_y + "px";
		}
	},

	end : function(){
		this.obj.style.marginLeft = (this.to.x) + "px";
		this.obj.style.marginTop = (this.to.y) + "px";
	},

	stop : function(){
		clearInterval(this.timer);
		this.timer = 0;
	},

	_deltaBounce : function(pos){
		var p = 1 - pos;

		var value;
		for (var a = 0, b = 1; 1; a += b, b /= 2){
			if (p >= (7 - 4 * a) / 11){
				value = - Math.pow((11 - 6 * a - 11 * p) / 4, 2) + b * b;
				break;
			}
		}
		return 1 - value;
	},

	_deltaExpo : function(pos){
		var p = 1 - pos;
		return 1 - Math.pow(2, 8 * (p - 1));
	},

	_deltaElastic : function(pos){
		var p = 1 - pos;
		return 1 - Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * 1 / 3);
	},

	_deltaStatic : function(pos){
		return 1;
	}
}

var StickerManager = {
	init : false,
	stickers : [],
	opts : [],
	add : function(id, duration, type){
		/*
		type
			Static
			Bounce
			Expo
			Elastic

		*/
		if(!this.init){
			var self = this;
			var init_event = function(){self.oninit();};
			var scroll_event = function(){self.onscroll();};

			if(window.attachEvent){
				window.attachEvent('onload', init_event);
				window.attachEvent('onscroll', scroll_event);
			}else{
				window.addEventListener('load', init_event, false);
				document.addEventListener('scroll', scroll_event, false);
			}

			this.init = true;
		}
	 this.stickers.push(id);
	 this.opts.push({duration:duration,type:type});
	 },

	 oninit : function(){
		var sticker;
		for(var x = 0, len = this.stickers.length; x < len; x++){
			sticker = document.getElementById(this.stickers[x]);
			if(!sticker){
				alert(this.stickers[x] + ' is bad id.');
				this.stickers[x] = null;
				continue;
			}
			this.stickers[x] = sticker;
			sticker.style.marginLeft = sticker.style.marginTop = "0px";
		}
	},

	onscroll : function(){
		var left = parseInt(document.body.scrollLeft);
		var top = parseInt(document.documentElement.scrollTop);
		var sticker;

		try{
			for(var x = 0, len = this.stickers.length; x < len; x++){
				sticker = this.stickers[x];

				if(!sticker)
					continue;

				if(!sticker.animation){
					sticker.animation = new StickerAnimation();
				}else{
					sticker.animation.stop();
				}

				sticker.animation.start(
					sticker,
					{x:parseInt(sticker.style.marginLeft), y:parseInt(sticker.style.marginTop)},
					{x:left, y:top},
					this.opts[x].duration,
					this.opts[x].type
				);

			}
		}catch(e){
		}

	}
}

function SaleCountry_change(e){
	setCookie("SaleCountry", e.value, 1);

	location.reload();
}

function SetInputStyle(obj, bool){
	if (typeof(obj.readOnly) == "undefined"){
		obj.disabled = bool;
	}else{
		obj.readOnly = bool;
	}

	if (bool){
		obj.className = "AC_READONLY_B1";
	}else{
		obj.className = "AC_READONLY_B";
	}
}

function CenterCodeChange(obj){
	var eval

	if (typeof(obj) == "undefined"){
		eval = event.srcElement;
	}else{
		eval = obj;
	}

	var CenterCode = eval.value.split(":")[0]

	if (CenterCode != "0"){
		iFrame1.location.replace("/solution/Common/AspCommon/SetCenterCodeCookiesUpdate.asp?CenterCode=" + CenterCode)
	}
}

function CheckDate(DateSTR){

	for (var i = 0; i < DateSTR.length; i++){
		if (DateSTR.indexOf("-") > 0){
			DateSTR = DateSTR.replace("-","");
		}else{
			break;
		}
	}

	if (DateSTR.length != 8){
		return true;
	}

    var Year  = DateSTR.substring(0, 4);
    var Month = DateSTR.substring(4, 6);
    var Day   = DateSTR.substring(6, 8);

    // Year Check
    if (isNaN(Year) || Year < 1900 || Year > 2020){
        return true;
    }
    // Month Check
    if (isNaN(Month) || Month < 1 || Month > 12){
        return true;
    }
    // Day Check
    return getDates(Year, Month, Day);
}

function getDates(Year, Month, Day)
{
	var TimeA = new Date(Year,Month,0,0,0,0,0);
	var dates = TimeA.getDate();

    if (isNaN(Day) || Day < 1 || Day > dates){
		return true;
	}

	return false;
}

function GetComp(obj_1, obj_2, returnval){
	if (obj_1 == obj_2 )
		return returnval;
	else
		return;
}

function StringCut(as_Str, ai_Num){
    if (as_Str.length <= ai_Num){
        return as_Str;
    }else{
        return as_Str.substring(0, ai_Num) + "...";
	}
}

function suOnlyCourse(source,suOnlyCurKey){
	if(!isDecimal(source.value.charAt(0))) source.value = "";
	if(suOnlyCurKey == 8 || suOnlyCurKey == 46 || isArrowKey(suOnlyCurKey)) return;
	else checkStringValid(source);
}

function checkStringValid(source){
	var len = source.value.length;
	for(var i=0;i<len;i++){
		if(!isDecimal(source.value.charAt(i)) || source.value.charAt(i)==" "){
			assortString(source,i);
			i=0;
		}
	}
}
function assortString(source,index){
	var len = source.value.length;
	var temp1 = source.value.substring(0,index);
	var temp2 = source.value.substring(index+1,len);
	source.value = temp1 + temp2;
}
function isDecimal(number){
	if(number>=0 && number<=9) return true;
	else return false;
}
function isArrowKey(key){
	if(key>=37 && key<=40) return true;
	else return false;
}

function GetExtNum(ExSTR, ExtNum, ExNumSTR){
	var i = 1;
	var k;
	ExSTR = ExSTR + "";

	k = (ExtNum + 1) - ExSTR.length;

	while (i < k){
		i += 1;
		ExSTR = ExNumSTR + ExSTR;
	}

	return ExSTR
}
// -------------------------------------------------------------------------------
// 점검
function FrmCheck(){
	try{
		top.mainFrame.iFMain.location;
	}catch(e){
		top.location.replace("/");
	}
}

// -------------------------------------------------------------------------------
function ShowRightMenu(){
	return false;
}

// -------------------------------------------------------------------------------
function ConvertDate(DateSTR){
	for (var i = 0; i < DateSTR.length; i++){
		if (DateSTR.indexOf("-") > 0){
			DateSTR = DateSTR.replace("-","");
		}else{
			break;
		}
	}

	return DateSTR.substring(0, 4) + '-' + DateSTR.substring(4, 6) + '-' + DateSTR.substring(6, 8)
}

//공백검사
function blankcheck(checkstr){
        for(i=0; i<checkstr.length; i++){
                if(checkstr.charAt(i)==' '){
	        	return false;
                        break;
                }
        }

}

// -------------------------------------------------------------------------------
function GetSMS(FromHand, ToHand, body, CustCode){
	var nWidth  = 400;
	var nHeight = 300;
	var path;

	path = "/common/etc/sms/sms.asp?FromHand=" + FromHand + "&ToHand=" + ToHand + '&CustCode=' + CustCode + "&body=" + body;
	openHelpWindow(path, "SMS",nWidth,nHeight,"noresize");
}

function ClipBoardCopy(Val){
	clipboardData.setData("Text", Val);
}


function GetMemberDesc(PDANumber){
	var nWidth  = 600;
	var nHeight = 500;
	var path;

	path = "/common/SearchWindow/MemberDescSearch/MemberDescSearch.asp?PDANumber=" + PDANumber;
	openHelpWindow(path, "MemberDescSearch"+PDANumber,nWidth,nHeight,"resize");
}


//--------------------------------------------------------------------------------
//마우스클릭,키보드 막기
/*
function m_click() {
	if ((event.button==2) || (event.button==3) || (event.keyCode == 93)) {
		return false;
	}
	else {
		if((event.ctrlKey) || (event.shiftKey)) {
			return false;
		}
	}
}

function keypressed() {
	event.keyCode = 0;
	event.cancelBubble = true;
	event.returnValue = false;
}

document.onmousedown=m_click;
document.onkeydown=keypressed;
*/

function leadingZeros(n, digits) {
	var zero = '';
	n = n.toString();

	if (n.length < digits) {
	for (i = 0; i < digits - n.length; i++)
		zero += '0';
	}
	return zero + n;
}

function roundXL(n, digits) {
  if (digits >= 0) return parseFloat(n.toFixed(digits)); // 소수부 반올림

  digits = Math.pow(10, digits); // 정수부 반올림
  var t = Math.round(n * digits) / digits;

  return parseFloat(t.toFixed(0));
}

