  //  
  // DuracellDirect.cn Web Site methods - Ben Jay Aug 2006  
  var siteTag = 'ddcn'; 
  var siteLinkRoot = 'http://www.duracelldirect.cn/'; 
  var siteSecRoot = 'https://www.duracelldirect.cn/'; 
  var siteRoot = 'http://www.duracelldirect.cn/'; 
  var siteServRoot = 'http://www.duracelldirect.cn/'; 
  var siteDomain='duracelldirect.cn'; 
 
  //-------------------------------------------   
	// no longer used by EU sites, can be removed soon. 
  function hidePhoto()  
  {  
    // if the screen is tall enough, then don't hide the photo ever: 
    if(document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth && 
	document.documentElement.clientHeight > 800 && document.documentElement.clientWidth > 950) 
    { 
      el1=document.getElementById('photo');  
      el1.style.height='185px';  
      el1.style.visibility='visible';  
      el2=document.getElementById('phototext');  
      el2.style.visibility='visible';  
      return; 
    } 
 
    // if we've already displayed the promo photo, leave it hidden: 
    if(readCookie('hidephoto')!='yes') { 
      el1=document.getElementById('photo');  
      el1.style.height='185px';  
      el1.style.visibility='visible';  
      el2=document.getElementById('phototext');  
      el2.style.visibility='visible';  
      setTimeout('hidePhoto2()',8000);  
      createCookie('hidephoto','yes'); 
    }     
  }  
  //-------------------------------------------    
  function hidePhoto2()  
  {  
    el1=document.getElementById('photo');  
    if(el1.offsetHeight>7)  
    {  
      el1.style.height=''+(el1.offsetHeight-7)+'px';  
      el2=document.getElementById('phototext');  
      el2.style.visibility='hidden';  
      setTimeout('hidePhoto2()',10);  
    }  
    else  
    {  
      el1.style.visibility='hidden';  
      el1.style.position='absolute';  
    }    
  }  
  //-------------------------------------------   
  // check the email address is reasonable:  
 
  function checkEmail(email)  
  {  
    if(!isValidEmail(email))  
    {  
      alert('\u6b64\u90ae\u7bb1\u5730\u5740\u65e0\u6548\u3002\n \u90ae\u7bb1\u5730\u5740\u5e94\u8be5\u4e0e\n\n yourname@yourcompany.com\n\n \u7c7b\u4f3c\uff0c\u5e76\u4e0d\u5305\u62ec\u7a7a\u683c\u3002\u8bf7\u91cd\u65b0\u8f93\u5165\u3002');  
      return false;  
    }  
    return true;  
  }  
  //-------------------------------------------   
  // check the email address is reasonable:  
  
  function isValidEmail(email)  
  {  
    if(isblank(email))  
      return false;  
  
    email = email.toLowerCase();  
  
    //  check for one '@':  
    var sections = email.split('@');  
    if(sections.length != 2)  
      return false;  
  
    // now split into sections on '.':  
    var username = sections[0].split('.');  
    var domain = sections[1].split('.');  
    if(domain.length < 2)  
      return false;  
  
    // check the username:  
    for(var i = 0; i < username.length; i++) { 
      if(!isValidEmailSection(username[i]))  
        return false;  
		} 
    // check the domain:  
    for(i = 0; i < domain.length; i++) { 
      if(!isValidEmailSection(domain[i]))  
        return false;  
		} 
    return true;  
  }  
  //-------------------------------------------   
  // check this section of an email address is valid  
  // a-z 0-9 - . _  
  
  function isValidEmailSection(sec)  
  {  
    if(sec.length < 1)  
      return false;  
  
    for(var i = 0; i < sec.length; i++)  
    {  
      var cc = sec.charCodeAt(i);  
      if( ((cc < 97) || (cc > 122)) &&  
          ((cc < 48) || (cc > 57)) &&  
          ((cc < 45) || (cc > 46)) &&  
          (cc != 95) )  
  	  return false;  
    }  
    return true;  
  }  
  //-------------------------------------------   
  // function call, embedded within notes etc in the database:  
  
  function pl(linkOb, linkValue)  
  {  
    if(linkValue) 
      linkOb.href=siteLinkRoot + 'pno/plink.html?ps=' + linkValue;    
  }  
  //-------------------------------------------   
  // if a number ends with .0, remove it  
  
  function trimdp(str)  
  {  
    if(str.lastIndexOf('.0') == str.length -2)  
      str = str.substring(0, str.length -2);  
  
    document.write(str);  
  }  
  //-------------------------------------------   
  // check there is a value:  
  
  function isblank(str)  
  {  
    for(var i = 0; i < str.length; i++)  
    {  
      var ch = str.charAt(i);  
      if((ch != ' ') && (ch != '\n') && (ch != '\t'))  
        return false;  
    }  
    return true;  
  }  
  //-------------------------------------------   
  // check there is a value:  
  
  function validCardNo(val, min, max)  
  {  
    var count = 0;  
    for(var i = 0; i < val.length; i++)  
    {  
      var ch = val.charAt(i);  
      if((ch == '0') || (ch == '1')|| (ch == '2') || (ch == '3') || (ch == '4') ||   
         (ch == '5') || (ch == '6') || (ch == '7') || (ch == '8') || (ch == '9'))  
        count++;  
      else if(ch != ' ')  
        return false;  
    }  
  
    if((count.valueOf() < min) || ((count.valueOf() > max) && (max > -1)))  
      return false;  
  
    return true;  
  }  
  //-------------------------------------------   
  
  function showHelp(helpTopic)  
  {  
    var win = window.open(siteServRoot+'e/Page.Filler?_page=help/'+helpTopic,'_help','status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes, width=650, height=400');  
    win.focus();  
  }  
  //-------------------------------------------   
  // check if the servlets have been able to set a Cookie, direct them to an error page if blocked.  
  function cookieCheck()  
  {      
    if(document.cookie.length < 1 && document.location.pathname.indexOf('/e/') != -1 && document.location.search.indexOf('cookies') == -1)  
      document.location = siteLinkRoot + 'info/cookies.html?returl=' + escape(document.location);  
  }  
  cookieCheck();  
 
  //-------------------------------------------   
 
  // reload the page which sent them to the Cookie error page.  
  function cookieContinue()  
  {  
    var i = document.location.search.indexOf('returl=');  
    var j = document.location.search.indexOf('&', i);  
    if(j < 0)  
      j = document.location.search.length;  
  
    if(i < 0 || i+7 == j)  
      document.location = 'http://www.duracelldirect.cn/'; 
    else  
      document.location = unescape(unescape(document.location.search.substring(i+7, j)));  
  }  
  //-------------------------------------------   
   
  function showLiveStock(isLive, level, order, central) 
  { 
    if(!isLive) 
      return;  
 
    if(level > 0) 
      document.write('有现货'); 
    else if(order > 0) 
      document.write('<b>商品补货中</b><br>(即将到货)'); 
    else if(central > 0) 
      document.write('<b>预购</b><br>(到货需要8天时间)'); 
    else 
      document.write('<b>货物补仓中，可预购</b><br>(可购买量未知)'); 
  }  
  //-------------------------------------------   
 
  function showLivePrice(isLive, value) 
  { 
    if(!isLive) 
      return; 
    document.write(value); 
  } 
  //-------------------------------------------   
 
  function order(locator,qty)   
  {   
		qty=1; 
		var el=document.getElementById('qty-'+locator); 
		if(el) 
			qty=el.value; 
    if(typeof(locator) == "undefined")   
      this.location=siteServRoot+'e/Shopping.Cart';  
		else 
      this.location=siteServRoot+'e/Shopping.Cart?_action=add&p_surrogate='+locator+'&qty='+qty; 		 
  }   
  //------------------------------------------- 
 
  function orderVpn(vpn, vpn2, qty)  
  {  
		if(!qty) 
			qty=1; 
		if(typeof(vpn) == "undefined")  
      this.location=siteServRoot+'e/Shopping.Cart';  
		else if(typeof(vpn2) == "undefined" || vpn2=='-')  
      this.location=siteServRoot+'e/Shopping.Cart?_action=add&vpn='+vpn+'&qty='+qty;	  
    else  
      this.location=siteServRoot+'e/Shopping.Cart?_action=add&vpn='+vpn+'&qty='+qty+'&vpn2='+vpn2+'&qty2='+qty;  
  }	  
  //-------------------------------------------   
 
  function orderTip(tipVpn)  
  {  
	  if(!confirm('警告: 此电源插嘴只适用于2-Power品牌的多功能电源插嘴类商品。您确定要购买此电源插嘴吗？')) 
		  return; 
		orderVpn(tipVpn,'-'); 
  }	  
  //-------------------------------------------   
	 
  function showCountryList(start, selected)  
  {  
    document.writeln('<SELECT ' + start + '>');  
  
    var countries = [ 'CN','中国' ]; 
  
    for(var i = 0; i < countries.length; i = i+2)  
    {  
      var html = '<OPTION value="' + countries[i] + '"';  
      if(countries[i] == selected)  
        html += ' selected';  
      html += '>' + countries[i+1] + '</OPTION>';  
      document.writeln(html);  
    }  
    document.writeln('</SELECT>');  
  }  
  //-------------------------------------------   
  
  function showYearList(start, selected, full)  
  {  
//    var currentYear = 2004;   
    var currentYear = (new Date()).getFullYear();  
  
    document.writeln('<SELECT ' + start + '>');  
    var maxYear = currentYear + 10;  
    if(full)  
    {  
      maxYear = currentYear + 1;  
      currentYear = currentYear - 5;  
      if(selected == ' ')  
        document.writeln('<OPTION value=" " selected> </OPTION>');  
      else  
        document.writeln('<OPTION value=" "> </OPTION>');  
    }  
  
    for(var i = currentYear; i < maxYear; i++)  
    {  
      var html = '<OPTION value="' + i + '"';  
      if(i == selected)  
        html += ' selected';  
      html += '>' + i + '</OPTION>';  
      document.writeln(html);  
    }  
    document.writeln('</SELECT>');  
  }  
  //-------------------------------------------   
  
  function showMonthList(startHtml, selected, full)  
  {  
    document.writeln('<SELECT ' + startHtml + '>');  
  
    var list = [' ',' ', '01','01', '02','02', '03','03', '04','04', '05','05', '06','06', '07','07', '08','08', '09','09', '10','10', '11','11', '12','12'];  
    var start = 2;  
    var end = list.length -2;  
    if(full)  
      start = start - 2;  
  
    for(var i = start; i <= end; i = i+2)  
    {  
      var html = '<OPTION value="' + list[i] + '"';  
      if(list[i] == selected)  
        html += ' selected';  
      html += '>' + list[i+1] + '</OPTION>';  
      document.writeln(html);  
    }  
    document.writeln('</SELECT>');  
  }  
 
   
  //-------------------------------------------   
 
  function email(account, text, html) 
  { 
    if(typeof(html) == "undefined") 
      html=''; 
    document.write('<a href="mailto:'+account+'@'+siteDomain+'" '+html+'>&bull;'+text+'</a>'); 
  } 
 
  //-------------------------------------------    
 
  function createCookie(name,value,days) { 
		var expires = ""; 
  	if (days) { 
	  	var date = new Date(); 
		  date.setTime(date.getTime()+(days*24*60*60*1000)); 
  		expires = "; expires="+date.toGMTString(); 
	  } 
	document.cookie = name+"="+value+expires+"; path=/"; 
  } 
 
  function readCookie(name) { 
	var nameEQ = name + "="; 
	var ca = document.cookie.split(';'); 
	for(var i=0;i < ca.length;i++) { 
		var c = ca[i]; 
		while (c.charAt(0)==' ') c = c.substring(1,c.length); 
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 
	} 
	return null; 
  } 
 
  function eraseCookie(name) { 
	createCookie(name,"",-1); 
  } 
 
  //-------------------------------------------     
  // modify the height of the tiles to match the tallest.  
  function adjustTileHeight(tagtype)    
  {    
    if(typeof document.body.clientHeight == 'undefined')      
      return;       // clientHeight is not supported by old netscape    
   
		if(!tagtype) 
			tagtype='div'; 
    var offHeight=0;   
    var tags=document.getElementsByTagName(tagtype);   
		var div; 
    for(var i=0;i<tags.length;i++)   
    {   
      div=tags[i];   
      if(div.id.substr(0,5)=='tile-' && div.offsetHeight>offHeight)   
        offHeight=div.offsetHeight;   
    }           
    for(i=0;i<tags.length;i++)   
    {   
      div=tags[i];   
      if(div.id.substr(0,5)=='tile-')   
        div.style.height=offHeight+'px';   
    }           
  }    
 
  //-------------------------------------------     
