function setmargin() {
	var w = (screen.width-270)*0.85;
	document.getElementById("path").style.marginLeft = w+"px";
}
function setsortmargin() {
	var w = ((screen.width-270)*0.85)-95;
	document.getElementById("sortbox").style.marginLeft = w+"px";
	displayNone("sortbutton");
	displayBlock("sorthidebutton");
}
function setanypathmargin() {
	var w = (screen.width-270)*0.75;
	document.getElementById("anypath").style.marginLeft = w+"px";
}
function showTags() {
	document.getElementById("tags").style.visibility = "visible";
	document.getElementById("showtags").style.display = "none";
}
function hideTags() {
	document.getElementById("tags").style.visibility = "hidden";
	document.getElementById("showtags").style.display = "inline";
}
function showComments() {
	document.getElementById("comments").style.visibility = "visible";
	document.getElementById("commentary").style.display = "none";
}
function hideComments() {
	document.getElementById("comments").style.visibility = "hidden";
	document.getElementById("commentary").style.display = "inline";
}
function showDetails() {
	document.getElementById("details").style.visibility = "visible";
	document.getElementById("detailbutton").style.display = "none";
}
function hideDetails() {
	document.getElementById("details").style.visibility = "hidden";
	document.getElementById("detailbutton").style.display = "inline";
}
function hidePath() {
	document.getElementById("path").style.visibility = "hidden";
	document.getElementById("showpath").style.display = "inline";
}
function hidePath_unique(divname) {
	document.getElementById(divname).style.visibility = "hidden";
}
function setmargin_unique(divname) {
	var w = (screen.width-270)*0.75;
	document.getElementById(divname).style.marginLeft = w+"px";
}
function setmargin_unique_custom(divname,percent) {
	var w = (screen.width-270)*percent;
	document.getElementById(divname).style.marginLeft = w+"px";
}
function showPath() {
	document.getElementById("path").style.visibility = "visible";
	document.getElementById("showpath").style.display = "none";
}
function hideAnypath() {
	document.getElementById("anypath").style.visibility = "hidden";
}
function displayNone(divname) {
	if (document.getElementById(divname)) {document.getElementById(divname).style.display = 'none';}
}
function displayBlock(divname) {
	if (document.getElementById(divname)) {document.getElementById(divname).style.display = 'block';}
}


function MM_preloadImages() { //v2.0 
  if (document.images) { 
    var imgFiles = MM_preloadImages.arguments; 
    if (document.preloadArray==null) document.preloadArray = new 
Array(); 
    var i = document.preloadArray.length; 
    with (document) for (var j=0; j<imgFiles.length; j++) if 
(imgFiles[j].charAt(0)!="#"){ 
      preloadArray[i] = new Image; 
      preloadArray[i++].src = imgFiles[j]; 
  } } 
}


function showMessageLoad() {
	if (document.getElementById("messageload")) {document.getElementById("messageload").style.display = 'block';}
}
function showMessageResponse(req){
	$('messageresult').innerHTML= req.responseText;
	$('messageload').style.display = 'none';
}

function sendMessageRequest() {
	if (document.getElementById("success")) {document.getElementById("success").style.display = 'none';}
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $('messageform').serialize(true),
		onLoading: showMessageLoad,
		onComplete: showMessageResponse 
		});
}

function saveComment(form,loaddiv,resultdiv) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(form).serialize(true),
		onLoading: 
		function saveCommentLoad() {
			if (document.getElementById(loaddiv)) {document.getElementById(loaddiv).style.display = 'block';}
		},
		onComplete: 
		function saveCommentResponse(req){
			$(resultdiv).innerHTML= req.responseText;
			$(loaddiv).style.display = 'none';
		} 
		});
}

function startDrag(path, pathtitle) {
	var theHandlecom = document.getElementById(pathtitle);
	var theRootcom = document.getElementById(path);
	Drag.init(theHandlecom, theRootcom);
	setmargin_unique(path);
}
function startDragForeign(path, pathtitle) {
	var theHandlecom = document.getElementById(pathtitle);
	var theRootcom = document.getElementById(path);
	Drag.init(theHandlecom, theRootcom);
	setmargin_unique_custom(path,0.50);
}
function startDragProfile(path, pathtitle) {
	var theHandlecom = document.getElementById(pathtitle);
	var theRootcom = document.getElementById(path);
	Drag.init(theHandlecom, theRootcom);
	setmargin_unique_custom(path,0.37);
}
function showLoad_update() {
	$('pathwaylist').innerHTML= "";
	//if (document.getElementById("load")) {document.getElementById("load").style.display = 'block';}
}
function showPathway(formname,path,pathtitle) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onComplete:					
			function showResponse_path(req){
				$('ajaxdiv').innerHTML= req.responseText;
				//$('load').style.display = 'none';
				startDrag(path,pathtitle);
				make_comments_editable();					
			}					
		});
}
function showForeignPathway(formname,path,pathtitle) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onComplete:					
			function showResponse_path(req){
				$('anypathdiv').innerHTML= req.responseText;
				//$('load').style.display = 'none';
				startDragForeign(path,pathtitle);	
			}					
		});
}


