//data retreval functions

var siteMode = 1;
if(siteMode == 1){
	var linksurl = "http://www.swinger-personals.co.uk/";
	var scripturl = "http://www.swinger-personals.co.uk/includes/ajax_files/";
	var imagesurl = "http://www.swinger-personals.co.uk/images/";
	var photosurl = "http://www.swinger-personals.co.uk/photos/";	
}
else{
	var linksurl = "http://localhost/swinger-personals.co.uk/";
	var scripturl = "http://localhost/swinger-personals.co.uk/includes/ajax_files/";
	var imagesurl = "http://localhost/swinger-personals.co.uk/images/";
	var photosurl = "http://localhost/swinger-personals.co.uk/photos/";	
}

function getGroupVideos(groupid, page){

	var theDiv = document.getElementById("videos_div");
	theDiv.innerHTML = "";
	
	if(page == "") page = 1;
	
	addLoader("videos_div", "contentLoader1");
	new Ajax.Updater(theDiv, scripturl + 'loadgroupvideos.php', { method: 'POST', parameters: {groupid: groupid, page: page},
		onSuccess: function(transport){
			removeLoader("extraPhotosContainer1");		
		}
	});
	
}

function getGroupPhotos(groupid, page){

	var theDiv = document.getElementById("photos_div");
	theDiv.innerHTML = "";
	
	if(page == "") page = 1;
	
	addLoader("photos_div", "contentLoader1");
	new Ajax.Updater(theDiv, scripturl + 'loadgroupphotos.php', { method: 'POST', parameters: {groupid: groupid, page: page},
		onSuccess: function(transport){
			removeLoader("extraPhotosContainer1");		
		}
	});
	
}

function getGroupMembers(groupid, page){

	var theDiv = document.getElementById("members_div");
	theDiv.innerHTML = "";
	if(page == "") page = 1;
	
	addLoader("members_div", "contentLoader2");
	new Ajax.Updater(theDiv, scripturl + 'loadgroupmembers.php', { method: 'POST', parameters: {groupid: groupid, page: page},
		onSuccess: function(transport){
			removeLoader("extraPhotosContainer2");		
		}
	});
	
}

function loadOtherPhotos(userid, page){

	var theDiv = document.getElementById("extraPhotosContainer");
	if(page == "") page = 1;
	
	addLoader("extraPhotosContainer", "contentLoader");
	new Ajax.Updater(theDiv, scripturl + 'loadextraphotos.php', { method: 'POST', parameters: {userid: userid, page: page},
		onSuccess: function(transport){
			removeLoader("extraPhotosContainer");		
		}
	});
	
}

function startOnlineNotify(theId){


	var body  = document.getElementsByTagName("body").item(0);
	new PeriodicalExecuter(function(pe){ 
	
		var temp = document.getElementById("friendsNotifyHolder");
		if(temp != null) body.removeChild(temp);

		new Ajax.Request(scripturl + 'checkfriendsonline.php', { method: 'POST', parameters: {userid: theId},
			onSuccess: function(transport){	
				var json  = eval('(' + transport.responseText + ')');
				var errors = json[0]['errors'];
				
				if(errors == '0' && json.length > 1){
				

					var theDiv = document.createElement("div");
					theDiv.id = "friendsNotifyHolder";
					theDiv.name = "friendsNotifyHolder";
					body.appendChild(theDiv);
					
					theImage = document.createElement("img");
					theImage.src = imagesurl + "icons/delete.gif";
					theImage.align = 'right';	
					
					
					theImage.onclick = function(){				
						body.removeChild(theDiv);
					}				
					theDiv.appendChild(theImage);
					

					for(x=1; x < json.length; x++){
						username = json[x]['username'];
					}

					theDiv.className = 'friendsNotifyHolder';
					theDiv.position = "absolute";
					theDiv.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='160' height='85' id='onlineFlash' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='" + imagesurl + "flash/online-box.swf' /><param name='quality' value='high' /><param name='FlashVars' VALUE='username=" + username + "'><embed src='" + imagesurl + "flash/online-box.swf' quality='high' width='160' height='85' name='link_tool' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' FlashVars='username=" + username + "' /></object>";
					
					
					moveDiv(theDiv);
					
					window.onscroll = function(){	
						moveDiv(theDiv);
					}

					theDiv.style.display = 'block';

				}
			}
		});		
		
	}, 6); 
}