// ============================================== 
	// show/hide enlarged product image 
	var prodImgRollerVisible=false; 
	var prodImgRollerSrc=''; 
 
 
 
	// ------------------ 
		function prodImgRollerShow(img,enlarge) 
		{ 
			enlarge=true; 
			if(prodImgRollerSrc==img.src) 
			{ 
				if(prodImgRollerHiding) 
					clearTimeout(prodImgRollerHiding); 
				else if(prodImgRollerVisible) 
					return;				 
			} 
			 
			var el1=document.getElementById('prodImgRoller'); 
			var cleanedSrc=img.src.replace(/_stamp/g, ''); 
			prodImgRollerSrc=img.src; 
			var vpId=img.id.substring(3); 
			var html=''; 
			if(enlarge) 
			{ 
				html+='<img src="'+cleanedSrc+'">'; 
				el1.innerHTML=html;			 
//alert(img.offsetLeft+' : '+img.offsetTop); 
				el1.style.left=(img.offsetLeft+100)+'px'; 
				el1.style.top=(img.offsetTop+0)+'px';			 
			} 
			else 
			{ 
//				if(!productVisible[vpId]) 
//					html='<table class="alert"><tr><th><img src="/i/icons/alert.gif"></th><td><b>This product is currently hidden.</b><br>Change the \'Product Display Filter\' options on the left, or click on the thumnail image to display this product.</td></tr></table>'; 
//				else 
//					html='<p>Click on the thumbnail image to jump to this product.</p>'; 
 
				html+='<img src="'+cleanedSrc+'">'; 
				el1.innerHTML=html;			 
//alert(img.offsetLeft+' : '+img.offsetTop); 
				el1.style.left=(img.offsetLeft+0)+'px'; 
				el1.style.top=(img.offsetTop+70)+'px'; 
			} 
 
			el1.style.visibility='visible'; 
		} 
	// ------------------ 
		function prodImgRollerHide() 
		{ 
			var el1=document.getElementById('prodImgRoller');		 
			prodImgRollerSrc=''; 
			el1.style.visibility='hidden'; 
			prodImgRollerVisible=false; 
		}		 
	// ------------------ 
		var prodImgRollerHiding=null;		 
		 
		function prodImgRollerOver() 
		{ 
			if(prodImgRollerHiding) 
				clearTimeout(prodImgRollerHiding); 
		}		 
	// ------------------ 
		function prodImgRollerOut() 
		{				 
			prodImgRollerHiding=setTimeout('prodImgRollerHide()',50);   
		}	 
	// ------------------ 
  function openSpPop(spMes) { 
    var spPop=document.getElementById('spPop'); 
    spPop.innerHTML=document.getElementById('spText').innerHTML+'<div>'+document.getElementById('sideDevs').innerHTML+'<div>'; 
    spPop.style.top=(spMes.offsetTop+116)+'px'; 
    spPop.style.left=(spMes.offsetLeft-100)+'px'; 
    spPop.style.visibility='visible'; 
  } 
	// ------------------ 
  function closeSpPop() { 
    document.getElementById('spPop').style.visibility='hidden'; 
  } 
