var q = "" + this.location;
var this_location = q.slice(0, q.lastIndexOf("/")+1);
var blogliatloc = "loadblog.asp";
var resq = blogliatloc;
var isIE = (navigator.userAgent.indexOf('MSIE') != -1) ? true : false;
var isFF = (navigator.userAgent.indexOf('Firefox') != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf('Opera') != -1) ? true : false;
var NeedResize = true;

function PageInit() {
  resize_mainframe_height();
  setpanel(document.getElementById("defpanel").value);
  window.onresize = resize_mainframe_height;
  if ((isFF||isOpera)&&document.getElementById("disallowstatus").value=="y") document.onmousedown = function() {return false;}
}

function UpdateSubtitleNDes() {
  document.getElementById("little_title").innerHTML = document.getElementById("subtitletmp").value;
  document.getElementById("b_des").innerHTML = document.getElementById("blogdes").value;
}
  
function UpdateReader() {
  fw = pageWidth() - 350;
  changecss('#facebox .body','width', fw + 'px');
  if (isIE) {
    document.getElementById("b_content").style.height = pageHeight() - 70;
  } else {
    document.getElementById("b_content").style.height = pageHeight() - 90;
  }
  if (fw>700) {
    document.getElementById("b_content").style.width = fw;
  } else {
    document.getElementById("b_content").style.width = 700;
  }
}

function AdjustCloseButton() {
  acb = parseFloat(GetCssVal("#facebox_close_btn","width"));
  document.getElementById("facebox_close_btn").style.left = findPosX(document.getElementById("trpos")) - acb/2;
  document.getElementById("facebox_close_btn").style.display = "block";
}
  
function Bookmark() {
bookmarkurl = thislink;
bookmarktitle = document.getElementById("pagetitle").value;
if (isIE) {
  window.external.AddFavorite(bookmarkurl,bookmarktitle)
} else {
  prompt("Please press Ctrl+D on your keyboard to bookmark this page.\n\nMy URL is:", bookmarkurl);
}
}

function GotoCate(cid) {
  document.title = document.getElementById("pagetitle").value;
  if (FBopened) jQuery.facebox.close();
  jah(blogliatloc + "?listonly=true&view=category&cate=" + cid, "BlogArticleList", "UpdateSubtitleNDes()");
}

function GoHome() {
  document.title = document.getElementById("pagetitle").value;
  if (FBopened) jQuery.facebox.close();
  jah(blogliatloc + "?listonly=true", "BlogArticleList", "UpdateSubtitleNDes()");
}

function GotoArchives(gmonth, gyear) {
  document.title = document.getElementById("pagetitle").value;
  if (FBopened) jQuery.facebox.close();
  jah(blogliatloc + "?listonly=true&view=archives&month=" + gmonth + "&year=" + gyear, "BlogArticleList", "UpdateSubtitleNDes()");
}

function GoToPage(i) {
  tolnk = blogliatloc + document.getElementById("CurrentPage").value;
  if (tolnk.indexOf("&page")>0) tolnk = tolnk.slice(0, tolnk.indexOf("&page"));
  tolnk = tolnk + "&page=" + i;
  jah(tolnk, "BlogArticleList", "UpdateSubtitleNDes()");
}

function GotoArticle(bref) {
  if (bref==null) bref='';
  if (bref!='') bref='?'+bref;
  jQuery(document).unbind('keydown.facebox');
  LoadFB('blog.asp'+bref, 'UpdateReader();');
}

function GotoAboutme() {
  LoadFB("aboutme.asp");
  changecss("#facebox .body","width", "700px");
  NeedResize = false;
}

var rssl;
function GotoRSS() {
  rssl = this_location + "rss.asp";
  document.getElementById('rsslink').innerHTML = rssl;
  jQuery.facebox(document.getElementById('rss_dialog').innerHTML);
  changecss('#facebox .body','width', '700px');
  document.getElementById('fade').style.display='block';
  AdjustCloseButton();
  NeedResize = false;
}

function GoToAdmin() {
  if (!isIE) {
    jQuery.facebox(document.getElementById('login_dialog').innerHTML);
    changecss('#facebox .body','width', '700px');
    document.getElementById('fade').style.display='block';
    AdjustCloseButton();
    NeedResize = false;
  } else {
    location.href = '../blog_admin/'
  }
}

