﻿//HR in LB
var currentUrlHref = location.href;
$(document).ready(function(){	
	var ilb = currentUrlHref.indexOf("contentmanager");
	var plb = currentUrlHref.indexOf("helenarubinstein.cn")
	/* if(plb < 0){
		$("#header #utilityNav .navInner").css("background-image","url('/helena-rubinstein/img/HR/global/nav_lb_bg.png')");
		$("#utilityNav #tollFree").css("display","none");
		$("#container").css("backgroundPosition","50% 153px");
		$("#container #content").css("padding-top","243px");
		$("#content .breadcrumb").css("top","502px");
		$("#giftBread").css("top","0px");
		$(".productViewInfor .productIco").css("top","0");
		$("#hr_promotion .kv").css("padding-top","153px");
	} */
	if(ilb > -1){
		//$("#header #utilityNav .navInner").css("background-image","url('/helena-rubinstein/img/HR/global/nav_lb_bg.png')");
		$("#utilityNav #tollFree").css("display","none");
		$("#container").css("backgroundPosition","50% 153px");
		$("#container #content").css("padding-top","243px");
		$("#content .breadcrumb").css("top","502px");
		$("#breadWrap .breadcrumb").css("top","0px");
		$("#giftBread").css("top","0px");
		$(".productViewInfor .productIco").css("top","0px");
		$("#hr_promotion .kv").css("padding-top","153px");
		$(".containerWithFlashInner").css({"top":"153px","left":"-14px"});
	}
	
	// modify the style for LB, by Hu 2011-06-30
	$("#overlaywrap").css("z-index","9");
	//$("#fixed").css("z-index","999");
	
	
	
});



$(document).ready(function () {
//// add form style
	$(".navUserRegisterForm").jqTransform();
	$(".userRegisterForm").jqTransform();						
	$(".modifyMyInforForm").jqTransform();
	$(".myAddressListForm").jqTransform();
	$(".inforAddressForm").jqTransform();
	if ($(".quantityAndOther")[0]){$(".quantityAndOther").jqTransform();}
	if($(".checkoutBasketList").is(":visible")){$(".checkoutBasketList").jqTransform();}
	if($("#totalPrice").is(":visible")){$("#totalPrice").jqTransform();}
	$(".userLoginInner").jqTransform();
	$(".userDeliveryForm").jqTransform();
	$(".userPaymentForm").jqTransform();
	$(".needInvoiceInnter").jqTransform();
	$(".userLoginForm").jqTransform();
	$("#forgetPsw").jqTransform();
	$(".contactUsForm").jqTransform();
	$(".shareEmailForm").jqTransform();
	$("#ForgetPwdForm").jqTransform();
	
// menu js

	$(".navBanner div div li").each(function(){
		var lastSubMenu = $(this).find("dl");
		if (lastSubMenu[0]){
			$(this).addClass("open");
		} else {
			$(this).find(".hotProduct").addClass("onlyPicture");
		}
	})
	$(".navBanner > div").bind("mouseenter", function(){  
		var findSubDiv = $(this).find("dl");
		var findGiftDiv = $(this).attr("class");
		var findGiftDivName = "gift" || "hot"
		if (findSubDiv[0]){
			$(this).addClass("on");
			$(this).find(".subNavMenu").addClass("openSubMenu");
			$(this).find(".openSubMenu li:first").addClass("on");
			$(".navBanner div div li").bind("mouseenter", function(){
				$(this).addClass("on");
				if ($(this).find("dl")[0]){
					var subddNum = $(this).find("dd").length;
					/*if (subddNum < 5){
						$(this).find("dl").addClass("dlHeight");
						var subSubMenu = $(this).find("dl").height();
						var subSubHeight = 266/2-subSubMenu/2;
						$(this).find("dl").css({"top":subSubHeight})
					}else{
						var subSubMenu = $(this).find("dl").height();
						var subSubHeight = 266/2-subSubMenu/2;
						$(this).find("dl").css({"top":subSubHeight})
					}*/
					
					if (subddNum < 5){
						$(this).find("dl").addClass("dlHeight");
						$(this).find("dl").css({"top":0});
					}else if(subddNum == 8){
						$(this).find("dl").addClass("dlHeight2");
						$(this).find("dl").css({"top":0})
					}else if(subddNum == 9){
						$(this).find("dl").addClass("dlHeight9");
						$(this).find("dl").css({"top":0})
					}else{
						$(this).find("dl").addClass("dlHeight3");
						$(this).find("dl").css({"top":0})
					}
					
					
				}
			}).bind("mouseleave",function(){  
				$(this).removeClass("on");
				if ($(this).attr("class") == ""){
					$(this).removeAttr("class");
				}
			});
		} else if (findGiftDiv = findGiftDivName){
			$(this).addClass("on");
			$(this).find(".subNavMenu").addClass("openSubMenu");
		} else {
			return false;
		}
	}).bind("mouseleave",function(){  
		$(this).removeClass("on");
		$(this).find("div").removeClass("openSubMenu");
	});  
});

