<!--
// show/hide
function switchMenu(obj) {
	var el = document.getElementById(obj);
	
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
	
}
function iknowdate() {
	var div = document.getElementById("dontknowthedate");
	var otherdiv = document.getElementById("knowthedate");
	var theform = document.getElementById("addflightform");
	div.style.display = 'none';
	otherdiv.style.display = 'inline';
	theform.style.display = 'inline';
	document.getElementById("iknowtab").style.backgroundColor = "#c7e6fb";
	document.getElementById("dontknowtab").style.backgroundColor = "#fff";
	document.getElementById("date_type").value = 'specific';
}
function dontknowdate() {
	var div = document.getElementById("dontknowthedate");
	var otherdiv = document.getElementById("knowthedate");
	var theform = document.getElementById("addflightform");
	otherdiv.style.display = 'none';
	div.style.display = 'inline';
	theform.style.display = 'inline';
	document.getElementById("iknowtab").style.backgroundColor = "#fff";
	document.getElementById("dontknowtab").style.backgroundColor = "#c7e6fb";
	document.getElementById("date_type").value = 'tba';
}
function table_Highlight() { /* for lovely IE6 & 7 :@ */
	var rows = document.getElementsByTagName('tr');	
	for(var i = 0; i < rows.length; i++) {	
		rows[i].onmouseover = function() {
			this.className += ' highlite';
		}		
		rows[i].onmouseout = function() {
			this.className = this.className.replace('highlite', '');
		}
	}
}

function pause(millisecs){
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millisecs);
} 
function newLocation(url){
	window.location=url;
}
//jQuery code for this page
$(document).ready(function(){
// close the offDiv content sections
//(doing this with js instead of css means if no js, content is all visible)
$('.offDiv > .show-hide').hide();
// show the correct buttons for each div
// they are hidden with css for no-js users
$('.offDiv > .showLink').show();
$('.onDiv > .hideLink').hide();
$('a.showAll').show();
$('a.hideAll').hide();
// showLink shows the content
$('a.showLink').click(function(){
$(this).siblings('.show-hide').slideToggle('slow');
$(this).parents('.offDiv').removeClass().addClass('onDiv');
$('a.hideAll').show();
$(this).hide();
$(this).siblings('.hideLink').show();
return false;
});
// hideLink hides the content
$('a.hideLink').click(function(){
$(this).siblings('.show-hide').slideToggle('slow');
$(this).parents('.onDiv').removeClass().addClass('offDiv');
$('a.showAll').show();
$(this).hide();
$(this).siblings('.showLink').show();
return false;
});
// show all link
$('a.showAll').click(function(){
$('.show-hide').slideDown('slow');
$('.offDiv').removeClass().addClass('onDiv');
$('a.hideAll').show();
$('a.hideLink').show();
$('a.showLink').hide();
$(this).hide();
return false;
});
// hide all link
$('a.hideAll').click(function(){
$('.show-hide').slideUp('slow');
$('.onDiv').removeClass().addClass('offDiv');
$('a.showLink').show();
$('a.hideLink').hide();
$(this).hide();
$('a.showAll').show();
return false;
});
});


//-------------- Ajax for resitration form -------------//
// username
var nameurl = "scripts/jscripts/ajax/username.php?param=";
var username_error = true;
function updateName() {
	var name = document.getElementById("username").value;
	if (name !== ""){
		// message while checking the database
		document.getElementById('checked').innerHTML = "Checking...";
		http.open("GET", nameurl + escape(name), true);
		http.onreadystatechange = handleHttpResponse;
		http.send(null);
	} else {
		document.getElementById('checked').innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> usernames must not be blank</font></span>";
		username_error = false;
	}
}
function handleHttpResponse() {
	if (http.readyState == 4) {
		results = http.responseText;
		/* Again, we're assuming your username input ID is "username" */
		var name = document.getElementById("username").value;
		/* If the username is available, Print this message: */
		if(results == ""){
			document.getElementById('checked').innerHTML = "<span class='tinytxt'><font color=\"green\"> <img src='images/layout/tick.jpg' alt='tick'> Available</font></span>";
			username_error = false;
			valid = true;
		} else {
			document.getElementById('checked').innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Taken</font></span>";
			username_error = true;
		}
	}
}
function getHTTPObject() {
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {xmlhttp = new XMLHttpRequest();} catch (e) {xmlhttp = false;}
}

if(!xmlhttp && typeof ActiveXObject != "undefined"){
   try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
   if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
  }

