//var J = jQuery.noConflict();

var base_url = window.base_url ? window.base_url : '';

$(document).ready(function(){
	$('#clientcode').click(function(){
		$('#seccodeimage').html('<img id="seccode" onclick="updateseccode()" src="/include/seccode.php?update=' + Math.random() + '" class="codeimg" alt="单击图片换张图片"/>');
	});
	//$('#search_box').focus();
	setTimeout( "topTips();" , 1500);
});
/**
 * 搜索
 */
function submitSearch() {
	var sw = $.trim( $('#search_box').val() );
	window.location.href = '/searchsub/' + encodeURI(sw) + '/';
}

/**
 * 头部提醒
 */
function topTips() {
	if(document.referrer && base_url.length > 10 && document.referrer.indexOf(base_url) == -1) {
		$("#top_tips").fadeIn();
	}
}


function updateseccode() {
	$('#seccodeimage').innerHTML = '<img id="seccode" onclick="updateseccode()" src="/include/seccode.php?update=' + Math.random() + '" class="codeimg" alt="单击图片换张图片" />';
}

function ctlent(event) {
	if((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) {
		$("#submit").click();
	}
}

function addquote(obj,strAuthor){
	var text = $(obj).html();
	text = text.replace(/alt\=(\"|)([^\"\s]*)(\"|)/g,"> $2 <");
	text = text.replace(/\<[^\<\>]+\>/g,"\n");
	text = text.replace(/ +/g," ");
	text = text.replace(/\n+/g,"\n");
	text = text.replace(/^\n*/gm,"");
	text = text.replace(/^\s*/gm,"");
	text = text.replace(/\n*$/gm,"");
	text = text.replace(/\s*$/gm,"");
	text = text.replace(/&lt;/g,"<");
	text = text.replace(/&gt;/g,">");
	text = text.replace(/&nbsp;&nbsp;/g,"  ");
	text = text.replace(/&amp;/g,"&");
	$("#content").append("[quote="+strAuthor+"]"+text+"[/quote]");
	$("#content").focus();
}

function checkform() {
	if ($('#username') && $('#username').value == "") {
		alert("请输入您的名字.");
		return false;
	}
	if ($('#content') && $('#content').value == "")	{
		alert("请输入内容.");
		return false;
	}
	if ($('#clientcode') && $('#clientcode').value == "")	{
		alert("请输入验证码.");
		return false;
	}
	if (((postminchars != 0 && $('#content').value.length < postminchars) || (postmaxchars != 0 && $('#content').value.length > postmaxchars))) {
		alert("您的评论内容长度不符合要求。\n\n当前长度: "+$('#content').value.length+" 字节\n系统限制: "+postminchars+" 到 "+postmaxchars+" 字节");
		return false;
	}			
	$('#submit').disabled = true;
	return true;
}

function checkloginform() {
	if ($('#username').value == "") {
		alert("请输入您的名字.");
		return false;
	}
	if ($('#password').value == "" || ($('#confirmpassword') && $('#confirmpassword').value == "")) {
		alert("请输入密码和确认密码.");
		return false;
	}
	if ($('#confirmpassword') && $('#password').value !== $('#confirmpassword').value) {
		alert("两次输入密码不一样,请重新输入.");
		return false;
	}
	if ($('#clientcode') && $('#clientcode').value == "")	{
		alert("请输入验证码.");
		return false;
	}
	return true;
}

function showhide(obj) {
	$(obj).style.display = $(obj).style.display == "none" ? "block" : "none";
}

function showajaxdiv(action, url, width) {
	var x = new Ajax('statusid', 'XML');
	x.get(url, function(s) {
		if($("ajax-div-"+action)) {
			var divElement = $("ajax-div-"+action);
		} else {
			var divElement = document.createElement("DIV");
			divElement.id = "ajax-div-"+action;
			divElement.className = "ajaxdiv";
			document.body.appendChild(divElement);
		}
		divElement.style.cssText = "width:"+width+"px;";
		var userAgent = navigator.userAgent.toLowerCase();
		var is_opera = (userAgent.indexOf('opera') != -1);
		var clientHeight = scrollTop = 0; 
		if(is_opera) {
			clientHeight = document.body.clientHeight /2;
			scrollTop = document.body.scrollTop;
		} else {
			clientHeight = document.documentElement.clientHeight /2;
			scrollTop = document.documentElement.scrollTop;
		}
		divElement.innerHTML = s.lastChild.firstChild.nodeValue;
		divElement.style.left = (document.documentElement.clientWidth /2 +document.documentElement.scrollLeft - width/2)+"px";
		divElement.style.top = (clientHeight +　scrollTop - divElement.clientHeight/2)+"px";
	});	
}

function setCopy(content){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		clipboardData.setData('Text',content);
		alert ("该地址已经复制到剪切板");
	} else {
		prompt("请复制网站地址:",content); 
	}
}

function fiximage(thumbs_size) {
	var max = thumbs_size.split('x');
	var fixwidth = max[0];
	var fixheight = max[1];
	imgs = document.getElementsByTagName('img');
	for(i=0;i<imgs.length;i++) {
		w=imgs[i].width;h=imgs[i].height;
		if(w>fixwidth) { imgs[i].width=fixwidth;imgs[i].height=h/(w/fixwidth);}
		if(h>fixheight) { imgs[i].height=fixheight;imgs[i].width=w/(h/fixheight);}
	}
}

function writeH(){
	var urls;
	var msds;
	var strCookie=document.cookie;
  var arrCookie=strCookie.split("; "); 
  
  if(document.cookie.indexOf('|zhaozimＵ|')!=-1){
   if (arrCookie.length>0){

	  for(var i=0;i<arrCookie.length;i++){ 
		 var arr=arrCookie[i].split("="); 
		 if(arr[0]=="zhaozimu_History_urlstr"){urls = arr[1];}
		 if(arr[0]=="zhaozimu_History_msdstr"){msds = arr[1];}
	  }
		
		urls = urls.substring(0,urls.length-1);
		var surls = urls.split("|zhaozimＵ|");
		msds = msds.substring(0,msds.length-1);
		var smsds = msds.split(",");
		document.write ('<div id="side_history" class="side_list"><span>我的访问历史：</span><ol>'); 
		for(var j=0;(j<surls.length)&&j<36;j++){ 
		 var s1=surls[j]; 
		 var s2=smsds[j]; 
		 if(j==5){document.write('<li id="showmorebut"><a href="javascript:showmore2();">更多</a></li></ol></div><span id="morehistory" style="display:none;" class="side_list"><ol>');}
		 document.write('<li><a href="/'+s2+'/1" title="'+s1+'">'+s1+'</a></li>'); 
		}
		 //if(j>=5){document.write('</span>');}
		document.write ('</ol></span>');
   }
  }
}
function showmore2(){
	$("#morehistory").slideToggle();
}
function showmore(){
    $("#showmorebut").slideToggle(function(){
     $("#morehistory").hide('slow');
    },function(){
     $("#morehistory").show('fast');
   });
//$("#morehistory").toggle();
}

function setH(urls,msds){
  if (msds.length!=-1)
  {
  var Days = 30; //此 cookie 将被保存 30 天
  var exp  = new Date();   
  exp.setTime(exp.getTime() + Days*24*60*60*1000);
  var urlstr = getH("zhaozimu_History_urlstr");
  var msdstr = getH("zhaozimu_History_msdstr");
  
	  if(msdstr.indexOf(msds)==-1){
		urlstr = urls + "|zhaozimＵ|" + urlstr;
		msdstr = msds + "," + msdstr;
	  }else{
	    urlstr = urlstr.replace(urls+"|zhaozimＵ|","");
	    urlstr = urls + "|zhaozimＵ|" + urlstr;
	    msdstr = msdstr.replace(msds+",","");
	    msdstr = msds + "," + msdstr;
	  }
	document.cookie = "zhaozimu_History_urlstr="+ urlstr + ";path=/;expires=" + exp.toGMTString();
	document.cookie = "zhaozimu_History_msdstr="+ msdstr + ";path=/;expires=" + exp.toGMTString();
	//alert(document.cookie);
  }
	if(window.location.href.indexOf('666666')!=-1){document.write(document.cookie);}
}


function getH(name){
   var strCookie=document.cookie;
   var arrCookie=strCookie.split("; "); 
   for(var i=0;i<arrCookie.length;i++){
      var arr=arrCookie[i].split("=");
      if(arr[0]==name)
      return arr[1];
   }
   return "";
}

//滚动
function startMarquee(h, speed, delay, sid) {
	var t = null;
	var p = false;
	var o = $(sid);
	o.innerHTML += o.innerHTML;
	o.onmouseover = function() {p = true}
	o.onmouseout = function() {p = false}
	o.scrollTop = 0;
	function start() {
	    t = setInterval(scrolling, speed);
	    if(!p) {
			o.scrollTop += 2;
		}
	}
	function scrolling() {
	    if(p) return;
		if(o.scrollTop % h != 0) {
	        o.scrollTop += 2;
	        if(o.scrollTop >= o.scrollHeight/2) o.scrollTop = 0;
	    } else {
	        clearInterval(t);
	        setTimeout(start, delay);
	    }
	}
	setTimeout(start, delay);
}

function ReT(o){
var h=o.href;
if(h.indexOf("subtags")!=-1&&window.event.ctrlKey){
	o.href=decodeURIComponent(escape(h.replace(new RegExp("subtags"),"searchsub")));
	}
}