//// nav user account js

function openUserCenter(){
	$("#topUserCenter .topUserCenterInnter").addClass("open");
	$("#topUserCenter .subMenu").slideDown(300);
}

function closeUserCenter(){
	$("#topUserCenter .topUserCenterInnter").removeClass("open");
	$("#topUserCenter .subMenu").slideUp(300);
}

$(document).ready(function () {
							
	var loginName = $("#loginOn .topUserTitle .name").text();
	if (loginName == "Guest"){
		$("#loginOut").show();
	}else{
		$("#loginOn").show();
	}
	
	$("#topUserCenter .openMenu").click(function(){
		var getUserSubmenuStatus = $(this).parent().parent().attr("class");
		var getShoppingBagStatus = $("#popinMiniShoppingBag").parent().parent().attr("class");
		if (getUserSubmenuStatus == 'topUserCenterInnter open'){
			closeUserCenter();
			return false;
		} else if (getShoppingBagStatus == 'open'){
			closeMiniBasket();
			openUserCenter();
			return false;
		} else{
			openUserCenter();
			return false;
		}
	});
});

/*mini basket js*/

function openMiniBasket(){
	var getUserloginStatus = $("#topUserCenter div[class*='open']").length;
	if (getUserloginStatus > 0){
		closeUserCenter(); //close user center submenu
		var miniBasketDiv = $("#popinMiniShoppingBag").parent().parent();
		$(miniBasketDiv).addClass("open");
		$("#shoppingBagContainer").slideDown(300);
	} else {
		var miniBasketDiv = $("#popinMiniShoppingBag").parent().parent();
		$(miniBasketDiv).addClass("open");
		$("#shoppingBagContainer").slideDown(300);
	}
	return false;
}

function closeMiniBasket(){
	var miniBasketDiv = $("#popinMiniShoppingBag").parent().parent();
	$(miniBasketDiv).removeClass("open");
	$("#shoppingBagContainer").slideUp(300);
}

$(document).ready(function() {
	$(".topShoppingBagBotton a").click(function(){
		var getShoppingBagStatus = $("#popinMiniShoppingBag").parent().parent().attr("class");
		if (getShoppingBagStatus == ''){
			var getTopShoppingBagNum = $(".topShoppingBagContent span").text();
			if (getTopShoppingBagNum == '0'){
				openMiniBasket();
				return false;
			}else{
				ELB.openMiniBasketEffect(ELB.querySelector.miniBasket);
				return false;
			}
		} else {
			closeMiniBasket();
			return false;
		}
	});
});

/*ScrollBar function*/

function showScrollBar (getDivHeight,addClass){
	$(getDivHeight).addClass(addClass);	
	$(getDivHeight).jscroll({
		W:"7px",
		BgUrl:"url(/helena-rubinstein/img/HR/faq/scroll_bg.gif)",
		Bg:"right",
		Btn:{btn:false},
		Bar:{
			Bg:{Out:"left",Hover:"none",Focus:"none"}
		}
	});
}

/*product infor accordion js*/

/*function productViewAddScrollBar() {
	$(".contentProductInnter").each(function(){
		var subDivHeight = $(this).height();
		var contentDivHeight = 282;
		if (subDivHeight > contentDivHeight){
			showScrollBar (this,"subMiniHeight");
		}
	})				
}*/

