/* Copyright (c) Fotki Inc */

// Copyright (c) Fotki.com 1998-2003
var notOrderedPrint = "uf_not_ordered";
var OrderedPrint = "uf_ordered";
//var OrderedPrint = "http://images.fotki.com/order_print_new-1.gif";
var Furl = window.location.href;
var fotki_hostname2 = location.hostname.match(/fotki\.com$/) ? "fotki.com" : location.hostname;
function CartItemPhoto(qnt) {
this.types = new Array();
this.giftQ = 0;
this.changed = 0;
this.quantity = (qnt ? qnt : 0);
this.is_checked_at_page = (qnt? 1 : 0);
this.switchSel = function(type, idPhoto) {
this.changed = 1;
if (this.types[type] == 1) {
this.types[type] = 0;
this.is_checked_at_page = 0;
if (type != 'photo_print' && this.giftQ > -1) {
this.giftQ--;
if (this.giftQ == 0) {
document.getElementsByName('gift'+idPhoto)[0].src = notOrderedPrint;
}}
Core.switchClassNames(idPhoto,OrderedPrint,notOrderedPrint);
try {
chint.quickHide();
CartHint_items["quantity"] = (CartHint_items["quantity"] - (this.quantity ? this.quantity : 1));
if (CartHint_items["quantity"] < 1) Core.setClassName("shopping_cart", "shoppingcartempty");
} catch (ex) {
//alert("cart2_fcart: "+ex);
return;
}} else {
this.types[type] = 1;
this.quantity = (this.quantity?this.quantity:1);
this.is_checked_at_page = 1;
if (type != 'photo_print') {
this.giftQ++;
document.getElementsByName('gift'+idPhoto)[0].src = OrderedPrint;
}
Core.switchClassNames(idPhoto,notOrderedPrint,OrderedPrint);
//order_animation(idPhoto);
try {
chint.quickHide();
if (CartHint_items["quantity"] == 0) Core.setClassName("shopping_cart", "shoppingcart");
CartHint_items["quantity"] = CartHint_items["quantity"] + 1;
} catch (ex) {
//alert("cart2_fcart: "+ex);
return;
}}
}
this.getSelect = function(type) {
return this.types[type];
}
this.addSelect = function(type) {
this.types[type] = 1;
if (type != "photo_print") {
this.giftQ++;
}}
}
function PageCartItemPhotos() {
this.photos = new Array();
this.getPhoto = function(id) {
return this.photos[id];
}
this.switchPhotoItem = function(idPhoto, type) {
this.photos[idPhoto].switchSel(type, idPhoto);
this.generateCookie();
}
this.setSelect = function(idPhoto, type) {
this.photos[idPhoto].addSelect(type);
if (type == 'photo_print') {
Core.switchClassNames(idPhoto,OrderedPrint,notOrderedPrint);
} else {
document.getElementsByName('gift'+idPhoto)[0].src = OrderedPrint;
}}
this.setCookie = function(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}
this.generateCookie = function () {
var expiredate = new Date();
expiredate.setTime(expiredate.getTime() + 14 * 24 * 60 * 60 * 1000);
var c = getCookie("fcart2") || '';
var addToCart = "";
for (i in this.photos) {
if (this.photos[i].changed > 0) {
var indexof = c.indexOf(i);
if (indexof != -1) {
var indexofend = c.indexOf('*', indexof);
c = c.substring(0, indexof) + c.substring(indexofend+1);
}
addToCart += i;
for (k in this.photos[i].types) {
addToCart += "," + k + "-" + this.photos[i].types[k];
}
addToCart += '*';
}}
addToCart = c + addToCart;
this.setCookie("fcart2",addToCart,expiredate,'/','.'+fotki_hostname2);
}}
var page = new PageCartItemPhotos();

