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);
var is_safari = (userAgent.indexOf('webkit') != -1 || userAgent.indexOf('safari') != -1);

//iframe包含
if (top.location != location) {
	top.location.href = location.href;
}
//键盘提交
//function chk(id){ 
//var value=document.getElementById(id).value; 
//window.location.href="00"+(value)+".htm"; 
//}
//document.onkeydown=function(){
//	if(event.keyCode=="13"){
//		chk('searchBtn')
//	}
//}
// JavaScript Document
//首页微博字数限制
var maxl=140;//首页微博字数限制

//导航切换按钮
function setTab(name,cursel,n){
	for(i=1;i<=n;i++){
	var menu=document.getElementById(name+i);
	var con=document.getElementById("con_"+name+"_"+i);
	menu.className=i==cursel?"hover":"";
	con.style.display=i==cursel?"block":"none";
}
}

//全选反选
function checkAll(e, itemName)
{
  var aa = document.getElementsByName(itemName);
  for (var i=0; i<aa.length; i++)
   aa[i].checked = e.checked;
}
function checkItem(e, allName)
{
  var all = document.getElementsByName(allName)[0];
  if(!e.checked) all.checked = false;
  else
  {
    var aa = document.getElementsByName(e.name);
    for (var i=0; i<aa.length; i++)
     if(!aa[i].checked) return;
    all.checked = true;
  }
}
//复制链接
function copyToClipboard(theField,isalert)
{
  var obj=document.getElementById(theField);
  if(obj!=null)
  {
    var clipBoardContent=obj.value;
    obj.select();
    window.clipboardData.setData("Text",clipBoardContent); 
    if(isalert!=false)
      alert("复制成功！将以上链接发给亲朋好友，他们接受邀请后会成为你的粉丝。");
  }
  else
  {
     alert("Error!");
  }
}
//个性化域名输入同步
function addEvent(eventHandler)
    {
        var tags = document.getElementsByTagName('input');
        for(var i=0;i<tags.length;i++)
        {
            if(tags[i].getAttribute('url') == 'true')
            {
                if(tags[i].addEventListener)
                {
                    tags[i].addEventListener('keyup',eventHandler,true);
                }
                else
                {
                    tags[i].attachEvent('onkeyup',eventHandler);
                }
            }
        }
    }
function addInput(e)
    {
        var obj = e.target ? e.target : e.srcElement;
        var tags = document.getElementsByTagName('input');
        for(var i=0;i<tags.length;i++)
        {
            if(tags[i].getAttribute('url') == 'true'&&tags[i]!=obj)
            {
                tags[i].value = obj.value;
            }
        }
    }
    window.onload = function()
    {
        addEvent(addInput);
    }
//上传文件限制
extArray = new Array(".gif", ".jpg", ".png");
function LimitAttach(form, file) 
{
   allowSubmit = false;
   if (!file) return;
   while (file.indexOf("\\") != -1)
   file = file.slice(file.indexOf("\\") + 1);
   ext = file.slice(file.indexOf(".")).toLowerCase();
   for (var i = 0; i < extArray.length; i++) {
   if (extArray[i] == ext) { allowSubmit = true; break; }
   }
   if (allowSubmit) form.submit();
   else
   alert("对不起，只能上传以下格式的文件:  "+ (extArray.join("  ")) + "\n请重新选择符合条件的文件"
+ "再上传.");
}
	
//模版切换
var cssPath = "style/t";
var styleID=1;
document.write('<link rel="stylesheet" type="text\/css" id="cssLink" href="'+cssPath+styleID+'.css" \/>');
var cssLink=document.getElementById("cssLink");
function styleChange(n) {
  if(n==5){
	document.getElementById("mytpl").style.background="#fff";
	}
	else{
	document.getElementById("mytpl").style.background="#fff";
	}
	cssLink.href = cssPath+n+".css";			
}

