// Za sroll na stranicite na pechatnoto izdanie
var L_Timer = "";


function shiftStep(id, stop) {
	posnow = document.getElementById(id).offsetLeft;
	
	dx=(stop<posnow?-1:1);

	if((stop - posnow)*dx<=0) {
			return;
	}
	if((stop - posnow)*dx < 2){
		posnow += dx*1;
	} else if((stop - posnow)*dx < 5){
		posnow += dx*2;
	} else {
		posnow += dx*5; 
	}
	if (posnow==stop) return;
	document.getElementById(id).style.left = posnow + 'px';
}


function shiftToLeft(id) {
	stopleft=0;
	shiftStep(id,stopleft);
	
	clearTimeout(L_Timer);
	L_Timer = setTimeout("shiftToLeft('"+id+"')",50);
}


function shiftToRight(id){
	stopright = document.getElementById(id).parentNode.offsetWidth - document.getElementById(id).offsetWidth;
	//~ alert(document.getElementById(id).offsetWidth);
	shiftStep(id, stopright);
	
	clearTimeout(L_Timer);
	L_Timer = setTimeout("shiftToRight('"+id+"')",50);
}
// end of scroll functions

// Skirvane/Pokazvane na tablicata s danni za faktura ot abonamentnata forma

function reloadchcks(elname, frmname) {
	if (!frmname) frmname = "def1";
	
	var p = document.forms[frmname].elements[elname];
	//~ alert(0;
	if (p.checked) {
			document.getElementById('divtype_1').style.display="";
	}
	if (!p.checked) {
		document.getElementById('divtype_1').style.display="none";
			
	}		
}

function rldContent(t) {
	if (t.value == 'Търсене') {
		t.value = '';
	}	
	t.style.color = '#000';
}

function rldContent2(t) {
	if (!t.value) {
		t.value = 'Търсене';
	}	
	t.style.color = '#A4A4A4';
}

function rldContentBuletin(t) {	
	if (t.value == 'Вашата е-поща') {
		t.value = '';
	}
	t.style.color = '#000';
}

function rldContentBuletin2(t) {
	if (!t.value) {
		t.value = 'Вашата е-поща';
	}	
	t.style.color = '#A4A4A4';
}

function hideGalPic(n) {
	var hold = document.getElementById('nextPic');
	
	if(!hold) {
		hold = document.getElementById('pic_' + n);
		hold.style.cursor = 'default';
	}
	
	if (document.getElementById) {
		document.getElementById('picNoScript_' + n).style.display = 'none';
	}
}

function doNext() {
	var ActiveNext = '<a href="javascript: void(0);" onclick="showDivNext({storyid}); return false;" title="следваща"><img src="/i/go-next.png" alt="следваща" style="border: 0px" /></a> <a id="nextBut" name="nextBut" onclick="showDivNext({storyid});return false;" href="javascript:void(0);">следваща</a>';
	var InActiveNext = '<img src="/i/go-next.png" alt="следваща" style="border: 0px" /> <span style="color:silver;">следваща</a>';
	var bts = document.getElementsByName(NDIV);
	var i;
	
	if(currentPic < (NUM_PICS)) {
		//document.getElementById(NDIV).style.textDecoration='none';
		//document.getElementById(NDIV).style.color='';
		
		for (i = 0; i < bts.length; i ++) {
			bts[i].style.textDecoration='underline';
			bts[i].style.color='';			
		}
		
	} else {
		for (i = 0; i < bts.length; i ++) {
			//~ bts[i].style.textDecoration='line-through';
			//~ bts[i].style.color=DISABLECOLOR;
			document.getElementById('HoldnextBut').innerHTML = InActiveNext;
		}		
		
		//document.getElementById(NDIV).style.color=DISABLECOLOR;
		//document.getElementById(NDIV).style.textDecoration='line-through';
	}
}

