var smsTextLimit = 160;
var feedbackTextLimit = 500;
var currentPage = 1;
var doCheckForNewVibes = true;
var commentCount = new Array();

function onLoadFunc() {
	jQuery('#vibetextAreaLenght').html("("+smsTextLimit+")");
}

function showMessages(elementId, msgText) {
	jQuery("#" + elementId).text(msgText);
	jQuery("#" + elementId).show();
}


function hideMessages(elementId){
	jQuery("#" + elementId).text('');
	jQuery("#" + elementId).hide();
}

function trimStr(str){
	return str.replace(/^\s+|\s+$/g, '') ;
	// return this.replace(/^[\s\u3000]+|[\s\u3000]+$/g, '');
}

function isEmpty(aText) {
	if ((aText.length==0) || (aText==null)) {
		return true;
	} else { 
		var t = aText.replace(/<\/?(b|i|u|strike)[^>]*?>/g, '');
		return (null == t || 0 == trimStr(t).length);
	}
}

function reloadMessageList(args) {
	jQuery("#main").load(contextPath + args.origin + "?ajax=yes&currentPage=" + args.p + "&when=" + new Date().getTime());
}

function reloadMessage(args) {
	if (jQuery("#msg_"+args.msgId).length > 0) {
		jQuery("#msg_"+args.msgId).load(contextPath + "/message?ajax=yes&msgId="+args.msgId + "&when=" + new Date().getTime());
	}
}

function reloadBestVibes(args) {
	jQuery('#BestVibes').removeClass("*");
	jQuery('#BestVibes').addClass("RightCol");
	jQuery('#BestVibes').load(contextPath + args.origin + '/bestvibes?ajax=ofcourse' + "&when=" + new Date().getTime());
	
}

function showTaipNeDiv(taipNeDivId){
	jQuery("#trintiTaipNe" + taipNeDivId).show();
}

function hideTaipNeDiv(taipNeDivId){
	jQuery("#trintiTaipNe"+taipNeDivId).hide();
}

function showFaqDiv() {
	jQuery("#FaqDiv").show();
	jQuery("#operatorLogos").hide();	
}

function hideFaqDiv() {
	jQuery("#FaqDiv").hide();
	jQuery("#operatorLogos").show();	
}

function toggleComments(link, msgId, noOfComments) {
	if (jQuery(link).attr('title') && jQuery(link).attr('title') == 'Uždaryti') { // true == uždarinėjam komentarus
		hideComments(msgId);
		jQuery(link).attr('title', 'Atidaryti');
		if (commentCount[msgId] == 0) {
			jQuery(link).text('Komentuoti');
		} else {
			jQuery(link).text('Komentarai (' + commentCount[msgId] + ')');
		}
	} else {	// atidarinėjam komentarus
		commentCount[msgId] = noOfComments;
		jQuery(link).attr('title', 'Uždaryti');
		showComments(msgId);
		jQuery(link).text('Slėpti komentarus');	
	}
}

function deleteComment(obj, cmtId, msgId) {
	hideTaipNeDiv(cmtId);
	XT.doAjaxAction('deleteComment', obj, {'itemId': cmtId, 'msgId': msgId, 'origin' : window.location.href, 'when' : new Date().getTime()});
}

function reloadComments(args) {
	showComments(args.msgId);
}

function showComments(msgId) {
	jQuery("#CommentForm_" + msgId).load(contextPath + '/comments.do?msgId=' + msgId + "&when=" + new Date().getTime(), 
			function() {
				if (jQuery('#fcmt_' + msgId + '_top').is(':visible')) {
					jQuery('#fcmt_' + msgId + '_top').children().get(0).focus();
				}
 			}
	);
	jQuery("#CommentForm_" + msgId).show();
}

function showCommentArea(msgId, suffix) {
	jQuery('#textAreaLenght_top' + msgId).html("("+smsTextLimit+")");
	jQuery('#textAreaLenght_bot' + msgId).html("("+smsTextLimit+")");
	jQuery('#cmtLink_' + msgId + suffix).hide();
	jQuery('#fcmt_' + msgId + suffix).show();
	jQuery('#fcmt_' + msgId + suffix).children().get(0).focus();
}