//头部搜索
function drop_mouseover(pos){
	try{window.clearTimeout(timer);}catch(e){}
}
function drop_mouseout(pos){
	var posSel=document.getElementById(pos+"Sel").style.display;
	if(posSel=="block"){
		timer = setTimeout("drop_hide('"+pos+"')", 1000);
	}
}
function drop_hide(pos){
	document.getElementById(pos+"Sel").style.display="none";
}
function search_show(pos,searchType,href){
    document.getElementById(pos+"SearchType").value=searchType;
    document.getElementById(pos+"Sel").style.display="none";
    document.getElementById(pos+"Slected").innerHTML=href.innerHTML;
    document.getElementById(pos+'q').focus();
	try{window.clearTimeout(timer);}catch(e){}
	return false;
}
function headDoSearch() {
	var searchValue = $('#headq').val();
	var searchType = $('#headSearchType').val();
	var redirectURL = '';
	
	if(''==searchValue || 'undefined'==searchValue || '请输入关键字'==searchValue) {
		alert("请输入关键字");
	} else {
		if('userSearch'==searchType ) {
			redirectURL = 'index.php?mod=profile&code=search&keyword='+searchValue;
		} else if ('tagSearch'==searchType ) {
			redirectURL = 'index.php?mod=tag&code='+searchValue;
		} else {
			alert("未定义的操作");
		}
		
		if(''!=redirectURL) {
			window.location.href=redirectURL;
		}
	}		

	return false;
}
	
//IE6 PNG 图片




//-------------------------------------------------------------------------------------
var imgId = 0;
var videoIds = 0;
var musicIds = 0;
function publishSubmit(ci,i,r) {
	var c = $('#'+ci).val();
	var c = 'undefined' == typeof(c) ? '' : c;
	if(''==c) {
		alert("内容不能为空。");
		return false;
	}
	
	var i = 'undefined' == typeof(i) ? 0 : i;
	var r = 'undefined' == typeof(r) ? '' : r;
	
	var myAjax = $.post(
		"ajax.php?mod=topic&code=do_add&act=reply",
		{
			totid:i,
			imgId:imgId,
			videoIds:videoIds,
			musicIds:musicIds,
			content:c,
			r:r
		},
		function (d) {		
			if( ''!=d && ''==r ) {
				$('#'+ci).val(c);
				alert(d);
				$('#'+ci).foucs();
				return false;
			} else if('vc'==r) {
				$("#reply_area_"+i).html(d);
			} else if(-1!=r.indexOf('rl')) {
				$("#replyListArea").html(d);
			} else if(-1!=r.indexOf('tohome')) {
				window.location.href= thisSiteURL + 'index.php?mod=topic&code=myhome';
			} else {
				if(''!=d) {
					$('#'+ci).val(c);
					alert(d);
					$('#'+ci).foucs();
					return false;					
				} else {
//话题发布成功后，清除图片、视频、音乐的ID值
					imgId=0;					
					videoIds = 0;
					musicIds = 0;

					if( 'myblog'==r || 'myhome'==r || 'tagview'==r ) {
						listTopic(0,0);
					}
				}
			}
		}
	);
	
	$('#'+ci).val('');


	document.getElementById('publisher_image_form').style.display='block';
	document.getElementById('insertImgDiv').style.display='block';
	document.getElementById('viewImgDiv').style.display='none';	
	
	document.getElementById('publisher_video_form').style.display='block';
	document.getElementById('insertvideoDiv').style.display='block';
	

	document.getElementById('viewvideoDiv').style.display='none';	
	document.getElementById('viewmusicDiv').style.display='none';	
	
	
	document.getElementById('publisher_video').value='输入链接地址';
	
	return true;
}
function deleteTopic(i,eid) {
	if(!confirm("确认删除？")) return false;
	
	var i = 'undefined' == typeof(i) ? 0 : i;
	var myAjax = $.post(
		"ajax.php?mod=topic&code=delete",
		{
			tid:i
		},
		function (d) {
			if(''!=d) {
				alert(d);
				return false;
			} else {
				$("#"+eid).remove();
			}
		}
	);
}





function replyTopic(i,eid) {
	var i = 'undefined' == typeof(i) ? 0 : i;
	var eid = 'undefined' == typeof(eid) ? 'reply_area_' + i : eid;
	var eidVal = $("#"+eid).html();
	
	if(''==eidVal) {
		var myAjax = $.post(
			"ajax.php?mod=topic&code=view_comment",
			{
				tid:i
			},
			function (d) {
				if(''!=d) {
					$("#"+eid).html(d);
				}
			}
		);
	} else {
		$("#"+eid).html('');
	}
}


