﻿
try  {  document.domain='dangdang.com';  }
catch(err) {} 


function $(element) {
  if (typeof element == 'string')
    element = document.getElementById(element);
  return element;
}


var currTId = null;
var currDId = null;
function mouseOver(obj,tag0,tag1,id)
{

if( currTId!=null)
{
 if($(currTId)) $(currTId).style.display="block";
 if($(currDId)) $(currDId).style.display="none";	   
}	

var Tid = tag0 + id;
var Did = tag1 + id;

if($(Tid)) $(Tid).style.display="none";	   
if($(Did)) $(Did).style.display="block";	  

currTId = Tid;
currDId = Did;


}


function openWin(url,name,w,h)
 {
    var x=(window.screen.width-w)/2;
	var y=(window.screen.height-h)/2;
	var win=window.open(url,name,'toolbar=0,location=0,status=0,top='+y+',left='+x+',width='+w+',height='+h );
	win.focus();
	
	return win;
 }
function openSuitWin(url,name)
 {
	var sw=window.screen.width;
	var sh=window.screen.height;
	var w=sw-300;
	var h=sh-300;
	var x=(sw-w)/2;
	var y=0;
	var win=window.open(url,name,'toolbar=0,scrollbars=1,location=1,menubar=1,resizable=1,status=1,top='+y+',left='+x+',width='+w+',height='+h );
	win.focus();
 }
 
 var last_img_btn_chg_prd=null;
 
function ImgBtnChgPrd_Mouseover(obj,mainpictureurl,largepictureurl)
 {

    if(last_img_btn_chg_prd!=null) 
        last_img_btn_chg_prd.className='img_btn_chg_prd';
    last_img_btn_chg_prd=obj;
    obj.className='img_btn_chg_prd_active';
    
    

    document.getElementById('img_show_prd').src=mainpictureurl;
	document.getElementById('img_show_prd').onclick=function(){ImgBtnChgPrd_Click(this,largepictureurl);}
	document.getElementById('spn_tobig').onclick=function(){ImgBtnChgPrd_Click(this,largepictureurl);}
	
 }

function ImgBtnChgPrd_Click(obj,largepictureurl)
 {
    document.getElementById('hid_largepictureurl').value=largepictureurl;
	var win=openWin('ProductExp.aspx','preview',700,580);
	win.opener=this;
 }

function suitImage(img,w,h)
{
		var image=new Image();
        image.src=img.src;

		var iw=image.width;
		var ih=image.height;
		var iratio=iw/ih;
        
        if(iw>w)
		{
                iw=w;
				ih=w/iratio;
        }
        if(ih>h)
		{
                ih=h;
                iw=h*iratio;
        }  
		img.width=iw;
		img.height=ih;
}

function AddToFavorlist(product_id)
{  
	var url="http://customer.dangdang.com/wishlist/cust_wish_add.aspx?productid="+product_id;
	var popup=window.open(url,"favorlist");
	popup.focus()
}

function addlike(product_id)
{
    if(confirm(unescape("%u786E%u5B9A%u5C06%u6B64%u4EA7%u54C1%u52A0%u5165%u60A8%u611F%u5174%u8DA3%u7684%u5546%u54C1%u5417%uFF1F")))
			document.getElementById("likepd").src="http://www.dangdang.com/usercut/savelikepd.asp?productid="+product_id+"&like=1";
}

function AddToOutOfStock(product_id)
{
    var url='http://www.dangdang.com/shoppingcart/pdnothing.aspx?pdname='+product_id;
    openWin(url,400,280);
}

function set_review_summary(product_type,total_review_count,total_question_count)
{
    //var str_total_count=product_type=='GM' || product_type=='UnKnow'?total_question_count:total_review_count;
      var str_total_count= product_type=='UnKnow'?total_question_count:total_review_count;
    if(str_total_count>'0')
    {
        var reviewTag = document.getElementById("review_summary");
        var revTag = document.getElementById("spn_rev_cnt");
        
        if(reviewTag)reviewTag.style.display='inline';
        if(revTag) revTag.innerHTML=str_total_count;
    }
}


