// Toggle top venues
function topVenues(id) {
	if (id == 0) document.getElementById("most-viewed").style.display = "block";
	if (id == 0) document.getElementById("top-rated").style.display = "none";
	if (id == 1) document.getElementById("most-viewed").style.display = "none";
	if (id == 1) document.getElementById("top-rated").style.display = "block";
	if (id == 0) document.getElementById("featured-select-0").className = "active";
	if (id == 0) document.getElementById("featured-select-1").className = "";
	if (id == 1) document.getElementById("featured-select-1").className = "active";
	if (id == 1) document.getElementById("featured-select-0").className = "";
}

// Confirm URL click
function confHref(id,text)
{
 var question = confirm(text);
 if (question == true)
 {
   window.location= id;
 }
}

// List regions
var regionHttp
function listRegions() {
	document.getElementById("region-wrap").innerHTML="<img src='/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
	} 
}


//Add venue
function addVenue(id) {
	outthumb = thumb[id];
	outname = venname[id];
	v1 = document.getElementById("venue1").value;
	v2 = document.getElementById("venue2").value;
	v3 = document.getElementById("venue3").value;
	v4 = document.getElementById("venue4").value;
	use = 0;
	if (v4 == "0") use = 4;
	if (v3 == "0") use = 3;
	if (v2 == "0") use = 2;
	if (v1 == "0") use = 1;
	if ((id == v1) || (id == v2) || (id == v3) || (id == v4)) use = 0;
	if (use > 0) {
		if (use == 1) {
			document.getElementById("venue1").value = id;
			document.getElementById("top" + use).innerHTML = "<img src='" + outthumb + "' width='102' height='77' /><br />" + outname + "<br /><a href='javascript: clearVenue(1);' title='Remove " + outname + "'>[remove]</a>";
		}
		if (use == 2) {
			document.getElementById("venue2").value = id;
			document.getElementById("top" + use).innerHTML = "<img src='" + outthumb + "' width='102' height='77' /><br />" + outname + "<br /><a href='javascript: clearVenue(2);' title='Remove " + outname + "'>[remove]</a>";
		}
		if (use == 3) {
			document.getElementById("venue3").value = id;
			document.getElementById("top" + use).innerHTML = "<img src='" + outthumb + "' width='102' height='77' /><br />" + outname + "<br /><a href='javascript: clearVenue(3);' title='Remove " + outname + "'>[remove]</a>";
		}
		if (use == 4) {
			document.getElementById("venue4").value = id;
			document.getElementById("top" + use).innerHTML = "<img src='" + outthumb + "' width='102' height='77' /><br />" + outname + "<br /><a href='javascript: clearVenue(4);' title='Remove " + outname + "'>[remove]</a>";
		}
	}
}
// Clear venue
function clearVenue(id) {
	document.getElementById("top" + id).innerHTML = "<img src='/uploads/venue-thumb.jpg' width='102' height='77' /><br />&nbsp;<br />&nbsp;";
	document.getElementById("venue" + id).value = "0";
}

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;
}

