﻿function checkState(state){
	var str='';
	if(state==false){
		str='加入名單中';
	}else{
		str='從名單中刪除';
	}
	return str;
}

function getGmap(id, name){
	var map;
	switch(name){
		
		case '基道出版社':
			map = '<iframe width="775" height="436" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.hk/maps/ms?ie=UTF8&amp;hl=zh-TW&amp;s=AARTsJoJR4CIQsr5-n-ofFiokO87uaoT3w&amp;msa=0&amp;msid=102931687472801946042.000458b6bfe7a6fa131b2&amp;ll=22.39732,114.195778&amp;spn=0.00865,0.01663&amp;z=16&amp;output=embed"></iframe>';
			break;
		case '基道書樓':
			map = '<iframe width="775" height="436" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.hk/maps/ms?ie=UTF8&amp;hl=zh-TW&amp;s=AARTsJoJR4CIQsr5-n-ofFiokO87uaoT3w&amp;msa=0&amp;msid=102931687472801946042.000458b6bfe7a6fa131b2&amp;ll=22.32217,114.169257&amp;spn=0.008654,0.01663&amp;z=16&amp;output=embed"></iframe>';
			break;
		case '宇宙光':
			map = '<iframe width="775" height="436" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.hk/maps/ms?ie=UTF8&amp;hl=zh-TW&amp;s=AARTsJoJR4CIQsr5-n-ofFiokO87uaoT3w&amp;msa=0&amp;msid=102931687472801946042.000458b6bfe7a6fa131b2&amp;ll=25.02567,121.536598&amp;spn=0.008477,0.01663&amp;z=16&amp;output=embed"></iframe>';
			break;
		case '書花書室':
			map = '<iframe width="775" height="436" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.hk/maps/ms?ie=UTF8&amp;hl=zh-TW&amp;s=AARTsJoJR4CIQsr5-n-ofFiokO87uaoT3w&amp;msa=0&amp;msid=102931687472801946042.000458b6bfe7a6fa131b2&amp;ll=3.08543,101.657996&amp;spn=0.009342,0.01663&amp;z=16&amp;output=embed"></iframe>';
			break;
		case '活水書室':
			map = '<iframe width="775" height="436" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.hk/maps/ms?ie=UTF8&amp;hl=zh-TW&amp;s=AARTsJoJR4CIQsr5-n-ofFiokO87uaoT3w&amp;msa=0&amp;msid=102931687472801946042.000458b6bfe7a6fa131b2&amp;ll=52.037445,-0.750546&amp;spn=0.01151,0.033259&amp;z=15&amp;output=embed"></iframe>';
			break;
		case '文宣':
			map = '<iframe width="775" height="436" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.hk/maps/ms?ie=UTF8&amp;hl=zh-TW&amp;s=AARTsJoJR4CIQsr5-n-ofFiokO87uaoT3w&amp;msa=0&amp;msid=102931687472801946042.000458b6bfe7a6fa131b2&amp;ll=49.191296,-122.795734&amp;spn=0.024457,0.066519&amp;z=14&amp;output=embed"></iframe>';
			break;
		case '圖書':
			map = '<iframe width="775" height="436" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.hk/maps/ms?ie=UTF8&amp;hl=zh-TW&amp;s=AARTsJoJR4CIQsr5-n-ofFiokO87uaoT3w&amp;msa=0&amp;msid=102931687472801946042.000458b6bfe7a6fa131b2&amp;ll=33.988776,-117.954841&amp;spn=0.015514,0.033259&amp;z=15&amp;output=embed"></iframe>';
			break;
		case '所有':
		default:
			map = '<iframe width="775" height="436" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.hk/maps/ms?f=q&amp;hl=zh-TW&amp;geocode=&amp;num=10&amp;ie=UTF8&amp;msa=0&amp;msid=102931687472801946042.000458b6bfe7a6fa131b2&amp;s=AARTsJo_P7jBTkZtRQSXY8cCnuf2KXQFVw&amp;ll=25.165173,115.3125&amp;spn=116.163092,272.460938&amp;t=p&amp;z=2&amp;output=embed"></iframe>';
			break;
	}
	
	var d = document.getElementById(id);
	d.innerHTML = map;
}

