/**
 *在StoreFront常用的脚本
 */

function signInViewPrice(){
	doRequiredLoginAction(function(){
	    document.location.reload();	
	});
}
/*
 * for miniCart
 */
function getMiniCartInfo(){
	var minCartInfo=getCookie("cookie_shoppingcart");
	if(minCartInfo!=null){
		var cartInfo=minCartInfo.split("|");
		return "<a href='#'>我的购物篮 <b>("+cartInfo[1]+" "+ __FMT.minicart_itemUnit +" ¥"+ cartInfo[2]+")</b></a>";
	}else{
		return "<a href='#'>我的购物篮 <b>(0"+ __FMT.minicart_itemUnit +" ¥0.00)</b></a>";
	}
}
/*
 * for miniCart
 */
function getMiniCartInfoForEshopping(){
	var minCartInfo=getCookie("cookie_shoppingcart");
	if(minCartInfo!=null){
		var cartInfo=minCartInfo.split("|");
		return "<b>"+cartInfo[1]+" "+ __FMT.minicart_itemUnit +" ¥"+ cartInfo[2]+"</b>";
	}else{
		return "<b>0"+ __FMT.minicart_itemUnit +" ¥0.00</b>";
	}
}
function refreshMiniCartInfo(){
	if($("spanMiniCartInfo")){
		$("spanMiniCartInfo").innerHTML=getMiniCartInfo();
	}
}

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";
		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 = "block";
}
/*隐藏 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";
	}
}
/** 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="curr";
				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="curr";
		}		
		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>';
	}
	if($("loginPromptHolder")){
	$("loginPromptHolder").innerHTML=_str;
	}
}