function addLoader(theDiv, loaderName){
	
	theDiv = document.getElementById(theDiv);
	
	tempImage = document.createElement("img");
	tempImage.src = imagesurl + "icons/loading.gif";
	tempImage.alt = "Content loading, please wait";
	tempImage.id = loaderName;;
	tempImage.name = loaderName;

	theDiv.style.textAlign = 'center';
	theDiv.appendChild(tempImage);
	
}

function removeLoader(loaderName){

	document.removeChild(document.getElementById(loaderName));
	
}

function loadInterestedMembers(theId, theDiv){

	addLoader(theDiv, "contentLoader");
	theDiv = document.getElementById(theDiv);
	
	new Ajax.Updater(theDiv, scripturl + 'loadinterestedmembers.php', { method: 'POST', parameters: {userid: theId},
		onSuccess: function(transport){
			removeLoader("contentLoader");
		}
	});
	
}

function loadLookedAt(theId, theDiv){

	addLoader(theDiv, "contentLoader");
	theDiv = document.getElementById(theDiv);	
	eventsDiv = document.getElementById("events_div");

	new Ajax.Updater(theDiv, scripturl + 'loadlookedat.php', { method: 'POST', parameters: {userid: theId},
		onSuccess: function(transport){
			

			theDiv.style.textAlign = 'left';
			removeLoader("contentLoader");
		}
	});
}
	

function loadEmoticons(divName){
	theDiv = document.getElementById(divName);
	new Ajax.Updater(theDiv, scripturl + 'loademoticons.php')		
}

function startDraftSaver(){
	new PeriodicalExecuter(saveDraft, 10); 
}

function saveDraft(){

	var messageSubject = document.getElementById("subject").value;
	var messageContent = document.getElementById("post").value;
	var messageTo = document.getElementById("to").value;
	var messageref = document.getElementById("messageref").value;

	new Ajax.Request(scripturl + 'savemessagedraft.php', { method: 'POST', parameters: {id: messageref, subject: messageSubject, message: messageContent, to: messageTo},
			onSuccess: function(transport){	
				var json  = eval('(' + transport.responseText + ')');
				
				theCount = json[0]['draftCount'];
				if(parseInt(theCount) > 0){
					theHolder = document.getElementById('dc_holder');
					theHolder.innerHTML = "(" + theCount + ")";
				}

			}
	});
	
}

function removePhotoMsg(id){
	attachedDiv = document.getElementById("attachedFiles");
	theDiv = document.getElementById("attachmentdiv");

	new Ajax.Request(scripturl + 'updatephotomsg.php', { method: 'POST', parameters: {id: id, type: 2},
		onSuccess: function(transport){	
			var json  = eval('(' + transport.responseText + ')');

			attachedDiv.removeChild(document.getElementById(id));
		}
	});	

}

function loadAlreadyAttachedPhotos(){

	attachedDiv = document.getElementById("attachedFiles");
	theDiv = document.getElementById("attachmentdiv");
	theErrorDiv = document.getElementById("attachError");

	new Ajax.Request(scripturl + 'updatephotomsg.php', { method: 'POST', parameters: {type: 3},
		onSuccess: function(transport){	
			var json  = eval('(' + transport.responseText + ')');


			for(x=0; x < json.length; x++){
				//add the photo to the div

				var id = json[x]['id'];
				var filename = json[x]['filename'];

				var tempImage = document.createElement("img");
				tempImage.src = linksurl + "/photos/small/" + filename;
				tempImage.setAttribute('id', id);
				tempImage.style.margin = "5px";
				
				tempImage.onclick = function(){	
					removePhotoMsg(id);
				}
				
				attachedDiv.appendChild(tempImage);
			}
		}
	});

	attachedDiv.style.display = 'block';	

}

