// $Revision: 12267 $

// User miniform dimentions
var _UserInfoWidth  = 1000;
var _UserInfoHeight = 650;

// перегружена стандартная Date.toLocaleString() для дамки
Date.prototype.toLocaleString = function (){
	var yy=this.getFullYear();
	var mm=this.getMonth()+1;
	if (mm<10) mm='0'+mm;
	var dd=this.getDate();
	if (dd<10) dd='0'+dd;
	var h=this.getHours();
	if (h<10) h='0'+h;
	var m=this.getMinutes();
	if (m<10) m='0'+m;
	return dd+'-'+mm+'-'+yy+' '+h+':'+m;
}

/////////// настройки меню ///////////

Menu = new Array( // названия разделов
	/*"большие гонки",*/
	"главная",
	"любовь с ПК",
	"дневники",
	"лотереи",
	"фотографии",
	"видео",
	"объявления",
	"форумы",
	"гюльчатай",
	"тесты",
	"место встречи",
	"тусовка",
	"щас лифчик!",
	"new угадун"
	);
	
MenuL = new Array( // ссылки разделов
	/*"/bigrace/",*/
	"/",
	"/love/",
	"/dnevnik/read.phtml?dnevnik=read",
	"/damatron/?class=lottery",
	"/photoz/",
	"/video/",
	"/bboard/",
	"/bb/",
	"/meet/view",
	"/test/",
	"/mv/",
	"/meeting/",
	"/lifchik/",
	"/ugadun/"
	);

SubMenu = new Array( // названия подразделов
	/*Array("правила","заказ билетов","минута славы","лидеры"),*/
	Array("статистика", "популярные анкеты", "юзеры онлайн", "расширенный поиск", "поиск по районам", "голосование", "архив новостей", "обратная связь", "хронология сайта", "дамочадцы дня", "рассылка", "дни рождения"),
	Array("рейтинги ЛПК", "топы вопросов ЛПК", "статистика ЛПК", "о ЛПК-рейтинге"),
	Array("блог лента", "рейтинги", 'тэги', "самый свежачок 25"),
	Array("FAQ лотерей"),
	Array(),
	Array("категории"),
	Array(),
	Array("секс", "любовь", "мнение мужчин", "мнение женщин", "брак и семья", "объявления о знакомствах", "однополая любовь", "культура и искусство", "поэзия и проза", "музыка", "кино", "фотография", /*"тату и пирсинг",*/ "танцы", "авто и байки", "спорт", "футбол на student.ru", "барахолка", "наука", "политология", "кулинария", "красота и здоровье", "кабинет психолога", "религия", /*"игры разума",*/ "путешествия", "флора и фауна", "юридическая консультация"/*, "непознанное"*/, "квартирный вопрос", "программирование", "компьютеры", "компьютерные игры", "GUI и Web дизайн", "мобильный мир", /*"интернет",*/ "официальные тусовки", "неофициальные тусовки", "игры и разделы сайта", "болталка", "без ограничений", "форумные игры"/*, "юмор"*/),
	Array("рейтинги Гули", "статистика Гули", "FAQ Гули"),
	Array("секс-тест", "половинка", "определи пол", "жмурки", "болтуны"),
	Array("FAQ МВ"),
	Array("МЕГАДАМ","Большие Гонки", "Москва", "Питер", "Латвия", "Азербайджан", "Алматы", "Владивосток", "Иркутск", "Казань", "Киев", "Краснодар",  "Литва", "Минск", "Нарва", "Нижний Новгород", "Новосибирск", "Нью-Йорк", "Омск", "Сочи", "Таллинн"),
	Array("топ-10 сегодня", "топ-100 ваще"),
	Array()
	);

