


/***********************************************
* Static Menu script- by JavaScript Kit (www.javascriptkit.com)
* This notice must stay intact for usage
* Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more
***********************************************/

//ids of menus to keep static on page (must be absolutely positioned, with left/top attribute added inline inside tag)
//Separate multiple ids with a comma (ie: ["menu1", "menu2"]
/***********************************************
* Ajax Page Fetcher- by JavaScript Kit (www.javascriptkit.com)
***********************************************/

var ajaxpagefetcher={
loadingmessage: "Loading... WAIT >:3",
exfilesadded: "",

connect:function(containerid, pageurl, bustcache, jsfiles, cssfiles){
	var page_request = false
	var bustcacheparameter=""
	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE6 or below
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
	var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
	page_request.onreadystatechange=function(){ajaxpagefetcher.loadpage(page_request, containerid, pageurl, jsfiles, cssfiles)}
	if (bustcache) //if bust caching of external page
		bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	document.getElementById(containerid).innerHTML=ajaxpagefetcher.loadingmessage //Display "fetching page message"
	page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true)
	page_request.send(null)
},

loadpage:function(page_request, containerid, pageurl, jsfiles, cssfiles){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(containerid).innerHTML=page_request.responseText
		for (var i=0; i<jsfiles.length; i++)
			this.loadjscssfile(jsfiles[i], "js")
		for (var i=0; i<cssfiles.length; i++)
			this.loadjscssfile(cssfiles[i], "css")
		this.pageloadaction(pageurl) //invoke custom "onpageload" event
	}
},

createjscssfile:function(filename, filetype){
	if (filetype=="js"){ //if filename is a external JavaScript file
		var fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", filename)
	}
	else if (filetype=="css"){ //if filename is an external CSS file
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", filename)
	}
	return fileref
},

loadjscssfile:function(filename, filetype){ //load or replace (if already exists) external .js and .css files
	if (this.exfilesadded.indexOf("["+filename+"]")==-1){ //if desired file to load hasnt already been loaded
		var newelement=this.createjscssfile(filename, filetype)
		document.getElementsByTagName("head")[0].appendChild(newelement)
		this.exfilesadded+="["+filename+"]" //remember this file as being added
	}
	else{ //if file has been loaded already (replace/ refresh it)
 	var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using
 	var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
 	var allsuspects=document.getElementsByTagName(targetelement)
 	for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
  	if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1){
   	var newelement=this.createjscssfile(filename, filetype)
   	allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
  	}
		}
 }
},


pageloadaction:function(pageurl){
	this.onpageload(pageurl) //call customize onpageload() function when an ajax page is fetched/ loaded
},

onpageload:function(pageurl){
 //do nothing by default
},

load:function(containerid, pageurl, bustcache, jsfiles, cssfiles){
	var jsfiles=(typeof jsfiles=="undefined" || jsfiles=="")? [] : jsfiles
	var cssfiles=(typeof cssfiles=="undefined" || cssfiles=="")? [] : cssfiles
	this.connect(containerid, pageurl, bustcache, jsfiles, cssfiles)
}

} //End object

//Sample usage:
//1) ajaxpagefetcher.load("mydiv", "content.htm", true)
//2) ajaxpagefetcher.load("mydiv2", "content.htm", true, ["external.js"])
//3) ajaxpagefetcher.load("mydiv2", "content.htm", true, ["external.js"], ["external.css"])
//4) ajaxpagefetcher.load("mydiv2", "content.htm", true, ["external.js", "external2.js"])
//5) ajaxpagefetcher.load("mydiv2", "content.htm", true, "", ["external.css", "external2.css"])

function topcorn(topcorner, loaded){
	var iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	var topcorner=(window.pageYOffset)? window.pageYOffset : iebody.scrollTop
	var loaded
document.getElementById("topshit").innerHTML=topcorner;

locale = document.getElementById("bottom").offsetTop;

if(topcorner>=locale-1000){
	var jesus=1;
	//ajaxpagefetcher.load('preload', 'index.php?page=2&rape=pls', true); // won't load rape for unknown reasons
}
	if(!jesus)setTimeout("topcorn()", 100)
}


var staticmenuids=["staticmenu"]

var staticmenuoffsetY=[screen.height-250]

function getmenuoffsetY(){
	for (var i=0; i<staticmenuids.length; i++){
		var currentmenu=document.getElementById(staticmenuids[i])
	 staticmenuoffsetY.push(isNaN(parseInt(currentmenu.style.top))? 0 : parseInt(currentmenu.style.top))
	}
		initstaticmenu()
}


