// ----------------------------------------------
// After some action --- response content of page

function responseContent(t)
{
	if (t.responseText == "search" || t.responseText == "search2") {
		document.location.href = serverName + '/' + t.responseText + '.php';
	} else {

	var res = eval('(' + t.responseText + ')');

	var doc;
	if (mainWin)
		doc = mainWin.document;
	else
		doc = document;

	if (res['login'] == "false") {
		// user don't login
		createMyPopup('permission', 0, 237);
	} else {
		// update infoblog: count of new messages, count of online users
		if (res['infoblog'] != undefined) {
			infoBlog = doc.getElementById("infoblog");
			infoBlog.innerHTML = res['infoblog'];
		}

		// global content
		if (res['content'] != undefined) {
			contentPageAll = doc.getElementById("content");
			contentPageAll.innerHTML = res['content'];

			if (res['count_columns'] == 2) {
				document.getElementById('footer_another').style.display = "none";
				document.getElementById('footer').style.display = "block";	
			} else {
				document.getElementById('footer').style.display = "none";
				document.getElementById('footer_another').style.display = "block";	
			}
		}
	
		// left column of content
		if (res['content1'] != undefined) {
			contentPage1 = doc.getElementById("content1");
			contentPage1.innerHTML = res['content1'];
		}

		// percent of fill profile
		if (res['percent'] != undefined) {
			if (doc.getElementById("percentProfile")) {
				percent = doc.getElementById("percentProfile");
				if (language == "rus")
					percent.innerHTML = "Профайл заполнен на " + res['percent'] + "%";
				else
					percent.innerHTML = "Profile is filled on " + res['percent'] + "%";
			}
			if (doc.getElementById("percentProfile2")) {
				percent = doc.getElementById("percentProfile2");
				percent.innerHTML = res['percent'] + "%";
			}
		}

		// right column of content
		if (res['content2'] != undefined) {
			contentPage2 = doc.getElementById("content2");
			contentPage2.innerHTML = res['content2'];

			if (document.forms['profile1'])
				checkLen();
		
			document.getElementById('footer_another').style.display = "none";
			document.getElementById('footer').style.display = "block";	
		}
		// 2-columns content
		else if (res['content3'] != undefined) {
			contentPage3 = doc.getElementById("content3");
			contentPage3.innerHTML = res['content3'];
		}

		// go to top of screen
		scroll(0,0);
	}
	}
}

// ----------------------------------------------
function responseContentMessage(t)
{
	document.location.href = serverName + '/message.php';
}

// ----------------------------------------------
// load page of menu
function loadPage(newPage, oldPage, userID)
{
	if (newPage == "index.php" || newPage == "")
		goIndex();
	else if (newPage == "message" && userID != null) {
		var params = "newPage=messagePage";
		params += "&msgID="+userID;
		params += "&task=loadPage";
		new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseContentMessage});
	} else {
		if (over) cClick();
		var params = "newPage="+newPage;
		if (oldPage)
			params += "&oldPage="+oldPage;
		if (userID)
			params += "&userID="+userID;
		params += "&task=loadPage";
		new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseContent});
	}
}

// ----------------------------------------------
// update different parts of profile
function loadPartProfile(profilePage)
{
	if (over) cClick();
	if (profilePage == 'quickSearch')
		profilePage = 'search';
	var params = "profilePage="+profilePage;
	params += "&task=loadPartProfile";

	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseContent});
}

// ----------------------------------------------
// load all profile data
function loadProfile(profilePage, idAbout)
{
	if (over) cClick();
	var params = "profilePage="+profilePage;
	if (idAbout)
		params += "&idAbout="+idAbout;
	params += "&task=loadProfile";

	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseContent});
}

// ----------------------------------------------
// go to next page (page # Number, previous, next) for all lists
function loadListNext(profilePage, go)
{
	var type = '';
	if (profilePage == "HistoryMessagesListNext") {
		var form_elt = document.forms['viewMessage'];
		var msg_id = form_elt.elements['msg'].value;
		var params = "go="+go;
		params += "&msg_id="+msg_id;

		var check_form = document.forms['sendMessage'];
		if (check_form) {
			var send = form_elt.elements['id'].value;
			var user = form_elt.elements['author'].value;
			var user_photo = form_elt.elements['author_photo'].value;

			params += "&send="+send;
			params += "&user="+user;
			params += "&user_photo="+user_photo;
			params += "&task=createMessageNext";
		} else
			params += "&task=viewMessageHistoryNext";
		new Ajax.Request('/lib/Ajax/ajax.message.update.php', {method:'post', postBody:params, onSuccess:responseMessage});
	} else {
		if (profilePage == "searchListNext")
			type = "search";
		else if (profilePage == "search2ListNext") {
			profilePage = "searchListNext";
			type = "search2";
		}
		else if (profilePage == "quickSearchListNext") {
			profilePage = "searchListNext";
			type = "quickSearch";
		}
		var params = "go="+go;
		if (type != '')
			params += "&type="+type;
		params += "&task="+profilePage;
		new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseContent});
	}
}

// ----------------------------------------------
function responseGoBackSearchResults(t)
{
	var res = eval('(' + t.responseText + ')');

	if (res['search_prev_type'] == "search" || res['search_prev_type'] == "search2" || res['search_prev_type'] == "quickSearch" || res['search_prev_type'] == "top2gether") {
		document.location.href = serverName + '/' + res['search_prev_type'] + '.php?page=' + res['search_prev_page'];
	}
	else
		document.location.href = serverName + '/index.php';
}

// ----------------------------------------------

function goBackSearchResults(type)
{
	params = "task=goBackSearchResults";
	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseGoBackSearchResults});
}

// ----------------------------------------------
// ----------------------------------------------
// when view information about another user => going to SITE/user/userName
function responseViewUserPage(t)
{
	document.location.href = serverName + '/user/' + t.responseText;
}

