function vote(vote_id, users_vote_id, part_name, type, city_url) 
{
	$.post("/"+city_url+"/vote", {"rumor_id": vote_id, "user_id": users_vote_id, "part_name": part_name, "vote_operation": type},
	function(data){
		$("#answer").html(data);
		$("#answer").slideDown();
		setTimeout('$("#answer").slideUp()',6000);
	});
}

function gotoevent(event_id, operation, city_url)
{
	$.post("/"+city_url+"/gotoevent", {"event_id": event_id, "operation": operation},
	function(data){
		$("#answer").html(data);
		$("#answer").slideDown();
		setTimeout('$("#answer").slideUp()',6000);
	});
}

function hide_gogo (event_id, city_url) {
	$("#gotobutt").html('<a href="javascript:void(0)" onclick="gotoevent('+event_id+', 0, \''+city_url+'\')"><img src="/i/buttons/del_red.gif" align="absmiddle" width="18" height="18" /> Не иду на это событие</a>')
}

function hide_goaway (event_id, city_url) {
	$("#gotobutt").html('<a href="javascript:void(0)" onclick="gotoevent('+event_id+', 1, \''+city_url+'\')"><img src="/i/buttons/add_violet.gif" align="absmiddle" width="18" height="18" /> Иду на это событие</a>')
}

function sendcomment(item_id, item_type, item_type_4_subscriber, col_comments, city_url)
{
	var sMessage = $("#message").val();
	if (sMessage != "")
	{
		$.post("/"+city_url+"/addcommentlive",{"message": sMessage, "item_id": item_id, "item_type": item_type, "item_type_4_subscriber": item_type_4_subscriber, "col_comments": col_comments},
		function(data)
		{
			if (data == 0)
			{
				$("#answer").html(data);
				$("#answer").slideDown();
				setTimeout('$("#answer").slideUp()',1000);
				
			}
			else
			{
				$("#commentstoadd").prepend(data);
				$(".newcomment").slideDown("slow");
				//$(".newcomment").animate( { opacity: 0.1 }, { queue:true, duration:100 } )
				//.animate( { opacity: 1 }, 700 );
			}
			$("#addonemore").slideDown();
			
		});
	}
	else
	{
		$("#answer").html('А где же комментарий?! Вы забыли его написать!');
		$("#answer").slideDown();
		setTimeout('$("#answer").slideUp()',1000);
		
	}
}

function showCommentForm()
{
	$("#addonemore").slideUp();
	$("#message").val("");
	$("#csf").slideDown();
}

function subscribe2comments(subscriber_id, operation, subscribe_item_id, subscribe_item_type, city_url)
{
	$.post("/"+city_url+"/subscribe", {"subscriber_id": subscriber_id, "operation": operation, "item_id": subscribe_item_id, "item_type": subscribe_item_type},
			function(data){
				if (data == 1)
				{
					$("#answer").html('<div class="error2">При подписке на комментраии произошла ошибка. Сервис временно не работает. Попробуйте позже.</div>');
					$("#answer").slideDown();
					setTimeout('$("#answer").slideUp()',6000);
				}
				else if ( data == 0 )
				{
					$("#answer").html('<div class="error2">Только зарегистрированные пользователи могут оформить подписку на комментарии.</div>');
					$("#answer").slideDown();
					setTimeout('$("#answer").slideUp()',6000);
				}
				else
				{
					$("#subscribe").html(data);
				}
			});
}

function openPopup(url, w, h)
{
	height = h + 1;
	width = w + 1;
	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	top = (myHeight-height)/2;
	left = (myWidth-width)/2;

	newWin = open(url, '', 'resizable=no,left='+left+',top='+top+',width='+width+',height='+height+',scrollbars=yes,status=no,toolbar=no,menubar=no');
}