function initstaticmenu(){
	var iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	var topcorner=(window.pageYOffset)? window.pageYOffset : iebody.scrollTop
	for (var i=0; i<staticmenuids.length; i++)
		document.getElementById(staticmenuids[i]).style.top=topcorner+staticmenuoffsetY[i]+"px"
	setTimeout("initstaticmenu()", 100)
	
}


if (window.addEventListener)
window.addEventListener("load", getmenuoffsetY, false)
else if (window.attachEvent)
window.attachEvent("onload", getmenuoffsetY)




/* Smooth scrolling
   Changes links that link to other parts of this page to scroll
   smoothly to those links rather than jump to them directly, which
   can be a little disorienting.
   
   sil, http://www.kryogenix.org/
   
   v1.0 2003-11-11
   v1.1 2005-06-16 wrap it up in an object
*/


var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
  
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
  
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
    if (!destinationLink) destinationLink = document.getElementById(anchor);

    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
  
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
  
    cypos = ss.getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
  
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    
    window.scrollTo(0,wascypos + scramount);
    
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      //location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },
  

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}

ss.STEPS = 25;

ss.addEvent(window,"load",ss.fixAllLinks);

function change(id, newClass) 
{ 
identity=document.getElementById(id); 
identity.className=newClass; 
} 

function preload_images(images)
 {
  var img = new Array();
  for(var i = 0; i < images.length; ++i)
   {
    img[i] = new Image();
    img[i].src = images[i];
   }
 }

function sf(id)
 {
  if(document.getElementById(id)) document.getElementById(id).focus();
 }

function simple_ajax_request(url,query)
 {
  var strURL = 'index.php';
  var xmlHttpReq = false;
  var self = this;
  // Mozilla/Safari
  if (window.XMLHttpRequest) {
      self.xmlHttpReq = new XMLHttpRequest();
  }
  // IE
  else if (window.ActiveXObject) {
      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }
  self.xmlHttpReq.open('POST', strURL, true);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  self.xmlHttpReq.setRequestHeader("Pragma", "no-cache");
  self.xmlHttpReq.setRequestHeader("Cache-Control", "must-revalidate");
  self.xmlHttpReq.setRequestHeader("If-Modified-Since", document.lastModified);
  self.xmlHttpReq.onreadystatechange = function() {
      if(self.xmlHttpReq.readyState == 4) {
       // just do nothing...   
      }
  }
  self.xmlHttpReq.send(query);
 }


function highlight_posting(thread,threadcolor,posting,postingcolor)
 {
  if(document.getElementById(thread)) document.getElementById(thread).style.background=threadcolor;
  if(document.getElementById(posting)) document.getElementById(posting).style.background=postingcolor;
 }

function fold_thread(id,expand_img,fold_img)
 {
  //var expand_title = decodeURIComponent(expand_title);
  //var fold_title = decodeURIComponent(fold_title);
  var ULs = document.getElementById('thread-'+id).getElementsByTagName("ul"); 
  if(ULs[0] && (ULs[0].style.display=='block' || ULs[0].style.display==''))
   {
    document.getElementById('expand_img_'+id).src = expand_img;
    //document.getElementById('expand_link_'+id).title = expand_title;
    for(var i = 0; i < ULs.length; i++) 
    ULs[i].style.display = 'none'; 
   }
  else
   {
    document.getElementById('expand_img_'+id).src = fold_img;
    //document.getElementById('expand_link_'+id).title = fold_title;
    for(var i = 0; i < ULs.length; i++) 
    ULs[i].style.display = 'block'; 
   } 
 }

function hide_posting(id,show_posting_img,hide_posting_img)
 {
  if(document.getElementById('posting-'+id).style.display!='none') 
   {
    document.getElementById('posting-'+id).style.display='none';
    if(document.getElementById('avatar-'+id)) document.getElementById('avatar-'+id).style.display='none';
    if(document.getElementById('hide-posting-'+id)) document.getElementById('hide-posting-'+id).src=show_posting_img;
   } 
  else
   {
    document.getElementById('posting-'+id).style.display='block';
    if(document.getElementById('avatar-'+id)) document.getElementById('avatar-'+id).style.display='block';
    if(document.getElementById('hide-posting-'+id)) document.getElementById('hide-posting-'+id).src=hide_posting_img;
   } 
 } 

