var ggnum = 0;
var adnum = 0;
var ggvar={};
var loadingGG=false;

function gg_ad_out(gwidth,gheight)
{
	if(gwidth==960 && gheight==60)return;
	if(gwidth==960 && gheight==90)gwidth=728;
	if(gwidth==760 && gheight==60){gwidth=650; gheight=70;}
	if(ggnum>=3)
	{
		return;
		ad_out(gwidth,gheight);
		ggnum++;
		return;
	}
	google_ad_width = gwidth;
	google_ad_height = gheight;
	//document.write('<script src="/js/jsgg_'+gwidth+'x'+gheight+'.js?'+Math.random()+'"></script>');
	document.write('<iframe marginwidth=0 marginheight=0 frameborder=0 scrolling=no src="/js/gg_'+gwidth+'x'+gheight+'.html" height='+gheight+' width='+gwidth+'></iframe>');
	//gg_showad(gwidth,gheight);
	ggnum++;
}

function gg_showad(gwidth,gheight)
{


var divstr='<script>google_ad_client = "pub-1052775908813201";google_ad_slot = "2516795540";google_ad_width = 300;google_ad_height = 250;</script>';
//divstr += '<script>showgg('+ggnum+');</script>';
var divhtml='<div id="ggdiv'+ggnum+'"  style="float:left;width:'+gwidth+'px;height:'+gheight+'px;border:1px solid blue;">'+divstr+'</div>';
document.write(divhtml);
ggvar[ggnum]='google_ad_client="pub-1052775908813201";google_ad_slot="2516795540";google_ad_width=300;google_ad_height=250;';
//alert(ggnum);
showgg(ggnum);
//x.x.x
}

function showgg(gnum)
{
	//alert(gnum);
	if(loadingGG)
	{
		setTimeout('showgg('+gnum+')',3500);
		return;
	}
	loadingGG=true;
	file = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
	var script=document.createElement('SCRIPT');
	script.setAttribute('type', 'text/javascript');
	script.setAttribute('src', file);
	document.getElementById('ggdiv'+gnum).appendChild(script);
	alert(document.getElementById('ggdiv'+gnum).innerHTML);
	//eval(ggvar[gnum]);
	//addJs('http://pagead2.googlesyndication.com/pagead/show_ads.js','ggjs'+gnum,afGGload);
}

function afGGload()
{
	//alert('');
	loadingGG=false;
}

function addJs(file)
{
	var scriptId=arguments[1];
	var funExec=arguments[2];
	var funcLoading=arguments[3];
	var expire=arguments[4];
	var expFunc=arguments[5];
	var parent=document.getElementsByTagName('head')[0];
	if($('scriptId'))
	{
		var script=$('scriptId');
		script.src=file;
	}
	else
	{
		var script=document.createElement('SCRIPT');
		script.setAttribute('type', 'text/javascript');
		script.setAttribute('src', file);
		script.setAttribute('id', scriptId);
		parent.appendChild(script);
	}
	script.onreadystatechange =  function (){
	if(typeof(funExec)=='function'){if(script.readyState == 'complete' || script.readyState =="loaded"){funExec()}}
	if(script.readyState == 'loading'&&typeof(funcLoading)=='function'){t=setTimeout(funcLoading ,expire )}
	};
	script.onload = function (){(typeof(funExec)=='function')?funExec():""};
	return script;
}

function ad_out(gwidth,gheight)
{
	if(adnum>=3)
	{
		//document.write(adnum);
		adnum++;
		return;
	}
	google_ad_width = gwidth;
	google_ad_height = gheight;
	document.write('<iframe id="ggframe_'+gwidth+'x'+gheight+'" marginwidth=0 marginheight=0 frameborder=0 scrolling=no src="/js/ad_'+gwidth+'x'+gheight+'.html" height='+gheight+' width='+gwidth+'></iframe>');
	adnum++;
}

/*
* poweredBy:bailing
* 
*/
var ua = navigator.userAgent.toLowerCase()
var isIE=ua.indexOf('msie') > -1
var isFF=ua.indexOf('firefox') > -1
function $(obj){return document.getElementById(obj)}

document.onclick = function(e){
	//e = window.event || e
	//sE = e.srcElement || e.target
	//if( sE.tagName == "A" )his(sE.innerHTML,sE.href)
}

window.onload=function(){
	ck('ckhis','');
	var tt = document.title.replace(",书书网(shushu.com.cn)","");
	if(tt.search("_")>-1)return;
	var vhref = location.href;
	vhref=vhref.replace("http://shushu.com.cn","");
	booklink=vhref.replace(/\/[0-9\.]+\.html/,'/');
	if( typeof(bookname)=='undefined' )
	{
		var ttarr=tt.split(',');
		if(ttarr.length<2)return;
		bookname=ttarr[0];
		zhangname=ttarr[1];
		bookname=bookname.replace(/[0-9]+$/,"");
		if(/index.php/.test(vhref))return;
	}
	his(bookname,booklink,zhangname,vhref);
}

