/**
 * 导航菜单
 *
 */
$(document).ready(function(){var a=null;$('#globalnav .withmenu').click(function(){$(this).find('.menu').css('visibility','visible');$('#globalnav .withmenu').hover(function(){if(a){a.find('.menu').css('visibility','hidden');a=null}$(this).find('.menu').css('visibility','visible')},function(){a=$(this);setTimeout(function(){if(a){a.find('.menu').css('visibility','hidden')}},400)})});$("#changeSkin").click(function(){$(this).hide();$("#skinlink").show()})});function skinlink(){var a=$("select[@name='sel'] option[@selected]").val();$("#skincss").attr("href",ROOT+"/SNS/Tpl/default/Public/images/"+a+".css");$.cookie("skin",a,{path:"/",expires:365})};$(function(){$("#deleteId,#deleteId1").click(function(){if(confirm(" 确定删除么?")){return true}else{return false}})});function IncludeJS(a){document.write('<script type="text/javascript" src="'+a+'"></script>')}function JHshStrLen(a){var b,iCount,i,strTemp;iCount=0;b=a.split("");for(i=0;i<b.length;i++){strTemp=escape(b[i]);if(strTemp.indexOf("%u",0)==-1){iCount=iCount+1}else{iCount=iCount+2}}return iCount}/*$(function(){$("#apps").sortable({delay:1,update:function(){var b=$('#apps').sortable('serialize');$.post(APP+"/Home/leftNav",b,function(a){})}})});*/function insertImg(b){var c=window.frames["Editor"];var a=c.window.frames["HtmlEditor"].document;var d="<img src='"+b+"' />";a.body.innerHTML+=d}function shareIt(){var e=$("#userId").val();var d=$("#module").val();var f=$("#recordId").val();var b=$("#title").val();var c=$("#stp-tarea").val();$.post(APP+"/Share/insert",{userId:e,module:d,recordId:f,title:b,info:c},function(a){if(a){$("#facebox .content").html("<center><font size='4'> 分享成功！</font></center>");setTimeout(function(){$.facebox.close()},1500)}else{$("#facebox .content").html("<center><font size='4'> 分享失败！</font></center>");setTimeout(function(){$.facebox.close()},1500)}})}function favourIt(){var e=$("#userId").val();var d=$("#module").val();var f=$("#recordId").val();var b=$("#title").val();var c=$("#stp-tarea").val();$.post(APP+"/Favour/insert",{userId:e,module:d,recordId:f,title:b,info:c},function(a){if(a=='success'){$("#facebox .content").html("<center><font size='4'> 收藏成功！</font></center>");setTimeout(function(){$.facebox.close()},1500)}else if(a=='favour'){$("#facebox .content").html("<center><font size='4'> 你已经收藏过了！</font></center>");setTimeout(function(){$.facebox.close()},1500)}else{$("#facebox .content").html("<center><font size='4'> 收藏失败！</font></center>");setTimeout(function(){$.facebox.close()},1500)}})}function insertQQ(b){var a=$("#con").val();var c="["+b+"]";$("#smileylist").hide();$("#con").val(a+c)}String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$) /g,"")}
$(function(){
		$(".Mconfirm").click(function(){if(confirm($(this).attr('title'))){return true}else{return false}})
		$(".Nconfirm").click(function(){doAjax(this.rel,this.id)})
		});
