var timer1;
var popmv = 0;
var ajaks = false;
if (window.XMLHttpRequest) {  
	ajaks = new XMLHttpRequest();
} else if (window.ActiveXObject) {   
    try {
		ajaks = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
		try {
			ajaks = new ActiveXObject("Microsoft.XMLHTTP");
    	} catch (failed) {
      		ajaks = false;
      	}
	}
}

function Ajax(file, get, xdiv, add) {
    now_time = new Date();
    unix = now_time.getTime();
    if (encodeURIComponent) {
        get = encodeURIComponent(get);
    } else {
        get = escape(get);
    }
    get = get.replace(/%3D/g,"=");
    get = get.replace(/%26/g,"&");
    url = file + '?&first_time=false&' + unix + get;
    if(xdiv == "") xdiv = 'div';
    if(ajaks) {
        var obj = gEl(xdiv);
        ajaks.open("GET", url);   
        ajaks.onreadystatechange = function() {
            if  (ajaks.readyState == 4 && ajaks.status == 200) {
                if (obj.type == "textarea") {
                    obj.value = AfterAjax(ajaks.responseText, add, xdiv);
                } else {
                    obj.innerHTML = AfterAjax(ajaks.responseText, add, xdiv);
                    if (obj.id == 'popUpJs') mb_CreateFileField();
                }
            }
        }
    }
    ajaks.send(null);
}

function AfterAjax(text, add, xdiv) {
	newtext = text;
	if (add == 'follow_search') {
		newtext = mbFollowSearchResult(text);
	}
	if (add == 'mb_get_more') {
		newtext = mbGetMoreResult(text, xdiv);
	}
	if (add == 'menu_message') {
		newtext = mbMenuMessage(text, xdiv);
	}
	return newtext;
}

function gEl(name) {
	return document.getElementById(name);
}

function gElv(name) {
	return document.getElementById(name).value;
}

function whatIsBrowser() {
	browserName = false;
	tmpv = window.navigator.userAgent;
	if (tmpv.indexOf('MSIE') != -1) browserName = 'IE';
	if (tmpv.indexOf('Firefox') != -1) browserName = 'Firefox';
	if (tmpv.indexOf('Opera') != -1) browserName = 'Opera';
    if (tmpv.indexOf('Safari') != -1) browserName = 'Safari';
    return browserName;
}

function mbDisplayElement(name) {
	if(obj = gEl(name)) {
		obj2 = gEl('mheader');
		if (obj.style.display == 'none') {
			//obj2.style.minHeight = '158px';
			obj.style.display = 'block';
		} else {
			//obj2.style.minHeight = '108px';
			obj.style.display = 'none';
		}
	}
	
}

function mbDisplay(name) {
	if(obj = gEl(name)) {
		if (obj.style.display == 'none') {
			obj.style.display = 'block';
		} else {
			obj.style.display = 'none';
		}
	}
}

function mb_max_length() {
	obj_cnt = gEl('ta_cnt');
	obj_ta = gElv('ta_msg');
	
	obj_as = gEl('a_submit');
	obj_ds = gEl('d_submit');
	
	obj_tmp = obj_ta;
	obj_tmp = obj_tmp.replace('[:img]', '');
	obj_tmp = obj_tmp.replace('[:music]', '');
	obj_tmp = obj_tmp.replace('[:df]', '');
	obj_tmp = obj_tmp.replace('[:link]', '');
	cnt = 150 - obj_tmp.length;
	if (cnt <= -1) {
		obj_cnt.className = 'dl_c1';
		obj_as.className = 'dl_blind dl_dn';
		obj_ds.className = 'dl_blind_not_active';
	} else {
		obj_cnt.className = '';
		obj_ds.className = 'dl_blind_not_active dl_dn';
		obj_as.className = 'dl_blind';
	}
	obj_cnt.innerHTML = cnt;
}

function mbPostBgOn(id) {
    obj1 = gEl('fav_'+id);
    obj2 = gEl('rew_'+id);
    obj1.style.display = 'block';
    obj2.style.display = 'block';
}

function mbPostBgOff(id) {
    obj1 = gEl('fav_'+id);
    obj2 = gEl('rew_'+id);
    obj1.style.display = 'none';
    obj2.style.display = 'none';
}