function getStructText(id, name){
	var txt;
	switch(name){
		case 'board':
			txt = '<b>主席：</b>鄧紹光<br><b>成員：</b>王明理、王道隆、李兆匡、張漢強、余劍雲、司徒永富';
			break;
		case 'president':
			txt = '<b>社長：</b>蔡桂球';
			break;
		case 'artwork':
			txt = '內容豐富的不一定有好裝幀，<br>裝幀精美的不一定是沒內涵。<br>我們構思，我們設計，我們以堅持成就美麗。';
			break;
		case 'editorial':
			txt = '我編輯到這裡，文字一個一個地死去；您閱讀到這裡，信息一絲一絲地生成。<br>書籍由閱讀賦予生命、文字由編輯淘煉成金；故事從我開始，由您終結。';
			break;
		case 'copyright':
			txt = '尊重版權，人人有責。<br>如要轉載，記得申請！<br>(請電：26870331)';
			break;
		case 'ministry':
			txt = '文字工作，是停不了的......<br>夢想理想，仍要堅持下去！';
			break;
		case 'executive':
			txt = '<b>行政：</b>訂文具？打文件？穿套裝？<br><b>還是：</b>以微笑迎接世上最瑣碎的俗務？';
			break;
		case 'wholesale':
			txt = '好書供應，源源不絕；<br>竭誠服務，推廣優閱。';
			break;
		case 'bookhouse':
			txt = '因為一本書，我們相遇了<br>因為愛閱讀，我們成長了<br>因為神的愛，我們在一起，<br>基道書樓，願意成為您一生的好朋友。';
			break;
		case 'promo':
			txt = '好東西沒遇上愛惜人是憾事。<br>讓我誠意推薦，叫您廣泛接受，<br>使遺憾化成美麗的祝福。';
			break;
		case 'finance':
			txt = '神對基道的祝福，<br>猶如荒漠中的綠洲。';
			break;
		case '':
		default:
			txt = '';
			break;
		
	}
	var d = document.getElementById(id);
	d.innerHTML = txt;
	var f = document.getElementById(name);
	f.style.borderStyle = 'solid';
	//f.style.borderColor = 'black';
}
	
function clearStructText(id, name){
	var txt;
	switch(name){
		case 'board':
		case 'president':
		case 'artwork':
		case 'editorial':
		case 'copyright':
		case 'ministry':
		case 'executive':
		case 'wholesale':
		case 'bookhouse':
		case 'promo':
		case 'finance':
		case '':
			txt = '';
			break;
		
	}
	var d = document.getElementById(id);
	d.innerHTML = txt;
	var f = document.getElementById(name);
	f.style.borderStyle = 'dashed';
	//f.style.borderColor = '#b2b2b2';
	
}

function showScrollbar(id){
	//alert(id);
	
	var d = document.getElementById(id);
	d.style.overflowX="hidden";
	d.style.overflowY="auto";
}