function ajaxShowComments(obj) {
	showComments(obj.msgId);
	return false;
}

function hideComments(msgId) {
	hideMessages('commentFormMessages_' + msgId + "_top");
	hideMessages('commentFormMessages_' + msgId + "_bot");
	if(document.forms['fcmt_' + msgId + "_top"])
		document.forms['fcmt_' + msgId + "_top"].text.blur();
	if(document.forms['fcmt_' + msgId + "_bot"])
		document.forms['fcmt_' + msgId + "_bot"].text.blur();
	jQuery("#CommentForm_" + msgId).hide();
}

function saveComment(obj, msgId, suffix) {
	var elId = "fcmt_" + msgId + suffix;
	var msgTxt = trimStr(document.forms[elId].text.value);
	msgTxt = msgTxt.substr(0, smsTextLimit);
	if(isEmpty(msgTxt)){
		showMessages('commentFormMessages_' + msgId + suffix, 'Tuščias komentaras nesiunčiamas.');
	} else {
		document.forms[elId].text.value = msgTxt;
		jQuery('#submitComment_'+msgId).hide(100);
		jQuery('#submitComment_'+msgId).after('<span id="#newcommentloader_'+msgId+'" class="loader"><img alt="tuoj..." title="tuoj..." src="' + contextPath + '/img/ajax-loader.gif"/></span>');
		XT.doAjaxSubmit('addComment', obj, {'msgId' : msgId, 'origin' : window.location.href}, {'formId' : 'fcmt_'+msgId+suffix, 'enableUpload' : true});
	}
}

function clearCommentLoader(args) {
	jQuery('#newcommentloader_' + args.msgId).hide(10);
	jQuery('#submitComment_' + args.msgId).show(300);
}

function updateCommentCount(args) {
	commentCount[args.msgId] = args.noOfComments;
}

function showCreateVibeForm() {
	jQuery('#text_newVibe').text('');
	jQuery('#vibetextAreaLenght').html("("+smsTextLimit+")");
	jQuery("#CreateVibeForm").show();
}

function hideCreateVibeForm() {
	hideMessages('vibeMessageFormMessages');
	jQuery('#text_newVibe').text('');
	jQuery('#vibetextAreaLenght').html("("+smsTextLimit+")");
	jQuery("#CreateVibeForm").hide();
}

function alertAlreadyVoted(){
	alert("Jau įdomu.");
}

function vote(obj, msgId) {
	jQuery(".vote"+msgId).html('Tuuuoooj....');
	XT.doAjaxAction('voteForMessage', obj, {'msgId': msgId, 'origin' : window.location.href, 'when' : new Date().getTime()});
	return false;
}

function updateVotes(args) {
	jQuery(".vote"+args.msgId).html('Įdomu! (' + args.noOfVotes + ')');
}

function deleteMsg(obj, msgId, pageNo) {
	hideTaipNeDiv(msgId);
	jQuery('#msg_'+msgId).hide();
	XT.doAjaxAction('deleteMessage', obj, {'itemId': msgId, 'currentPage': pageNo, 'origin' : window.location.href, 'when' : new Date().getTime()});
	return false;
}

function showFeedbackForm() {
	hideMessages('vibeFeedbackFormMessages');
	jQuery('#text_feedback').val('');
	jQuery('#feedbackTextAreaLenght').html('('+feedbackTextLimit+')');
	jQuery('#feedbackFormDiv #formGradient').show();
	jQuery("#feedbackFormDiv").show();
}

function hideFeedbackForm() {
	jQuery("#feedbackFormDiv").hide();
	jQuery('#feedbackFormDiv #formGradient').hide();
	jQuery('#vibeFeedbackFormMessages').hide();		
}