function productViewAddScrollBar(){//new add by Hu 20110608
	$(".contentProductInnter").each(function(){
		var subDivHeight = $(this).height();
		var contentDivHeight;
		var urlParameterS = location.search;
		if((urlParameterS.match("HR0061")!=null) || (urlParameterS.match("HR0062")!=null) || (urlParameterS.match("HR0063")!=null) || (urlParameterS.match("HR0064")!=null) || (urlParameterS.match("HR0060")!=null) || (urlParameterS.match("HR0069")!=null) || (urlParameterS.match("HR0068")!=null)){
			contentDivHeight = 418;
			if (subDivHeight > contentDivHeight){
				showScrollBar (this,"subMiniHeight");
			}
		}else{
			contentDivHeight = 282;
			if (subDivHeight > contentDivHeight){
				showScrollBar (this,"subMiniHeight");
			}
		}
	})				
}

$(document).ready(function() {
	if($(".productDetailsInnter")[0]) {
		$(".productDetailsInnter li .content").hide();
		$(".productDetailsInnter li .content:first").show();
		$(".productDetailsInnter li .content:first").parent().addClass("open");
		productViewAddScrollBar();
		$(".productDetailsInnter li a").click(function(){
			var checkElementNext = $(this).parent().next();		
			if((checkElementNext.is(".content")) && (checkElementNext.is(":visible"))) {
				return false;
			}
			if((checkElementNext.is(".content")) && (!checkElementNext.is(':visible'))) {
				$(checkElementNext).parent().addClass("open");
				$(".productDetailsInnter li .content:visible").parent().removeClass("open");
				$(".productDetailsInnter li .content:visible").hide();
				$(checkElementNext).show();
				productViewAddScrollBar();
				return false;
			}
		})
	}
	if($(".productViewInnter")[0]) {
		var getBreadcrumb = "<div class='breadcrumb'>" + $(".breadcrumb").html() + '</div>';
		$("#header #utilityNav").after(getBreadcrumb);
		$("#content .breadcrumb").empty();
	}
});	


/*product choose color js*/

$(document).ready(function() {
	if ($(".productViewInfor")[0]) {
		var imgBreadcrumb = "/helena-rubinstein/img/product/thumbnail/"
		var newSelect = $("#colorNum").prev().find("li a");
		var colorSelection = $(".colorSelectionInnter li");
		var quantitySelect = $(".quantity").find("li a");
		
		function addColor(newSelectIndex){ 
			$(".colorSelectionView").each(function(){
				var colorNum = $(colorSelection).eq(newSelectIndex).find("a").attr("name");	
				var colorBreadcrumb = imgBreadcrumb + colorNum + ".png";
				$(this).find("img").attr("src",colorBreadcrumb);
			})
		}
		
		function putCheckoutCode (vCode,qNum){
			var getVCode = "box[id=addToBasket;sku=" + vCode[0] + ";qty=" + qNum +"]";
			$(".productViewInfor .addToBasketBtn a").attr("class",getVCode);
		}
		
		function addToCheckoutBtn(newSelectIndex) {
			var getSelectVCode = $("#colorNum option").eq(newSelectIndex).val();
			var selectsVCode = getSelectVCode.split("#");
			var quantityNum = $(".quantity .jqTransformSelectWrapper div span").text();
			putCheckoutCode (selectsVCode,quantityNum);
			var getSelectsStock = selectsVCode[2];
			if (getSelectsStock < 1){
				$(".productViewInfor .content .addToBasketBtn a").hide();
				$(".productViewInfor .content .addToBasketBtn img").show();
			}else{
				$(".productViewInfor .content .addToBasketBtn img").hide();
				$(".productViewInfor .content .addToBasketBtn a").show();
			}
		}
				
		$(quantitySelect).click(function(){
			var quantitySelectIndex = $(".quantity").find("li a").index(this);
			var getQuantityNum = $(quantitySelect).eq(quantitySelectIndex).text();
			var newSelectCode = $(".capacity ul li a.selected").attr("index");
			var getSelectVCode = $("#colorNum option").eq(newSelectCode).val();
			var selectsVCode = getSelectVCode.split("#");
			putCheckoutCode (selectsVCode,getQuantityNum);
		})
		
		$(newSelect).click(function(){
			var newSelectIndex = $("#colorNum").prev().find("li a").index(this);
			$("#colorNum option").eq(newSelectIndex).text();
			var getAllSelectPrice = $("#colorNum option").eq(newSelectIndex).val();
			var getSelectsPrice = getAllSelectPrice.split("#");
			$(".productViewInfor .price").text(getSelectsPrice[1]);
			$(colorSelection).eq(newSelectIndex).addClass("selected");
			addColor(newSelectIndex);
			$(colorSelection).eq(newSelectIndex).siblings().removeAttr("class");
			addToCheckoutBtn(newSelectIndex);
		})
		
		$(colorSelection).click(function(){
			var colorSelectionIndex = $(".colorSelectionInnter li").index(this);
			addColor(colorSelectionIndex);
			$(newSelect).parent().eq(colorSelectionIndex).find("a").click();
			return false;
		})
		
		$(".colorSelectionColor").text($(".colorSelectionInnter li").length);
		$("#colorNum").prev().find("li a.selected").click();
		
		/*product view flash action*/
		
		var productViewPng = $("#videoContent .title").html();
		var videoflashvars = {
			xmlUrl:"/helena-rubinstein/xml/animationCustomer.xml",
			imgUrl:productViewPng
		};
		var params = {
			menu: "false",
			scale: "noScale",
			allowFullscreen: "true",
			allowScriptAccess: "always",
			wmode: "transparent",
			bgcolor: "#FFFFFF",
			base:'.'
		};
		var videoattributes = {
			id:"videoContent"
		};
		swfobject.embedSWF("/helena-rubinstein/swf/SingleProductionPlayer.swf", "videoContent", "324", "235", "9.0.0", "/helena-rubinstein/swf/expressInstall.swf", videoflashvars, params, videoattributes);

	}
	
});	