// Pop-up login
function popupLogin(id) {
	if (id == 0) document.getElementById("floating-login").style.display = "none";
	if (id == 1) document.getElementById("floating-login").style.display = "block";
}
// Count charcters
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);
}
// Contact information
function contactInformation() {
	output = "";
	query = document.getElementById("query").value;
	if (query == 1) output = "Nettleden.com only publishes access and location details for venues on this website to privalidged members, these are registered users who have upgraded their memberships or been promoted. This is due to the risks involved in entering these sites.<br /><br />Many of the location are extremely dangerous places and many of the sites do not allow public access.<br /><br />If you have experience and are seriously interested in visiting some of these locations we recommend that you reviews our suggested equipment page.<br /><br />If this has not answered your question please continue to submit your question below.";
	if (query == 2) output = "Nettleden.com does not organise visits or events, we have no official connection to any of the venues featured on this website.<br /><br />We do not recommend visiting any of the venues listed, places which allow public visits are very rare due to health and safety restrictions.<br /><br />If this has not answered your question please continue to submit your question below.";
	if (query == 3) output = "Please note that at the bottom of each page there is a further reading list where you may find the answer to your question.<br /><br />Alternatively, visit our shop page where you will find a selection of books and DVDs containing more information about the venues featured on this website.<br /><br />If this has not answered your question please continue to submit your question below.";
	if (query == 4) output = "All photos on Nettleden.com are taken and upload by our members, in order to use a photo or video you would need to approach the user who uploaded the video directly.<br /><br />The major exclusion to this is the photographs of Burlington, these photos were commissioned by the Ministry of Defence, they are Crown Copyright and used with permission of the Ministry of Defence.<br /><br />You can request copies of these photos through the Freedom of Information Act.<br />DCSA Secretariat Head<br />Defence Communication Services Agency,<br />Room 124,<br />Building 111,<br />Basil Hill Site,<br />Corsham,<br />Wiltshire<br />SN13 9NR<br /><br />Intellectual Property Group<br />Directorate of Intellectual Property Rights<br />Defence Procurement Agency<br />Poplar 2 #2218<br />MoD Abbey Wood,<br />Bristol<br />BS34 8JH.<br /><br />If this has not answered your question please continue to submit your question below.";
	if (query == 5) output = "If you would like to learn more about Nettleden.com, why it exists and what we do please visits the about us page.<br /><br />If this has not answered your question please continue to submit your question below.";
	if (query == 6) output = "The easiest way to report an infringement of copyright is to click the 'report' option on the page where your image or video appears.<br /><br />If you need to report more than one peice of content, you can report a user by visiting their profile and clicking on the 'report' option, you will then be given a series of option to determin the nature of the complaint.<br /><br />If this has not answered your question please continue to submit your question below.";
	if (query == 7) output = "We receive many requests to take part in interviews for radio, TV and print, we are more than happy to accomodate these requests. You can find previous interviews (including audio samples) on our media relations page.<br /><br />We also receive many requests to help out with student films or projects, due to time restriction we are unable to commit to these projects.<br /><br />If you would like to contact us to discuss this further please click the continue button below to be taken to an online contact form or call Steve Higgins on 07899 910869.<br /><br />If this has not answered your question please continue to submit your question below.";
	if (output != "") output = "<p class='msg warning'>" + output + "</p>";
	document.getElementById("contact-information").innerHTML = output;
}

// Venue rating
function rateVenue(venue,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 + "' title='You gave this venue " + rating + " stars'></li>";
	text = text + "<li id='star2' class='" + rating2 + "' title='You gave this venue " + rating + " stars'></li>";
	text = text + "<li id='star3' class='" + rating3 + "' title='You gave this venue " + rating + " stars'></li>";
	text = text + "<li id='star4' class='" + rating4 + "' title='You gave this venue " + rating + " stars'></li>";
	text = text + "<li id='star5' class='" + rating5 + "' title='You gave this venue " + rating + " stars'></li>";
	text = text + "</ul>";
	document.getElementById("stars").innerHTML = text;
	var rateHttp
	rateHttp=GetXmlHttpObject()
	if (rateHttp==null) return
	var url="/submit/rate/" + venue + "/" + rating + "/"
	rateHttp.onreadystatechange=rateState
	rateHttp.open("GET",url,true)
	rateHttp.send(null)
	function rateState() {
	if (rateHttp.readyState==4 || rateHttp.readyState=="complete") {
		document.getElementById("result-text").innerHTML = rateHttp.responseText
	}
	}
}

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';
}

function changeHistory(id) {
	if (id == 0) {
		document.getElementById("full-history").style.display = "none";
		document.getElementById("short-history").style.display = "block";
	}
	if (id == 1) {
		document.getElementById("full-history").style.display = "block";
		document.getElementById("short-history").style.display = "none";
	}
}

