/******

last mod june 13 06 - added toolbars for comments in 1-entry view, force anon name

******/

//alert(1)


if(parent){ // might have been called from pswin editing in fast_folders
    if (parent.editorTalkback) parent.editorTalkback(0, document, '')
}


var styleSheetCredits = new Array();
var defaultCSS = 'ibloglike'
var g_currentStyle = 'ibloglike'
var g_defaultSideBarDisplay = 'block'

var g_firstToggleDisplay = g_defaultSideBarDisplay == 'none' ?  'block' :  'none';

styleSheetCredits['ibloglike'] = ' stylesheet is derived from the <a href="http://webreakstuff.com/blog" title="go to the WeBreakStuff Blog" target="_blank">WeBreakStuff Blog</a> CSS, by Frederico Oliveira, customised by Mike Malloch';

var mtcredit =  ' stylesheet is a <a href="http://www.movabletype.org/default_styles.shtml" title="go to the Movable Type default styles page" target="_blank">Movable Type default</a> stylesheet';

styleSheetCredits['clean'] = mtcredit
styleSheetCredits['rusty'] = mtcredit
styleSheetCredits['stormy'] = mtcredit
styleSheetCredits['plain-jane'] = mtcredit
styleSheetCredits['georgia-blue'] = mtcredit
styleSheetCredits['gettysburg'] = mtcredit
styleSheetCredits['trendy'] = mtcredit
styleSheetCredits['simple'] = mtcredit



// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/
// ----------------------------------------------


function insertStyleCredits(style) {

    if(document.getElementById('style_select')){
        var selObj = document.getElementById('style_select'), i, N = selObj.options.length;
        for (i=0; i<N; i++){
            if (selObj.options[i].value == g_currentStyle) {
                selObj.selectedIndex = i;
            }
        }
    }
    if(document.getElementById('aboutStyleSheetDiv')){
        if (styleSheetCredits[style]) {
            document.getElementById('aboutStyleSheetDiv').innerHTML = 'The ' + style + styleSheetCredits[style]
        }else{
            document.getElementById('aboutStyleSheetDiv').innerHTML = 'No credits info for the ' + style + ' stylesheet'
        }
    }
}

function writeAltStylesSB(){
    // do nothing yet -- dropping the feature temporarily until rationalised; feb 06
}

function writeAboutStyleSB(){
    // do nothing yet -- dropping the feature temporarily until rationalised; feb 06
}

function setActiveStyleSheetFromSelect(selObj) {


    var i = selObj.selectedIndex;
    if (i > 0){
        var sheet = selObj.options[i].value;
        setActiveStyleSheet(sheet, 1)
    }
}

function setActiveStyleSheet(title, reset) {


    if (altStyles && altStyles.length > 1){}
    else{
        return 0
    }

  g_currentStyle = title
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      if((a.getAttribute("title")) && (a.getAttribute("title") != 'print_entries')) a.disabled = true;
      if(a.getAttribute("title") == title) {
        a.disabled = false;
        setTimeout('insertStyleCredits("' + title + '")', 800)
      }
    }
  }
  if (reset == 1) {
  createCookie("wstyle", title, 365);
  }
}

function setStyle() {
var style = readCookie("wstyle");


if (style != null) {
    setActiveStyleSheet(style, 0);
}else{
    setActiveStyleSheet(defaultCSS, 0);
}
}

var sideComponentStates = new Array();

function makeSidesCollapsible (){
//    getSidebarPrefs()
    var sidetitles = filterForClass('sidetitle', document.getElementsByTagName('*'))
    var N = sidetitles.length, i, oneID;
    for (i = 0; i < N; i++){
        makeOneSideThingCollapsible(sidetitles[i].id)
    }
}

var hiddenSidebars = [], hiddenSidebarsStr = ''

function in_array(a,val){
    for(var i=0; i<a.length; i++){
        if (a[i] == val) return true;
    }
}

function getSidebarPrefs() {
    var sbs = readCookie("knotes_sb");
    if (sbs != null) {
        hiddenSidebarsStr = sbs
        hiddenSidebars = hiddenSidebarsStr.split('*')
//        alert(hiddenSidebarsStr)
    }
}

function writeSidebarPrefs(sb_id, newDisplay) {
    if (newDisplay == 'block'){ // remove from hidden list, safe in old browsers
        var hiddenSidebarsTmp = hiddenSidebars;
        hiddenSidebars = []
        for (var i=0;i<hiddenSidebarsTmp.length;i++){
            if (hiddenSidebarsTmp[i] != sb_id){
                hiddenSidebars[hiddenSidebars.length] = hiddenSidebarsTmp[i]
            }
        }       
    }else{
        hiddenSidebars[hiddenSidebars.length] = sb_id
    }
    hiddenSidebarsStr = hiddenSidebars.join('*')
    createCookie("knotes_sb", hiddenSidebarsStr, 365);
}

function makeOneSideThingCollapsible(id){

    var oneTitleObj = document.getElementById(id)
    var oneID = id.split('sidetitle')
    if(oneID.length > 1){
        var oneItemID = 'side'+ oneID[1], oneDiv = document.getElementById(oneItemID)
        if (oneDiv){
            addOneToggler(oneTitleObj, oneItemID, oneID[1])
        }
    }
}

var gk_togglerIMGsrcColl = '<img src="' + blog_url + '/el2style_imgs/toggle_closed.gif" width="6" height="9" />'

var gk_togglerIMGsrcExp = '<img src="' + blog_url + '/el2style_imgs/toggle_expanded.gif" width="10" height="6" />'

function toggleSideBar (toggler_id, id){

    var titleID = toggler_id.split("sideToggler_").join('sidetitle')

    var ulobj = document.getElementById(id), togglerObj = document.getElementById(toggler_id), titleObj = document.getElementById(titleID)
    var newDisplay = (ulobj.style.display == g_firstToggleDisplay ) ? g_defaultSideBarDisplay : g_firstToggleDisplay;

	ulobj.style.display = newDisplay;
	togglerObj.innerHTML = newDisplay == 'none' ? gk_togglerIMGsrcColl : gk_togglerIMGsrcExp
	
	if ( titleObj ) titleObj.className = newDisplay == 'none' ? "sidetitle" : "sidetitle sidetitleExpanded"
	
///////	imgObj.src = portal_url + '/ol_sb_' + newDisplay + '.gif';
	
	writeSidebarPrefs(id, newDisplay)

}

