
//add href to img if larger. for welcome and post.
function popupImg(selector, thresholdWidth)
{
    $(document).ready(function()
    {

        $(selector).each(function()
        {
            var img = $(this);
            var width = img.width();
            if (width >= thresholdWidth && img.parent("a").length == 0)
            {
                //href
                img.wrap(String.format('<a href="{0}" title="查看大图" target="_Blank"></a>', img.attr("src")));
                img.attr("title", "查看大图");

                //border
                img.css("border", "1px solid blue");
            }

        });

    });
}



// manage member

function AddUserNameFromFriend()
{
   var userNameObjs = document.getElementsByName("UserName");
   var str = "";
   for ( i = 0; i < userNameObjs.length; i ++  )
   {
      if (userNameObjs[i].checked)
      {
         str += userNameObjs[i].value + "\r\n";
      }

   }
   var textAreaObj = top.window.E("UserNames");
   textAreaObj.value = textAreaObj.value + str;
   top.window.GB_hide();
}


function SelectAll(checkName, checkValue)
{
   var checkObjs = document.getElementsByName(checkName);
   for ( i = 0; i < checkObjs.length; i ++  )
   {
      checkObjs[i].checked = checkValue;
   }


}


// join
function QuitConfirm(formID, info)
{
   var formObj = E(formID);
   formObj.onsubmit = function()
   {
      return confirm(info);
   }
   ;

}





// poll
function AddChoice()
{
   var tgtObj = document.getElementById("choice");
   var str = document.getElementById("cloneSample").innerHTML;
   insertHtml('beforeend', tgtObj, str);
}


// topic and reply
function HideOptionInfo()
{
   E("OptionInfo").style.display = "none";
}

function ShowOptionInfo()
{
   E("OptionInfo").style.display = "";
}

// group option
function HideGroupOptionInfo()
{
   E("GroupOptionInfo").style.display = "none";
}

function ShowGroupOptionInfo()
{
   E("GroupOptionInfo").style.display = "";
}

function Reply(userNickName, contentID)
{
   var oEditor = FCKeditorAPI.GetInstance('inputContent') ;

   // need quote ?
   if (userNickName && contentID)
   {
      // check editor mode
      if (oEditor.EditMode != FCK_EDITMODE_WYSIWYG)
      {
         // oEditor.SwitchEditMode();
         alert('抱歉，不能在源代码模式下引用，请先切换出源代码模式。');
         return;
      }
      oEditor.Focus();


      var htmlStr = document.getElementById(contentID).innerHTML;

      // clear blockquote
      htmlStr = htmlStr.replace(/<blockquote[\s\S]+<\/blockquote *>/ig, '');

      // get simple text
      var textStr = htmlStr.replace(/<\/?[^>]+>/g, '');

      // build str
      htmlStr = '<blockquote>';
      htmlStr += '<strong>' + userNickName + '</strong> - 在上文提到：<br />';
      htmlStr += textStr;
      htmlStr += '</blockquote>';

      oEditor.EditorDocument.body.innerHTML = htmlStr;

   }


   window.location.hash = "ReplyAnchor";
   oEditor.Focus();

}



// end of topic and reply


// theme
function SetTheme(themeID, themeName, themeIcon)
{
   E("ThemeID").value = themeID;
   E("ThemeName").innerHTML = themeName;
   E("ThemeIcon").src = themeIcon;
   GB_hide();
}

// upload icon
function OnFileChange()
{
   var form = document.getElementById("form_upload");
   form.submit();
}

function onUploadFail(msg)
{
   alert(msg);
}

function onUploadOk(ImgUrl)
{

   // clear file input
   document.getElementById("input_file").outerHTML = document.getElementById("input_file").outerHTML;
   // open cut window
   // alert(ImgUrl);

   var CutUrl = "http://fileService.100e.com/tool/img/Cut/" + "?ImgUrl=" + ImgUrl + "&w=48&h=48";

   // use greybox
   GB_showFullScreen('裁剪图片', CutUrl);
}



function onImgCutOk(ImgUrl)
{
   // show img
   var img = document.getElementById("img_cut");
   img.src = ImgUrl + "?1=1";
   img.style.display = "";
   // set ImgUrl to hiddend value
   document.getElementById("input_ImgUrl").value = ImgUrl;
   // document.getElementById("input_submit").disabled = "";


}
// end


function CountChars()
{
   var b = document.getElementById("inputDesc");
   var c = document.getElementById("remainingChars");
   var a = 120 - b.value.length;
   if(a >= 0)
   {
      c.innerHTML = a
   }
   else
   {
      c.innerHTML = "<font color=red>" + ( - a + "") + " characters over</font>"
   }
}
