function rollOver(myImg)
{
    myImg.src = myImg.src.replace(/\.gif/i, "_over.gif");
}

function rollOut(myImg)
{
    myImg.src = myImg.src.replace(/_over\.gif/, ".gif");
}

function put_tip( field, term ) {
    var i=0;
    var fields = field.split('.');
    term = term.replace(/\\'/g, '\'');

    thefield = parent.editor.document;
    for( i=0; i<fields.length; i++ ) {
	thefield = thefield[fields[i]];
    }
    thefield.value += '%{Tip: ' + term + '}%';
}


function put_lplink( field, dqid, lpid, text, defaulttext, anchor ) 
{
    var fields = field.split('.');
    thefield = parent.editor.document;
    for( i=0; i<fields.length; i++ ) {
	thefield = thefield[fields[i]];
    }

    if( text == '' ) { text = defaulttext; }

    thefield.value += '%{Lesson: '+dqid+', '+lpid+'('+anchor+'), '+text+'}%';
} // function put_lplink

function put_link( field, method, url, text ) {
    var i=0;
    var fields = field.split('.');
    text = text.replace(/\\'/g, '\'');

    if( method == 'outweb' && url.indexOf('http://') != 0 ) {
	url = 'http://'+url;
    } // if it's outside, but they didn't say http

    thefield = parent.editor.document;
    for( i=0; i<fields.length; i++ ) {
	thefield = thefield[fields[i]];
    }
    thefield.value += '%{Link: ' + method
		    + ', ' + url + ', ' 
		    + text + '}%';
}


function put_attachment( field, file, text ) {
    var i=0;
    var fields = field.split('.');
    file = file.replace(/\\'/g, '\'');
    text = text.replace(/\\'/g, '\'');

    thefield = parent.editor.document;
    for( i=0; i<fields.length; i++ ) {
	thefield = thefield[fields[i]];
    }
    thefield.value += '%{File: ' +
	'worksheets/' + file + ', ' + text + '}%';
}

function put_image( field, file, text ) {
    var i=0;
    var fields = field.split('.');
    file = file.replace(/\\'/g, '\'');
    text = text.replace(/\\'/g, '\'');

    thefield = parent.editor.document;
    for( i=0; i<fields.length; i++ ) {
	thefield = thefield[fields[i]];
    }
    thefield.value += '%{Image: ' +
	'worksheets/images/' + file + ', ' + text + '}%';
}

function changeImages() {
    d = document;
    if (d.images) {
	var img;
	for (var i=0; i<changeImages.arguments.length; i+=2) {
	    img = null;
	    if (d.layers) {img = findElement(changeImages.arguments[i],0);}
	    else {img = d.images[changeImages.arguments[i]];}
	    if (img) {img.src = changeImages.arguments[i+1];}
	}
    }
}

function qec_popup(qec)
{
    var win = window.open("images_qec.php?qec=" + qec, "TipWin",
	"location=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=450,height=400"
);
    win.focus();
}

function doTip(ques)
{
    var ask = escape(ques);
    var win = window.open("dotip.php?tip=" + ask, "TipWin",
	"location=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=300"
);
    win.focus();
}

function doResTip(ques)
{
    var ask = escape(ques);
    var win = window.open("dotip.php?res=res&tip=" + ask, "TipWin",
	"location=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=300"
);
    win.focus();
}


function generalTipWin(lnk)
{
    url = lnk.href;

    var win = window.open(url, "TipWin",
	"location=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=300"
);
    win.focus();

    return false;
} // function generalTipWin


var seq = 0;


function helpButtons(target, gettopath, harried)
{
    seq++;

    if( typeof(gettopath) == 'undefined' ) {
	gettopath = '';
    }

    document.writeln(
'<a href="'+gettopath+'helper.php?field=' + target + '" target="helper">' +
'<img alt="[help]"' +
'name="hand' + seq + '" src="'+gettopath+'images/icons/helpinghand.gif" align="absmiddle" '+
'border="0">'+
'&nbsp;Assistant</a>\n' );
}

Object.prototype.getItem=function getItem(prop) { return this[prop]; }


