loadingimg = new Image(54,55);
loadingimg.src = 'http://www.shurtugal.com/images/loading.gif';
function switchpost(post) {
	if ($("#pbody_"+post).is(":hidden")) {
           	$("#openimage_"+post).attr("src", "http://www.shurtugal.com/ostraciidae/images/collapse.png");
		$("#pbody_"+post).slideDown("normal");
	} else {
           	$("#openimage_"+post).attr("src", "http://www.shurtugal.com/ostraciidae/images/expand.png");
		$("#pbody_"+post).slideUp("normal");
	}
}
function checkCharacters(field) { 
	spacesplit = field.value.split(" ");
	if(spacesplit[1]) {
		newsplit = "";
		for(i=0;i<spacesplit.length;i++) {
			newsplit += spacesplit[i];
		}
	} else {
		newsplit = field.value
	}
	dashsplit = newsplit.split("-");
	if(dashsplit[1]) {
		newsplit = "";
		for(i=0;i<dashsplit.length;i++) {
			newsplit += dashsplit[i];
		}
	} 
	underscoresplit = newsplit.split("_");
	if(underscoresplit[1]) {
		newsplit = "";
		for(i=0;i<underscoresplit.length;i++) {
			newsplit += underscoresplit[i];
		}
	}
	if(field.value != newsplit) {
		$("#alertbox").html("Your name has been changed due to use of spaces/hyphens/underscores.");
		field.value = newsplit;
	}
}
function loadingPage(field) {
	$("#"+field).html("<center><img src=\"http://www.shurtugal.com/images/loading.gif\"><br><b>Loading...</b></center><br><br><br><br>");
}

function commentlogin(id) {
	username = document.comlogin.username.value;
	password = document.comlogin.password.value;
	uname = encodeURIComponent(username);
	pword = encodeURIComponent(password);
	params = "password="+pword+"&username="+uname;
	loadingPage('comform_wrapper');
	$.ajax({
		type: "POST",
		url: "ostraciidae/output/run_data.php?page=login&id="+id,
		dataType: "html",
		data: params,
		success: function(responseText) {
			$("#comform_wrapper").html(responseText);
		}
	});
}

function loadForm(id) {
	loadingPage('comform_wrapper');
	$.ajax({
		type: "GET",
		url: "ostraciidae/output/run_data.php?page=form&id="+id,
		dataType: "html",
		success: function(responseText) {
			$("#comform_wrapper").html(responseText);
		}
	});
}

function loadComments(id,start,limit) {
	num = Math.floor(Math.random()*987235);

	loadingPage('comments_wrapper');
	$.ajax({
		type: "GET",
		url: "ostraciidae/output/run_data.php?page=comments&id="+id+"&start="+start+"&limit="+limit+"&num="+num,
		dataType: "html",
		success: function(responseText) {
			$("#comments_wrapper").html(responseText);
		}
	});
}

function postComment(id) {
	comment = document.commentform.comment.value;
	comment1 = encodeURIComponent(comment);
	params = "comment="+comment1;

	loadingPage('comform_wrapper');
	$.ajax({
		type: "POST",
		url: "ostraciidae/output/run_data.php?page=postcomment&id="+id,
		dataType: "html",
		data: params,
		success: function(responseText) {
			if(responseText == "true") {
				loadForm(id);
				loadComments(id,'0','25');
			} else {
				$("#comform_wrapper").html(responseText);
			}
		}
	});
}

function postGComment(id) {
	comment = document.commentform.comment.value;
	myname = document.commentform.name.value;
	sec_code = document.commentform.sec_code.value;
	comment1 = encodeURIComponent(comment);
	myname1 = encodeURIComponent(myname);
	sec_code1 = encodeURIComponent(sec_code);
	params = "comment="+comment1+"&name="+myname1+"&sec_code="+sec_code1;

	loadingPage('comform_wrapper');
	$.ajax({
		type: "POST",
		url: "ostraciidae/output/run_data.php?page=postcomment_guest&id="+id,
		dataType: "html",
		data: params,
		success: function(responseText) {
			if(responseText == "true") {
				loadForm(id);
				loadComments(id,'0','25');
			} else {
				$("#comform_wrapper").html(responseText);
			}
		}
	});
}

function loadPage(page,id) {
	loadingPage('comform_wrapper');
	$.ajax({
		type: "GET",
		url: "ostraciidae/output/run_data.php?page="+page+"&id="+id,
		dataType: "html",
		success: function(responseText) {
			$("#comform_wrapper").html(responseText);
		}
	});
}

function submitRegistration(id) {
	username = document.registerform.username.value;
	password1 = document.registerform.password1.value;
	password2 = document.registerform.password2.value;
	email = document.registerform.email.value;
	showemail = document.registerform.showemail.value;
	newsletter = document.registerform.newsletter.value;

	uname = encodeURIComponent(username);
	pword1 = encodeURIComponent(password1);
	pword2 = encodeURIComponent(password2);
	eml = encodeURIComponent(email);
	shweml = encodeURIComponent(showemail);
	nlttr = encodeURIComponent(newsletter);
	params = "password1="+pword1+"&username="+uname+"&password2="+pword2+"&email="+eml+"&showemail="+shweml+"&newsletter="+nlttr;

	loadingPage('comform_wrapper');
	$.ajax({
		type: "POST",
		url: "ostraciidae/output/run_data.php?page=registersubmit&id="+id,
		dataType: "html",
		data: params,
		success: function(responseText) {
			$("#comform_wrapper").html(responseText);
		}
	});
}

function submitlpw(id) {

	username = document.lostpw.username.value;
	email = document.lostpw.email.value;

	uname = encodeURIComponent(username);
	eml = encodeURIComponent(email);
	params = "username="+uname+"&email="+eml;

	loadingPage('comform_wrapper');
	$.ajax({
		type: "POST",
		url: "ostraciidae/output/run_data.php?page=lpwsubmit&id="+id,
		dataType: "html",
		data: params,
		success: function(responseText) {
			$("#comform_wrapper").html(responseText);
		}
	});
}