	var regionHttp
	function listRegions() {
		document.getElementById("region-wrap").innerHTML="<img src='/css/images/loading.gif'>"
		country = document.getElementById("country").value;
		regionHttp=GetXmlHttpObject()
		if (regionHttp==null) return
		var url="/ajax/regions/" + country + "/"
		regionHttp.onreadystatechange=regionState
		regionHttp.open("GET",url,true)
		regionHttp.send(null)
	}
	function regionState() {
		if (regionHttp.readyState==4 || regionHttp.readyState=="complete") {
			document.getElementById("region-wrap").innerHTML=regionHttp.responseText
		} 
	}


// CAPTCHA
var captchaHttp
function loadCaptcha() {
	captchaHttp=GetXmlHttpObject()
	if (captchaHttp==null) return
	var url="/ajax/captcha/"
	captchaHttp.onreadystatechange=captchaState
	captchaHttp.open("GET",url,true)
	captchaHttp.send(null)
}
function captchaState() {
	if (captchaHttp.readyState==4 || captchaHttp.readyState=="complete") {
		guid = captchaHttp.responseText
		document.getElementById("hash").value = guid
		document.getElementById("captcha").src = "/core/captcha/" + guid + ".gif"
	} 
}


// Pop-up player
function openRadioPlayer(width,height,audio,show) {
	if (audio == "") window.open ('/player/', 'player', config='height='+height+', width='+width+', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	if (audio != "") window.open ('/player/' + audio + '/' + show + '/', 'player', config='height='+height+', width='+width+', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	}


// Registration Form Help Text
function showHelpText(field) {
	if (document.getElementById(field).value == "") {
		if (field == "username") document.getElementById("username-result").innerHTML = "<span class='input-help'>Enter a unique username</span>";
		if (field == "name") document.getElementById("name-result").innerHTML = "<span class='input-help'>Enter your full name</span>";
		if (field == "email") document.getElementById("email-result").innerHTML = "<span class='input-help'>Enter your email address</span>";
		if (field == "confemail") document.getElementById("confemail-result").innerHTML = "<span class='input-help'>Re-enter your email address</span>";
		if (field == "pass1") document.getElementById("pass1-result").innerHTML = "<span class='input-help'>Enter your chosen password</span>";
		if (field == "pass2") document.getElementById("pass2-result").innerHTML = "<span class='input-help'>Re-enter your chosen password</span>";
	}
}
function checkName() {
	if (document.getElementById("name").value == "") document.getElementById("name-result").innerHTML = "<span class='input-fail'>This should be your full name</span>";
	if (document.getElementById("name").value != "") document.getElementById("name-result").innerHTML = "<span class='input-pass'>OK</span>";
}
function checkPass() {
	if (document.getElementById("pass1").value == "") document.getElementById("pass1-result").innerHTML = "<span class='input-fail'>Should be at least 8 characters long</span>";
	if (document.getElementById("pass1").value.length < 8) document.getElementById("pass1-result").innerHTML = "<span class='input-fail'>Too short</span>";
	if (document.getElementById("pass1").value.length >= 8) document.getElementById("pass1-result").innerHTML = "<span class='input-pass'>OK</span>";
	if (document.getElementById("pass2").value == "") document.getElementById("pass2-result").innerHTML = "<span class='input-help'>Re-enter your chosen password</span>";
	if ((document.getElementById("pass2").value.length >= 1) && (document.getElementById("pass2").value.length < 8)) document.getElementById("pass2-result").innerHTML = "<span class='input-fail'>Too short</span>";
	if ((document.getElementById("pass2").value.length >= 8) && (document.getElementById("pass1").value != document.getElementById("pass2").value)) document.getElementById("pass2-result").innerHTML = "<span class='input-fail'>Passwords entered do not match</span>";
	if ((document.getElementById("pass2").value.length >= 8) && (document.getElementById("pass1").value == document.getElementById("pass2").value)) document.getElementById("pass2-result").innerHTML = "<span class='input-pass'>OK</span>";
}

// Check username availability
var usernameHttp
function checkUsername() {
	document.getElementById("username-f").value = trimVar(document.getElementById("username-f").value)
	input = document.getElementById("username-f").value
	if (input == "") document.getElementById("username-result").innerHTML = "<span class='input-fail'>This should be a unique username</span>";
	if (input != "") {
		document.getElementById("username-result").innerHTML="<span class='input-help'>Checking availability <img src='/css/images/registration-loading.gif' width='15' height='15'></span>"
		usernameHttp=GetXmlHttpObject()
		if (usernameHttp==null) return
		var url="/ajax/checkusername/" + input + "/"
		usernameHttp.onreadystatechange=usernameState
		usernameHttp.open("GET",url,true)
		usernameHttp.send(null)
	}
}
function usernameState() {
	if (usernameHttp.readyState==4 || usernameHttp.readyState=="complete") {
		document.getElementById("username-result").innerHTML = usernameHttp.responseText
	} 
}
function trimVar(input) {
	// Remove spaces
	input = input.split(" ");
	input = input.join("");
	// Remove punctuation
	input = input.split("-");
	input = input.join("");
	input = input.split(".");
	input = input.join("");
	input = input.split("[");
	input = input.join("");
	input = input.split("]");
	input = input.join("");
	input = input.split("{");
	input = input.join("");
	input = input.split("}");
	input = input.join("");
	input = input.split(",");
	input = input.join("");
	input = input.split("'");
	input = input.join("");
	input = input.split("!");
	input = input.join("");
	input = input.split("&");
	input = input.join("and");
	input = input.split("?");
	input = input.join("");
	input = input.split("Â£");
	input = input.join("");
	input = input.split("$");
	input = input.join("");
	input = input.split("%");
	input = input.join("");
	input = input.split("^");
	input = input.join("");
	input = input.split("*");
	input = input.join("");
	input = input.split("(");
	input = input.join("");
	input = input.split(")");
	input = input.join("");
	input = input.split("+");
	input = input.join("");
	input = input.split("=");
	input = input.join("");
	input = input.split(";");
	input = input.join("");
	input = input.split(":");
	input = input.join("");
	input = input.split('"');
	input = input.join("");
	input = input.split(">");
	input = input.join("");
	input = input.split("<");
	input = input.join("");
	input = input.split("/");
	input = input.join("");
	input = input.split("`");
	input = input.join("");
	return input;
}


function checkEmail() {
	email = document.getElementById("email").value;
	if (email == "") document.getElementById("email-result").innerHTML = "<span class='input-fail'>This should be your email address</span>";
	if (email != "") {
		error = checkEmailAddress(email);
		if (error == true) document.getElementById("email-result").innerHTML = "<span class='input-fail'>This is not a valid email address</span>";
		if (error == false) {
			exists = lookupEmail(email);
			if (exists == true) document.getElementById("email-result").innerHTML = "<span class='input-fail'>This email address is already in use</span>";
			if (exists == false) document.getElementById("email-result").innerHTML = "<span class='input-pass'>OK</span>";
		}
	}
}

function checkEmailAddress(emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {
return true;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
return true;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
return true;
   }
}

if (user.match(userPat)==null) {
return true;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
return false;
   }
}
return false;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
return true;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
return true;
}