// ============================================== 
// generic method to return an object with properties 'top' and 'left' set to the actual top and left pixel positions of the object given. 
function getTopLeft(object) { 
  var pos=new Object(); 
  pos.top=0; 
  pos.left=0; 
  if(object.offsetParent) { 
    do { 
      pos.top+=object.offsetTop; 
      pos.left+=object.offsetLeft; 
    } while(object=object.offsetParent); 
  } 
  return pos; 
} 
  //------------------------------------------- 
	// called to finish setting up pno/model/mpno page 
	function loadStuff() { 
		// Load the thumbnail in the large product container 
		var lg_prods=document.getElementsByName('lg-product'); 
		count=0; 
		while (count<lg_prods.length) { 
			count=count+1; 
			var thumbs=document.getElementsByName('thumb-'+count); 
			var thumb_count=0; 
			while (thumb_count<thumbs.length) { 
				var thumb_id=thumbs[thumb_count].id; 
				var thumb=document.getElementById(thumb_id); 
				thumb_count+=1; 
				var thumb_url=document.getElementById('thumb-'+count+'-'+thumb_count+'-lg-img'); 
				thumb.src=thumb_url.href;//innerHTML; 
				if (thumb_count==1) { 
					thumb.className='thumb selected'; 
				} 
				else { 
					thumb.className='thumb'; 
				} 
			} 
		}; 
	} 
  //------------------------------------------- 
	function ShowThumb(curr_thumb) { 
		var thumbs=document.getElementsByName(curr_thumb.name); 
		var count=0; 
		while (count<thumbs.length) { 
			var thumb_id=thumbs[count].id; 
			var thumb=document.getElementById(thumb_id);  
			thumb.className='thumb'; 
			count+=1; 
		}; 
		curr_thumb.className='thumb selected'; 
		 
		var thumb_lg_img_url=document.getElementById(curr_thumb.id+'-lg-img'); 
		var img=document.getElementById('lg-prod-'+curr_thumb.name.substring(6)); 
		img.src=thumb_lg_img_url.href;//innerHTML; 
	} 
  //------------------------------------------- 
	sfHover = function() {  
	  var sfEls = document.getElementById("nav").getElementsByTagName("LI");  
    for (var i=0; i<sfEls.length; i++) {  
	    sfEls[i].onmouseover=function() {  
		    this.className+=" sfhover";  
      }  
      sfEls[i].onmouseout=function() {  
	      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");  
      }  
	  }  
  }  
  if (window.attachEvent)   
	  window.attachEvent("onload", sfHover);  
  // start Nav bar stuff -------------------------------------------  
  function closeNavPanel() {  
		var pnl=document.getElementById('prod-panel');  
		pnl.style.top='-1000px';  
		setTimeout('resetNavPanel()',500);  
	}  
  //-------------------------------------------  
  function resetNavPanel() {  
		var pnl=document.getElementById('prod-panel');  
		pnl.style.top='-10px';  
	}  
  // end Nav bar stuff -------------------------------------------  
  
   
