/*
* Clear Default Text: functions for clearing and replacing default text in
* elements.
*
*/
addEvent(window, 'load', init, false);
function init() {
var formInputs = document.getElementsByTagName('input');
for (var i = 0; i < formInputs.length; i++) {
var theInput = formInputs[i];
if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {
/* Add event handlers */
addEvent(theInput, 'focus', clearDefaultText, false);
addEvent(theInput, 'blur', replaceDefaultText, false);
/* Save the current value */
if (theInput.value != '') {
theInput.defaultText = theInput.value;
}
}
else if (theInput.className.match(/\bpasswordClear\b/) && theInput.className.match(/\bcleardefault\b/)) {
/* Add event handlers */
addEvent(theInput, 'focus', clearDefaultText, false);
}
else if (theInput.className.match(/\bpasswordObscure\b/) && theInput.className.match(/\bcleardefault\b/)) {
addEvent(theInput, 'blur', replaceDefaultText, false);
}
}
if ($('passwordObscure'))
fireEvent($('passwordObscure'), "blur");
}
function fireEvent(target, event)
{
if (document.createEvent)
{
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent(event, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var canceled = !target.dispatchEvent(evt);
}
else
{
var evt = document.createEventObject();
target.fireEvent("on" + event, evt);
evt.cancelBubble = true;
}
}
function clearDefaultText(e) {
var target = window.event ? window.event.srcElement : e ? e.target : null;
if (!target) return;
if (target.className.match(/\bpasswordClear\b/)) {
$('passwordClear').style.display = 'none';
$('passwordObscure').style.display = '';
$('passwordObscure').focus();
return;
}
if (target.value == target.defaultText) {
target.value = '';
}
}
function replaceDefaultText(e) {
var target = window.event ? window.event.srcElement : e ? e.target : null;
//alert('Blur Event '+target);
if (!target) return;
if (target.className.match(/\bpasswordObscure\b/) && $('passwordObscure').value == '') {
$('passwordObscure').style.display = 'none';
$('passwordClear').style.display = '';
return;
}
if (target.value == '' && target.defaultText) {
target.value = target.defaultText;
}
}
/*
* Cross-browser event handling
*/
function addEvent(element, eventType, lambdaFunction, useCapture) {
if (element.addEventListener) {
element.addEventListener(eventType, lambdaFunction, useCapture);
return true;
} else if (element.attachEvent) {
var r = element.attachEvent('on' + eventType, lambdaFunction);
return r;
} else {
return false;
}
}
/*
* Kills an event's propagation and default action
*/
function knackerEvent(eventObject) {
if (eventObject && eventObject.stopPropagation) {
eventObject.stopPropagation();
}
if (window.event && window.event.cancelBubble ) {
window.event.cancelBubble = true;
}
if (eventObject && eventObject.preventDefault) {
eventObject.preventDefault();
}
if (window.event) {
window.event.returnValue = false;
}
}
/*
* Cross-browser style extraction, from the JavaScript & DHTML Cookbook
*
*/
function getElementStyle(elementID, CssStyleProperty) {
var element = document.getElementById(elementID);
if (element.currentStyle) {
return element.currentStyle[toCamelCase(CssStyleProperty)];
} else if (window.getComputedStyle) {
var compStyle = window.getComputedStyle(element, '');
return compStyle.getPropertyValue(CssStyleProperty);
} else {
return '';
}
}
function resetPassword(invite)
{
showOverlay(300, 225, $('resetPassword').innerHTML, invite);
/*
if( document.getElementById('home') ){
if( $('home').getStyle('top')=='-15px' )
$('home').setStyle({top:'-259px'});
}
*/
if ($('loginName'))
$('loginName').focus();
}
function activateAccount(invite)
{
showOverlayMid(300, 225, $('activateAccount').innerHTML, invite);
/*
if( document.getElementById('home') ){
if( $('home').getStyle('top')=='-15px' )
$('home').setStyle({top:'-259px'});
}
*/
if ($('loginName'))
$('loginName').focus();
}
// Validate invite form fields.
function isValidResetPasswordForm()
{
var errs = 0;
// let's clear any existing messages
$('loginNameValidate').innerHTML = "";
$('emailValidate').innerHTML = "";
//validate that one of the fields is not blank
if (($('loginName').value == "") && ($('reset_email').value == ""))
{
validationMsg('loginNameValidate', 'Please enter a Login Name or email address.');
errs += 1;
}
// validate fields
if ($('reset_email').value != "")
{
if (!validateField($('reset_email'), 'emailValidate', 'email', 'Please include a valid email address.')) errs += 1;
}
if (errs > 0)
{
return false;
}
return true;
}
function isValidActivateAccountForm()
{
var errs = 0;
// let's clear any existing messages
$('loginNameValidate').innerHTML = "";
$('mailValidate').innerHTML = "";
//validate that one of the fields is not blank
if (($('loginName').value == "") && ($('reset_email').value == ""))
{
validationMsg('loginNameValidate', 'Please enter a Login Name or email address.');
errs += 1;
}
// validate fields
if ($('reset_email').value != "")
{
if (!validateField($('reset_email'), 'mailValidate', 'email', 'Please include a valid email address.')) errs += 1;
}
if (errs > 0)
{
return false;
}
return true;
}
function dimTitle()
{
//Effect.Fade('site_title_box', {from:1, to:0.2, duration:0.2});
}
function liteTitle()
{
//Effect.Appear('site_title_box', {duration:0.2});
}
function dimStory()
{
Effect.Fade('story_header', {from:1, to:0.2, duration:0.2});
Effect.Fade('story_box', {from:1, to:0.2, duration:0.2});
}
function liteStory()
{
Effect.Appear('story_header', {duration:0.2});
Effect.Appear('story_box', {duration:0.2});
}
function dimBlog()
{
if( $('forum_header') ){
Effect.Fade('forum_header', {from:1, to:0.2, duration:0.2});
}
if( $('wishes') ){
Effect.Fade('wishes', {from:1, to:0.2, duration:0.2});
}
if( $('well_wishes') ){
Effect.Fade('well_wishes', {from:1, to:0.2, duration:0.2});
}
}
function liteBlog()
{
if( $('forum_header') ){
Effect.Appear('forum_header', {duration:0.2});
}
if( $('wishes') ){
Effect.Appear('wishes', {duration:0.2});
}
if( $('well_wishes') ){
Effect.Appear('well_wishes', {duration:0.2});
}
}
function dimPhoto()
{
if( $('photoEdit') ){
Effect.Fade('photoEdit', {from:1, to:0.2, duration:0.2});
}
}
function litePhoto(noPhotoandAdmin)
{
if( $('photoEdit') ){
Effect.Appear('photoEdit', {duration:0.2});
}
}
function editBlog()
{
dimRightSidebar();
dimLeftSidebar();
dimTitleBox();
dimPhoto();
dimStory();
}
function showBlog()
{
liteRightSidebar();
liteLeftSidebar();
liteTitleBox();
litePhoto();
liteStory();
}
function editStory()
{
if ($('storyTemp').style.display == 'none')
{
//liteTitle();
liteRightSidebar();
liteLeftSidebar();
liteSupportBar();
liteBlog();
litePhoto();
$('storydiv').style.display='none';
$('storyTemp').style.display='';
$('storyEdit').style.display='';
}
else
{
//dimTitle();
dimRightSidebar();
dimLeftSidebar();
dimSupportBar();
dimBlog();
dimPhoto();
$('storydiv').style.display='';
$('storyTemp').style.display='none';
$('storyEdit').style.display='none';
//document.storyForm.storyTxt.focus(); //set focus to editor (gh cant make this work)
Effect.Appear('storydiv', {duration:0.2});
}
}
function editPhoto()
{
if ($("photoEdit")) {$('photoEdit').style.display='none';} //may not exist if not admin or picture exists
$("photoValidate").innerHTML = "";
$('photoSelect').style.display=''; //show the editor
}
function showPhoto()
{
if ($("photoEdit")) {$('photoEdit').style.display='';} //may not exist if not admin or picture exists
$('photoSelect').style.display='none'; //hide the editor
}
// Toggle home page edit blocks for adding a blog entry
function toggleAdd()
{
target = $("addDiv");
if (target.style.display == "")
{
target.style.display = "none";
$("forumEdit").style.display = "";
liteTitle();
litePhoto();
liteStory();
liteRightSidebar();
liteLeftSidebar();
liteSupportBar();
}
else
{
$("forumEdit").style.display = "none";
// $('blogAddButton').style.display="none"
target.style.display = "";
//document.entryForm.subject.focus();
dimTitle();
dimPhoto();
dimStory();
dimRightSidebar();
dimLeftSidebar();
dimSupportBar();
}
}
/** Realizes an Ajax request for mail contact */
function requestUserInfoByMail(requestURL){
$('requestlink').style.display = "none";
$('imageprogress').style.display = "";
var request = new Ajax.Request(requestURL, {method: 'post', onComplete: completeRequestByMail});
}
/** Receives the Ajax request done by requestUserInfoByMail function */
function completeRequestByMail(request){
hidePopup();
$('imageprogress').style.display = "none";
}