if (len<2) {
return true;
}

return false;
}





var emailHttp
function lookupEmail(email) {
	var email = email.replace(/\./g, "[dot]");
	document.getElementById("email-result").innerHTML="<span class='input-help'>Checking email <img src='/css/images/registration-loading.gif' width='15' height='15'></span?"
	emailHttp=GetXmlHttpObject()
	if (emailHttp==null) return
	var url="/ajax/checkemail/" + email + "/"
	emailHttp.onreadystatechange=emailState
	emailHttp.open("GET",url,true)
	emailHttp.send(null)
}
function emailState() {
	if (emailHttp.readyState==4 || emailHttp.readyState=="complete") {
		document.getElementById("email-result").innerHTML = emailHttp.responseText
	} 
}







// sfHover = function() {
//	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
//	for (var i=0; i<sfEls.length; i++) {
//		sfEls[i].onmouseover=function() {
//			this.className+=" sfhover";
//			this.style.zIndex=200; //this line added to force flyout to be above relatively positioned stuff in IE
//		}
//		sfEls[i].onmouseout=function() {
//			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
//		}
//	}
//}
//if (window.attachEvent) window.attachEvent("onload", sfHover);



	function popupLogin(id) {
		if (id == 0) document.getElementById("login").style.display = 'none';
		if (id == 1) document.getElementById("login").style.display = 'block';
	}




	function showTANDC(id) {
		if (id == 0) document.getElementById("formTAC").style.display = 'none';
		if (id == 1) document.getElementById("formTAC").style.display = 'block';
	}