SubMenuL = new Array( // ссылки подразделов
	/*Array("/bigrace/rules.phtml", "/bigrace/booking.phtml", "/bigrace/minofame.phtml","/bigrace/liders.phtml"), //субменю Гонок*/
	Array("/stat.phtml", "/stat_views.phtml", "/sms/online.phtml", "/vip/search.php", "/regions/search_region.php", "/vote.phtml?cid=-1", "/arch/news.phtml", "/arch/response.phtml","/arch/chrono.phtml","/arch/damday.phtml", "/subscribe/", "/arch/birth.phtml"),
	Array("/love/top.phtml", "/love/stat/", "/love/stat/stat.phtml?period=1", "/love/rating.phtml"), 
	Array("/dnevnik/read.phtml?dnevnik=read", "/dnevnik/?open=top100#top.all","/dnevnik/?open=top10#top.tag", "/dnevnik/?open=top10#top.last"),
	Array("/faka.phtml?id=lottery"),
	Array(),
	Array("/video/category.phtml"),
	Array(),
	Array("/bb/index.php?showforum=8", "/bb/index.php?showforum=13", "/bb/index.php?showforum=10", "/bb/index.php?showforum=9", "/bb/index.php?showforum=12", "/bb/index.php?showforum=70", "/bb/index.php?showforum=24", "/bb/index.php?showforum=42", "/bb/index.php?showforum=27", "/bb/index.php?showforum=21", "/bb/index.php?showforum=22", "/bb/index.php?showforum=20", /*"/bb/index.php?showforum=30",*/ "/bb/index.php?showforum=94", "/bb/index.php?showforum=17", "/bb/index.php?showforum=33", "/bb/index.php?showforum=16", "/bb/index.php?showforum=80", "/bb/index.php?showforum=99", "/bb/index.php?showforum=34", "/bb/index.php?showforum=45", "/bb/index.php?showforum=52", "/bb/index.php?showforum=61", "/bb/index.php?showforum=48",/* "/bb/index.php?showforum=61",*/ "/bb/index.php?showforum=39", "/bb/index.php?showforum=47", "/bb/index.php?showforum=51", /*"/bb/index.php?showforum=55",*/ "/bb/index.php?showforum=103", "/bb/index.php?showforum=83", "/bb/index.php?showforum=18", "/bb/index.php?showforum=31", "/bb/index.php?showforum=29", "/bb/index.php?showforum=82",/* "/bb/index.php?showforum=44",*/ "/bb/index.php?showforum=5", "/bb/index.php?showforum=26", "/bb/index.php?showforum=3", "/bb/index.php?showforum=46", "/bb/index.php?showforum=32", "/bb/index.php?showforum=63"/*, "/bb/index.php?showforum=25"*/),
	Array("/meet/top.phtml?w=girlstop", "/meet/stat.phtml", "/faka.phtml?id=meet2"),
	Array("/sex-test/", "/polovinka/", "/test/detector.phtml", "/zhmurki/", "/talk/"),
	Array("/faka.phtml?id=mv"),
	Array("/megadam/", "/bigrace/tusovka.phtml","/meeting/?cid=1", "/meeting/?cid=2","/meeting/?cid=114", "/meeting/?cid=96", "/meeting/?cid=93", "/meeting/?cid=48", "/meeting/?cid=103", "/meeting/?cid=62", "/meeting/?cid=10", "/meeting/?cid=39",  "/meeting/?cid=88", "/meeting/?cid=25", "/meeting/?cid=102", "/meeting/?cid=101", "/meeting/?cid=22", "/meeting/?cid=97", "/meeting/?cid=55", "/meeting/?cid=67", "/meeting/?cid=99"),
	Array("/lifchik/#top", "/lifchik/#top.all")
	);

SubNew_Mark	 = new Array ( // промаркированные суб-меню
	Array(),
	Array("", "", "", ""),
	Array(),
	Array(),
	Array(),
	Array(),
	Array(),
	Array(),
	Array(),
	Array(),
	Array(),
	Array(),
	Array(),
	Array()
	);

Menu_2 = new Array( //  разделы, второе меню
//	'<b>Bar Stars</b> <span style="color: red; font-size: 7px; font-family: verdana">NEW!</span>',
//	'<b>Bar Stars</b> <span style="color: red; font-size: 8px; font-family: verdana">NEW!</span>',
//	'<b>Bar Stars!</b> <img src="/static/main/new.gif" border="0">',
//	"<b>SMS Викторина</b>",
	"<b>FAQ</b>",
	"<b>ДАМАФОН</b>",
	"<b>DAMPS</b>",
	"<b>вакансии</b>",
	"<b>обратная связь</b>"
//	,"досуг"
	);

