var includeDues = false;
var username;
var password;
var privs = {};
//var localUpdates = [];
var onLogin = [];
var onReady = [];
var hols = [];
var yroptionlist = "";
var editableSelectCreated = false;
var abgcolor = '#4488bb';
var showLoginDivOnAutoLoginFail = false;
function setYrOptionList() {
var yr = (new Date()).getFullYear();
for (var y=0; y < 5; y++) {
yroptionlist += '';
}
}
setYrOptionList();
function encodeBase64(data) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
ac = 0,
enc = "",
tmp_arr = [];
if (!data) {
return data;
}
do { // pack three octets into four hexets
o1 = data.charCodeAt(i++);
o2 = data.charCodeAt(i++);
o3 = data.charCodeAt(i++);
bits = o1 << 16 | o2 << 8 | o3;
h1 = bits >> 18 & 0x3f;
h2 = bits >> 12 & 0x3f;
h3 = bits >> 6 & 0x3f;
h4 = bits & 0x3f;
// use hexets to index into b64, and append result to encoded string
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
} while (i < data.length);
enc = tmp_arr.join('');
var r = data.length % 3;
return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
}
/*
& --> &
< --> <
> --> >
" --> "
' --> ' ' is not recommended
/ --> / forward slash is included as it helps end an HTML entity
*/
function htmlEscape(html){
return html.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/\//g, "/");
}
function htmlUnescape(html){
return html.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/g, "'").replace(///g, "/");
}
var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var monthNumbers = {};
for (var m=0; m < 12; m++) monthNumbers[monthNames[m]] = (m < 9) ? "0" + (m+1) : (m+1);
var dayNames = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];
//var monthNumbers = { monthNames[0]: '01', monthNames[0] : '02', 'March' : '03', 'April' : '04', 'May' : '05', 'June' : '06', 'July' : '07', 'August' : '08',
// 'September' : '09', 'October' : '10', 'November' : '11', 'December' : '12' };
function addlang(url) {
// Insert the language qualifier
retval = '/' + lang + url;
return retval;
}
function authenticatedAjax(href, cb) {
var u = getCookie(rootBlogTopicId + '-username');
var p = getCookie(rootBlogTopicId + '-password');
var url = addlang(href);
//console.log("authenticatedAjax: " + url);
$.ajax({
url: url,
success: cb,
beforeSend: function(xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + encodeBase64(u + ":" + p));
}
});
}
function authenticatedPost(href, data, cb) {
var u = getCookie(rootBlogTopicId + '-username');
var p = getCookie(rootBlogTopicId + '-password');
$.ajax({
url: addlang(href),
type: 'POST',
data: JSON.stringify(data),
dataType: 'JSON',
success: cb,
beforeSend: function(xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + encodeBase64(u + ":" + p));
}
});
}
function fixup() {
if (screwtopDb.isFunction(window.prettyPrint)) {
$('pre.prettyprint').each(function(n,o) {
var jo = $(o);
jo.html(jo.html().replace(/= 12) {
h = hh-12;
dd = "PM";
}
if (h == 0) {
h = 12;
}
m = m<10?"0"+m:m;
s = s<10?"0"+s:s;
/* if you want 2 digit hours:
h = h<10?"0"+h:h; */
return h + ':' + m + ' ' + dd;
}
function dateDisplayString(d) {
return [
//"Posted on ",
d.toLocaleDateString(),
" ",
formatDate(d)
].join(' ');
}
RegExp.escape = function(text){
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
var caseBlindMatch = function (str1, str2){
if (str2 == undefined || str1 == undefined)
return false;
var re = new RegExp(RegExp.escape(str1), "i");
return str2.match(re);
}
function localize8601Dates() {
$('.ISO8601Date').each(function(arr, elem) {
var d = new Date();
var e = $(elem);
d.setISO8601(e.html());
e.html(dateDisplayString(d));
});
}
function generateToken(len) {
var tok = '';
var t = (Math.floor(Math.random() * 1000000)).toString(36);
while (t.length < len) {
t += (Math.floor(Math.random() * 1000000)).toString(36);
}
return t.slice(0,len);
}
function setSingleUseToken(cb) {
var tokstr = generateToken(32);
screwtopDb().url(DBURL)
.topicByName(username)
.addTags('singleUseTokens',tokstr/*, {private:true}*/)
.end(function() {
cb(tokstr);
});
}
function hasLocalStorage() {
return 'localStorage' in window && window['localStorage'] !== null;;
}
function hasSessionStorage() {
return 'sessionStorage' in window && window['sessionStorage'] !== null;;
}
function setSessionStorage(name,value) {
sessionStorage.setItem(name,value);
}
function getSessionStorage(name) {
return sessionStorage.getItem(name);
}
function setLocalStorage(name,value) {
//console.log("set " + name + "=" + value);
localStorage.setItem(name,value);
}
function getLocalStorage(name) {
//console.log("get " + name + "=" + localStorage.getItem(name));
return localStorage.getItem(name);
}
function deleteLocalStorage(name) {
//console.log("del " + name);
localStorage.removeItem(name);
}
function setCookie(name,value,days) {
if (hasLocalStorage()) {
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
setLocalStorage(name,value);
}
else {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
}
function getCookie(name) {
if (hasLocalStorage()) {
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return getLocalStorage(name);
}
else {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
}
function deleteCookie(name) {
if (hasLocalStorage()) deleteLocalStorage(name);
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
function cookiesSet() {
var u = getCookie(rootBlogTopicId + '-username');
var p = getCookie(rootBlogTopicId + '-password');
return (!screwtopDb.isEmpty(u) /* && !screwtopDb.isNull */);
}
var spinnerCount = 0;
function showSpinner() {
if (++spinnerCount == 1)
$('#spinner').fadeIn('fast');
//console.log('show spinnerCount='+spinnerCount);
}
function hideSpinner() {
if (--spinnerCount == 0)
$('#spinner').stop().hide();
//console.log('hide spinnerCount='+spinnerCount);
}
function isBlogPoster() {
var retval = false;
for (var k=0; k < blogPosters.length; k++) {
if (caseBlindMatch(blogPosters[k], username)) {
retval = true;
break;
}
}
return retval;
//return caseBlindMatch(blogOwner, username);
}
function isLoggedIn() {
return !screwtopDb.isEmpty(username);
}
function addHolidays() {
var today = new Date();
getHolidays(function(arr) {
arr.forEach(function(ev) {
//console.log(ev.date + ': ' + ev.name);
schedev = {
id: 0,
infolink: '#',
location: 'US',
duration: 24*60,
owner: 'pdclub',
//title: ev.name,
start: ev.date,
color:'white',
valueId: 0,
textColor: '#c00'
};
schedev["title"] = ev.name;
$('#calendardiv').fullCalendar('renderEvent',schedev,true);
});
addRecurringEvents();
});
}
function getHolidaysForYear(fullyr,cb) {
$.ajax(location.protocol + '//' + location.host + '/holidata.net/en-US/'+fullyr+'.json',{
dataType: 'text',
error: function(data,textStatus,errorThrown) {
$('#log').append('Error: ' + textStatus + ' ' + errorThrown + '
');
}
}).done(function(data) {
var hols = [];
var lines = data.split('\n');
lines.forEach(function(line) {
if (line.trim().length > 0) {
var obj = JSON.parse(line);
var date = new Date();
date.setDate(obj.date.split('-')[2]);
date.setMonth(obj.date.split('-')[1]-1);
date.setFullYear(obj.date.split('-')[0]);
date.setMinutes(0);
date.setHours(0);
date.setSeconds(0);
hols.push({ date: date, name: obj.description });
}
});
cb(hols);
}).fail(function() {
cb([]);
});
}
function getHolidays(cb) {
if (hols.length > 0) cb(hols);
else {
var dt = new Date();
getHolidaysForYear(dt.getFullYear()-1, function(arr) {
hols = hols.concat(arr);
getHolidaysForYear(dt.getFullYear(), function(arr) {
hols = hols.concat(arr)
getHolidaysForYear(dt.getFullYear()+1, function(arr) {
hols = hols.concat(arr)
cb(hols);
});
});
});
}
}
// n is 1-based, xday and month are 0-based.
function getNthXDayOfMonth(n, xday, month, year) {
var dt;
for ( var d = 1; d <= 7; ++d ) {
var dt = new Date( year, month, d );
if ( dt.getDay() == xday ) break;
}
dt.setDate( d + 7 * (n-1) );
if ( dt.getMonth() != month ) dt = null;
//console.log('getNthXDayOfMonth(' + n + ',' + xday + ',' + month + ',' + year + ') = ' + dt);
return dt;
}
function addRecurringEvents() {
var arr = getRecurringEvents();
arr.forEach(function(ev) {
$('#calendardiv').fullCalendar('renderEvent',ev,true);
});
}
function getRecurringEvents(months) {
var enddt = null;
if (!screwtopDb.isEmpty(months)) {
var dt = new Date();
var newMo = dt.getMonth() + months;
if (newMo > 11) {
dt.setFullYear(dt.getFullYear() + 1)
newMo %= 12;
}
dt.setMonth(newMo);
enddt = dt;
}
var retval = [];
recurSpecs.forEach(function(recurSpec) {
var dt = new Date();
dt.setTime(recurSpec.start);
if (screwtopDb.isEmpty(months)) enddt = parseFloat(recurSpec.end);
while (dt.getTime() < enddt) {
skip = false;
if (!screwtopDb.isEmpty(recurSpec.exceptions)) {
skip = (recurSpec.exceptions.indexOf('' + dt.getMonth()) >= 0)
}
/*
for (var e = 0; e < recurExceptions.length; e++) {
var rex = recurExceptions[e];
// Skip deleted months
if (rex.id == recurSpec.id && rex.month == dt.getMonth()) {
skip = true;
break;
}
}
*/
if (!skip) {
var evdt = getNthXDayOfMonth(recurSpec.nth, recurSpec.recurwkday, dt.getMonth(), dt.getFullYear());
evdt.setHours(recurSpec.startHr);
evdt.setMinutes(recurSpec.startMin);
schedev = {
id: recurSpec.id,
//location: recurSpec.location,
duration: recurSpec.duration,
owner: recurSpec.owner,
//title: recurSpec["title"],
start: evdt,
color:recurSpec.color,
valueId: recurSpec.valueId,
textColor: recurSpec.textColor,
recur: true
};
schedev["title"] = recurSpec["title"];
schedev["location"] = recurSpec["location"];
if (recurSpec.infolink) schedev.infolink = recurSpec.infolink;
if (recurSpec.articleTopicId) schedev.articleTopicId = recurSpec.articleTopicId;
retval.push(schedev);
}
var mo = dt.getMonth();
dt.setDate(1);
if (++mo < 12) dt.setMonth(mo);
else {
mo = 0;
dt.setMonth(0);
dt.setFullYear(dt.getFullYear() + 1);
}
}
});
return retval;
}
function utcToLocal(utcms) {
var dt = new Date();
var ms = utcms;
if (screwtopDb.isObject(utcms)) ms = utcms.getTime();
dt.setTime(ms); // Necessary if the target date is past a daylight savings time change.
return new Date(ms - dt.getTimezoneOffset() * 60 * 1000);
}
function updateCalendar() {
showSpinner();
$('#calendar').fullCalendar('removeEventSource');
$('#calendar').fullCalendar('removeEvents');
//events = null;
if (events == null) {
var evArray = [];
var valueIdsByTopicIds = {};
screwtopDb().url(DBURL)
.appName(APPNAME)
.topicByName('schedule')
.tags(/.*\/events$/)
.values()
.each(function(v) {
valueIdsByTopicIds[v.topicId] = v.valueId;
})
.topics({elide:true})
.sort(function(a,b) {
if (a.startTime[0] < b.startTime[0]) return -1;
else if (a.startTime[0] > b.startTime[0]) return 1;
else return 0;
})
.each(function(ev) {
var schedev;
//console.log(JSON.stringify(ev,null,' '));
//console.log("lang=" + lang);
if (screwtopDb.isEmpty(ev.infolink)) {
schedev = {
id: ev.id,
articleTopicId: ev.articleTopicId,
//location: ev.location,
duration: ev.duration[0],
//title: ev.title[0],
owner: screwtopDb.isEmpty(ev.owner) ? '':ev.owner[0],
valueId: valueIdsByTopicIds[ev.topicId],
start: utcToLocal(ev.startTime[0])
};
schedev["title"] = ev["title-" + lang][0];
schedev["location"] = ev["location-" + lang][0];
}
else {
schedev = {
id: ev.id,
infolink: ev.infolink,
//location: ev.location,
duration: ev.duration[0],
//title: ev.title[0],
owner: screwtopDb.isEmpty(ev.owner) ? '':ev.owner[0],
valueId: valueIdsByTopicIds[ev.topicId],
start: utcToLocal(ev.startTime[0])
};
schedev["title"] = ev["title-" + lang][0];
schedev["location"] = ev["location-" + lang][0];
}
evArray.push(schedev);
})
/*
.fn(function() {
var today = new Date();
getHolidays(function(arr) {
arr.forEach(function(ev) {
schedev = {
id: 0,
infolink: '#',
location: 'US',
duration: 24*60,
owner: 'pdclub',
title: ev.name,
start: ev.date,
background:white,
valueId: 0,
color: red
};
evArray.push(schedev);
});
screwtopDb().resume();
})
})
.wait()
*/
.end(function() {
//console.log('evArray: ' + JSON.stringify(evArray,null,' '));
populateEventsList(evArray);
$('#calendardiv').fullCalendar('addEventSource', evArray);
$('.rnd').corner('6px');
hideSpinner();
});
}
else {
if (screwtopDb.isEmpty(events[0]) || screwtopDb.isEmpty(events[0].start)) {
for (var i=0; i < events.length; i++) {
events[i].start = utcToLocal(events[i].startTime);
}
//populateEventsList(events);
//console.log("events:" + JSON.stringify(events,null,' '));
populateEventsList(mergeEventLists(events,getRecurringEvents(3)));
$('#calendardiv').fullCalendar('addEventSource', events);
$('.rnd').corner('6px');
hideSpinner();
}
}
}
function mergeEventLists(arr1, arr2) {
//console.log(JSON.stringify(arr1,null,' '));
//console.log(JSON.stringify(arr2,null,' '));
var arr = arr1.concat(arr2);
arr.sort(function(a,b) {
if (a.start < b.start) return -1;
else if (a.start > b.start) return 1;
else return 0;
});
//console.log(JSON.stringify(arr,null,' '));
return arr;
}
function populateEventsList(arr) {
//console.log(JSON.stringify(arr,null,' '));
$('.evlist').html('
Upcoming Events
');
var now = (new Date()).getTime();
screwtopDb.forEach(arr, function(ev) {
if (ev.start.getTime() >= now && ev.start.getTime() - now < 1000*60*60*24*42) {
if (!screwtopDb.isEmpty(ev.articleTopicId)) {
$('.evlist').append(
'
');
var items = $('.infoitem:not(#homebtn)');
var len = items.length;
$(items[0]).find('a div .ilfr').remove();
$(items[len - 1]).find('a div .irtr').remove();
$('.subitem:not(.sect) a').prepend(
'
' +
'' +
'' +
//'' +
'
');
items = $('.subitem');
len = items.length;
if (items.length == 1) items.find('.configtools').remove();
$(items[0]).find('a div .silf').remove();
$(items[len - 1]).find('a div .sirt').remove();
$('.subitem2:not(.blink):not(.sect) a').prepend(
'
' +
'' +
'' +
//'' +
'' +
'
');
items = $('.subitem2');
len = items.length;
if (items.length == 1) items.find('.ilf,.irt').remove();
$(items[0]).find('a div .ilf').remove();
$(items[len - 1]).find('a div .irt').remove();
$('#homebtn a').prepend(
'' +
'' +
'');
$('.sect a').prepend(
'
' +
'' +
'' +
'
');
$('body').prepend(
'
' +
'' +
'
');
$('#articles .articlediv').first().prepend(
'
' +
'' +
'
');
$('.fc-header-center').html(
'
' +
'' +
'
');
$('.td-commentdiv').first().prepend(
'
' +
'' +
'
');
$('.config').show();
}
function bindConfigTools() {
$('.iplus').unbind().click(function(e) {
var newTopicName;
var targetTopicId;
//e.preventDefault();
if ($(this).parent().parent().parent('#homebtn').length > 0) {
targetTopicId = rootBlogTopicId;
newTopicName = prompt('Enter the name for the new top-level section.');
}
else {
targetTopicId = blogTopicId;
newTopicName = prompt('Enter the subsection to create inside the section "' + blogTopicTitle + '".');
}
if (!newTopicName) return false;
newTopicName = newTopicName.trim();
var isDiscussion = (newTopicName.toLowerCase() == "discuss");
var options = [];
var guid = screwtopDb.guid();
screwtopDb().url(DBURL)
.invalidateCache()
.logout()
.login(APPNAME,APPNAME,configpass,60,true)
.topicById(targetTopicId,{elide: true})
.push()
.tag('./options')
.values()
.text()
.fn(function(opts) {
options = opts;
})
.pop()
.each(function(topic) {
var obj = {
text: newTopicName + guid,
options: options
};
obj['title-' + lang] = newTopicName;
obj['subtitle-' + lang] = topic["title-" + lang][0];
if (isDiscussion) obj['options'] = ["nonewbutton", "afterlogin"];
//alert(JSON.stringify(obj));
screwtopDb(topic).url(DBURL)
.addTags('subblogs',newTopicName + guid)
.addTopics(obj)
.end();
})
.logout()
.authentication(APPNAME,username,password)
.end(function() {
window.location.reload();
});
return false;
});
$('.icpy').unbind().click(function(e) {
var newTopicName;
var targetTopicId;
var srcTopicTitle = $(this).parent().parent().attr('href').substr(1);
//e.preventDefault();
/*
if ($(this).parent().parent().parent('#homebtn').length > 0) {
targetTopicId = rootBlogTopicId;
newTopicTitle = prompt('Enter the name for the copy of ' + srcTopicTitle + '.');
}
else {
targetTopicId = blogTopicId;
newTopicTitle = prompt('Enter the name for the copy of ' + srcTopicTitle + '.');
}
if (!newTopicTitle) return false;
newTopicTitle = newTopicTitle.trim();
newTopicName = newTopicTitle + screwtopDb.guid();
//alert(srcTopicTitle + '\n\n' + newTopicTitle + '\n\n' + newTopicName);
*/
screwtopDb().url(DBURL)
/*
.invalidateCache()
.logout()
.login(APPNAME,APPNAME,configpass)
.topicByName(srcTopicTitle,{include: 'inbound'})
.tags()
.tag('./title-' + lang)
.values()
.topics({include: 'inbound'}) // this is the subblog topic
.tag('./subblogs')
.values()
.topics() // this is the owning blog topic
.addTags('subblogs',newTopicName)
.tag('./subblogs')
.values()
.select("text = '" + srcTopicName + "'")
//.deleteValues(oldVid)
.topicByName(srcTopicName,{include: 'outbound'})
.tags()
.each(function(tag) {
var owner = tag.text.replace(/^(.+?)\/.*$/,"$1");
var tagtext = tag.tagText(true);
var topic = {};
screwtopDb().url(DBURL)
.login(APPNAME,owner,'')
.fn(function() {
topic.text = newTopicName;
screwtopDb(tag).url(DBURL)
.values()
.text()
.fn(function(textarr) {
topic[tagtext] = textarr;
})
.addTopics(topic)
.end();
})
.login(APPNAME,APPNAME,configpass)
.end();
})
.logout()
.authentication(APPNAME,username,password)
*/
.end(function() {
alert("This function is not yet available.");
//alert(window.location);
//window.location.reload();
});
return false;
});
$('.idel').unbind().click(function(e) {
$('#spinner').fadeIn('fast');
var topicname = $(this).closest('a').attr('href');
topicname = topicname.replace(/\/(.*)$/,"$1");
var cur = $(this).closest('.subitem2,.infoitem');
if (confirm(topicname + ': Are you sure you want to delete the section and all its content?')) {
var topicId;
screwtopDb().url(DBURL)
.invalidateCache()
.logout()
.login(APPNAME,APPNAME,configpass)
//.beginServerExecution()
.topicByName(topicname,{include: 'inbound'})
.tag('./title-' + lang)
.values()
.topics({include: 'inbound'})
.each(function(topic) {
var valId = "";
screwtopDb(topic).url(DBURL)
.tag('./subblogs')
.values()
.topics({elide:true, tagfilter: APPNAME + '/subblogs'})
.tags()
.values()
.each(function(v) {
if (valId == "") {
screwtopDb(v).url(DBURL)
.topics()
.select('text = /^' + topic.text + '/')
.ifAny(function() {
valId = v.valueId;
})
.end();
}
})
.fn(function() {
screwtopDb().url(DBURL)
.valueById(valId)
.push()
.topics()
.values()
.deleteValues()
.pop()
.deleteValues()
.end();
})
.end();
})
.logout()
.authentication(APPNAME,username,password)
.end(function() {
cur.remove();
$('#spinner').stop().hide();
});
}
return false;
});
var spec = '.ilf, .irtr';
if (rootBlogOptions.indexOf('layoutpitch') < 0) {
spec = '.irt, .ilfr';
}
$(spec).unbind().click(function(e) {
$('#spinner').fadeIn('fast');
var topicname = $(this).closest('a').attr('href');
topicname = topicname.replace(/\/(.*)$/,"$1");
var cur = $(this).closest('.subitem2,.infoitem');
var nxt = cur.prev().closest('.subitem2,.infoitem');
var subblogName;
screwtopDb().url(DBURL)
.invalidateCache()
.logout()
.login(APPNAME,APPNAME,configpass,3600,true)
.topicByName(topicname,{include: 'inbound'})
.tag('./title-' + lang)
.values()
.each(function(v) { subblogName = v.text; })
.topics({elide:true, include: "inbound"})
.tag('./subblogs')
.values()
.topics({elide:true, tagfilter: APPNAME + '/subblogs'})
.values()
.fn(function(vals) {
var prev = null;
vals.forEach(function(v) {
if (v.text != subblogName) {
prev = v;
}
else if (prev != null) {
screwtopDb().url(DBURL)
.moveValue(prev.valueId, v.valueId)
.end();
prev = null;
}
})
})
.logout()
.authentication(APPNAME,username,password)
.end(function() {
cur.insertBefore(nxt);
bindConfig();
$('#spinner').stop().hide();
});
return false;
});
spec = '.irt, .ilfr';
if (rootBlogOptions.indexOf('layoutpitch') < 0) {
spec = '.ilf, .irtr';
}
$(spec).unbind().click(function(e) {
$('#spinner').fadeIn('fast');
var topicname = $(this).closest('a').attr('href');
topicname = topicname.replace(/\/(.*)$/,"$1");
var cur = $(this).closest('.subitem2,.infoitem');
var nxt = cur.next().closest('.subitem2,.infoitem');
var subblogName;
screwtopDb().url(DBURL)
.invalidateCache()
.logout()
.login(APPNAME,APPNAME,configpass,3600,true)
.topicByName(topicname,{include: 'inbound'})
.tag('./title-' + lang)
.values()
.each(function(v) { subblogName = v.text; })
.topics({elide:true, include: "inbound"})
.tag('./subblogs')
.values()
.topics({elide:true, tagfilter: APPNAME + '/subblogs'})
.values()
.fn(function(vals) {
var targ = null;
vals.forEach(function(v) {
if (v.text == subblogName) {
targ = v;
}
else if (targ != null) {
screwtopDb().url(DBURL)
.moveValue(targ.valueId,v.valueId)
.end();
targ = null;
}
})
})
.logout()
.authentication(APPNAME,username,password)
.end(function() {
cur.insertAfter(nxt);
bindConfig();
$('#spinner').stop().hide();
});
return false;
});
spec = '.silf';
//if (rootBlogOptions.indexOf('layoutpitch') < 0) {
// spec = '.sirt';
//}
$(spec).unbind().click(function(e) {
$('#spinner').fadeIn('fast');
var topicid = $(this).closest('a').attr('href');
topicid = topicid.replace(/.*\/(.*)$/,"$1");
var cur = $(this).closest('.subitem');
var prv = cur.prev().closest('.subitem');
screwtopDb().url(DBURL)
.invalidateCache()
.logout()
.login(APPNAME,APPNAME,configpass, 3600, true)
.topicById(topicid,{elide:true, include:'inbound'})
.tags()
.select('text = /^.*?\\/article-month\\/.*$/')
.values()
.topics({elide:true})
.tags()
.select('text = /^.*?\\/article-month\\/.*$/')
.values() // This is the article list
.topics({elide:true})
.sort(function(a,b) {
var af = parseFloat(screwtopDb.isDefined(a.priority) ? a.priority[0] : 100);
var bf = parseFloat(screwtopDb.isDefined(b.priority) ? b.priority[0] : 100);
if (af < bf) return -1;
else if (af > bf) return 1;
else return 0;
})
.fn(function(topics) {
var i = 100;
screwtopDb(topics).url(DBURL)
.each(function(t) {
var p = i++;
if (t.topicId == topicid) {
p -= 1.5;
}
//"New priority: " + p);
screwtopDb(t).url(DBURL)
.tags()
.select('text = /.*\\/priority$/')
.values()
.ifNone(function() {
screwtopDb(t).url(DBURL)
.addTags('priority',p)
.end();
}, function(vals) {
screwtopDb(vals).url(DBURL)
.updateValue(p)
.end()
})
.end();
})
.end();
})
.logout()
.authentication(APPNAME,username,password)
.end(function() {
cur.insertBefore(prv);
bindConfig();
$('#spinner').stop().hide();
});
return false;
});
spec = '.sirt';
//if (rootBlogOptions.indexOf('layoutpitch') < 0) {
// spec = '.silf';
//}
$(spec).unbind().click(function(e) {
$('#spinner').fadeIn('fast');
var topicid = $(this).closest('a').attr('href');
topicid = topicid.replace(/.*\/(.*)$/,"$1");
var cur = $(this).closest('.subitem');
var nxt = cur.next().closest('.subitem');
screwtopDb().url(DBURL)
.invalidateCache()
.logout()
.login(APPNAME,APPNAME,configpass,3600,true)
.beginServerExecution()
.topicById(topicid,{elide:true, include:'inbound'})
.tags()
.select('text = /^.*?\\/article-month\\/.*$/')
.values()
.topics({elide:true})
.tags()
.select('text = /^.*?\\/article-month\\/.*$/')
.values() // This is the article list
.topics({elide:true})
.endServerExecution()
.sort(function(a,b) {
var af = parseFloat(screwtopDb.isDefined(a.priority) ? a.priority[0] : 100);
var bf = parseFloat(screwtopDb.isDefined(b.priority) ? b.priority[0] : 100);
if (af < bf) return -1;
else if (af > bf) return 1;
else return 0;
})
.fn(function(topics) {
var i = 100;
screwtopDb(topics).url(DBURL)
.each(function(t) {
var p = i++;
if (t.topicId == topicid) {
p += 1.5;
}
//console.log("New priority: " + p);
screwtopDb(t).url(DBURL)
.tags()
.select('text = /.*\\/priority$/')
.values()
.ifNone(function() {
screwtopDb(t).url(DBURL)
.addTags('priority',p)
.end();
}, function(vals) {
screwtopDb(vals).url(DBURL)
.updateValue(p)
.end()
})
.end();
})
.end();
})
.logout()
.authentication(APPNAME,username,password)
.end(function() {
cur.insertAfter(nxt);
$('#subblogs .subitem').removeClass('sect');
$('#subblogs .subitem').first().addClass('sect');
bindConfig();
$('#spinner').stop().hide();
});
return false;
});
function showhidehome() {
if (blogTopicId == rootBlogTopicId) {
$('.homepageonly').show();
$('.nohome').hide();
}
else {
$('.homepageonly').hide();
$('.nohome').show();
}
}
var configScriptLoaded = false;
$('.igearmain').unbind().click(function() {
var dialog = $("#igearmaindlg").dialog({
autoOpen: false,
height: 800,
width: 800,
modal: true,
buttons: {
Close: function() {
dialog.dialog( "close" );
}
},
close: function() {
//form[ 0 ].reset();
//allFields.removeClass( "ui-state-error" );
}
});
if (!configScriptLoaded) {
$.getScript('/js/colorpicker/js/colorpicker.js');
$.getScript('xl/js/configure.js').done(function(data, textStatus) {
populateConfig(configpass);
showhidehome();
dialog.dialog('open');
configScriptLoaded = true;
})
.fail(function(jqxhr, settings, e) {
console.log(e);
})
}
else {
populateConfig(configpass);
showhidehome();
dialog.dialog('open');
}
});
$('.igear').unbind().click(function() {
var dialog = $("#igearsectdlg").dialog({
autoOpen: false,
height: 800,
width: 800,
modal: true,
buttons: {
Close: function() {
dialog.dialog( "close" );
}
},
close: function() {
//form[ 0 ].reset();
//allFields.removeClass( "ui-state-error" );
}
});
if (!configScriptLoaded) {
$.getScript('/js/colorpicker/js/colorpicker.js');
$.getScript('xl/js/configure.js').done(function(data, textStatus) {
populateConfig(configpass);
dialog.dialog('open');
configScriptLoaded = true;
})
.fail(function(jqxhr, settings, e) {
console.log(e);
})
}
else {
populateConfig(configpass);
dialog.dialog('open');
}
});
}
$('#config').unbind().click(function() {
if (hasSessionStorage()) configActive = getSessionStorage(APPNAME + '-configActive') == 'true';
if (configActive) {
configActive = false;
setSessionStorage(APPNAME + '-configActive','false');
$('.configtools').remove();
$('.config').hide();
$('#infoline, #main').css('position','').css("top", "0");
if (rootBlogOptions.indexOf('layoutpitch') < 0) {
$('#infoline').css('margin-top','0px');
}
$('#bannerbtndiv').remove();
if (isBlogPoster()) {
$('.authoractions').show();
$('.commentactions').show();
$('#addarticlebtn').show();
}
return false;
}
else {
$('#addarticlebtn, .authoractions, .commentactions').hide();
}
if (hasSessionStorage()) configpass = getSessionStorage(APPNAME + '-configpass');
if (!configpass || configpass == "false") {
var pswd = prompt("Password");
if (pswd != null && pswd.trim().length > 0) {
screwtopDb().url(DBURL)
.onError(function() {
alert('Invalid password.');
screwtopDb().abort().end();
})
.login(APPNAME,APPNAME,pswd)
.onError()
.logout()
.authentication(APPNAME,username,password)
.end(function() {
configpass = pswd;
configActive = 'true';
if (hasSessionStorage()) {
setSessionStorage(APPNAME + '-configpass',pswd);
setSessionStorage(APPNAME + '-configActive','true');
}
showConfigTools();
bindConfigTools();
enableTitlePositioning();
enableBannerCropping();
});
}
}
else {
configActive = 'true';
if (hasSessionStorage()) {
setSessionStorage(APPNAME + '-configActive','true');
}
showConfigTools();
bindConfigTools();
enableTitlePositioning();
enableBannerCropping();
}
// ##### TODO: DISABLE ADD, EDIT, AND DELETE ARTICLES WHILE CONFIG TOOLS ARE SHOWN (BECAUSE THEY ARE
// LOGGED IN AS THE SUPERUSER.) -- Check to see if this is really needed now.
});
if (hasSessionStorage()) configActive = getSessionStorage(APPNAME + '-configActive') == 'true';
if (configActive) {
configpass = getSessionStorage(APPNAME + '-configpass');
showConfigTools();
bindConfigTools();
enableTitlePositioning();
enableBannerCropping();
}
}
function bindSettings() {
$('#settings').unbind().click(function() {
$('#settings').unbind().click(function() {
$('#settingscancelbtn').click();
});
var showSpinner = true;
setTimeout(function() {
if (showSpinner) {
$('#spinner').fadeIn('fast');
}
}, 1000);
//$('.wrapper, .commentdiv, #nominatediv, #logindiv, #regdiv, #faqdiv').hide();
$('#settingsstreet').val('');
$('#settingscity').val('');
$('#settingsstate').val('');
$('#settingszip').val('');
$('#settingsphone').val('');
$('#settingsemail').val('');
if (includeDues) $('#settingsduespaid').val('');
$('#settingspassword').val('');
$('#settingsconfirmpassword').val('');
$('.container').hide();
$('#settingsdiv').show('blind', 500);
screwtopDb().url(DBURL)
.session(function(s) {
if (!screwtopDb.isEmpty(getCookie(rootBlogTopicId + '-impersonating'))) {
$('#settingsusername').val(getCookie(rootBlogTopicId + '-impersonating'));
screwtopDb().url(DBURL)
.logout()
.login(APPNAME, getCookie(rootBlogTopicId + '-username'), getCookie(rootBlogTopicId + '-password'))
.login(APPNAME, getCookie(rootBlogTopicId + '-impersonating'), '')
.attributes()
// Login is required to get attributes with an empty password (don't know why…)
//.login(APPNAME,username, password)
.func(function(arr) {
screwtopDb.forEach(arr, function(pair) {
if (pair.name == "street") $('#settingsstreet').val(pair.value);
else if (pair.name == "city") $('#settingscity').val(pair.value);
else if (pair.name == "state") $('#settingsstate').val(pair.value);
else if (pair.name == "zip") $('#settingszip').val(pair.value);
else if (pair.name == "phone") $('#settingsphone').val(pair.value);
else if (pair.name == "email") $('#settingsemail').val(pair.value);
else if (includeDues && pair.name == "Year Paid") $('#settingsduespaid').val(pair.value);
});
if (includeDues) {
// Highlight unpaid dues
var dt = new Date();
var thisYr = dt.getFullYear();
if ($('#settingsduespaid').val() < thisYr) $('#duespaidlabel').css('color', 'red');
}
})
.end();
}
else {
$('#settingsusername').val(s.username);
screwtopDb().url(DBURL)
.login(APPNAME,username, password)
.attributes()
// Login is required to get attributes with an empty password (don't know why…)
//.login(APPNAME,username, password)
.func(function(arr) {
screwtopDb.forEach(arr, function(pair) {
if (pair.name == "street") $('#settingsstreet').val(pair.value);
else if (pair.name == "city") $('#settingscity').val(pair.value);
else if (pair.name == "state") $('#settingsstate').val(pair.value);
else if (pair.name == "zip") $('#settingszip').val(pair.value);
else if (pair.name == "phone") $('#settingsphone').val(pair.value);
else if (pair.name == "email") $('#settingsemail').val(pair.value);
else if (includeDues && pair.name == "Year Paid") $('#settingsduespaid').val(pair.value);
});
if (includeDues) {
// Highlight unpaid dues
var dt = new Date();
var thisYr = dt.getFullYear();
if ($('#settingsduespaid').val() < thisYr) $('#duespaidlabel').css('color', 'red');
}
})
.end();
}
})
/*
// Login is required to get attributes with an empty password (don't know why…)
//.login(APPNAME,username, password)
.func(function(arr) {
screwtopDb.forEach(arr, function(pair) {
if (pair.name == "street") $('#settingsstreet').val(pair.value);
else if (pair.name == "city") $('#settingscity').val(pair.value);
else if (pair.name == "state") $('#settingsstate').val(pair.value);
else if (pair.name == "zip") $('#settingszip').val(pair.value);
else if (pair.name == "phone") $('#settingsphone').val(pair.value);
else if (pair.name == "email") $('#settingsemail').val(pair.value);
});
})
//.attributes('email')
*/
.end(function() {
//$('#settingsemail').val(em[0].value);
showSpinner = false;
$('#spinner').stop().hide();
});
$('#settingscancelbtn').unbind().click(function() {
$('#settingsstreet').val('');
$('#settingscity').val('');
$('#settingsstate').val('');
$('#settingszip').val('');
$('#settingsphone').val('');
$('#settingsemail').val('');
if (includeDues) $('#settingsduespaid').val('');
$('#settingspassword').val('');
$('#settingsconfirmpassword').val('');
$('#settingsdiv').hide('blind', 500);
bindSettings();
})
$('#settingsbutton').unbind().click(function() {
var p = '';
if ($('#settingspassword').val() == $('#settingsconfirmpassword').val()) {
p = $('#settingspassword').val().trim();
}
else {
alert('Password and confirm password do not match.');
return;
}
var e = $('#settingsemail').val().trim();
var obj = {};
var doIt = false;
if (e != '') {
obj["email"] = e;
doIt = true;
}
if (p != '') {
obj["password"] = p;
doIt = true;
}
obj["street"] = $('#settingsstreet').val().trim();
obj["city"] = $('#settingscity').val().trim();
obj["state"] = $('#settingsstate').val().trim();
obj["zip"] = $('#settingszip').val().trim();
obj["phone"] = $('#settingsphone').val().trim();
if (doIt) {
var showSpinner = true;
setTimeout(function() {
if (showSpinner) {
$('#spinner').fadeIn('fast');
}
}, 1000);
screwtopDb().url(DBURL)
.updateUser(obj)
.end(function() {
showSpinner = false;
$('#spinner').stop().hide();
$('#settingsstreet').val('');
$('#settingscity').val('');
$('#settingsstate').val('');
$('#settingszip').val('');
$('#settingsphone').val('');
$('#settingsemail').val('');
$('#settingspassword').val('');
$('#settingsconfirmpassword').val('');
$('#settingsdiv').hide('blind', 500);
setSingleUseToken(function(tok) {
$.ajax(addlang('attr?token=' + tok));
})
alert('Account settings successfully updated.');
});
}
});
$('#deleteaccountbtn').unbind().click(function() {
var delpswd = prompt("All your contributions to this website will be removed.\n\n" +
"Enter your password below to delete your account.\n\n");
//if (!screwtopDb.isEmpty(delpswd)) {
$('#spinner').fadeIn('fast');
screwtopDb().url(DBURL)
.logout()
.onError(function() {
$('#spinner').stop().hide();
alert('Password match error.')
screwtopDb().url(DBURL).onError().abort().end();
})
.login(APPNAME, username, delpswd)
.onError()
.func(function() {
$('#settingsemail').val('');
$('#settingspassword').val('');
$('#settingsconfirmpassword').val('');
$('#settingsdiv').hide('blind', 500);
})
.deleteUser(username)
.func(localLogout)
.invalidateCache()
.end(function() {
$('#spinner').stop().hide();
location = '/';
});
//}
})
});
}
var shifted = false;
$(document).on('keyup keydown', function(e){shifted = e.shiftKey} );
function bindMenuLinks() {
$('#touchdiv').unbind().click(function() {
showLoginForm();
});
$('.infoitem')
.unbind()
.click(function(ev) {
$('.infoitem.selected').removeClass('selected');
$(this).addClass('selected');
if (shifted && !isLoggedIn()) {
showLoginForm();
return false;
}
else {
$('#main').show();
$('#newarticle').hide("blind");
var href = $(ev.target).find('a').attr('href');
showContent(href);
//var articleId = $(ev.target).attr('articleId');
}
return false;
});
$('.infoitem a').unbind().click(function() {
$(this).parent().click();
return false;
});
}
function schedEvent(localms, dur, title, loc, topicId, color) {
// Event times stored as UTC
var dt = new Date(localms);
var utcms = dt.getTime() + (dt.getTimezoneOffset() * 60 * 1000);
var event = {
text: screwtopDb.guid(),
startTime: utcms,
duration: dur,
//title: title,
//location: loc,
textColor: 'white',
color: color,
owner: username,
articleTopicId: topicId };
event["title-" + lang] = title;
event["location-" + lang] = loc;
//console.log(JSON.stringify(event,null,' '));
return { text: 'schedule', events: event };
}
function schedEvent2(localms, dur, title, loc, link, color) {
// Event times stored as UTC
var dt = new Date(localms);
var utcms = dt.getTime() + (dt.getTimezoneOffset() * 60 * 1000);
var event = {
text: screwtopDb.guid(),
startTime: utcms,
duration: dur,
//title: title,
//location: loc,
textColor: 'white',
color: color,
owner: username,
infolink: link };
event["title-" + lang] = title;
event["location-" + lang] = loc;
//alert(JSON.stringify(event,null,' '));
return { text: 'schedule', events: event };
}
function recurEvent(ev, nth, xDay, endMo, endYr, color) {
var startDt = new Date(ev.startTime);
var endDt = new Date();
endDt.setHours(0);
endDt.setMinutes(0);
endDt.setSeconds(0);
endDt.setMonth(endMo);
endDt.setDate(1);
endDt.setFullYear(endYr);
var recurSpec = {
text: screwtopDb.guid(),
nth: nth, // every 2nd
recurwkday: xDay, // friday
//location: ev["location"],
startHr: ((startDt.getHours() - startDt.getTimezoneOffset()/60) + 24) % 24, // Local timezone hour
startMin: ((startDt.getMinutes() - startDt.getTimezoneOffset()%60) + 60) % 60, // Local timezone minute
duration: ev.duration,
owner: ev.owner,
//title: ev["title"],
start: ev.startTime,
end: endDt.getTime(),
color: color,
textColor: 'white'
};
recurSpec["title-" + lang] = ev["title-" + lang];
recurSpec["location-" + lang] = ev["location-" + lang];
if (!screwtopDb.isEmpty(ev.infolink)) recurSpec.infolink = ev.infolink;
if (!screwtopDb.isEmpty(ev.articleTopicId)) recurSpec.articleTopicId = ev.articleTopicId;
return { text: 'recurringEvents', specifications: recurSpec };
}
function initCalendar() {
$('#startdate2').unbind().change(function() {
var dt = new Date(Date.parse($(this).val()));
$('#enddate2').datepicker('setDate',dt);
$('#starttime2').timepicker('setTime', dt);
});
$('#starttime2').unbind().change(function() {
$('#endtime2').timepicker({'minTime': $(this).val(), 'showDuration': true });
$('#endtime2').val($(this).val());
});
var holsAdded = false;
$('#calendardiv').fullCalendar({
theme: true,
timeFormat: { '': 'h(:mm)t' },
eventAfterAllRender: function() {
if (!holsAdded) {
holsAdded = true;
addHolidays();
}
},
eventColor: '#4488bb',
eventRender: function(event, element) {
element.click(function() {
var delbtnstr = ""
if (event.recur == true) {
delbtnstr = '' +
'';
}
else {
delbtnstr = '';
}
var morebtnstr = "";
if (!screwtopDb.isEmpty(event.infolink)) {
morebtnstr = 'More info';
}
else if (!screwtopDb.isEmpty(event.articleTopicId)) {
morebtnstr = 'Read more';
}
$('#eventdiv').html('' + event["title"] + ''
+ ''
+ $.fullCalendar.formatDate(event.start, 'MMMM d, h:mm TT')
+ ''
+ event.duration
+ ' min'
+ ''
+ event["location"]
+ ''
+ 'Close'
+ morebtnstr
+ delbtnstr).show('blind',500);
if (!screwtopDb.isEmpty(event.owner) && event.owner != username) $('#deleventbtn,#delinstbtn,#delrecurbtn').hide();
else $('#deleventbtn,#delinstbtnm,#delrecurbtn').show();
$('#deleventbtn').unbind().click(function() {
showSpinner();
screwtopDb().url(DBURL)
.deleteValues(event.valueId)
.invalidateCache()
.end(function() {
hideSpinner();
location = '/' + lang + '/calendar';
})
});
$('#delrecurbtn').unbind().click(function() {
showSpinner();
screwtopDb().url(DBURL)
.deleteValues(event.valueId)
.invalidateCache()
.end(function() {
hideSpinner();
location = '/' + lang + '/calendar';
})
});
$('#delinstbtn').unbind().click(function() {
showSpinner();
screwtopDb().url(DBURL)
//.beginServerExecution()
.topicById(event.id, {elide:true})
.addTags('exceptions',event.start.getMonth())
//.endServerExecution()
.invalidateCache()
.end(function() {
hideSpinner();
location = '/' + lang + '/calendar';
})
});
$('#eventclosebtn').unbind().click(function() {
$('#eventdiv').hide('blind', 500);
});
bindLinks();
$('.morebtn2, .closebtn').corner('6px');
$('#eventdiv').corner('6px');
//if (isBlogPoster()) $('#deleventbtn').show();
});
}
});
}
function localLogout() {
//username = '';
//$('.userinfoitem').hide();
//setAuthorActions();
epi.hidePersonalSidebar();
deleteCookie(rootBlogTopicId + '-impersonating');
deleteCookie(rootBlogTopicId + '-username');
deleteCookie(rootBlogTopicId + '-password');
//$('#addarticlebtn, #logoutbtn, #schedbtn, #deleventbtn, .localitem').hide();
//$('#loginbtn, #registerbtn').show();
deleteCookie(APPNAME + '-configpass')
if (hasSessionStorage) sessionStorage[APPNAME + '-configActive'] = false;
if (hasSessionStorage) sessionStorage[APPNAME + '-configpass'] = false;
configActive = false;
$('.configtools').remove();
window.location = '/';
}
var theAnimator = null;
/*
function animator(targetImg,targetDiv) {
if (theAnimator != null) {
theAnimator.stopAnimation();
}
theAnimator = this;
var curLeftPx = 0;
var curTopPx = 0;
var curHeight;
var leftInc = 0;
var topInc = 0;
var heightInc = 0;
var divh;
var divw;
var ih,iw;
var ratio;
var frameRate;
var frames;
var startTime;
var abort = false;
var maxmag;
var minmag;
var delay;
var rt;
iw = targetImg.width();
ih = targetImg.height();
divh = parseInt(targetDiv.css('height'));
divw = parseInt(targetDiv.css('width'));
targetImg.css('height',(ih * (divw/iw)) + 'px');
targetImg.css('margin-left', '0px');
//alert('iwxih=' + iw + 'x' + ih + '\n' + 'divwxdivh=' + divw + 'x' + divh);
this.stopAnimation = function stopAnimation() {
//$('#alog').remove();
abort = true;
}
this.toggle = function toggle() {
if (abort) {
this.resumeAnimation();
}
else this.stopAnimation();
}
this.initAnimation = function initAnimation() {
$('body').prepend('');
leftInc = -0.1;
topInc = -0.1;
heightInc = 0.05;
targetImg.css('height',((divw/iw) * ih) + 'px');
targetImg.css('margin-left', '0px');
curLeftPx = 0;
curTopPx = 0;
curHeight = (divw/iw) * ih;
ratio = divw/divh;
hdir = 0;
vdir = 0;
mdir = 0;
startTime = (new Date()).getTime();
frames = 0;
delay = 10;
rt = 0;
maxmag = ih * (divw/iw) * 2.5;
minmag = ih * (divw/iw);
abort = false;
}
this.resumeAnimation = function resumeAnimation() {
abort = false;
setTimeout(anim,0);
}
this.startAnimation = function startAnimation() {
this.initAnimation();
setTimeout(anim,0);
}
function anim() {
//var imgh = parseInt(targetImg.css("height"));
//var imgw = parseInt(targetImg.css("width"));
var threshold = 0;
var hthresh = 0;
var vthresh = 0;
var mthresh = 0;
// First zoom in...
if (0 && curHeightPct < minmag * 100) {
heightInc = 0.1;
leftInc = 0.1;
topInc = 0.1;
curHeightPct += heightInc;
curLeftPx -= heightInc*ratio;
curTopPx -= heightInc*1;
targetImg
.css('margin-left',curLeftPx + 'px')
.css('margin-top',curTopPx + 'px')
.css('height',(ih * (curHeightPct/100)) + 'px');
//$('#alog').html('curHeightPct=' + Math.round(curHeightPct) + ' heightInc=' + heightInc + ', frames=' + frames + ', rt=' + rt + ', frameRate=' + Math.round(frameRate) + ', delay=' + Math.round(delay));
}
else {
var imgh = parseInt(targetImg.css("height"));
var imgw = parseInt(targetImg.css("width"));
mthresh = ((maxmag - minmag) / 2) + minmag;
var distFromThresh = Math.abs(mthresh - imgh);
var howClose = distFromThresh / ((maxmag - minmag) / 2);
if (howClose >= 1) {
if (imgh <= minmag) mdir = 0;
else mdir = 1;
}
var minHeightInc = 0.5;
var maxHeightInc = 2.0;
heightInc = (((1-Math.abs(howClose)) * (maxHeightInc - minHeightInc)) + minHeightInc) * (mdir ? -1 : 1);
curHeight += heightInc;
//curLeftPx -= heightInc;
//curTopPx -= heightInc/ratio;
targetImg.css('height',curHeight + 'px');
var imgh = parseInt(targetImg.css("height"));
var imgw = parseInt(targetImg.css("width"));
hthresh = ((imgw - divw) / 2) * -1;
howClose = Math.abs(((hthresh - curLeftPx) / hthresh));
if (howClose >= 1) {
if (curLeftPx >= 0) hdir = 1;
else hdir = 0;
}
// if (imgw + curLeftPx - divw <= 0) hdir = 1;
// if (curLeftPx >= 0) hdir = 0;
var minLeftInc = 0.1;
var maxLeftInc = 4.0;
leftInc = (((1-Math.abs(howClose)) * (maxLeftInc - minLeftInc)) + minLeftInc) * (hdir ? 1 : -1);
//console.log('(((1-'+ Math.abs(howClose) + ')) * (' + maxLeftInc + ' - ' + minLeftInc + ')) + ' + minLeftInc + ') * ' + (hdir ? 1 : -1) + ' = ' + leftInc);
//vthresh = ((imgh - divh) / 2) * -1;
//if (imgh + curTopPx - divh <= 0) vdir = 1;
//if (curTopPx >= 0) vdir = 0;
//howClose = Math.abs(((vthresh - curTopPx) / vthresh));
//var minTopInc = 0.1;
//var maxTopInc = 4.0;
//topInc = (((1-Math.abs(howClose)) * (maxTopInc - minTopInc)) + minTopInc) * (vdir ? 1 : -1);
curLeftPx += leftInc;
//curTopPx += topInc;
targetImg
//.css('height',curHeight + 'px')
.css('margin-left',curLeftPx + 'px')
.css('margin-top',curTopPx + 'px');
$('#alog').html('xyz inc: ' + Math.round(leftInc*100) + ' ' + Math.round(topInc*100) + ' ' + Math.round(heightInc*100)
+ ', curLeftPx: ' + curLeftPx
+ ', hthresh: ' + Math.round(hthresh) + ', howClose: ' + Math.round(howClose*100)
);
}
frames++;
rt = (new Date()).getTime() - startTime;
frameRate = (frames*1000)/rt;
if (rt > 500) {
delay = delay * (frameRate/60);
startTime = (new Date()).getTime();
frames = 0;
}
if (!abort) setTimeout(anim,delay);
}
return this;
}
*/
function showLoginForm() {
$('#usernametext').val("");
$('#passwordtext').val("");
$('#loginloginbtn').attr('disabled', false);
$('#logindiv').show("blind", 500, function() {
$('#usernametext').focus();
});
}
$(document).ready(function() {
$('#perf').html(perfstr);
$('#endyr').html(yroptionlist);
if (rootBlogOptions.indexOf('layoutpitch') >= 0) $('.nopitch').hide();
window.onpopstate = function(ev) {
if (ev.state) {
$('#articles').html(ev.state);
bindLinks();
localize8601Dates();
fixup();
initCalendar();
updateCalendar();
}
}
$('.altlang').click(function() {
var newlang = $(this).attr('data-lang');
var re = new RegExp('/' + lang);
var newpathname = window.location.pathname + newlang;
if (window.location.pathname !="/")
newpathname = window.location.pathname.replace(re,'/' + newlang);
window.location = newpathname;
})
$('#loginbtn').click(function() {
showLoginForm();
$('#loginbtn, #registerbtn').hide();
});
$('#schedbtn').click(function() {
$('#logoutbtn, #schedbtn, #addarticlebtn').hide();
$('#scheddiv').show("blind", 500);
});
$('#cancelschedbtn').click(function() {
$('#logoutbtn, #schedbtn, #addarticlebtn').show();
$('#scheddiv').hide("blind", 500);
});
$('#logincancelbtn').click(function() {
$('#logindiv').hide("blind", function() {
$('#loginbtn, #registerbtn').show();
});
});
$('#registerbtn').click(function() {
$('#regfirstname').val("");
$('#reglastname').val("");
$('#regstreet').val("");
$('#regcity').val("");
$('#regstate').val("CA");
$('#regzip').val("");
$('#regphone').val("");
$('#regpassword').val("");
$('#regconfpassword').val("");
$('#regemail').val("");
$('#loginbtn, #registerbtn').hide();
$('#regregisterbtn').attr('disabled', false);
$('#registerdiv').show("blind", 500, function() {
$('#regfirstname').focus();
});
});
$('#regcancelbtn').click(function() {
$('#registerdiv').hide("blind", function() {
$('#registerbtn, #loginbtn').show();
});
});
function setInfoline(cb) {
screwtopDb().url(DBURL)
//.beginServerExecution()
.topicById(rootBlogTopicId)
.tag(APPNAME + '/subblogs')
.values()
.topics({elide:true, tagfilter: APPNAME + '/title-' + lang})
.values()
.text()
//.endServerExecution()
.fn(function() {
// Remove all but Home
$('.infoitem:not(#homebtn)').remove();
})
.each(function(subblog) {
if (rootBlogOptions.indexOf("layout3") < 0 && rootBlogOptions.indexOf("layout4") < 0) {
$('#infoline').append('