// Like content
var likeHttp
function likeThis(docid,id,from) {
	if (id == 1) {
		document.getElementById(from).href = "javascript: likeThis('" + docid + "',0," + from + ");";
		likeHttp=GetXmlHttpObject()
		if (likeHttp==null) return
		var url="/submit/like/" + docid + "/"
		likeHttp.onreadystatechange=likeState
		likeHttp.open("GET",url,true)
		likeHttp.send(null)
	}
}
function likeState() {
	if (likeHttp.readyState==4 || likeHttp.readyState=="complete") {
		document.getElementById("result-text").innerHTML=likeHttp.responseText
	} 
}

// Flag content
var flagHttp
function flagThis(docid,id,from) {
	if (id == 1) {
		document.getElementById(from).href = "javascript: flagThis('" + docid + "',0," + from + ");";
		flagHttp=GetXmlHttpObject()
		if (flagHttp==null) return
		var url="/submit/flag/" + docid + "/"
		flagHttp.onreadystatechange=flagState
		flagHttp.open("GET",url,true)
		flagHttp.send(null)
	}
}
function flagState() {
	if (flagHttp.readyState==4 || flagHttp.readyState=="complete") {
		document.getElementById("result-text").innerHTML=flagHttp.responseText
	} 
}


// AJAX username check
function checkUsername(id) {
	username = ajaxClean(document.getElementById("username").value);
	username = username.split(" ");
	username = username.join("");
	username = username.split("@");
	username = username.join("");
	username = username.split(".");
	username = username.join("");
	username = username.split("-");
	username = username.join("");
	username = username.split("_");
	username = username.join("");
	username = username.split("+");
	username = username.join("");
	username = username.split("/");
	username = username.join("");
	username = username.split("'");
	username = username.join("");
	document.getElementById("username").value = username;
	if (username == "") id = 0;
	if (id == 0) document.getElementById("username-result").innerHTML = "";
	if (id == 1) document.getElementById("username-result").innerHTML = "<img src='/images/loading.gif'>";
	if (id == 1) ajaxUsername(username);
}
var checkuserHttp
function ajaxUsername(username) {
	checkuserHttp=GetXmlHttpObject()
	if (checkuserHttp==null) return
	var url="/ajax/username/" + username + "/"
	checkuserHttp.onreadystatechange=checkuserState
	checkuserHttp.open("GET",url,true)
	checkuserHttp.send(null)
}
function checkuserState() {
	if (checkuserHttp.readyState==4 || checkuserHttp.readyState=="complete") {
		document.getElementById("username-result").innerHTML=checkuserHttp.responseText
	} 
}

// name check
function checkName(id) {
	fullname = ajaxClean(document.getElementById("fullname").value);
	fullname = fullname.split("@");
	fullname = fullname.join("");
	fullname = fullname.split(".");
	fullname = fullname.join("");
	fullname = fullname.split("_");
	fullname = fullname.join("");
	fullname = fullname.split("+");
	fullname = fullname.join("");
	fullname = fullname.split("/");
	fullname = fullname.join("");
	document.getElementById("fullname").value = fullname;
	if (id == 0) document.getElementById("name-result").innerHTML = "";
	if (id == 1) {
		error = 0;
		chars = fullname.length;
		if (chars < 6) error = 1;
		space = fullname.indexOf(" ");
		if (space < 2) error = 1;
		if (space == (chars - 1)) error = 1;
		if (error == 0) document.getElementById("name-result").innerHTML = "<span class='msg done'>OK</span>";
		if (error == 1) document.getElementById("name-result").innerHTML = "<span class='msg error'>Not valid</span>";
	}
}

