
// Скрипты главной страницы
function plusClicked(sel, msel) {
	var cursel = sel.selectedIndex;
	var i, exists;
	if (sel.options[cursel].value >= 0){
		// Убираем выделение
		for (i=0; i<msel.length; i++){
			msel.options[i].selected = false;
		}
		// Проверяем - имеется ли уже в наличии такой язык
		var f = false;
		for (i=0; i<msel.length; i++){
			if (msel.options[i].value == sel.options[cursel].value){
				f = true;
				exists = i;
				break;
			}
		}
		if (!f){
			// Всё ок, добавляем в список
			msel.options[msel.length] = new Option(sel.options[cursel].text, sel.options[cursel].value, false, true);
		} else {
			// Просто подсвечиваем уже существующую запись
			msel.options[exists].selected = true;
		}
	}
}

function minusClicked(sel, msel) {
	var i;
	for (i=msel.length; i>=0; i--){
		if ((msel.options[i] != null)&&(msel.options[i].selected)) {
			msel.options[i] = null;
		}
	}
}

// Упаковка содержимого мультиселекта
function multipack(msel, hid) {
	var i;
	var ret = '';
	for (i=0; i<msel.length; i++){
		ret += msel.options[i].value;
		if (i < msel.length-1){
			ret += '#|#';
		}
	}
	hid.value = ret;
}

function addIfEmpty(sel, msel) {
	if (msel.length <= 0){
		plusClicked(sel, msel);
	}
}

function ShowProfileOnID(user_id, but) {
	var win = window.open('showprofile.php?userid=' + user_id + ((but)?'&but=1':''), 'w', 'statusbar=no,toolbar=no,width=500,height=400');
//	win.focus();
}

// Функции E-mail
// Инициирование удаления писем
function doletters(form, num, act) {
	// Проверяем наличие хотя бы одного отмеченного письма
	var flag = 0;
	for (var cur = 0; cur < num; cur ++){
		if (form.elements["chboxN" + cur].checked){
			flag = 1;
			break;
		}
	}
	if (flag == 0){
		alert("Please, check at least one letter in mailbox");
	} else {
		form.m.value = act;
		form.submit();
	}
}