﻿   
 String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
 String.prototype.replaceAll  = function(s1,s2){    
return this.replace(new RegExp(s1,"gm"),s2);    
}   
 
 
function valueReplace(v){ 
v=v.toString().replace(new RegExp('(["\"])', 'g'),"\\\""); 
//alert(v);
v=v.toString().replaceAll("'","\\\'"); 
return v; 
} 
 
 
   //begin feed
   
    //弹出删除feed对话框
  function pop_feed_del(feedid,ctrId)
  {
      $("#append_parent").load("cp_feed.aspx?feedid="+feedid+"&op=delete #del_"+feedid,{},function()
	   {  
	  
	    setPopupPosition(ctrId,"del_"+feedid,0);
	   $(".popupmenu_centerbox").easydrag(true);
	   $("#del_"+feedid).focus();
	   });  
  }
  
  function del_feed(feedid) {
    var jsonData =  "{feedid :"+feedid+ "}"; 
             $.ajax({
          type: "POST",
          url: "cp_feed.aspx/del_feed",
          data: jsonData,
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(msg) {
      
                    if (msg=="true")
                    {
                    
                        $("#feed_"+feedid+"_li").remove();
                        showHintAutoClose("删除成功！");
                    
                    }
                    else
                    {
                      alert("只有作者才能删除自己的feed信息！");
                    
                    }
          
          
          
          }
          });
  
  }
  
  
    function pop_feed_ignore(feedid,uid,icon,ctrId)
  {
      $("#append_parent").load("cp_feed.aspx?feedid="+feedid+"&uid="+uid+"&icon="+icon+"&op=ignore #ignore_"+feedid,{},function()
	   {  
	
	    setPopupPosition(ctrId,"ignore_"+feedid,0);
	   $(".popupmenu_centerbox").easydrag(true);
	   $("#ignore_"+feedid).focus();
	   });  
  }
  
  function ignore_feed(feedid,icon) {
  
     var uid = $('input:radio[name=uid][checked=true]').val();
   //  alert(uid);
     
      var jsonData =  "{feedid :"+feedid+ ",uid:"+uid+",icon:'"+icon+"'}"; 
             $.ajax({
          type: "POST",
          url: "cp_feed.aspx/ignore_feed",
          data: jsonData,
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(msg) {
      
                    if (msg=="true")
                    {
                    
                        
                        showHintAutoClose("屏蔽成功！");
                    
                    }
                   
                   
          
          
          
          }
          });
  
  }
  
  
  
  
  
  //主页上向对方发送短信
  function poppm(touid)
  {
  
  
         $.ajax({
              type: "POST",
              url: "cp_common.aspx/check_online",
              data: "{}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
              if (msg=="false") {
                showHintAutoClose("你需要先登陆才能进行本操作！");
              
              }
              else
              {
                  
                  $("#append_parent").load("cp_pm.aspx?touid="+touid+"&op=ajax #pm_"+touid,{},function()
	               {  
	               setCenter("pm_"+touid);
	               $(".popupmenu_centerbox").easydrag(true);
	               $(".popupmenu_centerbox").setHandler('drag_title');
	               $("#pm_"+touid).focus();
	               }); 
         
	           } 
                
                 
              }
            });
  
  
  
  
 
  }
  
  //主页上发送短信
  function send_message_touid(touid) {

  var message = $('#message1').val();

   var jsonData =  "{touid :"+touid+","
                      +" message : '"+  message+"'" 
                    + "}"; 
                        
             $.ajax({
              type: "POST",
              url: "cp_pm.aspx/send_message_touid",
              data: jsonData,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
          
                        if (msg=="true")
                        {
                        
                            showHintAutoClose("发送成功！");
                        
                        }
                        else
                        {
                          alert(msg);
                        
                        }
              
              
              
              }
              });
  
  }
  
  
  
  
  
  
  function popuptrace(myuid,uid,blogid,cdiv)
    {
    if (myuid==0)
    {
        NewshowHintAutoClose("信息提示","该操作需要登陆，请先登陆");
    }
    else 
    {
        var jsonData =  "{myuid :'"+myuid+"',"
                      +" uid : '"+  uid+"',"   
                    +" blogid : '"+  blogid+"'"   
                    + "}";     
             $.ajax({
              type: "POST",
              url: "space_blog_view.aspx/Hastrace",
              data: jsonData,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
          
                        if (msg=="1")
                        {
                        
                            showHintAutoClose("你已经留过脚印了！");
                        
                        }
                        else
                        {
                         var ol = $("#trace_ul");
                         ol.append(msg); 
                         
                         $("#trace_li").remove();
                         $("#trace_li_show").remove();
                        
                         showHintAutoClose("你成功留下脚印");
                        
                        }
              
              
              
              }
              });
    }
    
}
//获取关键字
function relatekw() {
$("#tag")[0].value="";
    var subject="";
	 subject = $("#subject")[0].value;
//	var message = cnCode($('uchome-ttHtmlEditor').value);
//	if(message) {
//		message = message.substr(0, 500);
//		message = message.replace(/&/ig, '', message);
//	}
	
//	  var message =  $("#comment_message").val()=="undefined" ? "": $("#comment_message").val();
//      var id =  $("#id").val()=="undefined" ? "": $("#id").val();  
//      var uid =  $("#uid").val()=="undefined" ? "": $("#uid").val();  
//      var idtype =  $("#idtype").val()=="undefined" ? "": $("#idtype").val();  
    var jsonData =  "{subject :'"+subject+"'}";
        // var jsonData =  "{message :'"+message+"', id :'"+id+"', uid :'"+uid+"', idtype :'"+idtype+"'}";
         
             $.ajax({
              type: "POST",
              url: "cp_blog.aspx/relatekw",
              data: jsonData,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
              
              $("#tag")[0].value = msg;
              }
            });
	
}
function cnCode(str) {
	return is_ie && document.charset == 'utf-8' ? encodeURIComponent(str) : str;
}


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);