/*footerShare js*/

$(document).ready(function() {
	$(".footerShare").bind("mouseenter", function(){
		$(this).find(".footerShareContent").addClass("open");
		$(this).find(".footerShareInnter").slideDown(300);
	}).bind("mouseleave",function(){  
		$(this).find(".footerShareContent").removeClass("open");
		$(this).find(".footerShareInnter").slideUp(300);
	});
});	

/*faq and help center*/

$(document).ready(function(){
	//help center
	$(".helpingCenterMainNav .navContainer:first").show();
	$(".helpingCenterContent div:first").show();

	var firstLoadHeight = $(".helpingCenterContent .helpingCenterTxtList:first")
	showScrollBar (firstLoadHeight,"subNavC");
	
	$(".helpingCenterNavList").click(function(){
		$(this).addClass("current").next().show();
		$(this).parent().siblings().find(".helpingCenterNavList").removeClass("current");
		$(this).parent().siblings().find(".navContainer").hide();
		
		var subDivHeight = $(this).next().find(".navInner").height();
		var contentDivHeight = 180;
		if (subDivHeight > contentDivHeight){
			var getDivHeight = $(this).next();
			showScrollBar (getDivHeight,"subNavC")
		}
	});
	
	$(".helpingCenterMainNav a").click(function(){
		var id=$(this).attr("href").split("#")[1];
		$(".helpingCenterTxtList:visible").parent().css("display","none");
		$("#"+id).parent().css("display","block");
		
		var rightDivHeight = $("#"+id).height();
		var contentDivHeight = 366;
		if (rightDivHeight > contentDivHeight){
			showScrollBar ($("#"+id),"subNavC")
		}
		
		return false;
	});
	
	//faq
	$(".faqNav .faqContainer:first").show();
	$(".faqMainContent div:first").show();

	var firstLoadHeight = $(".faqMainContent .faqContentList:first")
	showScrollBar (firstLoadHeight,"subNavC");
	
	$(".faqList").click(function(){
		$(this).addClass("current").next().show();
		$(this).parent().siblings().find(".faqList").removeClass("current");
		$(this).parent().siblings().find(".faqContainer").hide();
		
		var subDivHeight = $(this).next().find(".faqInnter").height();
		var contentDivHeight = 180;
		if (subDivHeight > contentDivHeight){
			var getDivHeight = $(this).next();
			showScrollBar (getDivHeight,"subNavC")
		}
	});
	
	$(".faqNav a").click(function(){
		var id=$(this).attr("href").split("#")[1];
		$(".faqContentList:visible").parent().css("display","none");
		$("#"+id).parent().css("display","block");
		
		var rightDivHeight = $("#"+id).height();
		var contentDivHeight = 594;
		if (rightDivHeight > contentDivHeight){
			showScrollBar ($("#"+id),"subNavC")
		}
		
		return false;
	});

});