if (window.addEventListener) window.addEventListener("load",makeSidesCollapsible,false);
else if (window.attachEvent) window.attachEvent("onload",makeSidesCollapsible);


setStyle();

function addOneToggler(obj, id, name){
    var toggler_id = "sideToggler_" + name
	var childObj = document.createElement("a");
	
    childObj.setAttribute("href","javascript:void(toggleSideBar('" + toggler_id + "','" + id + "'))");
	
	childObj.setAttribute("title","show or hide the " + name + " information");
	childObj.setAttribute("id",toggler_id);
//	childObj.style.margin = "0 4px 2px -20px"; // NOPE -- BREAKS IN MSIE
	childObj.style.margin = "0 4px 2px 0"; // "0 4px 2px 0px";
	childObj.style.padding = "0"; //  "4px 2px 4px 2px";
//	childObj.style.fontFamily = "webdings";
//	childObj.style.fontWeight = "normal";
//	childObj.style.background = "#555";
//	childObj.style.border = "1px dotted #333";
	
	var display = g_defaultSideBarDisplay
//	alert(id)
	if (in_array(hiddenSidebars, id)){
	    display = 'none'
        document.getElementById(id).style.display = 'none'
    }
    
    /*
    var webdingChar = display == 'none' ? '4' : '6'
    childObj.appendChild(document.createTextNode(webdingChar));
    
    */
    childObj.innerHTML =  display == 'none' ? gk_togglerIMGsrcColl : gk_togglerIMGsrcExp
    
    
/*
	var childIMGObj = document.createElement("img");
	childIMGObj.setAttribute("src", portal_url + "/ol_sb_" + display + ".gif");
	childIMGObj.setAttribute("alt","show or hide subsection navigation");
	
	childIMGObj.setAttribute("id",img_id);
	childIMGObj.setAttribute("border",0);
	childIMGObj.setAttribute("width",9);
	childIMGObj.setAttribute("height",9);
	
	childObj.appendChild(childIMGObj)
*/	
	obj.insertBefore(childObj, obj.childNodes[0])
//	obj.style.border="1px dotted #555"
//	obj.className = "toggler";

}


var entriesByDay = []

function writeCalendar(){

    if (entriesByDay.length > 0) return 0// do not write out the cached calendar if another precedes it in markup
      
    if (cal_entries.length == 0) return 0; // do not write an empty calendar
    
    for (var i=0;i< 33;i++){entriesByDay[i] = 0;}
    for (var i=0;i < cal_entries.length;i++){
        entriesByDay[cal_entries[i].day] = cal_entries[i].count
    }
    var s = '<h3 class="sidetitle" id="sidetitleCalendar"> ' + cal_label + '</h3>\r'
    + '<div align="center" class="calendar side" id="sideCalendar">'
//    + '<h3 class="calendarhead">' + cal_label + '</h3>'
    + '<table border="0" cellspacing="4" cellpadding="0" summary="Monthly calendar with links to each day\'s posts">'
    + '<tr>'
    
    for (var i = 0; i< cal_days.length; i++){
        s += '<th>' + cal_days[i] + '</th>'
    }
    s += '</tr>'
    for (var i = 0; i< cal_weeks.length; i++){
        var week = cal_weeks[i]
        s += '<tr>'
        for (var j = 0; j< week.length; j++){
            var day = week[j]
            s += '<td>'
            if (day) {
                if (entriesByDay[day]){
                    s += '<a href="' + cal_urlpre + day + '" title="' + entriesByDay[day] 
                    + (entriesByDay[day] > 1 ? ' entries' : ' entry')
                    + ' for this day. Click to view'
                    + (entriesByDay[day] > 1 ? ' them.">' : ' it.">')
                    + day + '</a>'
                }else{
                    s += day
                }
            }
            s += '</td>'
        }
        s += '</tr>'
    }
    s += '</table></div>'

    document.write(s)
}

/*** batching controls ***/


function makeBatchFormSmart(){
    var sub = document.getElementById('batchSubmit')
    sub.style.display = 'none';
    
    var batches = document.getElementById('b_offset'), bi = batches.selectedIndex;
    var sorts = document.getElementById('b_sort_by'), si = sorts.selectedIndex;
    window.curBatch = batches.options[bi]
    window.bi = bi;
    window.curSort = sorts.options[si]
    window.showedCurBatch = false;
    batches.options[batches.options.length] = new Option('------', '-')
    batches.options[batches.options.length] = new Option('More?', 'MORE')
    batches.options[batches.options.length] = new Option('Fewer?', 'FEWER')
}





/*** from more recent js utility changes ***/

var g_defaultEntryDisplay = 'block'
var g_defaultWebdingChar = g_defaultEntryDisplay == 'none' ? '4' : '6'

    
var g_MinEntriesCollapsing = 3;
var g_MaxEntriesShowDetail = 25;

var entry_url_pre = blog_url + '/entries/' 
var cats_url_pre = blog_url + '/weblog.categories/'

/**** string that may need localising ****/

var permalink_longstr = 'Read Full Entry (permalink)', permalink_shortstr = 'permalink'
var discussion_longstr = 'View Discussion', discussion_shortstr = 'Discussion'

var howToStr = ' <a class="phelp" title="How to reply etc" onClick="loadEditIFrame(\'view_help\', \''
    + 'weblog.help/quick_tips\');return false;" href="' + blog_url + '/weblog.help/quick_tips">help</a>';


var toggleAllTmpl = '<div><a href="javascript:void(toggleAllEntries(\'block\'))"'
    + ' title="click to show the details for all entries at once">Show details</a> | '
    + '<a href="javascript:void(toggleAllEntries(\'none\'))"'
    + ' title="click to hide the details for all entries at once">Hide details</a> '
 //   + '(<small><i>Click the toggle-detail ( '
 //   + '<img  alt="detail-toggler icon" border="0" style="margin:0;padding:0;" '
//	+ ' width="9" height="9" class="entryToggler" src="' + portal_url + '/ol_sb_' + g_defaultEntryDisplay + '.gif">'
 //   + ' ) icon of any entry to show/hide just those details</i></small>)'
 + '</div>'