function countChar(obj,limit,target)
{
	if (obj.value.length > limit) obj.value = obj.value.substring(0, limit);
	numDisp = limit-obj.value.length;
	document.getElementById(target).innerHTML = (numDisp);
}




// Result Text
var resultHttp
function resultText()
{
resultHttp=GetXmlHttpObject()
if (resultHttp==null) return
var url="/ajax/result-text/"
resultHttp.onreadystatechange=resultState
resultHttp.open("GET",url,true)
resultHttp.send(null)
}
function resultState() 
{
if (resultHttp.readyState==4 || resultHttp.readyState=="complete")
 {
 document.getElementById("result-text").innerHTML=resultHttp.responseText
 } 
}




// BANNER AD LOADER
var banner1Http
function showAd1(category) {
banner1Http=GetXmlHttpObject()
if (banner1Http==null) return
var url="/ajax/adserve/1/" + category + "/"
banner1Http.onreadystatechange=banner1State
banner1Http.open("GET",url,true)
banner1Http.send(null)
}
function banner1State()
{
if (banner1Http.readyState==4 || banner1Http.readyState=="complete")
 {
  document.getElementById("adspot1").innerHTML=banner1Http.responseText
 } 
}

var banner2Http
function showAd2(category) {
banner2Http=GetXmlHttpObject()
if (banner2Http==null) return
var url="/ajax/adserve/2/" + category + "/"
banner2Http.onreadystatechange=banner2State
banner2Http.open("GET",url,true)
banner2Http.send(null)
}
function banner2State()
{
if (banner2Http.readyState==4 || banner2Http.readyState=="complete")
 {
  document.getElementById("adspot2").innerHTML=banner2Http.responseText
 } 
}

var banner3Http
function showAd3(category) {
banner3Http=GetXmlHttpObject()
if (banner3Http==null) return
var url="/ajax/adserve/3/" + category + "/"
banner3Http.onreadystatechange=banner3State
banner3Http.open("GET",url,true)
banner3Http.send(null)
}
function banner3State()
{
if (banner3Http.readyState==4 || banner3Http.readyState=="complete")
 {
  document.getElementById("adspot3").innerHTML=banner3Http.responseText
 } 
}

var banner4Http
function showAd4(category) {
banner4Http=GetXmlHttpObject()
if (banner4Http==null) return
var url="/ajax/adserve/4/" + category + "/"
banner4Http.onreadystatechange=banner4State
banner4Http.open("GET",url,true)
banner4Http.send(null)
}
function banner4State()
{
if (banner4Http.readyState==4 || banner4Http.readyState=="complete")
 {
  document.getElementById("adspot4").innerHTML=banner4Http.responseText
 } 
}

var banner5Http
function showAd5(category) {
banner5Http=GetXmlHttpObject()
if (banner5Http==null) return
var url="/ajax/adserve/5/" + category + "/"
banner5Http.onreadystatechange=banner5State
banner5Http.open("GET",url,true)
banner5Http.send(null)
}
function banner5State()
{
if (banner5Http.readyState==4 || banner5Http.readyState=="complete")
 {
  document.getElementById("adspot5").innerHTML=banner5Http.responseText
 } 
}






// Chart player
function chartPlayer(src,id) {
	link = "audio" + id;
	label = "label" + id;
	output = "<embed src='" + src + "' width='1' height='1' autoplay='true' controller='false'>";
	document.getElementById(link).href = "javascript:chartStop('" + src + "'," + id + ");";
	document.getElementById(label).src = "/css/images/chart_stop.gif";
	document.getElementById("chartplayer").innerHTML = output;
	setTimeout("chartStop('"+ src +"'," + id + ")",32000);
}
function chartStop(src,id) {
	link = "audio" + id;
	label = "label" + id;
	document.getElementById(link).href = "javascript:chartPlayer('" + src + "'," + id + ");";
	document.getElementById(label).src = "/css/images/chart_play.gif";
	document.getElementById("chartplayer").innerHTML = "";
}