/*checkout step2*/

$(document).ready(function() {
	if($(".checkoutUserContiner")[0]) {
		$(".checkoutUserList").bind("mouseenter", function(){
			$(this).siblings().find(".checkoutMask").show();
		}).bind("mouseleave",function(){  
			$(this).siblings().find(".checkoutMask").hide();
		});
	}
});	

/*news list js*/
$(document).ready(function(){
	if($("#newsViewInnter > li")[0]) {
		$("#newsViewInnter > li:eq(0)").addClass("first");
		var bigImgName = $("#newsViewInnter > li:eq(0) .pic img").attr("src");
		bigImgName=bigImgName.slice(0,-4)+"_L"+".jpg";
		$("#newsViewInnter > li:eq(0) .pic img").attr("src",bigImgName);
		$("#newsViewInnter > li").eq(1).addClass("second");
		var bigImgName2 = $("#newsViewInnter > li:eq(1) .pic img").attr("src");
		bigImgName2=bigImgName2.slice(0,-4)+"_L"+".jpg";
		$("#newsViewInnter > li:eq(1) .pic img").attr("src",bigImgName2);
		
		var lilength = $("#newsViewInnter > li").length;
		if(lilength > 2){
			$("#newsViewInnter > li:last").addClass("last");
		}
	}
});


//$(window).load(function(){
//	$("#coreMask").hide();
//})

/* user login and  forget password */
$(document).ready(function() {
	if($(".userLogin")[0]){		
		$("#masksBut").click(function(){
			$("#masksLayer").show();
			$("#layerWrap").show();
		});
		
		$(".layerWrapInner .close").click(function(){
			$("#masksLayer").hide();
			$("#layerWrap").hide();
		});
	}
});
/* end user login and  forget password */

/* e-mail us  textarea script */
function trySetDefaultText(obj,txt) {
	if(obj.value==""){
		obj.value = txt;
		obj.className = 'textareaColumn';
	}
	else obj.className = 'textblack';
}

function tryClearDefaultText(obj,txt) {
	if(obj.value==txt){
		obj.value = '';
		obj.className = 'textblack';
	}
}
/* end e-mail us textarea script */


/* my-account-my-infor.php */

/*form*/
$(document).ready(function() {
	ELB.edm.bind();  //newsletter
	ELB.search.ini();  //top search box, result page search box
	$(".forgetPassword .forgetPasswordInfor a").click(function(){
		ELB.forgotPassword();
	});
	$("#loginOffBtnAction").click(function(){
		ELB.topUserRegisterOut();
		return false;
	});
	$(".footerShareInnter .shareEmail a").click(function(){
		ELB.showCoreMask();
		var windowWidth = document.body.clientWidth;
		var popupWidth = $("#shareEmailPopin").width();
		$("#shareEmailPopin").show();
		return false;
	});
	$("#shareRegister").click(function(){
		if ($(".shareEmailForm").validate().form()) {
			ELB.popinShareEmail();
		}
		return false;
	})
	$("#closeShareEmailPopin a").click(function(){
		ELB.closeCoreMask();
		$("#shareEmailPopin").hide();
		return false;
	})

});

/*quick buy popin action*/

$(document).ready(function(){
	$(".btn .checkout a").click(function(){
		ELB.popinProduct(this);
		return false;
	})
	
	var listGroup = $(".productListInnter li,.hotProductInnter li,.productDetailsCollocation li,.valuedGiftInnter li,.categoryRecommend li,.searchProductInnter li");
	$(listGroup).bind("mouseenter", function(){
		$(this).addClass("on");
	}).bind("mouseleave",function(){  
		$(this).removeClass("on");
	});
	$(listGroup).find(".pic,.content").click(function(){
		var linkAddress = $(this).parent().find(".btn .view a").attr("href");
			window.location.href = linkAddress;
	})
});

/*product category page action*/