// Modal Dialog Box functions
addAlbumDialog = function addAlbumDialog(link) {
// Addition to html document DIV of dialog box container ...
if(Core.getElementU('add_album_dialog') == null){
if(!addAlbumDialog.box){
addAlbumDialog.box = document.createElement("div");
addAlbumDialog.box.setAttribute("id", "add_album_dialog");
addAlbumDialog.box.setAttribute("style", "display: none;");
}
document.getElementsByTagName("body")[0].appendChild(addAlbumDialog.box);
} // ... eoc
advAJAX.post({
cmd : "add_album_to_cart",
url : ''+document.location+link,
onLoading: function(obj) {
var load_str = "<center><img src=http://images.fotki.com/progress.gif> <span class='text2b black'>Loading...</span></center>";
Core.flushElementCache();
if(!addAlbumDialog.dialog) {
addAlbumDialog.dialog = new ModalDialog('add_album_dialog');
}
addAlbumDialog.dialog.show();
addAlbumDialog.dialog.setContent(load_str);
},
onSuccess : function(obj) {
if(addAlbumDialog.dialog != null && obj.responseText != 'error') {
addAlbumDialog.dialog.setContent(obj.responseText);
} else {
var err_tpl = "<span class='text3'>You cannot add this album to the shopping cart.</span><br><br><div align='right'><button onclick='javascript:closeAddAlbumDialog();'>Close</button></div>";
addAlbumDialog.dialog.setContent(err_tpl);
}},
onError : function(obj) {
alert('System error. Please reload this page (<F5>).');
}});
}
closeAddAlbumDialog = function closeAddAlbumDialog (action) {
if(addAlbumDialog.dialog != null) {
addAlbumDialog.dialog.hide();
switch(action) {
case 'gotoalbum':
_setPhotoQuantity();
_setAllPrintOrders();
break;
default:
_setPhotoQuantity();
break;
};
AddAlbum.descructor();
}}
function _setAllPrintOrders(type) {
var OrderedPrint = "http://images.fotki.com/order_print_new-1.gif";
var notOrderedPrint = "http://images.fotki.com/pixel.gif";
type = type ? type : 'photo_print';
try {
if(page.photos) {
for(var idPhoto in page.photos) {
page.photos[idPhoto].types[type] = 1;
page.photos[idPhoto].is_checked_at_page = 1;
var obj = document.getElementsByName(type+idPhoto)[0];
if(obj) {
obj.src = OrderedPrint;
}}
}}
catch (ex) {
return;
}}
function _getOrderedPhotoCount(type){
type = type ? type : 'photo_print';
var count = 0;
try {
if(page) {
for(var idPhoto in page.photos) {
if(document.getElementsByName(type+idPhoto)[0] && page.photos[idPhoto].types[type] == 1){
count++;
}}
}}
catch (ex) {
return 0;
}
return count;
}
function _setPhotoQuantity () {
try {
if(page) {
for(var idPhoto in page.photos) {
if(page.photos[idPhoto]){
var q = parseInt(page.photos[idPhoto].quantity);
var v = parseInt(AddAlbum.value["factor"]);
page.photos[idPhoto].quantity = (page.photos[idPhoto].is_checked_at_page ? q : v);
}}
}}
catch (ex) {
return 0;
}}
//----------------
addAlbumToCart = function addAlbumToCart(path, el_name, form_name, to_back){
form_name = form_name ? form_name : "add_album";
el_name = el_name ? el_name : "clear";
var form = Core.getElementU(form_name);
var radio_el;
var pr_format = pr_paper = "";
var btn_1, btn_2;
for(var i = 0; i < form.elements.length; i++) {
radio_el = form.elements[i];
if(radio_el.name == "format" && radio_el.checked == true) {
pr_format = radio_el.value;
} else if(radio_el.name == "paper" && radio_el.checked == true) {
pr_paper = radio_el.value;
}
if(pr_format && pr_paper) break;
}
advAJAX.post({
cmd		: "addalbum",
url		: path,
f_back	: (to_back ? '1' : '0'),
clear		: (Core.getElementU(el_name).checked == true ? "1" : "0"),
format	: pr_format || "size4x6_1",
paper		: pr_paper || "glossy",
timeout : (1000 * 30),
onTimeout : function () {
addAlbumDialog.dialog.setContent2("addalbum_progress", "");
alert("Connection timed out. Pleace try again later.");
if (btn_1 = Core.getElementU("addandgotocart_button")) btn_1.disabled = false;
if (btn_2 = Core.getElementU("addandgotoalbum_button")) btn_2.disabled = false;
closeAddAlbumDialog('gotoalbum');
},
onLoading : function(obj){
addAlbumDialog.dialog.setContent2("addalbum_progress", "<img src=http://images.fotki.com/progress.gif>");
if (btn_1 = Core.getElementU("addandgotocart_button")) btn_1.disabled = true;
if (btn_2 = Core.getElementU("addandgotoalbum_button")) btn_2.disabled = true;
},
onSuccess : function(obj){
var response = obj.responseText.split("|");
addAlbumDialog.dialog.setContent2("addalbum_progress", "");
if (btn_1 = Core.getElementU("addandgotocart_button")) btn_1.disabled = false;
if (btn_2 = Core.getElementU("addandgotoalbum_button")) btn_2.disabled = false;
if (response[0] == "ok") {
try {
if(to_back) {
CHint.setQuantity(response[1]);
closeAddAlbumDialog('gotoalbum');
} else {
document.location = response[1];
Core.flushElementCache();
var load_str = "<center><img src=http://images.fotki.com/progress.gif> <span class='text2b black'>Loading...</span></center>";
addAlbumDialog.dialog.setContent(load_str);
Core.addEvent(window, 'unload', closeAddAlbumDialog);
}} catch (ex) {
try {
closeAddAlbumDialog('gotoalbum');
} catch(ex) {
return;
}}
} else {
alert('System error.');
closeAddAlbumDialog();
}
return true;
},
onError : function(obj) {
if (btn_1 = Core.getElementU("addandgotocart_button")) btn_1.disabled = false;
if (btn_2 = Core.getElementU("addandgotoalbum_button")) btn_2.disabled = false;
addAlbumDialog.dialog.setContent2("addalbum_progress", "");
alert('System error. Please reload this page (<F5>).');
}});
}
function _clearChecked(e) {
if (e != null) {
var el = (typeof(e) == 'object') ? e : Core.getElementU(e);
}
if(typeof(e) == 'object') {
if(el.checked) {
Core.hideElement('cartinfo');
Core.hideElement('totalinfo');
} else {
Core.showElement('cartinfo');
Core.showElement('totalinfo');
}} else {
if(el.checked) {
el.checked = false;
Core.showElement('cartinfo');
Core.showElement('totalinfo');
} else {
el.checked = true;
Core.hideElement('cartinfo');
Core.hideElement('totalinfo');
}}
}
// require global obj of the price
//------------------------------------------------
AddAlbum = function(){}
AddAlbum.init_data = null;
AddAlbum.value = { "format":"size4x6_glossy", "paper":"glossy", "factor":1};
AddAlbum.price = null;
AddAlbum.descructor = function () {
AddAlbum.init_data = null;
AddAlbum.value = { "format":"size4x6_glossy", "paper":"glossy", "factor":1};
AddAlbum.price = null;
}
AddAlbum.calc = function(el, price){
if(AddAlbum.price == null) {
if(!price || price == null){
AddAlbum.price = { "size4x5_glossy":0.09, "size4x5_matte":0.09, "size4x6_glossy":0.09, "size4x6_matte":0.09, "size5x7_glossy":0.40, "size5x7_matte":0.40, "size8x10_glossy":1.50, "size8x10_matte":1.50, "size3x5_glossy":0.09, "size3x5_matte":0.09};
} else {
AddAlbum.price = price;
}}
if(AddAlbum.value == null) {
AddAlbum.value = { "format":"size4x6_glossy", "paper":"glossy", "factor":1};
}
if(AddAlbum.init_data == null) {
var data = new Object();
data["cartquantity"] = Core.getText("cartquantity");
data["albumquantity"] = Core.getText("albumquantity");
data["cartsum"] = Core.getText("cartsum");
if(data["cartsum"].indexOf("$") != -1) {
data["cartsum"] = data["cartsum"].substr(data["cartsum"].indexOf("$")+1);
}
//		if(data["albumsum"].indexOf("$") != -1) {
//}
AddAlbum.init_data = data;
} // end of init
if(el.name == "format") {
var mass = el.value.split("_");
AddAlbum.value["format"] = mass[0]+"_"+AddAlbum.value["paper"];
AddAlbum.value["factor"] = mass[1];
} else if(el.name == "paper") {
var mass = AddAlbum.value["format"].split("_");
AddAlbum.value["paper"] = el.value;
AddAlbum.value["format"] = mass[0]+"_"+el.value;
}
var album_quantity = AddAlbum.value["factor"] * AddAlbum.init_data["albumquantity"];
var total_quantity = album_quantity*1 + AddAlbum.init_data["cartquantity"]*1;
var album_sum = album_quantity * AddAlbum.price[AddAlbum.value["format"]];
var total_sum = album_sum*1 + AddAlbum.init_data["cartsum"]*1;
Core.setText("albumquantity", album_quantity);
Core.setText("totalquantity", total_quantity);
Core.setText("albumsum", "$"+Core.formatMoney(album_sum));
Core.setText("totalsum", "$"+Core.formatMoney(total_sum));
}