//-------------------------------------------   
  // put the most likely code to cause unterminated javascript errors at the end of the js file.  
  function showSidePromos(siteSection) { 
    //document.writeln('<h4>热销商品:</h4>'); 
//    document.writeln('<div><a href="/pno/hr06.html"><img src="/i/promos/products/hr06.gif"></a></div><div><a href="/pno/cef80.html"><img src="/i/promos/products/cef80.gif"></a></div><div><a href="/pno/du-sd-2048-r.html"><img src="/i/promos/products/du-sd-2048-r.gif"></a></div>'); 
    var promos = new Array(); 
   
		    promos[0]='<div><a href="/pno/mn1500b8.html"><img src="/i/promos/products/mn1500b8.gif"></a></div><img src="/i/bar/sep1.gif">'; 
		    promos[1]='<div><a href="/pno/mn2400b8.html"><img src="/i/promos/products/mn2400b8.gif"></a></div><img src="/i/bar/sep1.gif">'; 
		    promos[2]='<div><a href="/pno/mn1400b2.html"><img src="/i/promos/products/mn1400b2.gif"></a></div><img src="/i/bar/sep1.gif">'; 
		    promos[3]='<div><a href="/pno/mn1604b1.html"><img src="/i/promos/products/mn1604b1.gif"></a></div><img src="/i/bar/sep1.gif">'; 
//	if('ddcn'=='ddgb') { 
//	  document.write('<div><a href="/competition/index.html"><img src="/i/promos/products/blog.gif"></a></div><img src="/i/bar/sep1.gif">'); 
//	} 
	var count = 0; 
    while(promos.length>0 && count<4) 
		{ 
			count++; 
		  	i = Math.round((Math.random()*promos.length)-0.5); 
	  		document.write(promos[i]); 
			if(promos.length>0) 
			  promos.splice(i,1);			 
		}		 
  } 
 
//-------------------------------------------   
 
   