// the following stuff, I borrowed from RabYak on #javascript
//*** This code is copyright 2002-2003 by Gavin Kistner and Refinery; www.refinery.com
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt
//*** Reuse or modification is free provided you abide by the terms of that license.
//*** (Including the first two lines above in your source code satisfies the conditions.)

//***Adds a new class to an object, preserving existing classes
function AddClass(obj,cName){ KillClass(obj,cName); return obj.className+=(obj.className.length>0?' ':'')+cName; }

//***Removes a particular class from an object, preserving other existing classes.
function KillClass(obj,cName){ return obj.className=obj.className.replace(new RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),''); }

//***Returns true if the object has the class assigned, false otherwise.
function HasClass(obj,cName){ return (!obj || !obj.className)?false:(new RegExp("\\b"+cName+"\\b")).test(obj.className) }


// Okay, the rest of this stuff is mine.


function SearchableList( putithere, headers, data )
{
    if( arguments.length > 0 ) {
	this.init(putithere, headers, data);
    }
}

SearchableList.prototype.init = function SL_init( putithere, headers, data )
{
    var check;

    this.headers   = headers;
    this.data      = data;

    this.putithere = document.getElementById('putstuffhere');
    this.table     = document.createElement('table');
    check = this.putithere.appendChild(this.table);
}

SearchableList.prototype.drawRow = function SL_drawRow(row, data)
{
    var j;
    var col;
    var tx;

    for( j=0; j<data.length; j++ ) {
	col = document.createElement('td');
	    AddClass(col, "DataCol");
	tx  = document.createTextNode(data[j]);
	col.appendChild(tx);

	row.appendChild(col);
    }
}

SearchableList.prototype.searchfor = function SL_searchfor( searchterm )
{
    var i;
    var row;

    var check;

    if( this.putithere == null ) {
	return;
    }

    this.putithere.innerHTML='';
    this.table     = document.createElement('table');
	this.table.cellSpacing = 0;
	AddClass(this.table, "DataTable");
    this.table.tbody = document.createElement('tbody');

    for( i=0; i<this.data.length; i++ ) {
	for( j=0; j<this.data[i].length; j++ ) {
	    if( this.data[i][j].lastIndexOf(searchterm) >= 0 ) {
		// create this row
		row = document.createElement('tr');
		    AddClass(row, "DataRow");

		this.drawRow(row, this.data[i]);

		this.table.tbody.appendChild(row);

		break;
	    }
	}
    }

    this.table.appendChild(this.table.tbody);
    this.putithere.appendChild(this.table);
}

function alsoCheckEd421()
{
    var ed421 = document.getElementById('cked421');
    ed421.checked = true;
}



var COMPOSE_RQ = false;
var BEGIN_COMPOSE_HAS_RUN = false;



function beginCompose()
{
    var url = new String(window.location);

    url.replace(/^http:\/\//, "");
    urlbits = url.split("/");
    urlbits[urlbits.length-1] = "";

    url = urlbits.join("/");
    url += "/BeginCompose.php?" + new Date().getTime();

    if( ! COMPOSE_RQ ) {
	COMPOSE_RQ = true;
	notanimage = new Image();
	notanimage.src = url;

	wait_Compose_RQ();
    } // if there's not already an outstanding request
} // function beginCompose


function wait_Compose_RQ()
{
    var cookies = new String(document.cookie).split(";");
    for( i=0; i<cookies.length; i++ ) {
	var cookiestr = new String(cookies[i]);
	var cookie = cookiestr.split("=");
	cookie[0] = cookie[0].replace(/ +/, "");
	cookie[1] = cookie[1].replace(/ +/, "");
	if( cookie[0] == 'compose_cookie_ack' &&
	    cookie[1] == 'done' ) 
	{
	    COMPOSE_RQ = false;
	    cookies[i]='"compose_cookie_ack"="resolved"';
	    var resetcookies = cookies.join(";");
	    document.cookie = resetcookies;
	} // if we're acknowledged
    } // for all the cookies

    if( COMPOSE_RQ ) {
	window.setTimeout("wait_Compose_RQ()", 125);
    } // if there's still an outstanding request
} // function wait_Compose_RQ