// ----------------------------------------------

function viewUserPage(userName, profilePage)
{
	if (over) cClick();
	if (!profilePage)
		profilePage = "profile2";

	params = "profilePage="+profilePage;
	params += "&user="+userName;
	params += "&task=saveViewPage";

	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseViewUserPage});
}

// ----------------------------------------------
// ----------------------------------------------
// create popup window when we added some user to one of lists (favorite, friends, black)
function responseAddToList(t)
{	
	if (t.responseText) {
		if (document.chatIn != undefined) {
			createChatPopupAddList(t.responseText);
		} else  {
			createMyPopup(t.responseText,0,237);
			updateBlogs();
		}
	}	
	return false;
}

// ----------------------------------------------
function addToList(list, user)
{
	var params = "list="+list;
	params += "&user="+user;
	params += "&task=addToList";
	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseAddToList});
}


// ----------------------------------------------
// send request for close of account
function sendMailFakeProfile()
{
	var form_elt = document.forms['FakeAccount'];
	var user_id = form_elt.elements['user_id'].value;
	var user_name = form_elt.elements['user_name'].value;
	var allText = form_elt.elements['user_comment'].value;

	allText = allText.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
	user_comment = allText.replace(/<.*script.*(>|$)/g, "");

	var err = "";

	if (user_comment == "") {
		err = "<br><b>" + ErrorsFoundFor + "</b><br><br>" + IncorrectlyMsg + "<br>";

		action = "sendFakeProfile("+user_id+", '"+user_name+"');";
		x = calculateX();
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom  class=\"popupTop\">' + sendFakeProfileText + '</td></tr><tr><td class=\"popupCenter\">' + err + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);

	} else {
		params = "user_id=" + user_id;
		params += "&user_name=" + user_name;
		params += "&user_comment=" + user_comment;
		params += "&task=sendMailFakeProfile";
		new Ajax.Request('/lib/Ajax/ajax.contact.message.php', {method:'post', postBody:params, onSuccess: responseInviteToFriend});
	}
}

// ----------------------------------------------
function sendFakeProfile(user_id, user)
{
	if (over) cClick();
	
	if (mydrag)
		mydrag.destroy();
	mydrag = null;
	
	var text = "<form name='FakeAccount' class='myForm'><input type='hidden' name='user_id' value="+user_id+"><input type='hidden' name='user_name' value='"+user+"'><table width=90% border=0 cellspacing=2 cellpadding=2 align=center>";
		text += "<tr height=25><td colspan=2 align=center class='profile_value'>" + ThinkFake + "</td></tr>";
		text += "<tr><td colspan=2 align=center class='profile_value'><textarea name='user_comment' rows='3' cols='3' style='width:90%;'></textarea></td></tr></table></form>";

	var action_change = " sendMailFakeProfile();";
	var action_close = " cClick();";
	x = calculateX();
	overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom class=\"popupTop\">' + sendFakeProfileText + '</td></tr><tr><td class=\"popupCenter\">' + text + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/button_send_request.gif\" border=0 onClick=\"javascript:' + action_change + '\" alt=\"' + sendFakeProfileMessage + '\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action_close + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	document.forms['FakeAccount'].elements['user_comment'].focus();
}

// ----------------------------------------------
function responseAddContactPrincess(t)
{
	var res = eval('(' + t.responseText + ')');
	
	createMyPopup(res['text'],0,237);
	document.getElementById('princess_contact').innerHTML = res['divInner'];
	document.getElementById('princess_contact2').innerHTML = res['divInner2'];

	return false;
}

// ----------------------------------------------
function changeContactPrincess(type, user)
{
	var params = "user="+user;
	params += "&type="+type;
	params += "&task=changeContactPrincess";
	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseAddContactPrincess});
}

// ----------------------------------------------
// ----------------------------------------------
// when we answer to user ask for us to adding in Friends --- ADD or IGNORE
function responseAddToList2(t)
{
	loadPage('friends','friends');
}

function responseAddToList3(t)
{
	loadPage('friendsWaiting','friends');
}

// ----------------------------------------------
function addToList2(list, user, ignore)
{
	var params = "list="+list;
	params += "&user="+user;
	if (ignore)
		params += "&ignore=true";
	params += "&task=addToList";
	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseAddToList3});
//	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseAddToList2});
}

// ----------------------------------------------
// ----------------------------------------------
// delete som user form one of lists (favorite, friends, black)
function responseDeleteFromList(t)
{
	var res = eval('(' + t.responseText + ')');

	if (over) cClick();
	
	if (!mydrag) {
		mydrag = new Draggable('overDiv');
	}

	action = " loadPage('"+res['type']+"'); mydrag.destroy(); mydrag=null; cClick(); return true;";
	overlib('<div id=\"popupWin\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\">' + res['text'] + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, 0, RELY, 237);
}

// ----------------------------------------------
function deleteFromList(list, user)
{
	var params = "list="+list;
	params += "&user="+user;
	params += "&task=deleteFromList";
	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseDeleteFromList});
}

// ----------------------------------------------
// ----------------------------------------------
// save profile - text-field "about user"
function saveProfile1()
{
	var allText = document.forms['profile1'].elements['user_about'].value;

	allText = allText.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
	text = allText.replace(/<.*script.*(>|$)/g, "");

// 	var text = allText.replace(/<\/?[^>]+(>|$)/g, "");
	document.forms['profile1'].elements['user_about'].value = text;

	len = text.length;
	var params = "";
	if ((len>=40 && len<=2000) || text == "") {
		if (language == "rus") {
			if (text == "")
				personal_ad = Delete_string ;
			else
				personal_ad = Save_string;

			var var_y  = PersonalAdInPr + personal_ad + '.';

			createMyPopup(var_y, 585, 237);
			checkLen();
		} else
			createMyPopup(PersonalAdInPr, 585, 237);

		params = "text="+text;
		params += "&task=saveProfile1";

		new Ajax.Request('/lib/Ajax/ajax.profile.save.php', {method:'post', postBody:params, onSuccess:responseContent});
	}
	else {
			createMyPopup(TextMustContai,585, 237);
	}
}