MenuL_2 = new Array( // ссылки, второе меню
//	"http://barstars.student.ru",
//	"/smsquiz/",
	"/faka.phtml",
	"/damafon/",
	"/picasa/",
	"/vacancy.phtml",
	"/report.phtml"
//	,"/dosug/"
	);
	
menuOpened = false; // меню инфоцентра открыто ?
gulOpened = false; // фотки гул открыты ?


function setHomepage(f){
	f.style.behavior='url(#default#homepage)';
	f.setHomePage(document.location.href);
}

function addBookmark(){
	window.external.addFavorite(document.location.href, 'Дамочка.ру - познакомься играючи!"');
}



/////////// отрисовка меню ///////////
function draw_menu(part)
{	if(!part || part=='default') part = '/'; else part = '/'+part+'/';
	document.write('<table width="162" cellspacing="0" cellpadding="0">');
	document.write('<tr><td colspan="3"><img src="'+BASE_STATIC+'main/bg_menu_mtop.gif" width="162" height="9" border="0"><br></td></tr>');
	document.write('<tr bgcolor="#ffffff"><td style="border-left: 2px solid #b00000;">&nbsp;</td><td>');
	document.write('<table width="140" cellspacing="0" cellpadding="0" style="margin-left:12">');

for (j=0;j<Menu.length;j++)
{	document.write('<tr><td width="11"><div class=menu_plus><img id="menuImg'+MenuL[j]+'" onClick=menush(\''+MenuL[j]+'\') src="'+BASE_STATIC+'main/'+(MenuL[j]==part?'minus':'plus')+'.gif" width="11" height="11" border="0"><br></div></td>\n');
	document.write('<td width=100%><a href="'+MenuL[j]+'" class=menu_razdel>'+Menu[j]+'</a></td></tr>\n');
	document.write('<tr><td colspan="2"><div id="menu'+MenuL[j]+'" style="display:'+(MenuL[j]==part?'block':'none')+'"  class=menu_podrazdel>\n');
curSubMenu = SubMenu[j];
curSubMenuL = SubMenuL[j];
	for (k=0;k<curSubMenu.length;k++) {
		if( SubNew_Mark[j][k] == '*' ) {
			curSubMenu[k] = curSubMenu[k] + '&nbsp;<img src='+BASE_STATIC+'main/new.gif border=0>';
		}
		document.write('<a class=menu_podrazdel href="'+curSubMenuL[k]+'">'+curSubMenu[k]+'</a><br>');
	}
	document.write('</div></td></tr>');
	if (j < Menu.length-1)
	document.write('<tr><td colspan="2"><img src="'+BASE_STATIC+'main/dotline.gif" width="109" height="1" border="0" class=dotline><br></td></tr>');
}
document.write('</table>');
document.write('</td><td width="2" bgcolor="#b00000"><img src="'+BASE_STATIC+'main/dot.gif" width="2" height="1" border="0"></td></tr>');
document.write('<tr><td colspan="3"><img src="'+BASE_STATIC+'main/bg_menu_mbot.gif" width="162" height="9" border="0"><br></td></tr>');
document.write('</table>');
}
// это было основное меню //