function getElementsByClassName(class_name)
{
  var all_obj,ret_obj=new Array(),j=0;
  if(document.all)all_obj=document.all;
  else if(document.getElementsByTagName && !document.all)all_obj=document.getElementsByTagName("*");
  for(i=0;i<all_obj.length;i++)
  {
    if(all_obj[i].className==class_name)
    {
      ret_obj[j]=all_obj[i];
      j++
    }
  }
  return ret_obj;
}

function hide_all_postings(show_posting_image)
 {
  var obj=getElementsByClassName('postingcontainer');
  for(i=0;i<obj.length;i++)
   {
    obj[i].style.display='none';
   }
  var obj=getElementsByClassName('hide-posting');
  for(i=0;i<obj.length;i++)
   {
    obj[i].src=show_posting_image;
   }
  var obj=getElementsByClassName('avatar');
  for(i=0;i<obj.length;i++)
   {
    obj[i].style.display='none';
   }
 }
 
function show_all_postings(hide_posting_image)
 {
  var obj=getElementsByClassName('postingcontainer');
  for(i=0;i<obj.length;i++)
   {
    obj[i].style.display='block';
   }
  var obj=getElementsByClassName('hide-posting');
  for(i=0;i<obj.length;i++)
   {
    obj[i].src=hide_posting_image;
   }
  var obj=getElementsByClassName('avatar');
  for(i=0;i<obj.length;i++)
   {
    obj[i].style.display='block';
   }   
 } 
 
function hide_replies()
 {
  document.getElementsByTagName("ul").style.display='none';
 }   

function hide_sidebar(id,minimized_width,maximized_width,hide_image,show_image)
 {
  if(document.getElementById(id+'-container').style.display=='none') 
   {
    document.getElementById(id+'-container').style.display='block';
    document.getElementById(id+'-toggle').src=hide_image;
    document.getElementById(id).style.width=maximized_width;
    simple_ajax_request('index.php','hide='+id);
   } 
  else
   {
    document.getElementById(id+'-container').style.display='none';
    document.getElementById(id+'-toggle').src=show_image;
    document.getElementById(id).style.width=minimized_width;
    simple_ajax_request('index.php','hide='+id);
   } 
 }
 
function toggle_sidebar(hide_image,show_image)
 {
  //this.blur();
  if(document.getElementById('sidebarcontent').style.display=='none') 
   {
    document.getElementById('sidebarcontent').style.display='block';
    document.getElementById('sidebartoggle').src=hide_image;
   } 
  else
   {
    document.getElementById('sidebarcontent').style.display='none';
    document.getElementById('sidebartoggle').src=show_image;
   } 
  simple_ajax_request('index.php','toggle_sidebar=true');
 } 

function bbcode(id,code,value)
 {
  value = typeof(value) != 'undefined' ? value : '';
  if(value!='') value = '='+value;
  
  if (document.selection) // for IE
   {
    var str = document.selection.createRange().text;
    document.getElementById(id).focus();
    var sel = document.selection.createRange();
    sel.text = '[' + code + value + "]" + str + '[/' + code + ']';
    return;
   }
  else if((typeof document.getElementById(id).selectionStart) != 'undefined') // for Mozilla
   {
    var txtarea = document.getElementById(id);
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    var oldScrollTop = txtarea.scrollTop;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd);
    var s3 = (txtarea.value).substring(selEnd, selLength);
    txtarea.value = s1 + '[' + code + value + ']' + s2 + '[/' + code + ']' + s3;
    txtarea.selectionStart = s1.length;
    txtarea.selectionEnd = s1.length + code.length*2 + value.length + s2.length + 5;
    txtarea.scrollTop = oldScrollTop;
    txtarea.focus();
    return;
   }
  else insert(id,'[' + code + value + '][/' + code + ']');
 }

function insert(id,what)
 {
  if(document.getElementById(id).createTextRange) // IE
   {
    document.getElementById(id).focus();
    document.selection.createRange().duplicate().text = what;
   }
  else if((typeof document.getElementById(id).selectionStart) != 'undefined') // Mozilla
   {
    var tarea = document.getElementById(id);
    var selEnd = tarea.selectionEnd;
    var txtLen = tarea.value.length;
    var txtbefore = tarea.value.substring(0,selEnd);
    var txtafter =  tarea.value.substring(selEnd, txtLen);
    var oldScrollTop = tarea.scrollTop;
    tarea.value = txtbefore + what + txtafter;
    tarea.selectionStart = txtbefore.length + what.length;
    tarea.selectionEnd = txtbefore.length + what.length;
    tarea.scrollTop = oldScrollTop;
    tarea.focus();
   }
  else
   {
    document.getElementById(id).value += what;
    document.getElementById(id).focus();
   }
 }

