var newline = "\n";
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
function getSel()
{
if (document.getSelection) txt = document.getSelection();
else if (document.selection) txt = document.selection.createRange().text;
else return;
document.update.blogEntry.value = document.update.blogEntry.value+txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
}
function insert_tag(field, tag, insert_word) {
if (document.selection)
{
//ie
field.focus();
sel = document.selection.createRange();
if (sel.text == "") { sel.text = tag; } else { sel.text = tag.replace(insert_word, sel.text);}
} else if (field.selectionStart || field.selectionStart == '0') {
//moz
var start = field.selectionStart;
var end = field.selectionEnd;
var selection = field.value.substring( start , end);
var styled_tag = tag.replace(insert_word, selection);
var beginning = field.value.substring(0, start)
var ending = field.value.substring(end, field.value.length);
if (selection == "") { field.value = beginning + tag + ending; } else { field.value = beginning + styled_tag + ending;}
} else {
//stick it at the end
field.value += tag;
}
}
function change_text(message, id, underscore_strip)
{
if (underscore_strip == "y")
{
var message = message.replace("_", "'");
}
document.getElementById(id).innerHTML = message;
}
function spellChange(text, word, correction, feedback_element)
{
//strip out the underscores that were placeholders for apostrophes in the word and correction
var correction = correction.replace("_", "'");
var word = word.replace("_", "'");
//create the new text string with corrections made to replace the old entry text
var newText = text.replace(word, correction);
//print feedback to the screen for the user
if (feedback_element != "")
{
var message = word + " replaced by " + correction + " in your journal!";
change_text(message, feedback_element);
}
//send the new corrected entry back to the browser
return newText;
}
function sendvalueToWindow(cookieName, cookieValue, url, w, h, windowName, path, expDays)
{
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var path = '/';
setCookie(cookieName, cookieValue, exp, path);
openWindow(url, w, h, windowName, 'no')
}
//this function resizes div by id on window resize
function resizeElement(id, topOffSet)
{
var x,y;
if (self.innerHeight) // all except Explorer
{
x = self.innerWidth;
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
x = document.documentElement.clientWidth;
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
x = document.body.clientWidth;
y = document.body.clientHeight;
}
document.getElementById(id).style.height = (y - topOffSet)+'px';
}
//this function is used to make rollovers or replace any images src by id
function replaceImage(src, id, parent)
{
if (parent != "y")
{
document.getElementById(id).src = src;
} else {
window.opener.document.getElementById(id).src = src;
}
}
//add text to a section by id
function addText(text, id, parent, replace)
{
if (parent != "y")
{
var orig_text = document.getElementById(id).innerHTML;
if (replace == "y")
{
document.getElementById(id).innerHTML = text;
} else {
document.getElementById(id).innerHTML = orig_text + ' ' +text;
}
} else {
var orig_text = window.opener.document.getElementById(id).innerHTML;
if (replace == "y")
{
window.opener.document.getElementById(id).innerHTML = text;
} else {
window.opener.document.getElementById(id).innerHTML = orig_text + ' ' + text;
}
}
}
var pos=0;
function scrollText(text)
{
//sets teh scrollbar ett and scroll sit when used on interval
//e.g. onclick="setInterval('scrollText(\'Herello here is long string of tejlkjs dk lkadsjlk \')', 100);return false;"
document.title=text.substring(pos,text.length)+text.substring(0,pos);
pos=(pos+1)%text.length;
}
function rollSize(id, size)
{
if (size != "")
{
document.getElementById(id).style.width = size + 'px';
} else {
document.getElementById(id).style.width = 'auto';
}
}
function toggleClass(id, oldClass, newClass, cookie)
{
var oldCookie = (getCookie(cookie) != null)? getCookie(cookie) : null;
if (oldCookie != null)
{
if ((oldCookie).indexOf(id + ':') != -1)
{
removeId = oldCookie.replace(id + ":", "");
setCooky(cookie, removeId, null, "/");
if (removeId == "") {deleteCooky(cookie);}
document.getElementById(id).className = oldClass;
} else {
setCooky(cookie, oldCookie + id + ":", null, "/");
document.getElementById(id).className = newClass;
}
} else {
setCooky(cookie, id + ":", null, "/");
document.getElementById(id).className = newClass;
}
}
function toggleCookie(cookie, img, on_src, off_src)
{
var oldCookie = getCookie(cookie);
if (oldCookie != null)
{
if(oldCookie =="y")
{
setCooky(cookie, "n", null, "/");
if (img == "y") {document.getElementById(cookie).src = off_src;}
} else {
setCooky(cookie, "y", null, "/");
if (img == "y") {document.getElementById(cookie).src = on_src;}
}
} else {
setCooky(cookie, "y", null, "/");
if (img == "y") {document.getElementById(cookie).src = on_src;}
}
}
function scrollPos(axis){
var x,y;
if (self.pageYOffset) // all except Explorer
{
x = self.pageXOffset;
y = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
x = document.documentElement.scrollLeft;
y = document.documentElement.scrollTop;
} else if (document.body) // all other Explorers
{
x = document.body.scrollLeft;
y = document.body.scrollTop;
}
if (axis == "x") {return x; } else {return y;}
}
function moveWithScroll(id, axis, offset)
{
var pos = scrollPos(axis) + offset;
if (axis == "y"){ document.getElementById(id).style.top = pos + "px"; }
if (axis == "x"){ document.getElementById(id).style.left = pos + "px"; }
document.getElementById(id).style.zIndex = '10';
}
//this script had to be redone for xhtml 1 transitional - now it works
var ie=document.all
var moz=document.getElementById&&!document.all
var dragable=false
var z,x,y
function drag(e){
if (dragable){
z.style.left=moz? (temp1+e.clientX-x) + "px": (temp1+event.clientX-x) + "px";
z.style.top=moz? (temp2+e.clientY-y) + "px" : (temp2+event.clientY-y) + "px";
return false
}
}
function makeDragable(e){
if (!ie&&!moz) {return;} //escape if not using a drag capable browser
var obj=moz? e.target : event.srcElement;
while (obj.className!="dragme")
{
obj=moz? obj.parentNode : obj.parentElement;
}
if (obj.className=="dragme"){
dragable=true;
z=obj;
temp1=parseInt(z.style.left+0);
temp2=parseInt(z.style.top+0);
x=moz? e.clientX: event.clientX;
y=moz? e.clientY: event.clientY;
document.onmousemove=drag;
return false;
}
}
function write_flash(file, id, parent, replace)
{
var flash = '';
addText(flash, id, parent, replace);
}
function write_tags(tag, formName, formField, parent)
{
if (parent != "y")
{
document.update.blogEntry.value = document.update.blogEntry.value + "\n" + tag + "\n";
} else {
window.opener.document.update.blogEntry.value = window.opener.document.update.blogEntry.value + "\n" + tag + "\n";
}
}
function write_media(file, id, type, parent, replace)
{
if (type == "image")
{
var media = ' ';
} else if (type == "flash") {
var media = ' ';
} else if (type == "sounds") {
var media = ' '
}
addText(media, id, parent, replace);
}
setCooky('js', 'y', null, '/');