function RSSLinkGet(t) {
  if (t.innerHTML==rssl) t.innerHTML = '<input type="text" value="'+rssl+'" style="width:100%;font-size:10pt;border:none;" onclick="this.select()" readonly>';
}

function ScrollToComments() {
  if (!isIE) {
  con = document.getElementById("b_content");
  bcoh = Number(document.getElementById("b_comments").offsetHeight);
  conheight = con.style.height.slice(0,con.style.height.length-2);
  contenth = con.scrollTop + Number(conheight);
  con.scrollTop += 80;
  if (contenth < con.scrollHeight-bcoh+360) {scrolldelay = setTimeout("ScrollToComments()",10);} 
  else {document.body.style.cursor = 'auto';}
  } else {
    location.href = "#comments";
  }
}

function ScrollToComments2(id) {
  if (!isIE) document.body.style.cursor = 'wait';
  if (document.getElementById('b_comments_status').value=='n') document.getElementById('comment_loading').style.display = 'block';
  ShowComments(id, 'ScrollToComments();');
}

function ScrollToTop() {
  if (!isIE) {
  document.body.style.cursor = 'wait';
  con = document.getElementById("b_content");
  con.scrollTop -= 80;
  if (con.scrollTop > 10) {scrolldelay = setTimeout("ScrollToTop()",10);} 
  else {document.body.style.cursor = 'auto';}
  } else {
    location.href = "#top";
  }
}

function ShowComments(id, r) {
  if (r==null) r='';
  if (document.getElementById('b_comments_status').value=='n') {
    jah('get_comment.asp?id='+id, 'b_comments', 'ShowComments2();'+r, true);
    document.getElementById('b_comments_status').value = 'y';
  } else {
    if (r.length!=0) eval(r);
  }
}

function ShowComments2() {
  document.getElementById('comment_loading').style.display = 'none';
  OnCloseFunction='ForBlogClose(); CommentSav=""; DrawSav="";';
  DrawCommentGet();
  if (isIE) location.href = '#comments';
}

function ScrollCommentsAction(id, con) {
  conheight = con.style.height.slice(0,con.style.height.length-2);
  contenth = con.scrollTop + Number(conheight);
  if (contenth>=con.scrollHeight-30) ShowComments(id);
}

function ShowShareMenu(t) {
  sharem = document.getElementById('sharemenu');
  if (t) {
    sharem.style.display='block';
    if (!isIE) sharem.style.left = mouseX - 50
    else sharem.style.left = mouseX - 200;
    if (!isIE) sharem.style.top = mouseY - 30
    else sharem.style.top = mouseY - 40;
  } else {
    if (sharem.style.display!='none') sharem.style.display='none';
  }
}

function ShareTo(u, t, w) {
  winsetting = "width=750,height=550,menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes";
  u = encodeURIComponent(u);
  t = encodeURIComponent(t);
  switch (w) {
    case "facebook":
      window.open('http://www.facebook.com/sharer.php?u='+u+'&t='+t,'sharer',winsetting);
      break;
    case "twitter":
      window.open('http://twitter.com/home?status='+t+' - '+u,'sharer',winsetting);
      break;
    case "myspace":
      window.open('http://www.myspace.com/Modules/PostTo/Pages/?u='+u+'&t='+t,'sharer',winsetting);
      break;
    case "plurk":
      window.open('http://www.plurk.com/?qualifier=shares&status='+t+' - '+u,'sharer',winsetting);
      break;
    case "xanga":
      window.open('http://www.xanga.com/private/editorplain.aspx?t='+t+'&u='+u,'sharer',winsetting);
      break;
    case "hotmail":
      window.open('http://www.addtoany.com/add_to/hotmail?linkurl='+u+'&linkname='+t,'sharer',winsetting);
      break;
    case "gmail":
      window.open('http://www.addtoany.com/add_to/google_gmail?linkurl='+u+'&linkname='+t,'sharer',winsetting);
      break;
    case "ymail":
      window.open('http://www.addtoany.com/add_to/yahoo_mail?linkurl='+u+'&linkname='+t,'sharer',winsetting);
      break;
    case "email":
      window.open('http://www.addtoany.com/email?linkurl='+u+'&linkname='+t,'sharer',winsetting);
      break;
    case "outlook":
      emt = false;
      while (!emt) {
        em = prompt('Please enter the email address of the recipient:');
        if (em==null) em = '';
        if ((em.length!=0 && (em.indexOf("@")>0 || em.indexOf(".")>0))||em.length==0) {
          window.open('mailto:'+em+'?subject='+t+'&body='+u,'sharer',winsetting);
          if (!isIE) window.open('javascript:self.close()','sharer',winsetting);
          emt = true;
        } else {alert('Invalid email address, please enter again!');}
      }
      break;
  }
}

