function xn_js_getElement(element) {
	if (typeof(element) == 'string') {
		return document.getElementById(element);
	}
	return element;
}

function xn_js_toggle(element, display) {
	element = xn_js_getElement(element);
	if (element.style.visibility == "hidden"){
		xn_js_show(element, display);
	}
	else {
		xn_js_hide(element);
	}
}

function xn_js_show(element, display) {
	element = xn_js_getElement(element);
	element.style.visibility="visible";
	// Change back to 'block' unless specified otherwise.
	if (typeof(display) == "undefined" || display.length == 0) {
		element.style.display="block";
	} else {
		element.style.display=display;
	}
}

function xn_js_hide(element) {
	element = xn_js_getElement(element);
	element.style.visibility="hidden";
	element.style.display="none";
}

function xn_js_focusAndSelect(element) {
	element = xn_js_getElement(element);
	if (element != null) {
		element.focus();
		element.select();
	}
}

function xn_js_kill(e) {
	if (!e && window['event']) {
		e = window.event
	}
	e.cancelBubble = true;
	if (e.stopPropagation) {
		e.stopPropagation();
	}
	return false;
}

function xn_js_focusTextfield(e, defaultText, removeClass) {
	var input = e.srcElement || e.target;
	if (input.value == defaultText) {
		input.value = '';
		var newClasses = [];
		var oldClasses = input.className.split(' ');
		for (var i = 0; i < oldClasses.length; ++i) {
			var c = oldClasses[i];
			if (c && c != removeClass) {
				newClasses.push(c);
			}
		}
		input.className = newClasses.join(' ');
	}
}

function xn_js_blurTextfield(e, defaultText, addClass) {
	var input = e.srcElement || e.target;
	if (input.value == '') {
		input.className = input.className + " " + addClass;
		input.value = defaultText;
	}
}

function showInputLimit(input, output, limit)
{
	input = xn_js_getElement(input);
	output = xn_js_getElement(output);
	var charsLeft = limit - input.value.length;
	output.style.color = (charsLeft < 0 ? "#f00" : "");
	output.innerHTML = "(" + charsLeft + " letters remaining)";
	return charsLeft > 0;
}

/***********************************************
* WinXP Progress Bar- By Brian Gosselin- http://www.scriptasylum.com/
* Script featured on Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
***********************************************/
// xp_progressbar
// Copyright 2004 Brian Gosselin of ScriptAsylum.com
//
// v1.0 - Initial release
// v1.1 - Added ability to pause the scrolling action (requires you to assign
//        the bar to a unique arbitrary variable).
//      - Added ability to specify an action to perform after a x amount of
//      - bar scrolls. This requires two added arguments.
// v1.2 - Added ability to hide/show each bar (requires you to assign the bar
//        to a unique arbitrary variable).

// var xyz = xn_js_createBar(
// total_width,
// total_height,
// background_color,
// border_width,
// border_color,
// block_color,
// scroll_speed,
// block_count,
// scroll_count,
// action_to_perform_after_scrolled_n_times
// )

/* helper function added for Ning usage
 * (we've also prefixed all the functions with xn_js_)
 */
function xn_js_showProgressBar(mainUrl) {
	document.getElementById('xn_progress').style.visibility = 'visible';
	document.getElementById('xn_progress').style.display = 'block';
	bar.xn_js_togglePause();
	// Trick Safari into continuing the progress-bar animation after the click by loading an animated gif [Jon Aquino 2006-01-26]
	var img = document.getElementById('dummyAnimatedGif');
    if (img && img.src) {
        img.src = mainUrl + '/xnstatic/wait.gif';
    }
    return true;
}

var w3c=(document.getElementById)?true:false;
var ie=(document.all)?true:false;
var N=-1;

function xn_js_createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action){
	if(ie||w3c){
		var t='<div id="_xpbar'+(++N)+'" style="visibility:visible; position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
		t+='<span id="blocks'+N+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
		for(var i=0;i<blocks;i++){
			t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
			t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
			t+='"></span>';
		}
		t+='</span></div>';
		document.write(t);
		var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
		bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N);
		bA.blocks=blocks;
		bA.N=N;
		bA.w=w;
		bA.h=h;
		bA.speed=speed;
		bA.ctr=0;
		bA.count=count;
		bA.action=action;
		bA.xn_js_togglePause=xn_js_togglePause;
		bA.showBar=function(){
			this.bar.style.visibility="visible";
		}
		bA.hideBar=function(){
			this.bar.style.visibility="hidden";
		}
		// bA.tid=setInterval('xn_js_startBar('+N+')',speed);
		bA.tid = 0
		return bA;
	}
}
function xn_js_startBar(bn){
	var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
	if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
		t.style.left=-(t.h*2+1)+'px';
		t.ctr++;
		if(t.ctr>=t.count){
			eval(t.action);
			t.ctr=0;
		}
	}else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
}
function xn_js_togglePause(){
	if(this.tid==0){
		this.tid=setInterval('xn_js_startBar('+this.N+')',this.speed);
	}else{
		clearInterval(this.tid);
		this.tid=0;
	}
}

function xn_js_getScreenWidth(){
    return screen.width;
 }

function xn_js_getScreenHeight(){
    return screen.height;
}

function xn_js_getWindowX(){
    return window.screenLeft || window.screenX || "" ;
}

function xn_js_getWindowY(){
    if (window.screenLeft) return window.screenTop;
    else if (window.screenX) return window.screenY;
    else return "";
}

function xn_js_getViewportWidth()
{
    if (window.innerWidth) return window.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
    else if (document.body.clientWidth) return document.body.clientWidth;
    return "";
}

function xn_js_getViewportHeight()
{
    if (window.innerWidth) return window.innerHeight;
    if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientHeight;
    else if (document.body.clientWidth) return document.body.clientHeight;
    return "";
}

function xn_js_getScrollHorizontal()
{
    if (window.innerWidth) return window.pageXOffset;
    else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.scrollLeft;
    else if (document.body.clientWidth) return document.body.scrollLeft;
    return "";
}

function xn_js_getScrollVertical()
{
    if (window.innerWidth) return window.pageYOffset;
    else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.scrollTop;
    else if (document.body.clientWidth) return document.body.scrollTop;
    return "";
}