function insert_link(id,link_text,link_target)
 {
  var link_text = decodeURIComponent(link_text);
  var link_target = decodeURIComponent(link_target);
  if(document.selection) // for IE
   {
    var str = document.selection.createRange().text;
    document.getElementById(id).focus();
    var sel = document.selection.createRange();
    var insert_link = prompt(link_target,'http://');
    if(sel.text=='' && insert_link!='' && insert_link!=null) var str = prompt(link_text,'');
    if(insert_link && str!=null)
     {
      if(str!='')
       {
        sel.text = "[link=" + insert_link + "]" + str + "[/link]";
       }
      else
       {
        sel.text = "[link]" + insert_link + "[/link]";
       }
     }
    return;
   }
  else if((typeof document.getElementById(id).selectionStart) != 'undefined') // for Mozilla
   {
    var txtarea = document.getElementById(id);
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    var oldScrollTop = txtarea.scrollTop;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd);
    var s3 = (txtarea.value).substring(selEnd, selLength);

    var insert_link = prompt(link_target,'http://');
    if(selEnd-selStart==0 && insert_link!='' && insert_link!=null)
     {
      var s2 = prompt(link_text,'');
      var no_selection = true;
     }
    if(insert_link && s2!=null)
     {
      if(s2!='')
       {
        txtarea.value = s1 + '[link=' + insert_link + ']' + s2 + '[/link]' + s3;
        var codelength = 14 + insert_link.length + s2.length;
       }
      else
       {
        txtarea.value = s1 + '[link]' + insert_link + '[/link]' + s3;
        var codelength = 13 + insert_link.length;
       }
      if(no_selection) txtarea.selectionStart = s1.length + codelength;
      else txtarea.selectionStart = s1.length;
      txtarea.selectionEnd = s1.length + codelength;
      txtarea.scrollTop = oldScrollTop;
      txtarea.focus();
      return;
     }
   }
  else insert(id,'[link=http://www.domain.tld/]Link[/link]');
 }

function insert_image(id,image_url_label)
 {
  var image_url_label = decodeURIComponent(image_url_label);
  if(document.selection) // for IE
   {
    var str = document.selection.createRange().text;
    document.getElementById(id).focus();
    var sel = document.selection.createRange();
    if(str=='') 
     {
      var image_url = prompt(image_url_label,'http://');
      if(image_url!=null) sel.text = "[img]" + image_url + "[/img]";
     }
    else
     {
      sel.text = "[img]" + str + "[/img]";
     }
    return;
   }
  else if((typeof document.getElementById(id).selectionStart) != 'undefined') // for Mozilla
   {
    var txtarea = document.getElementById(id);
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    var oldScrollTop = txtarea.scrollTop;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd);
    var s3 = (txtarea.value).substring(selEnd, selLength);
    if(selEnd-selStart==0) 
     {
      var s2 = prompt(image_url_label,'http://');
      var no_selection = true;
     }
    if(s2!=null)
     {
      txtarea.value = s1 + '[img]' + s2 + '[/img]' + s3;
      var codelength = 11 + s2.length;
      if(no_selection) txtarea.selectionStart = s1.length + codelength;
      else txtarea.selectionStart = s1.length;
      txtarea.selectionEnd = s1.length + codelength;
      txtarea.scrollTop = oldScrollTop;
      txtarea.focus();
      return;
     }
   }
  else insert(id,'[link=http://www.domain.tld/]Link[/link]');
 }

function clear_input(form,field)
 {
  document.forms[form].elements[field].value = '';
  document.forms[form].elements[field].focus();
 }

function show_box(id,x,y)
 {
  x = typeof(x) != 'undefined' ? x : 0;
  y = typeof(y) != 'undefined' ? y : 0;
  if(!document.getElementById(id).style.display || document.getElementById(id).style.display=='none')
   {
    s_box = document.getElementById(id);
    s_box.style.display = 'block';
    s_box.style.left  = xpos+x + 'px';
    s_box.style.top = ypos+y + 'px';
   } 
  else
   {
    document.getElementById(id).style.display = 'none';
   }
 }

