var lang = new Array();
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);


/*	---------------- common function ---------------- */
function ShowHide(objname, display){
   var obj = document.getElementById(objname);
   if(obj.style.display=="none") obj.style.display = display;
	else obj.style.display="none";
}
function $(obj){
	return document.getElementById(obj);
}
function in_array(needle, haystack) {
	if(typeof needle == 'string' || typeof needle == 'number') {
		for(var i in haystack) {
			if(haystack[i] == needle) return true;
		}
	}return false;
}
//检查验证码
function chkvdcode(vdcode){
	if(vdcode.length == 4){
		var x = new Ajax();
		x.get('/skin/ajax.php?action=chk_vdcode&vdcode=' + vdcode, function(s) { set_warning('z_vdcode_warning', s)});
	}else{
		set_warning('z_vdcode_warning', '验证码错误！');
	}
}
//输出警告信息
function set_warning(box,message){
	$(box).innerHTML = message;
	$(box).style.color='red';
}


/*	---------------- common event ---------------- */
window.onload=function(){	searchEvent();commentEvent(); }
var key = ['非主流','非主流女生','非主流帅哥','非主流图片','自拍','可爱','Xyan图','Xyan','Tong','Tong图','小凡','可爱女生','自拍'];
var msg = ['还不错哦，支持下！！！！','我喜欢的图片。。。。。','支持下。。。。','呵呵。。我喜欢！','蛮好看的！！','好喜欢哦！','很好，支持下！'];

var commentDefaultValue = '还不错,偶顶一下!';
function dosearch(input){
	if(input.value.length > 1) return true; else alert('搜索关键词需大于2个字!'); return false;
}
function docommend(value){
	if(input.value.length > 1) return true; else alert('评论内容需大于2个字!'); return false;
}
function searchEvent(){
	var input = document.getElementById("keyword");
	if(input == undefined) return false;
	input.value = key[parseInt(Math.random()*key.length+0)];
	input.onblur  = function(){ if(input.value==''){searchEvent()}}
}
function commentEvent(){
	var input = document.getElementById("msg");
	if(input == undefined) return false;
	input.value = msg[parseInt(Math.random()*msg.length+0)];
	input.onblur  = function(){ if(input.value==''){commentEvent()}}
}












/* dede53 内容页JS函数开始 */
//检查评论
function checkSubmit(){
	if(document.feedback.msg.value!='') document.feedback.submit();
	else alert("评论内容不能为空！");
}
//digg 文章
function postDigg(ftype,aid)
{
var taget_obj = document.getElementById('newdigg');
var saveid = GetCookie('diggid');
if(saveid != null)
{
	var saveids = saveid.split(',');
	var hasid = false;
	saveid = '';
	j = 1;
	for(i=saveids.length-1;i>=0;i--)
	{
		if(saveids[i]==aid && hasid) continue;
		else {
			if(saveids[i]==aid && !hasid) hasid = true;
			saveid += (saveid=='' ? saveids[i] : ','+saveids[i]);
			j++;
			if(j==20 && hasid) break;
			if(j==19 && !hasid) break;
		}
	}
	if(hasid) { alert("您已经顶过该帖，请不要重复顶帖 ！"); return; }
	else saveid += ','+aid;
	SetCookie('diggid',saveid,1);
	}
	else
	{
		SetCookie('diggid',aid,1);
	}
	myajax = new DedeAjax(taget_obj,false,false,'','','');
	myajax.SendGet2("/plus/feedback.php?action="+ftype+"&aid="+aid+"&formarc=1");
	DedeXHTTP = null;
}
//digg 评论
function postBadGood(ftype,fid)
{
	var taget_obj = document.getElementById(ftype+fid);
	var saveid = GetCookie('badgoodid');
	if(saveid != null)
	{
		 var saveids = saveid.split(',');
		 var hasid = false;
		 saveid = '';
		 j = 1;
		 for(i=saveids.length-1;i>=0;i--)
		 {
			  if(saveids[i]==fid && hasid) continue;
			  else {
				if(saveids[i]==fid && !hasid) hasid = true;
				saveid += (saveid=='' ? saveids[i] : ','+saveids[i]);
				j++;
				if(j==10 && hasid) break;
				if(j==9 && !hasid) break;
			  }
		 }
	  if(hasid) { alert('您刚才已表决过了喔！'); return false;}
	  else saveid += ','+fid;
		 SetCookie('badgoodid',saveid,1);
	}
	else
	{
		SetCookie('badgoodid',fid,1);
	}
	//document.write("feedback.php?action="+ftype+"&fid="+fid);
	//return;
  myajax = new DedeAjax(taget_obj,false,false,'','','');
  myajax.SendGet2("/plus/feedback.php?aid="+fid+"&action="+ftype+"&fid="+fid);
  DedeXHTTP = null;
}

/* dede53 内容页JS函数完毕 */

