function mbFavBgOn(id) {
    obj1 = gEl('rem_'+id);
    obj1.style.display = 'block';
}

function mbFavBgOff(id) {
    obj1 = gEl('rem_'+id);
    obj1.style.display = 'none';
}

function mbPostRewrite(id, msg_id, firstname, ajax) {
	st = 0;
	if (obj1 = gEl('r_uid')) {
		st = 1;
	}
	if (obj2 = gEl('ta_msg')) {
		st = 1;
	}
	if (obj3 = gEl('to_fn')) {
		st = 1;
	}
	if (obj4 = gEl('r_mid')) {
		st = 1;
	}
	if (st == 1) {
		obj2.focus();
		obj1.value = id;
		obj4.value = msg_id;
		if (firstname) {
			cancel_lnk = '&nbsp;&nbsp;<span class="dl_fs10 dl_cp dl_c2 dl_n" onclick="mbPostRewriteCancel();">[X]</span>';
			to_arrow = '<img src="http://media.lichiko.com/images/ic_escape1.gif" style="height:14px; margin:0px;"/>';
			obj3.innerHTML = to_arrow + firstname + cancel_lnk;
		}
		document.documentElement.scrollTop = 0;
	} else {
		if (ajax) {
			mb_PageOpen('main', false, 'ruid='+id+'&rmid='+msg_id);
		} else {
			location.href = 'http://lichiko.com?ruid=' + id + '&rmid=' + msg_id;
		}
	}
}

function mbPostRewriteCancel() {
	st = 0;
	if (obj1 = gEl('r_uid')) {
		st = 1;
	}
	if (obj2 = gEl('user_id')) {
		st = 1;
	}
	if (obj3 = gEl('to_fn')) {
		st = 1;
	}
	if (obj4 = gEl('r_mid')) {
		st = 1;
	}
	if (st == 1) {
		obj1.value = obj2.value;
		obj4.value = 0;
		obj3.innerHTML = '';
	}
}

function mbPostBgOnL(id) {
    obj1 = gEl('favL_'+id);
    obj2 = gEl('rewL_'+id);
    obj1.style.display = 'block';
    obj2.style.display = 'block';
}

function mbPostBgOffL(id) {
    obj1 = gEl('favL_'+id);
    obj2 = gEl('rewL_'+id);
    obj1.style.display = 'none';
    obj2.style.display = 'none';
}

function showUserInfoEdit() {
    obj1 = gEl('ui_e');
    obj2 = gEl('ui_s');
    obj2.className = 'n_tr n_fi n_dn';
    obj1.className = 'n_tr';
}

function hideUserInfoEdit() {
    obj1 = gEl('ui_e');
    obj2 = gEl('ui_s');
    obj2.className = 'n_tr n_fi';
    obj1.className = 'n_tr n_dn';
}

function mb_play_music(filepath, divname, start) {
	var so = new SWFObject('http://media.lichiko.com/mediaplayer/mediaplayer.swf','player','0','0','8');
	pw = "0";
	ph = "0";
	
	so.addParam("allowfullscreen","true");
	so.addParam("bgcolor","#FFFFFF");
	so.addVariable('file', filepath);
	so.addVariable('lightcolor','0x557722');
	so.addVariable('searchbar','false');
	so.addVariable('autostart',start);
	so.addVariable('screencolor','0xFFFFFF');
	so.addVariable("width",pw);
	so.addVariable("height",ph);
	so.write(divname);

}

function mbMPlay(filepath, dur, id, cnt) {
	obj = gEl('sng_' + id);
	if(obj.title == 'Pause') {
		mbMPause(id, false);
		return false;
	}
	
	cnt++;
	for(i=1; i<cnt; i++) {
		mbMPause(i, true);
	}
	
	mb_play_music(filepath, 'mediaplayer', true);
	
	obj = gEl('bsng_' + id);
	obj.className = 'dl_item dl_nowPlay';
	obj = gEl('sng_' + id);
	obj.title = 'Pause';
	obj.innerHTML = 'Pause';
	obj = gEl('sbar_' + id);
	obj.style.width = '0%';
	
	if (dur != 0) {
		mbMStatusBar(dur, id, -1);
	}
}

