
/********************************************************************************
functions.js
This file contains functions and global Javascript variables used across the site.
********************************************************************************/

//crossbrowser load function
function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener){
		if(evType=="load")
			evType = "DOMContentLoaded";
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	}
	else {
		alert("Please upgrade your browser to use full functionality on this page");
	}
}

function addProvider(url){
	try {
		window.external.AddSearchProvider(url);
	}
	catch (e) {
		alert("You need to be using IE7 or Firefox2 to add a search engine\r\nYou can also install search plugins by using the drop down menu to the right of the search box.");
		return;
	}
}

// Initialize global site variables.
var urlroot = "http://www.lecturebreak.org";
var img = urlroot + "/images";
var snapypos;
var snapxpos;
var snapcache = new Array();
var snapdata;
var snapeid;
var currdate;
var IE = document.all?true:false
var isSafari = (navigator.appVersion.indexOf("Safari") != -1) ? true : false;
var thtml = null;
var hchtml = null;
var posturl = "";
var pane_orig_width;

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

function switchcheck(id){
	elm = document.getElementById(id);
	if(elm){
		if(elm.type=="checkbox"){
			if(elm.checked)
				elm.checked = false;
			else
				elm.checked = true;
		}
		else{
			elm.checked = true;
		}
		elm.focus();
		elm.blur();
	}
}

// Check the content of the PM
function checkPM(){
	if(document.getElementById('message').value==""){
		document.getElementById('PMerror').innerHTML="Please enter a message";
		return false;
	}
	else{
		// add to watched list
		document.getElementById('message').value += "\n\n--------------------------------------------\nThe above message was in response to your listing for\n[URL=http://www.lecturebreak.org/classifieds.browse.php?item="+document.getElementById('itemid').value+"]"+document.getElementById('itemtitle').value+"[/URL]";
		return true;
	}
}


// Capture mouse movements.
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {
		tempY = e.pageY - window.pageYOffset;
		tempX = e.pageX - window.pageXOffset;
	}
	return true
}

// Submit form to log out of site.
function goLogout() {
	document.getElementById("logoutform").submit();
}

/*
// Show shadowbox preview of posting from anywhere. Enqueues into AJAX.
function showPreview(item,mod,pub) {
	var pubreq = (pub==1) ? '&showpub=1' : "";
	var request = 'item=' + item + '&mode=preview' + pubreq;
	enqueueRequest('getPreview','/post/preview.php',request);
}
*/

// Function to pop up an informational alert with a title, message and close button.
// Can be hard coded to perform different functions on close if needed.
function popAlert(sbTitle,str) {
	dimBackground();
	var closelnk;
	var args = arguments.length;
	if (args >= 3) {
		closelnk = arguments[2];
	} else {
		closelnk = "closePop()";
	}
	var paneObj = document.getElementById("popUp");
	preHideObj(paneObj);
	paneObj.innerHTML = "<div><div id='sbHeader'>" + sbTitle + "</div><div id='sbBody'>" + str + "<div id='sbButtons'><input type='button' id='okButt' value='Close' onClick='" + closelnk + "' /></div></div></div>";
	setTimeout("centerDiv('popUp');", 200);
	setTimeout("document.getElementById('okButt').focus();",300);
}

// Standard function to close pop up box.
function closePop() {
	document.getElementById("popUp").style.display = "none";
	document.getElementById("popUp").style.visibility = "hidden";
	document.getElementById("popUp").innerHTML = "";
	unDimBackground();
}

// Function to hide select boxes in Internet Exploder. This is necessary
// due to IE not respecting z-index primacy of shadowbox. Function also
// unhides when argument is not 'hide'.
function hideSelects(dir) {
	if (IE) {
		var sls = document.all.tags('select');
		for (var i=0; i < sls.length; i++) { 
			var theElement = sls[i];
			if(!theElement) continue;
			if (dir == "hide") {
				theElement.style.visibility = "hidden";
			} else {
				theElement.style.visibility = "visible";
			}
		}
	}
}

// Function used globally to dim the background before a shadowbox pop up is shown.
function dimBackground() {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var tas = document.getElementsByTagName('textarea');
	var ifs = document.getElementsByTagName('iframe');
	for (var i=0; i < tas.length; i++) { tas[i].style.overflow = "hidden"; }
	for (var i=0; i < ifs.length; i++) { ifs[i].style.visibility = "hidden"; }
	hideSelects('hide');
	var bgd = document.getElementById("bgDimmer");
	bgd.style.height = (arrayPageSize[1] + 'px');
	bgd.className = "turnedon";
}