/////////////////////////////////////宋叶俊poke begin


    
    //显示poke
    function poppoke(uid)
    {
       
       
         $.ajax({
              type: "POST",
              url: "cp_common.aspx/check_online",
              data: "{}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
              if (msg=="false") {
                showHintAutoClose("你需要先登陆才能进行本操作！");
              
              }
              else
              {
               
                   $("#append_parent").load("cp_poke.aspx?op=send&uid="+uid+" #poke_div_"+uid,{"uid":uid ,"username":"syj"},function()
	               {  
	               setCenter("poke_div_"+uid);
	               $(".popupmenu_centerbox").easydrag(true);
	               $(".popupmenu_centerbox").setHandler("drag_title");
	               $("#poke_"+uid).focus();
	               }); 
	           } 
                
                 
              }
            });
       
       

         
    }
    
   
    //保存poke
	 function savepoke(uid)
    {
       
   
   //  var poke_i = $("input[@name=iconid][@checked]").val();
    // var poke_i = $("input[name='iconid']:checked").val();
       var poke_i =  $("input[name='iconid']:checked").val()==undefined ? 0: $("input[name='iconid']:checked").val();
        var note =  $("#note").val();
        var jsonData =  "{uid :'" + uid +"',"
                        +"poke_i :'" + poke_i +"',"
                        +"note :'"+ note +"'}";
                       
         
             $.ajax({
              type: "POST",
              url: "cp_poke.aspx/Savepoke",
              data: jsonData,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
               // hidePopup();
                hideMenu();
                
            //    showHintAutoClose("已经打招呼,下次"+msg+"登陆会看到招呼"); //$("#doingform").submit();
                
                 showHintAutoClose(msg);
              }
            });
    
    }
   
   
   