function mbMPause(id, sb) {
	if (gEl('bsng_' + id)) {
		obj = gEl('bsng_' + id); 
		obj.className = 'dl_item';
		obj = gEl('sng_' + id);
		obj.title = 'Play';
		obj.innerHTML = 'Play';
		
		mbMClearSB();
		
		if (sb) {
			obj = gEl('sbar_' + id); 
			obj.style.width = '0%';
		} else {
			mb_play_music('', 'mediaplayer', false);
		}
	}
}

function mbMStatusBar(duration, id, pos) {
	step = duration * 10;
	
	pos = pos * 1;
	newpos = pos + 1;
	obj = gEl('sbar_' + id); 
	obj.style.width = newpos + '%';
	
	if (newpos >= 100) {
		mbMPause(id, false);
		
		nid = (id * 1) + 1;
		if (gEl('sng_' + nid)) {
			obj = gEl('sng_' + nid);
			obj.onclick();
		} else {
			nid = 1;
			obj = gEl('sng_' + nid);
			obj.onclick();
		}
		
	} else {
		timer1 = setTimeout('mbMStatusBar(' + duration + ', ' + id + ', ' + newpos + ')', step);
	}
}

function mbMClearSB() {
	clearTimeout(timer1);
}

function mb_select_song(id) {
	obj = new Array;
	for (i=1; i<6; i++) {
		obj[i] = gEl('song_' + i);
		if (id == i) {
			obj[i].className = 'n_b n_cp';
		} else {
			obj[i].className = 'n_cp';
		}
	}
	
}

function mb_helpStartFunc(num) {
	idt = setTimeout('mb_helpShowDV('+num+')', 1000);
}

function mb_helpStopFunc() {
	clearTimeout(idt);
}

function mb_helpShowDV(num) {
	elm = document.getElementById('lms_' + num);
	return hs.htmlExpand(elm, { contentId: 'ums_' + num } );
}

function mb_helpCStartFunc(num) {
	idtc = setTimeout('mb_helpHideDV('+num+')', 500);
}

function mb_helpCStopFunc() {
	if (typeof(idtc) != 'undefined') clearTimeout(idtc);
}

function mb_helpHideDV(num) {
	elm = document.getElementById('ums_' + num);
	return hs.close(elm);
}

function mb_ie() {
	obj1 = gEl('frm_ms');
	ag = navigator.userAgent;
	num1 = ag.indexOf('MSIE 5');
	num2 = ag.indexOf('MSIE 6');
	if (num1 > 0 || num2 > 0) obj1.className = 'n_mk2';
}

function mb_top_frame(frame_path) {
	if (obj = parent.document.getElementById('top_frm')) {
		c_def = 'n_br0 n_w20 n_h24 n_of';
		
		v1 = '/help';
		s1 = 5;
		c1 = 'n_br0 n_w20 n_h27 n_of';
		res1 = frame_path.substr(0, s1);
		
		if (res1 == v1) {
			obj.className = c1;
		} else {
			obj.className = c_def;
		}
	}
}