function sendFeedback(obj) {
	var feedbackTxt = trimStr(jQuery('#text_feedback').val());
	feedbackTxt = feedbackTxt.substr(0, feedbackTextLimit);
	if(isEmpty(feedbackTxt)){
		showMessages('vibeFeedbackFormMessages', 'Tuščia žinutė nesiunčiama.');
	} else {
		jQuery('#text_feedback').val(feedbackTxt);	
		XT.doAjaxSubmit('sendFeedback', obj, {'origin' : window.location.href}, {'formId' : 'feedbackForm', 'enableUpload' : true});
	}
}

function thankYouForYourCooperation() {
	jQuery('#feedbackFormDiv').hide();
}

function toggleSettings(form) {
	var formName = "#" + form;
	if (jQuery(formName).attr('isopen') && jQuery(formName).attr('isopen') == 'Uždaryti') { // true == uždarinėjam bloką
		jQuery(formName).hide();
		jQuery(formName).attr('isopen', 'Atidaryti');
	} else {	// atidarinėjam settingus
		jQuery(formName).attr('isopen', 'Uždaryti');
		hideMessages(form + 'Messages');
		hideMessages(form + 'ErrorMessages');
		jQuery("#cancel" + form).text('Atšaukti');
		jQuery(formName).show();
	}
}

function hide(divId) {
	jQuery("#" + divId).hide();
}

function show(divId) {
	jQuery("#" + divId).show();
}

function saveSettings(obj, formName, divId){
	if ('' != formName) {
		XT.doAjaxSubmit('save' + formName, obj, {'origin' : window.location.href, 'form' : formName, 'divId' : divId}, {'formName' : formName, 'enableUpload' : true});
		hideMessages(divId + 'Messages');
		hideMessages(divId + 'ErrorMessages');
	}
}

function saveSettingsCallback(args) {
	if (args.saveOk) {
		jQuery("#cancel" + args.divId).text('Uždaryti');
		if ('phone' == args.divId) {
			resetPhoneConfirmation();
		}
		showMessages(args.divId + "Messages", 'Pakeitimai sėkmingai išsaugoti');
	}
}

function reloadMyInfoData(args) {
	var author = args.author;
	
//	jQuery("#myInfo").load(contextPath + args.origin + "/info" + "?when=" + new Date().getTime());
}

function showError(args) {
	showMessages(args.divId + 'ErrorMessages', args.errMsg);
	if ('phone' == args.divId) {
		resetPhoneConfirmation();
	}
}

function restoreField(args) {
	jQuery("#" + args.restoreVar).val(args.restoreValue);
}

function reloadMyInfo(args){
	if (args.saveOk) {
		reloadMyInfoData(args);
		jQuery("#My_UserName_Vibe_Link").val(args.nick);
		jQuery("#my_data_header_nick").val(args.nick);
	} else {
		showMessages('myInfoFormMessages', args.errMsg);
	}
}

function reloadPage(args) {
	window.location.href = contextPath + args.origin;
}

function saveFoto(obj){
	var fName = trimStr(document.getElementById('fileInput').value);
	if(isEmpty(fName)){
		showMessages('fotoErrorMessages', "Nenurodytas naujas avataras!");
		return false;
	}
	XT.doAjaxSubmit('uploadFile', obj, {'origin' : window.location.href}, {'formName' : 'FotoForm', 'enableUpload' : true});
	
	return false;
}

function saveFotoCallback(args){
	if (!args.saveOk){
		showMessages('fotoErrorMessages', args.saveFotoMsg);
		return false;
	} else {
		showMessages('fotoMessages', "Pakeitimai sėkmingai išsaugoti. Naujasis avataras matysis perkrovus puslapį.");
		jQuery("#cancel" + args.divId).text('Uždaryti');
		reloadPage(args);
	}
	return false;
}

function deleteFoto(obj, formName, divId) {
	if ('' != formName) {
		XT.doAjaxAction('deleteFoto', obj, {'origin' : window.location.href, 'form' : formName, 'divId' : divId, 'when' : new Date().getTime()});
	}
}

function setFavourite(obj, favouriteId, myId){
	XT.doAjaxAction('setFavourite', obj, {'favouriteId': favouriteId, 'myId' : myId, 'when' : new Date().getTime()});
}

function unsetFavourite(obj, favouriteId, myId){
	XT.doAjaxAction('unsetFavourite', obj, {'favouriteId': favouriteId, 'myId' : myId, 'when' : new Date().getTime()});
}