function addPhotoMsg(id, filename){

	attachedDiv = document.getElementById("attachedFiles");
	theDiv = document.getElementById("attachmentdiv");
	theErrorDiv = document.getElementById("attachError");

	new Ajax.Request(scripturl + 'updatephotomsg.php', { method: 'POST', parameters: {id: id, type: 1},
		onSuccess: function(transport){	
			var json  = eval('(' + transport.responseText + ')');
			var errors = json[0]['errors'];

			if(parseInt(errors) == 0){
				//add the photo to the div
				var tempImage = document.createElement("img");
				tempImage.src = linksurl + "/photos/small/" + filename;
				tempImage.setAttribute('id', id);
				tempImage.style.margin = "5px";
				
				tempImage.onclick = function(){	
					removePhotoMsg(id);
				}
				
				attachedDiv.appendChild(tempImage);
			}
			else{
				html = "<ul>";
				for(var x=1;  x < json.length; x++){
					html = html + json[x]['error'];
				}
				html = html + "</ul>";
				theErrorDiv.innerHTML = html;
			}
			
			theDiv.innerHTML = "";
			theDiv.style.display = "none";
		}
	});	

}

function loadPhotoAttach(){
	theDiv = document.getElementById("attachmentdiv");
	theErrorDiv = document.getElementById("attachError");
	theErrorDiv.innerHTML = "";
	

	
	if(theDiv.style.display == 'block'){
		theDiv.style.display = 'none';
		theDiv.innerHTML = "";
	}
	else{
		theDiv.style.display = 'block'
		
		//load the loading symbol
		var tempImage = document.createElement("img");
		tempImage.src = imagesurl + "/icons/loading.gif";
		tempImage.style.margin = "5px";
		tempImage.alt = "Content loading";
		theDiv.appendChild(tempImage);
		
		new Ajax.Updater(theDiv, scripturl + 'attachphoto.php')
	}
}

function removeVideoMsg(id){
	attachedDiv = document.getElementById("attachedFiles");
	theDiv = document.getElementById("attachmentdiv");

	new Ajax.Request(scripturl + 'updatevideomsg.php', { method: 'POST', parameters: {id: id, type: 2},
		onSuccess: function(transport){	
			var json  = eval('(' + transport.responseText + ')');

			attachedDiv.removeChild(document.getElementById(id));
		}
	});	

}

function loadAlreadyAttachedVideos(){

	attachedDiv = document.getElementById("attachedFiles");
	theDiv = document.getElementById("attachmentdiv");
	theErrorDiv = document.getElementById("attachError");

	new Ajax.Request(scripturl + 'updatevideomsg.php', { method: 'POST', parameters: {type: 3},
		onSuccess: function(transport){	
			var json  = eval('(' + transport.responseText + ')');

			for(x=0; x < json.length; x++){
				//add the photo to the div
				
				var id = json[x]['id'];
				var filename = json[x]['filename'];

				var tempImage = document.createElement("img");
				tempImage.src = filename;
				tempImage.setAttribute('id', id);
				tempImage.style.margin = "5px";
				
				tempImage.onclick = function(){	
					removeVideoMsg(id);
				}
				
				attachedDiv.appendChild(tempImage);
			}
		}
	});

	attachedDiv.style.display = 'block';

}

function addVideoMsg(id, filename){

	attachedDiv = document.getElementById("attachedFiles");
	theDiv = document.getElementById("attachmentdiv");
	theErrorDiv = document.getElementById("attachError");

	new Ajax.Request(scripturl + 'updatevideomsg.php', { method: 'POST', parameters: {id: id, type: 1},
		onSuccess: function(transport){	
			var json  = eval('(' + transport.responseText + ')');
			var errors = json[0]['errors'];

			if(parseInt(errors) == 0){
				//add the photo to the div
				var tempImage = document.createElement("img");
				tempImage.src = filename;
				tempImage.alt = "Attached image";
				tempImage.setAttribute('id', id);
				tempImage.style.margin = "5px";
				
				tempImage.onclick = function(){	
					removeVideoMsg(id);
				}
				
				attachedDiv.appendChild(tempImage);
			}
			else{
				html = "<ul>";
				for(var x=1;  x < json.length; x++){
					html = html + json[x]['error'];
				}
				html = html + "</ul>";
				theErrorDiv.innerHTML = html;
			}
			
			theDiv.innerHTML = "";
			theDiv.style.display = "none";
		}
	});	

}