// вторая часть осн.меню //
function draw_menu_2() {
	document.write('<table width="162" cellspacing="0" cellpadding="0">');
	document.write('<tr><td colspan="3"><img src="'+BASE_STATIC+'main/bg_menu_dtop.gif" width="162" height="9" border="0"><br></td></tr>');
	document.write('<tr bgcolor="#FFEFE6"><td style="border-left: 2px solid #ff9933;">&nbsp;</td><td>');
	document.write('<table width="140" cellspacing="0" cellpadding="0" style="margin-left:12">');

for (j=0;j<Menu_2.length;j++) {
	document.write('<tr><td><a class=menu_bottom href="'+MenuL_2[j]+'"><div class=menu_bottom>'+Menu_2[j]+'</div></a></td></tr>');

	if (j < Menu_2.length-1)
	document.write('<tr><td><img src="'+BASE_STATIC+'main/dotline_b.gif" width="109" height="1" border="0" class=dotline><br></td></tr>');
}

if ((navigator.appVersion.indexOf('MSIE 5.') != -1) | (navigator.appVersion.indexOf('MSIE 6.') != -1) | (navigator.appVersion.indexOf('MSIE 4.') != -1))
{	document.write('<tr><td><img src="'+BASE_STATIC+'main/dotline_b.gif" width="109" height="1" border="0" class=dotline><br></td></tr>');
	document.write('<tr><td><a href=# onClick=\'setHomepage(this);\'><div class=menu_bottom><i>сделать стартовой</i></div></a></td></tr>');
	document.write('<tr><td><img src="'+BASE_STATIC+'main/dotline_b.gif" width="109" height="1" border="0" class=dotline><br></td></tr>');
	document.write('<tr><td><a href=# onClick=\'addBookmark();\'><div class=menu_bottom><i>в избранное</i></div></a></td></tr>');
}

document.write('</table>');
document.write('</td><td width="2" bgcolor="#FF9933"><img src="'+BASE_STATIC+'main/dot.gif" width="2" height="1" border="0"></td></tr>');
document.write('<tr><td colspan="3"><img src="'+BASE_STATIC+'main/bg_menu_dbot.gif" width="162" height="9" border="0"><br></td></tr>');
document.write('</table>');
}

/////////////// открывалка меню  //////////////
function findObj(id)
{
	if(document.all)
		return document.all[id];
	else
		return document.getElementById(id);
}

function menush(sId, dir){
	if(!dir) dir="";
	e = findObj('menu'+sId);
	i = findObj('menuImg'+sId);

	if(!e) return;
	if (e.style.display == "block")
	{
		e.style.display = "none";
		if(i && i.src) i.src = BASE_STATIC+"main/"+dir+"plus.gif";
	}
	else {
		e.style.display = "block";
		if(i && i.src) i.src = BASE_STATIC+"main/"+dir+"minus.gif";
	}
}

function blockSh(sId, whichIm)
{
	e = findObj(sId);

	if(!e) return;
	if (e.style.display == "block")
	{
		e.style.display = "none";
		if(whichIm)
			{
				whichIm.className = "table_none_img";
				whichIm.title = "развернуть окно";
			}
	}
	else {
		e.style.display = "block";
		if(whichIm)
			{
				whichIm.className = "table_block_img";
				whichIm.title = "свернуть окно";
			}
	}
}

function blockSh_adv(sId, whichIm)
{
	e = findObj(sId);

	if(!e) return;
	if (e.style.display == "block")
	{
		e.style.display = "none";
		findObj("hidden_"+sId).style.display = "block";
		if(whichIm)
			{
				whichIm.className = "table_none_img";
				whichIm.title = "развернуть окно";
			}
	}
	else {
		e.style.display = "block";
		findObj("hidden_"+sId).style.display = "none";
		if(whichIm)
			{
				whichIm.className = "table_block_img";
				whichIm.title = "свернуть окно";
			}
	}
}
////////////    Cookie   ////////////

function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	if ((name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie;
	else
		if (confirm("Cookie превышает 4KB!"))
				document.cookie = curCookie;
}

function getCookie(name)
{
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1)
		return null;
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length;
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}


 
function openWin(page, width, height)
{
	syspage = '';
	if( /^\/sms\/read.phtml\?id=[^\/]+\/\d+\.\d+\.\d+\.\d+(,[^\/]+\/\d+\.\d+\.\d+\.\d+)*$/.test(page) ){
		ids = page.match(/[^,=]+\/\d+\.\d+\.\d+\.\d+/g);
		if( ids.length ){
			page_def = '';
			page_sys = '';
			for( j=0;j<ids.length;j++){
				p = ids[j].split('.');
				fr = p[0].split('/');
				t = p[3];
				sys = (fr[1]==0);

				if( t==4 || t==5 ){
					o = findObj('lpk_iframe');
					if( true ){
						o.src = '/love/join.php?id='+p.join('.');
					}
					else{
						alert('Ошибка! Нет мочи найти фрейм lpk_iframe!');
					}
				}
				else if( sys ){
					page_sys += ( (page_sys.length?',':'') + p.join('.'));
				}
				else{
					page_def += ( (page_def.length?',':'') + p.join('.'));
				}
			}


			if( !page_def.length && !page_sys.length){
				return true;
			}

			if( page_def.length ){
				page = '/sms/read.phtml?id='+page_def;
			}
			else
				page = '';

			if( page_sys.length ){
				syspage = '/sms/read.phtml?id='+page_sys;
			}
			else
				syspage = '';
		}
	}
	if(!width) width=488;
	if(!height) height=650;
	s = '';
	if(page.indexOf("ttp://")<=0 && typeof __server_mainServer != 'undefined')
	  s = __server_mainServer;

	if( page ){
		Win=this.open(s+page, '',	'toolbar=no,scrollbars=yes,status=yes,height='+height+',width='+width);
		Win.focus();
	}
	
	if( syspage ){
		WinSys=this.open(s+syspage, '',	'toolbar=no,scrollbars=yes,status=yes,height='+height+',width='+width);
		WinSys.focus();
	}

}