function popup(url,width,height)
 {
  width = typeof(width) != 'undefined' ? width : 340;
  height = typeof(height) != 'undefined' ? height : 340;
  winpops = window.open(url,'','width='+width+',height='+height+',scrollbars,resizable');
 }

function delete_cookie(deleting_cookie_message) 
 {
  document.getElementById('delete_cookie').innerHTML = decodeURIComponent(deleting_cookie_message);
    
    var strURL = 'index.php';
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.setRequestHeader("Pragma", "no-cache");
    self.xmlHttpReq.setRequestHeader("Cache-Control", "must-revalidate");
    self.xmlHttpReq.setRequestHeader("If-Modified-Since", document.lastModified);
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            //var deleted = self.xmlHttpReq.responseXML.getElementsByTagName('deleted')[0].firstChild.data;
            document.getElementById('delete_cookie').innerHTML = '&nbsp;';
            document.getElementById('setcookie').checked = '';
        }
    }
    //self.xmlHttpReq.send(true);
    self.xmlHttpReq.send('mode=delete_cookie&method=ajax');
 }

function ajax_preview(id,show_reply_link)
 {
  var srl = typeof(show_reply_link) == 'undefined' ? 0 : show_reply_link;
  if(document.getElementById('ajax-preview') && document.getElementById("ajax-preview").className == "active-"+id) // close preview if the same link is clicked again
   {
    ajax_preview_close();
   }
  else // display preview
   { 
    if(!document.getElementById('ajax-preview'))
     {
      // create preview container:
      var ap = document.createElement('div');
      ap.setAttribute('id','ajax-preview');
      // append it to the HTML body :
      document.getElementsByTagName('body')[0].appendChild(ap);
     }
    // set unique class name to be able check whether to open or close the preview:
    document.getElementById("ajax-preview").className = 'active-'+id;
    // insert HTML structure:  
    if(typeof ajax_preview_structure == 'undefined') ajax_preview_structure = '<div id="ajax-preview-top"></div><div id="ajax-preview-body"><div><a id="ajax-preview-close" href="#" onclick="ajax_preview_close(); return false">[x]</a></div><div id="ajax-preview-throbber"></div><div id="ajax-preview-content"></div></div>'; // this is only if the structure is not defined in the templae! Make design changes in ajax_preview.tpl.inc.
    document.getElementById('ajax-preview').innerHTML = ajax_preview_structure;
    // place it to the mouse position:
    ap = document.getElementById('ajax-preview');
    ap.style.left  = xpos-8 + "px";
    ap.style.top = ypos+2 + "px";    
    // show throbber:
    document.getElementById("ajax-preview-throbber").style.display = "block";
    // get data via AJAX:
    var strURL = 'index.php';
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) // Mozilla/Safari
     {
      self.xmlHttpReq = new XMLHttpRequest();
     }
    else if (window.ActiveXObject) // IE
     {
      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
     }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.setRequestHeader("Pragma", "no-cache");
    self.xmlHttpReq.setRequestHeader("Cache-Control", "must-revalidate");
    self.xmlHttpReq.setRequestHeader("If-Modified-Since", document.lastModified);
    self.xmlHttpReq.onreadystatechange = function() 
                                          {
                                           if(self.xmlHttpReq.readyState == 4)
                                            {
                                             updatepage(id,self.xmlHttpReq.responseXML,srl);
                                            }
                                          }
    self.xmlHttpReq.send('mode=entry&ajax_preview=true&id='+id);
   }
 }

function updatepage(id,xml,show_reply_link)
 {
  var show_reply_link = typeof(show_reply_link) == 'undefined' || show_reply_link == 0 ? 0 : 1;
  var content = xml.getElementsByTagName('content')[0].firstChild.data;
  if(content=='') content = '<p>-</p>';
  document.getElementById("ajax-preview-content").innerHTML = content;
  // hide throbber:
  document.getElementById("ajax-preview-throbber").innerHTML = '';
  document.getElementById("ajax-preview-throbber").style.display = 'none';
  if(document.getElementById("ajax-preview-replylink")) 
   {
    if(show_reply_link==1)
     {
      document.getElementById("ajax-preview-replylink").style.display = 'block';
      document.getElementById("replylink").href = 'index.php?mode=posting&id='+id;
     }
    else
     {
      document.getElementById("ajax-preview-replylink").innerHTML = '';
      document.getElementById("ajax-preview-replylink").style.display = 'none';
     }    
   } 
 }

