function getClasses(className)
	{
		var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
		var allElements = window.getElementsByTagName("*");
		var results = [];

		var element;
		for (var i = 0; (element = allElements[i]) != null; i++) {
			var elementClass = element.className;
			if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
				results.push(element);
		}

		return results;
	}

function showHide(me){
	thisclass = (me.match("spaceInfo")) ? "spaceInfo" : "";
	for (i=0;i<=lines;i++){
		thisl = thisclass + i;
		sh = (thisl==me) ? "block" : "none";
		document.getElementById(thisl).style.display=sh;
	}
	//alert (thisl+" -> "+sh+" - "+lines);
	window.self.focus();
}
function showHideSimple(me){
	doIt = (document.getElementById(me).style.display=="none") ? "block" : "none";
	document.getElementById(me).style.display=doIt;
	window.self.focus();
}
function showHideOne(div,show){
	document.getElementById(div).style.display=show;
	window.self.focus();
}

function fillIn(sn,n){
	alert (sn+" "+n);
}



function makeRequest(url,thisdiv) {
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	//http_request.onreadystatechange = function() { alertContents(http_request); };
	http_request.onreadystatechange = function() { echoContents(http_request,thisdiv); };
	http_request.open('GET', url, true);
	http_request.send(null);
}

function echoContents(http_request,thisdiv) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			document.getElementById(thisdiv).innerHTML = http_request.responseText;
		} else {
			alert('There was a problem with the request.');
		}
	}
}


//from http://sujithcjose.blogspot.com/2007/10/zero-padding-in-java-script-to-add.html
function zeroPad(num,count) { 
	var numZeropad = num + '';
	while(numZeropad.length < count) {
	numZeropad = "0" + numZeropad; 
	}
	return numZeropad;
}


function deleteAccount(code) {
	var conftext='WARNING!\n\nPLEASE READ CAREFULLY FIRST: By clicking \'OK\' you will be suspending your Park On My Drive account. This means that you will not be able to log in to your My Page; also, any spaces you have created will no longer appear in any searches, and can no longer be booked by other users. You will have to contact us directly if you want your user identity re-activated, for which there may be an admin charge.\n\nAre you sure you want to suspend your account?';
if (confirm(conftext)) {
	delUrl = 'login.php?del=' + code;
    document.location = delUrl;
  }
}




//										14/03/11	NEW BOOKING TRANSFER AND UPDATE FUNCTIONS
function txSpace (booking){
	var n = prompt("Please enter the SPACE No. you'd like to transfer this request to.");
	if (n!="" && n != null){
		if ((isNaN(parseFloat(n))) || (n>99999)){
			alert ("That's an invalid booking number, please try again");
			return false;
		}
		else if (!isFinite(n)){
			alert ("That's not a finite number, please try again");
			return false;
		}
		else if ( n % 1 != 0){
			alert ("That's not a whole number, please try again");
			return false;
		}
		else {
		var loc = "mypage.php?b="+booking+"&tx="+n;
		window.location=loc;
		}
	}
}


function approveBooking (booking) {
	var n = ("PLEASE READ THIS FIRST: accepting will automatically reject and delete any other requests for this space and time. You should transfer any other requests to another of your spaces before continuing. \n\nIf you have another space that is not listed click 'Cancel' now, hit the '+ Click here to add another parking space' link and follow the instructions, then transfer the booking.");
	if (confirm(n)) {
		var loc = "mypage.php?b="+booking+"&app=y";
		window.location=loc;
		}
}

function rejectBooking (booking) {
	var n = ("WARNING: You have chosen to *REJECT* this booking request. Do you wish to continue?");
	if (confirm(n)) {
		var loc = "mypage.php?b="+booking+"&rej=y";
		window.location=loc;
		}
}

function deleteBooking (booking) {
	var n = ("WARNING: You have chosen to *DELETE* your booking request. Do you wish to continue?");
	if (confirm(n)) {
		var loc = "mypage.php?bp="+booking+"&del=y";
		window.location=loc;
		}
}
