// JavaScript Document
function dialog(title, content, modal){
	return new Boxy("<span>" + content + "</span><a href='javascript://' onclick='Boxy.get(this).hide(); return false'>[关闭]</a>", {"title": title, "modal": ( modal == undefined  && modal != false ) ? true : false, "closeText": false });
//	Boxy.alert(content);
}

if("undefined" == typeof getCookie){
	function getCookie(name){
		var sRE = "(?:; )?" + name + "=([^;]*);?";
		var oRE = new RegExp(sRE);
		if(oRE.test(document.cookie)){
			return decodeURIComponent(RegExp.$1);
		}else{
			return null;
		}
	}

	function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure){
		var sCookie = sName + "=" + encodeURIComponent(sValue);
		if(oExpires)
			sCookie += "; expires=" + oExpires.toGMTString();
		if(sPath)
			sCookie += "; path=" + sPath;
		if(sDomain)
			sCookie += "; domain=" + sDomain;
		if(bSecure)
			sCookie += "; secure";
		document.cookie = sCookie;
	}
}

//控制如数字数
function CheckInputWordCount(obj,smsLength)
{
	//检查字数
	var needAlert = 1;
	var word = obj.value;
	//var num  = word.length;
	var num  = getLen(word);
	if (num > smsLength)
	{
		 //去掉该汉字
		 //obj.value = obj.value.substring(0,smsLength);
		 obj.value = subString(obj.value,smsLength);
		 if (needAlert == 1)
		 {
			//对象失去焦点，同时弹出
			obj.blur();
			alert("您最多只能输入"+smsLength+"个字符或者"+smsLength/2+"个汉字！");
		 }
	}
}
//获取字符串的长度（中文或英文）
function getLen(sString)
{
    var sStr,iCount,i,strTemp ; 

    iCount = 0 ;
    sStr = sString.split("");
    for (i = 0 ; i < sStr.length ; i ++)
    {
         strTemp = escape(sStr[i]);
         if (strTemp.indexOf("%u",0) == -1)
         {
              iCount = iCount + 1 ;
         }
         else
         {
              iCount = iCount + 2 ;
         }
     }
     return iCount ;
} 
//截取字符串函数
function subString(str, len, hasDot) 
{ 
    var newLength = 0; 
    var newStr = ""; 
    var chineseRegex = /[^\x00-\xff]/g; 
    var singleChar = ""; 
    var strLength = str.replace(chineseRegex,"**").length; 
    for(var i = 0;i < strLength;i++) 
    { 
        singleChar = str.charAt(i).toString(); 
        if(singleChar.match(chineseRegex) != null) 
        { 
            newLength += 2; 
        }     
        else 
        { 
            newLength++; 
        } 
        if(newLength > len) 
        { 
            break; 
        } 
        newStr += singleChar; 
    } 
     
    if(hasDot && strLength > len) 
    { 
        newStr += "..."; 
    } 
    return newStr; 
} 

var TagTools = {
  checkTags: function(s) {
    return /^\s*[a-zA-Z\d\u4e00-\u9fa5\s]+\s*$/gi.test(s);
  },
  checkTag: function(s) {
    return /^\s*[a-zA-Z\d\u4e00-\u9fa5]+\s*$/gi.test(s);
  },
  tags2str: function(tags) {
    return tags.join(" ");
  },
  str2tags: function(s) {
    return s.replace(/^\s+|\s+$/g, "").split(/\s+/);
  }
}

function copy_page_url(txt){
	var e = txt;//window.location.href;
	if( window.clipboardData && clipboardData.setData ){
		clipboardData.setData("Text", e);
		ShowDialog('复制地址', '地址已经拷贝到您的剪贴板中。');
	}
	else
	{
		ShowDialog('复制地址', '本功能需要IE浏览器支持。');
	}
}
//收藏
function addfavorite(slink,stitle){
   if(document.all){
      window.external.addFavorite(slink,stitle);
   }else if(window.sidebar){
      window.sidebar.addPanel(stitle,slink,'');
   }
}

function ShowDialog(title, message, callback){
	$('#dialog-common').attr({"title": title});
	$('#dialog-common p#message').text(message);
	$('#dialog-common').dialog({
		bgiframe: false,
//		height: auto,
		modal: true,
		buttons: {
			'确定': function(evt) {
				$(this).dialog('destroy');
				if(callback){
					callback();
				}
				evt.preventDefault();
			}					
		},
		close: function(event, ui) {
			$(this).dialog('destroy');
			event.preventDefault();
		}
	});
}

function GetAlbumPage(userID, albumID){
	return 'http://' + domain + '/album/' + userID + '/' + albumID + '.html';	
}

function GetPicPage(userID, imageID){
	return 'http://' + domain + '/picture/' + userID + '/' + imageID + '.html';
}