/*	---------------- common class ---------------- */
function tabPanel(id){
	var t = new Object();
	t.index;
	t.head;
	t.text;
	t.play = function(id) {
		var nodes = document.getElementById(id).childNodes;
		t.text = new Array();
		for(var i in nodes){
			if(nodes[i].className == 'head') t.head = nodes[i].getElementsByTagName('li');
			if(nodes[i].className == 'text'){
				var childs = nodes[i].childNodes;
				for(var i in childs){
					if(childs[i].nodeType == 1) t.text.push(childs[i]);
				}
			}
		}
		for(var i in t.head){
			if(t.head[i].nodeType == 1) {
  				t.head[i].value = i;
  				t.head[i].onmouseover=function(){t.change(this.value);};
				t.head[i].className = '';
  				t.text[i].style.display='none';
				t.index = i;
			}
		}
		t.change(0);
	}
	t.change = function(index) {
		t.head[t.index].className='';
  		t.text[t.index].style.display='none';
		t.index = index;
		t.head[t.index].className='hover';
  		t.text[t.index].style.display='';
	}
	t.play(id);
}

var Ajaxs = new Array();
function Ajax()
{
	var aj = new Object();
	aj.loading = 'Loading...';//public
	aj.resultHandle = null;//private
	aj.targetUrl = '';//private
	aj.request = null;//private


	aj.setloading = function(loading)
	{
		if(typeof(loading) !== 'undefined' && loading !== null) aj.loading = loading;
	}

	aj.createXMLHttpRequest = function()
	{
		var request = false;
		if(window.XMLHttpRequest)
		{
			request=new XMLHttpRequest();
			if(request.overrideMimeType) request.overrideMimeType("text/xml");
		}else if(window.ActiveXObject){
			try{
				request=new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					request=new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e){}
			}
		}
		aj.request = request;
		aj.request.onreadystatechange = aj.processHandle;
	}

	aj.processHandle = function()
	{
		//aj.resultHandle('<span><img src="/skin/images/loading.gif">Loading</span>');
		if (aj.request.readyState == 4){
			for(k in Ajaxs) {
				if(Ajaxs[k] == aj.targetUrl) Ajaxs[k] = null;
			}
			if(aj.request.status == 200 || aj.request.status == 304){
				aj.resultHandle(aj.request.responseText);
			}else{
				aj.resultHandle('载入网页错误:' + aj.request.status + ':' + aj.request.statusText);
			}
		}
	}

	aj.get = function(targetUrl, resultHandle)
	{
		if(in_array(targetUrl, Ajaxs)) return false;
		else Ajaxs.push(targetUrl);

		aj.targetUrl = targetUrl;
		aj.createXMLHttpRequest();
		aj.resultHandle = resultHandle;
		aj.request.open('GET', targetUrl, true);
		aj.request.send(null);
	}

	aj.post = function(targetUrl, sendString, resultHandle)
	{
		if(in_array(targetUrl, Ajaxs)) return false;
		else Ajaxs.push(targetUrl);

		aj.targetUrl = targetUrl;
		aj.createXMLHttpRequest();
		aj.resultHandle = resultHandle;
		aj.request.open('POST', targetUrl);
		aj.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		aj.request.send(sendString);
	}
	return aj;
}


/*
 *@ url: 需求请求的 url
 *@ id : 显示的 id
 *@ waitid: 等待的 id，默认为显示的 id，如果 waitid 为空字符串，则不显示 loading...， 如果为 null，则在 showid 区域显示
 *@ linkid: 是哪个链接触发的该 ajax 请求，该对象的属性(如 ajaxdisplay)保存了一些 ajax 请求过程需要的数据。
*/
function ajaxget(url, showid) {
	var x = new Ajax();
	x.get(url, showid);
}
/*	---------------- common class ---------------- */