function SelectNDragControl(tf) {
  if (document.getElementById("disallowstatus").value=="y") {
  if (tf) {
    document.onselectstart = function() {return true;}
    document.ondragstart = function() {return true;}
    if (isFF) document.onmousedown = "";
    if (isOpera) document.onmousedown = function() {return true;}
  } else {
    document.onselectstart = function() {return false;}
    document.ondragstart = function() {return false;}
    if (isFF||isOpera) document.onmousedown = function() {return false;}
  } }
}

function LoadFB(lnk, run) {
    NeedResize = true;
    AllowEsc = false;
    if (lnk.indexOf("?")>0) {
      lnk = lnk + '&random=' + Math.random();
    } else {
      lnk = lnk + '?random=' + Math.random();
    }
    if (run==null) run='';
  document.getElementById('fade').style.display='block';
  OnCloseFunction = '';
  jQuery.facebox(function() {jQuery.get(lnk, function(data) { jQuery.facebox.reveal(data, "", run+"AdjustCloseButton();AllowEsc = true;");})});
}

function resize_mainframe_height() {
  reserved_s = document.getElementById("reserved_space").offsetHeight;
  mainframewidth = document.getElementById("mainframe_content").offsetWidth - 40;
  document.getElementById("mainframe_bg").style.height = pageHeight() - reserved_s - 40;
  document.getElementById("mainframe_content").style.height = pageHeight() - reserved_s - 40;
  if (isIE) {
    document.getElementById("BlogArticleList").style.height =  "100%";
    document.getElementById("SideBarList").style.height = "100%";
    sch = pageHeight() - reserved_s - (220 + parseFloat(GetCssVal(".sidebar_headers","height"))*(parseFloat(document.getElementById("noofpanels").value)+2));
    changecss(".switchcontent","height", sch + "px");
  } else {
    document.getElementById("BlogArticleList").style.height =  pageHeight() - reserved_s - 130;
    document.getElementById("BlogArticleList").style.width = mainframewidth - 200;
    document.getElementById("SideBarList").style.height = pageHeight() - reserved_s - parseFloat(GetCssVal(".sidebar_myhead","height"));
    document.getElementById("SideBarList").style.width = 200 - 12;
    if (isFF) sch = pageHeight() - reserved_s - (225 + (parseFloat(GetCssVal(".sidebar_headers","height"))+2)*(parseFloat(document.getElementById("noofpanels").value)+2))
    else sch = pageHeight() - reserved_s - (225 + parseFloat(GetCssVal(".sidebar_headers","height"))*(parseFloat(document.getElementById("noofpanels").value)+2));
    changecss(".switchcontent","height", sch + "px");
  }
  if (FBopened && NeedResize) UpdateReader();
  if (FBopened && document.getElementById("facebox_close_btn").style.display!="none") AdjustCloseButton();
}

function ForBlogClose() {
  if (document.new_comment.main.value.length!=0 || document.new_comment.drawval.value.length!=0) {
    fbcc = confirm("Your comment hasn't finished yet.\nAre you sure to leave it out?\n\n(Note: You comment has NOT saved.)")
    if (!fbcc) {document.new_comment.main.focus(); stopclosing=true;}
  }
}

var CommentSav;
var DrawSav;
function CommentSubmit() {
  if (document.new_comment.drawstatus.value=="y") DrawCommentSav();
  var formObj = new DHTMLSuite.form({ formRef:"new_comment",action:"add_comment.asp",responseEl:"formResult"});
  if (document.new_comment.name.value.length==0 || document.new_comment.strCAPTCHA.value.length==0) {
    alert("Please finish all the required fields first!");
    document.new_comment.name.focus();
  } else if (document.new_comment.main.value.length==0 && document.new_comment.drawval.value.length==0) {
    alert("Please enter your comment before submit!");
    if (document.getElementById("writecomment").style.display!="none") document.new_comment.main.focus();
  } else if (document.new_comment.email.value.length!=0 && (document.new_comment.email.value.indexOf("@")<=0 || document.new_comment.email.value.indexOf(".")<=0)) {
    alert("The email address is invalid, please enter again!");
    document.new_comment.email.select();
  } else {
  document.getElementById("formResponse2").innerHTML = "<img border='0' src='progressbar.gif'>";
  document.getElementById("facebox_close_btn").style.display = "none";
  submitExe = "SubmittedFunction()";
  setCookie("visitorName",document.new_comment.name.value,30);
  setCookie("visitorEmail",document.new_comment.email.value,30);
  AllowEsc = false;
  CommentSav = document.new_comment.main.value;
  DrawSav = document.new_comment.drawval.value;
  formObj.submit();
  }
}

