
if (! self.PincushionReleaseVersions)
  PincushionReleaseVersions = new Array();

PincushionReleaseVersions.push("$Id: site.js 4769 2008-12-01 07:27:54Z jonathan $");
///
// precaching is the law
///
websiteRootPath = "/";

var iCache = [
		{"w":116,"h":18,"src":websiteRootPath + "/images/b116_u.png"},
		{"w":116,"h":18,"src":websiteRootPath + "/images/b116_a.png"},
		{"w":116,"h":18,"src":websiteRootPath + "/images/b116_d.png"},
		{"w":116,"h":18,"src":websiteRootPath + "/images/b116_h.png"},
		{"w":80,"h":18,"src":websiteRootPath + "/images/b80_u.png"},
		{"w":80,"h":18,"src":websiteRootPath + "/images/b80_a.png"},
		{"w":80,"h":18,"src":websiteRootPath + "/images/b80_d.png"},
		{"w":80,"h":18,"src":websiteRootPath + "/images/b80_h.png"}
	]

function init()
{	
	for (var entry in iCache) {
		entry = iCache[entry]
		if (! entry || ! entry.h) continue
		var img = new Image(entry.w, entry.h)
		img.src = entry.src
	}
}


function getRootedUrl(url) {
    return websiteRootPath + url;
}

///
// dirty tricks from Prototype and elsewhere...
///
function e(thing)
{
    if (typeof(thing) == "string")
        return document.getElementById(thing)
    return null
}
//   Sam Stephenson has better kung fu than I
///      ...but you are not a Jedi yet.
var $A = Array.from = function(iterable) {
  if (!iterable) return []
  if (iterable.toArray) {
    return iterable.toArray()
  } else {
    var results = []
    for (var i = 0, length = iterable.length; i < length; i++)
      results.push(iterable[i])
    return results
  }
}
//   Sam Stephenson has better kung fu than I
function bind()
{
  var args = $A(arguments), object = args.shift(), __method = args.shift()
  return function() {
    return __method.apply(object, args.concat($A(arguments)))
  }
}

function trim(s)
{
	return rtrim(ltrim(s));
}
function ltrim(s)
{
	var l=0;
	while(l < s.length && s.substr(l, 1) == ' ') { l++; }
	return s.substring(l, s.length);
}
function rtrim(s)
{
	var r = s.length - 1;
	while(r > 0 && s.substr(r, 1) == ' ') { r--; }
	return s.substring(0, r + 1);
}

//*****************************
//     XML whatsits
//******************************

function escapeXml(str)
{
	switch (typeof(str)) {
		case "undefined":
			return ""
		case "string":
			break
		default:
			str = str.toString()
	}
	
	return str.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/&/g, "&amp;");
}

function unescapeXml(str)
{
	switch (typeof(str)) {
		case "undefined":
			return ""
		case "string":
			break
		default:
			str = str.toString()
	}
	
	return str.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
}


///
// Localization 
///
var pcStringTable = new Array() // the actual string table used by l10nLabel
var pcActiveLocale = new Array() // a stack of locale definitions that have been loaded

// lookup a tag and return the localized string equivalent
function l10nLabel(tag)
{
  if (pcStringTable[tag])
    return pcStringTable[tag]
    
  return "l10nLabel('"+tag+"') :: UNDEFINED"
}

///
// DHTML style shortcuts
///
function bColor(thing, color)
{
	if (! thing) return
	if (typeof(thing) == "string")
		thing = e(thing)
	if (! thing || ! thing.style) return

	thing.style.borderColor = color
}
function colorMeRGB(element, r, g, b)
{
	var color = "#" + colorD2H(r) + colorD2H(g) + colorD2H(b)
	colorMe(element, color)
}
var hD="0123456789ABCDEF";
function D2H(d) {
	var h = hD.substr(d&15,1)
	while(d>15) {d>>=4;h=hD.substr(d&15,1)+h}
	return h
}
function colorD2H(d)
{
	var h = D2H(Math.min(Math.max(d, 0), 255))
	if (h.length < 2) h = "0"+h
	return h
}
function colorMe(element, color)
{
	var lmnt = null
	if (typeof(element) == "string")
		lmnt = e(element)
	else
		lmnt = element
	
	if (lmnt && lmnt.style)
	{
		lmnt.style.color = color
	}
}
function enableControl(element, enable) 
{
	var lmnt = null
	if (typeof(element) == "string")
		lmnt = e(element)
	else
		lmnt = element
	
	if (lmnt && lmnt.enable) {
		if (enable)
			lmnt.enable()
		else
			lmnt.disable()
	}
}
function toggleVisibility(element) 
{
	var lmnt = null
	if (typeof(element) == "string")
		lmnt = e(element)
	else
		lmnt = element
	
	if (lmnt && lmnt.style) {
		if (lmnt.style.visibility == "hidden")
			setVisibility(lmnt, true)
		else
			setVisibility(lmnt, false)
	}
}
function setVisibility(element, visible)
{
	var lmnt = null
	if (typeof(element) == "string")
		lmnt = e(element)
	else
		lmnt = element
	
	if (lmnt && lmnt.style) {
		if (visible) {
			lmnt.style.visibility = "visible"	
			lmnt.style.display = ""
		}
		else {
			lmnt.style.visibility = "hidden"	
			lmnt.style.display = "none"
		}
	}
}
function isVisible(element)
{
	var lmnt = null
	if (typeof(element) == "string")
		lmnt = e(element)
	else
		lmnt = element
	
	if (lmnt && lmnt.style)
	{
	    if (lmnt.style.visibility == "hidden" || lmnt.style.visibility == "collapse" || lmnt.style.display == "none")
	        return false
    }
    return true
}