$(document).ready(function(){
									   
			//resize Window imgs
						   
	if ($('.categoryInnterPush')[0]){
		$('.categoryInnterPush').slides({
			preload: true,
			preloadImage: '/helena-rubinstein/img/HR/global/hr_loading.gif',
			play: 12000,
			pause: 800,
			hoverPause: true
		});	
	}

	if ($('#content-wrap')[0]){
		var windowWidth = document.documentElement.clientWidth;
		var postionRight = (windowWidth-1015)/2;
		$(".slides_container").width(windowWidth);
		$(".slides_container a").width(windowWidth);
		//$(".slides_container a img").width(windowWidth);
		$(".detailedBut").css("right",postionRight+27+"px");
		$(window).resize(function(){
			//windowWidth = $(window).width();
			windowWidth = document.documentElement.clientWidth;
			windowHeight= document.documentElement.clientHeight;
			postionRight = (windowWidth-1015)/2;
			$(".slides_container").width(windowWidth);
			$(".slides_container a").width(windowWidth);
			$(".pagination").css("right",postionRight+"px");	
			$(".detailedBut").css("right",postionRight+27+"px");
		});
		
		// slide Default
		$('#content-wrap').slides({
			preload: true,
			preloadImage: '/helena-rubinstein/img/HR/global/hr_loading.gif',
			play: 5000,
			pause: 800,
			hoverPause: true
			/*animationStart: function() {
				if($('.textHere').length>0){
					$('.textHere img').fadeOut('800');
					$('.textHere a').hide();
				}
			},
			animationComplete:function(){
				var index=$('.slides_container a img:visible').index('.slides_container a img');
				if($('.textHere').length>0){
					$('.textHere img:eq('+index+')').show();
					$('.textHere a:eq('+index+')').css('display','block');
				}
			}*/
		});
			
		$(".pagination").css("right",postionRight+"px");		
	}
	
});

/*del product list ico*/

$(document).ready(function(){
	$("#HR_F1_Skin_NewListing,#HR_F1_Skin_Hotproduct,#HR_F1_Skin_topgradeProduct,#HR_F1_Makeup_NewListing,#HR_F1_Makeup_Hotproduct").find(".ico").hide();
});

/* for CM bug */
$(document).ready(function(){
	$('#forHeaderBlackFont').css('background-image','url("http://www.GD365.COM.cn/HR/IMAGE/HR0602.jpg")');
	$('#forHeaderBlackFont .detailedBut').css('top','477px');
});

/* for HR0080*/
$(document).ready(function(){
	if(location.search.match('HR0080')!=null){
		$('.jqTransformSelectWrapper ul').remove();	
	}
});
/*
	lucky draw
*/