var DialogInviteLoading = null;
var DialogInviteForm = null;
var DialogInviteSending = null;
var DialogInviteComplete = null;
var iv_ssid = null;
var iv_key = null;
var member = true;
function AlbumInvite() {
advAJAX.post({
"cmd"     : "invite_album",
onLoading: function(obj) {
if (!DialogInviteForm) {
DialogInviteForm = new ModalDialog('album_invite_form');
}
DialogInviteForm.setContent('<center><img src=http://images.fotki.com/progress.gif> <span class=\"text2b black\">Loading...</span></center>');
//Core.flushElementCache();
setTimeout('DialogInviteForm.show();', 20);
},
onSuccess : function(obj) {
var response = obj.responseText.split("||");
DialogInviteForm.setContent(response[0]);
eval(response[1]);
}});
}
function addemail(email) {
document.emailform.to.focus();
if (document.emailform.to.value == 0) {
document.emailform.to.value = email;
} else {
var index = document.emailform.to.value.indexOf("," + email);
if (index == -1){
index = document.emailform.to.value.indexOf(", " + email);
}
if (index == -1) {
document.emailform.to.value=document.emailform.to.value+', '+email;
} else {
var regexp = new RegExp("," + email);
var regexp2 = new RegExp("," +email);
var regexp3 = new RegExp(", "+email);
document.emailform.to.value = document.emailform.to.value.replace(regexp3, "");
document.emailform.to.value = document.emailform.to.value.replace(regexp, "");
document.emailform.to.value = document.emailform.to.value.replace(regexp2, "");
}}
}
function checkEmailRun() {
Core.setText('email_error', "");
Core.setText('message_error', "");
var check1 = checkEmails('field_to');
var check2 = checkEmails('email_from');
if (check1) { // if error
Core.setText('email_error', "Wrong email address format.");
} else if (check2){
Core.setText('from_error', "Wrong email address format.");
} else if (!(Core.getText('field_to'))) {
Core.setText('email_error', "Please specify email address.");
} else if (!(Core.getText('user_name'))) {
Core.setText('from_error', "Please specify your name.");
} else if (!(Core.getText('email_from'))) {
Core.setText('from_error', "Please specify your email address.");
} else if (!(Core.getText('message_text'))) {
Core.setText('message_error', "Please type your text.");
} else {
sendEmail();
}}
function checkEmails(field){
var txt = Core.getText(field); //specify the id of textarea
var e_regexp = new RegExp("^([A-Za-z0-9\-\_\.])+@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,4}$");
var error = 0; // by default we have no error
txt = txt.replace(/\n/g, "");
txt = txt.replace(/\r/g, "");
txt = txt.replace(/ /g, "");
var matches = txt.split(",");
for (var i = 0; i < matches.length; i++) {
if (matches[i]) {
var email = matches[i];
if (!email.match(e_regexp)) { // if didn`t match - error is 1
error = 1;
}}
}
return error;
}
var mailservice = 'fotki';
function setServ(type) {
mailservice = type;
}
function encryptForInvite(str, pwd) {
if(pwd == null || pwd.length <= 0) {
alert("Please enter a password with which to encrypt the message.");
return null;
}
var prand = "";
for(var i=0; i<pwd.length; i++) {
prand += pwd.charCodeAt(i).toString();
}
var sPos = Math.floor(prand.length / 5);
var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));
var incr = Math.ceil(pwd.length / 2);
var modu = Math.pow(2, 31) - 1;
if(mult < 2) {
alert("Algorithm cannot find a suitable hash. Please choose a different password. \nPossible considerations are to choose a more complex or longer password.");
return null;
}
var salt = Math.round(Math.random() * 1000000000) % 100000000;
prand += salt;
while(prand.length > 10) {
prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
}
prand = (mult * prand + incr) % modu;
var enc_chr = "";
var enc_str = "";
for(var i=0; i<str.length; i++) {
enc_chr = parseInt(str.charCodeAt(i) ^ Math.floor((prand / modu) * 255));
if(enc_chr < 16) {
enc_str += "0" + enc_chr.toString(16);
} else enc_str += enc_chr.toString(16);
prand = (mult * prand + incr) % modu;
}
salt = salt.toString(16);
while(salt.length < 8)salt = "0" + salt;
enc_str += salt;
return enc_str;
}
function getContact() {
var login = Core.getText("login");
var password = Core.getText("password");
if (mailservice == 'fotki') {
password = encryptForInvite(password, iv_key);
advAJAX.post({
"login" : login,
"passwd"  : password,
"cmd"     : "get_contact",
"mailservice" : mailservice,
"iv_ssid" : iv_ssid,
timeout : 28900,
onTimeout : function() {
Core.setText('loading', '');
Core.setText('error', 'Connection timed out. Please try again.');
Core.showElement('error');
},
onLoading : function (obj) {
Core.hideElement('error');
Core.setText('error', '');
Core.setText('loading', '<img src=http://images.fotki.com/progress.gif> ');
},
onSuccess : function(obj) {
var n = obj.responseText.indexOf('<!DOCTYPE');
if (n == 0)  {
Core.setText('password', '');
Core.setText('loading', '');
Core.setText('error', 'UserName or Password is incorrect.');
Core.showElement('error');
} else {
Core.hideElement('login_form');
Core.setText('loading', '');
Core.setText('login', '');
Core.setText('password', '');
Core.setText('add_book_' + mailservice, obj.responseText);
}}
});
} else {
password = password;
advAJAX.post({
"login" : login,
"passwd"  : password,
"cmd"     : "get_contact",
"mailservice" : mailservice,
timeout : 28900,
onTimeout : function() {
Core.setText('loading', '');
Core.setText('error', 'Connection timed out. Please try again.');
Core.showElement('error');
},
onLoading : function (obj) {
Core.hideElement('error');
Core.setText('error', '');
Core.setText('loading', '<img src=http://images.fotki.com/progress.gif> ');
},
onSuccess : function(obj) {
var n = obj.responseText.indexOf('Error');
if (n == 0)  {
Core.setText('password', '');
Core.setText('loading', '');
Core.setText('error', obj.responseText.substr(n + 7));
Core.showElement('error');
} else {
Core.hideElement('login_form');
Core.setText('loading', '');
Core.setText('login', '');
Core.setText('password', '');
Core.setText('add_book_' + mailservice, obj.responseText);
}}
});
}}
function sendEmail() {
var display_name = Core.getText('user_name');
var subject_text = display_name + Core.getText("subject_text");
var checkbox = '';
if (Core.getElementU('checkbox')) {
checkbox =  '' + Core.getElementU("checkbox").checked;
}
var pid =  '';
var is_ecard = '';
if (Core.getElementU('is_ecard')){
is_ecard = Core.getText('is_ecard');
}
if (Core.getElementU('pid')) {
pid =  Core.getText("pid");
progress_text = "E-card sending...";
limit_text = "Dayly e-cards limit reached";
complite_text = "E-card sent";
} else {
progress_text = "Sending invitation...";
limit_text = "Daily invitation limit reached";
complite_text = "Invitation sent";
}
advAJAX.post({
"cmd"     : "invite_sendemail",
"to"      : Core.getText("field_to"),
"subject" : subject_text,
"text"    : Core.getText("message_text"),
"checkbox" : checkbox,
"email_from" : Core.getText("email_from"),
"user_name"  : display_name,
"pid"   : pid,
"is_ecard" : is_ecard,
onLoading : function (obj) {
DialogInviteForm.hide();
Core.setText('album_invite_sending', '<center><img src=http://images.fotki.com/progress.gif> <span class=\"text2b black\">'+progress_text+'</span></center>');
DialogInviteSending = new ModalDialog('album_invite_sending');
DialogInviteSending.show();
},
onSuccess : function(obj) {
var n = obj.responseText.indexOf('ERROR');
setTimeout('DialogInviteSending.hide();', 3000);
if (n == 0)  {
Core.setText('album_invite_complete', '<center><span class=\"text2b black\"><img src=http://images.fotki.com/cart/warning.gif>'+limit_text+'</span></center>');
DialogInviteComplete = new ModalDialog('album_invite_complete');
setTimeout('DialogInviteComplete.show();', 3000);
setTimeout('DialogInviteComplete.hide();', 5000);
} else {
Core.setText('album_invite_complete', '<center><img src=http://images.fotki.com/cart/ok.gif> <span class=\"text2b black\">'+complite_text+'</span></center>');
DialogInviteComplete = new ModalDialog('album_invite_complete');
setTimeout('DialogInviteComplete.show();', 3000);
setTimeout('DialogInviteComplete.hide();', 5000);
}}
});
}
function setBg(element, bg) {
element.style.background=bg;
}
function changeMailType(type) {
var mails = ['hotmail', 'yahoo', 'fotki', 'gmail'];
for (var i in mails) {
if (mails[i] == type) {
setServ(type);
Core.setClassName(mails[i] + '_td', 'arrow_' + mails[i]);
if ((mails[i] == "fotki" && !member) || mails[i] != "fotki") {
Core.showElement('login_form');
} else {
Core.hideElement('login_form')
}
Core.showElement("add_book_" + mails[i]);
} else {
Core.setClassName(mails[i] + '_td', '');
Core.hideElement('error', '');
Core.hideElement('add_book_' + mails[i]);
}}
}