function SubmittedFunction() {
  UnlockReader();
  document.getElementById('userRespond').focus();
  gcid = document.new_comment.bid.value;
  if (document.getElementById('add_comment_ok').value=='y') {
    OnCloseFunction = 'ForBlogClose(); if (!stopclosing) AfterSubmitted();';
    jah('get_comment.asp?commentonly=y&id='+gcid, 'comment_show', 'DrawCommentGet()');
    document.new_comment.B2.click();
  } else if (document.getElementById('add_comment_ok').value=='ya') {document.new_comment.B2.click();}
  if (document.getElementById('add_comment_ok').value!='n') {
    cc = parseFloat(document.getElementById('commentcnt').value);
    cc += 1;
    document.getElementById('commentcnt').value = cc;
  }
}

function DrawCommentSav() {
  var ifrm = document.getElementById('pboard');
  ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
  el = ifrm.document.getElementById('pntboard');
  ch = el.offsetHeight;
  cw = el.offsetWidth;
  pdata = el.innerHTML;
  pdata2 = ""; separate = "</div>"; f=1; r=0; c=0; tmp="";
  pdata = pdata.toLowerCase();
  pdata = pdata.slice(pdata.indexOf('<div style="position:'), pdata.length-separate.length);
  for (i=0;i<pdata.length;i++) {
    cha = pdata.slice(i, i+separate.length);r++;
    if (cha==separate||i==pdata.length) {
      if (i==pdata.length) r++;
      pickval = pdata.slice(f, f+r-1);
      c = c + 1; r = 0;
      f = i + separate.length;

      pixleft = pickval.slice(pickval.indexOf("left:")+5, pickval.length);
      pixleft = pixleft.slice(0, pixleft.indexOf("px"));
      pixtop = pickval.slice(pickval.indexOf("top:")+4, pickval.length);
      pixtop = pixtop.slice(0, pixtop.indexOf("px"));
      pixwidth = pickval.slice(pickval.indexOf("width:")+6, pickval.length);
      pixwidth = pixwidth.slice(0, pixwidth.indexOf("px"));
      pixheight = pickval.slice(pickval.indexOf("height:")+7, pickval.length);
      pixheight = pixheight.slice(0, pixheight.indexOf("px"));
      pixcolor = pickval.slice(pickval.indexOf("color:")+6,  pickval.length);
      pixcolor = pixcolor.slice(0, pixcolor.indexOf(";"));
      if (pixtop<=ch && pixleft<=cw) {
        pdata2 += pixleft + ',' + pixtop + ',' + pixwidth + ',' + pixheight + ',/' + pixcolor + '/,';
      }
    }
  }
  pdata2 = pdata2.slice(0, pdata2.length-1);
  document.new_comment.drawval.value = pdata2;
  pdata = ""; pdata2 = "";
}