/*


var btitleTmpl =  '<a class="entryToggler" id="entryToggler_*ZID*" style="font-family:webdings;font-weight:normal;" href="javascript:void(toggleEntry(\'*ZID*\'))">'
//	+ '<img id="entryToggler_*ZID*" alt="detail-toggler icon"  title="show or hide this entry\'s details" border="0"'
//	+ ' width="9" height="9" class="entryToggler" src="' + portal_url + '/ol_sb_' + g_defaultEntryDisplay + '.gif"></a>' 
    + g_defaultWebdingChar + '</a>'
    + '<a class="entryTitle" '
    + ' title="Click to view this entry alone and in full. Use this link when referring to the entry" '
    + ' href="' + entry_url_pre + '*ZID*">*TITLE*</a>'


var navTopTmpl = '<a style="display:block;padding:0;width:25px;margin:1px 0 0 -23px;" href="javascript:void(scrollToTop())"> '
    + '<img src="' + portal_url + '/knotes_ui_imgs/nav_top.png" width="23" height="17" '
    + ' alt="nav-to-top icon" title="Scroll to top of the page" hspace="0" vspace="0"  border="0"></a>'

var navUpTmpl = '<a  style="display:block;padding:0;width:25px;margin:1px 0 0 -23px;;" href="javascript:void(scrollToPost(\'*ZID*\'))"> '
    + '<img src="' + portal_url + '/knotes_ui_imgs/nav_up.png" width="23" height="17" hspace="0" vspace="0" border="0" '
    + ' alt="nav-to-top icon" title="Scroll up to previous post"></a>'


var navDownTmpl = '<a style="display:block;padding:0;width:25px;margin:1px 0 0 -23px;;" href="javascript:void(scrollToPost(\'*ZID*\'))"> '
    + '<img src="' + portal_url + '/renderIMGS/nav_down.png" hspace="0" vspace="0"  border="0" width="23" height="17" '
    + ' alt="nav-to-top icon" title="Scroll down to next post"></a>'
*/

/*
var navTopTmpl = '<a href="javascript:void(scrollToTop())">'
    + '9</a> '

var navUpTmpl = ' <a href="javascript:void(scrollToPost(\'*ZID*\'))">'
    + '7</a> '


var navDownTmpl = ' <a href="javascript:void(scrollToPost(\'*ZID*\'))">'
    + '8</a> '
*/


var btitleTmpl =  '<a class="entryToggler" id="entryToggler_*ZID*" href="javascript:void(toggleEntry(\'*ZID*\'))">'
//	+ '<img id="entryToggler_*ZID*" alt="detail-toggler icon"  title="show or hide this entry\'s details" border="0"'
//	+ ' width="9" height="9" class="entryToggler" src="' + portal_url + '/ol_sb_' + g_defaultEntryDisplay + '.gif"></a>' 
    + (g_defaultEntryDisplay == 'block' ? gk_togglerIMGsrcExp : gk_togglerIMGsrcColl) + '</a>'
    + '<a class="entryTitle" '
    + ' title="Click to view this entry alone and in full. Use this link when referring to the entry" '
    + ' href="' + entry_url_pre + '*ZID*">*TITLE*</a>'


var navTopTmpl = '<a href="javascript:void(scrollToTop())"> '
    + '<img src="' + blog_url + '/el2style_imgs/knotes_topentry.gif"width="12" height="10" '
    + ' alt="nav-to-top icon" title="Scroll to top of the page" hspace="0" vspace="0"  border="0"></a>'

var navUpTmpl = '<a  href="javascript:void(scrollToPost(\'*ZID*\'))"> '
    + '<img src="' + blog_url + '/el2style_imgs/knotes_preventry.gif"  width="11" height="10" hspace="0" vspace="0" border="0" '
    + ' alt="nav-to-top icon" title="Scroll up to previous post"></a>'


var navDownTmpl = '<a href="javascript:void(scrollToPost(\'*ZID*\'))"> '
    + '<img src="' + blog_url + '/el2style_imgs/knotes_nextentry.gif" hspace="0" vspace="0"  border="0"  width="11" height="10" '
    + ' alt="nav-to-top icon" title="Scroll down to next post"></a>'



var catTmpl = '<a href="' + cats_url_pre + '*CAT*" title="View all entries with category: \'*CAT*\'">*CATNAME*</a>'


/* code below; you should not need to change this */

var g_N_entries = 1;

function scrollToTop(){
    window.scrollTo(0,0)
//   alert('otta scroll to top')
}

function scrollToPost(id){
    var domObj = document.getElementById(id)

    if (domObj){
        scrollObjIntoView(domObj)
        if(domObj.className == 'blogCollapsed'){
            var oneID = id.split('bb_')
            if(oneID.length > 1)  toggleEntry(oneID[1])
        }
    }
}

function toggleEntry(id){
    var domObj = document.getElementById('bb_' + id)
    var state = domObj.className
    if (state == 'blogbody') domObj.className = 'blogCollapsed';
    else domObj.className = 'blogbody';
    
    var togglerObj = document.getElementById('entryToggler_' + id)
    if (togglerObj){
        togglerObj.innerHTML = state == 'blogbody' ? gk_togglerIMGsrcColl : gk_togglerIMGsrcExp
//      togglerObj.src = portal_url + (state == 'blogbody' ?  "/ol_sb_none.gif" : "/ol_sb_block.gif")
    }
}

function toggleAllEntries(state){
    var newIMGtoggle = gk_togglerIMGsrcColl
//    var newImgSrc = "/ol_sb_none.gif"
    if (state == 'none'){
        var entries = filterForClass('blogbody', document.getElementsByTagName('div'))
        var N = entries.length, i, oneID;
        for (i = 0; i < N; i++){
            entries[i].className = 'blogCollapsed';
        }
    }

    if (state == 'block'){
        newIMGtoggle = gk_togglerIMGsrcExp
        var entries = filterForClass('blogCollapsed', document.getElementsByTagName('div'))
        var N = entries.length, i, oneID;
        for (i = 0; i < N; i++){
            entries[i].className = 'blogbody';
        }
    }
    
    var togglers = filterForClass('entryToggler', document.getElementsByTagName('a'))
    var N = togglers.length, i, oneID;
    for (i = 0; i < N; i++){
        togglers[i].innerHTML = newIMGtoggle
    }
}