////////////    messages  ////////////

smsUpdateTimeOut=60;

function setUpdateTimeOut(type){
	if (type == 'html') smsUpdateTimeOut=30;
	else
	if (type == 'java') smsUpdateTimeOut=180;
}

function sms_auto(sessid){
	document.write('<iframe id="sms_update" src="about:blank" frameborder=0 vspace=0 hspace=0 width=0 height=0 marginwidth=0 marginheight=0 scrolling=no></iframe>');
	document.write(
	'<s'+'cript>\
		window.DAMDInterval = null;\
		window.Functions.AddEventListener(window, "load", function(){\
			refreshSMSUpdate();\
			DAMDInterval = setInterval ("refreshSMSUpdate()", smsUpdateTimeOut*1000);\
		});\
		window.Functions.AddEventListener(window, (ThisBrowser.IsIE ? "beforeunload":"unload"), function(){\
			if (DAMDInterval) window.clearInterval(DAMDInterval);\
		});\
	</s'+'cript>');
}
function refreshSMSUpdate(){
//	var anticache = Math.round(Math.random() * 100000);
	var lastUpdate = getCookie('lastUpdate');
	var d = new Date();
	var now = new Date();
	var fr=document.getElementById('sms_update');
	if (lastUpdate==null || ((d.getTime()-lastUpdate)>smsUpdateTimeOut*1000)){
		update_loc = /*DAMD_SMS_HOST+*/'/GETMESG'+
			'?sid='+my_session_id+
			'&uid='+my_id+
			'&sb='+(js_show_banners?1:0)+
			'&id='+(new Date).getTime()+
			'&nn='+escape(my_nickname).replace(/&/g, '%26')+
			'&fn='+escape(my_fullname).replace(/&/g, '%26');
		d.setMonth(d.getMonth()+6);
		setCookie('lastUpdate', now.getTime(), d, '/');
		fr.src=update_loc;
	}
}

function alertForLogin()
{
    alert('Эта функция доступна только зарегистрированным пользователям');
}

function alertSMSBlocked()
{
    alert('Пользователь отключил прием сообщений');
}

function op_jswin(mkey,uclass,uname,ustat,uid){
	s = '';
	if(typeof __server_mainServer != 'undefined')
	  s = __server_mainServer;

	var pop_win=window.open(s+"/sms/write_cont.phtml?key="+mkey+"&uclass="+uclass+"&uname="+uname+"&ustat="+ustat+"&uid="+uid, '_blank', 'toolbar=no,scrollbars=yes,status=yes,height=290,width=488');
	pop_win.focus();
}

function openUserInfo(uid){	
	var win=open(
		"/sms/info_frame.phtml?key=" + uid,
		"",
		"toolbar=no,scrollbars=no,status=yes,resizable=yes,height=" + _UserInfoHeight + ",width=" + _UserInfoWidth
		//"toolbar=no,scrollbars=no,status=yes,resizable=no,height=650,width=996" 
	);
	win.focus();
}
function openUserInfoM(uid){
	var win=open(
		"/brief/" + uid,
		"",
		"toolbar=no,scrollbars=no,resizable=yes,status=yes," + _UserInfoHeight + ",width=" + _UserInfoWidth
	);
	win.focus();
}

