// 	dojo.place('<div class="errorTextMessage displayMe">We couldn\'t verify your details. Please try again.</div>', dojo.byId('accountSignInMessages'), 'first');
function reloadPage() {
	location.reload(true);
	return true;
}

/* captcha retrieval system */
function captcha_refresh(id) {
	if (e = dojo.byId(id)) {
		dv=new Date();
		e.src="captcha/?dummy=" + dv.getTime() + id.length;
		return false;
	}
}
function captcha_main_load_handler()  { captcha_refresh('captcha'); }
function captcha_mail_load_handler()  { captcha_refresh('captcha'); }
function captcha_unload_handler()  { } 
dojo.addOnLoad(captcha_main_load_handler);
/* captcha refresh */
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

window.onresize = function() {
	resizeBackground();
	resizeContentBox();
}

function resizeContentBox() {
	if (window.innerHeight) {
		locatorHeight = window.innerHeight;
	} else {
		locatorHeight = document.documentElement.clientHeight;
	}
	var div = dojo.byId('contentBoxOuter');
	div.style.height = (locatorHeight-180)+'px'; 
}

function resizeBackground() {
	var db=document.body;
	var img = dojo.byId('backgroundImage');

	var dbsize={}; //needed to store body size
	var imgsrc=img.src; //needed to store images src
	var keyStop=function(e){
		var e=window.event||e||{};
		var tag=e.target.tagName.toLowerCase();
		if(tag!='textarea'&&!(tag=='input'&&(e.target.type=='text'||e.target.type=='password'))){ //are the user not writing?
			if(e.keyCode==32||e.keyCode==39||e.keyCode==40){ //Did he press any of the "scrolling-keys"? (down, right, and space key)
				if(e.preventDefault)e.preventDefault();
				else e.returnValue=false;
			}
		}
	}

	if(this.addEventListener)window.addEventListener('keydown',keyStop,false);
	else window.attachEvent('onkeydown',keyStop);
		window.scrollTo(0,0);
		if(img.complete){ //check if image has loaded
			if(db.clientWidth!=dbsize.w||db.clientHeight!=dbsize.h||img.src!=imgsrc){ //check if size or img size has changed
				imgsrc=img.src; //store current src
				dbsize.w=db.clientWidth; //store current body width
				dbsize.h=db.clientHeight; //store current body height

				var newwidth=Math.round(dbsize.h*(img.offsetWidth/img.offsetHeight)); //calculate new width based on height

				img.style.width=(dbsize.w>newwidth?dbsize.w:newwidth)+'px'; //use the largest value of body-width and newwidht
				//and this is the real trick: if there's no specified height, the height is automaticly calculated relative to the with
			}
		} 
	}
function initBackground(img) {
	// initialise 
	var currentImage = dojo.byId('backgroundImage');
	if (img == undefined) {
		var newImage = new Image();
		newImage.src = randomBackground();
		if (newImage.src == currentImage.src) {
			newImage.src = randomBackground();
		}
	} else {
		var newImage = new Image();
		newImage.src = img;
	}


	if (newImage.complete) {

		var contentNode = dojo.byId('backgroundImageHolder');
		imageAnimateIn = dojo.fadeIn({
							node: contentNode,
							delay:0,
							duration:500
							});
		imageAnimateOut = dojo.fadeOut({
							node: contentNode,
							delay:0,
							duration:500,
							onEnd: function() {
										currentImage.src = newImage.src;
										resizeBackground();
										imageAnimateIn.play();
									}
							}).play();

//		currentImage.src = newImage.src;
		setTimeout('initBackground()', 30000);		
	} else {	// image hasn't loaded. wait for it
		setTimeout('initBackground("' + newImage.src + '")', 250);		
	}
}

	function pauseBGAnim() {
		window.runBackgroundAnimation = false;
//		window.backgroundAnimation.stop();
	}
	function playBGAnim() {
		window.runBackgroundAnimation = true;
		setInterval('setAutoChangeBackgrounds()', 5000);
	}