function loadVideoAttach(){
	theDiv = document.getElementById("attachmentdiv");
	theErrorDiv = document.getElementById("attachError");
	theErrorDiv.innerHTML = "";
	
	if(theDiv.style.display == 'block'){
		theDiv.style.display = 'none';
		theDiv.innerHTML = "";
	}
	else{
		//load the loading symbol
		var tempImage = document.createElement("img");
		tempImage.src = imagesurl + "/icons/loading.gif";
		tempImage.style.margin = "5px";
		tempImage.alt = "Content loading";
		theDiv.appendChild(tempImage);
		
		theDiv.style.display = 'block'
		new Ajax.Updater(theDiv, scripturl + 'attachvideo.php')
	}
}

function suggestTopics(e){

	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	var theTextarea = document.getElementById("ticket");
	var theDiv = document.getElementById("suggestHolder");

	if(parseInt(key) == 32){
		//send text off to be searched for relevant articles
		var theText = theTextarea.value;
		theText = encodeURI(theText);

		new Ajax.Request(scripturl + 'suggesttopics.php', { method: 'POST', parameters: {text: theText},
			onSuccess: function(transport){
				
				var json  = eval('(' + transport.responseText + ')');
				var theDiv2 = document.getElementById("suggestedTopics");
				var results = parseInt(json.length);
				
				theDiv2.innerHTML = "";

				if(results > 0){	

					theDiv.style.display = 'block';
				
					for(var x=0; x < results; x++){		
					
						var theId = json[x]['id'];
						var theTitle = json[x]['title'];
	
						var theLink = document.createElement("a");
						theLink.setAttribute('href', "view-article.html?id=" + theId);
						theLink.setAttribute('target', "blank");
						
						var theAnchor = document.createTextNode(theTitle);
						theLink.appendChild(theAnchor);	
						
						theDiv2.appendChild(theLink);
						
						var theBr = document.createElement("br");
						theDiv2.appendChild(theBr);

					}
				}
				else theDiv.style.display = 'none';
			}
		});	
	}
}

function updateComment(theType, theID){

	var commentText = document.getElementById("comment").value;

	new Ajax.Request(scripturl + 'updatephoto.php', { method: 'POST', parameters: {type: theType, id: theID, text: commentText},
		onSuccess: function(transport){
		
			var json  = eval('(' + transport.responseText + ')');
			var errors =  json[0]['errors'];
			var comment = json[0]['comment'];
			
			commentBox = document.getElementById('comment');
			theText = document.getElementById("thetext");
			theText.style.display = 'block';
			
			if(errors == 1){
				//do errors
				var html = "<ul>";
				
				for(x=1; x < json.length; x++){
					error = json[x]['error'];
					html = html + "<li>" + error + "</li>";
				}
				html = html + "</ul><br /><br />";
				theText.innerHTML = html;
			}
			else{
				//update text
				theText.innerHTML = "<p>The comment has been updatead</p>";
				commentBox.value = comment;
				
			}
		}
	});	
	

}