//检查是否登录，否则页面正中显示登录框
function checkLogin(){
	if (MID==''){
		$("#loginbox").css('display','block');
		return false;
	}
	else{
		return true;
	}
}
//文本输入框默认灰色文字
function inputDefaultTips(id,tips) {
		var input = $("#"+id);
		if ($(input).val()=='')
		$(input).val(tips);
		if ($(input).val()==tips)
		$(input).css('color','#AAA');
		$(input).focus(function() {
			if ($(this).val() == tips){
			$(this).val('');
			$(this).css('color','#000');
			}
			})
			.blur(function() {
				if($(this).val()==''){
				$(this).val(tips);
				$(this).css('color','#AAA');
				}
			})
}
//兼容复制文本
function copyToClipboard(txt) {  
	if(window.clipboardData) {  
		window.clipboardData.clearData();  
		window.clipboardData.setData("Text", txt);  
	} else if(navigator.userAgent.indexOf("Opera") != -1) {  
		window.location = txt;  
	} else if (window.netscape) {  
		try {  
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
		} catch (e) {  
			alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");  
		}  
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);  
		if (!clip)  
			return false;  
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);  
		if (!trans)  
			return false;  
		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 = txt;  
		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 true;  
}  
function copyText(id)  
{
	var text = $("#"+id).text();
	if(!text)
		text = $("#"+id).val();
	if (copyToClipboard(text))
		alert("复制成功!");
}
function sayHello(b,r){
	if (!checkLogin())
		return
	r=(typeof(r)=="undefined")?0:r;
	var c=Math.random();
	$("#facebox").hide();
	$("#tipbox").show();
	$("#tipbox .content").html('<div class="loading">&nbsp;</div>');
	$.post(APP+'/Friend/hello',{id:b,re:r,ran:c},function(a){
			if(a){
			$("#tipbox .content").html('<div class="center" style="text-align:center;">操作成功！</div>');
			setTimeout(function(){
				$("#tipbox").fadeOut()
				},1500)
			}else{
			$("#tipbox .content").html('操作失败！')
			}
			})
}
function addFriend(b){
	if (!checkLogin())
		return
	c = $('#facebox #friendRequestContent').val();
	$("#facebox .content").html('<div class="loading">&nbsp;</div>');
	$.post(APP+'/Friend/newadd',{id:b,content:c},function(a){
			if(a=='1'){
			$("#facebox .content").html('<div class="center">成功发送好友请求！</div>')
			}else if(a=='0'){
			$("#facebox .content").html('<div class="center"> 你已经发过请求了，而对方还没有处理！</div>')
			}else if(a=='-1'){
			$("#facebox .content").html('<div class="center">对方已经在你的好友名单中！</div>')
			}else if(a=='-2'){
			$("#facebox .content").html('<div class="center">不能加自己为好友！</div>')
			}
			setTimeout(function() {
				$.facebox.close()
				},2000)
			})
}
function sendMsg(b){
	if (!checkLogin())
		return
	m = '{$mid}';
	c = $('#facebox #sendMsgContent').val();
	if(c.Trim()==""){
		alert("内容不能为空!");
		return false
	}
	$("#facebox .content").html('<div class="loading">&nbsp;</div>');
	$.post(APP+'/Message/insert',{toUserId:b,fromUserId:m,content:c,ajax:'1'},function(a){
			if(a){
			$("#facebox .content").html('<div class="center">发送成功！</div>');
			setTimeout(function(){
				$.facebox.close()
				},1500)
			}else{
			$("#facebox .content").html('发送失败！')
			}
			})
}
function recommend(module,ele){
	$("#tipbox .content").html('<div class="loading">&nbsp;</div>');
	var id = $(ele).attr('tid');
	$.post(APP+'/Recommend/insert',{module:module,recordId:id,ajax:'1'},function(a){
			$("#tipbox").show();
			if(a){
			var ret = eval('('+a+')');
			if (ret['status']=='1'){
			var b=parseInt($("#recommendnum").text())+1;
			$("#recommendnum").text(b+" ");
			if (typeof albumPhotos != "undefined")
			albumPhotos[cur]['recommendCount']++;
			if (module=="Blog") {
			$("#tipbox .content").html('<div class="center">成功赞了一下游记！</div>');
			}else if(module=="Collect"){
			$("#tipbox .content").html('<div class="center">成功赞了一下珍藏集！</div>');
			}else{
			$("#tipbox .content").html('<div class="center">成功推荐！</div>');
			}
			if((XNID!=0)&&(ret.xnfeedTitle!='')){
			var template_id = 2;
			var title_data = {"title":ret.xnfeedTitle};
			var body_data = {"content":ret.xnfeedContent};
			XN.Main.apiClient.feed_publishTemplatizedAction(template_id, title_data, body_data, function(result, ex){});
			}
			}else
			$("#tipbox .content").html('<div class="center">你已经推荐过了！</div>');
			setTimeout(function(){
				$("#tipbox").fadeOut('slow');
				},1500)
			}else{
			$("#tipbox .content").html('推荐失败！')
			}
			})
}
function referURL(url){
	var isIe=(document.all)?true:false;
	if(isIe) {
		var linka = document.createElement('a');
		linka.href=url;
		document.body.appendChild(linka);
		linka.click();
	}else {
		window.location = url;
	}
}
function settab(id){
	$(".tit_dl03 li").removeClass('cur');
	$(".tit_dl03 li#tab"+id).addClass('cur');
	$(".contentlist").hide();
	$("#content"+id).show();
}
function checkContent(text){
	if((text.Trim()=="")||(text.Trim().replace("\n",'').replace(/(<br>|<p>|<\/p>|&nbsp;)/gi,'')==""))
		return false;
	return true;
}
function huifuThread(d,h){
	//$("#hf_userId").val(h);
	//$("#replyId").val(d);
	if(d){
	if ($("#huifu_form_"+d+" iframe").attr('src')=='')
		$("#huifu_form_"+d+" iframe").attr('src',PUBLIC+"/Js/Editor/editorcmt.html?id=icontent"+d+"&btn=btn"+d+"&height=180");
	$("#huifu_form_"+d+" input[@name='hf_userId']").val(h);
	$("#huifu_form_"+d+" a.switch").attr('href',$("#huifu_form_"+d+" a.switch").attr('rel')+'/hf_userId/'+h);
	$("#huifu_form_"+d).show();
	$("#huifu_form_"+d+" textarea#icontent"+d).show();
	$("#huifu_form_"+d+" textarea#icontent"+d).focus();
	$("#huifu_form_"+d+" textarea#icontent"+d).hide();
	setTimeout(function(){window.frames['Editor'+d].frames['HtmlEditor'].focus();},1000);
	}else{
	window.frames['Editor'].frames['HtmlEditor'].focus();
	}
	//window.location='#r';
}
function send_hf(a){
	if(typeof a == 'undefined')
		a = '';
	frames['Editor'+a].SaveContent();
	if(checkContent($('#icontent'+a).val())){
		$('#huifu_form_'+a).submit();
	}else{
		alert('请输入回复内容');
	}
}
function switchpost(t){
	if (t=='simple'){
		$('#simple').show();
		$('#complex').hide();
		$('#fastposttip').show();
		$('#Editor').attr('src',PUBLIC+'/Js/Editor/editorcmt.html?id=icontent&height=180');
		$('#Editor').css('height',180);
	}else{
		$('#simple').hide();
		$('#complex').show();
		$('#fastposttip').hide();
		$('#Editor').attr('src',PUBLIC+'/Js/Editor/editor.html?id=icontent&height=300');
		$('#Editor').css('height',300);
	}
}
function getpos(element,abs)
{
	if ( arguments.length < 1 || element == null )
	{
		return null;
	}
	if(arguments.length == 1)   
		abs = 0;   
	var elmt = element;
	var offsetTop = elmt.offsetTop;
	var offsetLeft = elmt.offsetLeft;
	var offsetWidth = elmt.offsetWidth;
	var offsetHeight = elmt.offsetHeight;
	while( elmt = elmt.offsetParent )
	{
		if(!abs){
		offsetTop += elmt.offsetTop;
		offsetLeft += elmt.offsetLeft;
		}
		// add this judge
		if ( elmt.style.position == 'absolute'
//              || elmt.style.position == 'relative'
				|| ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) )
		{
			break;
		}
		if(abs){
		offsetTop += elmt.offsetTop;
		offsetLeft += elmt.offsetLeft;
		}
	}
	return {top:offsetTop, left:offsetLeft, right:offsetWidth+offsetLeft, bottom:offsetHeight+offsetTop };
}
function b_strlen(fData)
{
	var intLength=0;
	for (var i=0;i<fData.length;i++)
	{
		if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255))
			intLength=intLength+2;
		else
			intLength=intLength+1;   
	}
	return intLength;
}
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 getCurTime(){
	var now = new Date();  
	return now.getTime();
}
function IsIE()
{
	return document.all ? true : false;
} 


var cityArray=new Array("北京","深圳","广州");
$(function(){
		var city = $.cookie('city');
		var content = '';
		if (city!=null) {
		var pos=-1;
		for (i=0;i<cityArray.length;++i){
		if (cityArray[i] == city)
		pos=i;
		}
		content += '<li><font color="#FF6702">'+city+'</font></li>';
		}
		for (i=0;i<((pos==-1)?(cityArray.length-1):(cityArray.length));++i){
		if (i != pos)
		content += '<li><a href="'+APP+'/Public/city/name/'+encodeURIComponent(cityArray[i])+'">'+cityArray[i]+'</a></li>';
		}
		$("#citys").html(content);
		$(".g_fx a").click(function(){
			if(checkLogin())
			$.facebox.click(this);
			})
		$(".autocut a").each(function(){
			if (this.parentNode.clientWidth && (this.scrollWidth >= this.parentNode.clientWidth)) {
			$(this).attr("title",$(this).text());
			}
			})
		$(".topicBox img").each(function(){
			if (this.width > 560) {
			this.width = 560;
			}
			})
		});