// Function used globally to undim the background after a shadowbox pop up is closed.
function unDimBackground() {
	var bgd = document.getElementById("bgDimmer");
	var tas = document.getElementsByTagName('textarea');
	var ifs = document.getElementsByTagName('iframe');
	for (var i=0; i < ifs.length; i++) { ifs[i].style.visibility = "visible"; }
	for (var i=0; i < tas.length; i++) { tas[i].style.overflow = "auto"; }
	hideSelects('unhide');
	bgd.className = "";
}

// Pops up a window with the contact form in it.
function showContactForm() {
	var argv=arguments;
	var cu=null;
	if (argv.length) {
		if (argv[0] == "feedback") {
			var sbTitle = "Feedback";
			cu = document.getElementById("feedbackHTML");
		}
	} else {
		var sbTitle = "Contact Us";
		cu = document.getElementById("contactUsHTML");
	}
	dimBackground();
	var cp = document.getElementById("popUp");
	thtml = cu.innerHTML;
	cu.innerHTML = "";
	preHideObj(cp);
	cp.innerHTML = "<div id='sbHeader'>" + sbTitle + "</div><div id='sbBody2'>" + thtml + "</div>";
	setTimeout("centerDiv('popUp');", 100);
}

// Send message submitted in contact form pop up. Enqueues message into AJAX.
function sendContact() {
	var cfe = document.getElementById("contactFormError");
	cfe.innerHTML = "";
	cfe.style.display = "none";
	var name = document.getElementById("contactName").value;
	var email = document.getElementById("contactEmail").value;
	var subject = document.getElementById("contactSubj").value;
	var message = document.getElementById("contactMsg").value;
	if (name.length && email.length && message.length) {
		document.getElementById("popUp").style.visibility = "hidden";
		name = name.replace(/&/g,"%26");
		email = email.replace(/&/g,"%26");
		message = message.replace(/&/g,"%26");
		var request = 'action=sendContactUs&name=' + name + '&email=' + email + '&subject=' + subject + '&body=' + escape(message);
		enqueueRequest('sendContactUs',urlroot+'/ajax/messages.php',request);
	} else {
		var err_array = new Array();
		if (!name.length) err_array.push("name");
		if (!email.length) err_array.push("email address");
		if (!message.length) err_array.push("message");
		cfe.innerHTML = "Please provide your ";
		for (var i=0; i < err_array.length; i++) {
			if (i > 0) cfe.innerHTML += ", ";
			cfe.innerHTML += err_array[i];
		}
		cfe.innerHTML += ".";
		cfe.style.display = "block";
	}
}

// Send message submitted in feedback form pop up. Enqueues message into AJAX.
function sendFeedback() {
	var ffe = document.getElementById("feedbackFormError");
	ffe.innerHTML = "";
	ffe.style.display = "none";
	var name = document.getElementById("feedbackName").value;
	var email = document.getElementById("feedbackEmail").value;
	var message = document.getElementById("feedbackMsg").value;
	if (name.length && email.length && message.length) {
		document.getElementById("popUp").style.visibility = "hidden";
		name = name.replace(/&/g,"%26");
		email = email.replace(/&/g,"%26");
		message = message.replace(/&/g,"%26");
		var request = 'action=sendFeedback&name=' + name + '&email=' + email + '&body=' + escape(message);
		enqueueRequest('sendFeedback',urlroot+'/ajax/messages.php',request);
	} else {
		var err_array = new Array();
		if (!name.length) err_array.push("name");
		if (!email.length) err_array.push("email address");
		if (!message.length) err_array.push("message");
		ffe.innerHTML = "Please provide your ";
		for (var i=0; i < err_array.length; i++) {
			if (i > 0) ffe.innerHTML += ", ";
			ffe.innerHTML += err_array[i];
		}
		ffe.innerHTML += ".";
		ffe.style.display = "block";
	}
}

// Pops up confirmation of message being sent or error.
function showContactResult() {
	if (http.readyState == 4) {
		var response = http.responseText;
		queueJump();
		if (response === "success") {
			popAlert('Contact us','Your message has been sent.');
		} else {
			popAlert('Contact error','There was a problem sending your message. Please try again.');
		}
		var cu = document.getElementById("contactUsHTML");
		cu.innerHTML = thtml;
	}
}