function setItemBackground(name, color) 
{
	var theitem = e(name)
	if (theitem)
		theitem.style.backgroundColor = color
}
function setItemColors(name, foreground, background) 
{
	var theitem = e(name)
	if (theitem && theitem.style) {
		theitem.style.color = foreground
		theitem.style.backgroundColor = background
	}
}


///
// For pretty buttons, call obXx at (503) xxx-xxxx
///
function obOv(thing)
{
	if (! thing.className) return
	thing.style.backgroundImage = "url(" + websiteRootPath + "/images/"+thing.className + "_h.png)"
}
function obOu(thing)
{
	if (! thing.className) return
	var bimg 
	if (thing.getAttribute("active"))
		bimg = "url(" + websiteRootPath + "/images/"+thing.className + "_a.png)"
	else
		bimg = "url(" + websiteRootPath + "/images/"+thing.className + "_u.png)"
	thing.style.backgroundImage = bimg
}
function obUp(thing)
{
	if (! thing.className) return
	thing.style.backgroundImage = "url(" + websiteRootPath + "/images/"+thing.className + "_h.png)"
}
function obDn(thing)
{
	if (! thing.className) return
	thing.style.backgroundImage = "url(" + websiteRootPath + "/images/"+thing.className + "_d.png)"
}
// manage visual state of a "button"
//  e.g. <span onmouseover="onMButton('over', this, 'button_60', false)" ...
function onMButton(evt, thing, button, stuck)
{
	if (! thing) return
	if (typeof(thing) == "string")
		thing = e(thing)
	if (! thing || ! thing.style) return
	
	var state = "up"
	
	switch (evt) {
		case 'over':
			state = "hover"
			break
		case 'out':
			if (stuck)
				state = "down"
			else
				state = "up"
			break
		case 'down':
			state = "down"
			break
		case 'up':
			state = "hover"
			break
	}
	
	thing.style.backgroundImage = "url(" + websiteRootPath + "/images/"+button+"_"+state+".png)"
}


///
// Active images
///
function getImgBtnSuffix(image) {
    if (!image) return;
    if (image.imgBtnState == "Down") {
        return "Down";
    } else {
        return "Up";
    }
}

function imgBtnOv(image, imagePrefix)
{
    if (!image || !imagePrefix) return;
	image.src = getRootedUrl("/images/" + imagePrefix + "Hover.png");
}

function imgBtnOu(image, imagePrefix)
{
    if (!image || !imagePrefix) return;
    var imageSuffix = getImgBtnSuffix(image);
    image.src = getRootedUrl("/images/" + imagePrefix + imageSuffix + ".png");
}

function imgBtnUp(image, imagePrefix)
{
    if (!image || !imagePrefix) return;
	image.src = getRootedUrl("/images/" + imagePrefix + "Hover.png");
}

function imgBtnDn(image, imagePrefix)
{
    if (!image || !imagePrefix) return;
    var imageSuffix = getImgBtnSuffix(image);
    image.src = getRootedUrl("/images/" + imagePrefix + imageSuffix + ".png");
}


