/**
 *在StoreFront常用的脚本
 */

function signInViewPrice(){
	doRequiredLoginAction(function(){
	    document.location.reload();	
	});
}
/*
 * 返回Cookie的Minicart字符串
 */
function getCartCookieInfo(){
	var minCartInfo=getCookie("cookie_shoppingcart");
	if(minCartInfo!=null){
		var cartInfo=minCartInfo.split("|");
		return cartInfo;
	}	
	return null;
}
function getCartBuyNowCount(){
	var cartInfo=getCartCookieInfo();
	if(cartInfo!=null && cartInfo[1] > 0){
		return cartInfo[1];		
	}
	return 0;
}
function getMiniCartInfo(){
	var cartInfo=getCartCookieInfo();
	if(cartInfo!=null && cartInfo[1] > 0){
		return "<b>"+cartInfo[1]+"</b> "+ __FMT.minicart_itemUnit +" $<b>"+ cartInfo[2]+"</b>";
	}
	return "0 items in your bag";	
}
function getMiniCheckoutInfo(){
	return "<a href='"+__ctxPath+"/checkout/checkout.html?process=begin'><img src='"+__tsCtxPath+"/images/btn/checkout.png' /></a>";
}
function refreshMiniCartInfo(){	
	if($("spanMiniCartInfo")){
		$("spanMiniCartInfo").innerHTML="";
		$("spanMiniCartInfo").innerHTML=getMiniCartInfo();
	}
	if($("spanMiniCheckoutInfo")){
		$("spanMiniCheckoutInfo").innerHTML="";
		var cartInfo=getCartCookieInfo();
		if(cartInfo!=null && cartInfo[1] > 0){
			$("spanMiniCheckoutInfo").innerHTML=getMiniCheckoutInfo();
		}
	}	
}

function isIE()
{
	return (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
}
/*显示all caegory pop */
function fnShowAllCategoryPop(){
	var mainBoxDIV=$("mainBox");
	if($("allCategoryContent").innerHTML==""){
		var url = __ctxPath + "/siteAllCatalog.html?decorator=selecter";
		if(("https:" == document.location.protocol)){
			url=window.location.protocol+"//"+window.location.host+ __ctxPath+ "/siteAllCatalog_ssl.html?decorator=selecter";
		}
		fillDivWithPage("allCategoryContent",url,null,null,"GET");
	}
	mainBoxDIV.style.display='block';
	//IFrame
	/**
	var hideSelectorIFrame=$('hideSelectorIFrame');
	hideSelectorIFrame.style.width = mainBoxDIV.offsetWidth;
	hideSelectorIFrame.style.height = mainBoxDIV.offsetHeight;
	hideSelectorIFrame.style.top = mainBoxDIV.style.top;
	hideSelectorIFrame.style.left = mainBoxDIV.style.left;
	hideSelectorIFrame.style.display = "";
	*/
}
/*隐藏 all caegory pop */
function fnHideAllCategoryPop(e){
	e = e || window.event;
	o = e.relatedTarget||e.toElement;
	if(o==null)return;
	while(o.parentNode&&o.id!='mainBox'){	o=o.parentNode;}
	if(o.id!='mainBox'){
		$("mainBox").style.display='none';
		$('hideSelectorIFrame').style.display = "none";
	}
}
function fnHidePop(e,id){
	e = e || window.event;
	o = e.relatedTarget||e.toElement;
	if(o==null)return;
	while(o.parentNode&&o.id!=id){	o=o.parentNode;}
	if(o.id!=id){
		$(id).style.display='none';
	}
}
/** AD js start **/
//for publish ad
 function publishAd(){
  var j = 0;
  //find adp
  var divs = new Array();
  var positions = new Array();
  var positionId = new Array();
  divs=document.getElementsByTagName("div");
   for(var i=0;i<divs.length;i++){
     var nam;
	 nam = divs[i].id;
	 if(!nam)
	  continue;
	 if(nam.length>2){
	  if(nam.indexOf("advertisement_")==0){
	   if(!isNaN(nam.substr(2,nam.length-1))){
	      var positionName=divs[i].getAttribute("adPositionType");
	      if(!positionName){
	      	continue;
	      }
	      if(divs[i].innerHTML==null||divs[i].innerHTML=="")
	       divs[i].style.display="none";
	      positions[j] = positionName;
		  positionId[j] = nam.substr(2,nam.length-1);
	      j++;
		}
	   }
	 }
   }   
 }
 
function fnChangeImg()
{
	if(num>adLen){
		num=1;
	}
	var oPic=document.getElementById("focusPic"+num);
	if(oPic==null){
		num=1;
	}
	setTimeout("setFocusTimer()",20000);
	num++;
	setTimeout('fnChangeImg()',20000);
}
function setFocusTimer(){
	setFocus(num,adLen);
}
function fnSetAdLen(len){
	adLen=len;
}
function setFocus(current,len)
{
	if(len!=null && len>0){
		adLen=len;
	}
	var hasShow=0;
	for(var ind=1;ind<=len;ind++){
		var oPic=document.getElementById("focusPic"+ind);		
		var oNav=document.getElementById("fnLi_"+ind);	
		if(oPic!=null){
			if(ind==current){
				oPic.style.display="block";
				oNav.className="selected";
				hasShow=1;
				num=current;
			}else{
				oPic.style.display="none";
				oNav.className="";			
			}
		}
	}
	if(hasShow==0){
		var oPic=document.getElementById("focusPic1");		
		var oNav=document.getElementById("fnLi_1");	
		if(oPic!=null){
			oPic.style.display="block";
			oNav.className="selected";
		}		
		num=1;
	}
}
/** AD js end **/
function fillLoginPrompt() {
	var _str='';
	if (!isLogined()) {
		_str=_str+'<a href="'+__ctxPath+'/customer/account.html">'+__FMT.customer_account+'</a>&nbsp;|&nbsp;';
		_str=_str+'<a href="'+__ctxPath+'/customer/signup.html">'+__FMT.customer_login+'</a>&nbsp;|&nbsp;<a href="'+ __ctxPath+'/customer/register.html">'+__FMT.customer_signup+'</a>';
	} else {
		_str=_str+'<a href="'+__ctxPath+'/customer/account.html">'+getCookie("UNAME")+'</a>&nbsp;|&nbsp;';
		_str=_str+'<a href="'+__ctxPath+'/j_acegi_logout">'+__FMT.customer_logout+'</a>';
	}
	$("loginPromptHolder").innerHTML=_str;
}