function mbFollowSearchResult(text) {
	if (text == '') {
		if (obj = gEl('fw_pager')) obj.style.display = 'none';
		return '<div class="n_lnk3 n_tc"><br />Ничего не найдено!<br /></div>';
	}
	newtext = '';
	a = text.split(",,,");
	k = 0;
	for(i=0; i<a.length; i++) {
		b = a[i].split(",,");
		c = new Array();
		for(j=0; j<b.length; j++) {
			c[j] = b[j].substr(1, b[j].length - 2);
		}
		
		m_id = gEl('member_id');
		if (!c[3]) c[3] = 'http://media.lichiko.com/data/user2.png';
		if (c[4] == 't') c[4] = 'online'; else c[4] = '&nbsp;';
		if (c[5] == 'f') c[5] = '<div id="flw_' + c[0] + '" class="n_fs10 n_tl n_c11 n_lnk14"><a href="#" onclick="Ajax(\'http://lichiko.com/ajax.php\', \'&st=mb_add_follow&read=' + m_id.value + '&write=' + c[0] + '\', \'flw_' + c[0] + '\');">читать</a></div>'; else c[5] = '';
		
		newtext += '<div class="n_fl n_tl n_w25">';
		newtext += '<div class="n_fl n_pad1">';
		newtext += '<a title="' + c[6] + '" target="_top" href="http://lichiko.com/' + c[1] + '"><img border="0" src="' + c[3] + '" class="n_hw1"/></a>';
		newtext += '<div class="n_fs10 n_c1 n_tc">' + c[4] + '</div>';
		newtext += '</div>';
		newtext += '<div class="n_tl">';
		newtext += '<div class="n_lnk13 n_fs14"><a title="' + c[6] + '" target="_top" href="http://lichiko.com/' + c[1] + '">' + c[2] + '</a></div>';
		newtext += '<div class="n_lnk16 n_fs10"><a onclick=\'window.open("/messenger.php?login=' + c[1] + '","MessengerWindow","width=600,height=700,scrollbars=yes");return false;\' href="#">Личное сообщение</a></div>';
		newtext += c[5];
		newtext += '</div>';
		newtext += '</div>';
		k++;
		
		if (k % 3 == 0) newtext += '<div class="n_cb n_fs1 n_h17">&nbsp;</div>';
		if (k >= 54) break;
	}
	if (k % 3 != 0) newtext += '<div class="n_h9 n_cb">&nbsp;</div>';
	
	if (obj = gEl('fw_pager')) {
		if (k < 54) {
			obj.style.display = 'none';
		} else {
			obj.style.display = 'block';
		}
	}
	
	return newtext;
}

function mbULpos(type) {
	obj = gEl('ULpos');
	mp = obj.style.marginLeft;
	mp = mp.substr(0, mp.indexOf('px'));
	mp = mp * 1;
	if (type == 'left') {
		if (mp < 0) {
			pos = mp += 78;
			obj.style.marginLeft = pos + 'px';
		}
	} else if (type == 'right') {
		if (mp > -5964) {
			pos = mp -= 78;
			obj.style.marginLeft = pos + 'px';
		}
	}
	
	obj_l = gEl('ULlarr');
	if (mp >= 0) {
		obj_l.className = 'dl_larr dl_lnone';
	} else {
		obj_l.className = 'dl_larr';
	}
	obj_r = gEl('ULrarr');
	if (mp <= -5964) {
		obj_r.className = 'dl_rarr dl_rnone';
	} else {
		obj_r.className = 'dl_rarr';
	}
}

function mbSlider(type) {
	ar = Array();
	if (type == 'left') {
		ar[1] = 3;
		ar[2] = 1;
		ar[3] = 2;
	} else if (type == 'right') {
		ar[1] = 2;
		ar[2] = 3;
		ar[3] = 1;
	}
	for(i=1; i<4; i++) {
		//obj = gEl('TPslide');
		//suf = ar[i];
		//if(ar[i] == 1) suf = '';
		//obj.className = 'dl_slideShow' + suf;
		
		obj = gEl('slide' + i);
		if (obj.style.display == 'block') {
			obj.style.display = 'none';
			obj = gEl('slide' + ar[i]);
			obj.style.display = 'block';
			break;
		}
	}
}

function mbMlist(type) {
	a = 1;
}

function mbShowPhoto(num, pl) {
	obj = gEl('commentsBlock');
	obj.innerHTML = '';
	id = pl[num]['id'];
	photo = pl[num]['photo'];
	title = pl[num]['title'];
	comment = pl[num]['cnt'];
	obj = gEl('winphoto');
	obj.src = photo;
	obj = gEl('wintitle');
	obj.innerHTML = title + '&nbsp;';
	if (gEl('etitle')) {
		obj_e = gEl('etitle');
		obj_e.value = title;
	}
	obj = gEl('nowPhoto');
	obj.value = num;
	if (gEl('saveID')) {
		obj = gEl('saveID');
		obj.value = id;
	}
	if (gEl('delID')) {
		obj = gEl('delID');
		obj.value = id;
	}
	if (gEl('commentCnt')) {
		obj = gEl('commentCnt');
		obj.innerHTML = comment;
	}
	obj = gEl('nowIdPhoto');
	obj.value = id;
	obj = gEl('linkPhotoId');
	obj.value = 'http://lichiko.com/photo?phid=' + id;
}