// ----------------------------------------------

function checkLen()
{
	len = document.forms['profile1'].elements['user_about'].value.length;
	count = 2000 - len;
	if (count < 0)
		count = 0;
	document.forms['profile1'].elements['least_chars'].value  = count;
}

// ----------------------------------------------
// ----------------------------------------------
// save profile data (all pages and search criteria) after popup window
function responseUpdateProfile(t)
{
	var res = eval('(' + t.responseText + ')');
	var pageContent = document.getElementById(res['key']+'Value');
	var countryValue;
	var countryDIV;

	if (res['key'] == "country") {
		countryDIV = document.getElementById("countryProfile");
		countryDIV.innerHTML = res['value'] + "<br>";
	}

	if (res['key'] == "region") {
		countryValue = document.getElementById("countryValue").innerHTML;
		countryDIV = document.getElementById("countryProfile");
		countryDIV.innerHTML = countryValue + "<br>";
		if (res['value'] == "Киев" || res['value'] == "Kiev" || res['value'] == "Севастополь" || res['value'] == "Sevastopol")
			countryDIV.innerHTML += res['value'];
	}

	if (res['key'] == "city") {
		countryValue = document.getElementById("countryValue").innerHTML;
		countryDIV = document.getElementById("countryProfile");
		countryDIV.innerHTML = countryValue + "<br>" + res['value'];
		document.getElementById("cityValue").innerHTML = res['value'];
	}

	if (res['key'] != "country" && res['key'] != "region" && res['key'] != "city") {
		pageContent.innerHTML = res['value'];
	}

	if (res['key'] == "country") {
		document.getElementById("countryValue").innerHTML = res['value'];
		document.getElementById("regionValue").innerHTML = "";
		document.getElementById("cityValue").innerHTML = "";
	}

	if (res['key'] == "region") {
		document.getElementById("regionValue").innerHTML = res['value'];
		if (res['value'] == "Киев" || res['value'] == "Kiev" || res['value'] == "Севастополь" || res['value'] == "Sevastopol")
			document.getElementById("cityValue").innerHTML = res['value'];
		else
			document.getElementById("cityValue").innerHTML = "";
	}

	if (res['percent'] != undefined) {
		if (document.getElementById("percentProfile")) {
			percent = document.getElementById("percentProfile");
			if (language == "rus")
				percent.innerHTML = "Профайл заполнен на " + res['percent'] + "%";
			else
				percent.innerHTML = "Profile is filled on " + res['percent'] + "%";
		}
		if (document.getElementById("percentProfile2")) {
			percent = document.getElementById("percentProfile2");
			percent.innerHTML = res['percent'] + "%";
		}
	}

	cClick();
}

// ----------------------------------------------
// ----------------------------------------------
function responseSaveQuickSearch(t)
{
	var res = eval('(' + t.responseText + ')');
	var tbField = res['key'];
	var formSearch = document.forms['quickSearch'];
	
	formSearch.elements[tbField].options.length = 0;
	formSearch.elements[tbField].options[0] = new Option (res['value'], '');

	cClick();
}

// ----------------------------------------------

function responseSaveSettings(t)
{
	var res = eval('(' + t.responseText + ')');
	var tbField = res['key'];
	var formSettings = document.forms['advSettings'];
	
	formSettings.elements[tbField].options.length = 0;
	formSettings.elements[tbField].options[0] = new Option (res['value'], '');

	if (tbField == "region" && formSettings.elements['country_id'].value == 1 && formSettings.elements['region_id'].value == 10) {
		formSettings.elements['city_id'].value = 36;
		formSettings.elements['city'].options.length = 0;
		formSettings.elements['city'].options[0] = new Option (res['value'], '');
	} else if (tbField == "region" && formSettings.elements['country_id'].value == 1 && formSettings.elements['region_id'].value == 19) {
		formSettings.elements['city_id'].value = 61;
		formSettings.elements['city'].options.length = 0;
		formSettings.elements['city'].options[0] = new Option (res['value'], '');
	}

	cClick();
}

// ----------------------------------------------

function responseSaveSettingsIncome(t)
{
	createMyPopupNoMove(SettingsReceiv, 300, 237);
}

// ----------------------------------------------

function responseSaveRegForm(t)
{
	var res = eval('(' + t.responseText + ')');

	var tbField = res['key'];
	var regForm = document.forms['registration'];
	
	regForm.elements[tbField].value = res['value'];

	if (tbField == "region" && regForm.elements['country_id'].value == 1 && regForm.elements['region_id'].value == 10) {
		regForm.elements['city_id'].value = 36;
		regForm.elements['city'].value = res['value'];
	} else if (tbField == "region" && regForm.elements['country_id'].value == 1 && regForm.elements['region_id'].value == 19) {
		regForm.elements['city_id'].value = 61;
		regForm.elements['city'].value = res['value'];
	}

	if (res['code'] && tbField == "country")
		regForm.elements['user_mobile_code'].value = "+" + res['code'];

	cClick();
}