///////////////////////////////////////好友操作开始friend
 function popAdd(uid,myuid,username,ctlId)
     {
     
     
         $.ajax({
              type: "POST",
              url: "cp_common.aspx/check_online",
              data: "{}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
              if (msg=="false") {
                showHintAutoClose("你需要先登陆才能进行本操作！");
              
              }
              else
              {
                 var jsonData =  "{fuid :'"+uid+"'}";       
                 $.ajax({
                  type: "POST",
                  url: "cp_friend.aspx/HasFriend",
                  data: jsonData,
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function(msg) {
                            if (msg=="2")
                            {
                                 showHint("正在等待对方验证中");
                            
                            }
                            else if (msg=="1")
                            {
                            
                                showHint("对方已是你的好友");
                            
                            }
                            else
                            {
                            
                                popupMenu(uid,myuid,username,ctlId);
                            
                            }
                  
                  
                  
                  }
                  
                  });
              }
     
     }
     });
     

     
     }
    
    
    

    function popupMenu(uid,myuid,username,ctlId)
    {
       hideMenu();
                
 var sDiv = "<div id='a_friend_friend_"+uid+"_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class='popupmenu_centerbox'><div class='popupmenu_option'><div id="+uid+">"
+"<div id='drag_title'>"
+"<h1>加好友</h1>"
+"<a class='float_del' title='关闭' href='javascript:hideMenu();'>关闭</a>"
+"</div>"
+"<div class='popupmenu_inner'>"
+"<table cellspacing='0' cellpadding='3'>"
+"<tbody><tr>"
+"<th width='52'><a href='space.aspx?uid="+uid+"'><img height='48' width='48' alt="+ username+" src='/avatar.aspx?uid="+uid+"&size=Small'/></a></th>"
+"<td>加 <strong>"+ username+"</strong> 为好友，附言：<br/>"
+"<input type='text' onkeydown='ctrlEnter(event,\"addsubmit_btn\", 1);' id ='txtNote' style='width: 300px;' class='t_input'size='20' value=''/>"
+"<p class='gray'>(附言为可选，"+ username+" 会看到这条附言，最多50个字符)</p>"
+"</td>"
+"</tr>"
+"<tr>"
+"<th></th>"
+"<td>"
+"分组: <select name='gid' id='gid'>"
//+"<option value='0'>其他</option>"
//+"<option value='1'>通过本站认识</option>"
//+"<option value='2'>通过活动认识</option>"
//+"<option value='3'>通过朋友认识</option>"
//+"<option value='4'>亲人</option>"
//+"<option value='5'>同事</option>"
//+"<option value='6'>同学</option>"
//+"<option value='7'>不认识</option>"
//+"<option value='8'>自定义8</option>"
//+"<option value='9'>自定义9</option>"
+"</select>"
+"<input type='button' onclick='addFriend("+uid+", \""+username+"\")' class='submit' value='确定' id='addsubmit_btn' name='addsubmit_btn'/>"
+"</td></tr></tbody></table></div></div></div></div>";
                
                   
                   
                   
         $("#append_parent").append(sDiv);
        $(".popupmenu_centerbox").easydrag(true);
        $(".popupmenu_centerbox").setHandler('drag_title');
         setPopupPosition(ctlId,"a_friend_friend_"+uid+"_menu",1);
        //bindFriendGroup(uid);
        bindFriendGroup(myuid);
         
    }
    function addFriend(uid,username)
    {
       
        var jsonData =  "{fuid :'"+uid+"',"
                    +" fusername : '"+username+"',"
                    +" note : '"+ $("#txtNote").val()+"',"
                    +" gid : '"+   $("#gid").val()+"'"   
                    + "}"; 
                    
        $.ajax({
              type: "POST",
              url: "cp_friend.aspx/saveaddfriend",
              data: jsonData,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
                showHintAutoClose("正在等待对方验证中")
              }
              }
              );           
       
    
    }
    
    function bindFriendGroup(uid)
    {
            var jsonData =  "{uid :'"+uid+"'}";       
             $.ajax({
              type: "POST",
              url: "cp_friend.aspx/GetFriendGroup",
              data: jsonData,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
             
              var myjson="";
              eval("myjson=" + msg + ";")
              
                var data = myjson.rows;
                var gid =  $("#gid");
                $.each(data, function(i, n){
                
                 $("<option value='" + n.i + "'>" + n.name + "</option>").appendTo(gid)
                
               
                
                });
              }
            });
      }
    
    
    function denyReq(uid)
{
   // var tbid = id.substr(6);
    
    var jsonData =  "{fuid :'"+uid+"'}";       
     $.ajax({
      type: "POST",
      url: "cp_friend.aspx/DenyReq",
      data: jsonData,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
            $('#friend_'+uid).empty();
            $('#friend_'+uid).html('<p class="l_status">成功忽略了该用户的好友申请</p>');
      }
      });
}

function acceptReq(fuid,fusername)
{
    //var tbid = id.substr(6);
    var jsonData =  "{fuid :'"+fuid+"',"
                    +"fusername :'"+fusername+"' }"    
     $.ajax({
      type: "POST",
      url: "cp_friend.aspx/ChooseGroup",
      data: jsonData,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
      $("#append_parent").empty();
 
       $("#append_parent").append(msg);
       setCenter("a_f_r_" + fuid + "_menu");
        $("#a_f_r_" + fuid + "_menu").easydrag(true);
        $("#a_f_r_" + fuid + "_menu").setHandler('hander');
      
//            $('#friend_'+tbid).empty();
//            $('#friend_'+tbid).html('<p class="l_status">成功忽略了该用户的好友申请</p>');
      }
      });

}