function ExpandableDiv() {}
ExpandableDiv.expand = function ExpandableDiv_expandReadMore(more_id) {
Core.setText(more_id, window.more_text[more_id]);
}
ExpandableDiv.onmouseover_bg_color = '#dfe5f4';
ExpandableDiv.onmouseout_bg_color = 'transparent';
ExpandableDiv.default_readmore_text = 'read more...'
ExpandableDiv.init = function ExpandableDiv_inititalizeViewMoreEffect(whole_id, more_id, textarea_container_id, textarea_id, cancel_id, save_id, save_callback) {
if (! window.more_text) {
window.more_text = new Array();
}
var is_editable = (! textarea_container_id ) ? 0 : 1;
var whole_visible_text_id = whole_id + '_text';
window.more_text[more_id] = Core.getText(more_id);
Core.hideElement(more_id);
Core.hideElement(textarea_container_id);
var more_element = Core.getElementU(more_id);
if (more_element) {
var more_link = more_element.getAttribute("title") || ExpandableDiv.default_readmore_text;
Core.setText(more_id, "<a href='javascript:ExpandableDiv.expand(\"" + more_id + "\")' id=\"expand_" + more_id + "\">" + more_link + "</a>");
Core.showElement(more_id);
}
if (! is_editable) {
return;
}
window['ExpandableDiv_showEditField_'+ more_id] = function showEditField (e) {
if (!e) var e = window.event;
var tg = (window.event) ? e.srcElement : e.target;
if (tg.id != ('expand_' + more_id)) {
ExpandableDiv.expand(more_id);
Core.flushElementCache();
var set_text = '';
if (Core.getElementU(whole_visible_text_id) && (Core.getText(more_id) != undefined)) {
set_text = Core.getText(whole_visible_text_id) + Core.getText(more_id);
} else if (Core.getElementU(whole_visible_text_id)) {
set_text = Core.getText(whole_visible_text_id);
} else {
set_text = Core.getText(whole_id);
}
Core.setText(textarea_id, set_text.replace(/<br>/gi,"\n"));
Core.hideElement(whole_id);
Core.showElement(textarea_container_id);
}}
var whole_element = Core.getElementU(whole_id);
Core.addEvent(whole_element, 'click', window['ExpandableDiv_showEditField_'+more_id]);
window['ExpandableDiv_cancelEdit_'+more_id] = function cancelEdit() {
Core.hideElement(textarea_container_id);
Core.showElement(whole_id);
}
var cancel_element = Core.getElementU(cancel_id);
Core.addEvent(cancel_element, 'click', window['ExpandableDiv_cancelEdit_'+more_id]);
window['ExpandableDiv_saveEdit_'+more_id] = function saveEdit() {
var text = Core.getText(textarea_id);
if ((text == '') && (whole_visible_text_id != 'tabsdescr_text')) {
alert('Empty text.'); return;
}
Core.setText(whole_id, text.replace(/\n/gi,"<br>"));
Core.flushElementCache();
window['ExpandableDiv_cancelEdit_'+more_id]();
save_callback(text, whole_id);
}
var save_element = Core.getElementU(save_id);
Core.addEvent(save_element, 'click', window['ExpandableDiv_saveEdit_'+more_id]);
window['ExpandableDiv_onMouseOverEdit_'+more_id] = function () {
Core.setBg(whole_id, ExpandableDiv.onmouseover_bg_color);
}
window['ExpandableDiv_onMouseOutEdit_'+more_id] = function () {
Core.setBg(whole_id,ExpandableDiv.onmouseout_bg_color);
}
Core.addEvent(whole_element, 'mouseover', window['ExpandableDiv_onMouseOverEdit_'+more_id]);
Core.addEvent(whole_element, 'mouseout',  window['ExpandableDiv_onMouseOutEdit_'+more_id]);
window['ExpandableDiv_onKeyPressEdit_'+more_id] = function myonKeyPress(e) {
if (!e) var e = window.event;
var character = e.charCode > 0 ? String.fromCharCode(e.charCode) : null;
var code = e.keyCode;
if (code==27) {
window['ExpandableDiv_cancelEdit_'+more_id]();
return false;
} else if (code==13 && Core.getElementU(textarea_id).tagName == 'INPUT') {
window['ExpandableDiv_saveEdit_'+more_id]();
return false;
}}
Core.getElementU(textarea_id).onkeypress =
function myKeyPress_wrapper(e) {
return window['ExpandableDiv_onKeyPressEdit_'+more_id](e);
}}
function Inputs() {}
Inputs.interactiveEdit = function Inputs_interactiveEdit(element_id,element_edit_area) {
Core.setText(element_edit_area,Core.getText(element_id).replace(/<br>/gi,"\n"));
}
Inputs.interactiveSave = function Inputs_interactiveSave(element_id,element_edit_area,save_command,album_id) {
var typed_message = Core.getText(element_edit_area);
typed_message.replace = (' ', '');
typed_message = typed_message.replace(/\n/g, "");
typed_message = typed_message.replace(/\r/g, "");
typed_message = typed_message.replace(/ /g, "");
if (typed_message.length >= 1 || element_id == 'photoalbum_description') {
advAJAX.post({
cmd:save_command,
new_text:Core.getText(element_edit_area),
aid:album_id,
onLoading: function(obj) {},
onSuccess: function(obj) {
Core.setText(element_id,Core.getText(element_edit_area).replace(/\n/gi,"<br>"));
}});
} else {
alert("Cannot save empty place!");
Core.showElement(element_id);
}
Core.showElement(element_id);
}
var UE_MAX_WIDTH = 100;
var UE_MAX_HEIGHT = 14;
var UE_max_characters = 0xFFFFFFFF;
function uniedit_width( text ) {
var width = 25;
while (text.length>0) {
var lwidth = text.indexOf("\n") + 1;
if ( lwidth == 0 ) { lwidth = text.length}
width = Math.max( width, lwidth );
if (width+1>=UE_MAX_WIDTH) {
return UE_MAX_WIDTH;
}
if ( lwidth == text.length ) {
return width+1;
}
text = text.substring( lwidth , text.length - 1 );
}
return width+1;
}
function uniedit_height( text ) {
var height = 1;
while ( text.length > 0 ) {
if ( height+1 > UE_MAX_HEIGHT ) {
return UE_MAX_HEIGHT;
}
var lwidth = text.indexOf("\n") + 1;
if ( lwidth == 0 ) {
return height+1;
}
if ( lwidth == text.length ) {
return ( height+1 );
}
text = text.substring( lwidth , text.length - 1 );
height++;
}
return height+1;
}
function uniedit_checklen( edit_area, maxlen ) {
if (Core.getText(edit_area).length > maxlen) {
Core.setText(edit_area, Core.getText(edit_area).substr(0, maxlen));
alert('Max text size ' + maxlen + ' symbols!');
}}
function uniedit_update_edit_size( edit_area ) {
uniedit_checklen( edit_area, UE_max_characters );
var obj = document.getElementById(edit_area);
if ( obj ) {
obj.cols = uniedit_width( obj.value );
obj.rows = uniedit_height( obj.value );
}}
function universal_edit2(text_var, text_var_value, edit_area, formated_text_area, post_url, post_cmd, objects_to_hide) {
if ( text_var && edit_area ) {
var text_area_width = uniedit_width( text_var_value );
var text_area_height = uniedit_height( text_var_value );
var obj_hidden = "";
var obj_oncancel_show = "";
for (var i = 0 ; i < objects_to_hide.length ; i++ ){
Core.hideElement( objects_to_hide[ i ] );
obj_oncancel_show = obj_oncancel_show +
"Core.showElement('" + objects_to_hide[ i ] + "');";
if (obj_hidden == "") {
obj_hidden = "'" + objects_to_hide[ i ] + "'";
} else obj_hidden = obj_hidden + ", '" + objects_to_hide[ i ] + "'";
}
if (obj_hidden == "") {
obj_hidden = 0;
} else obj_hidden = "[" + obj_hidden + "]";
Core.setText( edit_area ,
"<textarea id=UE_area" + text_var + " " +
"onkeypress=\"uniedit_update_edit_size('UE_area"+ text_var + "');\" " +
"onkeyup=\"uniedit_update_edit_size('UE_area"+ text_var + "');\" " +
"onkeydown=\"uniedit_update_edit_size('UE_area"+ text_var + "');\"" + ">" +
"</textarea>" +
"<input type=button class=button " +
"id=UE_sb_" + text_var + " " +
"value=\""+LangDict.translateToken('Common.Save')+"\" onclick=\"uniedit_post('UE_area" + text_var +
"', " + text_var + ", '" + edit_area +
"', '" + formated_text_area +
"', '" + post_url + "', " +
post_cmd + ", " +
obj_hidden + ");\">" +
"<input type=button class=button " +
"id=UE_cb_" + text_var + " " +
"value=\""+LangDict.translateToken('Common.Cancel')+"\" onclick=\"Core.hideElement('" +
edit_area + "');" + obj_oncancel_show +"\">" );
Core.flushElementCache( edit_area );
Core.setText("UE_area"+text_var, text_var_value.value);
uniedit_update_edit_size("UE_area" + text_var);
Core.showElement( edit_area );
Core.flushElementCache( edit_area );
}}
function uniedit_post(ue_ref, text_var, edit_area, formated_text_area, post_url, post_cmd, objects_to_show) {
if ( text_var && formated_text_area ) {
uniedit_checklen( ue_ref, UE_max_characters );
text_var.value = Core.getText( ue_ref );
if (post_url == "" || post_cmd == "") {
alert( "AJAX post parameters are NULL" );
return;
}
Core.hideElement(edit_area);
advAJAX.post({
url : post_url,
parameters : post_cmd,
"new_text": text_var.value,
onLoading: function(obj) {},
onSuccess: function(obj) {
Core.setText( formated_text_area , obj.responseText );
Core.hideElement(edit_area);
for (var i = 0 ; i < objects_to_show.length ; i++ ){
Core.showElement( objects_to_show[ i ] );
}
Core.flushElementCache(formated_text_area);
}});
}}
function universal_edit(get_text_from, textarea_id, textarea_height, textarea_width, put_textarea_to, save_command, a_id) {
if (get_text_from && textarea_id && textarea_height && textarea_width && put_textarea_to && save_command !== undefined) {
if (textarea_height == "1") {
Core.setText(put_textarea_to, "<input type=text id=" + textarea_id +  " size=" + textarea_width + "><br><input type=button class=button id='save_button' value=Save onClick=\"save_edited_text('" + save_command + "', '" + textarea_id + "', '" + get_text_from + "','" + put_textarea_to +"', '"+ a_id + "')\"><input type=button class=button id='cancel_button' value=Cancel onCLick=\"Core.hideElement('" +  put_textarea_to + "');Core.showElement('" + get_text_from + "');Core.setText('" + put_textarea_to + "', window.more_text['" +get_text_from+ "']);Core.flushElementCache();\">");
} else {
Core.setText(put_textarea_to, "<textarea id=" + textarea_id + " rows=" + textarea_height + " cols=" + textarea_width + "></textarea><br><input type=button class=button id='save_button' value=Save onClick=\"save_edited_text('" + save_command + "', '" + textarea_id + "', '" + get_text_from + "','" + put_textarea_to +"', '"+ a_id +"');\"><input type=button class=button id='cancel_button' value=Cancel onCLick=\"Core.hideElement('" +  put_textarea_to + "');Core.showElement('" + get_text_from + "');Core.showElement('onpage_edit_button');Core.setText('" + put_textarea_to + "', window.more_text['" +get_text_from+ "']);Core.flushElementCache();\">");
}
Core.setText(textarea_id, window.more_text[get_text_from]);
Core.hideElement(get_text_from);
Core.showElement(put_textarea_to);
}}
function save_edited_text(save_cmd,textarea_id,get_text_from,put_textarea_to, a_id) {
var messagetext = Core.getText(textarea_id);
messagetext = messagetext.replace(/id="onpage_edit_button"/gi, "");
messagetext = messagetext.replace(/id="text"/gi, "");
messagetext = messagetext.replace(/id="for_text_area"/gi, "");
messagetext = messagetext.replace(/id="editing_area"/gi, "");
messagetext = messagetext.replace(/onClick="universal_edit"/gi, "");
messagetext = messagetext.replace(/id=onpage_edit_button/gi, "");
messagetext = messagetext.replace(/id=text/gi, "");
messagetext = messagetext.replace(/id=for_text_area/gi, "");
messagetext = messagetext.replace(/id=editing_area/gi, "");
messagetext = messagetext.replace(/onClick=universal_edit/gi, "");
advAJAX.post({
cmd:save_cmd,
aid : a_id,
new_text : messagetext,
onLoading: function(obj) {},
onSuccess: function(obj) {
Core.setText(put_textarea_to, messagetext);
Core.setText(get_text_from, obj.responseText);
Core.hideElement(put_textarea_to);
Core.hideElement('save_button');
Core.hideElement('cancel_button');
Core.hideElement(textarea_id);
Core.showElement(get_text_from);
Core.showElement('onpage_edit_button');
Core.flushElementCache(get_text_from);
}});
}
function erase_welcomepage_contents() {
var conf_box = confirm("Delete all contents?");
if (conf_box == true){
advAJAX.post({
newly_edited_text:' ',
cmd:'save_edited_page',
onLoading: function(obj) {},
onSuccess: function(obj) {window.location.reload()}});} else {
window.location.reload;
}}
function checkLen(description_limit) {
var descr_text = Core.getText('large_edit_area');
var text_lenght = descr_text.length;
Core.setText('text_lenght', text_lenght);
Core.setText('chars_left', description_limit - text_lenght);
if(text_lenght > description_limit) {
Core.setText('large_edit_area',descr_text.substr(0, description_limit))
alert('Max text size '+description_limit+' symbols!');
}}

