// PhotoBlog JavaScript
var previewWindow = null;
// Validate search form
function validateSearchForm () {
var query = trim(document.searchform.query.value);
if (query == '') {
alert('Please fill in one or more keywords.');
document.searchform.query.focus();
return false;
} else return true;
}
// Select archive by date
function selectDate () {
var index = document.blogarchiveform.blogdateselect.selectedIndex;
var url = document.blogarchiveform.blogdateselect.options[index].value;
if (url != '') document.location = url;	
else document.blogarchiveform.blogdateselect.selectedIndex = 0;
}
// Select archive by category
function selectCategory () {
var index = document.blogarchiveform.blogcategoryselect.selectedIndex;
var url = document.blogarchiveform.blogcategoryselect.options[index].value;
if (url != '') document.location = url;	
else document.blogarchiveform.blogcategoryselect.selectedIndex = 0;
}
// Validate e-mail picture form
function validateEmailForm () {
var name = trim(document.emailform.name.value);
var email = trim(document.emailform.email.value);	
var friendEmail = trim(document.emailform.friendemail.value);	
var message = trim(document.emailform.message.value);
if (name == '') {
alert('Please fill in your name.');
document.emailform.name.focus();
return false;
}
if (email == '') {
alert('Please fill in your e-mail address.');
document.emailform.email.focus();
return false;
}
if (!isEmail(email)) {
alert('Your e-mail address is not valid.');
document.emailform.email.focus();
return false;
}
if (friendEmail == '') {
alert('Please fill in your friends e-mail address.');
document.emailform.friendemail.focus();
return false;
}
if (!isEmail(friendEmail)) {
alert('Your friends e-mail address is not valid.');
document.emailform.friendemail.focus();
return false;
}
return true;
}
// Validate post comment form
function validatePostCommentForm () {
var name = trim(document.postcommentform.name.value);
var body = trim(document.postcommentform.body.value);
var email = trim(document.postcommentform.email.value);
if (name == '') {
alert('Please fill in your name.');
document.postcommentform.name.focus();
return false;
}
if (body == '') {
alert('Please fill in your comment.');
document.postcommentform.body.focus();
return false;
}
if (email != '' && !isEmail(email)) {
alert('Please fill in a valid e-mail address.');
document.postcommentform.email.focus();
return false;
}
return true;
}
// Delete comment submit
function deleteComment (commentID) {
if (confirm('Are you sure you want to delete this comment?')) {
document.commentsform.deletecomment.value = 'true';
document.commentsform.commentid.value = commentID;
document.commentsform.submit();
}}
// Post comment
function postComment () {
document.postcommentform.action = 'portfolio.php';
document.postcommentform.target = '_self';
}
// Preview comment
function previewComment () {
if (validatePostCommentForm()) {
document.postcommentform.action = 'preview.php?context=comment';
document.postcommentform.target = 'preview';
if (previewWindow != null) previewWindow.close();
previewWindow = rawPopup('', 'preview', 530, 400);
previewWindow.focus();
document.postcommentform.submit();
}}