function acceptmyfriend(fuid,fusername)
{

   

    var gid = $('input[name=gid][checked]').val();

    var jsonData =  "{fuid :'"+fuid+"',"
                    +"fusername :'"+fusername+"',"
                    +"gid :'" + gid+"'}";   
     $.ajax({
      type: "POST",
      url: "cp_friend.aspx/AcceptReq",
      data: jsonData,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
      
        showHintAutoClose("添加当前好友成功了");
        $('#friend_'+fuid).empty();
        $('#friend_'+fuid).html("<p class='l_status'>添加当前好友成功了。您可以<a href=myspace--"+fuid+".html> 访问好友的主页</a></p>");
       
      
      }
      });


}

    //////////////////////////////////////好友操作结束friend


function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

function insertContent(target, text) {
	var obj = $('#'+target)[0];
	selection = document.selection;
	checkFocus(target);
	if(!isUndefined(obj.selectionStart)) {
		var opn = obj.selectionStart + 0;
		obj.value = obj.value.substr(0, obj.selectionStart) + text + obj.value.substr(obj.selectionEnd);
	} else if(selection && selection.createRange) {
		var sel = selection.createRange();
		sel.text = text;
		var length = strlen(text);
		sel.moveStart('character', -length);
	} else {
		obj.value += text;
	}
}

function checkFocus(target) {
	var obj = $('#'+target)[0];
	if(!obj.hasfocus) {
		obj.focus();
	}
}

//Ctrl+Enter 發佈
function ctrlEnter(event, btnId, onlyEnter) {
	if(isUndefined(onlyEnter)) onlyEnter = 0;
	if((event.ctrlKey || onlyEnter) && event.keyCode == 13) {
		$('#'+btnId)[0].click();
	}
}



//缩放Textarea
function zoomTextarea(id, zoom) {
	zoomSize = zoom ? 10 : -10;
	obj=$("#"+id)[0]
	//obj = $(id);
	if(obj.rows + zoomSize > 0 && obj.cols + zoomSize * 3 > 0) {
		obj.rows += zoomSize;
		obj.cols += zoomSize * 3;
	}
}
function strlen(str) {
	return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}


function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	while((obj = obj.offsetParent) != null) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset };
}
//pos ==1 表示居中，pos = 0 则表示在showid的边上
function setPopupPosition(showid,popupid,pos) {
	
		
		var showobj = $("#"+showid)[0];
		var popobj = $("#"+popupid)[0];
		if (pos == 0)
		{
			showobj.pos = fetchOffset(showobj);
			showobj.X = showobj.pos['left'];
			showobj.Y = showobj.pos['top'];
			showobj.w = showobj.offsetWidth;
			showobj.h = showobj.offsetHeight;
		}
		popobj.w = popobj.offsetWidth;
		popobj.h = popobj.offsetHeight;
		if (pos==0)
		{
	
			
			popobj.style.left = (showobj.X + popobj.w > document.body.clientWidth) && (showobj.X + showobj.w - popobj.w >= 0) ? showobj.X + showobj.w - popobj.w + 'px' : showobj.X + 'px';
			popobj.style.top = ((showobj.Y + showobj.h + popobj.h > document.documentElement.scrollTop + document.documentElement.clientHeight) && (showobj.Y - popobj.h >= 0)) ? (showobj.Y - popobj.h) + 'px' : showobj.Y + showobj.h + 'px';

		}
		else
		{			
			popobj.style.left = (document.body.clientWidth-popobj.w)/2 + 'px';
			var divtop = document.documentElement.scrollTop + (document.documentElement.clientHeight-popobj.h)/2;
			if(divtop > 100) divtop = divtop - 100;
			popobj.style.top = divtop + 'px';		
		}
		
	
}


function setCenter(popupid) {

    var popobj = $("#"+popupid)[0];
    popobj.w = popobj.offsetWidth;
	popobj.h = popobj.offsetHeight;
    
	popobj.style.left = (document.body.clientWidth-popobj.w)/2 + 'px';
	var divtop = document.documentElement.scrollTop + (document.documentElement.clientHeight-popobj.h)/2;
	if(divtop > 100) divtop = divtop - 100;
	popobj.style.top = divtop + 'px';	

}