function mbPhotoSlider(type, pl) {
	obj = gEl('nowPhoto');
	num = obj.value;
	num = num * 1;
	
	cnt = 0;
	while(true) {
		if (pl[cnt + 1]) {
			cnt++;
		} else break;
	}
	//cnt = pl.length - 1;
	if (type == 'left') {
		if (num == 1) {
			num = cnt;
		} else {
			num = num - 1;
		}
	} else if (type == 'right') {
		if (num == cnt) {
			num = 1;
		} else {
			num = num + 1;
		}
	}
	mbShowPhoto(num, pl);
}

function mbMoveFolder(num) {
	obj = gEl('moveSelect');
	obj.selectedIndex = num;
	obj = gEl('moveFU');
	ret = 'mailbox';
	//if (num == 2) ret = 'mailbox_black';
	//if (num == 3) ret = 'mailbox_trash';
	mb_FormSubmit(obj, ret);
}

function mbExmLink() {
	obj1 = gEl('loginUR');
	obj2 = gEl('exm_link');
	obj2.innerHTML = 'lichiko.com/' + obj1.value;
}

function mbPhotoPagerAct(id, type, plcount) {
	obj1 = gEl('PPleft');
	obj2 = gEl('PPright');
	obj3 = gEl('now_page');
	
	page = obj3.value;
	page = page * 1;
	max_page = Math.ceil(plcount / 25);
	
	if (type == 'left') {
		if (obj3.value == 1) {
			page = max_page;
		} else {
			page = page - 1;
		}
	} else if (type == 'right') {
		if (max_page != obj3.value) {
			page = page + 1;
		} else {
			page = 1;
		}
	}
	
	mb_UniClearContent('list_block');
	Ajax('http://lichiko.com/ajax.php', '&st=mb_photo_pager&id='+id+'&spage='+page, 'list_block', '');
}

function mbMore(blok, id, getparams) {
	dname = 'pageC';
	if (gEl('pageC-' + blok)) dname = 'pageC-' + blok;
	obj = gEl(dname);
	page = obj.value;
	page = page * 1;
	page++;
	
	if (gEl('MpageC')) obj2 = gEl('MpageC');
	m_page = obj2.value;
	m_page = m_page * 1;
	if (m_page != 0 && page >= m_page) {		
		if (gEl('iMore')) {
			obj3 = gEl('iMore');
			obj3.style.display = 'none';
		}
	}
	
	gp = '&st=mb_get_more&id='+id+'&spage='+page+'&type='+blok;
	if (getparams) gp += '&' + getparams;
	Ajax('http://lichiko.com/ajax.php', gp, blok, 'mb_get_more');
}

function mbGetMoreResult(text, name) {
	obj = gEl(name);
	result = obj.innerHTML + text;
	
	dname = 'pageC';
	if (gEl('pageC-' + name)) dname = 'pageC-' + name;
	obj = gEl(dname);
	page = obj.value;
	page = page * 1;
	page++;
	obj.value = page;
	
	return result;
}

function mb_ctrl_enter(e, form) {
	//if (((e.keyCode == 13) || (e.keyCode == 10)) && (e.ctrlKey == true)) form.submit();
	
	obj = gElv('ta_msg');
	cnt = obj.length - 1;
	if (cnt < 150) {
		if (e.keyCode == 13) mb_FormSubmit(form, 'main');
	}
}

//new
function mb_ctrl_enter_click(e, id) {	
	obj = gElv('ta_msg');
	cnt = obj.length - 1;
	if (cnt < 150) {
		if (e.keyCode == 13) {
			obj1 = gEl(id);
			obj1.onclick();
		}
	}
}

