function SendPM(divID) {
	if (XMLHttpRequestObject) {
		var obj = document.getElementById(divID);
		// var id = document.getElementById("subuser").value;
		var comment = document.getElementById("comment").value;
		var id = document.getElementById("userid").value;
		// var withimages = document.getElementById("withimages").value;
		// alert(withimages); return false;

		if (comment == '' || id == '') {
			alert ("Please enter a comment to be sent to this user. If you have already done this, and this error continues to occur, please contact a member of staff.");
			return false;
		} else {		
			obj.innerHTML = "Posting your comment.<br/><img src=\"/images/animation/loading.gif\"><br/>Please Wait";
			// Must tell it that we are opening it in POST format
			XMLHttpRequestObject.open("POST", "/user.php?do=postpm", true);
			// Also tell if which content-type
			XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			// Create a null function
			XMLHttpRequestObject.onreadystatechange = function() {
				// Check to make sure download is 100% ready
				// 200 to make sure download is ready
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
					// Respond with error code / response in divid
					var response = XMLHttpRequestObject.responseText;
					var details = new Array();
					
					details = response.split('|');
					
					// This now makes details[0] the action
					if (details[0] == 'refresh') {
						// We must now refresh
						obj.innerHTML = "Your comment has been sent";
						document.getElementById("comment").style.visibility = "hidden";
						document.getElementById("sendpm").style.visibility = "hidden";
					} else {
						obj.innerHTML = details[0];	

					}
				}	
			}
			
			XMLHttpRequestObject.send("comment=" + encodeURI(comment) + "&uid=" + encodeURI(id));
		}
	}
}

function CheckPM(divID) {
	if (XMLHttpRequestObject) {
		DisplayWin("MYPM", "650");
		
		var obj = document.getElementById(divID);
		
		// Must tell it that we are opening it in POST format
		XMLHttpRequestObject.open("POST", "/user.php?do=getpm", true);
		// Also tell if which content-type
		XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		// Create a null function
		XMLHttpRequestObject.onreadystatechange = function() {
			// Check to make sure download is 100% ready
			// 200 to make sure download is ready
			if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
				// Respond with error code / response in divid
				var response = XMLHttpRequestObject.responseText;
				var details = new Array();
				
				details = response.split('|');
				
				obj.innerHTML = details[0];	
				
			}	
		}
		XMLHttpRequestObject.send(null);
	}
}

function ReplyPM(divID, pmid) {
	if (XMLHttpRequestObject) {
		DisplayWin("Reply", "400", "1");
		
		var obj = document.getElementById(divID);
		var id =  pmid;

		// Must tell it that we are opening it in POST format
		XMLHttpRequestObject.open("POST", "/user.php?do=buildreply", true);
		// Also tell if which content-type
		XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		// Create a null function
		XMLHttpRequestObject.onreadystatechange = function() {
			// Check to make sure download is 100% ready
			// 200 to make sure download is ready
			if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
				// Respond with error code / response in divid
				var response = XMLHttpRequestObject.responseText;
				var details = new Array();
				
				details = response.split('|');
				
				obj.innerHTML = details[0];	
				
			}	
		}
		XMLHttpRequestObject.send("id=" + encodeURI(id));
	}
}



function SendReply(divID) {
	if (XMLHttpRequestObject) {
		var obj = document.getElementById(divID);
		// var id = document.getElementById("subuser").value;
		var comment = document.getElementById("comment").value;
		var id = document.getElementById("id").value;
		// var withimages = document.getElementById("withimages").value;
		// alert(withimages); return false;
		if (comment == '' || id == '') {
			alert ("Please enter a message to be sent to this user. If you have already done this, and this error continues to occur, please contact a member of staff.");
			return false;
		} else {		
			obj.innerHTML = "Posting your comment.<br/><img src=\"/images/animation/loading.gif\"><br/>Please Wait";
			// Must tell it that we are opening it in POST format
			XMLHttpRequestObject.open("POST", "/user.php?do=postpmreply", true);
			// Also tell if which content-type
			XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			// Create a null function
			XMLHttpRequestObject.onreadystatechange = function() {
				// Check to make sure download is 100% ready
				// 200 to make sure download is ready
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
					// Respond with error code / response in divid
					var response = XMLHttpRequestObject.responseText;
					var details = new Array();
					
					details = response.split('|');
					
					// This now makes details[0] the action
					if (details[0] == 'refresh') {
						// We must now refresh
						obj.innerHTML = "Your comment has been sent";
						document.getElementById("comment").style.visibility = "hidden";
						document.getElementById("sendpm").style.visibility = "hidden";
					} else {
						obj.innerHTML = details[0];	

					}
				}	
			}
			
			XMLHttpRequestObject.send("comment=" + encodeURI(comment) + "&id=" + encodeURI(id));
		}
	}
}