function makeEntriesSmart(){

    if (g_useJSutilities){

        if(isOneEntryView){
        
            makeCategoryLinks();
            makeTopEditLinks();
            makeCommentsSmart();
        }else{
            var contextBar = filterForClass('context', document.getElementsByTagName('div'), 1)
            if (document.getElementById('sideContext')) contextBar = document.getElementById('sideContext');
        
            if(contextBar){
                var s = contextBar.innerHTML
                contextBar.innerHTML = s + toggleAllTmpl   
                var entries = filterForClass('blogbody', document.getElementsByTagName('div'))
                var N = entries.length, i;
                g_N_entries = N;
                for (i = 0; i < N; i++){
                    var prevID = i > 0 ? entries[i-1].id : 0
                    var nextID = i < (N-1) ? entries[i+1].id : 0
                    makeOneEntrySmart(entries[i], prevID, nextID)
                }
                makeCategoryLinks();
                makeTopEditLinks();
            }
        }
    }
}


function makeCommentsSmart(){   /// mike trialing june 11 06 --- ***** need to get the parentzid/commentzid into the calls in the toolbar

    if (g_useJSutilities){
        if(isOneEntryView  && canReply){
            var commentsDiv = document.getElementById('replies');
            
            if (commentsDiv){
                var comments = filterForClass('posted', commentsDiv.getElementsByTagName('div'));
                var N = comments.length, i;
                for (i = 0; i < N; i++){
                    var comment = comments[i], oid = comment.getAttribute('kn:objid')
                    var canEditPost = comment.getAttribute('kn:canEdit')
                    var s = oneEditLinksStr(canEditPost, oid, 'Comment ' + (i+1)) // stubbed here, branches by permissions in blog_edit.js
                    s = s.split('*ZID*').join(thisID + '/' + oid)
                    var curHTML = comment.innerHTML
            
                    comment.innerHTML = s + curHTML //  + howToStr             
                }
            }
        }
    }

}

function makeTopEditLinks(){ // stub overridden in edit scripts, called in addLinksToPosted
}

function makeEntryToolBar(){ // stub overridden in edit scripts, called in addLinksToPosted
}

function makeCategoryLinks(){
    var catlists = filterForClass('category', document.getElementsByTagName('div'))
    var N = catlists.length, i;
    for (i = 0; i < N; i++){    
        makeOneCatListSmart(catlists[i])
    }
}

function makeOneEntrySmart(entryObj, prevID, nextID){

    var id = entryObj.id, title = ''
    var oneID = id.split('bb_')
    if(oneID.length > 1){
       title = addLinksToTitle(entryObj, oneID[1])
       addLinksToPosted(entryObj, oneID[1], title) /// addLinksToPosted now also writes toolbars if user has permissions
    }
    if ((g_defaultEntryDisplay == 'none') && (g_N_entries > g_MinEntriesCollapsing)){
        entryObj.className = 'blogCollapsed'
    }
    if (g_N_entries > g_MaxEntriesShowDetail){
            entryObj.className = 'blogCollapsed'
    }
    
    makeOneNavLinks(entryObj, prevID, nextID)
}

function makeOneNavLinks(entryObj, prevID, nextID){
    var dateObj = filterForClass('date', entryObj.getElementsByTagName('*'), 1)
    var navS = navTopTmpl
    if (prevID) navS += navUpTmpl.split('*ZID*').join(prevID)
    if (nextID) navS += navDownTmpl.split('*ZID*').join(nextID)
    
    var s = dateObj.innerHTML;
    dateObj.innerHTML = s + navS

//	var childObj = document.createElement("div");
//	childObj.className = 'navLinks'

//    var newObj = entryObj.insertBefore(childObj, textObj )
//	newObj.innerHTML = navS
//// rHTML = s + '<div>' + navS
}



function makeOneCatListSmart(catsObj){
    var cats = catsObj.getElementsByTagName('b'), s, oneS, catname, subcats, oneSubCat

    for (var i=0, N=cats.length; i<N; i++){
        catname = cats[i].innerHTML
        
        subcats = catname.split('/')
        oneSubCat = subcats[0]
        s = catTmpl.split('*CAT*').join(oneSubCat)
        s = s.split('*CATNAME*').join(oneSubCat)
        for(var j=1, M=subcats.length; j<M; j++){
            oneSubCat += '/' + subcats[j]
            var oneLink = catTmpl.split('*CATNAME*').join(subcats[j])
            s += '/' + oneLink.split('*CAT*').join(oneSubCat)
        }
        cats[i].innerHTML = s
    }
}


function addLinksToTitle(bb_obj, id){
    var obj = bb_obj, h2s = bb_obj.getElementsByTagName('h2')
    if (h2s.length) obj = h2s[0]
    else return
    
    var s = btitleTmpl.split('*ZID*').join(id)
    var title = obj.innerHTML
    s = s.split('*TITLE*').join(title)
    
    obj.innerHTML = s
    
    return title

}

function addLinksToPosted(bb_obj, id, title){
    var posted = filterForClass('posted', bb_obj.getElementsByTagName('div'), 1)
    
    if (posted){
    
        var canEditPost = posted.getAttribute('kn:canEdit')
        var s = oneEditLinksStr(canEditPost, id, title) // stubbed here, branches by permissions in blog_edit.js
        s = s.split('*ZID*').join(id)
        var curHTML = posted.innerHTML

        posted.innerHTML = s + curHTML + howToStr
        
        return posted
    }
}

if (window.addEventListener) window.addEventListener("load",makeEntriesSmart,false);
else if (window.attachEvent) window.attachEvent("onload",makeEntriesSmart);

function registerPloneFunction(func){ 
    if (window.addEventListener) window.addEventListener("load",func,false);
    else if (window.attachEvent) window.attachEvent("onload",func);   
}

function getContentArea(){
    node =  document.getElementById('region-content')
    if (! node){
        node = document.getElementById('content')
    }
    return node
}