var tagreg = new RegExp("</?[^>]+>","ig");
function his( bookname,booklink,zhangname,zhanglink )
{
	var hisstr=GetCookie('ckhisnew'),hisarr=new Array();
	//alert(hisstr);
	if( hisstr != null && hisstr != '' ) hisarr=hisstr.split('^^');
	var tmpb ={},tmpz ={},tmpbz ={},rowb,rowz,rowarr;
	if(typeof(hisarr) == 'object')
	{
		if(hisarr.length > 14) delete(hisarr[0])
		if(hisarr.length>0)
		{
			for(v in hisarr)
			{
				rowarr = hisarr[v].split(',');
				rowb=rowarr[0].split('**'); //书
				rowz=rowarr[1].split('**'); //章节
				tmpb[rowb[0]] = rowb[1];
				tmpz[rowz[0]] = rowz[1];
				tmpbz[rowb[0]] = rowz[0];
			}		
			if( typeof(tmpb[bookname]) != 'undefined' )
			{
				oldzhangname=tmpbz[bookname];
				delete(tmpz[oldzhangname]);
				tmpz[zhangname]=zhanglink;
				tmpbz[bookname]=zhangname;
			}
		}
		hisarr=new Array();


		for(bname in tmpb)
		{
			if(bname==bookname)continue;
			zname=tmpbz[bname];
			itemstr=bname+"**"+tmpb[bname];
			itemstr+=","+zname+"**"+tmpz[zname];
			hisarr.push(itemstr)
		}
		itemstr=bookname+"**"+booklink;
		itemstr+=","+zhangname+"**"+zhanglink;
		hisarr.push(itemstr)
	}
	cookstr=hisarr.join('^^');
	ck('ckhisnew',hisarr.join('^^'));
	if($('ggframe_760x60'))frame('ggframe_760x60').location.reload();
}

function ck(n,v){SetCookie(n,v,94608000,'/')}
function frame(n){return (isFF)?document.getElementById(n).contentWindow:document.frames[n]}


function SetCookie(name, value){
var expdate = new Date()
var argv = SetCookie.arguments
var argc = SetCookie.arguments.length
var expires = (argc > 2) ? argv[2] : null
var path = (argc > 3) ? argv[3] : null
var domain = (argc > 4) ? argv[4] : null
var secure = (argc > 5) ? argv[5] : false
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ))
document.cookie = name + "=" + value +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "")}


function top_domain(){document.domain.replace(/www./i,'')}
function GetCookie(n){
var aCookie = document.cookie.split("; ")
for(var i=0; i < aCookie.length; i++){
var aCrumb = aCookie[i].split("=")
if(n == aCrumb[0])	return unescape(aCrumb[1])
}return null}



v3ghref=location.href.replace('www.','');v3ghref=v3ghref.replace('http://','http://3g.');
if(screen.width<640){
	//document.write('<a href="'+v3ghref+'">手机浏览通道</a>');
	//document.write('<script src="/ipjs.php"></script>');
}



function clicksearch(inpob)
{
if(inpob.value=='请不要输入错别字'||inpob.value=="名称/全拼/简拼")inpob.value='';

}

oldkey='';
sukey='';
sudone=true;
function susearch(e,inpob)
{
	var e = window.event || e;
	if( inpob.value==oldkey || inpob.value==''  )
	{
		if(inpob.value=='')$('sudiv').style.display="none";
		return;
	}
	jsf="/su.php?word="+encodeURIComponent(inpob.value);
	if(sudone)addJs(jsf,"sujs",sugetend);
	sudone=false;
}

function inpchange(inpob)
{
	jsf="/su.php?word="+encodeURIComponent(sukey);
	addJs(jsf,"sujs");
}

function sugetend(){sudone=true;}

function sugo(bookobj,authorobj)
{
	var str='<ul>',authorstr='<ul>';
	var i=0,ai=0;
	for (var btitle in bookobj)
	{
		i++;
		var blink=bookobj[btitle];
		var blink2=blink.replace("index.html","bookupdate.html");
		str +='<li><a href="'+blink+'" target=_blank>'+btitle+'</a>_<a href="'+blink2+'" target=_blank>最新30章</a></li>';
		//if(!(i%3))str+='';
	}
	str +="</ul>";
	for (var authorname in authorobj)
	{
		ai++;
		//var blink="/modules/article/search.php?searchtype=author&searchkey="+authorname;
		var blink=authorobj[authorname];
		authorstr +='<li><a href="'+blink+'" target=_blank>'+authorname+'</a></li>';
		//if(!(ai%3))authorstr+='<br>';
	}
	authorstr +="</ul>";
	document.getElementById('subody').innerHTML=str;
	document.getElementById('subodyauthor').innerHTML=authorstr;
	oldkey=document.getElementById('searchkey').value;
	$('sudiv').style.display="";
	sudone=true;
}

function copyToClipBoard(){
var clipBoardContent=''; 
clipBoardContent+=document.title;
clipBoardContent+=window.location;
window.clipboardData.setData("Text",clipBoardContent);
alert("你已复制链接及标题，赶快与你的好友分享哦!");
}

function BAIDU_CLB_singleFillSlot(adid)
{
	if(adid=='65616')
	{
		gg_ad_out( 300 , 250 );
		gg_ad_out( 300 , 250 );
	}
	else if(adid=='70761')
	{
		//尾部
	}
	else if(adid=="70767")
	{
		gg_ad_out( 650 , 70 );
	}
}