function EnterReply() {
	if (IsEmpty("messagetitle")) {
		alert("Please enter a title");
		return false;
	} else if (IsEmpty("messagereply")) {
		alert("Please enter a reply into the reply box. We cannot send this user a blank message!");
		return false;
	} else {
		return true;
	}
}

function SendNewMessage() {
	if (IsEmpty("messagetitle")) {
		alert("Please enter a message title");
		return false;
	} else if (IsEmpty("messagereply")) {
		alert("Please enter a reply into the reply box. We cannot send this user a blank message!");
		return false;
	} else {
		return true;
	}
}

function SendVideo(divID, userid) {
	if (XMLHttpRequestObject) {
		var obj = document.getElementById(divID);

		DisplayWin("PMVideo", "400");
		
		if (userid == '') {
			alert ("Fatal error with userid. Contact a member of staff asap.");
			return false;
		} else {	
			obj.innerHTML = "<div style=\"width:100%;text-align:center;\"><img src=\"/images/animation/loading.gif\"></div>";	
			// Must tell it that we are opening it in POST format
			XMLHttpRequestObject.open("POST", "/user.php?do=postpmvideo", true);
			// Also tell if which content-type
			XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			// Create a null function
			XMLHttpRequestObject.onreadystatechange = function() {
				// Check to make sure download is 100% ready
				// 200 to make sure download is ready
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
					// Respond with error code / response in divid
					var response = XMLHttpRequestObject.responseText;
					obj.innerHTML = response;	
				}	
			}
			
			XMLHttpRequestObject.send("id=" + encodeURI(userid));
		}
	}
}

function OpenPM(divID, userid) {
	if (XMLHttpRequestObject) {
		var obj = document.getElementById(divID);
		
		DisplayWin("OpenPM", "380");
		
		if (userid == '') {
			alert ("Fatal error with userid. Contact a member of staff asap.");
			return false;
		} else {	
			obj.innerHTML = "<div style=\"width:100%;text-align:center;\"><img src=\"/images/animation/loading.gif\"></div>";	
			// Must tell it that we are opening it in POST format
			XMLHttpRequestObject.open("POST", "/user.php?do=openpm", true);
			// Also tell if which content-type
			XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			// Create a null function
			XMLHttpRequestObject.onreadystatechange = function() {
				// Check to make sure download is 100% ready
				// 200 to make sure download is ready
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
					// Respond with error code / response in divid
					var response = XMLHttpRequestObject.responseText;
					obj.innerHTML = response;	
				}	
			}
			
			XMLHttpRequestObject.send("id=" + encodeURI(userid));
		}
	}
}

function EditProfile(divID, userid) {
	if (XMLHttpRequestObject) {
		var obj = document.getElementById(divID);
		
		DisplayWin("OpenDetails", "800");
		
		if (userid == '') {
			alert ("Fatal error with userid. Contact a member of staff asap.");
			return false;
		} else {	
			obj.innerHTML = "<div style=\"width:100%;text-align:center;\"><img src=\"/images/animation/loading.gif\"></div>";	
			// Must tell it that we are opening it in POST format
			XMLHttpRequestObject.open("POST", "/user.php?do=editprofile", true);
			// Also tell if which content-type
			XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			// Create a null function
			XMLHttpRequestObject.onreadystatechange = function() {
				// Check to make sure download is 100% ready
				// 200 to make sure download is ready
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
					// Respond with error code / response in divid
					var response = XMLHttpRequestObject.responseText;
					obj.innerHTML = response;	
				}	
			}
			
			XMLHttpRequestObject.send("id=" + encodeURI(userid));
		}
	}
}