function hideSetFavouriteLink(){
	showMessages('favouriteMsg', 'Įtrauktas į mėgstamus.');
	jQuery("#setFavouriteLink").hide();
	jQuery("#unsetFavouriteLink").show();
}

function hideUnsetFavouriteLink(){
	showMessages('favouriteMsg', 'Išmestas iš mėgstamų');
	jQuery("#unsetFavouriteLink").hide();
	jQuery("#setFavouriteLink").show();
}

function isPhoneNumber(someId) {
	var startsWithPlus = /^\+/;
	return startsWithPlus.test(someId);
}

function isCorrectPhoneNumber(phone) {
	var plusAndAllDigits = /\+\d{11,12}/;
	return (phone.length < 32 && plusAndAllDigits.test(phone) );
}

function isOwnPhone(phone) {
	return ("+37068485155" == phone) || ("+37065494904" == phone) || ("+37062307015" == phone);
}
 
function forgotPassword(obj){
	var someId = trimStr(document.getElementById('remindPassToPhone').value);
	
	if (isEmpty(someId)){
		showMessages('recoverMessages', 'Klaida: Neįvestas identifikatorius');
		return false;
	}
	
	if (isPhoneNumber(someId) && (!isCorrectPhoneNumber(someId) || isOwnPhone(someId)) ) {
		showMessages('recoverMessages', "Klaida: Tel. numerį turi sudaryti '+' ir skaitmenys (pvz. +37012312345).");
		return false;
	} 
	
	showMessages('recoverMessages','Laukite sms...');
	XT.doAjaxSubmit('forgotPassword', obj, {'origin' : window.location.href}, {'formId' : 'remindPassForm', 'enableUpload' : true});
	
	return false;
}

function doLogin(obj) {
	var someId = trimStr(document.loginForm.j_username.value);
	var pass  = trimStr(document.loginForm.j_password.value);
	var remember  = document.loginForm._spring_security_remember_me.checked;
	
	if(isEmpty(someId) || isEmpty(pass)) {
		showMessages('loginFormMessages','Klaida: Neįvestas identifikatorius arba slaptažodis.');
		return false;
	}
	
	if (isPhoneNumber(someId) && (!isCorrectPhoneNumber(someId) || isOwnPhone(someId)) ) {
		showMessages('loginFormMessages','Klaida: Tel. numerį turi sudaryti "+" ir skaitmenys (pvz. +37012312345).');
		return false;
	}

	digitsAndLetters = /\w+/;
	if (! digitsAndLetters.test(pass)) {
		showMessages('loginFormMessages', 'Klaida: Slaptažodį turi sudaryti skaitmenys ir lotyniškos raidės.')
	}
	
	if(pass.length > 16) {
		showMessages('loginFormMessages','Klaida: Slaptažodį turi sudaryti ne daugiau 16 simbolių.');
		return false;
	}
	
    var ajaxRequest = new XT.taconite.AjaxRequest(contextPath + '/j_spring_security_check'); // Create
																								// AjaxRequest
																								// object
    ajaxRequest.addNamedFormElements('ajax', 'ofcourse');
    ajaxRequest.addNamedFormElements('j_username', someId);
    ajaxRequest.addNamedFormElements('j_password', pass);
    ajaxRequest.addNamedFormElements('_spring_security_remember_me', remember);
    ajaxRequest.sendRequest();

	return false;
}

function doLoginCallback(args){
	if(!args.loginOk) {
		showMessages('loginFormMessages', args.msgText);
		jQuery('#password').val("");
		return false;
	}
	if (args.redirectUrl != '') {
		window.location.href = args.redirectUrl;
	} else {
		window.location.href = window.location.href;
	}
	return false;
}

function ShowLoginScreen(){
	hideMessages('loginFormMessages');
	jQuery("#RemindPass").hide();
	jQuery("#LeftLogin").show();
}

function ShowRemindPassScreen(){
	hideMessages('recoverMessages');
	jQuery("#LeftLogin").hide();
	jQuery("#RemindPass").show();
}