function hideScrollbar(id){
	
	var d = document.getElementById(id);
	d.style.overflowX="hidden";
	d.style.overflowY="hidden";
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 



function initJSTweener(){
	var p = getURLParam("id");
	if (p=='975'){	
		initTop10();
	}
}



function listScrollLeft(list, listID, listHdr){
	var d = document.getElementById(listID);
	var frameWidth = 540;
	if (list.index== -1){
		list = genList(listID, listHdr);
		list.index = 0;
	}
	
	var c = list[list.index];
	var index = list.index;
	list.index+=4;
	var pos = -c.offsetLeft;
	var listLen = list.length;
	if (list.index==listLen){
		list.index=0;
		JSTweener.addTween(d.style, {
		  time: 2,
		  delay:4,
		  transition: 'easeInOutQuad',
		  onComplete: listScrollLeft,
		  onCompleteParams:[list,listID,listHdr] , 
		  left: pos,
		  suffix: {
			left: 'px'
			}		  
		});	
	}else{	
		
		JSTweener.addTween(d.style, {
		  time: 2,
		  delay:4,
		  transition: 'easeInOutQuad',
		  onComplete: listScrollLeft,
		  onCompleteParams:[list,listID,listHdr] , 
		  left: pos,
		  suffix: {
			left: 'px'
			}
		  
		});
	}
}


function genList(listId, listHdr){
	var list = new Array();
	var d = document.getElementById(listId);
	var len = d.childNodes.length;
	var node = d.firstChild;
	do{
		var h = node.id;
		if (h){
			var hLen = listHdr.length;
			if (h.substr(0,hLen)==listHdr){
				list.push(node);
			}
		}
	}while(node=node.nextSibling)
	return list;
}

function toggleBookList(b){
	
	var d = document.getElementById(b);
	var sh = 0;
	var h = d.scrollHeight;
	
	var p = getURLParam('test');
	
	if (p=='1'){
		if (parseInt(d.style.height)<100){
			extendDiv(d);
		}else{
			collapseDiv(d);
		}
		
	}else{
		if (d.style.display=="none"){
			d.style.display="block";
			d.style.height=d.scrollHeight;
		}else{
			d.style.display="none";
		}
		//d.style.height = sh;
	}
	
}

function extendDiv(da){
	var d = da;
	
	
	d.style.height='100';
	d.style.display="block";
	var h = d.scrollHeight;
	//d.style.display = "block";
	JSTweener.addTween(d.style, {
		  time: 2,
		  delay:0,
		  transition: 'easeInOutQuad',
		  onComplete: function(){},
		  height: h		  
		});		
		
}

function collapseDiv(da){
	var d = da;
	var h = 100;
	d.style.display = "block";
	JSTweener.addTween(d.style, {
		  time: 2,
		  delay:0,
		  transition: 'easeInOutQuad',
		  onComplete: function(){},
		  height: h		  
		});		
}

var top10List = new Array();
//top10List.index = -1;

function initTop10_2(){
	var id = 'top10-list';
	var d = document.getElementById(id);
	var len = d.childNodes.length;
	var h="";
	var node = d.firstChild;
	var i=0;
	
	//alert(len);
	do{
		h = node.id;
		
		//alert(h);
		if (h){
			
			if (h.substr(0,3)=='li-'){
				//alert(h);
				//var nl = node.childNodes.length;
				
					var n = node.firstChild;
					do{
						var nh = n.id;
						if (nh){
							if (nh.substr(0, 3)=='li-'){
								//alert(node.id + "," +node.offsetHeight+","+node.clientHeight+","+node.height+","+node.style.height);
								//n.style.filter
								n.style.height=node.offsetHeight;
								top10List.push(n.id);
							}
						}
					}while(n=n.nextSibling)
					
				
				
			}
		}
		
	}while(node=node.nextSibling)
	
	top10List.index=0;
	//alert(top10List.index);
	showTop10();
}

function initTop10(){
	var id = 'top10-list';
	var d = document.getElementById(id);
	var len = d.childNodes.length;
	var h="";
	var node = d.firstChild;
	var i=0;
	
	//alert(len);
	do{
		h = node.id;
		
		//alert(h);
		if (h){
			
			if (h.substr(0,3)=='li-'){
				top10List.push(h);
				//alert(h);
				//var nl = node.childNodes.length;
				
				/*
					var n = node.firstChild;
					do{
						var nh = n.id;
						if (nh){
							if (nh.substr(0, 3)=='li-'){
								
								n.style.height=node.offsetHeight;
								top10List.push(n.id);
							}
						}
					}while(n=n.nextSibling)
					
				*/
				
			}
		}
		
	}while(node=node.nextSibling)
	
	top10List.index=0;
	//alert(top10List.index);
	showTop10();
}

function showTop10(){
	
	var listIndex = top10List.index;
	var d = document.getElementById(top10List[listIndex]);
	if (listIndex==top10List.length){
		//alert('again');
		listIndex=0;
		top10List.index=0;
		for (var i=0; i<top10List.length; i++){
			d = document.getElementById(top10List[i]);
			d.style.opacity=0;
			d.style.top=-10;
		}
		JSTweener.addTween(d.style, {
		  time: 1,
		  delay:2,
		  transition: 'easeInOutQuad',
		  onComplete: showTop10,
		  opacity:1
		});	
	}else{
		//alert(d);
		top10List.index++;
		
		JSTweener.addTween(d.style, {
		  time: 1,
		  delay:0,
		  transition: 'easeInOutElastic',
		  onComplete: showTop10,
		  top:10,
		  opacity:1

			
		  
		});
		/*
		JSTweener.addTween(d.style, {
		  time: 1,
		  delay:1,
		  transition: 'easeOutElastic',
		  onComplete: showTop10,
		  top:10
		 });
		 */
	}
}
function encodeURL2(str){
    var clist = new Array("?" "&");
    var elist = new Array("%3f" "%26");
    var newstr;
    for (var i=0; i<clist.length; i++){
	str = str.replace(clist[i], elist[i]);
    }
    return str;
}

function getPageTitle(){
    var href="http://www.addtoany.com/share_save?linkname=" + document.title + "&linkurl=";
    alert(href);
    //window.location.href="http://www.addtoany.com/share_save?linkname=" + document.title + "&linkurl=";
} 
/*
function getTitle(){
    return document.title;
}
*/
function listScrollLeft2(){
	//var list = LBN;
	var listID = 'brandnew-list';
	var listHdr = 'BN-';
	var d = document.getElementById(listID);
	var frameWidth = 540;
	if (listIndex== -1){
		//listIndex = findListHead(id);
		LBN = genList(listID, listHdr);
		listIndex = 0;
	}
	
	var c = LBN[listIndex];
	var index = listIndex;
	listIndex++;
	//var pos = c;
	//var p = -c.offsetLeft;
	//p = 100;
	var pos = -c.offsetLeft;
	//d.style.Left='120px';
	//if (pos+frameWidth>=list[list.length-1]){
	var listLen = LBN.length;
	//alert(pos);
	//offset = pos;
	if (listIndex==listLen){
		//listIndex=findListHead(id);;
		//c = d.childNodes[listIndex];
		//pos = c.offsetLeft;
		listIndex=0;
		JSTweener.addTween(d.style, {
		  time: 1,
		  delay:2,
		  transition: 'easeInOutQuad',
		  onComplete: listScrollLeft,
		  left: pos,
		  suffix: {
			left: 'px'
			}		  
		});	
	}else{	
		
		JSTweener.addTween(d.style, {
		  time: 2,
		  delay:4,
		  transition: 'easeInOutBack',
		  onComplete: listScrollLeft,
		  onCompleteParams:[LBN,'brandnew-list','BN-'] , 
		  left: pos,
		  suffix: {
			left: 'px'
			}
		  
		});
	}
}

/*
function findListHead(od){
	var d = document.getElementById(od);
	var len = d.childNodes.length;
	
	var h="";
	var node = d.firstChild;
	var i=0;
	do{
		h = node.id;
		if (h){
			if (h.substr(0,3)=="BN-"){
				return i;
			}
		}
		i++;
	}while(node=node.nextSibling)
	return 1;
}
*/
/*
function listScrollUp(){
	var id = 'bookListDiv';
	var d = document.getElementById(id);
	var frameHeight = 300;
	if (listIndex== -1){
		listIndex = findListHead(id);
	}
	
	var c = d.childNodes[listIndex];
	listIndex++;
	var pos = c.offsetTop;
	if (pos+frameHeight>=d.scrollHeight){
		listIndex=findListHead(id);;
		c = d.childNodes[listIndex];
		pos = c.offsetTop;
		JSTweener.addTween(d, {
		  time: 1,
		  delay:10,
		  transition: 'easeInOutQuad',
		  onComplete: listScrollUp,
		  scrollTop: pos		  
		});	
	}else{
		JSTweener.addTween(d, {
		  time: 1,
		  delay:2,
		  transition: 'easeInOutQuad',
		  onComplete: listScrollUp,
		  scrollTop: pos		  
		});
	}
}
*/