// Pops up confirmation of message being sent or error.
function showFeedbackResult() {
	if (http.readyState == 4) {
		var response = http.responseText;
		queueJump();
		if (response === "success") {
			popAlert('Feedback','Your feedback has been sent.');
		} else {
			popAlert('Feedback error','There was a problem sending your feedback. Please try again.');
		}
		var cu = document.getElementById("feedbackHTML");
		cu.innerHTML = thtml;
	}
}

function closeContactPop() {
	var cu = document.getElementById("contactUsHTML");
	cu.innerHTML = thtml;
	closePop();
}

function closeFeedbackPop() {
	var cu = document.getElementById("feedbackHTML");
	cu.innerHTML = thtml;
	closePop();
}

/*
// Preview pop up function used throughout the site.
function outputPreviewData() {
	if (http.readyState == 4) {
		dimBackground();
		var response = http.responseText;
		queueJump();
		var md = document.getElementById("previewPane");
		preHideObj(md);
		md.style.padding = "15px";
		md.innerHTML = response;
		setTimeout("centerDiv('previewPane');", 500);
		document.getElementById("popUp").style.display = "none";
		document.getElementById("popUp").style.visibility = "hidden";
	} else if (http.readyState == 1) {
		var loadimg = "<div><img src='" + img + "/loading.gif' border='0' /></div>";
		document.getElementById("popUp").innerHTML = loadimg;
		document.getElementById("popUp").style.padding = "0";
		document.getElementById("popUp").style.display = "block";
		document.getElementById("popUp").style.visibility = "hidden";
		setTimeout("centerDiv('popUp');", 10);
	}
}

// Function first called for displaying a snapshot. It sets a timeout to
// call the real function for AJAX fetching snapshots. This
// function also checks the cache to see whether or not that is necessary.
function showSnap(item,elem) {
	if (elem.id) {
		snapeid = elem.id;
	} else {
		var tDate = new Date();
		var rnd = Math.floor((tDate * Math.random()) / 1000);
		elem.id = rnd;
		snapeid = rnd;
	}
	var arrayPageSize = getPageSize();
	var ymidpoint = Math.ceil(arrayPageSize[3] / 2);
	var xmaxpoint = (arrayPageSize[2] - 400);
	snapypos = (tempY >= ymidpoint) ? "above" : "below";
	snapxpos = (tempX >= xmaxpoint) ? "left" : "right";
	if (!snapcache[item]) {
		if (typeof ajtimer == "number") {
			clearTimeout(ajtimer);
		}
		ajtimer = setTimeout('doShowSnap(' + item + ')',200);
	} else {
		snapdata = snapcache[item];
		ajtimer = setTimeout("showSnapShot(snapdata)",200);
	}
}

// This function makes the actual AJAX request for a snap shot.
function doShowSnap(item) {	
	var request = 'item=' + item + '&mode=snapshot&snappos=' + snapxpos + ':' + snapypos;
	enqueueRequest('getSnapshot','/post/preview.php',request);
	return overlib('<img src="' + img + '/indicator.gif" border="0">',OFFSETX,10,OFFSETY,-9,WIDTH,20,HEIGHT,20,BGCOLOR,'',FGCOLOR,'');
}

// Function to cancel any timeouts or active AJAX request for snapshots.
// Called by onMouseOut.
function noShow() {
	abortAJAX();
	if (typeof ajtimer == "number") {
		clearTimeout(ajtimer);
	}
	nd();
	hideSelects('unhide');
}

// Callback function of AJAX snap shot request.
function outputSnapShot() {
	if (http.readyState == 4) {
		var response = http.responseText;
		queueJump();
		var response_bits = response.split(":::");
 		var item = response_bits[0];
		response = response_bits[1];
		snapcache[item] = response;
		if (response != null) {
			showSnapShot(response);
		} else {
			return false;
		}
		
	}
}

// Function to actually display the snap shot. Takes into account orientation
// requirements based on mouse location in reference to page. Used for both new 
// AJAX snapshots and caches ones.
function showSnapShot(response) {
	var snaphtml = "";
	var snapbefore = "";
	var snapafter = "";
	hideSelects('hide');
	switch (snapxpos) {
		case "right":
			snapbefore += '<td><img src="' + img + '/snapbox_toplongl.png" style="width: 71px; height: 23px" alt="" /></td>';
			snapbefore += '<td><img src="' + img + '/snapbox_tc.png" style="width: 284px; height: 23px" alt="" /></td>';
			snapbefore += '<td><img src="' + img + '/snapbox_topshortr.png" style="width: 23px; height: 23px" alt="" /></td>';
			snapafter +=  '<td><img src="' + img + '/snapbox_bottomlongl.png" style="width: 71px; height: 23px" alt="" /></td>';
			snapafter +=  '<td><img src="' + img + '/snapbox_bc.png" style="width: 284px; height: 23px" alt="" /></td>';
			snapafter +=  '<td><img src="' + img + '/snapbox_bottomshortr.png" style="width: 23px; height: 23px" alt="" /></td>';
			break;
		case "left":
			snapbefore += '<td><img src="' + img + '/snapbox_topshortl.png" style="width: 23px; height: 23px" alt="" /></td>';
			snapbefore += '<td><img src="' + img + '/snapbox_tc.png" style="width: 284px; height: 23px" alt="" /></td>';
			snapbefore += '<td><img src="' + img + '/snapbox_toplongr.png" style="width: 71px; height: 23px" alt="" /></td>';
			snapafter +=  '<td><img src="' + img + '/snapbox_bottomshortl.png" style="width: 23px; height: 23px" alt="" /></td>';
			snapafter +=  '<td><img src="' + img + '/snapbox_bc.png" style="width: 284px; height: 23px" alt="" /></td>';
			snapafter +=  '<td><img src="' + img + '/snapbox_bottomlongr.png" style="width: 71px; height: 23px" alt="" /></td>';
			break;
	}
	var snappos = snapxpos + ":" + snapypos;
	
	var _100 = "<td height='76' valign='top' style='width: 71px; height: 76px'>";
	var _101 = "<img src='" + img + "/snapbox_@@@.png' style='width: 71px; height: 76px' alt='' /></td>";
	var _102 = "<td rowspan='2'><img id='snapStretchFull' src='" + img + "/snapbox_@@@.png' style='width: 23px; height: 1px' alt='' /></td>";
	var _103 = "<td><img id='snapStretch' src='" + img + "/snapbox_@@@.png' style='width: 71px; height: 1px' alt='' /></td>"
	switch (snappos) {
		case "right:below":
			var snapbleft = _100 + _101.replace(/@@@/, "leftuparr");
			var snapbright = _102.replace(/@@@/, "shortright");
			var snapother = _103.replace(/@@@/, "longleft");
			break;
		case "left:below":
			var snapbleft = _102.replace(/@@@/, "shortleft");
			var snapbright = _100 + _101.replace(/@@@/, "rightuparr");
			var snapother = _103.replace(/@@@/, "longright");
			break;
		case "right:above":
			var snapbleft = _103.replace(/@@@/, "longleft");
			var snapbright = _102.replace(/@@@/, "shortright");
			var snapother = _100 + _101.replace(/@@@/, "leftdnarr");
			break;
		case "left:above":
			var snapbleft = _102.replace(/@@@/, "shortleft");
			var snapbright = _103.replace(/@@@/, "longright");
			var snapother = _100 + _101.replace(/@@@/, "rightdnarr");
			break;
		default:
			var snapbleft = _100 + _101.replace(/@@@/, "leftuparr");
			var snapbright = _102.replace(/@@@/, "shortright");
			var snapother = _103.replace(/@@@/, "longleft");
			break;
	}
	
	snaphtml += '<table id="snapShotter" style="width:378px; z-index:1000" border="0" cellpadding="0" cellspacing="0"><tr>' + snapbefore + '</tr><tr>';
	snaphtml += snapbleft + '<td style="background: #fff" rowspan="2"><div id="snapContent" style="width: 284px; min-height:100px; margin: auto;">' + response;
	snaphtml += '</div></td>' + snapbright + '</tr><tr>' + snapother + '</tr><tr>' + snapafter + '</tr></table>';
	
	switch (snappos) {
		case "right:below":
			overlib(snaphtml,FULLHTML,FOLLOWMOUSE,RIGHT,BELOW,OFFSETX,10,OFFSETY,-38);
			stretchSnapDiv();
			break;
		case "left:below":
			overlib(snaphtml,FULLHTML,FOLLOWMOUSE,LEFT,BELOW,OFFSETX,180,OFFSETY,-38);
			stretchSnapDiv();
			break;
		case "right:above":
			overlib(snaphtml,FULLHTML,FOLLOWMOUSE,RIGHT,ABOVE,OFFSETX,10,OFFSETY,-40);
			stretchSnapDiv();
			break;
		case "left:above":
			overlib(snaphtml,FULLHTML,FOLLOWMOUSE,LEFT,ABOVE,OFFSETX,180,OFFSETY,-40);
			stretchSnapDiv();
			break;
		default:
			overlib(snaphtml,FULLHTML,FOLLOWMOUSE,OFFSETX,15,OFFSETY,-38);
			stretchSnapDiv();
			break;
	}
}

// Function finally makes certain that the bounding border images of
// the snapshot stretch to meet each other based on the dynamic content
// size.
function stretchSnapDiv() {
	var sch = document.getElementById("snapContent").clientHeight;
	if (sch < 100) {
		sch = 100;
		document.getElementById("snapContent").style.height = sch;
	}
	var newh = sch - 76;
	if (newh < 0) newh=0;
	document.getElementById("snapStretch").style.height = newh;
	document.getElementById("snapStretchFull").style.height = sch;
}

function clearSnapPreload() {
	if (document.getElementById("snappreloader")) {
		document.getElementById("snappreloader").innerHTML="";
	}
}
*/