function mb_FrameStatus(type, login, getparams) {
	obj = parent.frames['frame'];
	if (obj2 = obj.document.getElementById('frameMsg')) {
	    result = obj.document.getElementById('frameMsg').innerHTML;
	} else {
		result = '';
	}
	if (result == 'done' || result == 'error') {
		if (typeof(idfr) != 'undefined') clearTimeout(idfr);
		if (type == 'links_photo') {
			mbPopUpOpen('upload');
		} else {
			gp = '&ajaxcontent=1&type='+type;
			if (login) gp += '&login='+login;
			if (getparams) gp += '&' + getparams;
			Ajax('http://lichiko.com/ajax.php', gp, 'acontent');
			mb_AcTab(type);
		}
	} else {
		par = '"' + type + '"';
		if (login) par += ',"' + login + '"'; else par += ',0';
		if (getparams) par += ',"' + getparams + '"';
		idfr = setTimeout('mb_FrameStatus('+par+')', 500);
	}
}

function mb_FormSubmitStatus(form, type, login, getparams) {
	obj = parent.frames['frame'];
	if (obj2 = obj.document.getElementById('frameMsg')) obj.document.getElementById('frameMsg').innerHTML = '';
	form.submit();
	if (type == 'photo') {name = 'photoShower'; mb_UniClearContent(name);}
	if (type == 'links_photo') {name = 'uploadList'; mb_UniClassClearContent(name, 'dl_uni2_content_loading');}
	mb_FrameStatus(type, login, getparams);
}

function mb_FormSubmit(form, type, login, getparams) {
	form.submit();
	mb_ClearContent();
	
	gp = '&ajaxcontent=1&type='+type;
	//if (form.id == 'msg_form') gp += '&double=1';
	if (login) gp += '&login='+login;
	if (getparams) gp += '&' + getparams;
	
	Ajax('http://lichiko.com/ajax.php', gp, 'acontent');
	mb_AcTab(type);
}

function mb_PageOpen(type, login, getparams) {
	mb_ClearContent();
	
	gp = '&ajaxcontent=1&type='+type;
	gp += '&double=1';
	if (login) gp += '&login='+login;
	if (getparams) gp += '&' + getparams;
	
	Ajax('http://lichiko.com/ajax.php', gp, 'acontent');
	mb_AcTab(type);
	
	urchinTracker('/ingoing/' + type);
}