function DecodeDrawComment(v) {
  var DCoutput = "";
  DComment = v.replace(/\//ig,"\"");
  eval("var DCtmp = ["+DComment+"];");
  for (i=0;i<DCtmp.length;i++) {
    if (i%5==0) DCoutput += "<div class='jsgraph' style='position:absolute;left:" + DCtmp[i] + ";top:" + DCtmp[i+1] + ";width:" + DCtmp[i+2] + ";height:" + DCtmp[i+3] + ";clip:rect(0," + DCtmp[i+2] + "," + DCtmp[i+3] + ",0);border-color:" + DCtmp[i+4] + ";background-color:" + DCtmp[i+4] + ";overflow:hidden;'></div>";
  }
  DCoutput = "<div style='font-size:0px;position:relative;width:100%;height:180px;'>" + DCoutput + "</div>";
  return DCoutput;
  DCoutput = ""; DComment = "";
}

function DrawCommentGet() {
  dcptotal2 = document.getElementById("dcptotal").value;
  var i=0;
  while (i<dcptotal2) {
    eval("document.getElementById('dcpdiv"+i+"').innerHTML = DecodeDrawComment(document.getElementById('dcp"+i+"').value)");
    i++;
  }
}

function CommentTab(t) {
  t1 = document.getElementById("tabb1");
  t2 = document.getElementById("tabb2");
  if (t=="tabb1") {
    t1.style.backgroundColor = "Highlight";
    t1.style.color = "HighlightText";
    t1.style.fontWeight = "bold";
    t2.style.backgroundColor = "transparent";
    t2.style.color = "ButtonText";
    t2.style.fontWeight = "normal";
    document.getElementById('writecomment').style.display = "block";
    document.getElementById('drawcomment').style.display = "none";
  } else {
    t2.style.backgroundColor = "Highlight";
    t2.style.color = "HighlightText";
    t2.style.fontWeight = "bold";
    t1.style.backgroundColor = "transparent";
    t1.style.color = "ButtonText";
    t1.style.fontWeight = "normal";
    document.getElementById('writecomment').style.display = "none";
    document.getElementById('drawcomment').style.display = "block";
  }
}

function UnlockReader() {
  AdjustCloseButton();
  document.new_comment.main.value = CommentSav;
  AllowEsc = true;
  if (DrawSav.length>0) {
    var ifrm = document.getElementById("pboard");
    ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;    
    ifrm.document.open();
    ifrm.document.write("<div style='position:absolute;top:0;left:0;z-index:500;'><center><DIV style='background: #F5CF0A url(images/BG_yellow.png) repeat-x;border:1px solid #666; width:300px; height:180px;' class='comment_stickyM'>");
    ifrm.document.write(DecodeDrawComment(DrawSav) + "</div><br><INPUT type='button' value='Clear' onclick='parent.UnlockReaderClearPaint()' style='cursor:pointer;'></center></div>");
    ifrm.document.close();
    document.new_comment.drawstatus.value = "yo"
    document.new_comment.drawval.value = DrawSav;
  }
}

function UnlockReaderClearPaint() {
  document.getElementById('pboard').src = "js_paint.htm";
  document.new_comment.drawval.value="";
  document.new_comment.drawstatus.value = "y"
}

function AfterSubmitted() {
  CommentSav = "";
  DrawSav = "";
  OnCloseFunction = "";
  jahloaded = false;
  tolnk = blogliatloc + document.getElementById("CurrentPage").value;
  jah(tolnk, "BlogArticleList", "UpdateSubtitleNDes()");
}

function CharCount(f, max) {
  tcnt = max - f.value.length;
  if (tcnt<0) tcnt=0;
  document.new_comment.char_remain.value = tcnt;
  if (f.value.length>max) f.value = f.value.slice(0, max);
}

function CommentFormReset(captcha, tcnt) {
  document.new_comment.strCAPTCHA.value=captcha;
  document.new_comment.char_remain.value=tcnt;
  document.new_comment.main.value='';
  document.new_comment.name.value='';
  document.new_comment.email.value='';
  document.new_comment.drawval.value='';
  if (document.new_comment.drawstatus.value=="yo") document.new_comment.drawstatus.value = "y";
  if (document.new_comment.drawstatus.value=="y") document.getElementById('pboard').src = "js_paint.htm";
}

function getCommentInput() {
cname = getCookie("visitorName");
if (cname!=null && cname!="") document.new_comment.name.value = cname;
cemail = getCookie("visitorEmail");
if (cemail!=null && cemail!="") document.new_comment.email.value = cemail;
cmain = getCookie("visitorComment");
if (cmain!=null && cmain!="") document.new_comment.main.value = cmain;
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 ;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return ""
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
}

function deleteCookie(cookie_name)
{
  var cookie_date = new Date ();  // current date & time
  cookie_date.setTime(cookie_date.getTime()-1);
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

 function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function GetCssVal(theClass,element) {
 var cssRules;
 if (document.all) {
   cssRules = 'rules';
 } else if (document.getElementById) {
   cssRules = 'cssRules';
 }
 for (var S = 0; S < document.styleSheets.length; S++){
  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
    if(document.styleSheets[S][cssRules][R].style[element]){
    return document.styleSheets[S][cssRules][R].style[element];
	break;
    }
   }
  }
 }
 return null;
}