///
// login popup helpers
///
function cLF(thing)
{
	if (thing.value == "username") {
		thing.value = ""
		thing.style.color = "black"
	}
}
function cL()
{
	var user = document.getElementById('username').value
	var pass = document.getElementById('password').value
	var remember = document.getElementById('rememberLogin').checked

	if (user.length < 4 || user == "username") {
		alert("Your username must be entered!")
		document.getElementById('username').focus()
		return false
	}
	if (pass.length < 4) {
		alert("Your password must be entered!")
		document.getElementById('password').focus()
		return false
	}
	
	return true
}
function onTopBarLoginLinkClick() {
    setVisibility(document.getElementById("topBarMixedPanel"), false);
    setVisibility(document.getElementById("topBarLoginPanel"), true);
    var usernameTextBox = document.getElementById("topBarUsername");
    if (usernameTextBox) usernameTextBox.focus();
}
function onTopBarSubmitLoginClick() {
    var topBarLoginForm = document.getElementById("topBarLoginForm");
    topBarLoginForm.submit();
}
function onTopBarCancelLoginClick() {
    setVisibility(document.getElementById("topBarMixedPanel"), true);
    setVisibility(document.getElementById("topBarLoginPanel"), false);
}


///
// everybody loves search; good thing we're not a search startup!
///
var pcSearchEngine = "google"

// search preferences handlers...
function onSelectWebSearch()
{
	setVisibility('search_options', true)
}
function onSetWebSearch(engine)
{
	pcSearchEngine = engine
	setVisibility('search_options', false)
	var ob = e('search_go_web')
	if (ob)
		ob.src = websiteRootPath + "/images/s_"+pcSearchEngine+".png"
}
function onUnselectWebSearch()
{
	setVisibility('search_options', false)
}

// Search event handlers
function onSearchPin()
{
	onSearch("pincushion")
}
function onSearchWeb()
{
	onSearch("the web")
}
function onKp_search(evt)
{
	var ob = e('topBarSearch')
	if (ob && (ob.value == "Search..." || ob.value == l10nLabel("SEARCH_WATERMARK")))
		ob.value = ""

	if (evt != null) {
  		var knum = null
  		if(window.event) // IE
  			knum = evt.keyCode
  		else if (evt.which)
  			knum = evt.which
  		
  		if (knum == 13 || knum == 10)
  			onSearch("")
  	}	
}
function onSearch(whereTo)
{
	var ob = e('topBarSearch')
	if (! ob) return
	
	if (ob.value && ob.value != "Search..." && ob.value != l10nLabel("SEARCH_WATERMARK"))
	{
	    var url = web_base+"/My/Search.aspx?q="+escape(ob.value);
	    if (whereTo == "the web")
	        url += "&t="+escape(pcSearchEngine)
	    document.location = url
	}
	else
		ob.focus()
}

// Feed me 'dat feeedback
var feedbackDialog = null
function openFeedback()
{
	if (feedbackDialog) feedbackDialog.close()
	feedbackDialog = window.open("/feedback/", "feedback", 
						 "height=400,width=500,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no")
    
}
/* Release Prep 
Mon 04/28/2008 
03:51 PM
*/ 
/* Release Prep 
Tue 04/29/2008 
11:47 AM
*/ 
/* Release Prep 
Thu 05/01/2008 
11:33 AM
*/ 
/* Release Prep 
Thu 05/01/2008 
04:38 PM
*/ 
/* Release Prep 
Fri 05/02/2008 
03:00 PM
*/ 
/* Release Prep 
Wed 05/28/2008 
05:19 PM
*/ 
/* Release Prep 
Tue 06/03/2008 
10:16 AM
*/ 
/* Release Prep 
Wed 06/18/2008 
02:26 PM
*/ 
/* Release Prep 
Fri 06/20/2008 
10:58 AM
*/ 
/* Release Prep 
Mon 06/23/2008 
12:58 PM
*/ 
/* Release Prep 
Thu 06/26/2008 
04:58 PM
*/ 
/* Release Prep 
Fri 06/27/2008 
05:48 PM
*/ 
/* Release Prep 
Tue 07/01/2008 
12:36 PM
*/ 
/* Release Prep 
Tue 07/08/2008 
11:07 AM
*/ 
/* Release Prep 
Fri 07/11/2008 
04:02 PM
*/ 
/* Release Prep 
Tue 07/15/2008 
11:20 AM
*/ 
/* Release Prep 
Mon 07/21/2008 
03:45 PM
*/ 
/* Release Prep 
Sun 07/27/2008 
11:58 PM
*/ 
/* Release Prep 
Wed 08/27/2008 
03:27 PM
*/ 
/* Release Prep 
Tue 09/02/2008 
12:22 PM
*/ 
/* Release Prep 
Wed 09/10/2008 
09:55 PM
*/ 
/* Release Prep 
Mon 11/03/2008 
11:26 AM
*/ 
/* Release Prep 
Thu 11/06/2008 
02:36 PM
*/ 
/* Release Prep 
Sun 11/30/2008 
11:27 PM
*/ 