function openUserInfoFrom(uid, from){
	var win=open(
		"/sms/info_frame.phtml?key=" + uid + "&from=" + from,
		"",
		"toolbar=no,scrollbars=no,status=yes,resizable=yes,height=" + _UserInfoHeight + ",width=" + _UserInfoWidth
	);
	win.focus();
}

function openInfoByUserId(uid) {
	openUserInfo(uid);
}

function uid_show_popup()
{
	uid_to_show = parseInt((findObj("uid_show").value));
	if ( isNaN(uid_to_show) || uid_to_show < 1) 
	alert('неверный USER_ID')
	else openUserInfo(uid_to_show);
}

function dot_line()
{
	var innerHTML;
	
    innerHTML = 
    	'<table cellspacing="0" cellpadding="0" border="0" width="100%">'+
        	'<tr><td height="5"><img src="'+BASE_STATIC+'main/dot.gif" height="5" border="0"></td></tr>'+
        	'<tr><td background="'+BASE_STATIC+'pics/point_g.gif" height="1"></td></tr>'+
        	'<tr><td height="10"><img src="'+BASE_STATIC+'main/dot.gif" height="10" border="0"></td></tr>'+
    	'</table>';
	
	document.write(innerHTML);
}

function draw_dot_line()
{
	var innerHTML;
	
    innerHTML = 
    	'<table cellspacing="0" cellpadding="0" border="0" width="100%">'+
        	'<tr><td height="5"><img src="'+BASE_STATIC+'main/dot.gif" height="5" border="0"></td></tr>'+
        	'<tr><td background="'+BASE_STATIC+'pics/point_g.gif" height="1"></td></tr>'+
        	'<tr><td height="10"><img src="'+BASE_STATIC+'main/dot.gif" height="10" border="0"></td></tr>'+
    	'</table>';
	
	return innerHTML;
}

function resizeIFRAME(name) {
    clearTimeout(this.name);
    var scrollHeight = 0;
    var elem = document.getElementById(name), i;
    var childNodes, body, firstChild;
    
    if(elem) {
        if( elem.contentWindow && 
            elem.contentWindow.document &&
            elem.contentWindow.document.documentElement &&
            elem.contentWindow.document.documentElement.childNodes
        ) {
            childNodes = elem.contentWindow.document.documentElement.childNodes;
            for(i in childNodes) {
                if((body = childNodes[i]) && body.nodeName == 'BODY') {
                    if(firstChild = body.firstChild) {
                        if(!firstChild.length) {//not Opera
                            if(firstChild.nodeName == 'IMG') {//IFRAME with IMG
                                if(firstChild.naturalHeight) {//FireFox
                                    scrollHeight = 
                                        body.scrollHeight +
                                        firstChild.naturalHeight -
                                        firstChild.scrollHeight
                                    ;
                                }
                            }
                        } else {
                            //TODO: Opera
                        }
                    }
                    if(!scrollHeight) {//IE & sometimes Opera
                        scrollHeight = childNodes[i].scrollHeight;                        
                    }
                    break;
                }
            }
        }
        
        if(scrollHeight) {
            elem.setAttribute('height', scrollHeight);
        } else {
            this.name = setTimeout('resizeIFRAME("'+name+'")', 500);
        }
    }
}

function drawIFRAME(src, name) {
    document.writeln('<iframe src="'+src+'" id="'+name+'" width="100%" frameborder="0" scrolling="No"></iframe>');
    resizeIFRAME(name);
}

//hack
var __regUsersCount = 1466810;

		
function open_menut(j)
{
	var memit = document.getElementById("opcla"+j);

	if (memit.className=="")
	{
		memit.className='item-open';
		setCookie('OMenu'+j, '1', null, '/');
			
	}
	else{
		memit.className="";
		setCookie('OMenu'+j, '6',null, '/');
		
	}

}

function openmenuonly(j)
{
	var memit = document.getElementById("opcla"+j);
	memit.className='item-open';
	setCookie('OMenu'+j, '1', null, '/');
}