function watchVideo(id,src) {
	if (id == 0) {
		document.getElementById("video-wrap").style.display = 'none';
		document.getElementById("video-player").innerHTML = "";
	}
	if (id == 1) {
		document.getElementById("video-wrap").style.display = 'block';
		output = "<embed src='" + src + "' width='477' height='274' autoplay='true' controller='false'>";
		output = output + "<a href='javascript:watchVideo(0,0);'>close player window</a>";
		document.getElementById("video-player").innerHTML = output;
	}
}




function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}







			// CHANGE GALLERY IMAGE (PLUS CAPTION ETC)
			function galleryChange(move,slide) {
				if (firstrun == 1) galleryBuild();
				document.getElementById("dispImage").innerHTML = "";
				showhidegalleryCaption(galCaptions);
				if (related == 1) {
					if (slide !== total) document.getElementById("promo-slide").style.display = 'none';
					if (slide == total) {
						document.getElementById("promo-slide").style.display = 'block';
						showhidegalleryCaption(0);
					}
				}
				prev = slide - 1;
				next = slide + 1;
				if (prev == 0) prev = total;
				if (next > total) next = 1;
				if (move == 1) {
					position = (slide-1) * -88;
					document.getElementById("thumbnails").style.left = position + "px";
				}
				document.getElementById("dispImage").innerHTML = "<img src='" + image[slide] + "' height=" + imgHeight + ">";
				document.getElementById("dispCaption").innerHTML = caption[slide];
				document.getElementById("dispCount").innerHTML = "Image " + slide + " of " + total;
				var i=1;
				for (i=1;i<=total;i++)
					{
						document.getElementById("thumb" + i).className = 'inactive-thumb';
					}
				document.getElementById("thumb" + slide).className = 'active-thumb';
				document.getElementById("left").onclick = function() { galleryChange(1,prev); return false;};
				document.getElementById("right").onclick = function() { galleryChange(1,next); return false;};
			}

			function galleryCaption(id) {
				if (id == 0) galCaptions = 0;
				if (id == 1) galCaptions = 1;
				showhidegalleryCaption(galCaptions);
			}
			function showhidegalleryCaption(id) {
				if (id == 0) document.getElementById("caption").style.display = 'none';
				if (id == 1) document.getElementById("caption").style.display = 'block';
				if (id == 0) document.getElementById("captions-hidden").style.display = 'block';
				if (id == 1) document.getElementById("captions-hidden").style.display = 'none';
			}


			// SCROLL THUMBNAILS
			function startThumbScroll(direction) {
				clearTimeout(scrolltimer);
				if (direction > 0) doThumbScroll(direction);
			}
			function doThumbScroll(direction) {
				scrolltimer = setTimeout("doThumbScroll("+direction+")", 1);
				moveThumbnails(direction);
			}
			function moveThumbnails(direction) {
				if (direction == 1) position = position + 3;
				if (direction == 2) position = position - 3;
				if (position > 0) position = 0;
				if (position < scrolllimit) position = scrolllimit;
				document.getElementById("thumbnails").style.left = position + "px";
			}


			// SLIDE SHOW
			function startSlideshow(id) {
				if (id == 0) document.getElementById("button-slideshow").href = "javascript:startSlideshow(1);";
				if (id == 1) document.getElementById("button-slideshow").href = "javascript:startSlideshow(0);";
				if (id == 0) document.getElementById("button-slideshow").className = 'off';
				if (id == 1) document.getElementById("button-slideshow").className = 'on';
				clearTimeout(slideshow);
				if (id == 1) doAutoSlide();
			}

			function doAutoSlide() {
				slideshow = setTimeout("doAutoSlide()", 4000);
				galleryChange(1,next);
				return false;
			}


			// First run gallery builder
			function galleryBuild() {
				firstrun = 0;
				document.getElementById("slidebutton-holder").innerHTML = "<a class='off' href='javascript:startSlideshow(1);' id='button-slideshow'>Start/stop slideshow</a>";
				document.getElementById("captionbutton-holder").innerHTML = "<a href='javascript:galleryCaption(0);' id='icon'>Hide captions</a>";
				document.getElementById("thumbleft-holder").innerHTML = "<a href='javascript:startThumbScroll(1);' id='left' onMouseOver='startThumbScroll(1);' onMouseOut='startThumbScroll(0);'>Scroll thumbnails left | </a>";
				document.getElementById("thumbright-holder").innerHTML = "<a href='javascript:startThumbScroll(2);' id='right' onMouseOver='startThumbScroll(2);' onMouseOut='startThumbScroll(0);'>Scroll thumbnails right</a>";
			}



