// Show/Hide Sidebar
//alert("Debug！");

function trim(str){
   return str.replace(/(^\s*)|(\s*$)/g, "");
}

function showHideSidebar(){
  try{
    var objSidebar=document.getElementById("sidebar");
    var objContent=document.getElementById("content");
    if(objSidebar.className!="sidebar-hide"){
      objSidebar.className="sidebar-hide";
      objSidebar.style.display="none";
      objContent.className="content-wide";
    }else{
      objSidebar.className="sidebar";
      objSidebar.style.display="block";
      objContent.className="content";
    }
  }catch(e){}
}

// Search
function doBlogSearch(){
  var form=document.getElementById("searchForm");
  if(form.keys.value.length < 1){
   showMessage("请输入关键字!");
    return false;
  }
  switch(form.searchType.value){
    case "Title":
      form.action="/Blog/Search.aspx?Title="+form.keys.value;
      return true;
      break;
    case "Nickname":
	  form.action="/Blog/Search.aspx?Nickname="+form.keys.value;
      return true;
    case "Tag":
      form.action="/Blog/Search.aspx?Tag="+form.keys.value;
      return true;
    default:
      form.action="/Blog/Default.aspx";
      return true;
      break;
  }
}

//load verifyCode
function loadVerifyCode(idName)
{
    try
   {
        var picCode = document.getElementById(idName);
        picCode.innerHTML = "<img src='/ValidCode.aspx?t="+Math.random()+"' alt='点击图片刷新验证码'  width='60' height='24' />";
        
   } catch(e){}
   
}

// Show/Hide Login Panel
function showLogin(){
  try{
    var panel=document.getElementById("loginPanel");
    if(panel){
      if(panel.style.display=='none'){
        panel.style.display='block';
      }else{
        panel.style.display='none';
      }
    }else{
      document.location="/User/Login.aspx";
    }
  }catch(e){}
}


// String Length with unicode support
function lengthW(str){
  if(str==undefined){ return 0; }
  str=String(str);
  var tLen=0;
  for(var i=0;i<str.length;i++){
    charCode=str.charCodeAt(i);
    if(charCode<0||charCode>255){ tLen+=2 }else{ tLen++ }
  }
  return tLen;
}


// Set Article Font Size
function setFontSize(pt){
  try{
    var t=document.getElementById("textboxContent");
    if(t){
      t.style.fontSize=pt+"pt";
    }
  }catch(e){}
}



function showMessage(str)
{
    try
    {
        alert("提示信息：\n--------------------------------------------------\n\n"+str+"\n\n\n\n　　　　　　　　　　　Power by:cszi.com\n");
    }catch(e){}
    
}


function autoGo(sec,url)
{
    try
   { 
        //setTimeout("location.replace("+url+");",sec)
        setTimeout("location.href= '"+url+"';",sec*1000);
   } catch(e){}
}

// Post Comment -Atwind 2008-1-12
function loginMyBlog(frm,isVerify)
{
    try
    {
        frm.btnSubmit_login.disabled = true;
       var userName = frm.UserName.value;
       var userPass = frm.Password.value;
       if(userName == "" || userPass == "" )
       {
            showMessage("1. 请输入用户名和密码后再登录。");
            frm.UserName.focus();
            frm.btnSubmit_login.disabled = false;
            return false;
       }          
       return true; 
   }catch(e){return false;}
   
  
}


//显示隐藏块
function blockShow(e,id){
	 e.className=(e.className=="btnC")?"btnE":"btnC"
	 document.getElementById(id).style.display=(e.className=="btnC")?"":"none"
	 ReImgSize()
}

//查找网页内宽度太大的图片进行缩放以及PNG纠正
function ReImgSize(){
  for (i=0;i<document.images.length;i++)
   {
   if (document.all){
	if (document.images[i].width>400)
	 {
       document.images[i].width="400"
       try{
	       document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
  	 	}catch(e){}
  	 }
   }
  else{
	if (document.images[i].width>400) {
	  document.images[i].title="在新窗口打开图片"
	  document.images[i].style.cursor="pointer"
	  document.images[i].onclick=function(e){window.open(this.src)}
	}
  }
  }
}