function smsPasswordCallback(args){
	document.getElementById('remindPassToPhone').value = '+370';
	showMessages('recoverMessages',args.msgText);
	window.setTimeout('ShowLoginScreen()', 3000);
}

function changePassword(obj, formName, divId) {
	hideMessages('changePassErrorMessages');
	hideMessages('changePassMessages');
	
	var oldPass = jQuery("#OldPass").val();
	var newPass1 = jQuery("#NewPass").val();
	var newPass2 = jQuery("#RepeatNewPass").val();
	
	if(isEmpty(oldPass) || isEmpty(newPass1) || isEmpty(newPass2)) {
		showMessages('changePassErrorMessages', 'Ne visi laukai užpildyti.');
		return false;
	}
	
	if(newPass1 != newPass2){
		showMessages('changePassErrorMessages', 'Naujas ir pakartotas slaptažodžiai nesutampa.');
		return false;
	}
	
	if (newPass1 == oldPass) {
		showMessages('changePassErrorMessages', 'Naujas slaptažodis toks pats, kaip ir senas.');
		return false;
	}
	
	XT.doAjaxAction('changePassword', obj, {'oldPass':oldPass, 'newPass1':newPass1, 'newPass2':newPass2, 'form' : formName, 'divId' : divId, 'when' : new Date().getTime()});
	return false;
}

function changePasswordCallback(args){
	if(args.passUpdated) {
		showMessages('changePassMessages', 'Slaptažodis sėkmingai pakeistas.');
		jQuery("#OldPass").val('');
		jQuery("#NewPass").val('');
		jQuery("#RepeatNewPass").val('');
	} else {
		showMessages('changePassErrorMessages', 'Slaptažodis nepakeistas: ' + args.msgText);
	}
}

function saveVibeMessage(obj) {
	var msgTxt = trimStr(jQuery('#text_newVibe').val());
	msgTxt = msgTxt.substr(0, smsTextLimit);
	if(isEmpty(msgTxt)){
		showMessages('vibeMessageFormMessages', 'Tuščia žinutė nesiunčiama.');
	} else {
		jQuery('#text_newVibe').val(msgTxt);
		jQuery("#vibeMessageOrigin").val(window.location.href);
		jQuery('#SendNewVibe').hide(100);
		jQuery('#SendNewVibe').after('<span class="newmsgloader loader"><img alt="tuoj..." title="tuoj..." src="' + contextPath + '/img/ajax-loader.gif"/></span>');
		XT.doAjaxSubmit('saveVibeMessage', obj, {'origin' : window.location.href}, {'formId' : 'vibeMessageForm', 'enableUpload' : true});
		
	}
	return false;
}

function saveVibeMessageCallback(args){
	jQuery('.newmsgload').hide(10);
	jQuery('#SendNewVibe').show(100);
	jQuery('#text_newVibe').val("");
	jQuery('#vibetextAreaLenght').html("("+smsTextLimit+")");
	reloadMessageList(args); 
}

function showAllVibers(divId){
	if(document.getElementById(divId).style.display == 'none'){
		jQuery("#all"+divId).hide();
		jQuery("#"+divId).show();
	} else {
		jQuery("#"+divId).hide();
		jQuery("#all"+divId).show();
	}
}

/*
 * http://www.ajaxray.com/blog/2007/11/09/interactive-character-limit-for-textarea-using-jquery/
 * textid : (string) The ID of your textarea. limit : (num) The number of
 * character you allow to write. infodiv : (string) The ID of a div, in which
 * limit information will be shown .
 */
function limitChars(textid, limit, infodiv) {

	var mytext = jQuery('#'+textid).val(); 
	var textlength = mytext.length;

	if(textlength > limit) {
		jQuery('#' + infodiv).html('(0)');
		jQuery('#'+textid).val(mytext.substr(0,limit));
  		return false;
	} else {
		jQuery('#' + infodiv).html('(' + (limit - textlength) +')');
		return true;
	}
}