/*	---------------- write html ---------------- */
/* 收藏 */
function bookmark() {
	document.writeln("<span id=\"bookmark\"> <A onclick=window.external.AddFavorite(document.location.href,document.title); href=\"javascript:;\"><IMG src=\"\/skin/images/bookmark\/ie.gif\" alt=\"收藏到IE收藏夹\" border=\"0\"><\/A>");
	document.write("<a href=\"javascript:u=location.href;t=document.title;c = %22%22 + (window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text);var url=%22http:\/\/cang.baidu.com\/do\/add?it=%22+encodeURIComponent(t)+%22&amp;iu=%22+encodeURIComponent(u)+%22&amp;dc=%22+encodeURIComponent(c)+%22&amp;fr=ien#nw=1%22;window.open(url,%22_blank%22,%22scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes%22); void 0\"><img title=\"收藏到百度收藏\" src=\"\/skin/images/bookmark/baidu.gif\" border=\"0\"><\/a> ");
	document.write("<a title=\'GOOGLe书签\' href=\"javascript:window.open(\'http:\/\/www.google.com\/bookmarks\/mark?op=add&bkmk=\'+encodeURIComponent(location.href)+\'&title=\'+encodeURIComponent(document.title));void(0)\"><img src=\'\/skin/images/bookmark/google.gif\' title=\'收藏到Google书签\' border=\'0\'><\/a> ");
	document.writeln("<a href=\"javascript:window.open(\'http:\/\/shuqian.qq.com\/post?from=3&title=\'+encodeURIComponent(document.title)+\'&uri=\'+encodeURIComponent(document.location.href)+\'&jumpback=2&noui=1\',\'favit\',\'width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes\');void(0)\"><img alt=QQ书签 src=\"\/skin/images/bookmark/qq.gif\" border=0><\/a>");
	document.write("<a href=\"#\" onclick=\"window.open(\'http:\/\/myweb.cn.yahoo.com\/popadd.html?url=\'+encodeURIComponent(document.location.href)+\'&title=\'+encodeURIComponent(document.title), \'Yahoo\',\'scrollbars=yes,width=780,height=455,left=80,top=80,status=yes,resizable=yes\');\"><img src=\"\/skin/images/bookmark/yahoocn.gif\"  border=\"0\" title=\"收藏到雅虎中文书签\"><\/a> ");
	document.write("<a href=\"javascript:d=document;t=d.selection?(d.selection.type!=\'None\'?d.selection.createRange().text:\'\'):(d.getSelection?d.getSelection():\'\');void(vivi=window.open(\'http:\/\/vivi.sina.com.cn\/collect\/icollect.php?pid=28&title=\'+escape(d.title)+\'&url=\'+escape(d.location.href)+\'&desc=\'+escape(t),\'vivi\',\'scrollbars=no,width=480,height=480,left=75,top=20,status=no,resizable=yes\'));vivi.focus();\"><img src=\'\/skin/images/bookmark/vivi.gif\' title=\'收藏到新浪ViVi\' border=\'0\'><\/a> ");
	document.write("<a href=\"javascript:d=document;t=d.selection?(d.selection.type!=\'None\'?d.selection.createRange().text:\'\'):(d.getSelection?d.getSelection():\'\');void(live=window.open(\'https:\/\/favorites.live.com\/quickadd.aspx?marklet=1&mkt=en-us&url=\'+escape(d.location.href)+\'&title=\'+escape(d.title)+\'&top=1\',\'live\',\'scrollbars=no,status=no,resizable=yes\'));live.focus();\"><img src=\"\/skin/images/bookmark/live.gif\" title=\"收藏到微软Live\" border=\"0\"><\/a> <\/span>");
}
function banner() {
	document.writeln('banner');
}
function footer() {
	showloading();
	/* 首页 */
	if (typeof(page)!='undefined') if(page=='index') { playchange();tabPanel('tab1');tabPanel('tab2');tabPanel('tab3'); } 
	/* 统计 */
	document.writeln('<a href="http://www.miibeian.gov.cn/" target="_blank">鄂ICP备05012751号</a> <script type="text/javascript" src="http://js.users.51.la/560237.js"></script>');
	/* 网警 */
	document.writeln(" <a href=\"http://www.hubei.cyberpolice.cn\" target=\"_blank\"><img src=\"http://www.qqzjz.com/skin/images/szbj.gif\" alt=\"\" width=\"30\" border=\"0\" \/><\/a> ");
	/* 弹弹 */
	ViewPopUp();
}

function showloading(){
	var jsonstr = { GGContent: [
		{ view: "show1", data: "data1" },
		{ view: "show2", data: "data2" },
		{ view: "show3", data: "data3" },
		{ view: "show4", data: "data4" },
		{ view: "show5", data: "data5" },]};
	show(jsonstr);
}

function show(JsonStr) {
	if (!JsonStr || JsonStr.GGContent.length <= 0) return;
	var TempAdContent, EmptyAdContent;
	for (var i in JsonStr.GGContent) {
		EmptyAdContent = document.getElementById(JsonStr.GGContent[i].view);
		TempAdContent = document.getElementById(JsonStr.GGContent[i].data);
		if (EmptyAdContent && TempAdContent) {
			EmptyAdContent.innerHTML = TempAdContent.innerHTML;
		}
	}
}

function ViewPopUp(){
	if (document.cookie.indexOf("cmp_cnxad") == -1){
		/* 设置cookie */
		var expiredays = 1;
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		document.cookie = "cmp_cnxad=1" + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使设置的有效时间正确。增加toGMTString()

		/* 输出弹弹 */
		document.writeln("<script type=\'text\/javascript\' language=\'javascript\'>");
		document.writeln("var cnxad_f=\'pop_un\';");
		document.writeln("var cnxad_userid=\'11467\';");
		document.writeln("var cnxad_subid=\'0\';");
		document.writeln("var cnxad_exid=\'0\';");
		document.writeln("var cnxad_t=\'0\';");
		document.writeln("var cnxad_encode=\'sIbxLiwAFZCQfsPJtGZbhnezQdRsZw%2b3mNjNodWiofYLqJBe6HeblA%3d%3d&et=1\';");
		document.writeln("<\/script>");
		document.writeln("<script type=\'text\/javascript\' language=\'javascript\' src=\'http:\/\/code.cnxad.com\/pcode.js\'><\/script>");
	}
}