
 var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }

//-->
function getViewportData(){
	
	var viewportwidth;
	var viewportheight;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
	if (typeof window.innerWidth != 'undefined'){
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
	
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)	{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	
	// older versions of IE
	
	else{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return [viewportwidth, viewportheight];
	
	//-->
}
$(document).ready(function(){
	message_checker();
	
});
function validate_date(obj){
	if (obj.value){
		var milliseconds = Date.parse(obj.value);
		var month = new Array(12);
		month[0]="Jan";
		month[1]="Feb";
		month[2]="Mar";
		month[3]="Apr";
		month[4]="May";
		month[5]="Jun";
		month[6]="Jul";
		month[7]="Aug";
		month[8]="Sep";
		month[9]="Oct";
		month[10]="Nov";
		month[11]="Dec";	
		
		
		var date = new Date(milliseconds);
		obj.value = month[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear();	
	}
}
function cancelUpload(screenName, obj){
	$.ajax({
		url:"ajax.php", 
		data: "action=cancelUpload&screenName=" + screenName,
		type: "POST",
		success:function(result){
    		$(obj).parent().parent().remove();
 		}
	});
}
function updateLivePhoto(obj, url){
	$('*').removeClass('activePhoto'); 
	$(obj).addClass('activePhoto');
	document.getElementById('updateButton').setAttribute("onclick", "updatePreferences('" + url + "')");	
}
function updatePreferences(url){
	$.ajax({
		url:"ajax.php", 
		data: "action=updatePreferences&url=" + url,
		type: "POST",
		success:function(result){
			$("#photoUpdated").html("Updated");
			var t=setTimeout("removeUpdated()",3000);
 		}
	});
}
function removeUpdated(){
	$("#photoUpdated").html("");
}
function submitForm(){
	var loading = document.createElement('div');
	loading.setAttribute('id', 'loading');
	loading.innerHTML = "<div style='margin:300px auto 0px auto; width:100px; height:50px; vertical-align:middle;'><p style='font-size:30px; margin:auto;'>Loading</p></div>";
	loading.style.left = "0px";
	loading.style.top = "0px";
	document.getElementById('body').appendChild(loading);
	
	
	var t=setTimeout("submitDelayForm()",3000);
	
	
}
function submitDelayForm(){
	document.forms['uploadForm'].submit();	
}
function confirmDelete(file){
	var conf = confirm("Are you sure you want to delete the photo?");
	if (conf == true){
		deletePhoto(file);	
	}
}
function message_checker(){
	$.ajax({
		url:"ajax.php", 
		data: "action=message_checker",
		type: "POST",
		success:function(result){
    		if (result == '1'){
				$("#message_alert").css("visibility", "visible");
			}else{
				$("#message_alert").css("visibility", "hidden");
			}
 		}
	});
	var t=setTimeout("alertMsg()",60000);
}
function post(threadId, replyId, title){
	if (replyId == 0){
		var comment = document.getElementById('newComment').value;
	}else{
		var comment = document.getElementById('replyComment-' + replyId).value;
	}
	
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=post&comment=" + comment + "&threadId=" + threadId + "&replyId=" + replyId + "&title=" + title);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			if (xmlhttp.responseText == "Fail"){
				//cancelReply(replyId);
				alert("Make sure you do not type nonsense. You cannot have words that are longer than 20 characters. Sorry for any inconvenience");
			}else{
				if (replyId == 0){
					document.getElementById('addCommentRow').style.display='none';
				}else{
					document.getElementById('addReplyRow-' + replyId).style.display='none';
				}
				location.reload(true);
			}
		}
	}
	
}
function deleteGoal(goal_id, obj){
	$.ajax({
		url:"ajax.php",
		data: "action=deleteGoal&goal_id=" + goal_id,
		type: "POST", 
		success:function(result){
			$(obj).parent().parent().remove();
		}
	});	
}
function cancelReply(id){
	$("#addReplyRow-" + id).remove();
}
function reply(obj, id, threadId, level){
	var row = obj.parentNode;
	
	var reply = document.createElement('div');
	reply.setAttribute('id', 'addReplyRow-' + id);
	reply.setAttribute('class', 'replyDiv indent-' + level);
	reply.innerHTML = "<textarea id='replyComment-" + id + "' class='replyBox'></textarea><br /><br /><input type='button' value='Post' onclick=\"post('" + threadId + "', '" + id + "', '')\" /><input type='button' value='Cancel' onclick=\"cancelReply('" + id + "')\" />";
	
	if (row.nextSibling){
		row.parentNode.insertBefore(reply, row.nextSibling);
	}else{
		row.parentNode.appendChild(reply);
	}
	document.getElementById("replyComment-" + id).focus();
	
}