// Function to empty defaul, instructional form field values.
// Will only clear the field if you pass the exact text you want cleared.
function clearValue(elem,disallow) {
	if (elem.value.length && elem.value==disallow) {
		elem.style.color = "#333";
		elem.style.background = "#fff";
		elem.value='';
	}
}

// Function to determine the size of a shadowbox pop up and center it on screen.
function centerDiv(d) {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var md = document.getElementById(d);
	var bgd = document.getElementById("bgDimmer");
	var winh = arrayPageSize[3];
	var winw = arrayPageSize[2];
	var popw = md.clientWidth;
	var poph = md.clientHeight;
	var popxloc = ((winw / 2) - (popw / 2));
	var popyloc = arrayPageScroll[1] + ((winh / 2) - (poph / 2));
	md.style.top = (popyloc < 0) ? "0px" : popyloc + "px";
	md.style.left = (popxloc < 0) ? "0px" : popxloc + "px";
	md.style.visibility = "visible";
	arrayPageSize = getPageSize();
	bgd.style.height = (arrayPageSize[1] + 'px');
	return;
}

function closePreview() {
	document.getElementById("previewPane").style.display = "none";
	unDimBackground();
}

// Site search.
/*
function submitSearch() {
	var s_str = document.getElementById("searchstr").value;
	//var scope = document.getElementById("scope").options[document.getElementById("scope").selectedIndex].value;
	var scope = document.getElementById("scope").value;
	if (s_str != "") {
		document.location.href = "http://www.campusdock.com/search/" + scope + "/" + s_str + "/";
	} else {
		popAlert("Search error","You haven't included a search word or phrase.");
	}
	return false;
}*/

