var defaultTextLabels = new Array();

function validateSearchQuery(e) {
	if (defaultTextLabels[e.id] == null) {
		e.value = "";
	}
	return true;
}

// Clears the specified element's value if it contains
// its initial value. This value is stored for later retrieval
// in the global array defaultTextLabels and called upon
// in the blurInput() function.
function focusInput(elem) {
	
	if ( (elem.id != '') && (defaultTextLabels[elem.id] == null) ) {
		defaultTextLabels[elem.id] = elem.value;
		defaultText = elem.value;
	} else {
		defaultText = defaultTextLabels[elem.id];
	}
	
	if (!defaultText || elem.value == defaultText) {
		elem.value = '';
	}
}

// resets the specified element's value with its default text
// (if focusInput() was previously invoked with the element and its
// initial value has been stored)
function blurInput(elem) {
	if ( (defaultTextLabels[elem.id] != null) && (elem.value == '') ) {
		elem.value = defaultTextLabels[elem.id];
	}
}

function popup(url, name, width, height) {
	if (!width) {
		width = 795;
	}
	if (!height) {
		height = 600;
	}
	if (!name) {
		name = "azd_win";
	}
	var x = (screen.width - width) / 2;
	var y = (screen.height - height) / 2;
	var attributes = 'scrollbars=no,resizable=no,location=no,dependent=no,toolbar=no,width=' + width + ',height=' + height + ',left=' + x + ',top=' + y;
	window.open(url, name, attributes).focus();
	return false;
}


function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
	
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


// getElementsByClass implementation by Dustin Diaz
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// inserts a flash movie via FlashObject.
function insertFlashObject(id) {
	var e = document.getElementById(id);
	var source = e.attributes.getNamedItem("flashobject").nodeValue;
	var values = source.split(";");
	var conf = new Array();
	var len = values.length;
	var kv = null;

	for (var i = 0; i < len; i++) {
		kv = values[i].split(":");
		if (kv[0] != undefined && kv[1] != undefined) {
			conf[kv[0]] = kv[1];
			document.write("<!--" + kv[0] + ":" + kv[1] + " -->\n");
		}
	}
	var fo = new FlashObject(conf["src"], id, conf["width"], conf["height"], conf["version"], conf["background"], conf["detect"].toLowerCase() == "true");
	if (fo != null) {
		fo.write(id);
	}
}

function init() {
	// fix for short columns
	if (document.all && document.getElementById) {
		var columnWrapper = document.getElementById('column-wrapper');
		var columnContent = document.getElementById('content');
		var columnSubnavBar = document.getElementById('subnavbar');
		var maxHeight = Math.max(columnContent.offsetHeight, columnSubnavBar.offsetHeight);
		
		// shifty fix
		if (navigator.appVersion.indexOf("MSIE 7") > -1) {
			// IE >= 7
			columnContent.offsetHeight = 0;			
		} else {
			// IE < 7
			columnContent.style.position = "absolute";
			columnContent.style.top = "0";
		}
		columnContent.style.height = maxHeight + "px";
		columnWrapper.style.height = (maxHeight+1) + "px";
	}
}