function climb(node, word){
    // traverse childnodes
    if (! node){return false}
    if (node.hasChildNodes) {
        var i;
        for (i=0;i<node.childNodes.length;i++) {
            climb(node.childNodes[i],word);
        }
        if (node.nodeType == 3){
            checkforhighlight(node, word);
           // check all textnodes. Feels inefficient, but works
        }
    }
}
function checkforhighlight(node,word) {
    ind = node.nodeValue.toLowerCase().indexOf(word.toLowerCase())
    if (ind != -1) {
        if (node.parentNode.className != "highlightedSearchTerm"){
            par = node.parentNode;
            contents = node.nodeValue;
            	
            // make 3 shiny new nodes
            hiword = document.createElement("span");
            hiword.className = "highlightedSearchTerm";
//            hiword.style.background = 'red'
            hiword.appendChild(document.createTextNode(contents.substr(ind,word.length)));
				
            par.insertBefore(document.createTextNode(contents.substr(0,ind)),node);
            par.insertBefore(hiword,node);
            par.insertBefore(document.createTextNode(contents.substr(ind+word.length)),node);

            par.removeChild(node);
        }
    } 
}
  



function highlightSearchTerm() {
        // search-term-highlighter function --  Geir Bækholt
               
        query = window.location.search
        // _robert_ ie 5 does not have decodeURI 
        if (typeof decodeURI != 'undefined'){
            query = decodeURI(unescape(query)) // thanks, Casper 
        }
        else {
            return false
        }
        
        
        if (query){
            var qfinder = new RegExp()
            qfinder.compile("searchterm=([^&]*)","gi")
            qq = qfinder.exec(query)
            if (qq && qq[1]){
                query = qq[1]
                
                if (!query){return false}
                queries = query.replace(/\+/g,' ').split(/\s+/)
                
                // make sure we start the right place and not higlight menuitems or breadcrumb
                contentarea = getContentArea();
                for (q=0;q<queries.length;q++) {
                        climb(contentarea,queries[q]);
                }
            }
        }
}
registerPloneFunction(highlightSearchTerm);

function writeExtraSubscribeLinks(){
    if (document.getElementById){
        if (document.getElementById('email_subscribe')){
            document.write('<li>EMAIL Notifications : <a title="receive email notification of new posts" id ="email_subscribe_2" href =" '  + blog_url + '/subscribe">Subscribe</a></li>')
        }
        
        if (document.getElementById('email_unsubscribe')){
            document.write('<li>EMAIL Notifications : <a  title="stop receiving email notification of new posts" id ="email_unsubscribe_2" href = "' + blog_url + '/unsubscribe">Unsubscribe</a></li>')
        }
    }
}

function writeSideBarRules(){
    getSidebarPrefs()
    var i, N= hiddenSidebars.length, s = '<STY' + 'LE>\r'
    for (i=0;i<N;i++){
        s += '#' + hiddenSidebars[i] + ' {display:none;}\r'
    }
    s += '#quick_login_box{display:none;position:absolute;width:30em;}\r'
    
    s += '</ST' + 'YLE>'
    document.write(s)
}

/// del.icio.us playtagger from http://del.icio.us/js/playtagger - here, in-line, in case del site goes down