// Functions below are for determining placements, positions and sizes.
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// Handle requests to browse textbooks by department.
/*
function browseDepartment(elem) {
	var deptid = elem.value;
	if (deptid != "") {
		location.href = urlroot + "/browse/forsale/textbooks/" + deptid + "/";
	} else {
		location.href = urlroot + "/browse/forsale/textbooks/";
	}
}*/

function changeIPP(p,elem) {
	var ipp = elem.value;
	location.href = p + "itemsperpage-" + ipp + ".html";
}

/*
function postModLink(elem,sid,sname,snick) {
	var sel = elem.value;
	if (sel != "") {
		if (sel != "events") {
			posturl = urlroot + "/post/" + sel + "/";
		} else {
			location.href = urlroot + "/events/index.php?action=add";
		}
	}
	doChangeSchool(sid,sname,snick,'quiet',posturl);
}
*/

function nullFunction() {
	var o=1;
}

function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(e.className == 'hidden')
		e.className = 'shown';
	else
		e.className = 'hidden';
}

// Some stuff to make hovering over divs do something in IE.
function hoverDiv(elem,onstyle,offstyle,dir) {
	if (IE) {
		switch(dir) {
			case "on":
				elem.className = onstyle;
				break;
			case "off":
				elem.className = offstyle;
				break;
		}
	}
}

// Hide a shadowbox popup object before you use it.
function preHideObj(obj) {
	obj.style.padding = "0";
	obj.style.display = "block";
	obj.style.visibility = "hidden";
}