function getNotifyCount(uid){

//  var jsonData =  "";   
     $.ajax({
      type: "POST",
      url: "my/Func.aspx/GetNotifyCount",
 //     data: jsonData,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
      
        $('.menu').append("<li   class='notify' ><a href='space.php?do=notice'>总共有"+msg+"条新通知</a></li>");       
      
      }
      });
}



function hideMenu()
{

    $(".popupmenu_centerbox").hide();       
    $("#append_parent").empty();
}

function showHint(content)
{
    hideMenu();
    var hint = "<div id='hint_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class='popupmenu_centerbox'><div class='popupmenu_option'><h1>  &nbsp</h1><a class='float_del' onclick='hideMenu();' href='javascript:;'>X</a><div class='popupmenu_inner'></div></div></div>"

    $("#append_parent").append(hint);
    $(".popupmenu_inner").html(content);
    setCenter("hint_menu");
}



function showHintAutoClose(content)
{
    hideMenu();
    //var hint = "<div id='hint_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class='popupmenu_centerbox'><div class='popupmenu_option'><div class='popupmenu_inner'></div></div></div>"
    var hint = "<div id='hint_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class='popupmenu_centerbox'><div class='popupmenu_option'><h1>  &nbsp</h1><a class='float_del' onclick='hideMenu();' href='javascript:;'>X</a><div class='popupmenu_inner'></div></div></div>"
    $("#append_parent").append(hint);
    $(".popupmenu_inner").html(content);
    setCenter("hint_menu");
    setTimeout(hideMenu,1700);
}


function wj_showHintAutoClose(title,content)
{
    hideMenu();
    //var hint = "<div id='hint_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class='popupmenu_centerbox'><div class='popupmenu_option'><div class='popupmenu_inner'></div></div></div>"
    var hint = "<div id='hint_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); width:200px' class='popupmenu_centerbox'><div class='popupmenu_option'><h1>"+title+"</h1><a class='float_del' onclick='hideMenu();' href='javascript:;'>X</a><div class='popupmenu_inner'></div></div></div>"
    $("#append_parent").append(hint);
    $(".popupmenu_inner").html(content);
    setCenter("hint_menu");
    setTimeout(hideMenu,2000);
}



function showHintCredit(rewardtype,rulename,credit)
{
    hideMenu();
    //var hint = "<div id='hint_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class='popupmenu_centerbox'><div class='popupmenu_option'><div class='popupmenu_inner'></div></div></div>"
    if (rewardtype="0")
    {
    var rt="-";
    }
    else 
    {
     var rt="+";
    }
    var hint = "<div id='hint_menunew' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class=\"popupmenu_layer\"><p>"+rulename+"</p><p class=\"btn_line\">积分 <strong>"+rt+credit+"</strong> </p><p>发的越多,积分越多</p></div>"
    
    $("#append_parent").append(hint);
    $(".popupmenu_rulename").html(rulename);
    $(".popupmenu_credit").html(credit);
    setCenter("hint_menunew");
    setTimeout(hideMenu,1700);
}
function NewshowHintAutoClose(title,content)
{
    hideMenu();
    //var hint = "<div id='hint_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class='popupmenu_centerbox'><div class='popupmenu_option'><div class='popupmenu_inner'></div></div></div>"
    var hint = "<div id='hint_menu' style='position: absolute; z-index: 50; clip: rect(auto, auto, auto, auto); ' class='popupmenu_centerbox'><div class='popupmenu_option'><h1>"+title+"</h1><a class='float_del' onclick='hideMenu();' href='javascript:;'>X</a><div class='popupmenu_inner'></div></div></div>"
    $("#append_parent").append(hint);
    $(".popupmenu_inner").html(content);
    setCenter("hint_menu");
    setTimeout(hideMenu,1700);
}