// Flag comment
function flagComment(comment) {
	var question = confirm("Are you sure you want to flag this comment as innapropriate?");
	if (question == true) {
		flagCom(comment)
		document.getElementById("flag" + comment).innerHTML = "";
	}
}
var flagComHttp
function flagCom(comment) {
	flagComHttp=GetXmlHttpObject()
	if (flagComHttp==null) return
	var url="/response/flag-comment/" + comment + "/"
	flagComHttp.onreadystatechange=flagComState
	flagComHttp.open("GET",url,true)
	flagComHttp.send(null)
}
function flagComState() {
	if (flagComHttp.readyState==4 || flagComHttp.readyState=="complete") {
		resultText()
 	} 
}


// Article rating
function rateArticle(article,rating)
{
	rating1 = "off";
	rating2 = "off";
	rating3 = "off";
	rating4 = "off";
	rating5 = "off";
	if (rating > 0) rating1 = 'on';
	if (rating > 1) rating2 = 'on';
	if (rating > 2) rating3 = 'on';
	if (rating > 3) rating4 = 'on';
	if (rating > 4) rating5 = 'on';
	text = "<ul>";
	text = text + "<li id='star1' class='" + rating1 + "'></span>";
	text = text + "<li id='star2' class='" + rating2 + "'></span>";
	text = text + "<li id='star3' class='" + rating3 + "'></span>";
	text = text + "<li id='star4' class='" + rating4 + "'></span>";
	text = text + "<li id='star5' class='" + rating5 + "'></span>";
	text = text + "</ul>";
	document.getElementById("stars").innerHTML = text;

	var rateHttp
	rateHttp=GetXmlHttpObject()
	if (rateHttp==null) return
	var url="/response/rate-article/" + article + "/" + rating + "/"
	rateHttp.onreadystatechange=rateState
	rateHttp.open("GET",url,true)
	rateHttp.send(null)
	function rateState() {
		if (rateHttp.readyState==4 || rateHttp.readyState=="complete")
		{
			resultText()
		} 
	}
}

function rateOn(pos)
{
	document.getElementById("star1").className = 'off';
	document.getElementById("star2").className = 'off';
	document.getElementById("star3").className = 'off';
	document.getElementById("star4").className = 'off';
	document.getElementById("star5").className = 'off';
	if (pos > 0) document.getElementById("star1").className = 'on';
	if (pos > 1) document.getElementById("star2").className = 'on';
	if (pos > 2) document.getElementById("star3").className = 'on';
	if (pos > 3) document.getElementById("star4").className = 'on';
	if (pos > 4) document.getElementById("star5").className = 'on';
}

function rateOff(rating)
{
	document.getElementById("star1").className = 'off';
	document.getElementById("star2").className = 'off';
	document.getElementById("star3").className = 'off';
	document.getElementById("star4").className = 'off';
	document.getElementById("star5").className = 'off';
	if (rating > 0) document.getElementById("star1").className = 'on';
	if (rating > 1) document.getElementById("star2").className = 'on';
	if (rating > 2) document.getElementById("star3").className = 'on';
	if (rating > 3) document.getElementById("star4").className = 'on';
	if (rating > 4) document.getElementById("star5").className = 'on';
}


// Live Player
				var mute = "false";
				var volume = 100;
				function playerPlay() {
					if (document.getElementById("play-button").className == "play-button") ppClass = "pause-button";
					if (document.getElementById("play-button").className == "pause-button") ppClass = "play-button";
					document.getElementById("play-button").className = ppClass;
					if (ppClass == "pause-button") player.sendEvent('PLAY');
					if (ppClass == "play-button") player.sendEvent('STOP');
				}
				function playerMute() {
					if (mute == "false") set = "true";
					if (mute == "true") set = "false";
					mute = set;
					if (document.getElementById("mute-button").className == "unmute-button") ppClass = "mute-button";
					if (document.getElementById("mute-button").className == "mute-button") ppClass = "unmute-button";
					document.getElementById("mute-button").className = ppClass;
					player.sendEvent('MUTE', mute);
				}
				function playerVolume(inc) {
					volume = volume + inc;
					if (volume < 0) volume = 0;
					if (volume > 100) volume = 100;
					player.sendEvent('VOLUME', volume);
				}