if(typeof(Delicious) == 'undefined') Delicious = {}
Delicious.Mp3 = {
    playimg: null,
    player: null,
    go: function() {
        var all = document.getElementsByTagName('a')
        for (var i = 0, o; o = all[i]; i++) {
            if(o.href.match(/\.mp3$/i)) {
                var img = document.createElement('img')
                img.src = 'http://del.icio.us/static/img/mp3/play.gif'; img.title = 'listen'
                img.height = img.width = 12
                img.style.marginRight = '0.5em'
                img.style.cursor = 'pointer'
                img.onclick = Delicious.Mp3.makeToggle(img, o.href)
                o.parentNode.insertBefore(img, o)
    }}},
    toggle: function(img, url) {
        if (Delicious.Mp3.playimg == img) Delicious.Mp3.destroy()
        else {
            if (Delicious.Mp3.playimg) Delicious.Mp3.destroy()
            var a = img.nextSibling, c=''
            if (document.defaultView && document.defaultView.getComputedStyle) c = document.defaultView.getComputedStyle(a,null).getPropertyValue('color')
            else if (a.currentStyle) c = a.currentStyle['color']
            c = c.replace(/^rgb|[ ()]/g, '')
            var hex = c.match(/^#?([a-f0-9]{6})$/), hexSm = c.match(/^#?([a-f0-9]{3})$/), rgb = c.match(/^([0-9]+),([0-9]+),([0-9]+)$/)
            if (rgb) { var c16 = "0123456789abcdef", c=''; for(var i=1,d;d=rgb[i];i++) { var j=d%16; c=c+c16.charAt((d-j)/16)+c16.charAt(j) } }
            else if (hex) c = hex[1]
            else if (hexSm) c = hexSm[1].charAt(0) + hexSm[1].charAt(0) + hexSm[1].charAt(1) + hexSm[1].charAt(1) + hexSm[1].charAt(2) + hexSm[1].charAt(2)
            else c = "000000"
            img.src = 'http://del.icio.us/static/img/mp3/stop.gif'; Delicious.Mp3.playimg = img;
            Delicious.Mp3.player = document.createElement('span')
            Delicious.Mp3.player.innerHTML = '<object style="vertical-align:bottom;margin-right:0.2em" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
            'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
            'width="100" height="14" id="player" align="middle">' +
            '<param name="wmode" value="transparent" />' +
            '<param name="allowScriptAccess" value="sameDomain" />' +
            '<param name="flashVars" value="theLink='+url+'&amp;fontColor='+c+'" />' +
            '<param name="movie" value="http://del.icio.us/static/swf/playtagger.swf" /><param name="quality" value="high" />' +
            '<embed style="vertical-align:bottom;margin-right:0.2em" src="http://del.icio.us/static/swf/playtagger.swf" flashVars="theLink='+url+'&amp;fontColor='+c+'"'+
            'quality="high" wmode="transparent" width="100" height="14" name="player"' +
            'align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"' +
            ' pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'
            img.parentNode.insertBefore(Delicious.Mp3.player, img.nextSibling)
    }},
    destroy: function() {
        Delicious.Mp3.playimg.src = 'http://del.icio.us/static/img/mp3/play.gif'; Delicious.Mp3.playimg = null
        Delicious.Mp3.player.removeChild(Delicious.Mp3.player.firstChild); Delicious.Mp3.player.parentNode.removeChild(Delicious.Mp3.player); Delicious.Mp3.player = null
    },
    makeToggle: function(img, url) { return function(){ Delicious.Mp3.toggle(img, url) }}
}

Delicious.addLoadEvent = function(f) { var old = window.onload
    if (typeof old != 'function') window.onload = f
    else { window.onload = function() { old(); f() }}
}

Delicious.addLoadEvent(Delicious.Mp3.go)

/// end of del.icio.us playtagger



/***** utility stufff for login / anon from quick reply form *****/

var vemail = false;
var vmembername = true;

var whitespace = " \t\n\r";
function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}
function isWhitespace (s) {
    var i;

    if (isEmpty(s)) return true;


    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


/*****************captcha validation **************************/

var captcha_http;

function handleValidateCaptcha() { 
  if (captcha_http.readyState == 4) {
    results = captcha_http.responseText;
    if (results == '1'){
        window.status="Posting comment...";
        document.forms['inpage_comment_form'].submit()
    }else{
        window.status="Captcha validation failed!";   
        cw=document.getElementById("captcha_word")
        cw.value="";
        o = document.getElementById("captcha_img")
        o.src= "getCaptchaIMG/"+Math.round(Math.random()*9999999999)+".gif";
        alert('Oops! You got the image text wrong. Please try again.')
        
        cw.focus();
    }
  }
}

function validateCaptcha() {
    captcha_http = getHTTPObject();
    window.status="Validating captcha...";
    var url = "validateCaptchaAjaxian?"
    var cw = document.getElementById("captcha_word")
    if(!cw) {
        window.status="Posting comment...";
        document.forms['inpage_comment_form'].submit()
        return false;
    }
    var word=cw.value    
    if (isWhitespace(word)) {
        alert('Please enter the text shown in the image')
        return false;
    }
    var params = "word="+word
    url = url+params;
    captcha_http.open("GET", url, true);
    captcha_http.onreadystatechange = handleValidateCaptcha;
    captcha_http.send(null);
}

function validateCommentFromFormObj(formEl) {

    var bodyObj = formEl.text
    var body = bodyObj.value
    var title = formEl.title.value
    var usequote = formEl.usequote.checked
    var breakLines = formEl.breaks.checked
    
    
    if (isWhitespace(title)){
        alert("You must enter a comment title");
        return false;
    }
    
    if (breakLines){
        body = body.replace('\r','\n')
        //body = '<p>' + body.split('\r').join('<' + '/p><p>') + '<' + '/p>'
        body = '<p>' + body.split('\n').join('<' + '/p><p>') + '<' + '/p>'
        body = body.split('<p><' + '/p>').join('')
        body = body.replace('/p>','/p>\n')


    }
    if (usequote){
        var txt = ''
        if (window.getSelection)
            txt = window.getSelection();
        else if (document.getSelection)
            txt = document.getSelection();
        else if (document.selection)
            txt = document.selection.createRange().text;
        if (! isWhitespace(txt)) {
            txt="<"+"blockquote"+">"+txt+"<"+"/blockquote"+">";
            body = txt+body;
        }

    }
    bodyObj.value = body;

    return true;
    
}

function validateComment() {
    var formEl = document.getElementById("inpage_comment_form")
    if(document.getElementById('anon_reply').style.display!='none'){
        var full_name = formEl.anon_full_name
        if (full_name){
            full_name = full_name.value
            if(isWhitespace(full_name)){
                alert("You must enter a name of some kind in the 'Name' field.  Please enter a name and try again.");
                return false;
            }
        }
    }
    var anon_style = document.getElementById("reply_form").style.display

    if(anon_style.toLowerCase()=="block"){
        var o = document.forms['inpage_comment_form']['join_optional'].value

        if (o == '0'){
            var join_name = document.getElementById("join_name").value
            if(isWhitespace(join_name)){
                alert("You must choose a username!");
                return false;
            }
        }
    }




    validateCommentFromFormObj(formEl);
    validateCaptcha();
    return false;
    
}

function handleLogIn() {
  var f = document.forms['inpage_comment_form']
  if (http2.readyState == 4) {
    results = http2.responseText;

    if (results == "1"){
        alert("Wrong username or password!\n\nPlease try again");
        f["comment_submit_button"].disabled=true;
    }else{
        f["comment_submit_button"].disabled=false;
        document.getElementById("login_form").style.display="None";
        var asel = document.getElementById("auth_select");
        if (asel) asel.style.display="None";
        var cpt = document.getElementById("captcha")
        if(cpt) cpt.style.display="None";
        window.status="Log-in successful";

    }
  }
}

function logIn() {
    window.status="Contacting server for log-in";
    var url = "knLogIn?"
    var username=document.getElementById("ac_name").value;
    var password=document.getElementById("ac_password").value;
    var params = "__ac_name="+username+"&__ac_password="+password;
    url = url+params;
    http2.open("GET", url, true);
    http2.onreadystatechange = handleLogIn;
    http2.send(null);
}

function handleValidateEmail() {
  var f = document.forms['inpage_comment_form']
  if (http2.readyState == 4) {
    results = http2.responseText;
    if(results != "1"){
        window.status="Validating email address failed!"
        alert("Invalid Email Address");
        f["comment_submit_button"].disabled=true;

    }else{
        window.status="Email address valid";
        vemail = true;
        if(vmembername)f["comment_submit_button"].disabled=false;
    }

  }
}

function validateEmail() {
    window.status="Validating email address...";
    var url = "validateEmail?"
    var email=document.getElementById("email_for_anon").value
    if (isWhitespace(email)) {
        return false;
    }
    var params = "email="+email
    url = url+params;
    http2.open("GET", url, true);
    http2.onreadystatechange = handleValidateEmail;
    http2.send(null);
}


function handleValidateMemberName() {
  window.status="Validating member name..."
  var f = document.forms['inpage_comment_form']
  if (http2.readyState == 4) {
    results = http2.responseText;
    if(results != "1"){
        window.status="Validating member name failed!"
        alert("Invalid user name!\nIt may already be taken.\nPlease try again");
        document.getElementById("comment_submit_button").setAttribute('disabled',true);
        vmembername = false;

    }else{
        window.status="Member name valid";
        vmembername = true;
        if (vemail) f["comment_submit_button"].disabled=false;
    }

  }
}

function validateMemberName() {
    var url = "validateUserName?"
    var join_name = document.getElementById("join_name").value
    var f = document.forms['inpage_comment_form'];
    if (isWhitespace(join_name) ){
        vmembername = true;
        if (vemail) f["comment_submit_button"].disabled=false;
        return true;
    }else{
        var params = "join_name="+join_name
        url = url+params;
        http2.open("GET", url, true);
        http2.onreadystatechange = handleValidateMemberName;
        http2.send(null);
    }
}

function showForm(form) {
    var f = document.forms['inpage_comment_form']
    document.getElementById(form).style.display="Block";
    if (form == "login_form"){
        document.getElementById("anon_reply").style.display="None";
        f['l_b'].disabled=true;
        f['a_b'].disabled=false;
        f['comment_submit_button'].disabled=true;
    }else{
        document.getElementById("login_form").style.display="None";
        f['a_b'].disabled=true;
        f['l_b'].disabled=false;
        f['comment_submit_button'].disabled=true;
        validateemail=true;
    }

}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

/*****Quick login form********/
var ql_form_showing=false;
var ql_http = '';

function cancelLogin(){

    if (document.getElementById('quick_login_box')){
        document.getElementById('quick_login_box').style.display = 'none'
    }
    ql_form_showing=false;
}

function showQuickLoginForm(){

    if (ql_form_showing) return false;
    
    if (document.getElementById('quick_login_box')){
        var formObj = document.getElementById('quick_login_box')
        formObj.style.display = 'block'
        if (document.getElementById('login_anchor')){
            var anchorObj = document.getElementById('login_anchor');
            formObj.style.left = getAbsX(anchorObj) - 100 + 'px'
            formObj.style.top = getAbsY(anchorObj) + 20 + 'px'            
        }
        if (document.getElementById('ql_ac_name')){
            document.getElementById('ql_ac_name').focus()
        }
    }
    ql_form_showing=true;
    ql_http = getHTTPObject();
}




function handleQuickLogIn() {
  if (ql_http.readyState == 4) {
    results = ql_http.responseText;
    if (results == "1"){
        document.getElementById('ql_error').innerHTML='Wrong user name or password!'
        window.status="Log-in failed!";
    }else{
        var href = this_url
        href += (href.indexOf('?') > -1) ? '&' : '?'
        href += 'portal_status_message=welcome!+your+are+now+logged+in'
        document.location=href
//    document.location = this_url;
        window.status="Log-in succeeded";
    }
  }
}

function quickLogIn() {
    window.status="Contacting server for log-in";
    var url = "knLogIn?"
    var username=document.getElementById("ql_ac_name").value;
    var password=document.getElementById("ql_ac_password").value;
    var params = "__ac_name="+username+"&__ac_password="+password;
    url = url+params;

    ql_http.open("GET", url, true);
    ql_http.onreadystatechange = handleQuickLogIn;
    ql_http.send(null);
}

var gk_hideStatusMsgLinkStr = '<a href="javascript:void(hideStatusMsg())" '
    + 'title="Click to hide the message above">hide this message</a>'

var gk_hideQuickLoginLinkStr = ' <a id="quicklogin_close" href="javascript:void(cancelLogin())" title="close this form"><img src="'
    + portal_url + '/knotes_ui_imgs/close_icon.gif" style="float: right;"></a>'

function hideStatusMsg(){
    if(document.getElementById('status_message')) document.getElementById('status_message').style.display = 'none';
}

function scrollObjIntoView(domObj){

    if(document.getElementById){
        if(domObj.scrollIntoView){
            domObj.scrollIntoView(top);
        }
        else {
            var y = getAbsY(domObj)
            var divY = getAbsY(document.getElementById('folders'))
            window.scrollTo(0,y-divY);
        }
    }
}


// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!

function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
} 