// 停止音乐flash
function stopMusic(preID, playerID) {
	var musicFlash = preID.toString() + '_' + playerID.toString();
	if($("#"+musicFlash)[0]) {
		$("#"+musicFlash)[0].SetVariable('closePlayer', 1);
	}
}
// 显示影视、音乐flash
function showFlash(host, flashvar, obj, shareid) {
	var flashAddr = {
		'youku.com' : 'http://player.youku.com/player.php/sid/FLASHVAR/v.swf',
		'ku6.com' : 'http://player.ku6.com/refer/FLASHVAR/v.swf',
		'youtube.com' : 'http://www.youtube.com/v/FLASHVAR',
		'5show.com' : 'http://www.5show.com/swf/5show_player.swf?flv_id=FLASHVAR',
		'video.sina.com.cn' : 'http://vhead.blog.sina.com.cn/player/outer_player.swf?vid=FLASHVAR',
		'blog.sohu.com' : 'http://v.blog.sohu.com/fo/v4/FLASHVAR',
		'mofile.com' : 'http://tv.mofile.com/cn/xplayer.swf?v=FLASHVAR',
		'music' : 'FLASHVAR',
		'flash' : 'FLASHVAR'
	};
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="480" height="400">'
	    + '<param name="movie" value="FLASHADDR" />'
	    + '<param name="quality" value="high" />'
	    + '<param name="bgcolor" value="#FFFFFF" />'
	    + '<embed width="480" height="400" menu="false" quality="high" src="FLASHADDR" type="application/x-shockwave-flash" />'
	    + '</object>';
	var videoFlash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="450">'
        + '<param value="transparent" name="wmode"/>'
		+ '<param value="FLASHADDR" name="movie" />'
		+ '<embed src="FLASHADDR" wmode="transparent" allowfullscreen="true" type="application/x-shockwave-flash" width="480" height="450"></embed>'
		+ '</object>';
	var musicFlash = '<object id="audioplayer_SHAREID" height="24" width="290" data="image/player.swf" type="application/x-shockwave-flash">'
		+ '<param value="image/player.swf" name="movie"/>'
		+ '<param value="autostart=yes&bg=0xCDDFF3&leftbg=0x357DCE&lefticon=0xF2F2F2&rightbg=0xF06A51&rightbghover=0xAF2910&righticon=0xF2F2F2&righticonhover=0xFFFFFF&text=0x357DCE&slider=0x357DCE&track=0xFFFFFF&border=0xFFFFFF&loader=0xAF2910&soundFile=FLASHADDR" name="FlashVars"/>'
		+ '<param value="high" name="quality"/>'
		+ '<param value="false" name="menu"/>'
		+ '<param value="#FFFFFF" name="bgcolor"/>'
	    + '</object>';
	var musicMedia = '<object height="64" width="290" data="FLASHADDR" type="audio/x-ms-wma">'
	    + '<param value="FLASHADDR" name="src"/>'
	    + '<param value="1" name="autostart"/>'
	    + '<param value="true" name="controller"/>'
	    + '</object>';
	var flashHtml = videoFlash;
	var videoMp3 = true;
	if('' == flashvar) {
		alert('音乐地址错误，不能为空');
		return false;
	}
	if('music' == host) {
		var mp3Reg = new RegExp('.mp3$', 'ig');
		var flashReg = new RegExp('.swf$', 'ig');
		flashHtml = musicMedia;
		videoMp3 = false
		if(mp3Reg.test(flashvar)) {
			videoMp3 = true;
			flashHtml = musicFlash;
		} else if(flashReg.test(flashvar)) {
			videoMp3 = true;
			flashHtml = flash;
		}
	}
	flashvar = encodeURI(flashvar);
	if(flashAddr[host]) {
		var flash = flashAddr[host].replace('FLASHVAR', flashvar);
		flashHtml = flashHtml.replace(/FLASHADDR/g, flash);
		flashHtml = flashHtml.replace(/SHAREID/g, shareid);
	}
	
	if(!obj) {
		$("#flash_div_" + shareid)[0].innerHTML = flashHtml;
		return true;
	}
	if($("#flash_div_" + shareid)[0]) {
		$("#flash_div_" + shareid)[0].style.display = '';
		$("#flash_div_" + shareid)[0].style.display = '';
		obj.style.display = 'none';
		return true;
	}
	if(flashAddr[host]) {
		var flashObj = document.createElement('div');
		flashObj.id = 'flash_div_' + shareid;
		obj.parentNode.insertBefore(flashObj, obj);
		flashObj.innerHTML = flashHtml;
		obj.style.display = 'none';
		var hideObj = document.createElement('div');
		hideObj.id = 'flash_hide_' + shareid;
		var nodetxt = document.createTextNode("收起");
		hideObj.appendChild(nodetxt);
		obj.parentNode.insertBefore(hideObj, obj);
		hideObj.style.cursor = 'pointer';
		hideObj.onclick = function() {
			if(true == videoMp3) {
				stopMusic('audioplayer', shareid);
				flashObj.parentNode.removeChild(flashObj);
				hideObj.parentNode.removeChild(hideObj);
			} else {
				flashObj.style.display = 'none';
				hideObj.style.display = 'none';
			}
			obj.style.display = '';
		}
	}
}

