// Search box functions
//////////////////////////////////////////////////////////////////////////////////////
function sBoxFocus() {
	
	
}

function sBoxBlur() {
	
	
}

function sBoxChange() {
	
	
}





// Hover functions
//////////////////////////////////////////////////////////////////////////////////////
function addEvent(elm, evType, fn, useCapture) {
	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 added");
	}
}
// homepage only
function labels_setup() {
	labels_init("hc-login");
	labels_init("acc-login");
	labels_init("or-login");
	labels_init("searchblock");
}
addEvent(window, "load", labels_setup);

//==============================================================================
// labels.js 1.0
// lives at : www.thestandardhack.com/components/labels.html (soon my friend)
// born by  : aaron boodman aaron@youngpup.net www.youngpup.net
// reporposed for SunRocket by NavigationArts: navarts.com
//==============================================================================
// this file uses the html label element to create one of those chill default 
// label things for form elements that flicks on and off when you focus and 
// blur the element.
//
// some cool features: 
//  - it uses event listening, so it doesn"t interfere with anything else.
//  - it"s easy to use: just drop this file in the head of your document.
//  - it degrades (users see traditional HTML labels)
//  - it cleans itself up before unload so that labels are never accidentally
//    submitted through forms.
//
// everything would be alot simpler if IE would just let you change the type
// of an input element (as mozilla does and the spec requires)
//==============================================================================

//==============================================================================
// Setup
//==============================================================================
// - turn display of labels off
// - initialize all labels
// - arrange for uninit to be called before any form submissions
//==============================================================================
function labels_init(container) {
	if (document.getElementById && document.getElementsByTagName) {
		try {
			if(document.getElementById(container)) {
				// check to see if there is a password field, because if there is, we don"t want 
				// to hide the form fields in browsers that don"t support type switching (Safari)
				var els = document.getElementById(container).getElementsByTagName("input");
				var i = 0;
				var hasPassword = false;
				while (i < els.length) {
					if(els[i].getAttribute("type") == "password") {
						hasPassword = true;
					}
					i++;
				}
				
				// now go through the labels
				var els = document.getElementById(container).getElementsByTagName("label");
				var i = 0;
				while (i < els.length) {
					if(navigator.appVersion.match(/Safari\/\d+$/) != null &&
					   hasPassword == true) { }
					else {
						//els[i].parentNode.className += " nolabel";
					//	els[i].className += " nolabel";
						label_init(els[i]);
					}
					i++;
				}
			}
			
			// now uninit for the forms when submitting
			var els = document.getElementById(container).getElementsByTagName("form");
			var i = 0;
			while (i < els.length) {
				addEvent(els[i], "submit", labels_uninit);
				i++;
			}
		} 
		catch (e) { }
	}
}
	


// tear-down.
// - clear all labels so they don"t accidentally get submitted to the server
function labels_uninit(e) {
	if (document.getElementById && document.getElementsByTagName) {
		for (var i = 0, label = null; 
			(label = document.getElementsByTagName("label")[i]); 
			i++) 
		{
			var el = document.getElementById(label.htmlFor);
			if (el && el.value == el._labeltext) label_hide(el);
		}
	}
}
	



// initialize a single label.
// - only applicable to textarea and input[text] and input[password]
// - arrange for label_focused and label_blurred to be called for focus and blur
// - show the initial label
// - for other element types, show the default label
function label_init(label) {
	try {
		var el = document.getElementById(label.htmlFor);
		var elName = el.nodeName;
		var elType = el.getAttribute("type");

		if (elName == "TEXTAREA" 
		|| (elType == "text" || elType == "password")) {
			el._labeltext = label.firstChild.nodeValue;
			el._type = el.getAttribute("type");
			addEvent(el, "focus", label_focused);
			addEvent(el, "blur", label_blurred);
			label_blurred({currentTarget:el});
		} else {
			label.style.position = "static";
			label.style.visibility = "visible";
		}
	}
	catch (e) { 
		label.style.position = "static";
		label.style.visibility = "visible";
	}
}




function label_focused(e) {
	e = fix_e(e);
	var el = e.currentTarget;
	if (el.value == el._labeltext) el = label_hide(el);
	el.focus();
	// without this extra focus() the script doesn"t focus on PASSWORD fields in MSIE
	el.focus();
}

function label_hide(el) {
	if (el._type == "password") el = label_setInputType(el, "password");
	el.value = "";
	return el;
}

function label_blurred(e) {
	e = fix_e(e);
	var el = e.currentTarget;
	if (el.value == "") el = label_show(el);
}

function label_show(el) {
	if (el._type == "password") el = label_setInputType(el, "text");
	el.value = el._labeltext;
	return el;
}



//==============================================================================
// XXX hack:
//==============================================================================
// msie won"t let us change the type of an existing input element, so to get this 
// functionality, we need to create the desired element type in an HTML string.
//==============================================================================
function label_setInputType(el, type) {
	if (navigator.appName == "Microsoft Internet Explorer") {
		var newEl = document.createElement("SPAN");
		newEl.innerHTML = '<input type="' + type + '" />';
		newEl = newEl.firstChild;
		var s = "";
		for (prop in el) {
			// some properties are read-only
			try {
				// the craziest browser bug ever: "height" and "width" (which 
				// should not even exist) return totally garbage numbers, like 
				// 458231 for instance, so we need to ignore those.
				if (prop != "type"
				 && prop != "height"
				 && prop != "width") newEl[prop] = el[prop];
			} 
			catch(e) { }
		}
		addEvent(newEl, "focus", label_focused);
		addEvent(newEl, "blur", label_blurred);
		el.parentNode.replaceChild(newEl, el);
		return newEl;
	} else {
		el.setAttribute("type", type);
		return el;
	}
}


// makes ie behave like a sc browser with regard to events
function fix_e(e) {
	if (!e && window.event) e = window.event;
	if (!e.currentTarget && e.srcElement) e.currentTarget = e.srcElement;
	if (!e.originalTarget && e.srcElement) e.originalTarget = e.srcElement;

	return e;
}

sfrHover = function() {
	var naEls = ["nav", "help-dd"];
	var c = 0;
	while (c < naEls.length)
	{
		if (document.getElementById(naEls[c]))
		{
			var sfEls = document.getElementById(naEls[c]).getElementsByTagName("li");
			for (var i=0; i<sfEls.length; i++) {
				if (sfEls[i].parentNode.id == naEls[c]) {
					sfEls[i].onmouseover=function() {
						this.className+=" sfhover";
					}
					sfEls[i].onmouseout=function() {
						this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					}
				}
			}
		}
	c++;
	}
}
if (window.attachEvent) window.attachEvent("onload", sfrHover);



/////////////////////////////////
var sBoxModified = false;


function sBoxFocus() {
	var sBox = document.forms['searchblock'].stext;
	if (!sBoxModified)
		sBox.value = "";
}

function sBoxBlur() {
	var sBox = document.forms['searchblock'].stext;
	if ((!sBoxModified) || (sBox.value == "")) {
		sBox.value = "Search";
	} 
}

function sBoxChange() {
	window.status = "Change ";
	var sBox = document.forms['searchblock'].stext;
	if (sBox.value != "")
		sBoxModified = true;
}

function sBoxOnSubmit () {
	var sBox = document.forms['searchblock'].stext;
	if ((!sBoxModified) || (sBox.value == "")) {
		sBox.value = "Enter search term!";
		return false;
	} else
		return true;
}