function openZoom(img,t,w,h)
{
	height = h + 1;
	width = w + 1;
	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	top = (myHeight-height)/2;
	left = (myWidth-width)/2;

	newWin = open('', '_blank', 'resizable=no,left='+left+',top='+top+',width='+width+',height='+height+',scrollbars=1,status=no,toolbar=no,menubar=no');
	newWin.document.open();
	newWin.document.write('<html><head><title>style.dp.ua</title><meta http-equiv="Content-Type" content="text/html;charset=windows-1251"><style>body {margin:0;padding:0;font-family:Verdana,Tahoma,Arial,sans-serif} td, div {font-size:12px}</style></head>'+"\r\n");
	newWin.document.write('<body bgcolor="#FFFFFF" text="#000000">'+"\r\n");
	newWin.document.write('<table cellspacing="0" cellpadding="0" border="0">');
	newWin.document.write('<tr><td bgcolor="#EEEEEE"><a href="" onclick="window.close();return false;"><img src="'+img+'" width="'+w+'" height="'+h+'" alt="" border="0"></a></td></tr>');
	if (t!='')
	{
		newWin.document.write('<tr valign="top"><td><table cellspacing="0" cellpadding="0" border="0" width="100%"><tr valign="top"><td style="border-top:1px solid #999;padding:10px 20px 10px 0"><b>'+t+'</b></td></tr></table></td></tr>');
	}
	newWin.document.write('</table>');
	newWin.document.write('</body></html>');
	newWin.document.close();
}

function imgopen(imgf,tit)
{
	rand_id='image'+(Math.round(Math.random()*1000));

	outf="<html>"
	+"<head>"
	+"<title>"+tit+"</title>"
	+"<style>body{margin:0px}</style>"
	+"</head>"
	+"<body leftmargin=0 topmargin=0>"
	+"<img src=\""+imgf+"\">";

	iopen="iwin=self.open('"+imgf+"', '"+rand_id+"', 'width='+(img1.width)+',height='+(img1.height)+',top=0,left=0');"
	+"iwin.document.write('"+outf+"');"
	+"iwin.focus();";

	img1=new Image();
	img1.src=imgf;

	if(img1.width!=0) eval(iopen);

	else{
		iwin = self.open('about:blank', 'f'+rand_id, 'width=200,height=200,top=0,left=0');
		iwin.document.write("<html>"
		+"<body>Загрузка...<br>"
		+"<"+"script>"+"function imo(img1){"+iopen+"self.close();"+"}<"+"/script>"
		+"<img src='"+imgf+"' onload='imo(this);'>");
 }
}


function select_all(checked, arr_name)
{
	var f = document.Form;
	if(!f)
		f = document.form1;
	for (i=0;i<f.length;i++)
	{
		if (f.elements[i].name.indexOf(arr_name)!=-1 && f.elements[i].type.toLowerCase() == "checkbox" )
		{
			f.elements[i].checked = checked;
		}
	}
}

function hideLayer(id) {
	document.getElementById(id).style.display = "none"
}

function showLayer(id) {
	document.getElementById(id).style.display = "block"
}

function characterCount(textarea, form_name, counter_name) {
    if (textarea.value.length > 3500)
        textarea.value = textarea.value.substring(0, 3500);
    document.forms[form_name].elements[counter_name].value = textarea.value.length;
}

function post(act, data, formName){


	if (formName != null){
		formObj = eval ('document.' + formName);
		if(!formObj)
		{
			formObj = eval(formName);
		}
	} else {
		formObj = document.forms[0];
	}

	formObj.elements["act"].value = act;

	if (data != null){
		formObj.elements["somedata"].value = data;
	}
	formObj.submit();
}


function confirmPost(confirmMsg, act, data, formName)
{ 
   var is_confirmed = confirm(confirmMsg);

   var formName = (formName == null)?data:formName;
  
   if (is_confirmed){
	   post(act, data, formName);
	   return true;
   } else {
	   return false;
   }
}

var scr='/tpl/popup.tpl.html'; // где находится файл с шаблоном попапа

function imgWin(img,tit, w, h)
{
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2;
	var wn = window.open(scr+'?'+escape(img), tit,'resizable,width='+w+',height='+h+',screenX=0,screenY=0,top='+t+',left='+l+',status=no,toolbar=no,menubar=no');
	wn.focus();
	return false;
}
var req_countryCity = false;

function setOptions(select, arr)
{
	select.length = 0;
	for (var i in arr) {
		select.options[select.length] = new Option(arr[i], i, false, false);
	}
	select.selectedIndex = 0;
	select.disabled = false;
	return;
}