function ajax_preview_close()
 {
  if(document.getElementById('ajax-preview'))
   {
    document.getElementsByTagName('body')[0].removeChild(document.getElementById('ajax-preview'));
   }
 }

function mouse_position(e) 
 {
  if(!e) e = window.event;
  xpos  = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  ypos = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
 }

function hide_element(e) 
 {
  document.getElementById(e).style.display = 'none';
 }

function mark(id,marked_image,unmarked_image,process_mark_image,mark_title,unmark_title) 
 {
    //this.blur();
    
    pmi = new Image();
    pmi.src = process_mark_image;
    mi = new Image();
    mi.src = marked_image;
    umi = new Image();
    umi.src = unmarked_image;
        
    document.getElementById('markimg_'+id).src = process_mark_image;
    document.getElementById('markimg_'+id).alt = '[ ]';
    
    var strURL = 'index.php';
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.setRequestHeader("Pragma", "no-cache");
    self.xmlHttpReq.setRequestHeader("Cache-Control", "must-revalidate");
    self.xmlHttpReq.setRequestHeader("If-Modified-Since", document.lastModified);
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            var action = self.xmlHttpReq.responseXML.getElementsByTagName('action')[0].firstChild.data;
            if(action==1) 
             {
              document.getElementById('markimg_'+id).src = marked_image;
              document.getElementById('markimg_'+id).alt = '[â—?]';
              document.getElementById('marklink_'+id).title = decodeURIComponent(unmark_title);
              document.getElementById('markimg_'+id).title = decodeURIComponent(unmark_title);
             } 
            else 
             {
              document.getElementById('markimg_'+id).src = unmarked_image;
              document.getElementById('markimg_'+id).alt = '[â—‹]';
              document.getElementById('marklink_'+id).title = decodeURIComponent(mark_title);
              document.getElementById('markimg_'+id).title = decodeURIComponent(mark_title);
             } 
        }
    }
    //self.xmlHttpReq.send(true);
    self.xmlHttpReq.send('mode=posting&mark='+id+'&method=ajax');
 }

function delete_posting_confirm(this_link,confirm_question)
 {
  var confirmed = confirm(decodeURIComponent(confirm_question));
  if(confirmed) this_link.href += '&delete_posting_confirm=true';
  return confirmed;
 } 

function clear_input(form,field)
 {
  document.forms[form].elements[field].value = '';
  document.forms[form].elements[field].focus();
 }

function hide_quote()
 {
  document.getElementById('insert_quote_link').style.visibility = 'visible';
  quotes = document.forms['postingform'].elements['text'].value;
  document.forms['postingform'].elements['text'].value = '';
 }
 
function insert_quote()
 {
  document.getElementById('insert_quote_link').style.visibility = 'hidden';
  var current_value = document.forms['postingform'].elements['text'].value;
  document.forms['postingform'].elements['text'].value = quotes + '\n\n' + current_value;
  document.forms['postingform'].elements['text'].focus();
 } 

function is_postingform_complete(name_error,subject_error,text_error,terms_of_use_error)
 {
	terms_of_use_error = typeof(terms_of_use_error) != 'undefined' ? terms_of_use_error : '';
  error_message='';
	if(document.forms['postingform'].elements['name'] && document.forms['postingform'].elements['name'].value=='')
	 {
		error_message += "- "+decodeURIComponent(name_error)+"\n";
	 }
	if(document.forms['postingform'].elements['subject'].value=='')
	 {
		error_message += "- "+decodeURIComponent(subject_error)+"\n";
	 }
	if(text_error!='' && document.forms['postingform'].elements['text'].value=='')
	 {
		error_message += "- "+decodeURIComponent(text_error)+"\n";
	 }
	if(terms_of_use_error!='' && document.forms['postingform'].elements['terms_of_use_agree'].checked==false)
	 {
		error_message += "- "+decodeURIComponent(terms_of_use_error)+"\n";
	 }
  if(error_message)
	 {
		alert(error_message);
		return false;
	 }
	else
	 {
		document.getElementById('throbber-submit').style.visibility = 'visible';
    return true;
	 }
 }

function insert_avatar(avatar)
 {
  document.getElementById('avatar').innerHTML = '<a href="index.php?mode=avatar" onclick="popup(\'index.php?mode=avatar\'); return false"><img src="'+avatar+'" alt="Avatar" /><\/a>';
 }

document.onmousedown = mouse_position;