function PmSend(to_user,eid) {
	var eid = 'undefined' == typeof(eid) ? 'Pmsend_to_user_area' : eid;
	var to_user = 'undefined' == typeof(to_user) ? '' : to_user;
	var eidVal = $("#"+eid).html();
	
	if(''==eidVal) {
		var myAjax = $.post(
			"ajax.php?mod=pm&code=send",
			{
				to_user:to_user
			},
			function (d) { 
				if(''!=d) {
					$("#"+eid).html(d);
				}
			}
		);
	} else {
		$("#"+eid).html('');
	}
}

function PmSubmit(i,eid,to_user) {

	var i = 'undefined' == typeof(i) ? 0 : i;
	
	var subject = document.getElementById("subject").value;  
	var message = document.getElementById("message").value; //取得input里面的值
	
	var myAjax = $.post(
		"ajax.php?mod=pm&code=do_add",
		{
			pmid:i,
			subject:subject,
			message:message,
			to_user:to_user
		},
		function (d) {
			if(''!=d) {
				alert(d);
				return false;
			} else {
				$("#"+eid).remove();
			}
		}
	);
}


function Pmdelete(i,eid,act) {
	if(!confirm("确认删除？")) return false;
	
	var i = 'undefined' == typeof(i) ? 0 : i;
	var act = 'undefined' == typeof(act) ? '' : act;
	var myAjax = $.post(
		"ajax.php?mod=pm&code=delete",
		{
			pmid:i,
			act:act
			
		},
		function (d) {
			if(''!=d) {
				alert(d);
				return false;
			} else {
				$("#"+eid).remove();
			}
		}
	);
}

function pmTopic(i,eid,act) {
	var i = 'undefined' == typeof(i) ? 0 : i;
	var eid = 'undefined' == typeof(eid) ? 'Pmreply_area_' + i : eid;
	var act = 'undefined' == typeof(act) ? '' : act;
	var eidVal = $("#"+eid).html();
	
	if(''==eidVal) {
		var myAjax = $.post(
			"ajax.php?mod=pm&code=view_comment",
			{
				pmid:i,
				cod:act
			},
			function (d) { 
				if(''!=d) {
					$("#"+eid).html(d);
				}
			}
		);
	} else {
		$("#"+eid).html('');
	}
}



function favoriteTopic(i,act) {
	var i = 'undefined' == typeof(i) ? 0 : i;
	var act = 'undefined' == typeof(act) ? '' : act;
	var eid = 'favorite_' + i;
	var myAjax = $.post(
		"ajax.php?mod=topic&code=favor",
		{
			tid:i,
			act:act
		},
		function (d) {
			if(''!=d) {
				$("#"+eid).html(d);
			}
		}
	);	
}
function follow(fid,eid) {
	var myAjax = $.post(
		"ajax.php?mod=topic&code=follow",
		{
			id:fid
		},
		function (d) {
			if(''!=d) {
				$('#'+eid).html(d);
			}
		}
	);
}
function favoriteTag(i,act) {
	var i = 'undefined' == typeof(i) ? '' : i;
	var act = 'undefined' == typeof(act) ? '' : act;
	var eid = 'favorite_' + i;
	var myAjax = $.post(
		"ajax.php?mod=topic&code=favor_tag",
		{
			tag:i,
			act:act
		},
		function (d) {
			if(''!=d) {
				$("#"+eid).html(d);
			}
		}
	);	
}
function reportOpenWin (url) {
    window.open(url, "举报不良信息", "height=538px,width=450px,toolbar=no, menubar=no,resizable=no,location=no, status=no");
};
//复制URL地址
function copyText(_sTxt){
	if(is_ie) {
		clipboardData.setData('Text',_sTxt);
		alert ("网址“"+_sTxt+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请使用Ctrl+C快捷键复制下面的内容:",_sTxt); 
	}
}