function limitTextLengthByFormId(formId, infodiv){
	limitTextLength(formId, infodiv, smsTextLimit);
 }
 
 function limitFeedbackLengthByFormId(formId, infodiv){
 	limitTextLength(formId, infodiv, feedbackTextLimit);
 }
 
 function limitTextLength(formId, infodiv, limit){
	var mytext = document.forms[formId].text.value;
	var textlength = mytext.length;

	if(textlength > limit) {
		jQuery('#' + infodiv).html('(0)');
  		document.forms[formId].text.value = mytext.substr(0, limit);
  		return false;
	} else {
		jQuery('#' + infodiv).html('(' + (limit - textlength) +')');
		return true;
	}
 }
 
function inviteViber(obj) {
	var invitePhone = document.inviteForm.invite_phone.value;
	invitePhone = trimStr(invitePhone);
	if (!isCorrectPhoneNumber(invitePhone) || isOwnPhone(invitePhone) || invitePhone.length > 32) {
		jQuery("#foundAuthor").html('');
		jQuery("#foundAuthor").hide();
		showInviteMessages(false, "Klaida: Tel. numerį turi sudaryti 12 skaitmenų (pvz. +37012312345).");
	} else {
		XT.doAjaxSubmit('inviteViber', obj, {'origin' : window.location.href}, {'formId' : 'inviteForm', 'enableUpload' : true});
	}
	return false;
}

function inviteViberOnMessageCallback(args) {
	document.inviteForm.invite_phone.value = "+370";
	jQuery("#foundAuthor").html('');
	jQuery("#foundAuthor").hide();
	showInviteMessages(args.inviteSuccess, args.msgText);
}

function loadFoundAuthor(args) {
	document.inviteForm.invite_phone.value = "+370";
	hideMessages('inviteFormErrorMessages');
	if(args.showMeInSearch) {
		showMessages('inviteFormMessages', "Tavo draugas jau čia!");
		jQuery("#foundAuthor").load(contextPath + "/foundAuthor.do?authorId=" + args.foundAuthorId + "&when=" + new Date().getTime());
		jQuery("#foundAuthor").show();
	} else {
		showMessages('inviteFormMessages', "Tavo draugas jau čia! Susisiek asmeniškai.");
		jQuery("#foundAuthor").hide();
	}
}

function inviteViberOnSmsCallback(args) {
	document.inviteForm.invite_phone.value = "+370";
	jQuery("#foundAuthor").html('');
	jQuery("#foundAuthor").hide();
	showInviteMessages(true, 'Pakvietimas numeriu ' + args.invitePhone + ' sėkmingai išsiųstas!');
}

function showInviteMessages(inviteSuccess, message) {
	if (inviteSuccess) {
		hideMessages('inviteFormErrorMessages');
		showMessages('inviteFormMessages', message);		
	} else {
		hideMessages('inviteFormMessages');
		showMessages('inviteFormErrorMessages', message);		
	}
}

function checkForNewVibes() {
//	if(doCheckForNewVibes) {
//		XT.doAjaxAction('checkForNewVibes', document.getElementById('main'), {'origin' : window.location.href, 'when' : new Date().getTime()});
//	}
	return false;
}

function checkForNewVibesCallback (args) {
//	if ('1' == args.newVibes) {
//		doCheckForNewVibes = false;
//		document.getElementById("refreshButton").src = contextPath + '/img/yranauju.jpg';
//	} else {
//		doCheckForNewVibes = true;
//		document.getElementById("refreshButton").src = contextPath + '/img/refresh.png';
//	}
	return false;
}

function getViberListPage(page, divid) {
	var location = window.location.href;
	if (-1 != location.indexOf("?")) {
		location = location.substring(0, location.indexOf("?"));
	}
	jQuery("#viberList_" + divid).load(location + "/viberlist?viberPage="+page+"&divid="+divid + "&when=" + new Date().getTime());
}

function toggleStickMsg(obj, msgId, isSticky) {
	if (isSticky) {
		jQuery(".stick"+msgId).html("unsticking....");
	} else {
		jQuery(".stick"+msgId).html("sticking...");
	}
	XT.doAjaxAction('toggleStickMessage', obj, {'msgId': msgId, 'origin' : window.location.href, 'when' : new Date().getTime()});
}