function ctrlEnter(event, btnId, onlyEnter) {
	if(isUndefined(onlyEnter)) onlyEnter = 0;
	var k = event.ctrlKey || onlyEnter;
	if( k && (event.keyCode == 13)) {

		$("#"+btnId).click();


    
        
//       	event.stopPropagation(); 
//		event.preventDefault(); 
		event.returnValue   =   false;  
		 
        return false;

       

	}
}
//Enter 發佈
function Enter(event, btnId) {
	if( event.keyCode == 13) {
		$('#'+btnId)[0].click();
	}
}


//复制URL地址
function setCopy(_sTxt){
	if(is_ie) {
		clipboardData.setData('Text',_sTxt);
		alert ("网址“"+_sTxt+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请复制网站地址:",_sTxt); 
	}
}

function checkAll(form, name) {
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name.match(name)) {
			e.checked = form.elements['chkall'].checked;
		}
	}
}

function getExt(path) {
	return path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
}

function showPreview(val, id) {
 var showObj = $("#"+id);
 if(typeof showObj == 'object') {
  showObj.innerHTML = val.replace(/\n/ig, "<br />");
 }
}


function showPreview(val, id) {
	var showObj = $("#"+id);
	if(typeof showObj == 'object') {
		showObj.innerHTML = val.replace(/\n/ig, "<br />");
	}
}

function addSort(obj) {
	if (obj.value == 'addoption') {
 	var newOptDiv = document.createElement('div')
 	newOptDiv.id = obj.id+'_menu';
 	newOptDiv.innerHTML = '<h1>添加</h1><a href="javascript:;" onclick="addOption(\'newsort\', \''+obj.id+'\')" class="float_del">删除</a><div class="popupmenu_inner" style="text-align: center;">名称：<input type="text" name="newsort" size="10" id="newsort" class="t_input" /><input type="button" name="addSubmit" value="创建" onclick="addOption(\'newsort\', \''+obj.id+'\')" class="button" /></div>';
 	newOptDiv.className = 'popupmenu_centerbox';
 	newOptDiv.style.cssText = 'position: absolute; left: 50%; top: 200px; width: 400px; margin-left: -200px;';
 	document.body.appendChild(newOptDiv);
 	$('#newsort')[0].focus();
 	}
}
	
function addOption(sid, aid) {
	var obj = $("#"+aid)[0];
	var newOption = $("#"+sid)[0].value;
	$("#"+sid)[0].value = "";
	if (newOption!=null && newOption!='') {
		var newOptionTag=document.createElement('option');
		newOptionTag.text=newOption;
		newOptionTag.value="new:" + newOption;
		try {
			obj.add(newOptionTag, obj.options[0]); // doesn't work in IE
		} catch(ex) {
			obj.add(newOptionTag, obj.selecedIndex); // IE only
		}
		obj.value="new:" + newOption;
	} else {
		obj.value=obj.options[0].value;
	}
	// Remove newOptDiv
	var newOptDiv = document.getElementById(aid+'_menu');
	var parent = newOptDiv.parentNode;
	var removedChild = parent.removeChild(newOptDiv);
}



//缩小图片并添加链接
function resizeImg(id,size) {

if ($("#"+id)[0]!=undefined) {

	var theImages = $("#"+id)[0].getElementsByTagName('img');
	for (i=0; i<theImages.length; i++) {
		theImages[i].onload = function() {
			if (this.width > size) {
				this.style.width = size + 'px';
				if (this.parentNode.tagName.toLowerCase() != 'a') {
					var zoomDiv = document.createElement('div');
					this.parentNode.insertBefore(zoomDiv,this);
					zoomDiv.appendChild(this);
					zoomDiv.style.position = 'relative';
					zoomDiv.style.cursor = 'pointer';
					
					this.title = '点击图片，在新窗口显示原始尺寸';
					
					var zoom = document.createElement('img');
					zoom.src = 'image/zoom.gif';
					zoom.style.position = 'absolute';
					zoom.style.marginLeft = size -28 + 'px';
					zoom.style.marginTop = '5px';
					this.parentNode.insertBefore(zoom,this);
					
					zoomDiv.onmouseover = function() {
						zoom.src = 'image/zoom_h.gif';
					}
					zoomDiv.onmouseout = function() {
						zoom.src = 'image/zoom.gif';
					}
					zoomDiv.onclick = function() {
						window.open(this.childNodes[1].src);
					}
				}
			}
		}
	}
	}
}