return xmlhttp;
}
var http = getHTTPObject();


// passwords
function checkpass1(){ // checks the 1st password box to make sure it's not empty
	var password1 = document.getElementById("password").value;
	if (password1 == ""){
		document.getElementById('pass1check').innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> you must enter a password</font></span>";
	} else {
		document.getElementById('pass1check').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
		checkpass(); // call the main checker function, in case they modified the 1st box after entering something in the 2nd
	}
}
var password_error = true;
function checkpass() {
	var password1 = document.getElementById("password").value;
	var password2 = document.getElementById("password1").value;
	if (password2 !== ""){
		/* Print message while checking */
		document.getElementById('passcheck').innerHTML = "Checking...";
		if(password1 == password2){
			document.getElementById('passcheck').innerHTML = "<span class='tinytxt'><font color=\"green\"> <img src='images/layout/tick.jpg' alt='tick'> passwords match</font></span>";
			password_error = false;
			valid = true;
		} else {
			document.getElementById('passcheck').innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> passwords do not match</font></span>";
			password_error = true;
		}
	}
}
// email
var emailurl = "scripts/jscripts/ajax/email.php?email=";
var email_error = true;
function updateEmail() {
	var email = document.getElementById("email").value;
	if (email !== ""){
		// message while checking the database
		document.getElementById('emailcheck').innerHTML = "Checking...";
		http.open("GET", emailurl + escape(email), true);
		http.onreadystatechange = handleHttpResponse_email;
		http.send(null);
	} else {
		document.getElementById('emailcheck').innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> you must enter a valid e-mail address</font></span>";
		email_error = true;
	}
}
function handleHttpResponse_email() {
	if (http.readyState == 4) {
		email_results = http.responseText;
		/* Again, we're assuming your username input ID is "username" */
		var email = document.getElementById("email").value;
		/* If the username is available, Print this message: */
		if(email_results == ""){
			document.getElementById('emailcheck').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
			email_error = false;
			valid = true;
		} else {
			document.getElementById('emailcheck').innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> you must enter a valid e-mail address</font></span>";
			email_error = true;
		}
	}
}

// captcha
var captchaurl = "scripts/jscripts/ajax/captcha.php?captcha=";
var captcha_error = true;
function checkcaptcha() {
	var captcha = document.getElementById("captcha").value;
	if (captcha !== ""){
		// message while checking the database
		document.getElementById('captchacheck').innerHTML = "Checking...";
		http.open("GET", captchaurl + escape(captcha), true);
		http.onreadystatechange = handleHttpResponse_captcha;
		http.send(null);
	} else {
		document.getElementById('captchacheck').innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> the text entered does not match</font></span>";
		captcha_error = true;
	}
}
function handleHttpResponse_captcha() {
	if (http.readyState == 4) {
		captcha_results = http.responseText;
		/* Again, we're assuming your username input ID is "username" */
		var captcha = document.getElementById("captcha").value;
		/* If the username is available, Print this message: */
		if(captcha_results == ""){
			document.getElementById('captchacheck').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
			captcha_error = false;
			valid = true;
		} else {
			document.getElementById('captchacheck').innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> the text entered does not match</font></span>";
			captcha_error = true;
		}
	}
}
var phone_error = true;
function phonecheck1(){
	var phone = document.getElementById("phone").value;
	if (phone.length < 5){
		phonecheck();
	} else {
		document.getElementById('msgphone').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
		document.getElementById('msgmobile').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
		phone_error = false;
		valid = true;
	}
}
function phonecheck() {
	var phone_num = document.getElementById("phone").value;
	var mobile = document.getElementById("mobile").value;
	if (mobile.length > 10){
		document.getElementById('msgphone').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
		document.getElementById('msgmobile').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
		phone_error = false;
		valid = true;
	} else if (phone_num.length < 5){
		document.getElementById('msgphone').innerHTML = ""
		document.getElementById('msgmobile').innerHTML = "";
		phone_error = true;
	} else {
		document.getElementById('msgphone').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
		document.getElementById('msgmobile').innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
		phone_error = false;
		valid = true;
	}
}
// all other fields (just to show a tick when they enter data
var fname_error = true;
var sname_error = true;
var flyingex_error = true;
function fieldcheck(the_field, number){
	var num = number;
	if (num == null){
		num = 5;
	}
	var field = document.getElementById(the_field).value;
	if (field.length > num){
		document.getElementById("msg" + the_field).innerHTML = " <img src='images/layout/tick.jpg' alt='tick'>";
		valid = true;
		if (the_field == "fname"){
			fname_error = false;
		} else if (the_field == "sname"){
			sname_error = false;
		} else if (the_field == "flyingex"){
			flyingex_error = false;
		} else if (the_field == "flyingexUpdater"){
			flyingex_error = false;
		}
	} else {
		document.getElementById("msg" + the_field).innerHTML = "";
		valid = false;
		if (the_field == "fname"){
			fname_error = true;
		} else if (the_field == "sname"){
			sname_error = true;
		} else if (the_field == "flyingex"){
			flyingex_error = true;
		} else if (the_field == "flyingexUpdater"){
			flyingex_error = true;
		}
	}
}