var g_nReplies = 'not set yet'

function previewComment(){
    var formEl =  document.forms['inpage_comment_form']
    var body = formEl.text.value, title = formEl.title.value, lead = formEl.lead.value;
    
    var origBody = body; // so can undo prep for posting
    validateCommentFromFormObj(formEl); // this prepares the paras and quotes !!!! NB ought to fix the side-effect assuming posting
    
    body = formEl.text.value
    formEl.text.value = origBody
 
    var anchorDiv, nReplies;
    if(document.getElementById('reply_form_preview')) {
        anchorDiv = document.getElementById('reply_form_preview')
        if (g_nReplies == 'not set yet') g_nReplies = anchorDiv.innerHTML
    }else{
        alert('Sorry, there was a problem.')
        return 0;
    }
    var tmpl = '<h3><b>*N*</b> <a href="javascript:void(alert(\'this is just a preview '
    + 'of what your comment would look like.\'))">*TITLE*</a></h3><div class="leadin">'
    + '*LEAD*</div>*BODY*<div class="posted">Preview of your comment <a href="javascript:void(hidePreview())">hide preview</a></div>'
    
    var s = tmpl.split('*N*').join(g_nReplies)
     s = s.split('*TITLE*').join(title)
     s = s.split('*LEAD*').join(lead)
     s = s.split('*BODY*').join(body)
     
     anchorDiv.innerHTML = s;
     anchorDiv.style.display='block'
    
}

function hidePreview(){
    if(document.getElementById('reply_form_preview')) document.getElementById('reply_form_preview').style.display='none'
}


function oneEditLinksStr(canEditThis, id, title) { // stub overridden in edit scripts, called in addLinksToPosted
    return ''
}

function batchChoice(id){
/// maybe hide submit button if both the select boxen are in original state?
    var sub = document.getElementById('batchSubmit')
    sub.style.display = 'inline';

    if (id == 'b_offset'){
        var selObj = document.getElementById('b_offset')
        var i = selObj.selectedIndex, val  = selObj.options[i].value;
        if (val == 'MORE'){
            alert('should increase number of records in batches')
            selObj.selectedIndex = window.bi;
            return false;
        }
        if (val == 'FEWER'){
            alert('should decrease number of records in batches')
            selObj.selectedIndex = window.bi;
            return false;
        }
        if (val == '-'){
            selObj.selectedIndex = window.bi;
            return false;
        }
        window.bi = i;
    }
    return true;
}
/*** below is for exfile preview ***/

