﻿function urlEncoding(str)
{
    str = str.replace(/%/g,"%25");
    str = str.replace(/&/g,"%26");
    str = str.replace(/=/g,"%3d");
    str = str.replace(/#/g,"%23");
    str = str.replace(/[+]/g,"%2b");
    return str;
}

function AddPDNothing(ProdID)
{
	var url = "http://www.dangdang.com/shoppingcart/pdnothing.aspx?pdname="+ProdID;
	window.open(url);
}

function DrawImage(img){ 
var width=50;
var height=69;

var image=new Image(); 
image.src=img.src; 
	if(image.width>0 && image.height>0)
	{
	  if(image.width!=width)
	  {
	  	rate=image.height/image.width;
	  	newHeight=rate*width;
	  	img.width=width;
	  	img.height=newHeight;
	  } 
	}
	if(img.height>height)
	{
		rate=image.width/image.height;
		newWidth=rate*height;
		img.height=height;
		img.width=newWidth;
	}
}


function setCookie (name, value, days) {
  var expires = new Date();
  expires.setTime (expires.getTime() + (86400 * 1000 * days));
  document.cookie = name + "=" + escape(value) +   "; expires=" + expires.toGMTString() +  "; path=/";
}

function getCookie(name) {
  var search;
  search = name + "="
  offset = document.cookie.indexOf(search) 
  if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return unescape(document.cookie.substring(offset, end));
  }
  else
    return "";
}

function deleteCookie(name) {
  var expdate = new Date();
  expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
  setCookie(name, "", expdate);
}

var WordCount=99;

//function isExecute(id,imagePath)
//{
////    obj=document.getElementById("div_"+id);   
////    
////    var str = obj.innerText;
////    var count = str.length;
//    if(divCount(id)>WordCount)
//        slide(id,imagePath);    
//}

function strCount(id,imagePath)
{
    obj=document.getElementById("div_"+id);
    img=document.getElementById("img_"+id);
    
    var str = obj.innerText;
    var count = str.length;
    if(count>WordCount)
    {
        img.style.display="block";        
    }
    else
        img.style.display="none";
}

function divCount(id)
{
    obj=document.getElementById("div_"+id);   
    if(obj==null) return 0;
    var str = obj.innerText;
    return str.length;
    
}

var intervalId = null; 
var falg = null;
function slide(id,imagePath,nMaxHth,nMinHth)
{   
    sp1=document.getElementById("sp1_"+id);
    sp2=document.getElementById("sp2_"+id);
    sp1.style.display="none"; 
    sp2.style.display="block";    
    
    obj=document.getElementById("div_"+id);
    img=document.getElementById("img_"+id);
    
    this.maxHeigth=divCount(id)/50*19 || 90; 
    this.minHeigth=nMinHth || 30; 
    this.state=img.getAttribute("state") || "down" ;
    
    if(this.state=="down")
    {        
        img.setAttribute("state","up");
        img.src=imagePath+"fold_up.gif";
        img.title="收起";
    }
    else
    {
        img.setAttribute("state","down");
        img.src=imagePath+"fold_down.gif";
        img.title="展开";        
    }
    function openBox(){     
    var h = obj.offsetHeight; 
    //obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px"; 
    if(this.state== "down")
    {
         obj.style.height = h + 2 +"px";
         if(obj.offsetHeight>this.maxHeigth){ 
         window.clearInterval(intervalId); 
         sp1.style.display="block"; 
         sp2.style.display="none";
         //intervalId=window.setInterval(closeBox,this.stayTime); 
         }
     }
     else
     {
         obj.style.height = h - 2 +"px"; 
         if (obj.offsetHeight<this.minHeigth){ 
         window.clearInterval(intervalId); 
         sp1.style.display="block"; 
         sp2.style.display="none";
         //obj.style.display="none"; 
         }
     }    
   } 
   intervalId = window.setInterval(openBox,10);    
}

function isIE(){ //ie? 
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) 
    return true; 
   else 
    return false; 
} 

if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText", 
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    } 
   ); 
   HTMLElement.prototype.__defineSetter__(     "innerText", 
    function(sText){ 
     this.textContent=sText; 
    } 
   ); 
}

function fucCheckLength(strTemp)    
{    
var i,sum;    
sum=0;    
for(i=0;i<strTemp.length;i++)    
{    
  if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))    
    sum=sum+1;    
  else   
    sum=sum+2;    
}    
return sum;    
}    


	function SafeXML(s) {
		s = s.replace(/(&+)/g,'&amp;');
		s = s.replace(/(>+)/g,'&gt;');
		s = s.replace(/(<+)/g,'&lt;');
		s = s.replace(/("+)/g,'&quot;');
		s = s.replace(/('+)/g,'&apos;');
		return s;
	}
	
	function SafeXMLSBCcase(s) {
		s = s.replace(/(>+)/g,'＞');
		s = s.replace(/(<+)/g,'＜');
		s = s.replace(/("+)/g,'＂');
		s = s.replace(/('+)/g,'＇');
		s = s.replace(/(&+)/g,'＆');
		return s;
	}
	
	function HTMLEncode(s) {
		s = s.replace(/(\s+)/g,'&nbsp;');
		s = s.replace(/(\n+)/g,'<br/>');
		return s;
	}	


function toBreakWord(intLen, id){
var obj=document.getElementById(id);
if(isIE()|obj==null)return;
var strContent=SafeXML(obj.innerText); 
var strTemp="";
while(strContent.length>intLen){
   strTemp+=strContent.substr(0,intLen)+"&#10;"; 
   strContent=strContent.substr(intLen,strContent.length); 
}
strTemp+="&#10;"+ strContent;
obj.innerHTML=strTemp;
}