function doBack(){
	var ActivePrev = '<a id="prevBut" name="prevBut" onclick="showDivPrev({storyid});return false;" href="javascript:void(0);">предишна</a> <a href="javascript: void(0);" onclick="showDivPrev({storyid}); return false;" title="предишна"><img src="/i/go-previous.png" alt="предишна" style="border: 0px;" /></a>';
	var InActivePrev = '<span style="color:silver;">предишна</span> <img src="/i/go-previous.png" alt="предишна" style="border: 0px;" />';
	var bts = document.getElementsByName(BDIV);
	var i;	
	
	if(currentPic > 1) {
		for (i = 0; i < bts.length; i ++) {
			bts[i].style.textDecoration='underline';
			bts[i].style.color='';			
		}		
		//document.getElementById(BDIV).style.textDecoration='none';
		//document.getElementById(BDIV).style.color='';
	} else {
		for (i = 0; i < bts.length; i ++) {
			//~ bts[i].style.textDecoration='line-through';
			//~ bts[i].style.color=DISABLECOLOR;
			document.getElementById('HoldprevBut').innerHTML = InActivePrev;
		}			
		//document.getElementById(BDIV).style.color=DISABLECOLOR;
		//document.getElementById(BDIV).style.textDecoration='line-through';
	}
	//alert(bts[0].style.textDecoration);
}

function showDiv(nDiv) {
	for(var i = 1; i <= NUM_PICS; i++) {
		
		//~ if (NUM_PICS > 1) {
			//~ document.getElementById(LINKID_PREF + i).style.backgroundPosition= '0 0';
			//~ document.getElementById(LINKID_PREF + i).className = '';
			
			//document.getElementById(LINKID_PREF + i).style.color= currentPicColor;
		//~ }
		
		var buttonid = i;
		var id = PICID_PREF + i;
		var node = document.getElementById(id);
		if(node && i==nDiv) {
			node.style.display='block';
			currentPic = i;
			document.getElementById(LINKID_PREF + i).style.backgroundPosition= '0 -112px';
			//document.getElementById(LINKID_PREF + currentPic).style.color= unselectedColor;
		} else if(node) {
			node.style.display='none';
			document.getElementById(LINKID_PREF + i).style.backgroundPosition= '';
		}
	}
	doBack();
	doNext();
}

function showDiv2(nDiv) {
	for(var i = 1; i <= NUM_PICS; i++) {
		var buttonid = i;
		var id = PICID_PREF + i;
		var node = document.getElementById(id);
		if(node && i==nDiv) {
			node.style.display='block';
			currentPic = i;			
		} else if(node) {
			node.style.display='none';			
		}
	}
	doBack();
	doNext();
}

function showRelDiv(nDiv) {
	for(var i = 1; i <= NUM_PICS; i++) {
		
		var buttonid = i;
		var id = PICID_PREF + i;
		var node = document.getElementById(id);
		if(node && i==nDiv) {
			node.style.display='block';
			currentPic = i;
		} else if(node) {
			node.style.display='none';
		}
	}
	doBack();
	doNext();		
}

function showDivPrev(storyid) {
	var prevPic = currentPic - 1;
	if(currentPic > 1) {
		if (!RelGall) {
			window.location = '?storyid=' + storyid + '&pic=' + prevPic + '#pic_' + prevPic;
		} else {
			showRelDiv(currentPic - 1);
		}
	}
}

function showDivNext(storyid) {
	var nextPic = currentPic + 1;
	if(currentPic < NUM_PICS) {
		if (!RelGall) {
			window.location = '?storyid=' + storyid + '&pic=' + nextPic + '#pic_' + nextPic;
		} else {
			showRelDiv(currentPic + 1);
		}
	}
}

//~ function showDivPrev() {
	//~ if(currentPic > 1) {
		//~ if (!RelGall) {
			//~ showDiv(currentPic - 1);
		//~ } else {
			//~ showRelDiv(currentPic - 1);
		//~ }
	//~ }
//~ }

//~ function showDivNext() {
	//~ if(currentPic < NUM_PICS) {
		//~ if (!RelGall) {
			//~ showDiv(currentPic + 1);
		//~ } else {
			//~ showRelDiv(currentPic + 1);
		//~ }				
	//~ }
//~ }