function doLoad_city(form, nm)
{
	if (!req_countryCity)
		req_countryCity = new Subsys_JsHttpRequest_Js();
	form.elements[nm+"_city"].disabled = true;
	var country = form.elements[nm+"_country"].options[form.elements[nm+"_country"].selectedIndex].value;
	if (country) {
		req_countryCity.onreadystatechange = function() {
			if ( req_countryCity.readyState == 4 && req_countryCity.responseJS && req_countryCity.responseJS.citys)
			{
//				alert(req_countryCity.responseJS.citys);
				eval("cc = {"+req_countryCity.responseJS.citys+"};");
				setOptions(form.elements[nm+"_city"], cc);
			}
		}
		req_countryCity.caching = false;
		req_countryCity.open('GET', '/gen/reg_city.php', true);
		req_countryCity.send({ c: country });
	} else {
		setOptions(form.elements[nm+"_city"], []);
	}
}

function doLoad_profile(form, nm)
{
	var city = form.elements["city_id"].value;

	onAjaxFail = function()
	{
		alert("AJAX call failed!");
		form.elements["city_id"].disabled = false;
	}

	onAjaxDone = function(ajaxObj, responseText)
	{
		if(responseText != "error")
		{
			eval("cc = {"+responseText+"};");
			setOptions(form.elements[nm], cc);
			form.elements["city_id"].disabled = false;
		}
	}

	form.elements["city_id"].disabled = true;

	var ajax = new Ajax(onAjaxDone, onAjaxFail);

	args = {
		"city" : city,
		"name" : nm
	};

	ajax.get("/gen/get_profiles.php", args);
}

function onSuccess(data)
{
	$("#inproc").fadeOut();
	$("#success").html(data);
	$("#success").slideDown();
}

function addBlockImage (id, path, site) {
	var params = "imgPath="+path;
	if (site) params += "&site="+site;
	
	AC_FL_RunContent(
		'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0',
		'width','200',
		'height','150',
		'src','/flash/blockImage.swf',
		'quality','high',
		'wmode','transparent',
		'menu','false',
		'pluginspage','http://www.macromedia.com/go/getflashplayer',
		'movie','/flash/blockImage.swf',
		'flashVars',params
	); //end AC code
}

function addBlockImageAD (id, path, site) {
	addBlockImage (id, path, site);	
}

function addFlashBlock (id, url, width, height, site) {
	var w = (width) ? width : 410;
	var h = (height) ? height : 260;

	var params = "";
	if(site) params = "site="+site.split('&').join('*');

	AC_FL_RunContent(
		'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0',
		'width',w,
		'height',h,
		'src',url,
		'quality','high',
		'wmode','opaque',
		'menu','false',
		'pluginspage','http://www.macromedia.com/go/getflashplayer',
		'movie',url,
		'flashVars',params
	); //end AC code
}

function addFlashBlockAD (id, url, width, height, site) {
	addFlashBlock (id, url, width, height, site);
}

function showLoginForm () {
	$('#loginButtons').hide();
	$('#formCity').hide();
	$('#loginForm').show('fast');
}

function showLoginResult () {
	$('#loginForm').hide();
	$('#loginResult').show('fast');
	$('#formCity').show('fast');
}

function checkLogin () {
	var elm, l, p;	
	elm = document.getElementById('login');
	if(elm && elm.value.length < 1) {
		alert('Введите логин и пароль!');
		return false;
	}
	elm = document.getElementById('password');
	if(elm && elm.value.length < 1) {
		alert('Введите логин и пароль!');
		return false;
	}
	return true;
}


function addDefaultText (field, text) {

	field = document.getElementById(field);

	field.defaultText = text;
	function changetype () {
		if(lastField) lastField.value = '';
	}
	
	field.onclick = function () {
		if (this.value == this.defaultText) this.value = '';
	}

	field.onblur = function () {
		if (this.value == '') this.value = this.defaultText;
	}
	field.onblur();
}

function addCommentName (name) {
	var field = document.getElementById('message');
	if (field) {
		field.value += '*' + name + '* ';
		field.focus();
	}
}

