// Show/Hide Sidebar
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){}
}

// Show/Hide Login Panel
function showLogin(){
  try{
    var panel=document.getElementById("panelUser");
    if(panel){
      if(panel.style.display=='none'){
        panel.style.display='block';
      }else{
        panel.style.display='none';
      }
    }else{
      document.location="login.asp";
    }
  }catch(e){}
}

// Dynamic write object tag - SiC/CYAN 2004-2005
function ubbShowObj(strType,strID,strURL,intWidth,intHeight)
{
	var objPrefix="bShow";
	var tmpstr="";
	var bSwitch = false;
	//Reverse the State
	bSwitch = document.getElementById(objPrefix+strID).value;
	bSwitch	=~bSwitch;
	document.getElementById(objPrefix+strID).value = bSwitch;
	if(bSwitch){
		//Code for already shown
		document.getElementById(strID).innerHTML = "<a href=\""+strURL+'" target="_blank">'+strURL+"</a>";
	}else{
		//Code for not shown
		switch(strType){
			case "swf":
				tmpstr=strURL+'<br /><object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+intWidth+'" height="'+intHeight+'"><param name="movie" value="'+strURL+'" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="'+strURL+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+intWidth+'" height="'+intHeight+'" /></object>';
				break;
			case "wmp":
				tmpstr=strURL+'<br /><object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" type="application/x-oleobject" standby="Loading..." width="'+intWidth+'" height="'+intHeight+'"><param name="FileName" VALUE="'+strURL+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="'+strURL+'" autostart="true" width="'+intWidth+'" height="'+intHeight+'" /></object>';
				break;
			case "rm":
				tmpstr=strURL+'<br /><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="'+intHeight+'"><param name="SRC" value="'+strURL+'" /><param name="CONTROLS" VALUE="ImageWindow" /><param name="CONSOLE" value="one" /><param name="AUTOSTART" value="true" /><embed src="'+strURL+'" nojava="true" controls="ImageWindow" console="one" width="'+intWidth+'" height="'+intHeight+'"></object>'+
        '<br /><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="32" /><param name="CONTROLS" value="StatusBar" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+strURL+'" nojava="true" controls="StatusBar" console="one" width="'+intWidth+'" height="24" /></object>'+'<br /><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="32" /><param name="CONTROLS" value="ControlPanel" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+strURL+'" nojava="true" controls="ControlPanel" console="one" width="'+intWidth+'" height="24" autostart="true" loop="false" /></object>';
				break;
			case "qt":
				tmpstr=strURL+'<br /><embed src="'+strURL+'" autoplay="true" loop="false" controller="true" playeveryframe="false" cache="false" scale="TOFIT" bgcolor="#000000" kioskmode="false" targetcache="false" pluginspage="http://www.apple.com/quicktime/" />';
		}
		document.getElementById(strID).innerHTML = tmpstr;
	}
}

// Quote Comment Text - SiC/CYAN 2004-2005
function doQuote(objID,strAuthor){
  var obj=document.getElementById(objID);
  var text=obj.innerHTML;
  text=text.replace(/alt\=(\"|)([^\"\s]*)(\"|)/g,"> $2 <");
  text=text.replace(/\<[^\<\>]+\>/g,"\n");
  text=text.replace(/ +/g," ");
  text=text.replace(/\n+/g,"\n");
  text=text.replace(/^\n*/gm,"");
  text=text.replace(/^\s*/gm,"");
  text=text.replace(/\n*$/gm,"");
  text=text.replace(/\s*$/gm,"");
	document.inputform.message.value += "[quote="+strAuthor+"]\n"+text+"\n[/quote]\n";
	window.location.hash="commentbox";
}

// Show/Hide Comments & Trackback - SiC/CYAN 2005
function toggleComments(bShowComment,bShowTrackback){
  var objs=document.getElementById("commentWrapper");
  objs=objs.getElementsByTagName("div");
  for(var i=0;i<objs.length;i++){
    if(objs[i].id.indexOf("comment")>-1&&objs[i].id!="commentTop"){
      if(bShowComment){
        objs[i].style.display="block";
      }else{
        objs[i].style.display="none";
      }
    }
    if(objs[i].id.indexOf("trackback")>-1&&objs[i].id!="commentTop"){
      if(bShowTrackback){
        objs[i].style.display="block";
      }else{
        objs[i].style.display="none";
      }
    }
  }
}

// Toggle Comments & Trackback Order
var bOrder=true;
function toggleOrder(){
  var obj=document.getElementById("commentWrapper");
  // I want to use outerHTML but that stupid fox does not support it
  var objtopHTML='<div id="commentTop" class="comment-top">\n'+document.getElementById("commentTop").innerHTML+'</div>\n';
  var objs=obj.getElementsByTagName("div");
  var tmpArray=new Array();
  for(var i=0;i<objs.length;i++){
    if((objs[i].id.indexOf("comment")>-1||objs[i].id.indexOf("trackback")>-1)&&objs[i].id!="commentTop"){
      tmpArray[i]='<div id="'+objs[i].id+'" class="'+objs[i].className+'">\n'+objs[i].innerHTML+'</div>\n';
    }
  }
  tmpArray.reverse();
  obj.innerHTML=objtopHTML+tmpArray.join("\n");
  delete tmpArray;
}

// Search - SiC/CYAN 2004-2005
function doSearch(){
  var form=document.getElementById("searchForm");
  if(lengthW(form.q.value)<3){
    alert("Keyword length must greater than 3 chars.");
    return false;
  }
  switch(form.searchType.value){
    case "comments":
      form.action="comment.asp";
      return true;
      break;
    case "guestbook":
      form.action="gbook.asp";
      return true;
    case "trackbacks":
      form.action="trackback.asp?act=list";
      return true;
    default:
      form.action="default.asp";
      return true;
      break;
  }
}

// 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){}
}

// ideatelier's Navigator

var enabletabpersistence=1 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("a")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
}
} //end outer for loop
}


function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}