function mb_ClearContent() {
	obj = gEl('acontent');
	obj.innerHTML = '<div class="dl_content_loading">&nbsp;</div>';
	obj.innerHTML += "<div style='visibility:hidden;height:0px;'><a href='http://www.liveinternet.ru/click' "+
	"target=_blank><img src='http://counter.yadro.ru/hit?t14.3;r"+
	escape(document.referrer)+((typeof(screen)=="undefined")?"":
	";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
	screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
	";"+Math.random()+
	"' alt='' title='LiveInternet: показано число просмотров за 24"+
	" часа, посетителей за 24 часа и за сегодня' "+
	"border='0' width='88' height='31'><\/a></div>";
}

//new
function mb_UniClearContent(name) {
	obj = gEl(name);
	obj.innerHTML = '<div class="dl_content_loading">&nbsp;</div>';
}

function mb_UniClassClearContent(name, cl) {
	obj = gEl(name);
	obj.innerHTML = '<div class="' + cl + '">&nbsp;</div>';
}

//new
function mb_CommentReply(id) {
	gEl('pid').value = id;
	obj = gEl('commentText');
	obj.focus();
}

//new
function mb_CommentReplyCancel() {
	gEl('pid').value = 0;
}

//new
function mb_CommentDelete(photo_id, comment_id) {
	mb_UniClearContent('commentsBlock');
	obj = gEl('commentCnt');
	cnt = obj.innerHTML;
	cnt = cnt * 1;
	if (cnt != 0) obj.innerHTML = cnt - 1;
	Ajax('http://lichiko.com/comments/' + photo_id, '&ajax=1&delete_comment=' + comment_id, 'commentsBlock');
}

//new
function mb_CommentPager(photo_id, page) {
	mb_UniClearContent('commentsBlock');
	Ajax('http://lichiko.com/comments/' + photo_id, '&ajax=1&spage=' + page, 'commentsBlock');
}

//new
function mb_LoadingPhotoComments() {
	obj = gEl('commentsBlock');
	if (obj.innerHTML == '') {
		mb_UniClearContent('commentsBlock');
		obj = gEl('nowIdPhoto');
		Ajax('http://lichiko.com/comments/' + obj.value, '&ajax=1', 'commentsBlock');
		if (gEl('newCommentCnt_' + obj.value)) {
			obj1 = gEl('newCommentCnt_' + obj.value);
			obj1.innerHTML = '&nbsp;&nbsp;&nbsp;';
		}
	} else {
		obj.innerHTML = '';
	}
}

function mb_AcTab(type) {
	if (gEl('tab_main')) obj = gEl('tab_main').className = "";
	if (gEl('tab_general')) obj = gEl('tab_general').className = "";
	if (gEl('tab_my')) obj = gEl('tab_my').className = "";
	if (gEl('tab_reply')) obj = gEl('tab_reply').className = "";
	if (gEl('tab_favorites')) obj = gEl('tab_favorites').className = "";
	if (gEl('tab_mailbox')) obj = gEl('tab_mailbox').className = "";
	if (gEl('tab_photo')) obj = gEl('tab_photo').className = "";
	if (gEl('tab_music')) obj = gEl('tab_music').className = "";
	if (gEl('tab_search')) obj = gEl('tab_search').className = "";
	
	if (type == 'mailbox_black' || type == 'mailbox_trash') type = 'mailbox';
	
	if (gEl('tab_'+type)) obj = gEl('tab_'+type).className = "dl_active";
}

function mb_CreateFileField() {
	$(document).ready(function(_e) {
		$('#file').customFile();
	});
}

function mb_js_cron() {
	//Ajax('http://lichiko.com/ajax.php', '&st=menu_message', 'tmp_buff', 'menu_message');
	mbMenuMessageStatic();
	timer2 = setTimeout('mb_js_cron()', 10000);
}

function mbMenuMessageStatic() {
	st = 0;
	if (obj1 = gEl('in_mr')) st = 1;
	if (obj2 = gEl('in_mp')) st = 1;
	if (st == 1) {
		sta = 0;
		if (obj_a1 = gEl('indReply')) sta = 1;
		if (obj_a2 = gEl('indMsg')) sta = 1;
		if (sta == 1) {
			a1 = obj_a1.value * 1;
			a2 = obj_a2.value * 1;
			if (a1 == 0) {
				obj1.innerHTML = '';
			} else {
				obj1.innerHTML = '<ins>' + a1 + '</ins>';
			}
			if (a2 == 0) {
				obj2.innerHTML = '';
			} else {
				obj2.innerHTML = '<ins>' + a2 + '</ins>';
			}
		}
	}
}

function mbMenuMessage(text, xdiv) {
	st = 0;
	if (obj1 = gEl('in_mr')) {
		st = 1;
	}
	if (obj2 = gEl('in_mp')) {
		st = 1;
	}
	if (st == 1) {
		a = text.split(".");
		a[0] = a[0] * 1;
		a[1] = a[1] * 1;
		if (a[0] == 0) {
			obj1.innerHTML = '';
		} else {
			obj1.innerHTML = '<ins>' + a[0] + '</ins>';
		}
		if (a[1] == 0) {
			obj2.innerHTML = '';
		} else {
			obj2.innerHTML = '<ins>' + a[1] + '</ins>';
		}
	}
}

function mb_AbuseTypeComment() {
	obj = gEl('abuseType');
	if (obj.value == 'b1') {
		obj1 = gEl('typeComment1');
		obj1.style.display = 'block';
	} else {
		obj1 = gEl('typeComment1');
		obj1.style.display = 'none';
	}
	
}

function mbFastAjaxSearch(gp, xdiv, more_button) {
	if (more_button) {
		obj1 = gEl('fastSearch');
		obj2 = gEl('moreBtn');
		if (obj1.value.length != 0) {
			obj2.style.display = 'none';
		} else {
			obj2.style.display = 'block';
		}
	}
	Ajax('http://lichiko.com/ajax.php', gp, xdiv);
}

function mbMsgAddFavorite(user_id, msg_id) {
	gp = '&st=mb_add_favorites&user_id=' + user_id + '&msg_id=' + msg_id;
	Ajax('http://lichiko.com/ajax.php', gp, 'faddl_' + msg_id);
}

function mbPopUpLoading(name, type) {
	obj = gEl(name);
	result = '';
	brows = whatIsBrowser();
	if (brows == 'Safari') {
		poss = document.body.scrollTop;
	} else {
		poss = document.documentElement.scrollTop;
	}
	if (poss > 100) poss -= 100;
	if (type == 'show') {
	    result += '<div class="pjsBody" style="width:360px; top:'+poss+'px; left:215px;">';
        result += '<div class="pjsTitle">Просмотр изображения <a href="javascript:void(0);" class="close"><img src="http://media.lichiko.com/images/popUp_title_ic_close.gif" /></a></div>';
        result += '<div class="dl_uni_content_loading">&nbsp;</div>';
    	result += '</div>';
    } else {
    	result += '<div class="pjsBody" style="width:420px; top:'+poss+'px; left:190px;">';
	    result += '<div class="pjsTitle">Добавление изображения <a href="javascript:void(0);" class="close"><img src="http://media.lichiko.com/images/popUp_title_ic_close.gif" /></a></div>';
	    result += '<div class="dl_uni_content_loading">&nbsp;</div>';
	    result += '</div>';
    }
    obj.innerHTML = result;
}

function mbPopUpAutoStart(name, getparams) {
	idt = setTimeout('mbPopUpOpen("'+name+'", "'+getparams+'")', 500);
}

function mbPopUpAutoStop() {
	clearTimeout(idt);
}

function mbPopUpOpen(name, getparams) {
	//obj = gEl('popUpJs');
	//obj.style.position = 'relative';
	mbPopUpLoading('popUpJs', name);
	brows = whatIsBrowser();
	if (brows == 'Safari') {
		poss = document.body.scrollTop;
	} else {
		poss = document.documentElement.scrollTop;
	}
	if (poss > 100) poss -= 100;
	
	gp = '&ajaxcontent=1&type=links_photo&popup=' + name;
	gp += '&postop=' + poss;
	if (getparams) gp += '&' + getparams;
	Ajax('http://lichiko.com/ajax.php', gp, 'popUpJs');
}

function mbPopUpClose(name) {
	obj = gEl(name);
	obj.innerHTML = '';
}

function mbPopUpCancel(name) {
	mbPopUpClose(name);
	gp = '&st=mb_clear_photo_link';
	Ajax('http://lichiko.com/ajax.php', gp, 'tmp_buff2');
}

function mbPopUpHideFile(id) {
	gp = '&st=mb_remove_upload_photo_link&photo_id=' + id;
	Ajax('http://lichiko.com/ajax.php', gp, 'upFile' + id);
}

function mbPopUpSelect(id, obj) {
	if (obj.className == 'dl_hw6') {
		obj.className = 'dl_hw6 dl_bg4'
		gp = '&st=mb_add_select_photo_link&photo_id=' + id;
		Ajax('http://lichiko.com/ajax.php', gp, 'tmp_buff2');
	} else {
		obj.className = 'dl_hw6'
		gp = '&st=mb_remove_select_photo_link&photo_id=' + id;
		Ajax('http://lichiko.com/ajax.php', gp, 'tmp_buff2');
	}
}

function mbPopUpAddTag(type, name) {
	txt = '[:'+type+']';
	
	obj = gEl(name);
	obj_tmp = obj.value;
	l1 = obj_tmp.length;
	obj_tmp = obj_tmp.replace(txt, '');
	l2 = obj_tmp.length;
	
	if (l1 == l2) obj.value += txt;
}

function mbPopUpMove(e) {
	if (popmv == 100000) {
		obj = gEl('popUpJs');
		obj.style.position = 'absolute';
		obj = gEl('mbPBody');
		obj.style.position = 'absolute';
		obj.style.top = (e.pageY - 15) + 'px';
		obj.style.left = (e.pageX - 200) + 'px';
	}
}

function mbPopUpMoveOn() {
	popmv = 1;
}

function mbPopUpMoveOff() {
	popmv = 0;
}

function mbHLOpen(id, name) {
	obj = gEl(id);
	return hs.htmlExpand(obj, { contentId: name } );
}