function showDivPrev2() {
	if(currentPic > 1) {
		showDiv2(currentPic - 1);		
	}
}

function showDivNext2() {
	if(currentPic < NUM_PICS) {
		showDiv2(currentPic + 1);
	}
}

function GallInit(galpic) {
	var i;

	for (i = 1; i < 20; i ++) {
		if (document.getElementById(NAV_DIV + i)) {
			document.getElementById(NAV_DIV + i).style.display='block';
		}
	}
	if (!galpic) {
		showDiv(1);
	} else {
		showDiv(galpic);
	}
}
function GallInitShort() {
	showDiv2(1);
}
function RelGallInit() {
	showRelDiv(1);
	document.getElementById(NAV_DIV).style.display='block';
}

function openw(url, title, options) {
	var newwin = window.open(url, title, options);
	newwin.focus();
}

var MinCookieName = 'ObjMinimize';
var MinCookieDays = 30;
var CVal = readCookie(MinCookieName);

function ObjMinimize(objid, butid) {
	var obj = document.getElementById(objid);
	ChngShowHideBut(butid);
	
	if (!readCookie(MinCookieName)) {
		createCookie(MinCookieName, '', MinCookieDays);
	}
	
	if (obj.style.display == '') {
		obj.style.display = 'none';
		AddHideId(objid);
	} else {
		obj.style.display = '';
		RemoveHideId(objid);
	}
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else 
		var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

function AddHideId(objid) {
	if (CVal) {
		var ids = CVal.split(',');
		var test = 0;
		for (var i=0; i < ids.length; i++) {
			if (ids[i] == objid) test++;
		}
		if (!test) CVal += ',' + objid;
	} else 
		CVal = objid;
	createCookie(MinCookieName, CVal, MinCookieDays);
}

function RemoveHideId(objid) {
	if (CVal) {
		var ids = CVal.split(',');
		CVal = '';
		for (var i=0; i < ids.length; i++) {
			if (ids[i] != objid) CVal += (CVal ? ',' : '') + ids[i];
		}
	}
	createCookie(MinCookieName, CVal, MinCookieDays);
}

function ChkHideState(objid, butid) {
	if (CVal) {
		var re = new RegExp('' + objid + '','gi');
		if (CVal.match(re)) {
			var obj = document.getElementById(objid);
			var but = document.getElementById(butid);
			obj.style.display = 'none';
			but.className = 'offon';
		}
	}
}

function ChngShowHideBut(butid) {
	var but = document.getElementById(butid);
	
	if (but.className == 'onoff')
		but.className = 'offon';
	else
		but.className = 'onoff';
}

function ShowSubmenus(parentid) {
	var mm = document.getElementById('mm' + parentid);
	var menu = document.getElementById('menu');
	var lis = menu.getElementsByTagName("li");
	
	for (var i = 0; i < lis.length; i++) {
		if (lis[i].getAttribute('parent'))
			if (lis[i].getAttribute('parent') == parentid) {
					if (mm.className == 'submenuopen')
						lis[i].className = 'hidden';
					else
						lis[i].className = 'subrubrmenu';
			} else {
				lis[i].className = 'hidden';
			}
		if (lis[i].getAttribute('sm') && lis[i] != mm) lis[i].className = 'submenu';
	}
	
	if (mm.className == 'submenu')
		mm.className = 'submenuopen';
	else
		mm.className = 'submenu';
}

function ShowSubmenusRedir(parentid, url) {
	ShowSubmenus(parentid);
	window.location = url;
}

function SetMenuCookie(rubrid) {
	createCookie('activeMenu', rubrid, 0.25); 
}
		
var kumulatsize = 0;

function vbaneri2(section, htmlstart, htmlend) {
	if (typeof(banners) == 'undefined') return false;
	if (!banners[section]) return false;
	if (showban1==1) {
		document.write(htmlstart);
		vbaneri(section);
		document.write(htmlend);
	}
}

function vbaneriArr(sectionArr, htmlstart, htmlend, separator, startrs, endrs) {
	if (typeof(banners) == 'undefined') return false;
	
	var ret = new Array(); //vzemame banerite tuk vutre
	var k = 0;
	for(var i=0; i<sectionArr.length; i++) {
		if(banners[sectionArr[i]]) {
			ret[k] =  sectionArr[i];
			k++;
		}
	}
	
	if(ret.length <= 0) {
		return false;
	}
	
	document.write(htmlstart);
	for(var j=0; j<ret.length; j++) {
		if(j!=0) {
			document.write(separator);
		}
		document.write(startrs);
		vbaneri(ret[j]);
		document.write(endrs);
	}
	document.write(htmlend);
}

function vbaneridnevnik2(section, htmlstart, htmlend) {
	if (typeof(banners) == 'undefined') return false;
	if (!banners[section]) return false;
	if (showban1==1) {
		document.write(htmlstart);
		if (banners[section][6] == 2) { //ako e razlichen ot textov link da si se writeva normalno
			document.write("<h5>Спонсорирани връзки</h5><div class=\"splinks\">");
		} else {
			document.write("<a href=\"/reklama.php\">Реклама</a><center>");
		}
		document.write(singleBanner(banners[section][0], banners[section][8], banners[section][2], banners[section][3], banners[section][1], banners[section][4], banners[section][5], banners[section][6], banners[section][7], banners[section][9], banners[section][10]));
		if (banners[section][6] == 2) { //ako e razlichen ot textov link da si se writeva normalno
			document.write("</div>");
		} else {
			document.write("</center>");
		}
		document.write(htmlend);
	}
}

function megakareChageTab(t, obj) {
	t.blur();
	var http_request = getxmlhttp();
	if(!http_request) return true;
	
	http_request.onreadystatechange = function() { hndsubmit(http_request,'uraganMegaHolder'); };
	for(var i = 1; i <= 5; i++) {
		tab = document.getElementById('Uragan'+i);
		if(tab.id == t.id) {
			tab.parentNode.className = 'active';
		} else {
			tab.parentNode.className = '';
		}
	}
	
	http_request.open('GET', './?ajaxobj=' + obj, true);
	http_request.send(null);

	createCookie('DnevnikMegakareTab',t.id,0);
	createCookie('DnevnikMegakareTabObj',obj,0);
}

function photoMegakareChageTab(t, obj) {
	t.blur();
	var http_request = getxmlhttp();
	if(!http_request) return true;
	
	http_request.onreadystatechange = function() { hndsubmit(http_request,'uraganMegaPhotoHolder'); };
	for(var i = 1; i <= 3; i++) {
		tab = document.getElementById('UraganPhoto'+i);
		if(tab.id == t.id) {
			tab.parentNode.className = 'active';
		} else {
			tab.parentNode.className = '';
		}
	}
	
	http_request.open('GET', './?ajaxobj=' + obj, true);
	http_request.send(null);
}

function showMMSDiv(nDiv) {
	for(var i = 1; i <= NUM_PICS; i++) {
		var node = document.getElementById('mmsitem_' + i);
		if(node && i==nDiv) {
			node.style.display='block';
		} else if(node) {
			node.style.display='none';
		}
	}
}

function mmsDoBack(rownum) {
	var nDiv = rownum - 1;
	if (nDiv < 1) nDiv = 1;
	showMMSDiv(nDiv);
}

function mmsDoNext(rownum) {
	var nDiv = rownum + 1;
	if (nDiv > NUM_PICS) nDiv = NUM_PICS;
	showMMSDiv(nDiv);
}

function genrandom(i) {
	return Math.floor(Math.random()*i+1)
}

function anketatest() {
	var CVal = readCookie('anketa1');
	var cdays = 1;
	if (CVal) return;
	if(genrandom(3) == 3) {
		if (confirm('Желаете ли да участвате в анкета на вестник Дневник?')) {
			cdays = 300;
			window.open('/anketa/');
		}
	}
	createCookie('anketa1', '1', cdays);
}

function anketapopup() {
	var cdays = 1;
	var CVal = readCookie('anketa1');
	if (CVal) return;
	if(genrandom(7) == 7) {
		w = window.open("/anketa.html", "anketa", "width=600,height=250,scrollbars=0,resizable=1,status=0,toolbar=0,location=0,menubar=0,directories=0");
	}
	createCookie('anketa1', '1', cdays);
}

function anketapopupext() {
	var cdays = 60;
	var CVal = readCookie('anketaext');
	var curDay = new Date;
	
	curDay = curDay.getDay();
	
	if(CVal && CVal == curDay) return;
	
	w = window.open("http://infovalidator.com/ic/popup.php?&encID=~VGhaKAFzVzZUZQ_3D_3D%3C=eng", "anketaext", "width=620,height=450,scrollbars=0,resizable=1,status=0,toolbar=0,location=0,menubar=0,directories=0");
	createCookie('anketaext', curDay, cdays);
}

function anketaok() {
	cdays = 300;
	createCookie('anketa1', '1', cdays);
	window.open('/anketa/', 'anketareal', 'width=1024,height=700,scrollbars=1,resizable=1,status=1,toolbar=1,location=1,menubar=1,directories=1');
	window.close();
	return false;
}

function anketacancel() {
	window.close();
}

//window.onload = anketatest;

function showBizkit(p) {
	var mShowMe;
	var mHideMe;
	
	if(p == 1) {
		mShowMe = document.getElementById('bizkit1');
		mHideMe = document.getElementById('bizkit2');
		document.getElementById('BizkitBG').style.fontWeight = 'bold';
		document.getElementById('BizkitEU').style.fontWeight = 'normal';
	} else {
		mShowMe = document.getElementById('bizkit2');
		mHideMe = document.getElementById('bizkit1');
		document.getElementById('BizkitBG').style.fontWeight = 'normal';
		document.getElementById('BizkitEU').style.fontWeight = 'bold';
	}
	
	mShowMe.style.display = 'block';
	mHideMe.style.display = 'none';
}


function mmsnewChangeNext(t) {
	var http_request = getxmlhttp();
	if (!http_request) return true;
	
	http_request.onreadystatechange = function() { hndsubmit(http_request, 'mmschange'); };
	http_request.open('GET', './?ajaxobj=newmms&p=' + t, true);
	http_request.send(null);
}

function ajaxSend(url,responseDivId) {
	var http_request = getxmlhttp();
	if (!http_request) return true;
	
	http_request.onreadystatechange = function() { hndsubmit(http_request, responseDivId); };
	http_request.open('GET', url, true);
	http_request.send(null);
}

function StoryGalInit() {
	var lenta = document.getElementById('Klenta');
	
	if(GALCNT > 1) {
		var imghold = document.getElementById('agImg_1');
		
		imghold.style.display = 'block'; //da se pokaje purvata snimka
		
		lenta.innerHTML = StoryGalMenu(null, GALCNT);
		
	} else if(GALCNT == 1) {
		var imghold = document.getElementById('agImg_1');
		imghold.style.display = 'block';
		lenta.style.display = 'none';
	}
	return false;
}

function StoryGalShow(showpage) {
	var lenta = document.getElementById('Klenta');
	var imghold;
	
	for(var i=1; i<=GALCNT; i++) {
		if(i == showpage) {
			imghold = document.getElementById('agImg_' + i);
			imghold.style.display = 'block';
		} else {
			imghold = document.getElementById('agImg_' + i);
			imghold.style.display = 'none';
		}
	}
	
	lenta.innerHTML = StoryGalMenu(showpage,GALCNT);
	return false;
}

function StoryGalMenu(curpage, totalpages) {
	var tCurPage;
	var nav = '<span id="Kstranici">';
	var prevImg = '<p id="Kpager">';
	var nextImg = '';
	
	
	if(!curpage) tCurPage = 1;
	else tCurPage = curpage;
	
	if(tCurPage == 1) {
		prevImg += '<span id="Kpurv">Предишна снимка</span>';
	} else {
		prevImg += '<a href="javascript:void(0);" onclick="StoryGalShow(' + (tCurPage - 1) + ')" id="Kpred" title="Предишна снимка">Предишна снимка</a>';
	}
	
	for(var i = 1; i<= totalpages; i++) {
		if(i == totalpages && i == tCurPage) {
			nav += ' <strong id="Kclean">' + i + '</strong>';
		} else if(i == tCurPage) {
			nav += ' <strong>' + i + '</strong>';
		} else if(i == totalpages && i != tCurPage) {
			nav += ' <a id="Kclean" href="javascript:void(0);" onclick="StoryGalShow(' + i + ')" >' + i + '</a>';
		} else {
			nav += ' <a href="javascript:void(0);" onclick="StoryGalShow(' + i + ')" >' + i + '</a>';
		}
	}
	
	nav += '</span>';
	
	if(tCurPage == totalpages) {
		nextImg += '<span id="Klast">Следваща снимка</span></p>';
	} else {
		nextImg += '<a href="javascript:void(0);" onclick="StoryGalShow(' + (tCurPage + 1) + ')" id="Ksled" title="Следваща снимка">Следваща снимка</a></p>';
	}
	
	return prevImg + nav + nextImg;
}


function galPicNextImg(p) {
	var hold = document.getElementById('nextPic');
	if(hold) {
		document.location.href= hold.href;
	} 
	
	return false;
}

function calendarChangeMonth(m,y,rn) {
	var http_request = getxmlhttp();
	if (!http_request) return true;
	
	http_request.onreadystatechange = function() { hndsubmit(http_request, 'clndrbox'); };

	http_request.open('GET', './?ajaxobj=calendar&m=' + m + '&y=' + y + '&rubrikaname=' + rn, true);
	http_request.send(null);
	return false;
}

 function showhideDiv(param, lnk){
	var dv = document.getElementById(param);

	if(dv.style.display == 'none'){
		lnk.className = 'dBarrwOn';
		dv.style.display = 'block';
	}else{
		lnk.className = 'dBarrw';
		dv.style.display = 'none';
	}
}

//uragan jQuery

jQuery(document).ready(function() {
	jQuery('.buttons li').hover(
			function() {
					if(this.className != 'active' && this.id != 'AP') {
						this.className += ' hover';
					}
			},
			function() {
					if(this.className != 'active' && this.id != 'AP') {
						this.className = this.className.replace(/hover/g, '');;
					}
			}
	);
	jQuery('.click').hover(
			function() {
				this.className += ' clickhover';
			},
			function() {
				var clN = this.className;
				this.className = clN.replace(/clickhover/g, '');
			}
	);
	
	tl = jQuery('.treelist > li > strong');
	if (tl) {
		tl.each(function() {makeTreeList(this)});
	}
	
	if(typeof(activeWeatherCity) != 'undefined') {
		setInterval('uraganWeatherFx()', 10000);
		setInterval('uraganValutiFx()', 10000);
		setInterval('uraganIndicesFx()', 10000);
	}
	
	var dnkstrysize = readCookie('dnevnikstorysize');
	var artclhold = jQuery('div.article');
	if(artclhold.length && dnkstrysize) {
		artclhold.css('font-size', dnkstrysize + 'px');
	}
	
	var bigGalleryStory = jQuery('.albumPhotos');
	if(bigGalleryStory.length) { //koda da se izpulnqva samo ako ima takuv div
		jQuery('#msg').focus(function(e) {
			if(typeof(galKeyPressHandler) == 'function') {
				jQuery(document).unbind('keyup', galKeyPressHandler);
			}
		});
		
		jQuery('#msg').change(function(e) {
			if(typeof(galKeyPressHandler) == 'function') {
				jQuery(document).unbind('keyup', galKeyPressHandler);
			}
		});
		
		jQuery('#msg').blur(function(e) {
			jQuery(document).bind('keyup', galKeyPressHandler);
		});
		
		function galKeyPressHandler(e) {
			if(e.keyCode == 39) { //next ->
				var nextlnk = jQuery('span:visible div.gallery ul.buttons li.right a');
				if(nextlnk.length) {
					document.location.href= nextlnk[0].href;
				}
			} else if(e.keyCode == 37) { //prev <-
				var prevlnk = jQuery('span:visible div.gallery ul.buttons li:not(.right) a');
				if(prevlnk.length) {
					document.location.href= prevlnk[0].href;
				}
			} else {
				return false;
			}
		};
		
		jQuery(document).bind('keyup',galKeyPressHandler);
	}
	
	var pmms = jQuery('#pmms');
	var nmms = jQuery('#nmms');
	if(pmms.length || nmms.length) {
		var mmsKeyUpHandler = function(e) {
			if(e.keyCode == 39) {
				if(nmms.length) {
					document.location.href = nmms.attr('href');
				} else {
					return false;
				}
			} else if(e.keyCode == 37) {
				if(pmms.length) {
					document.location.href = pmms.attr('href');
				} else {
					return false;
				}
			} else {
				return false;
			}
		}
		
		jQuery(document).bind('keyup', mmsKeyUpHandler);
		
		jQuery('#msg').focus(function(e) {
			if(typeof(mmsKeyUpHandler) == 'function') {
				jQuery(document).unbind('keyup', mmsKeyUpHandler);
			}
		});
		
		jQuery('#msg').change(function(e) {
			if(typeof(mmsKeyUpHandler) == 'function') {
				jQuery(document).unbind('keyup', mmsKeyUpHandler);
			}
		});
		
		jQuery('#msg').blur(function(e) {
			jQuery(document).bind('keyup', mmsKeyUpHandler);
		});
	}
});

function makeTreeList(pobj) {
	jQuery(pobj).click(function() {
		var liel = jQuery(this.parentNode);
		var lpos = liel.attr("mypos");
		if (lpos) {
			liel.append("<div>зареждане...</div>");
			jQuery(liel.find('strong')[0]).toggleClass("arrdown");
			liel.find('div').load('./?ajaxobj=vestnikrubrs&newpos=' + lpos, null, function(pRes, pStatus, pXml) {
				jQuery(this).find('li > strong').each(function() {makeTreeList(this)});
			});
			liel.attr("mypos", "");
		} else {
			jQuery(liel.find('strong')[0]).toggleClass("arrdown");
			liel.find('div').toggle();
		}
	});
}

function uraganIndicesFx() {
	if(typeof(activeIndex) != 'undefined') {
		jQuery('#uraganIndices' + activeIndex).toggle();
		if(activeIndex >= maxactiveIndices) {
			activeIndex = 1;
		} else {
			activeIndex++;
		}
		jQuery('#uraganIndices' + activeIndex).toggle();
	}
	
	return false;
}

function uraganValutiFx() {
	if(typeof(activeValuti) != 'undefined') {
		jQuery('#uraganValuti' + activeValuti).toggle();
		if(activeValuti >= maxactiveValuti) {
			activeValuti = 1;
		} else {
			activeValuti++;
		}
		jQuery('#uraganValuti' + activeValuti).toggle();
	}
	
	return false;
}

function uraganWeatherFx() {
	if(typeof(activeWeatherCity) != 'undefined') {
		jQuery('#uraganWeather' + activeWeatherCity).toggle();
		if(activeWeatherCity == totalWeatherCity) {
			activeWeatherCity = 1;
		} else {
			activeWeatherCity++;
		}
		jQuery('#uraganWeather' + activeWeatherCity ).toggle();
	}
	
	return false;
}

function uraganTvTab(tvid, p) {
	if(activeTVprog != tvid) {
		jQuery('#nowshowing' + activeTVprog).toggle();
		jQuery('#tvtab' + activeTVprog).removeClass('active');

		jQuery('#nowshowing' + tvid).toggle();
		p.blur();
		p.parentNode.className = 'active';
		
		activeTVprog = tvid;
	}
}

function uraganMiniSearch() {
	var labelCollection;
	var searchQry = Array();
	
	labelCollection = jQuery('.aFilter input');
	for(var i=0; i < labelCollection.length; i++) {
		if(labelCollection[i].checked) {
			searchQry.push(labelCollection[i].value);
		}
	}
	
	location.href= '/search/?stext=' + encodeURIComponent(searchQry.join(' & ')) + '&searchinto=3';
}

function resize(oper, p) {
	p.blur();
	var elem = jQuery('.article');
	var curFontSize = parseInt(elem.css('font-size'));
	if (oper == 1) {
		if(curFontSize <= 24) {
			newFontSize = curFontSize + 2;
			elem.css('font-size',newFontSize);
		}
	} else if(!oper) {
		if(curFontSize > 10) {
			newFontSize = curFontSize - 2;
			elem.css('font-size',newFontSize);
		}
	} else {
		elem.css('font-size', 14);
		newFontSize = 14;
	}
	
	createCookie('dnevnikstorysize',newFontSize, 365);
	
	return false;
}

function voteForMsg(msgid, vote, commentHolderId) {
	var intvote;
	var http_request = getxmlhttp();
	if (!http_request) return true;
	if (!msgid || !vote) return false;
	
	if(vote == '+') {
		intvote = 'u';
	} else if(vote == '-') {
		intvote = 'd';
	} else {
		return false;
	}
	
	http_request.onreadystatechange = function() { 
		voteForMsgResponse(http_request,msgid, commentHolderId);
	};
	
	http_request.open('GET', '/voteform.php?msg=' + msgid + '&vote=' + intvote, true);
	http_request.send(null);
	return false;
}

function voteForMsgResponse(p, msgid, commentHolderId) {
	var rateHolder = document.getElementById('rate_' + msgid);
	var usrrateHolder = document.getElementById('usrvotes_' + msgid);
	
	if(typeof(p.responseText) == 'undefined') {
		return false;
	}
	
	var rez = p.responseText.split('/');
	
	if(typeof(rez[0]) != 'undefined') {
		rateHolder.innerHTML = '<em>Оценка:	' + rez[0] + '</em>';
	}
	if(typeof(rez[1]) != 'undefined') {
		if(rez[1] == 1)  {
			var rezstr = ' глас';
		} else {
			var rezstr = ' гласа';
		}
		usrrateHolder.innerHTML = rez[1] + rezstr;
	}
	
	if(parseInt(rez[0]) < 15) {
		var cmntHolder = document.getElementById(commentHolderId);
		if(cmntHolder.className.indexOf('yellow')) {
			cmntHolder.className = cmntHolder.className.replace(/yellow/g,'');
		}
	} else if(parseInt(rez[0]) == 15) {
		var cmntHolder = document.getElementById(commentHolderId);
		if(cmntHolder.className.indexOf('yellow') == -1) {
			cmntHolder.className += ' yellow';
		}
	}
	
	jQuery('#msgid' + msgid + ' li.eMinus').toggle();
	jQuery('#msgid' + msgid + ' li.ePlus').toggle();
	
	return false;
}

function uraganCal(rubrname) {
	var month = document.getElementById('calm');
	var year = document.getElementById('caly');
	
	calendarChangeMonth(month.value,year.value,rubrname);
	return false;
}

function toggle(id) {
	var hold = document.getElementById(id);
	
	if(hold.style.display == 'block') {
		hold.style.display = 'none';
	} else if(hold.style.display == 'none') {
		hold.style.display = 'block';
	}
	
	return false;
}

function idxchartswitch(p) {
	jQuery('#idxchartswitches li').removeClass('active');
	p.parentNode.className = 'active';
}

function redirectSearch() {
	var code = jQuery('#tickerhid').val();
	if(code && code.length > 0) {
		window.location = '/pazari/profile/' + code + '/';
	}
	
	return false;
}

function sportrezChange(p,val) {
	if(val && p) {
		var old = jQuery('#rezultatidiv ul.buttons li.active');
		if(old.length) {
			old.removeClass('active');
		}
		var newb = jQuery(p);
		newb.parent().addClass('active');
		newb.blur();
		
		ajaxSend('./?ajaxobj=sportrezbox&guid='+val, 'sportrezbox');
	}
	return false;
}