//$(document).ready(function(){
	/*if ($(".hrHomepage")[0]){
		checkCookie();
	}
	//set cookie
	function getCookie(c_name)
	{		
	  if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
	  {
	  c_start=c_start + c_name.length+1;
	  c_end=document.cookie.indexOf(";",c_start);
	  if (c_end==-1) c_end=document.cookie.length;
	  return unescape(document.cookie.substring(c_start,c_end));
	  }
	 }
	return "";
	}
	
	function setCookie(c_name,value,expiredays)
	{
	  var exdate=new Date();
	  exdate.setDate(exdate.getDate()+expiredays);
	  document.cookie=c_name+"="+escape(value)+
	  ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
	function checkCookie()
	{
	  firstCome=getCookie('firstCome');
		if(firstCome!=null && firstCome!=""){
		}else{
			ELB.showCoreMask();
			$("#hrLuckydrawLink").hide();
			$("#column1, #errorTip1, #phoneDefaultTip, #hrluckydraw").show();
			$("#errorTip2, #errorTip3, #submitError, #errorPhoneTip, #column2, #column3").hide();
			$("#txt-mail").focus();
			$("#txt-mail").val("");
			$("#txt-phone").val("");
			setCookie('firstCome','first',365);
		}
	 }*/
	 
	 //indexOf index.aspx
	/* var currentUrl = window.location.pathname;
	 var subCurrentUrl = "/helena-rubinstein/_zh/_cn/home/index.aspx";
	 if(currentUrl.match(subCurrentUrl) !=  null){
		 ELB.showCoreMask();
		 $("#hrLuckydrawLink").hide();
		 $("#column1, #errorTip1, #phoneDefaultTip, #hrluckydraw").show();
		 $("#errorTip2, #errorTip3, #submitError, #errorPhoneTip, #column2, #column3").hide();
		 $("#txt-mail").focus();
		 $("#txt-mail").val("");
		 $("#txt-phone").val("");
	}
	 
	 
	 $("#hrLuckydrawLink").click(function(){
		ELB.showCoreMask();
		$(this).hide();
		$("#column1, #errorTip1, #phoneDefaultTip, #hrluckydraw").show();
		$("#errorTip2, #errorTip3, #submitError, #errorPhoneTip, #column2, #column3").hide();
		$("#txt-mail").focus();
		$("#txt-mail").val("");
		$("#txt-phone").val("");
	});
	 
	$("#closeLuckyLayer").click(function(){
		ELB.closeCoreMask();
		$("#hrLuckydrawLink").show();
		$("#column1").show();
		$("#column2, #column3").hide();
		$("#hrluckydraw").hide();
	});
	
	// check mail
	$("#butJoin").click(function(){
		chkmail();
		return false;
		
	});
	
	// check phone
	$("#submitMsg").click(function(){
		chkphone();
		return false;
	});
	
	// share to
	var currentUrl = window.location.href;
	var currentTitle = $.trim($("#hrluckydraw .container .inner-container .top").text());
	$("#shareToSina").attr("href","http://v.t.sina.com.cn/share/share.php?title="+currentTitle+"&url="+currentUrl);
	$("#shareToKaixin").attr("href","http://www.kaixin001.com/repaste/share.php?rtitle="+currentTitle+"&rurl="+currentUrl);
	$("#shareToRenren").attr("href","http://share.renren.com/share/buttonshare.do?link="+currentUrl+"&title="+currentTitle);
	$("#shareToDoub").attr("href","http://www.douban.com/recommend/?url="+currentUrl+"&title="+currentTitle);
	
	$("#noAnd3qs").click(function(){
		$("#column2").hide();
		$("#column3").show();
	})
	
});

//check mail
function chkmail(){
	var email = $("#txt-mail").val();
	var emailMatch = /^([a-zA-Z0-9_-]|(\.))+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,10}){1,10})$/;
	if(email==''){
		$("#errorTip1, #errorTip3").hide();
		$("#errorTip2").show();
		$("#txt-mail").focus();
		return false;
	}else if(email.match(emailMatch) == null){
		$("#errorTip1, #errorTip3").hide();
		$("#errorTip2").show();
		$("#txt-mail").focus();
		return false;
	}else{
		$("#txt-mailH").val(email);
		chkMailExist();  //执行ajax函数
		return false;
	}
}
// check phone
function chkphone(){
	var phone = $("#txt-phone").val();
	var phoneMatch = /^1[3458]\d{9}$/;
	if(phone==''){
		submitMailPhone(); //提交表单
	}else if(phone.match(phoneMatch) == null){
		$("#phoneDefaultTip").hide();
		$("#errorPhoneTip").show();
		return false;
	}else{
		submitMailPhone(); //提交表单
		return false;
	}
}


function chkMailExist(){
	var _mail = $.trim($("#txt-mail").val());
	$.ajax({
		url: AAB.url.checkoutSrv + "/lucky.aspx/CheckEmailExist",
		dataType: "jsonp",
		data: {email:_mail},
		jsonp: "jsoncallback",
		success:  function(data){
			if(data['result'] == 'true'){
				$('#errorTip1,#errorTip2').hide();
				$('#errorTip3').show();
				return false;
			}else{
				$('#column1').hide();
				$('#column2').show();
			}
		}
	});
}




function submitMailPhone(){
	$.ajax({
			url: AAB.url.checkoutSrv + '/lucky.aspx/AddLuckyEmail',
			dataType: 'jsonp',
			data: {
				email: $.trim($("#txt-mailH").val()),
				mobile: $.trim($("#txt-phone").val())
			},
			jsonp: 'jsoncallback',
			success:  function(data){
				if(data['result'] == 'success'){
					$("#column2").hide();
					$("#column3").show();
				}else{
					$("#phoneDefaultTip, #errorPhoneTip").hide();
					$("#submitError").show();
					return false;
				}			
			}	
		});	
}*/


/*
	end lucky draw
*/


/* 
	For header black font
*/
/*$(document).ready(function(){
	var displayStyle = $("#content-wrap #forHeaderBlackFont").css("display");
	alert(displayStyle);
	if(displayStyle=="block"){
		$("#utilityNav div.integral a").css("color","#000000");
	}
});*/

/* 
	end For header black font
*/
