var AssBox =
{
frm: null,
submit: function(el)
{
if (!signedInUser())
return false;
AssBox.frm = $(el).up('form');
if (!parseInt(AssBox.frm.newItemId.value) && AssBox.frm.newItemName.hasAttribute('defVal')
&& AssBox.frm.newItemName.readAttribute('defVal') == AssBox.frm.newItemName.value) {
AssBox.frm.submit();
return true;
}
else if (AssBox.frm.type.value == 'keywords' && !parseInt(AssBox.frm.newItemId.value)) {
AssBox.selectActionType('newItem');
return true;
}
else if (!parseInt(AssBox.frm.newItemId.value)) {
$('assBoxLV').select('input[type="radio"]').each( function(el) { el.selected = false; } );
$('assBoxLV').select('[name="keywordName"]')[0].update(AssBox.frm.newItemName.value);
Lightview.show({
href: 'assBoxLV',
rel: 'inline',
options: {
autosize: true,
topclose: true
}
});
return false;
}
else {
AssBox.frm.submit();
}
},
selectActionType: function(type)
{
switch (type) {
case 'tag':
//$(AssBox.frm.create_link).remove();
AssBox.frm.submit();
break;
case 'newItem':
AssBox.frm.action = '/fast_item.php';
AssBox.frm.submit();
break;
}
//Lightview.hide();
}
}
function submitForm(el)
{
var t;
if (signedInUser()) {
if (t = el.up('form').select('[fname="UserItemId"]')[0])
t.value = window.UserItemId;
$(el).up('form').submit();
}
}
function openWindow(url, name)
{
if (typeof name == 'undefined' || name == '')
name = 'new window';
window_hdl = window.open(url, name, 'width=470,height=440,menubar=yes,directories=no,location=no,resizable=yes,scrollbars=yes');
window_hdl.focus();
return true;
}
function arraySearch(needle, haystack)
{
for (var i = 0; i < haystack.length; ++i) {
if (haystack[i] == needle)
return i;
}
return -1;
}
function Win()
{
this.x_max = 640;
this.y_max = 480;
this.x_offset = 0;
this.y_offset = 0;
this.hdl = 0;
if (document.all) {
this.x_max = screen.width;
this.y_max = screen.height;
}
else {
if (document.layers) {
his.x_max = window.outerWidth;
this.y_max = window.outerHeight;
}
}
this.open = function(url, width, height, title)
{
if (width)
this.x_offset = (this.x_max - width) / 2;
if (height)
this.y_offset = (this.y_max - height) / 2;
var params = 'width=' + width + ', height=' + height + ',screenX=' + this.x_offset + ',screenY=' + this.y_offset;
params += ',top=' + this.y_offset + ',left=' + this.x_offset + ',copyhistory=no,directories=no,';
params += 'menubar=no,location=no,scrollbars=yes,resizable=no';
this.hdl = window.open(url, title, params);
return this.hdl;
}
}
function back(ref, steps)
{
if (ref != '')
window.location.href = ref;
else if (document.refferer && document.refferer != window.location.href)
window.location.href = document.refferer;
else if (!steps)
history.go(-2);
else
history.go(-steps);
}
function showHideEl(id)
{
if ($(id).style.display == 'none')
$(id).style.display = '';
else
$(id).style.display = 'none';
}
var parseNUM = function(text)
{
var ret = /[\d-]+/.exec(text);
return parseInt(ret[0]);
}
var Rating =
{
in_progress: false,
voteValue: 0,
clickedElement: null,
vote: function(element, rating, type, id)
{
if (!signedInUser())
return false;
if (Rating.in_progress) {
Rating.alert("Request is in progress. Please, wait...");
return false;
}
Rating.clickedElement = $(element);
Rating.voteValue = parseInt(rating);
Rating.proccessVote();
new Ajax.Request('/utils/ajax.php?m=vote&v=' + rating + '&id=' + id + '&type=' + type,
{method: 'get', onComplete: Rating.response});
},
proccessVote: function(el)
{
Rating.in_progress = true;
},
response: function(request)
{
Rating.in_progress = false;
var msg;
switch (request.responseText) {
case '1':
msg = 'Your vote has been added.';
var el = Rating.clickedElement.up().select('[name="ratingNum"]')[0];
el.update(Rating.formatNum(parseNUM(el.innerHTML) + Rating.voteValue));
Rating.clickedElement.up().select('input[name="ratingButton"]').each( function(el) { // ie bug
el.remove();
});
break;
case '-1':
msg = 'You have already voted';
break;
default:
msg = 'An error occured';
}
Rating.alert(msg);
},
alert: function(msg)
{
alert(msg);
return true;
},
formatNum: function(num)
{
if (!num)
return '0';
else if (num > 0)
return '' + num;
else
return '' + num;
},
init: function(voted)
{
if (!voted)
return;
var els;/*
for (var i = 0; i < voted.length; ++i) {
els = $$('[val="' + voted[i] +'"]');
for (var ii = 0; ii < els.length; ++ii) {
if (els[ii].readAttribute('name') == 'ratingVoteBox') {
els[ii].remove();
}
}
}*/
}
}
function reloadCaptcha()
{
$('captcha').src = '/registration.php?captcha&top_secret_key=' + (Math.random() * 1000);
}
function populateSelectBox(el, data)
{
el.length = 0;
el.disabled = false;
if (!data.ids.length) {
el.disabled = true;
return;
}
var opt = document.createElement('option');
opt.value = '0';
opt.text = ' ';
selAdd(opt, el, null);
for (var i = 0; i < data.ids.length; ++i) {
opt = document.createElement('option');
opt.value = data.ids[i];
opt.text = data.values[i];
selAdd(opt, el, null);
}
}
function selAdd(opt, el, before_index)
{
if (Prototype.Browser.IE) {
if (!before_index)
el.add(opt);
else
el.add(opt, before_index);
}
else {
if (!before_index)
el.add(opt, null);
else
el.add(opt, el.options[before_index]);
}
}
var TextareaAutoHeight =
{
_checkHeight: function(event)
{
this.doCheckHeight(Event.element(event));
},
doCheckHeight: function(field)
{
var tester = $(document.createElement('div'));
field = $(field);
if (field.offsetWidth) {
tester.setStyle({
width: (field.offsetWidth-25)+'px',
fontFamily: field.getStyle('font-family'),
fontSize: field.getStyle('font-size'),
lineHeight: field.getStyle('line-height'),
border: '1px solid #FFFFFF'
});
}//alert(field.getStyle('line-height'));
tester.appendChild(document.createTextNode(field.value));
tester.innerHTML = tester.innerHTML.replace(/\n/g,'
')+' ';
field.parentNode.appendChild(tester);
if (tester.getHeight() > 10 && (tester.getHeight() > $(field).getHeight() - 20)) {
field.setStyle({height: ($(tester).getHeight() + 20) + 'px'});
}
field.parentNode.removeChild(tester);
},
init: function()
{
TextareaAutoHeight.checkHeight = TextareaAutoHeight._checkHeight.bindAsEventListener(TextareaAutoHeight);
var textareas;
if (textareas = document.getElementsByTagName('textarea')) {
for (var i = 0; i < textareas.length; ++i) {
if (!textareas[i].getAttribute('disabled') && !textareas[i].getAttribute('readonly') && !textareas[i].getAttribute('fixHeight')) {
$(textareas[i]).observe('keyup', TextareaAutoHeight.checkHeight);
this.doCheckHeight(textareas[i]);
}
};
}
}
}
var ExpandCollapse =
{
init: function()
{
var els = document.getElementsByClassName('expandCollapse');
for (var i = 0; i < els.length; ++i) {
ExpandCollapse.observe(els[i].getElementsByTagName('a')[0]);
this.calcInitialState(els[i]);
}
},
observe: function(el)
{
Event.observe(el, 'click', ExpandCollapse.eventHandler.bindAsEventListener(ExpandCollapse));
},
eventHandler: function(event)
{ var el = Event.element(event).parentNode;
ExpandCollapse.proccessEvent(el);
},
proccessEvent: function(el)
{
if (!el.readAttribute('isExpanded') || el.readAttribute('isExpanded') == '0') { // expand that fucking shit!!!
el.writeAttribute('isExpanded', true);
$(this.getDynamicElementId(el)).show();
}
else {
el.writeAttribute('isExpanded', false);
$(this.getDynamicElementId(el)).hide();
}
var callback;
if (callback = el.readAttribute('callback')) {
window[callback].call(window, el);
}
this.setText(el);
},
setText: function(el)
{
var sign = el.childNodes[0];
for (var i = 0; i < 2; ++i) {
if (sign.nodeType == 3)
break;
sign = sign.childNodes[0];
}
if (el.readAttribute('isExpanded')) {
sign.nodeValue = sign.nodeValue.replace(/\+|\-/, '-');
}
else {
sign.nodeValue = sign.nodeValue.replace(/\+|\-/, '+');
}
},
getDynamicElementId: function(el)
{
return el.id.substr(1);
},
calcInitialState: function(el)
{
var hasNonEmptyField = false;
if (el.readAttribute('isExpanded') === null) {
var dynEl = $(this.getDynamicElementId(el));
var els = [];
els[0] = dynEl.getElementsBySelector('[type="text"]');
els[1] = dynEl.getElementsByTagName('textarea');
for (var i = 0; i < els.length; ++i) {
for (var ii = 0; ii < els[i].length; ++ii) {
if (els[i][ii].value != '') {
hasNonEmptyField = true;
break;
}
}
}
}
else if (el.readAttribute('isExpanded') === '0')
return;
if (el.readAttribute('isExpanded') || hasNonEmptyField) {
/*
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);// wow! 15!
el.getElementsByTagName('a')[0].dispatchEvent(evt);
*/
el.getElementsByTagName('a')[0].fire('MouseEvents:click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
}
}
}
var El =
{
maxChildIteratorDepth:5,
maxFields: 4,
fieldsCnt: {},
clone: function(srcId, beforeElId, callBack)
{
if (typeof(El.fieldsCnt[srcId]) == 'undefined')
El.fieldsCnt[srcId] = 1;
if (El.fieldsCnt[srcId] >= El.maxFields) {
return false;
}
++El.fieldsCnt[srcId];
var el = $(srcId);
var node = el.cloneNode(true);
if (!Prototype.Browser.IE)
delete(node.id);
node.id = '';
El.clearValues(node);
if (callBack) {
callBack(node, el, beforeElId);
}
var newNode = el.parentNode.insertBefore(node, $(beforeElId));
return newNode;
},
clearValues: function(el)
{
El.clear(el.getElementsBySelector('input[type="text"]'));
El.clear(el.getElementsByTagName('textarea'));
El.clear(el.getElementsByTagName('select'));
},
clear: function(els)
{
for (var i = 0; i < els.length; ++i) {
//els[i].value = els[i].defaultValue;
if (els[i].tagName.toUpperCase() == 'SELECT')
els[i].selectedIndex = 0;
else
els[i].value = '';
}
},
remove: function(el, srcId)
{
el.parentNode.removeChild(el);
--El.fieldsCnt[srcId];
},
getParentTag: function(el, tagName)
{
tagName = tagName.toUpperCase();
for (var i = 0; i < 50; ++i) {
el = el.parentNode;
if (el.nodeType == 1 && el.tagName == tagName)
return el;
}
return false;
},
getChildsByAttribute: function(el, attribute, attributeValue, deep)
{
if (!deep)
deep = 0;
var childs = el.childNodes;
var ret = [];
for (var i = 0; i < childs.length; ++i) {
if (childs[i].nodeType != 1)
continue;
if (childs[i].hasAttribute(attribute) && childs[i].getAttribute(attribute) == attributeValue) {
ret.push(childs[i]);
}
if (childs[i].hasChildNodes() && deep < El.maxChildIteratorDepth && childs[i].tagName != 'SELECT')
ret = ret.concat(El.getChildsByAttribute(childs[i], attribute, attributeValue, deep + 1));
}
return ret;
}
}
var locationParamReplace = function(paramName, value)
{
var loc = window.location.search;
if (loc) {
var re = new RegExp("((\\?|&)" + paramName + "=)([^&]*)");
if (re.test(loc))
loc = loc.replace(re, "$1" + value);
else
loc += "&" + paramName + "=" + value;
}
else {
loc = "?" + paramName + "=" + value;
}
window.location.search = loc;
}
function removeLinkItem(reload)
{
try {
$('cancel_link').style.display = 'none';
$('link_item_notice').style.display = 'none';
}
catch (e) {
}
linked_item_info = {id: '', s: ''};
if (typeof(reload) != 'undefined' && reload) {
window.location.href = '/search.php';
}
return false;
}
var MessageBox = {
show: function(msg)
{
// dirty hack
if (!$('_lvContent')) {
var d = document.createElement('div');
d.id = '_lvContent';
d.style.display = 'none';
document.body.appendChild(d);
}
$('_lvContent').innerHTML = msg;
Lightview.show({
href: '_lvContent',
rel: 'inline',
options: {
title: 'results',
menubar: true,
topclose: false,
autosize: false,
width: 200,
height: 50
}
});
return true;
},
close: function()
{
Lightview.hide();
}
}
var ExpandCollapseSimple = function(targetEl)
{
if (targetEl.visible())
targetEl.hide();
else
targetEl.show();
}
var Track =
{
ids: {},
init: function(id, track)
{
Track.ids[id] = track;
Track.processDesc(id, track);
},
process: function(id, track, type)
{
if (!signedInUser())
return false;
var el = $(id);
Track.ids[id] = track;
var success = false;
new Ajax.Request('/utils/ajax.php?m=track&v=' + el.value +'&subscribe=' + Track.ids[id] + '&type=' + type, {method: 'post', asynchronous: false
, onSuccess: function() { success = true; } });
if (success) {
Track.processDesc(id, Track.ids[id]);
return true;
}
else {
Track.ids[id] = !track;
return false;
}
},
processDesc: function(id, isChecked)
{
var elName = id + 'Desc';
if (isChecked) {
$(elName).getElementsBySelector('[name="on"]')[0].show();
$(elName).getElementsBySelector('[name="off"]')[0].hide();
}
else {
$(elName).getElementsBySelector('[name="on"]')[0].hide();
$(elName).getElementsBySelector('[name="off"]')[0].show();
}
}
}
var notImplementedYet = function()
{
alert('Not implemented yet');
}
var prev_type = contacts = '';
function showInfo(type)
{
if (prev_type == type)
showHideEl('info_pane');
else {
$('info_pane').style.display = '';
}
prev_type = type;
if (type == 'address')
$('info_pane').innerHTML = $(type).innerHTML;
else {
if (contacts.length == 0) {
var containers = ['phones', 'urls', 'emails'];
for (var i = 0; i < containers.length; ++i) {
contacts += $(containers[i]).innerHTML;
}
}
$('info_pane').innerHTML = contacts;
}
}
var $radio = function(el)
{
for (var i = 0; i < el.length; ++i) {
if (el[i].checked || el[i].selected)
return el[i].value;
}
return null;
}
var Search = {
init: function()
{
/*
$$('form[action="/search.php"]').each( function(el) { Event.observe(el, 'submit', Search.send.bindAsEventListener(Search)); } ); // prototype 1.6.0 - doesn't work in Opera9
*/
var df = document.forms;
for (var i = 0; i < df.length; ++i) {
if (df[i].action.search(/\/search\.php/) != -1) {
Event.observe(df[i], 'submit', Search.send.bindAsEventListener(Search));
}
}
},
send: function(event)
{ /*
var uri = '';
var f = Event.element(event);
var ss = f.s.value.strip();
ss = ss.toLowerCase();
ss = ss.replace(/[^a-z\d_]+/g, '-');
ss = encodeURIComponent(ss);
if (typeof(f['item_id[]']) != 'undefined')
return true;// νε-νε-νε!
if (typeof(f.item_id) != 'undefined' && f.item_link_name)
uri = '/' + encodeURIComponent(f.item_link_name) + '/similar';
else
uri = '/' + ss;
var t;
if (t = removeEmptyFormElements(f)) {
if (uri.charAt(uri.length - 1) != '/')
uri += '/';
uri += '?' + t;
}
*/
window.location.href = uri;
Event.stop(event);
}
}
var removeEmptyFormElements = function(f)
{
var uri = '';
for (var i = 0; i < f.elements.length; ++i) {
var el = f.elements[i];
if ((el.tagName == 'INPUT' && (el.value == '' || el.type == 'submit'))
|| (el.tagName == 'SELECT' && ((el.name == 'sort_order' && el.options[el.selectedIndex].value == 'editor')
|| el.options[el.selectedIndex].value == '')) || el.name == 's') {
continue;
}
uri += el.name + '=' + encodeURIComponent($F(el)) + '&';
}
return uri;
}
var DefaultValues = {
init: function()
{
$$('[defVal]').each( function(el) {
el.value = $(el).readAttribute('defVal');
Event.observe(el, 'focus', DefaultValues.onFocus.bindAsEventListener(window));
Event.observe(el, 'blur', DefaultValues.onBlur.bindAsEventListener(window));
} );
},
onFocus: function(evt)
{
var el = Event.element(evt);
if (el.value == el.readAttribute('defVal'))
el.value = '';
},
onBlur: function(evt)
{
var el = Event.element(evt);
if (el.value == '')
el.value = el.readAttribute('defVal');
}
}
var signedInUser = function()
{
if (parseInt(UserId)) {
return true;
}
Event.observe($('loginLVForm').select('form')[0], 'submit', doLogin.bindAsEventListener(window));
Lightview.show({
href: 'loginLVForm',
rel: 'inline',
options: {
autosize: true,
topclose: true
}
});
return false;
//window.location.href = '/login.php?ret=' + encodeURIComponent(window.location.href);
}
var doLogin = function(ev)
{
if (ev)
Event.stop(ev);
new Ajax.Request('/utils/ajax.php?m=login', {
onSuccess: loginCallback
, method: 'post', parameters: $('loginLVForm').select('form')[0].serialize(true)
, evalJS: false, evalJSON : false
});
}
var loginCallback = function(req)
{
if (!req.responseText.length || req.responseText == '0') {
$('loginLVForm').select('div[name="messageBox"]')[0].show();
Lightview.updateViews();
}
else {
eval(req.responseText);
if (!USER.id) {
$('loginLVForm').select('div[name="messageBox"]')[0].setStyle({visibility: 'visible'});
Lightview.updateViews();
return false;
}
window.UserId = parseInt(USER.id);
window.UserItemId = parseInt(USER.item_id);
if (Linker.prototype.linkType && !window.Linker.prototype.mainObjId) {
window.Linker.prototype.mainObjId = USER.item_id;
}
$$('a[ttip="1"]').each(window.linkTip);
Lightview.hide();
setTimeout(function() { Lightview.show({
href: 'signedSuccessfully',
rel: 'inline',
options: {
autosize: true,
topclose: true
}
}); }, 800);
setTimeout(function() { Lightview.hide(); }, 6000);
}
}
var createLinkLB = function(linkEl)
{
if (!signedInUser())
return false;
if (typeof(linkEl.href) != 'undefined')
window.location.href = linkEl.href;
else {
window.location.href = linkEl;
}
return false;
/*
Lightview.show({
href: '/utils/ajax.php?m=create_link_lb&v=' + linkEl.href,
rel: 'ajax',
title: 'Create link',
caption: 'capTION',
options: {
autosize: true,
topclose: true,
ajax: {
method: 'get',
onComplete: function(){ $('name').focus(); }
}
}
});
return false;
*/
}
function deleteObject(obj_type, id, user_id, kws)
{
if (!(id = parseInt(id))) {
alert('Error: unknown id');
return false;
}
if (obj_type != 'user_kw_association_data' && obj_type != 'user_association_data') {
var ret = window.confirm('Are you sure you want to delete "' + obj_type + ' #' + id + '"?');
}
else {
var ret = window.confirm('Are you sure you want to delete this association?');
}
if (typeof(user_id) == 'undefined')
user_id = '';
if (typeof(kws) == 'undefined')
kws = '';
if (ret) {
window.location = '/backend/delete.php?obj_type=' + obj_type + '&id=' + id + '&user_id='+ user_id + '&keywords=' + kws + '&ret=' + encodeURIComponent(window.location.href);
return true;
}
return false;
}
function createCheckBox(labelText, attrs)
{
var chk = document.createElement("INPUT");
for (var i in attrs) {
chk[i] = attrs[i];
}
if (!attrs.type)
chk.setAttribute('type', 'checkbox');
var l = document.createElement('label');
l.appendChild(chk);
l.appendChild(document.createTextNode(' ' + labelText));
return l;
}
function setSelectValue(el, val)
{
el.selectedIndex = 0;
for (var i = 0; i < el.options.length; ++i) {
if (el.options[i].value == val) {
el.selectedIndex = i;
break;
}
}
}
/*
function createRadioGroup(labelTexts, name, values, attrs, delimiter)
{
var op, l;
for (var i = 0; i < labelTexts.length; ++i) {
opt = document.createElement('input');
opt.type = 'radio';
opt.name = name;
opt.value = values[i];
l = document.createElement('label');
l.appendChild(chk);
l.appendChild(document.createTextNode(labelTexts[i]));
}
}*/
function createSelectBox(name, values, selected, params)
{
var e = document.createElement('select');
e.name = name;
if (params) {
Object.extend(e, params);
}
for (var i in values) {
var opt = document.createElement('option');
opt.value = i;
opt.text = values[i];
if (typeof(selected) != 'undefined' && i == selected)
opt.selected = true;
selAdd(opt, e, null);
}
return e;
}
function createAutoCompleteField(fieldName, ajaxURI, acOptions)
{
if (!acOptions)
acOptions = {};
var options = {
paramName: acOptions.paramName || 'v',
minChars: acOptions.minChars || 3,
frequency: acOptions.frequency || 0.6,
inheritWidth: acOptions.inheritWidth || false,
setWidth: acOptions.setWidth || false
};
var h;
var div = document.createElement('div');
div.setStyle({display: 'inline'});
var input = document.createElement('input');
input.type = 'text';
input.name = fieldName;
div.appendChild(input);
if (fieldName[0] == '_') {
h = document.createElement('input');
h.type = 'hidden';
h.name = fieldName.substr(1);
div.appendChild(h);
if (!options.afterUpdateElement) {
// =-0
options.afterUpdateElement = autoCompleteOnAfterUpdate;
}
}
var acDiv = document.createElement('div');
acDiv.name = fieldName + 'Choices';
acDiv.className = 'autocomplete';
div.appendChild(acDiv);
// without progress indicator
new Ajax.Autocompleter(input, acDiv, ajaxURI, options);
return div;
}
function autoCompleteOnAfterUpdate(textField, li) {
textField.up('div').select('input[name="' + textField.name.substr(1) + '"]')[0].value = li.readAttribute('itemId');
};
// "1 click" associations
var LinkerStatic = function(caller, itemId, rootCatId, totalVotes, itemName, isVoted, descriptions, link)
{
var t;
this.isProccessing = false;
this.itemId = itemId;
this.rootCatId = rootCatId;
this.caller = caller;
this.isVoted = isVoted;
//this.contentDiv = $('linkerForm');
if (descriptions) {
this.descriptions = descriptions;
if (descriptions[0].flag)
this.flag = descriptions[0].flag.split(",");
else
this.flag = [];
}
else {
Linker.prototype.clearDescription.apply(this);
this.flag = [];
}
this.totalVotes = parseInt(totalVotes);
this.itemName = itemName;
this.link = link;
}
LinkerStatic.prototype.edit = function(isAdding)
{
this.contentDiv = $('linkerForm');
if (!signedInUser())
return false;
Element.update(this.contentDiv.select('div[name="hidden"]')[0]);
//this.contentDiv.show();
var cnt = 0;
var t;
if (isAdding && this.descriptions.length > 1)
var limit = 1;
else
var limit = this.descriptions.length;
for (var y = 0; y < limit; ++y) {
var adId = typeof(this.descriptions[y]['adId']) != 'undefined' && !isAdding && this.descriptions[y]['adId'] ? this.descriptions[y]['adId'] : 0;
var h = document.createElement('input');
h.setAttribute('type', 'hidden');
h.setAttribute('name', 'associationId[]');
h.setAttribute('value', this.descriptions[y]['associationId'] ? this.descriptions[y]['associationId'] : 0);
Element.insert(this.contentDiv.select('div[name="hidden"]')[0], h);
if (this.linkType != 'items') {
var arr = '[' + adId + '][' + this.descriptions[y]['name'] + ']';
}
else {
var arr = '[' + adId + '][]';
}
t = this.contentDiv.select('select[name^="showTo"]')[0];
t.name = 'showTo' + arr;
setSelectValue(t, this.descriptions[y]['visibility']);
try {
this.contentDiv.select('input[name^="file"]')[0].name = 'file' + arr;
}
catch (e) {}
var ta = this.contentDiv.select('textarea')[0];
ta.name = 'description' + arr;
if (!isAdding && this.descriptions[y]['editable_description']) {
ta.value = this.descriptions[y]['editable_description'];
}
else {
ta.value = '';
}
var mask, i;
if (!y && Linker.prototype.linkType == 'items' && (mask = Linker.prototype.getFlagMask.call(this, Linker.prototype.mainObjRootCatId, this.rootCatId))) {
//Linker.prototype.createFlags.call(this, this.contentDiv.select('div.flags')[0]);
var el = this.contentDiv.select('div[name="flags"]')[0];
el.show();
$("flags").show();
el.update();
var mask = Linker.prototype.getFlagMask(Linker.prototype.mainObjRootCatId, this.rootCatId);
for (i in Linker.prototype.flagsDescriptions[mask]) {
if (i == 'attending') {
if (!this.ableTo('attend'))
continue;
}
el.appendChild(createCheckBox(Linker.prototype.flagsDescriptions[mask][i]
, {name: 'flag[]', value: i, checked: (arraySearch(i, this.flag) != -1)}));
}
}
}
return true;
}
LinkerStatic.prototype.del = function()
{
if (!Linker.prototype.confirmDel())
return false;
this.contentDiv = $('linkerForm');
var h = document.createElement('input');
h.setAttribute('type', 'hidden');
h.setAttribute('name', 'act');
h.setAttribute('value', 'delete');
Element.insert(this.contentDiv.select('div[name="hidden"]')[0], h);
this.contentDiv.select('form')[0].submit();
}
var linkerInitData = {};
var linkerInit = function(caller, itemId, rootCatId, totalVotes, itemName, isVoted, descriptions, link)
{
linkerInitData[itemId] = arguments;
}
var Linker = function(caller, itemId, rootCatId, totalVotes, itemName, isVoted, descriptions, link)
{
var t;
this.isAttendingBox = false;
this.isProccessing = false;
this.itemId = itemId;
this.rootCatId = rootCatId;
this.caller = caller;
this.isVoted = isVoted;
if (descriptions) {
this.descriptions = descriptions;
if (descriptions[0].flag)
this.flag = descriptions[0].flag.split(",");
else
this.flag = [];
}
else {
this.clearDescription();
this.flag = [];
}
this.totalVotes = parseInt(totalVotes) ? parseInt(totalVotes) : 0;
this.itemName = itemName;
this.ajaxQS = 'm=links&v[]=' + itemId + '&'
+ (this.linkType == 'items' ? ('v[]=' + this.mainObjId) : ('ss=' + this.mainObjName + '&linkType=keywords'));
this.link = link;
if ($('linkerTip_' + itemId)) {
this.contentDiv = $('linkerTip_' + itemId);
return true;
}
if (!this.boxType) {
this.contentDiv = $('linkTipSrc').cloneNode(true);
this.contentDiv.writeAttribute('id', 'linkerTip_' + itemId);
this.contentDiv = $('linkerTipsContainer').appendChild(this.contentDiv);
}
else {
this.contentDiv = $('linkerForm');
}
// fill out it
try {
//this.contentDiv.select('[name="assCount"]')[0].update(this.totalVotes);
//this.contentDiv.select('[name="item0"]')[0].update(this.itemName);
//this.contentDiv.select('[name="item1"]')[0].update(this.mainObjName);
}
catch (e) {}
var dummy = this;
this.contentDiv.select('input[type="radio"]').each( function(el) {
Event.observe(el, 'click', Linker.prototype.reconnectOptions.bindAsEventListener(dummy, true));
} ); // reconnect options
//this.contentDiv = this.caller.insertBefore(this.contentDiv, this.caller.lastChild);
// /utils/ajax.php?m=search_item_name
this.contentDiv.select('div[name="reconnectFields"] input').each( function(el) {
new Ajax.Autocompleter(el, $(el.name + 'Choices'), '/utils/ajax.php?m=search_item_name',
{paramName: 'v', minChars: 3, frequency: 0.6, inheritWidth: false, setWidth: false}
);
});
if (t = this.contentDiv.select('a[title="addDetail"]')[0]) {
Event.observe(t, 'click', this.edit.bindAsEventListener(this, true));
Event.observe(this.contentDiv.select('a[title="edit"]')[0], 'click', this.edit.bindAsEventListener(this));
Event.observe(this.contentDiv.select('a[title="links"]')[0], 'click', this.linksList.bindAsEventListener(this));
Event.observe(this.contentDiv.select('a[title="save"]')[0], 'click', this.save.bindAsEventListener(this));
Event.observe(this.contentDiv.select('[class="delete"]')[0], 'click', this.del.bindAsEventListener(this));
}
if ((this.mainObjId == window.UserItemId && arraySearch(this.rootCatId, Linker.prototype.attendingCategories) != -1)
|| (this.itemId == window.UserItemId
&& arraySearch(Linker.prototype.mainObjRootCatId, Linker.prototype.attendingCategories) != -1)) {
this.isAttendingBox = true;
this.contentDiv.select('a[title="links"]')[0].update("See who's coming");
}
else {
this.isAttendingBox = false;
this.contentDiv.select('a[title="links"]')[0].update("View descriptions");
}
this.updateTextContent();
if (this.isVoted)
this.show();
this.setVoted();
}
Linker.prototype.updateTextContent = function()
{
this.contentDiv.select('[name="assCount"]')[0].update(this.totalVotes);
var tc = this.contentDiv.select('[name="textContent"]')[0];
tc.update();
if (this.isVoted)
tc.insert(', including you,');
if (this.isAttendingBox) {
tc.insert(' will attend');
if (this.mainObjId == window.UserItemId) {
tc.insert(' ' + this.itemName);
}
else {
tc.insert(' ' + this.mainObjName);
}
}
else {
tc.insert(' agree that ' + this.mainObjName + ' is like ' + this.itemName);
}
tc.insert('.');
if (!this.isVoted) {
if (this.isAttendingBox) {
tc.insert(' Will you?');
}
else {
tc.insert(' Do you agree?');
}
}
}
Linker.prototype.setVoted = function()
{
if (!this.isVoted) {
this.contentDiv.select('div[name="descrSrc"]').each( function(el) { el.hide(); } );
var c = this.contentDiv.select('div[name="static"]')[0];
c.update();
c.hide();
this.contentDiv.select('div[name="flags"]')[0].hide();
this.contentDiv.select('[name="linkEdit"]')[0].hide();
if (this.isAttendingBox) {
this.contentDiv.select('a[title="addDetail"]')[0].update('Yes');
}
else {
this.contentDiv.select('a[title="addDetail"]')[0].update('Yes, add my link');
}
}
else {
this.contentDiv.select('[name="linkEdit"]')[0].show();
this.contentDiv.select('a[title="addDetail"]')[0].update('Add details');
}
}
Linker.prototype.linksList = function(ev)
{
ev.stop();
window.location.href = this.link;
}
Linker.prototype.clearDescription = function()
{
if (this.linkType == 'items') {
this.descriptions = [{name: '', description: '', visibility: 'all', flag: ''}];
}
else {
this.descriptions = [];
//var words = this.mainObjName.split(/\W+/g);
var words = [this.mainObjName];
for (var i = 0; i < words.length; ++i) {
this.descriptions.push({name: words[i], description: '', visibility: 'all', flag: ''});
}
}
}
Linker.prototype.add = function(isAdding)
{
this.edit(null, true);
}
Linker.prototype.edit = function(ev, isAdding)
{
if (!signedInUser())
return false;
if (ev && Event.element(ev))
ev.stop();
if (!this.isVoted) {
this.contentDiv.select('[name="addDetail"]')[0].hide();
}
var c = this.contentDiv.select('div[name="static"]')[0].hide();
this.contentDiv.select('div[name="descrSrc"]').each( function(el) { el.show(); } );
var descriptions = this.contentDiv.select('div[name="descrSrc"]');
for (var i = 1; i < descriptions.length; ++i) {
descriptions[i].remove();
}
Element.update(this.contentDiv.select('div[name="hidden"]')[0]);
//this.contentDiv.show();
var cnt = 0;
var t;
if (isAdding && this.descriptions.length > 1)
var limit = 1;
else
var limit = this.descriptions.length;
for (var y = 0; y < limit; ++y) {
if (y > 0) {
var n = this.contentDiv.select('div[name="descrSrc"]')[0].cloneNode(true);
n = this.contentDiv.select('div[name="descrSrc"]')[0].parentNode.insertBefore(n, this.contentDiv.select('div[name="descrSrc"]')[0].nextSibling);
}
else {
var n = this.contentDiv.select('div[name="descrSrc"]')[0];
}
var adId = typeof(this.descriptions[y]['adId']) != 'undefined' && !isAdding && this.descriptions[y]['adId'] ? this.descriptions[y]['adId'] : 0;
var h = document.createElement('input');
h.setAttribute('type', 'hidden');
h.setAttribute('name', 'associationId[]');
h.setAttribute('value', this.descriptions[y]['associationId'] ? this.descriptions[y]['associationId'] : 0);
Element.insert(this.contentDiv.select('div[name="hidden"]')[0], h);
if (this.linkType != 'items') {
var arr = '[' + adId + '][' + this.descriptions[y]['name'] + ']';
}
else {
var arr = '[' + adId + '][]';
}
t = n.select('select[name^="showTo"]')[0];
t.name = 'showTo' + arr;
setSelectValue(t, this.descriptions[y]['visibility']);
try {
this.contentDiv.select('input[name^="file"]')[0].name = 'file' + arr;
}
catch (e) {}
var ta = n.select('textarea')[0];
ta.name = 'description' + arr;
if (!isAdding && this.descriptions[y]['editable_description']) {
ta.value = this.descriptions[y]['editable_description'];
}
else {
ta.value = '';
}
var mask, i;
}
if (this.linkType == 'items' && (mask = this.getFlagMask(this.mainObjRootCatId, this.rootCatId))) {
this.createFlags(this.contentDiv.select('div.flags')[0]);
}
return true;
}
Linker.prototype.show = function(noticeOnly)
{
if (!signedInUser())
return false;
var desc = '';
if (!this.isVoted) {
this.edit();
return;
}
this.contentDiv.select('div[name="descrSrc"]').each( function(el) { el.hide(); } );
var c = this.contentDiv.select('div[name="static"]')[0];
c.update();
for (var y = 0; y < this.descriptions.length; ++y) {
if (!this.descriptions[y]['description'])
continue;
c.insert(this.descriptions[y]['description'] + '