function authAction(actionType){

	if(actionType == 3){
	
		//check to see if they have double clicked

		//load message box so they can tell the user why
		theText = document.getElementById("thetext");

		if(document.getElementById("formHolder") == undefined){
		
			var theDiv = document.createElement("div");
			theDiv.id = "formHolder";
			theDiv.name = "formHolder";
			
			var para = document.createElement("p");
			var sometext = document.createTextNode("Please enter a reason why photo was deleted") ;
			
			para.appendChild(sometext);
			theDiv.appendChild(para);

			var theform = document.createElement("form");
			theform.id = "messageForm";
			theform.name = "messageForm";
			theform.onsubmit = function(){
				new Ajax.Request(scripturl + 'authphoto.php', { method: 'POST', parameters: {id: thisPhoto.id, action: actionType, reason: document.getElementById("message").value, userid: userid, username: thisPhoto.username},
					onSuccess: function(transport){
				
					var json  = eval('(' + transport.responseText + ')');
					var errors =  json[0]['errors'];
					
						if(errors == 1){		
							theText = document.getElementById("thetext");
							theText.style.display = 'block';
							
							//do errors
							var html = "<ul>";
							
							for(x=1; x < json.length; x++){
								error = json[x]['error'];
								html = html + "<li>" + error + "</li>";
							}
							html = html + "</ul><br /><br />";
							theText.innerHTML = html;
						}
						else{
							theText.removeChild(theDiv);
							theText.style.display = 'none';
						
							//move to the next photo
							loadPhoto2Auth();
						}

					}
				});	
				
				return false;
			}
			
			var textarea = document.createElement("textarea");
			textarea.id = "message";
			textarea.name = "message";
			textarea.className = 'form';
			textarea.style.width = "90%";
			textarea.rows = 3;
			theform.appendChild(textarea);
			
			var theBr = document.createElement('br');
			theform.appendChild(theBr);
			var theBr = document.createElement('br');
			theform.appendChild(theBr);
			
			var theBtn = document.createElement('input');
			theBtn.type = "image";
			theBtn.src = imagesurl + '/buttons/next.gif';
			theBtn.alt = 'Send message';
			theBtn.id = "submitButton";
			theform.appendChild(theBtn);
			theDiv.appendChild(theform);
			
			var theBr = document.createElement('br');
			theform.appendChild(theBr);
			var theBr = document.createElement('br');
			theform.appendChild(theBr);
			
			theText.appendChild(theDiv);
			theText.style.display = 'block';
		}
	}
	else{

		new Ajax.Request(scripturl + 'authphoto.php', { method: 'POST', parameters: {id: thisPhoto.id, action: actionType, userid: userid},
			onSuccess: function(transport){
			
				var json  = eval('(' + transport.responseText + ')');
				var errors =  json[0]['errors'];
				
				if(errors == 1){		
					theText = document.getElementById("thetext");
					theText.style.display = 'block';
					
					//do errors
					var html = "<ul>";
					
					for(x=1; x < json.length; x++){
						error = json[x]['error'];
						html = html + "<li>" + error + "</li>";
					}
					html = html + "</ul><br /><br />";
					theText.innerHTML = html;
				}
				else{
					//move to the next photo
					loadPhoto2Auth();
				}

			}
		});	
		
	}

}

function checkPhotoAuthSize(){
	var currentSize = photoArray.length;
	var requiredPhoto = 5 - currentSize;

	if(requiredPhoto > 0) loadPhotoAuth(requiredPhoto);
}

function loadPhoto2Auth(){

	var theImage = document.getElementById('loadedImage');

	theText = document.getElementById("thetext");
	theText.style.display = 'none';

	if(photoArray.length > 0){

		//get last photo into the array
		thisPhoto = photoArray.shift();

		var theComment = document.getElementById('comment');
		var username = document.getElementById('username');
		var email = document.getElementById('email');
		var gender = document.getElementById('gender');

		//load the photo
		theImage.src = thisPhoto.theImage.src;

		//load the comment
		theComment.value = thisPhoto.comment;
		
		//load user details
		username.innerHTML = "<a style='color: #909090; text-decoration: underline;' href='" + linksurl + "/admin/member-lookup.html?userid=" + thisPhoto.userid + "' target='_blank'>" + thisPhoto.username + "</a>";
		email.innerHTML = thisPhoto.email;
		gender.innerHTML = thisPhoto.type;
		
		userid = thisPhoto.userid;
		
		//check the size of the cached photos
		checkPhotoAuthSize();
		
		//load the users notes
		theNotes = document.getElementById("notesHolder");
		theNotes.innerHTML = "<p style='font-weight: bold; color: #909090;'>Loading notes....</p>";
		loadUserNotes();
	}
	else{
		//no photos left
		theText = document.getElementById('buttons');
		theImage = document.getElementById('photoDetails');
		
		theImage.style.display = 'none';
		theText.style.display = 'block';
		theText.innerHTML = "<p>There are currently no photos that need authing</p>";
	}
}