function addComment(threadId, title){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	text = document.getElementById("newComment").value;
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=addComment&text=" + text + "&threadId=" + threadId + "&title=" + title);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    $("#addCommentRow").after(xmlhttp.responseText);
			document.getElementById("newComment").value="";
			document.getElementById("addCommentRow").style.display = "none";
    	}
  	}
}
function deleteMessage(option, id){
	
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=deleteMessage&option=" + option + "&id=" + id);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    document.getElementById('message_id_' + id).style.display = "none";
    	}
  	}
}	
function addReply(id, threadId, level){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	text = document.getElementById("newReply" + id).value;
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=addReply&text=" + text + "&id=" + id + "&threadId=" + threadId + "&level=" + level);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    //$("#addCommentRow").after(xmlhttp.responseText);
			
			location.href="threads.php?threadId=" + threadId;
    	}
  	}
	
}
function changePassword() {
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=changePassword");
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    //$("#resetEmailSent").html("Reset Email has been sent");
			
    	}
  	}
	
} 
function changeVisibleThread(threadId) {
	location.href = "threads.php?threadId=" + threadId;
}
function checkDelete(threadId,id){
	if (confirm("Are you sure you want to delete this message?")){
		deleteComment(threadId, id);	
	}
}
function deleteComment(threadId, id){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=deleteComment&id=" + id);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    location.reload(true);
    	}
  	}
}
function findThread(id){
	obj = document.getElementById(id);
	var popup = document.getElementById("findThread");
	obj.appendChild(popup);
	popup.style.display="block";
	popup.style.top="300px";
	sortThreadsPopup();
	
}
function fixQuestion(screenName){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=fixQuestion&screenNameRecover=" + screenName);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			   document.getElementById("recoverQuestion").innerHTML = xmlhttp.responseText;
		}
  	}
}
function popup(left, top, userwidth, file, screenName){
	if ($("#popup")){
		$("#popup").remove();	
	}
	viewportwidth = getViewportData()[0];
	
  	xmlhttp=new XMLHttpRequest();
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=getFileContents&file=" + file + "&screenName=" + screenName);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var popup = document.createElement('div');
			popup.setAttribute('id', 'popup');
			popup.setAttribute('class', 'popup shadow');
			popup.setAttribute('style', 'width:' + userwidth + "px");
			popup.innerHTML = xmlhttp.responseText;
			popup.style.left = ((Math.abs(viewportwidth)/2)-(userwidth/2)) + "px";
			popup.style.top = Math.abs($(window).scrollTop()) + Math.abs(top) + "px";
			
			
			document.getElementById('body').appendChild(popup);
			runStarters();
			
			//set focus
			if (file == "calculator.php"){
				$('#beginning_date').next().click();
			}else if (file == 'compose.php'){
				$("#compose_new_message").focus();
			}else if (file == 'search.php'){
				$("#search_query").focus();
			}
		}
	}
	
}
//general function used for all popups. added July 15, 2011
function popup_new(popup_url, id, screenName, arguments){
	if ($(".popup")){
		$(".popup").remove();
	}
	
	if (screenName){
		var post_data = "screenName=" + screenName;
		if (arguments){
			var i=0;
			while (arguments[i]){
				post_data = post_data + "&arg" + i + "=" + encodeURI(arguments[i]);
				i++;	
			}
		}
	}
	$.ajax({
		url: popup_url,
		type: "POST",
		data:post_data,
		success:function(result){
			var popup = document.createElement('div');
			popup.setAttribute("id", id);
			popup.setAttribute("class", "popup shadow");//this class is required because when clicking on the system cover, it removes this class
			
			//center the popup on the page using offsetWidth and offsetHeight. First, hide the element
			popup.style.visibility = "hidden";
			$('body').append(popup);
			popup.innerHTML = result;
			
			popup.style.left = (((getViewportData()[0] - popup.offsetWidth) / 2) + getScrollXY()[0]) + "px";
			popup.style.top = (((getViewportData()[1] - popup.offsetHeight) / 2) + getScrollXY()[1]) + "px";
			//alert(popup.style.left);
			//setStarters(tags);
			popup.style.visibility = "visible";
			
			runStarters();			
		}
	});
	
}
//get scrolling
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}
function photoSave(){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	var obj = document.getElementById('draggable');	
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=photoSave&top=" + obj.style.top + "&left=" + obj.style.left + "&width=" + obj.style.width);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){ 
			//alert(ui.id);
			location.reload(true);
		}
	}
}
$(document).ready(function(){
	runStarters();
});
function calculate(start, end){
	
	$.ajax({
		url:"ajax.php", 
		data: "action=calculate&start=" + start + "&end=" + end,
		type: "POST",
		success:function(result){
			$("#counter").html(result);
 		}
	});
}
function calculate_from(from_days, from_date){
		$.ajax({
		url:"ajax.php", 
		data: "action=calculate_from&from_days=" + from_days + "&from_date=" + from_date,
		type: "POST",
		success:function(result){
			$("#counter").html(result);
 		}
	});
}
function photoEdit(left, top, userwidth, file, screenName, photo){
	document.getElementById("photoUpload1").style.display='none';
	//document.getElementById("photoUpload2").style.display='none';
	//document.getElementById("photoUpload3").style.display='none';
	//document.getElementById("photoUpload4").style.display='none';
	//document.getElementById("photoUpload5").style.display='none';
 	document.getElementById('photoUpload' + photo).style.display = 'block';
	var popup = document.getElementById('photoUpload' + photo);
	popup.setAttribute('class', 'popup shadow');
	popup.setAttribute('style', "padding:0px;");
	popup.style.left = ((Math.abs(viewportwidth)/2)-(userwidth/2)) + "px";
	popup.style.top = Math.abs($(window).scrollTop()) + Math.abs(top) + "px";
	
}
function deletePhoto(file){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=deletePhoto&file=" + file);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    window.location = "photos.php";
    	}
  	}	
}
function removePopup(){
	var popup = document.getElementById('popup');
  	document.getElementById('body').removeChild(popup);
	
}
function followThread(threadId) {
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=followThread&threadId=" + threadId);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    alert(xmlhttp.responseText);
    	}
  	}
}
function hide(id){
	var obj = document.getElementById(id);
	obj.style.display = "none";
	
	if (id == 'toolbarMore'){
		document.getElementById('toolbarMoreButton').style.backgroundColor="#0047B3";
		document.getElementById('toolbarMoreButton').style.color="#FFFFFF";
		document.getElementById('toolbarMoreButton').setAttribute('onclick', 'show("toolbarMore", "table-row")');
	}
	if (id == 'toolbarAbout'){
		document.getElementById('toolbarAboutButton').style.backgroundColor="#0047B3";
		document.getElementById('toolbarAboutButton').style.color="#FFFFFF";
		document.getElementById('toolbarAboutButton').setAttribute('onclick', 'show("toolbarAbout", "table-row")');
	}
	if (id == 'toolbarContact'){
		document.getElementById('toolbarContactButton').style.backgroundColor="#0047B3";
		document.getElementById('toolbarContactButton').style.color="#FFFFFF";
		document.getElementById('toolbarContactButton').setAttribute('onclick', 'show("toolbarContact", "table-row")');
	}
}		
function openReply(commentRow, screenName){
	if (screenName == ""){
		location.href="#?logout=1";
	}else{
		//alert('hi');
		document.getElementById(commentRow).style.display="table-row";
		/*
		element = document.getElementById("addCommentRow"); 
		document.getElementById("addReplyButton").setAttribute("onclick", "addReply('" + id + "', '" + threadId + "', '" + level + "')");
		parent = document.getElementById(threadRow); 
		
		parent.appendChild(element);
		element.style.display = "table-row";
		//$("#" + threadRow).after(addedElement);
		*/
	}
}
function passwordCheck(obj) {
	password1 = document.getElementById("password1").value;
	password2 = document.getElementById("password2").value;
	if (password1 == password2){ 
		if (password1 == ""){
			document.getElementById("passwordCheck").innerHTML = "";
			document.getElementById("submitCheck").innerHTML = "";
		}else{
			document.getElementById("passwordCheck").innerHTML = "Passwords Match";
			document.getElementById("submitCheck").innerHTML = "";
		}
		return true;
	}else{
		document.getElementById("passwordCheck").innerHTML = "Passwords Do Not Match";
		if (obj.id == "createButton"){
			document.getElementById("submitCheck").innerHTML = "Passwords must match to create an account.";
		}
		return false;
	}
}
function removeSaved() {
	$(".saved").css("display", "none");
}
function save() {
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	if (include_day_1.checked){
		include_day = 1;
	}else{
		include_day = 0;
	}
	
	
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=save&caption=" + caption.value + 
	"&birthdateMonth=" + birthdateMonth.value + 
	"&birthdateDate=" + birthdateDate.value + 
	"&birthdateYear=" + birthdateYear.value + 
	"&gender=" + gender.value + 
	"&orientation=" + orientation.value + 
	"&religion=" + religion.value + 
	"&ethnicity=" + ethnicity.value + 
	"&relationshipStatus=" + relationshipStatus.value + 
	"&interestedInCasual=" + interestedInCasual.checked + 
	"&interestedInDating=" + interestedInDating.checked + 
	"&interestedInRelationship=" + interestedInRelationship.checked + 
	"&interestedInFriend=" + interestedInFriend.checked + 
	"&city=" + city.value + 
	"&state=" + state.value + 
	"&country=" + country.value + 
	"&email=" + email.value + 
	"&zip=" + zip.value + 
	"&recoverQuestion=" + recoverQuestion.value + 
	"&recoverAnswer=" + recoverAnswer.value + 
	"&timezone=" + timezone.value + 
	"&startingThreadRecent=" + startingThreadRecent.checked + 
	"&startingThreadPreferred=" + startingThreadPreferred.checked + 
	"&include_day=" + include_day);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById('headerDetails').innerHTML = xmlhttp.responseText;
		    
			$(".saved").css("display", "inline");
			var t=setTimeout("removeSaved()",3000);
    	}
  	}
}
function screenNameCheck(screenNames) {
	newName = "," + document.getElementById("screenName").value + ",";
	if (screenNames.search(newName) != -1){
		document.getElementById("screenNameCheck").innerHTML = "Already Taken";
	}else if (newName == ",,"){
		document.getElementById("screenNameCheck").innerHTML = "";
	}else{
		document.getElementById("screenNameCheck").innerHTML = "Valid";
	}
}
function sendResetEmail(email){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=sendResetEmail&email=" + email);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    $("#resetEmailSent").html("Reset Email has been sent");
			 
    	}
  	}
	
}
function show(id, display) {
	
	
	document.getElementById(id).style.display = display;
	if (id == "addCommentRow"){
		document.getElementById("newComment").focus();	
	}
	
}
function check_compose_message(message, recipient){
	if (message == "" || recipient == ""){
		alert("Make sure all fields are filled in.");
		return false;	
	}else{
		return true;
	}
}
function createGoal(){
	title = document.getElementById('goalTitle').value;
	description = document.getElementById('goalDescription').value;
	due = document.getElementById('goalDue').value;
	goal_id = document.getElementById('goal_id').value;
	
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=createGoal&title=" + title + "&description=" + description + "&due=" + due + "&goal_id=" + goal_id);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			if (xmlhttp.responseText == "Fail"){
				alert("Make sure you do not type nonsense. You cannot have words that are longer than 20 characters. Sorry for any inconvenience");
			}else{
			    location.reload(true);
			}
		}
  	}
		
}
function resizeDraggable(num, i){
	switch (num){
		case '1':
			$('#draggable' + i).css({"width":"50px", "height":"50px"});
			break;	
		case '2':
			$('#draggable' + i).css({"width":"60px", "height":"60px"});
			break;	
		case '3':
			$('#draggable' + i).css({"width":"70px", "height":"70px"});
			break;	
	}
}
function showImage(num){
	document.getElementById("image" + num).style.display = "block";
}
function sortThreads(choice){
	location.href="threadIndex.php?sort=" + choice;
}
function sortThreadsPopup(){
	if (document.getElementById("sortSearchAuthor").checked == true){
		sortValue = "screenName";
	}else if (document.getElementById("sortSearchThreadtitle").checked == true){
		sortValue = "title";
	}else{
		sortValue = "timestamp";
	}
	
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=sortSearch&sortValue=" + sortValue);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    document.getElementById("sortThreads").innerHTML = xmlhttp.responseText;
    	}
  	}		
}
function ableStartingThread(id) {
	if  (id == "startingThreadRecent"){
		document.getElementById('preferredThread').style.display = "none";
	}else{
		document.getElementById('preferredThread').style.display = "table-row";
	}
		
}
function setPreferredThreadId(threadId, title){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=setPreferredThreadId&threadId=" + threadId);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			$('#preferredThreadTitle').html(title);
		    $('#popup').remove();
    	}
  	}	
}
function disableThread(threadId){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=disableThread&threadId=" + threadId);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    document.getElementById("disableButton-" + threadId).value = xmlhttp.responseText;
		    document.getElementById("disableButton-" + threadId).setAttribute("disabled", "true");
		    document.getElementById("enableButton-" + threadId).value = "Enable";
		    document.getElementById("enableButton-" + threadId).disabled = false;
    	}
  	}
}
function enableThread(threadId){
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.open("POST","ajax.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("action=enableThread&threadId=" + threadId);
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    document.getElementById("enableButton-" + threadId).value = xmlhttp.responseText;
		    document.getElementById("enableButton-" + threadId).setAttribute("disabled", "true");
		    document.getElementById("disableButton-" + threadId).value = "Disable";
		    document.getElementById("disableButton-" + threadId).disabled = false;
    	}
  	}
}