function showWindow (url, maxWidth, maxHeight, scrollbars) {
	maxWidth = parseInt(maxWidth);
	maxHeight = parseInt(maxHeight);
	var addSize = (scrollbars) ? 40 : 0;
	var w = Math.min(screen.width - 40, maxWidth + addSize);
	var h = Math.min(screen.height - 40, maxHeight + addSize);
	var l = Math.round((screen.width - w) / 2);
	var t = Math.round((screen.height - h) / 2);
	var wn = window.open(url, '', 'resizable,' + ((scrollbars) ? 'scrollbars=1,' : '') + 'width='+w+',height='+h+',screenX=0,screenY=0,top='+t+',left='+l+',status=no,toolbar=no,menubar=no');
	wn.focus();
}


var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}

        var map; var geoResult;
        function mapinit (cityN) {
		map = new YMaps.Map(document.getElementById("YMapsID"));
		if (cityN == 'Днепропетровск') {
			map.setCenter(new YMaps.GeoPoint(34.958559,48.439003), 11);
		} else {
			map.setCenter(new YMaps.GeoPoint(30.557865,50.447132), 11);
		}
		map.addControl(new YMaps.TypeControl());
		map.addControl(new YMaps.ToolBar());
		map.addControl(new YMaps.Zoom());
		map.addControl(new YMaps.MiniMap());
		map.addControl(new YMaps.ScaleLine());
		map.enableScrollZoom();
		//map.GeoBounds('34.755998,48.592284','35.156997,48.358527');
		
           // ml = new YMaps.YMapsML( 'http://style.in.ua/styleobjects.xml' );
           // map.addOverlay(ml);

           // YMaps.Events.observe(ml, ml.Events.Fault, function (error) {
           //	alert('Ошибка: ' + error);
           // });
/*
			var s = new YMaps.Style();
            s.lineStyle = new YMaps.LineStyle();
            s.lineStyle.strokeColor = '0000FF55';
            s.lineStyle.strokeWidth = '5';
            YMaps.Styles.add("example#CustomLine", s);

			pl = new YMaps.Polyline([ new YMaps.GeoPoint(35.060563,48.512165),
                                  new YMaps.GeoPoint(35.061344,48.512052),
                                  new YMaps.GeoPoint(35.061066,48.511473),
                                  new YMaps.GeoPoint(35.060078,48.511676),
                                  new YMaps.GeoPoint(35.060266,48.51204),
                                  new YMaps.GeoPoint(35.060482,48.512004),
                                  new YMaps.GeoPoint(35.060563,48.512201)
                                 ]);
            pl.setStyle('example#CustomLine');			
			map.addOverlay(pl);
*/			

		YMaps.Events.observe(map, map.Events.Click, function (mEvent) {
                var myHtml = "Значение: " + mEvent.getGeoPoint() + " на масштабе " + map.getZoom();
                map.openBalloon(mEvent.getGeoPoint(), myHtml);
            });
}

function mapinitp () {
	map = new YMaps.Map(document.getElementById("YMapsID"));
		map.setCenter(new YMaps.GeoPoint(34.958559,48.439003), 16);
		map.addControl(new YMaps.TypeControl());
		map.addControl(new YMaps.ToolBar());
		map.addControl(new YMaps.Zoom());
		//map.addControl(new YMaps.ScaleLine());
		map.enableScrollZoom();
}

function showAddress (value) {
            map.removeOverlay(geoResult);
            var geocoder = new YMaps.Geocoder(value, {results: 1, boundedBy: map.getBounds()});

            YMaps.Events.observe(geocoder, geocoder.Events.Load, function () {

                if (this.length()) {
                    geoResult = this.get(0);
                    map.addOverlay(geoResult);
                    if (geoResult.getGeoPoint().toString() != '34.958559,48.439003') { 
                    	map.panTo(geoResult.getGeoPoint());
                    	map.setBounds(geoResult.getBounds());
                    } else {
                    	document.getElementById("mapanswer").innerHTML = '<p class="error" style="margin-top:15px">Адрес не найден, попробуйте ввести другой адрес.</p>';
                    }
                }else {
                    document.getElementById("mapanswer").innerHTML = '<p class="error" style="margin-top:15px">Адрес не найден, попробуйте ввести другой адрес.</p>';
                }
            });
}