var red_array=["顾客评分：","<img src='images/star_gray.gif' />","<img src='images/star_gray.gif' />","<img src='images/star_gray.gif' />","<img src='images/star_gray.gif' />","<img src='images/star_gray.gif' />"];
function set_average_score(average_score)
{
    if(average_score=='' || average_score < 0.5)
        return;

    var int_average_score = parseInt(average_score);
    for(var i=0;i<int_average_score;i++)
        red_array[i+1]="<img src='images/star_red.gif' />";
        
    if(int_average_score<average_score)
        red_array[i+1]="<img src='images/star_red2.gif' />";
    
    if( document.getElementById('spn_average_score'))
    document.getElementById('spn_average_score').innerHTML=red_array.join('');
}

function AddToShoppingCart(product_id)
{
	var url=null;

	if(product_id==null || product_id<1)
		url="http://shopping.dangdang.com/shoppingcart/shopping_cart.aspx";
	else
		url="http://shopping.dangdang.com/shoppingcart/shopping_cart_add.aspx?product_ids="+product_id+"&reference_url="+escape(window.location.href);

	var popup=window.open(url,"shoppingcart");
	popup.focus()
}


window.onerror=function()
{
	return true;
}






function getposOffset(what, offsettype)
{ 
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop; 
    var parentEl=what.offsetParent; 
    while (parentEl!=null)
    { 
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop; 
         parentEl=parentEl.offsetParent; 
    } 
    return totaloffset; 
} 

function showLocSelect(objid,divId,x_offset,y_offset)
{
	
	var locdiv=document.getElementById(divId);
	var obj=document.getElementById(objid);
	
    locdiv.style.top=(getposOffset(obj,"top")-y_offset)+"px";
	locdiv.style.left=(getposOffset(obj,"left")-x_offset)+"px";
	locdiv.style.display="block";
}

function hideLocSelect(divId)
{	
	document.getElementById(divId).style.display="none";
}



var cat_link =
{
		'作者':'http://search.book.dangdang.com/search.aspx?category=01&key2=',
		'出版社':'http://search.book.dangdang.com/search.aspx?category=01&key3=',
		'歌手':'http://search.music.dangdang.com/search.aspx?catalog=03&key2=',
		'演奏者':'http://search.music.dangdang.com/search.aspx?catalog=03&key2=',
		'导演':'http://search.movie.dangdang.com/search.aspx?catalog=05&key2=',
		'主演':'http://search.movie.dangdang.com/search.aspx?catalog=05&key4='
};

var new_click_99_name=
{
        '作者':'author_bk',
		'出版社':'publisher_bk',
		'歌手':'singer',
		'演奏者':'singer',
		'导演':'director',
		'主演':'star'
};

var li_ids=
{
        '作者':'author_',
		'出版社':'publisher_',
		'歌手':'singer_',
		'演奏者':'singer_',
		'导演':'director_',
		'主演':'star_'
};



var click_99_name=
{
        '作者':'author',
		'出版社':'publisher',
		'歌手':'singer',
		'演奏者':'singer',
		'导演':'director',
		'主演':'star'
};

function key_link(cat,key,mode)
{
    var click_name = null;
    
    if(mode == "new")
    {
     click_name = new_click_99_name;
    }
    else
    {
      click_name = click_99_name;
    }
    var normal_html= "";
	var link =cat_link[cat] + escape(key);
	var link_name=click_name[cat];
	var rep_id=li_ids[cat];
	var link_html="<a  class='blue12a'  href='"+link+"' name='"+link_name+"' target='_blank'>"+key+"</a>";
	if(document.getElementById(rep_id))normal_html = document.getElementById(rep_id).innerHTML;	
	if(document.getElementById(rep_id)) document.getElementById(rep_id).innerHTML=normal_html.replace(key,link_html);
}