// ----------------------------------------------
// ----------------------------------------------
function saveProfile(profilePage, table, index)
{
//	alert("saveProfile:\n profilePage = " + profilePage + "\n table = " + table + "\n index = " + index);

	var params = "";
	if (profilePage == 5) {
		params = "table="+table;
		params += "&index="+index;
		params += "&task=saveSearch";
		new Ajax.Request('/lib/Ajax/ajax.search.php', {method:'post', postBody:params, onSuccess:responseUpdateSearch});
	} else if (profilePage >= 6 && profilePage <=8) {
		if (table == 0) tbField = "country_id";
		else if (table == 1) tbField = "region_id";
		else tbField = "city_id";
		if (profilePage == 6)
			document.forms['quickSearch'].elements[tbField].value = index;
		else if (profilePage == 8)
			document.forms['advSettings'].elements[tbField].value = index;
		else
			document.forms['registration'].elements[tbField].value = index;
		
		params = "table="+table;
		params += "&index="+index;
		params += "&quickSearch=yes";
		if (profilePage == 7)
			params += "&task=saveSearch2";
		else
			params += "&task=saveSearch";

		if (profilePage == 6)
			new Ajax.Request('/lib/Ajax/ajax.search.php', {method:'post', postBody:params, onSuccess:responseSaveQuickSearch});
		else if (profilePage == 8)
			new Ajax.Request('/lib/Ajax/ajax.search.php', {method:'post', postBody:params, onSuccess:responseSaveSettings});
		else
			new Ajax.Request('/lib/Ajax/ajax.search.php', {method:'post', postBody:params, onSuccess:responseSaveRegForm});
	} else {
		params = "profilePage="+profilePage;
		params += "&table="+table;
		params += "&index="+index;
		params += "&task=saveProfile";
		
		if (profilePage == 2 && table < 2) {
			if (table == 0) {
				document.forms['profile2'].elements['country'].value = index;
				document.forms['profile2'].elements['region'].value = '';
			}
			if (table == 1)
				document.forms['profile2'].elements['region'].value = index;
			new Ajax.Request('/lib/Ajax/ajax.profile.save.php', {method:'post', postBody:params, onSuccess:responseUpdateProfile});
		}
		else
			new Ajax.Request('/lib/Ajax/ajax.profile.save.php', {method:'post', postBody:params, onSuccess:responseUpdateProfile});
	}
}

// ----------------------------------------------

function saveSettingsPeriod()
{
	var formSettings = document.forms['advSettings'];
	if (formSettings.elements['period'].checked)
		period = 1;
	else
		period = 0;
	var params = "period="+period;
	params += "&task=saveSettingsPeriod";
	new Ajax.Request('/lib/Ajax/ajax.user.update.php', {method:'post', postBody:params, onSuccess:responseSaveSettingsIncome});
}

// ----------------------------------------------

function saveSettingsIncome()
{
	var formSettings = document.forms['advSettings'];
	
	if (formSettings.elements['receive_mail'].checked)
		receive_mail = 1;
	else
		receive_mail = 0;

	if (formSettings.elements['receive_flash'].checked)
		receive_flash = 1;
	else
		receive_flash = 0;

	if (formSettings.elements['receive_visit'].checked)
		receive_visit = 1;
	else
		receive_visit = 0;

/*	var country_id = formSettings.elements['country_id'].value;
	var region_id = formSettings.elements['region_id'].value;
	var city_id = formSettings.elements['city_id'].value;

	var age_up = formSettings.elements['user_income_age_up'].value - 0;
	var age_to = formSettings.elements['user_income_age_to'].value - 0;

	if (   (age_up && age_to && (age_up <= age_to)) 
		|| (age_up && formSettings.elements['user_income_age_to'].value=='') 
		|| (formSettings.elements['user_income_age_up'].value=='' && age_to)
		|| (formSettings.elements['user_income_age_up'].value=='' && formSettings.elements['user_income_age_up'].value=='') ) {
		var params = "age_up="+age_up;
		params += "&age_to="+age_to;

		params += "&country_id="+country_id;
		params += "&region_id="+region_id;
		params += "&city_id="+city_id;
		params += "&receive_mail="+receive_mail;
		params += "&receive_flash="+receive_flash;
		params += "&receive_visit="+receive_visit;
		params += "&task=saveSettingsIncome";
		new Ajax.Request('/lib/Ajax/ajax.user.update.php', {method:'post', postBody:params, onSuccess:responseSaveSettingsIncome});
	} else {
		if (language == "rus")
			createMyPopupNoMove("Вы неправильно задали возраст<br>для фильтра входящих сообщений.", 300, 237);
		else
			createMyPopupNoMove("Warning:<br>errors have been found in advanced settings.", 300, 237);
	}
*/

		var params = "&receive_mail="+receive_mail;
		params += "&receive_flash="+receive_flash;
		params += "&receive_visit="+receive_visit;
		params += "&task=saveSettingsIncome";
		new Ajax.Request('/lib/Ajax/ajax.user.update.php', {method:'post', postBody:params, onSuccess:responseSaveSettingsIncome});

}

// ----------------------------------------------

function saveFormProfile()
{
	var form_obj = document.forms[0];
	var key = form_obj.name;

	var myObj = Object();
	ref = getCheckboxVal(form_obj, key+'_id[]');

	params = "table="+key;
	params += "&ref="+ref;
	params += "&task=saveFormProfile";
	new Ajax.Request('/lib/Ajax/ajax.profile.save.php', {method:'post', postBody:params, onSuccess:responseUpdateProfile});
}

// ----------------------------------------------
// ----------------------------------------------
// when we want send letter to some user, we save this ID to SESSION
function responseSaveToSession(t)
{
	if (t.responseText == "blockActions2")
		createMyPopup(t.responseText, 0, 237);
	else if (t.responseText == "sendGift")
		document.location.href = serverName + "/gift.php" ;
	else
		document.location.href = serverName + "/message.php" ;
}

// ----------------------------------------------

function saveToSession(id)
{
	params = "send_mail="+id;
	params += "&task=saveToSession";
	new Ajax.Request('/lib/Ajax/ajax.message.update.php', {method:'post', postBody:params, onSuccess:responseSaveToSession});
}