function loadPhotoAuth(num, firsttime){

	new Ajax.Request(scripturl + 'loadphotostoauth.php', { method: 'POST', parameters: {num: num},
		onSuccess: function(transport){
			var json  = eval('(' + transport.responseText + ')');
			var numreturned =  json[0]['numphotos'];

			if(numreturned > 0){
	
				for(x=1; x < json.length; x++){

					var id = json[x]['id'];
					var filename = json[x]['filename'];
					var comment = json[x]['comment'];
					var userid = json[x]['userid'];
					var username = json[x]['username'];
					var type = json[x]['type'];
					var email = json[x]['email'];

					tempPhoto = new Object();
					tempPhoto.id = id;
					tempPhoto.filename = filename;
					tempPhoto.comment = comment;
					tempPhoto.userid = userid;
					tempPhoto.username = username;
					tempPhoto.type = type;
					tempPhoto.email = email;

					theImage = document.createElement('img');
					theImage.setAttribute('id', "photo_" + id);
					theImage.setAttribute('src', photosurl + 'fullsize/' + filename);
					theImage.setAttribute('width', 250);
					theImage.setAttribute('height', 125);
					tempPhoto.theImage = theImage;

					photoArray.push(tempPhoto);
				}

				if(firsttime) loadPhoto2Auth();		
			}
			
			if(firsttime && numreturned == 0){			
				theText = document.getElementById('buttons');
				theImage = document.getElementById('photoDetails');
		
				theImage.style.display = 'none';
				theText.style.display = 'block';
				theText.innerHTML = "<p>There are currently no photos that need authing</p>";
			}
		}
	});	

}

function sendMessage(theUser, from){

	theMessage = document.getElementById("message").value;
	theSubject = document.getElementById("subject").value;
	fromAdmin = document.message_form.fromadmin;
	
	for( i = 0; i < fromAdmin.length; i++ ){
		if( fromAdmin[i].checked == true ) fromAdminSelected = fromAdmin[i].value;
	}
	
	if(fromAdminSelected == '1') from = 37;
	
	new Ajax.Request(scripturl + 'sendmessage.php', { method: 'POST', parameters: {message: theMessage, subject: theSubject, userid: theUser, fromid: from},
		onSuccess: function(transport){
			var json  = eval('(' + transport.responseText + ')');
			var errors =  json[0]['errors'];
			
			if(errors == 1){
				theText = document.getElementById("thetext");
				theText.style.display = 'block';
				
				//do errors
				var html = "<ul>";
				
				for(x=1; x < json.length; x++){
					error = json[x]['error'];
					html = html + "<li>" + error + "</li>";
				}
				html = html + "</ul><br /><br />";
				theText.innerHTML = html;
			}
			else{
				document.getElementById("message").value = "";
				document.getElementById("subject").value = "";
			}
			
		}
	});
}

function loadUserNotes(userid){
	theDiv = document.getElementById("notesHolder");
	new Ajax.Updater(theDiv, scripturl + 'loadusernotes.php', {parameters: {userid: userid}})		
}

function addUserNote(userid){

	var note = document.getElementById("note").value;

	new Ajax.Request(scripturl + 'addusernote.php', { method: 'POST', parameters: {userid: userid, note: note},
		onSuccess: function(transport){
		
			var json  = eval('(' + transport.responseText + ')');
			var errors =  json[0]['errors'];
			
			if(errors == 0){
				document.getElementById("note").value = "";
				loadUserNotes();
			}
			else{
				theText = document.getElementById("thetext");
				theText.style.display = 'block';
				
				//do errors
				var html = "<ul>";
				
				for(x=1; x < json.length; x++){
					error = json[x]['error'];
					html = html + "<li>" + error + "</li>";
				}
				html = html + "</ul><br /><br />";
				theText.innerHTML = html;
			}
		}
	});	
}
	
	
	