/*
function showChangeSchools() {
	var request = 'action=showSchools';
	enqueueRequest('showSchools','/frontend/ajax/changeschool.php',request);
}

function showSchoolsOutput() {
	if (http.readyState == 4) {
		dimBackground();
		var response = http.responseText;
		queueJump();
		var sbTitle = "Change Schools";
		var cp = document.getElementById("popUp");
		preHideObj(cp);
		cp.innerHTML = "<div id='sbHeader'>" + sbTitle + "</div><div id='sbBody2'>" + response + "</div>";
		setTimeout("centerDiv('popUp');", 100);
	}
}

function doChangeSchool(id,name,nick) {
	var argv=arguments;
	var xtra = "";
	if (argv.length >= 4) {
		xtra = (argv[3] == "quiet") ? "&mode=quiet" : "";
		posturl = argv[4];
	}
	var request = 'action=changeSchools&id=' + id + '&name=' + name + '&nickname=' + nick + xtra;
	enqueueRequest('changeSchools','/frontend/ajax/changeschool.php',request);
}

function finishChangeSchool() {
	if (http.readyState == 4) {
		var response = http.responseText;
		queueJump();
		if (response == "success") {
			location.href = urlroot + "/";
		} else if (response == "success1") {
			location.href = posturl;
		}
	}
}

function showCatChanger(elem) {
	hideSelects('hide');
	var c = document.getElementById("catChooser");
	c.className='shown';
}

function showHeadCats(elem) {
	hideSelects('hide');
	var c = document.getElementById("headCatChooser");
	var cXY = findPos(elem);
	var cX = cXY[0];
	var pad = 248;
	if (IE) pad = 258;
	c.style.left = parseInt(cX - pad) + "px";
	//showCal(cal,elem.id);
	c.className='show';
}

function hideCats(elemid) {
	document.getElementById(elemid).className='hidden';
	hideSelects('unhide');
}
*/

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function stripHTML(){
	var re = /<\S[^><]*>/g;
	var re2 = /&lt;\S[^&gt;&lt;]*&gt;/g;
	var re3 = /&lt;.*&gt;/g;
	var clean = '';
	for (i=0; i<arguments.length; i++) {
		clean=arguments[i].replace(re, "");
		clean=clean.replace(re2, "");
		clean=clean.replace(re3, "");
		clean=clean.replace('&amp;','&');
	}
	return clean;
}

function showWhatsThis(which) {
	var sbTitle = "";
	var popcontent = "";
	var paneObj = document.getElementById("previewPane");
	preHideObj(paneObj);
	pane_orig_width = paneObj.style.width;
	paneObj.style.width = "550px";
	var buttons = "<div id='sbButtons'><input type='button' id='sdCloseButt' value='Close' onClick='closeHelp()' /></div>";
	switch(which) {
		case "grabimage":
			sbTitle = "Get an image from the web!";
			popcontent = "<div class='helpPop'>Find an image of your item anywhere on the web and import it directly to the Edit page. Here's how:<h3>Using a PC:</h3><p><span style='text-decoration:underline'>Mozilla Firefox:</span> Right click on the image and click 'Copy Image Location'. The paste it (Ctrl-V) into the text box and click 'add'.</p><p><span style='text-decoration:underline'>Internet Explorer:</span> Right click on the image and click 'Properties'. Copy image address (Ctrl-C) and paste it (Ctrl-V) into the text box. Then click 'add'.</p><h3>Using a Mac:</h3><p><span style='text-decoration:underline'>Mozilla Firefox:</span> Right click (Ctrl + mouse button) on the image and click 'Copy Image Location'. The paste it (Command + V) into the text box and click 'add'.</p><p><span style='text-decoration:underline'>Safari:</span> Right click (Ctrl + mouse button) on the image and click 'Copy Image Address'. The paste it (Command + V) into the text box and click 'add'.</p><div style='text-align:center'>" + buttons + "</div></div>";
			break;
		case "addattrib":
			sbTitle = "Adding custom attributes";
			popcontent = "<div class='helpPop'>Attributes help describe specific characteristics of your item. For example, if you are selling a couch, \"Material\" can be an attribute name and \"Leather\" can be an attribute value. Attributes help users find and learn more about your item. Click \"Add another attribute\" to add as many attributes as you want.<div style='text-align:center'>" + buttons + "</div></div>";
			break;
	}
	paneObj.innerHTML = "<div><div id='sbHeader'>" + sbTitle + "</div>" + popcontent + "</div>";
	dimBackground();
	setTimeout("centerDiv('previewPane');", 300);
	setTimeout("document.getElementById('sdCloseButt').focus();",400);
}

function closeHelp() {
	document.getElementById("previewPane").style.width = pane_orig_width;
	document.getElementById("previewPane").style.display = "none";
	unDimBackground();
}