function PopupPreview(preview_url, size1, size2) {
    size1=size1+50;
    if (size1>850) {
        size1=850;
    }
    size2=size2+150;
    if (size2>650) {
        size2=650;
    };
    F = window.open(preview_url,"Popup","resizable=1,status=0,scrollbars=1,width=" + size1 +",height="+ size2 );
    F.focus();
}



function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/;";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


var g_EditIFrameAction = 'x';
var g_iframeTemplates = new Array();

var iframeHTML_help = '<div id="editor_tabs">'
    + '<a href="javascript:dismissEditor()">Close (back to normal view)</a>'
    + ' <small>[When you are finished with the content below, click the Close button to return to your previous view]</small></div>'
    + '<iframe style="display: block;width:100%;height:2000px;" id="editor_pane"'
    + 'src="' + blog_url + '/*ZID*?template=weblog_nowrap_template">'

g_iframeTemplates['view_help'] = iframeHTML_help

var g_lastYScroll = 0;

function loadEditIFrame(action, id) {    

    if (g_iframeTemplates[action]){
        var iframeHTML = g_iframeTemplates[action]
        
        if (id){
            iframeHTML = iframeHTML.split('*ZID*').join(id)
            iframeHTML = iframeHTML.split('*URL*').join(id)
        }
        var d = document.getElementById('iframeEditDiv')
        
    //    '*ZID*'
        
        if (g_EditIFrameAction != action) d.innerHTML = iframeHTML; // check to see if it had been cancelled since last pageload
        
        if(isForumView){
            document.getElementById('subsForumTop').style.display='none'
            document.getElementById('iframeEditDiv').style.display='block'
            
            if ((action.indexOf('new_kndiscussion') < 0) && (document.getElementById('crumbs'))){
                document.getElementById('crumbs').style.display='none'
            }
            
            if (action.indexOf('new_kndiscussion') > -1){
                scrollObjIntoView(document.getElementById('iframeEditDiv'))
            }      
        }else{
            document.getElementById('content').style.display='none'
            document.getElementById('links').style.display='none'
            document.getElementById('iframeEditDiv').style.display='block'
            
            if (document.body.scrollTop) g_lastYScroll = document.body.scrollTop
            
            if (action.indexOf('new_blog_entry') == -1){
                window.scrollTo(0,0)
            }
        }
    }
}


function dismissEditor() {

    if(isForumView){
        document.getElementById('subsForumTop').style.display='block'
        if(document.getElementById('crumbs')) document.getElementById('crumbs').style.display='block'
    }else{
        document.getElementById('content').style.display='block'
        document.getElementById('links').style.display='block'
    }
    document.getElementById('iframeEditDiv').style.display='none'
        
    if (g_lastYScroll) window.scrollTo(0, g_lastYScroll)
    
    g_lastYScroll = 0;
    
}
function filterForType(aType, aNodeList, firstEl){
    var aType = new String(aType);
    aType=aType.toLowerCase();
    var filteredNodeList = new Array();
    if(!(aNodeList.length > 0)){return filteredNodeList}
    for(var i=0; i<aNodeList.length; i++){
        var nodeString = new String(aNodeList[i].nodeName);
        nodeString = nodeString.toLowerCase();
        if(nodeString == aType){
            filteredNodeList[filteredNodeList.length] = aNodeList[i];
//          filteredNodeList.push(aNodeList[i]);
        }
    }
    if (firstEl){
        if(filteredNodeList.length > 0) return filteredNodeList[0]
        else return null;
    }
    return filteredNodeList;
}

function filterForClass(aClass, aNodeList, firstEl){
    var aClass = new String(aClass);
    aClass=aClass.toLowerCase();
    var filteredNodeList = new Array();
    if(!(aNodeList.length > 0)){return filteredNodeList}
    for(var i=0; i<aNodeList.length; i++){
        var nodeString = new String(aNodeList[i].className);
        nodeString = nodeString.toLowerCase();
        if(nodeString == aClass){
            filteredNodeList[filteredNodeList.length] = aNodeList[i];
//          filteredNodeList.push(aNodeList[i]);
        }
    }
    if (firstEl){
        if(filteredNodeList.length > 0) return filteredNodeList[0]
        else return null;
    }
    return filteredNodeList;
}




/**********changing banner image*************/
var banner_form_showing = false;
function showBannerForm(){
    if(banner_form_showing) cancelBannerForm();
    var html = '<a id="banner_change_close" href="javascript:void(cancelForm(\'banner_form_div\'))" title="close this form"><img src="knotes_ui_imgs/close_icon.gif" style="float: right;"></a>'
         + '<div>Choose an image with a maximum width of 800px and a maximum height of 250px. only image files (files with [.gif .jpg .png] extension) allowed</div>'
         + '<form enctype="multipart/form-data" method="POST" action="attachBannerImage" onsubmit="return checkFileType()" name="banner_form">'
         + '<input type="file" name="banner_file" /><br />'
         + '<input type="submit" value="Upload" />'
         + '</form>'
    var bf=document.createElement('div');
    bf.id="banner_form_div";
    bf.style.position="absolute"
    bf.style.padding=".5em";
    bf.style.width="250px";
    bf.style.top=document.body.scrollTop+40+"px";
    bf.style.right="100px";
    bf.style.background="#DDDDEE";
    bf.style.border="solid 1px black";
    bf.innerHTML=html
    document.body.appendChild(bf);
    banner_form_showing=true;
}

function cancelForm(id){
    var obj=document.getElementById(id);
    obj.parentNode.removeChild(obj);
    banner_form_showing=false;

}

function checkFileType(){
    var file = document.banner_form.banner_file.value
    var extArray = new Array("gif", "jpg", "png")
    var ext = file.split('.')
    if (ext.length<2){
        alert("The file you are trying to upload is not valid\nPlease select an image file (.gif, .jpg, .png)");
        return false;
    }
    ext = ext[ext.length-1]
    for (var i = 0; i < extArray.length; i++) {
        if (extArray[i] == ext) 
            return true; 
    }
    alert("The file you are trying to upload is not valid\nPlease select an image file (.gif, .jpg, .png)");
    return false;
}


/***** writing CSS below *****/


var searchstr_style = '<STY' + 'LE> span.highlightedSearchTerm {background:yellow;padding:1px;}</ST' + 'YLE>'
document.write(searchstr_style)