function resendVerifyCode(userid){

	var theSpan = document.getElementById('verifySpan');

	new Ajax.Request(scripturl + 'resendverifyemail.php', { method: 'POST', parameters: {userid: userid},
		onSuccess: function(transport){
			var json  = eval('(' + transport.responseText + ')');
	
			//check to see if the entry was valid
			var status = json[0].failed;
			if(status == 0) theSpan.innerHTML = "<span style='color: green;'>Sent</span>";
			else theSpan.innerHTML = "<span style='color: red;'>Error sending</span>";

		}
	});	
}

function cancelsubscription(subid){
	
	var theSpan = document.getElementById('cancelStatus');
	var fRet = confirm("This will cancel their subscription with 3bill! are you sure you wish to continue?");
	if (fRet == true){
		new Ajax.Request(scripturl + 'cancel3billsubscription.php', { method: 'POST', parameters: {subid: subid},
			onSuccess: function(transport){
				var json  = eval('(' + transport.responseText + ')');

				//check to see if the entry was valid
				var status = json[0].status;
				if(status == 1) theSpan.innerHTML = "<span style='color: green;'>Done</span>";
				else theSpan.innerHTML = "<span style='color: red;'>Failed</span>";

			}
		});	
	}
	
}

function loadmailtemplate(){
	
	var theSelect = document.getElementById('premail');
	var theTextArea = document.getElementById('message');
	var theSubject = document.getElementById('subject');
	
	var selectedId = theSelect[theSelect.selectedIndex].value;

	if(selectedId == ""){
		theTextArea.value = "";
		theSubject.value = "";
	}
	else{
		new Ajax.Request(scripturl + 'loadmailtemplate.php', { method: 'POST', parameters: {id: selectedId},
			onSuccess: function(transport){
				var json  = eval('(' + transport.responseText + ')');

				//check to see if the entry was valid
				var subject = json[0].subject;
				var message = json[0].mail;
				
				theTextArea.value = message;
				theSubject.value = subject;

			}
		});
	}
}

function loadphoto(photoid){
	var theDiv = document.getElementById("photo_holder");
	theDiv.innerHTML = "";
	
	new Ajax.Updater(theDiv, scripturl + 'loadphoto.php', {parameters: {photoid: photoid}})	
}

function loadusersphotos(userid, page){

	var theDiv = document.getElementById("users_photos_holder");
	theDiv.innerHTML = "";
	
	new Ajax.Updater(theDiv, scripturl + 'loadusershotos.php', {parameters: {userid: userid, page: page}})

}

function checkPassword(){

	var formValue1 = document.getElementById("password").value;
	var formValue2 = document.getElementById("password2").value;
	var theContainer = document.getElementById("password_details");
	var theImage = document.getElementById("password_image");

	if(formValue1 != "" && formValue2 != ""){
	
		new Ajax.Request(scripturl + 'checkpassword.php', { method: 'POST', parameters: {password1: formValue1, password2: formValue2},
			onSuccess: function(transport){
				var json  = eval('(' + transport.responseText + ')');

				//check to see if the entry was valid
				var valid = json[0].valid;
				var username = json[0].password;
				
				if(valid == 1){
					//change error to cross
					theContainer.style.display = 'none';
					theImage.src = imagesurl + "icons/tick.gif";
					theImage.alt = "Username is ok";
				}
				else{
				
					//change error to cross
					theImage.src = imagesurl + "icons/cross.gif";
					theImage.alt = "Your password is not ok";
				
					html = "<p style='color: #909090; font-weight: bold;'>The password you entered was invalid, below is some more info</p>";
					for(i=1; i<json.length; i++){
						var thisError = json[i].error;
						html = html + thisError + "<br />";
					}
					
					theContainer.innerHTML = html;
					theContainer.style.display = 'block';
				}
			}
		});
	}
	else{
		theContainer.style.display = 'none';
		theImage.src = imagesurl + "icons/form-star.gif";
		theImage.alt = "You must fill in this field";
	}
}