var valid = true;
function validate (){
    if (username_error == true || password_error == true || email_error == true || captcha_error == true || fname_error == true || sname_error == true || phone_error == true || flyingex_error == true){/// etc etc for the other ones
        valid = false;
    }
	if(username_error == true){
		document.getElementById("checked").innerHTML = "<img src='images/layout/cross.jpg' alt='cross'>";
	}
	if(password_error == true){
		document.getElementById("passcheck").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> passwords don't match</font></span>";
	}
	if(email_error == true){
		document.getElementById("emailcheck").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Please enter a valid e-mail address</font></span>";
	}
	if(captcha_error == true){
		document.getElementById("captchacheck").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> The number entered didn't match</font></span>";
	}
	if(fname_error == true){
		document.getElementById("msgfname").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Required field</font></span>";
	}
	if(sname_error == true){
		document.getElementById("msgsname").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Required field</font></span>";
	}
	if(phone_error == true){
		document.getElementById("msgmobile").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> You must enter at least 1 phone number</font></span>";
	}
	if(flyingex_error == true){
		document.getElementById("msgflyingex").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Required field</font></span>";
	}
	return valid; // woot!
}
var valid = true;
function validate_update (){
    if (email_error == true || fname_error == true || sname_error == true || phone_error == true || flyingex_error == true){
        valid = false;
    }
	if(email_error == true){
		document.getElementById("emailcheck").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Please enter a valid e-mail address</font></span>";
	}
	if(fname_error == true){
		document.getElementById("msgfname").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Required field</font></span>";
	}
	if(sname_error == true){
		document.getElementById("msgsname").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Required field</font></span>";
	}
	if(phone_error == true){
		document.getElementById("msgmobile").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> You must enter at least 1 phone number</font></span>";
	}
	if(flyingex_error == true){
		document.getElementById("msgflyingex").innerHTML = "<span class='tinytxt'><font color=\"red\"> <img src='images/layout/cross.jpg' alt='cross'> Required field</font></span>";
	}
	return valid;
}
var update_details_checked = false;
function checkALL() { // this one gets run soon as the mouse goes over the update details form, just validates all the fields so that it'll submit ok ;)
	if (update_details_checked == false){
		update_details_checked = true;
		fieldcheck('fname',2);
		fieldcheck('sname',3);
		fieldcheck('address',10);
		fieldcheck('postcode',5);
		updateEmail();
		phonecheck1();
		phonecheck();
		fieldcheck('flyingexUpdater',2);
		fieldcheck('aboutUpdater');
	}
}
function flightlist(chosen_page) {
	var the_page = chosen_page;
	document.getElementById('page').innerHTML = "loading...";
	if (the_page == "yourflights") {
		http.open("GET", "scripts/jscripts/ajax/board_yourflight.php", true);
	} else {
		http.open("GET", "scripts/jscripts/ajax/board_home.php", true);
	}
	http.onreadystatechange = handleHttpResponse_getboardpage;
	http.send(null);
}
function handleHttpResponse_getboardpage() {
	if (http.readyState == 4) {
		boardpage = http.responseText;
		document.getElementById('page').innerHTML = boardpage;
	}
}
var flight_ID;
function getReplies(ID) {
	flight_ID = ID;
	document.getElementById('replies').innerHTML = "loading...";
	http.open("GET", "scripts/jscripts/ajax/getReplies.php?ID=" + escape(flight_ID), true);
	http.onreadystatechange = handleHttpResponse_getReplies;
	http.send(null);
}
function handleHttpResponse_getReplies() {
	if (http.readyState == 4) {
		getReplies_results = http.responseText;
		document.getElementById('replies').innerHTML = getReplies_results;
	}
}
function delete_comment(ID,flight){
	var flight_ID = flight;
	var comment_ID = ID;
	var q=confirm("Are you sure you want to delete this comment?");
	if (q==true){
		//do stuff ere
		http.open("GET", "scripts/jscripts/ajax/deletecomment.php?ID=" + escape(comment_ID), true);
		http.send(null);
		pause(500);		
		getReplies(flight_ID);
		return true;
	} else {
		return false;
	}
}
function subscribe(ID,flight){
	var flight_ID = flight;
	var user_ID = ID;
		http.open("GET", "scripts/jscripts/ajax/subscribe.php?user_ID=" + escape(user_ID) + "&flight_ID=" + escape(flight_ID), true);
		http.send(null);
		getReplies(flight_ID);
		pause(500);
		document.getElementById('subscribe_links').innerHTML = "<span class='tinytxt'>You <strong>are</strong> subcribed to updates for this flight <a href='javascript:void(0)' onclick=\"unsubscribe('" + user_ID + "','" + flight_ID + "')\">Unsubscribe?</a></span>";
}
function unsubscribe(ID,flight){
	var flight_ID = flight;
	var user_ID = ID;
		http.open("GET", "scripts/jscripts/ajax/unsubscribe.php?user_ID=" + escape(user_ID) + "&flight_ID=" + escape(flight_ID), true);
		http.send(null);
		getReplies(flight_ID);
		pause(500);
		document.getElementById('subscribe_links').innerHTML = "<span class='tinytxt'>You are <strong>not</strong> subcribed to updates for this flight <a href='javascript:void(0)' onclick=\"unsubscribe('" + user_ID + "','" + flight_ID + "')\">Subscribe?</a></span>";
}
var reply_flight_ID;
var reply_user_ID;
var reply_Comment;
var reply_subscribe;
function post_Reply() {
	reply_flight_ID = document.getElementById("flight_ID").value;
	reply_user_ID = document.getElementById("posters_ID").value;
	reply_Comment = tinyMCE.get('reply_comment').getContent();
	reply_subscribe = document.getElementById("subscribe").checked;
	document.getElementById('replymessage').innerHTML = "posting...";
	http.open("GET","scripts/jscripts/ajax/postReply.php?ID=" + escape(reply_flight_ID) + "&comment=" + escape(reply_Comment) + "&user=" + escape(reply_user_ID) + "&subscribe=" + escape(reply_subscribe), true);
	http.onreadystatechange = handleHttpResponse_postReply;
	http.send(null);
}
function handleHttpResponse_postReply() {
	if (http.readyState == 4) {
		postReply_results = http.responseText;
		if (postReply_results == "naa"){
			document.getElementById('replymessage').innerHTML = "Comment added!";
			tinyMCE.get('reply_comment').setContent('');
			pause(1000);
			getReplies(reply_flight_ID);
			if (reply_subscribe == true){
				document.getElementById('subscribe_links').innerHTML = "<span class='tinytxt'>You <strong>are</strong> subcribed to updates for this flight <a href='javascript:void(0)' onclick=\"unsubscribe('" + reply_user_ID + "','" + reply_flight_ID + "')\">Unsubscribe?</a></span>";
			}
		} else {
			document.getElementById('replymessage').innerHTML = "Error";
		}
	}
}
function checkflightform(form){
	var date = form.date.value.length;
	var when = form.when.value.length;
	var start = form.start.value.length;
	var end = form.end.value.length;
	if (date == 0 && when == 0){
		alert("You must enter either a specific date, or, a rough time/date in the 'when' field.");
		return false;
	} else {
		if (date > 0){
			if (start == 0 || end == 0){
				alert ("You must enter both a start and end time");
				return false;
			}
		}
	}
}

// -----------------------------------------------//
/* ------ functions loaded when page finishes ----- */
window.onload = function() {
	// remove value in 'about' textarea when text is entered/user clicks in box
	if (document.getElementById("about")) {
		var m = document.getElementById("about");
		var v = m.defaultValue;
		m.onfocus = function() {if(m.value==v) m.value='';}
		m.onblur= function() {if(m.value=='') m.value=v;}
	}
	// remove value in 'flying experience' textarea when text is entered/user clicks in box
	if (document.getElementById("flyingex")) {
		var x = document.getElementById("flyingex");
		var y = x.defaultValue;
		x.onfocus = function() {if(x.value==y) x.value='';}
		x.onblur= function() {if(x.value=='') x.value=y;}
	}
// External links to open in new window	
	if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
			anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}


//-->