function AddToPathway(formname) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $('addtopath').serialize(true),
		onLoading: 
			function showLoad_AddToPathway() {
				$('pathcontents').innerHTML= "";
				//if (document.getElementById("load")) {document.getElementById("load").style.display = 'block';}
			},
		onComplete: 
			function showResponse_AddToPathway(req){
				$('pathcontents').innerHTML= req.responseText;
				makeedit();
				if (document.getElementById("sortbox")) {document.getElementById("sortbox").style.display = 'none';}
				HideSortList();
				//showSortList(formname);
				//startDrag();
				//$('load').style.display = 'none';
			} 
		});

}
function deletePostFromPathwayInPost(formname) {
	if (confirm("Are you sure you want to delete this item from your pathway? This can't be undone!") ) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad_deletePostFromPathway() {
				$('pathcontents').innerHTML= "";
			},
		onComplete: 
			function showResponse_deletePostFromPathway(req){
				$('pathcontents').innerHTML= req.responseText;
				makeedit();
				if (document.getElementById("sortbox")) {document.getElementById("sortbox").style.display = 'none';}				
			} 					
		});
	}
}
function deletePostFromPathway(formname) {
	if (confirm("Are you sure you want to delete this item from your pathway? This can't be undone!") ) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad_deletePostFromPathway() {
				$('pathcontents').innerHTML= "";
			},
		onComplete: 
			function showResponse_deletePostFromPathway(req){
				$('pathcontents').innerHTML= req.responseText;
				make_comments_editable();
			} 					
		});
	}
}
function addToFavorites(formname) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad_addToFavorites() {
					//if (document.getElementById("addbutton")) {document.getElementById("addbutton").style.display = 'block';}
			},
		onComplete: 
			function showResponse_addToFavorites(req){
				if (document.getElementById("addtofavsbutton")) {document.getElementById("addtofavsbutton").style.display = 'none';}
				if (document.getElementById("myfavorite")) {document.getElementById("myfavorite").style.display = 'block';}
			} 					
		});
}	
function deleteFavorite(formname) {
if (confirm("Are you sure you want to delete this pathway from your favorites? This can't be undone!") ) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php",
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad_deleteFavorite() {
				$('favoritespathwaylist').innerHTML= "";			
			},		
		onComplete:					
			function showResponse_deleteFavorite(req){
				$('favoritespathwaylist').innerHTML= req.responseText;
				init();
			}					
		});
		}
}			
function updateActive(formname)	{
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: showLoad_update,
		onComplete:					
			function showResponse_update(req){
				$('pathwaylist').innerHTML= req.responseText;
				init();
			}					
		});
}
function deletePathway(formname) {
if (confirm("Are you sure you want to delete this pathway? This can't be undone!") ) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php",
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: showLoad_update,
		onComplete:					
			function showResponse_delete(req){
				$('pathwaylist').innerHTML= req.responseText;
				init();
			}					
		});
		}
}
function deletePathwayFromList(formname) {
if (confirm("Are you sure you want to delete this pathway? This can't be undone!") ) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php",
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad_deleteFavorite() {
				$('favoritespathwaylist').innerHTML= "";			
			},		
		onComplete:					
			function showResponse_delete(req){
				$('favoritespathwaylist').innerHTML= req.responseText;
				init();
			}					
		});
		}
}

function savePathway() {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $('pathwayform').serialize(true),
		onLoading: 
			function showLoad() {
				$('pathwaylist').innerHTML= "";
				if (document.getElementById("load")) {document.getElementById("load").style.display = 'block';}
			},
		onComplete: 
			function showResponse(req){
				$('pathwaylist').innerHTML= req.responseText;
				$('load').style.display = 'none';
				init();
			} 
		});
}
function viewProfile(formname,profile,profiletitle) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onComplete:					
			function showResponse_path(req){
				$('profilediv').innerHTML= req.responseText;
				startDragProfile(profile,profiletitle);
			}					
		});
}
function showSortList(formname) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onComplete:					
			function showResponse_path(req){
				$('sortholder').innerHTML= req.responseText;
				Sortable.create('itemlist', { onUpdate: updateOrder, treeTag: 'ul', tag: 'li' });
				setsortmargin();
			}					
		});
}
function HideSortList() {
		displayNone("sorthidebutton");
		displayBlock("sortbutton");
		displayNone("sortbox");
}

function getReplyForm(formname) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad() {
				//$('').innerHTML= "";
			},
		onComplete: 
			function showResponse(req){
				$('replyform').innerHTML= req.responseText;
			} 
		});

}

function addTopic() {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $('addtopic').serialize(true),
		onLoading: 
			function showLoad_addTopic() {
					$('forumcontent').innerHTML= "";
			},
		onComplete: 
			function showResponse(req){
				$('forumcontent').innerHTML= req.responseText;
			} 				
		});
}

function addTopicComment(formname,contentdiv) {
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad_addTopic() {
					$(contentdiv).innerHTML= "";
			},
		onComplete: 
			function showResponse(req){
				$(contentdiv).innerHTML= req.responseText;
			} 				
		});
}

function deleteTopic(formname) {
if (confirm("Are you sure you want to delete this topic? This can't be undone! All comments in this topic will also be deleted!") ) {	
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad_deleteTopic() {
					$('forumcontent').innerHTML= "";
			},
		onComplete: 
			function showResponse(req){
				$('forumcontent').innerHTML= req.responseText;
			} 				
		});
		}
}

function deleteComment(formname,contentdiv) {
if (confirm("Are you sure you want to delete this comment? This can't be undone!") ) {	
	new Ajax.Request("http://www.sp-ark.org/ajax.php", 
		{ 
		method: 'post',
		parameters: $(formname).serialize(true),
		onLoading: 
			function showLoad_deleteTopic() {
					$(contentdiv).innerHTML= "";
			},
		onComplete: 
			function showResponse(req){
				$(contentdiv).innerHTML= req.responseText;
			} 				
		});
		}
}