function reloadStickyVibes(args) {
	jQuery('#StickyVibes').removeClass("*");
	jQuery('#StickyVibes').addClass("RightCol");
	jQuery('#StickyVibes').load(contextPath + args.origin + '/stickyvibes?ajax=ofcourse' + "&when=" + new Date().getTime());
}

function showDeleteMeForm(){
	hideMessages('mySuccessMessages');
	hideMessages('myInfoMessages');
	jQuery("#myInfoDiv").hide();
	jQuery("#DeleteMeTaipNeDiv").hide();
	jQuery("#DeleteMeDiv").show();
}

function hideDeleteMeForm(){
	jQuery('#DeleteMeTaipNeDiv').hide();
	jQuery("#DeleteMeDiv").hide();
	jQuery('#SuicidePermit').val("not yet");
	jQuery("#myInfoDiv").show();
}

function requestSuicidePermit(obj, myId) {
	XT.doAjaxAction('requestSuicidePermit', obj, {'myId' : myId, 'origin' : window.location.href, 'when' : new Date().getTime()});
}

function receiveSuicidePermit(args) {
	jQuery('#SuicidePermit').val(args.permitNo);
	hide('DeleteMeDiv');
	show('DeleteMeTaipNeDiv');
}

function harakiri(obj, myId) {
	XT.doAjaxAction('harakiri', obj, {'myId' : myId, 'ohreally' : jQuery('#SuicidePermit').val(), 'origin' : window.location.href, 'when' : new Date().getTime()});
}

function cancelHarakiri(obj, myId, divId) {
	hide('DeleteMeTaipNeDiv');
	show('DeleteMeDiv');
	toggleSettings(divId);
	XT.doAjaxAction('cancelHarakiri', obj, {'myId' : myId, 'ohreally' : jQuery('#SuicidePermit').val(), 'origin' : window.location.href, 'when' : new Date().getTime()});
}

function requestPhoneConfirmation(myId, oldVal) {
	hideMessages('changePhoneMessages');
	var newVal = jQuery('#phoneField').val();
	if (newVal != oldVal) {
		if (! isCorrectPhoneNumber(newVal)) {
			showMessages('changePhoneErrorMessages', 'Negeras telefono numeris!');
		} else {
			XT.doAjaxAction('requestPhoneConfirmation', null, {'newVal' : newVal, 'myId' : myId, 'origin' : window.location.href, 'when' : new Date().getTime()}, {'formId' : 'PhoneForm'});
		}
	}
}
	
function phoneConfirmationCallback(args) {
	if (args.skip) {
		return false;
	}
	
	if (args.saveOk) {
		jQuery("#changePhoneStep1").hide();
		jQuery("#changePhoneSave").show();
		jQuery('#changePhoneExpl').text('Įveskite sms žinute gautą patvirtinimo kodą.');
	} else {
		showMessages('changePhoneErrorMessages', args.cfMsg);
	}
	
	return false;
}

function resetPhoneConfirmation() {
	jQuery('#changePhoneExpl').text("Paspaudus 'Tęsti' jūsų nurodytu numeriu sms žinute bus išsiųstas patvirtinimo kodas.");
	jQuery("#changePhoneConfirm").val('');
	jQuery("#changePhoneSave").hide();	
	jQuery('#changePhoneStep1').show();
}

function hideCurrentMoreLink(pageno) {
	jQuery("#morelink" + pageno).hide();
}

function loadMore(pageno, nick, type, startTime) {
	var location = contextPath;
	if (0 != nick && null != nick) {
		location = location + "/viber/" + nick;
	}
	location = location + "/loadmore"; 
	jQuery('#messages').after('<span class="msgloader loader"><img alt="dar..." title="dar..." src="' + contextPath + '/img/ajax-loader.gif"/></span>');
	$.get(location, {'currentPage' : pageno, 'uri' : type, 'startTime' : startTime, 'when' : new Date().getTime()}, function(data){jQuery(".msgloader").remove(); jQuery("#messages").append(data);});
}