function sendGift(id)
{
	params = "send_mail="+id;
	params += "&send_gift=1";
	params += "&task=saveToSession";

	new Ajax.Request('/lib/Ajax/ajax.message.update.php', {method:'post', postBody:params, onSuccess:responseSaveToSession});
}

// ----------------------------------------------

function responseGoToCredits(t)
{
//	alert(t.responseText);
	var res = eval('(' + t.responseText + ')');

	if (res['result'] == "contactFALSE")
		document.location.href = serverName + "/payment.php";
	else {
		if (res['type'] == "message") {
			saveToSession(res['user_id']);
		} else if (res['type'] == "chat") {
			createChat(res['user_id']);
		} else if (res['type'] == "flash") {
			sendFlash(res['user_id'], res['name_about']);
		}
	}
}

// ----------------------------------------------

function goToCreditsFunc(id, type, name_about)
{
	params = "user_id="+id;
	params += "&type="+type;
	if (name_about && name_about != '')
		params += "&name_about=" + name_about;
	params += "&task=goToCredits";
	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseGoToCredits});
}

// ----------------------------------------------
// generate form to delete personal account
function goToCredits(id, type, name_about)
{
	if (over) cClick();
	
	if (mydrag)
		mydrag.destroy();
	mydrag = null;
		var action_close = " cClick();";

	if (!name_about) {
		var name_about = '';
	}

	x = calculateX();

	if (type == 'gift') {
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=121 valign=bottom class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\">' + SorryZeroPoints1 + ' <b>' + name_about + '</b>' + SorryZeroPoints2 + '.<br><a href=\"javascript: void(0);\" onClick=\"javascript: goToCreditsFunc(' + id + ', \'' + type + '\', \'' + name_about + '\');\" class=\"popup_link\"><b>' + GetCredits + '</b></a>.</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action_close + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	} else {
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=121 valign=bottom class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\">' + SorryNotMatchCriteria + '<br><a href=\"javascript: void(0);\" onClick=\"javascript: goToCreditsFunc(' + id + ', \'' + type + '\', \'' + name_about + '\');\" class=\"popup_link\"><b>' + GetVIPAccess + '</b></a>.</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action_close + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	}
}

// ----------------------------------------------
// ----------------------------------------------

function calculateX()
{
	if (location.href == serverName+"/" || location.href == serverName || location.href == serverName+"/index.php" || location.href == serverName+"/profile.php" || location.href == serverName+"/invite_friend.php")
		x = 585;
	else
		x = 0;
	return x;
}

// ----------------------------------------------
// ----------------------------------------------
// change password system
// create finish popup window
function responseChangePassword(t)
{
	x = calculateX();
	if (t.responseText == "ok") {
		createMyPopupNoMove('changePassw', x, 237);
	} else {
		if (language == "rus") {
			changePass = "Изменение пароля";
			closeW = "Закрыть окно";
		} else {
			changePass = "Password change";
			closeW = "Close window";
		}

		action = " changePassword(); return false;";

		x = calculateX();
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom class=\"popupTop\">' + changePass + '</td></tr><tr><td class=\"popupCenter\"><br>' + t.responseText + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	}
}

// ----------------------------------------------
// send password to mail
function sendPassword()
{
	var form_elt = document.forms['changeMyPassword'];
	var old_pass = form_elt.elements['old_password'].value;
	var new_pass = form_elt.elements['new_password'].value;
	var confirm_pass = form_elt.elements['confirm_password'].value;

	params = "old="+old_pass;
	params += "&new="+new_pass;
	params += "&confirm="+confirm_pass;
	params += "&task=changePassword";
	new Ajax.Request('/lib/Ajax/ajax.user.update.php', {method:'post', postBody:params, onSuccess: responseChangePassword});
}

// ----------------------------------------------
// generate form to change of password
function changePassword()
{
	if (over) cClick();
	
	if (mydrag)
		mydrag.destroy();
	mydrag = null;
	text = "<br><form name='changeMyPassword' class='myForm'><table width=90% border=0 cellspacing=2 cellpadding=2 align=center>";
	text += "<tr><td width=45% align=right class='profile_value'>" + CurrentPassStr + "</td><td align=left><input type='password' name='old_password' maxlenght=100 class='searchForm'></td></tr>";
	text += "<tr><td align=right class='profile_value'>" + NewPasswordStr + "</td><td align=left><input type='password' name='new_password' maxlenght=100 class='searchForm'></td></tr>";
	text += "<tr><td align=right class='profile_value'>" + ConfirmPassStr + "</td><td align=left><input type='password' name='confirm_password' maxlenght=100 class='searchForm'></td></tr>";
	text += "</table></form>";

	var action_change = " sendPassword();";
	var action_close = " cClick();";

	x = calculateX();
	overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom class=\"popupTop\">' + changePass + '</td></tr><tr><td class=\"popupCenter\">' + text + '</td></tr><tr><td height=80 class=\"popupBottom\" align=right valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/button_passw.gif\" border=0 onClick=\"javascript:' + action_change + '\" alt=\"' + passChange + '\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action_close + '\" alt=\"' + closeW + '\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);

	document.forms['changeMyPassword'].elements['old_password'].focus();
}

// ----------------------------------------------
// generate popup window with 6 reasons for try 2gether (payment page)
function payment6reasons()
{
	if (over) cClick();
	
	if (mydrag)
		mydrag.destroy();
	mydrag = null;
	text = "<br>1. Western managers / English company <br>2. Dating site / direct relations <br>3. The most beautiful and loving women in the world <br>4. Advanced dating services <br>5. Best prices <br>6. No-scam policy <br><p style='margin-left:100px; margin-bottom:0;'><a href='/about_us.php' target='_blank' style='color: #000000; text-decoration: underline;'>More about us</a></p>";

	var action_close = " cClick();";

	x = calculateX();
	overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\" align=left style="padding-left: 60px;">' + text + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action_close + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
}

// ----------------------------------------------
// ----------------------------------------------
// change e-mail in system
// create finish popup window
function responseChangeMail(t)
{
	x = calculateX();

	if (t.responseText == "ok") {
		createMyPopupNoMove('changeMail', x, 237);
	} else {

		action = " changeMail(); return false;";
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom class=\"popupTop\">' + changeMailText + '</td></tr><tr><td class=\"popupCenter\"><br>' + t.responseText + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	}
}

// ----------------------------------------------
// send password to mail
function sendMail()
{
	var form_elt = document.forms['changeMyMail'];
	var e_mail = form_elt.elements['new_email'].value;
	var confirm_pass = form_elt.elements['confirm_password'].value;

	params = "mail="+e_mail;
	params += "&confirm_pass="+confirm_pass;
	params += "&task=changeMail";
	new Ajax.Request('/lib/Ajax/ajax.user.update.php', {method:'post', postBody:params, onSuccess: responseChangeMail});
}

// ----------------------------------------------
// generate form to change of e-mail
function changeMail()
{
	if (over) cClick();
	
	if (mydrag)
		mydrag.destroy();
	mydrag = null;

	text = "<br><form name='changeMyMail' class='myForm'><table width=90% border=0 cellspacing=2 cellpadding=2 align=center>";
	text += "<tr><td width=45% align=right class='profile_value'>" + NewEmailString + "</td><td align=left><input type='text' name='new_email' maxlenght=100 class='searchForm'></td></tr>";
	text += "<tr><td align=right class='profile_value'>" + CurrentPassStr + "</td><td align=left><input type='password' name='confirm_password' maxlenght=100 class='searchForm'></td></tr>";
	text += "</table></form>";

	var action_change = " sendMail();";
	var action_close = " cClick();";

	x = calculateX();
	overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom class=\"popupTop\">' + changeMailText + '</td></tr><tr><td class=\"popupCenter\">' + text + '</td></tr><tr><td height=80 class=\"popupBottom\" align=right valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/button_mail.gif\" border=0 onClick=\"javascript:' + action_change + '\" alt=\"' + mailChange + '\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action_close + '\" alt=\"' + closeW + '\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	document.forms['changeMyMail'].elements['new_email'].focus();
}


// ----------------------------------------------
// ----------------------------------------------
// generate form to send new confrimation mail

// ----------------------------------------------
function responseValidationMail(t)
{
	if (t.responseText == "ok") {
		createMyPopupNoMove('msgConfirmReg2', 0, 237);
	} else {
		action = " resendValidationMail(); return false;";
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom class=\"popupTop\">' + ActivateAccoun + '</td></tr><tr><td class=\"popupCenter\"><br>' + t.responseText + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, 0, RELY, 237);
	}
}

// ----------------------------------------------
function responseValidationMail2(t)
{
	if (t.responseText == "ok") {
		document.location.href = serverName + "/confirm_signup.php";
//		createMyPopupNoMove('msgConfirmReg2', 601, 317);
	} else {
		action = " cClick(); ";
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\" valign=\"bottom\">' + ActivateAccoun + '</td></tr><tr><td class=\"popupCenter\"><br>' + t.responseText + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, 601, RELY, 317);
	}
}

// ----------------------------------------------

function sendValidationMail()
{
	var form_elt = document.forms['new_confirm'];
	var user_mail = form_elt.elements['user_mail'].value;
	var confirm_pass = form_elt.elements['confirm_password'].value;

	var err = "";

	if (user_mail == "") {
		err = ErrorEmptyEmai;
	} else if (confirm_pass == "") {
		err = ErrorCurrePass;
	}

	if (err != "") {
		err = "<br>" + err;
		action = " resendValidationMail(); ";

		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\" valign=\"bottom\">' + ActivateAccoun + '</td></tr><tr><td class=\"popupCenter\">' + err + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, 0, RELY, 237);
	} else {
		params = "mail="+user_mail;
		params += "&confirm_pass="+confirm_pass;
		params += "&task=sendValidationMail";
		new Ajax.Request('/lib/Ajax/ajax.user.update.php', {method:'post', postBody:params, onSuccess: responseValidationMail});
	}
}

// ----------------------------------------------

function sendValidationMail2()
{
	var form_elt = document.forms['new_confirm'];
	var user_mail = form_elt.elements['user_mail'].value;

	var err = "";

	if (user_mail == "") {
		err = ErrorEmptyEmai;
	} 

	if (err != "") {
		err = "<br>" + err;
		action = " cClick(); ";

		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\" valign=\"bottom\">' + ActivateAccoun + '</td></tr><tr><td class=\"popupCenter\">' + err + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, 601, RELY, 317);
	} else {
		params = "mail="+user_mail;
		params += "&task=sendValidationMail";
		new Ajax.Request('/lib/Ajax/ajax.user.update.php', {method:'post', postBody:params, onSuccess: responseValidationMail2});
	}
}

// ----------------------------------------------

function resendValidationMail()
{
	if (over) cClick();
	
	if (mydrag)
		mydrag.destroy();
	mydrag = null;

	text = "<br>"  + WeSendConfirma;
	text += "<br><br><form name='new_confirm' class='myForm'><table width=90% border=0 cellspacing=2 cellpadding=2 align=center>";
	text += "<tr><td width=45% align=right class='profile_value'>" + NewEmailString + "</td><td align=left><input type='text' name='user_mail' maxlenght=100 class='searchForm'></td></tr>";
	text += "<tr><td align=right class='profile_value'>" + CurrentPassStr + "</td><td align=left><input type='password' name='confirm_password' maxlenght=100 class='searchForm'></td></tr>";
	text += "</table></form>";

	var action_change = " sendValidationMail();";
	var action_close = " cClick();";

	x = calculateX();
	overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 valign=bottom class=\"popupTop\">' + ActivateAccoun + '</td></tr><tr><td class=\"popupCenter\">' + text + '</td></tr><tr><td height=80 class=\"popupBottom\" align=right valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/button_mail.gif\" border=0 onClick=\"javascript:' + action_change + '\" alt=\"' + mailChange + '\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action_close + '\" alt=\"' + closeW + '\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	if (document.forms['new_confirm'])
		document.forms['new_confirm'].elements['user_mail'].focus();
}

// ----------------------------------------------
// ----------------------------------------------
// send invite to friend

function createInviteForm()
{
	params = "task=createInviteToFriend";
	new Ajax.Request('/lib/Ajax/ajax.contact.message.php', {method:'post', postBody:params, onSuccess: responseInviteToFriend});
}

// ----------------------------------------------

function responseInviteToFriend(t)
{
	if (t.responseText == "sendRequestDeleteAccountPoints") {
		x = calculateX();
		createMyPopupNoMove("sendRequestDeleteAccountPoints", x, 237);
	} else if (t.responseText == "sendRequestDeleteAccount") {
		if (over) cClick();
		document.location.href = serverName + '/logout_page.php';
	} else if (t.responseText == "sendRequestDeleteAccountError") {
		err = "<b>" + ErrorsFoundFor + "</b><br><br>" + IncorrectlyEma + "<br>";
		action = "deleteAccount();";
		x = calculateX();
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\">' + err + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	} else if (t.responseText == "sendMailFakeProfile") {
		x = calculateX();
		createMyPopupNoMove("sendMailFakeProfile", x, 237);
	}else {
		contentInviteText = document.getElementById("content2");
		contentInviteText.innerHTML = t.responseText;
	}
}

// ----------------------------------------------
function responseInviteToFriendFirst(t)
{
	document.location.href = serverName + '/invite_friend.php';
}
// ----------------------------------------------

function sendInviteToFriendFirst()
{
	var friendMail = document.forms['inviteFrFirst'].elements['friendMail'].value;
	var err = "";

	if (friendMail == "") {
		err += EnterEmailFrie + ".";
	} else if ( ! pochta(friendMail) ) {
		err += "- " + IncorrectlyEma;
	}

	if (err != "") {
		err = "<b>" + ErrorsFoundFor + "</b><br><p align=left>" + err;

		action = "cClick();";
		x = calculateX();
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\">' + err + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	} else {
		params = "friendMail="+friendMail;
		params += "&task=sendInviteToFriendFirst";
		new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess: responseInviteToFriendFirst});
	}
}

// ----------------------------------------------

// ADVANCED VERSION 

function sendInviteToFriend()
{
	var form_elt = document.forms['inviteFr'];
	var friendFirstname = form_elt.elements['friendFirstName'].value;
	var friendLastname = form_elt.elements['friendLastName'].value;
	var friendMail = form_elt.elements['friendMail'].value;
	var textMsg = form_elt.elements['textMsg'].value;

	var err = "";

	if (friendFirstname == "") {
		err = EnterNameFrien + ".";
	}

	if (friendMail == "") {
		if (err != "")
			err += "<br><br>";

		err += EnterEmailFrie + ".";

	} else if ( ! pochta(friendMail) ) {
		if (err != "")
			err += "<br><br>";

			err += "- " + IncorrectlyEma;
	}

	allText = textMsg.replace(/&(lt|gt);/g, function (strMatch, p1){
		 	return (p1 == "lt")? "<" : ">";
	});
	textMsg = allText.replace(/<.*script.*(>|$)/g, "");

	if (err != "") {
		err = "<b>" + ErrorsFoundFor + "</b><p align=left>" + err;
		action = "cClick();";
		x = calculateX();
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\">' + err + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	} else {
		params = "friendFirstName="+friendFirstname;
		params += "&friendLastName="+friendLastname;
		params += "&friendMail="+friendMail;
		params += "&msg="+textMsg;
		params += "&task=sendInviteToFriend";
		new Ajax.Request('/lib/Ajax/ajax.contact.message.php', {method:'post', postBody:params, onSuccess: responseInviteToFriend});
	}
}

// ----------------------------------------------

function sendInviteToFriends()
{
	var form_elt = document.forms['inviteFr'];
	var err = "";
	var myArray = Array();
	var in_ar = 0;

	for (i=1; i<=10; i++) {
		var err_user = "";
		if (document.getElementById('friend_'+i).style.display != "none" && err == "") {
			var friendFirstname = form_elt.elements['friendFirstName' + i].value;
			var friendLastname = form_elt.elements['friendLastName' + i].value;
			var friendMail = form_elt.elements['friendMail' + i].value;

			if (friendFirstname != "" || friendMail != "") {
				if (friendFirstname == "") {
					err_user = EnterNameFrien + " " + i + ".<br><br>";
				}
		
				if (friendMail == "") {
					err_user += EnterEmailFrie + " " + i + ".<br><br>";
				} else if ( ! pochta(friendMail) ) {
					err_user += "- " + IncorEmailFrie + " " + i + ".<br><br>";
				}

				if (err_user == "") {
					myObj = Object();
					myObj['friendFirstname'] = addOneSlash(friendFirstname);
					myObj['friendLastname'] = addOneSlash(friendLastname);
					myObj['friendMail'] = addOneSlash(friendMail);
					myArray.push(myObj);
					in_ar = 1;
				} else
					err = err_user;
			}
		}
	}

	if (in_ar == 0) {
		err = EnterContactsF;
	}
	
	var textMsg = form_elt.elements['textMsg'].value;

	allText = textMsg.replace(/&(lt|gt);/g, function (strMatch, p1){
		 	return (p1 == "lt")? "<" : ">";
	});
	textMsg = allText.replace(/<.*script.*(>|$)/g, "");

	if (err != "") {
		err = "<b>" + ErrorsFoundFo2 + "</b><br><p align=left>" + err;
	

		action = "cClick();";
		x = calculateX();
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\">' + err + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	} else {
		data_friends = myArray.toJSON();
		params = "data_friends="+data_friends;
		params += "&msg="+textMsg;
		params += "&task=sendInviteToFriends";
		new Ajax.Request('/lib/Ajax/ajax.contact.message.php', {method:'post', postBody:params, onSuccess: responseInviteToFriend});
	}
}

// ----------------------------------------------
// send request for close of account
function sendMailRequestDeleteAccount()
{
	var form_elt = document.forms['delAccount'];
	var user_mail = form_elt.elements['user_mail'].value;
	var allText = form_elt.elements['user_comment'].value;

	allText = allText.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
	user_comment = allText.replace(/<.*script.*(>|$)/g, "");

	var err = "";

	if ( ! pochta(user_mail) ) {
		err = "<b>" + ErrorsFoundFor + "</b><br><br>" + IncorrectlyEma + "<br>";

		action = "deleteAccount();";
		x = calculateX();
		overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=101 class=\"popupTop\"></td></tr><tr><td class=\"popupCenter\">' + err + '</td></tr><tr><td height=80 class=\"popupBottom\" align=center valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action + '\" alt=\"' + closeW + '\"></a></td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);

	} else {
		params = "user_mail=" + user_mail;
		params += "&user_comment=" + user_comment;
		params += "&task=sendRequestDeleteAccount";
		
//		alert(params);
		new Ajax.Request('/lib/Ajax/ajax.contact.message.php', {method:'post', postBody:params, onSuccess: responseInviteToFriend});
	}
}

// ----------------------------------------------
// generate form to delete personal account
function deleteAccount()
{
	if (over) cClick();
	
	if (mydrag)
		mydrag.destroy();
	mydrag = null;
	
	var text = "<br>" + CloseYourAccou + "<br>";
		text += "<br><form name='delAccount' class='myForm'><table width=90% border=0 cellspacing=2 cellpadding=2 align=center>";
		text += "<tr><td width=45% align=right class='profile_value'>" + EnterEmailStr2 + "</td><td align=left><input type='text' name='user_mail' class='searchForm'></td></tr>";
		text += "<tr height=25><td colspan=2 align=center class='profile_value'>" + DecidedUnregis + "</td></tr>";
		text += "<tr><td colspan=2 align=center class='profile_value'><textarea name='user_comment' rows='3' cols='3' style='width:90%;'></textarea></td></tr></table></form>";

	var action_change = " sendMailRequestDeleteAccount();";
	var action_close = " cClick();";
	x = calculateX();
	overlib('<div id=\"popupWin2\"><table border=0 width=100% cellspacing=0 cellpadding=0><tr><td height=121 valign=bottom class=\"popupTop\">' + sendRequestDeleteAccountText + '</td></tr><tr><td class=\"popupCenter\">' + text + '</td></tr><tr><td height=80 class=\"popupBottom\" align=right valign=middle><a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/button_close_account.gif\" border=0 onClick=\"javascript:' + action_change + '\" alt=\"' + CloseAccountSt + '\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript: void(0);\"><img src=\"/img/' + language + '/popup_close.gif\" border=0 onClick=\"javascript:' + action_close + '\" alt=\"' + closeW + '\"></a>' + spaceSymb_1 + '</td></tr></table></div>', STICKY, CENTER, WIDTH, 382, FIXX, x, RELY, 237);
	document.forms['delAccount'].elements['user_mail'].focus();
}

// ----------------------------------------------
// Create popup window with confirm of ZERO credits
function responseBlockActions(t)
{
	createMyPopup(t.responseText, 0, 237);
}

// ----------------------------------------------
function blockActions()
{
	params = "task=blockActions";
	new Ajax.Request('/lib/Ajax/ajax.content.upload.php', {method:'post', postBody:params, onSuccess:responseBlockActions});
}

// ----------------------------------------------
// Chat

function activeChat(user_id)
{
	if (document.createChatForm.createChatVar.value == '1') {
		if (chat)
			chat.focus();
	}
}

// ----------------------------------------------

function activeChat2(t)
{
	if (document.createChatForm.createChatVar.value == '1') {
		chat.focus();
	}
}

// ----------------------------------------------

function responseCreateChat(t)
{		
	r = 0;

	if (t.responseText == "blockActions") {
		createMyPopup("blockActions", 0, 237);
	}	
	else if (t.responseText == "blockActions2") {
		createMyPopup("blockActions2", 0, 237);
	} else {
		var res = t.responseText;

		if (chat && chat.name == 'Chat') {
			chat.location = serverName + '/chat/index.php?id=' + res;
			r = 1;
//			chat.focus();
		} else {
			chat = window.open(serverName + '/chat/index.php?id='+res,'Chat','location=no, titlebar=no, menubar=no, toolbar=no, status=no, resizable=no, scrollbars=no, width='+(screen.availWidth - 10).toString()+', height='+(screen.availHeight - 60).toString()+', top=0, left=0');
			if (!chat) {
				createMyPopup("blockPopup", 0, 237);
			} else {
				r = 1;
				//chat.focus();
			}
		}
	}

	document.createChatForm.createChatVar.value = r;
}

// ----------------------------------------------

function createChat(id)
{
	params = "id="+id;
	params += "&task=checkBlockActions";
	new Ajax.Request('/lib/Ajax/ajax.chat.upload.php', {method:'post', postBody:params, onSuccess:responseCreateChat, onComplete:activeChat2});
}

// ----------------------------------------------