function checkUsername(){
	var formValue = document.getElementById("username").value;
	var theContainer = document.getElementById("username_details");
	var theImage = document.getElementById("username_image");
	
	if(formValue != ""){

		new Ajax.Request(scripturl + 'checkusername.php', { method: 'POST', parameters: {username: formValue},
			onSuccess: function(transport){
				var json  = eval('(' + transport.responseText + ')');

				//check to see if the entry was valid
				var valid = json[0].valid;
				var username = json[0].username;
				
				if(valid == 1){
					//change error to cross
					theContainer.style.display = 'none';
					theImage.src = imagesurl + "icons/tick.gif";
					theImage.alt = "Username is ok";
				}
				else{
				
					//change error to cross
					theImage.src = imagesurl + "icons/cross.gif";
					theImage.alt = "Your username is not ok";
				
					html = "<p style='color: #909090; font-weight: bold;'>The username " + username + " was invalid, below is some more info</p>";
					for(i=1; i<json.length; i++){
						var thisError = json[i].error;
						html = html + thisError + "<br />";
					}
					
					theContainer.innerHTML = html;
					theContainer.style.display = 'block';
				}
			}
		});
	}
	else{
		theContainer.style.display = 'none';
		theImage.src = imagesurl + "icons/form-star.gif";
		theImage.alt = "You must fill in this field";
	}
}

function checkEmailAddress(){
	var formValue = document.getElementById("email").value;
	var theContainer = document.getElementById("email_details");
	var theImage = document.getElementById("email_image");
	
	if(formValue != ""){

		new Ajax.Request(scripturl + 'checkemail.php', { method: 'POST', parameters: {email: formValue},
				onSuccess: function(transport){
				var json  = eval('(' + transport.responseText + ')');

				//check to see if the entry was valid
				var valid = json[0].valid;
				var email = json[0].email;
				
				if(valid == 1){
					//change error to cross
					theContainer.style.display = 'none';
					theImage.src = imagesurl + "icons/tick.gif";
					theImage.alt = "Email is ok";
				}
				else{
				
					//change error to cross
					theImage.src = imagesurl + "icons/cross.gif";
					theImage.alt = "Your email is not ok";
				
					html = "<p style='color: #909090; font-weight: bold;'>The email " + email + " you entered was invalid, below is some more info</p>";
					for(i=1; i<json.length; i++){
						var thisError = json[i].error;
						html = html + thisError + "<br />";
					}
					
					theContainer.innerHTML = html;
					theContainer.style.display = 'block';
				}
			}
		});
	}
	else{
		theContainer.style.display = 'none';
		theImage.src = imagesurl + "icons/form-star.gif";
		theImage.alt = "You must fill in this field";
	}
}

function checkPostcode(){
	var formValue = document.getElementById("postcode").value;
	var theContainer = document.getElementById("postcode_details");
	var theImage = document.getElementById("postcode_image");

	if(formValue != ""){
	
		new Ajax.Request(scripturl + 'checkpostcode.php', { method: 'POST', parameters: {postcode: formValue},
			onSuccess: function(transport){

				var json  = eval('(' + transport.responseText + ')');

				//check to see if the entry was valid
				var valid = json[0].valid;
				var postcode = json[0].postcode;

				if(valid == 1){
					//change error to cross
					theContainer.style.display = 'none';
					theImage.src = imagesurl + "icons/tick.gif";
					theImage.alt = "postcode is ok";
				}
				else{
				
					//change error to cross
					theImage.src = imagesurl + "icons/cross.gif";
					theImage.alt = "Your postcode is not ok";
				
					html = "<p style='color: #909090; font-weight: bold;'>The postcode " + postcode + " was invalid, below is some more info</p>";
					for(i=1; i<json.length; i++){
						var thisError = json[i].error;
						html = html + thisError + "<br />";
					}
					
					theContainer.innerHTML = html;
					theContainer.style.display = 'block';
				}
			}
		});
	}
	else{
		theContainer.style.display = 'none';
		theImage.src = imagesurl + "icons/form-star.gif";
		theImage.alt = "You must fill in this field";
	}
}