// AJAX email check
function checkEmail(id) {
	email = ajaxClean(document.getElementById("email").value);
	email = email.split("@");
	email = email.join("--at--");
	email = email.split(".");
	email = email.join("--dot--");
	email = email.split("+");
	email = email.join("--plus--");
	email = email.split("/");
	email = email.join("");
	if (email == "") id = 0;
	if (id == 0) document.getElementById("email-result").innerHTML = "";
	if (id == 1) document.getElementById("email-result").innerHTML = "<img src='/images/loading.gif'>";
	if (id == 1) ajaxEmail(email);
}
var checkemailHttp
function ajaxEmail(email) {
	checkemailHttp=GetXmlHttpObject()
	if (checkemailHttp==null) return
	var url="/ajax/email/" + email + "/"
	checkemailHttp.onreadystatechange=checkemailState
	checkemailHttp.open("GET",url,true)
	checkemailHttp.send(null)
}
function checkemailState() {
	if (checkemailHttp.readyState==4 || checkemailHttp.readyState=="complete") {
		document.getElementById("email-result").innerHTML=checkemailHttp.responseText
	} 
}

// AJAX dob check
function checkDob(id) {
	dob = ajaxClean(document.getElementById("dob").value);
	dob = dob.split("/");
	dob = dob.join("--s--");
	dob = dob.split("@");
	dob = dob.join("");
	dob = dob.split(".");
	dob = dob.join("");
	dob = dob.split("_");
	dob = dob.join("");
	dob = dob.split("+");
	dob = dob.join("");
	dob = dob.split(" ");
	dob = dob.join("");
	dob = dob.split("'");
	dob = dob.join("");
	if (dob == "") id = 0;
	if (id == 0) document.getElementById("dob-result").innerHTML = "";
	if (id == 1) document.getElementById("dob-result").innerHTML = "<img src='/images/loading.gif'>";
	if (id == 1) ajaxDob(dob);
}
var checkdobHttp
function ajaxDob(dob) {
	checkdobHttp=GetXmlHttpObject()
	if (checkdobHttp==null) return
	var url="/ajax/dob/" + dob + "/"
	checkdobHttp.onreadystatechange=checkdobState
	checkdobHttp.open("GET",url,true)
	checkdobHttp.send(null)
}
function checkdobState() {
	if (checkdobHttp.readyState==4 || checkdobHttp.readyState=="complete") {
		document.getElementById("dob-result").innerHTML=checkdobHttp.responseText
	} 
}

// 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";
}


function ajaxClean(text) {
	text = text.split(",");
	text = text.join("");
	text = text.split("!");
	text = text.join("");
	text = text.split("&");
	text = text.join("");
	text = text.split("[");
	text = text.join("");
	text = text.split("]");
	text = text.join("");
	text = text.split("{");
	text = text.join("");
	text = text.split("}");
	text = text.join("");
	text = text.split("|");
	text = text.join("");
	text = text.split("~");
	text = text.join("");
	text = text.split("?");
	text = text.join("");
	text = text.split("£");
	text = text.join("");
	text = text.split("$");
	text = text.join("");
	text = text.split("%");
	text = text.join("");
	text = text.split("^");
	text = text.join("");
	text = text.split("*");
	text = text.join("");
	text = text.split("(");
	text = text.join("");
	text = text.split(")");
	text = text.join("");
	text = text.split("=");
	text = text.join("");
	text = text.split(";");
	text = text.join("");
	text = text.split(":");
	text = text.join("");
	text = text.split('"');
	text = text.join("");
	text = text.split(">");
	text = text.join("");
	text = text.split("<");
	text = text.join("");
	text = text.split("`");
	text = text.join("");
	return text;
}

function lettersOnly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function lettersSpaceOnly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789'- ").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function emailOnly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789-_.@").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function dateOnly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("0123456789/").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function numbersOnly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function webcharsOnly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789=-_.@?&/:").indexOf(keychar) > -1))
   return true;
else
   return false;
}

// Toggle photo title field
function toggleTitle() {
	id = document.getElementById("notvenue").checked;
	if (id == true) document.getElementById("not-venue").style.display = "block";
	if (id == false) document.getElementById("not-venue").style.display = "none";
	if (id == true) document.getElementById("venue").disabled = true;
	if (id == false) document.getElementById("venue").disabled = false;
}

// Add contact to form
function sendMessage(username) {
	tonames = document.getElementById("toname").value;
	if (tonames !== "") tonames =  username + "," + tonames;
	if (tonames == "") tonames = username;
	document.getElementById("toname").value = tonames;
}