function copyRow(tbody) {
 var add = false;
 var newnode;
 if($("#"+tbody)[0].rows.length == 1 && $("#"+tbody)[0].rows[0].style.display == 'none') {
  $("#"+tbody)[0].rows[0].style.display = '';
  newnode = $("#"+tbody)[0].rows[0];
 } else {
  newnode = $("#"+tbody)[0].rows[0].cloneNode(true);
  add = true;
 }
 tags = newnode.getElementsByTagName('input');
 for(i in tags) {
  if(tags[i].name == 'pics[]') {
   tags[i].value = 'http://';
  }
 }
 if(add) {
  $("#"+tbody)[0].appendChild(newnode);
 }
}
 
function delRow(obj, tbody) {
 if($("#"+tbody)[0].rows.length == 1) {
  var trobj = obj.parentNode.parentNode;
  tags = trobj.getElementsByTagName('input');
  for(i in tags) {
   if(tags[i].name == 'pics[]') {
    tags[i].value = 'http://';
   }
  }
  trobj.style.display='none';
 } else {
  $("#"+tbody)[0].removeChild(obj.parentNode.parentNode);
 }
}
function insertWebImg(obj) {
 if(checkImage(obj.value)) {
  insertImage(obj.value);
  obj.value = 'http://';
 } else {
  alert('图片地址不正确');
 }
}
function checkFocus(target) {
 var obj = $("#"+target)[0];
 if(!obj.hasfocus) {
  obj.focus();
 }
}
function insertImage(text) {
 text = "\n[img]" + text + "[/img]\n";
 insertContent('message', text)
}
function insertContent(target, text) {
 var obj = $("#"+target)[0];
 selection = document.selection;
 checkFocus(target);
 if(!isUndefined(obj.selectionStart)) {
  var opn = obj.selectionStart + 0;
  obj.value = obj.value.substr(0, obj.selectionStart) + text + obj.value.substr(obj.selectionEnd);
 } else if(selection && selection.createRange) {
  var sel = selection.createRange();
  sel.text = text;
  sel.moveStart('character', -strlen(text));
 } else {
  obj.value += text;
 }
}
function checkImage(url) {
 var re = /^http\:\/\/.{5,200}\.(jpg|gif|png)$/i
 return url.match(re);
}

function imageonmousemove(evnt)
{
	var photopos = getpos($("#bigImage")[0]);

	if (evnt)
	{
		//nx = (parseInt(evnt.clientX)-photopos2.left) / $("bigImage").width;
		nx = (parseInt(evnt.clientX)-photopos.left) / $("#bigImage")[0].width;
		if(nx>0.5 )
		{
			$("#bigImage")[0].style.cursor = "url("+"/image/right.cur"+"),auto";
			$("#bigImage")[0].title = "点击浏览下一张>>";
		}
		
		if  (nx<=0.5 )
		{
			$("#bigImage")[0].style.cursor = "url("+"/image/left.cur"+"),auto";
			$("#bigImage")[0].title = "<<点击浏览上一张";
		}
	}
}
function imageonclick(evnt)
{
	var photopos = getpos($("#bigImage")[0]);


	if (evnt)
	{
		nx = (parseInt(evnt.clientX)-photopos.left) / $("#bigImage")[0].width;
	}

	if(nx>0.5)
	{
		var href= $("#nextLink")[0].href;
		window.location.href = href;
	}
	
	if (nx<=0.5)
	{
		var href= $("#preLink")[0].href;
		window.location.href = href;
	}
}


//获取元素的位置
function getpos(element)
{
        if ( arguments.length != 1 || element == null )
        {
               return null;
        }
        var elmt = element;
        var offsetTop = elmt.offsetTop;
        var offsetLeft = elmt.offsetLeft;
        var offsetWidth = elmt.offsetWidth;
        var offsetHeight = elmt.offsetHeight;
        while( elmt = elmt.offsetParent )
        {
                // add this judge
                if ( elmt.style.position == 'absolute'
//              || elmt.style.position == 'relative'
                || ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) )
                {
                        break;
                }
                offsetTop += elmt.offsetTop;
                offsetLeft += elmt.offsetLeft;
        }
        return {top:offsetTop, left:offsetLeft, right:offsetWidth+offsetLeft, bottom:offsetHeight+offsetTop };
}