if (window.navigator.userAgent.indexOf ("MSIE") > 0) ie4=true;
else ie4=false;
var news_id, news_id_a, pr=0; var pr_a=0;
var pr_levels=0; var pr_levels_a=0; 
var level_light, level_light_a, active_news=1;
var active_news_a=1;
var nid = new Array()
var http = createRequestObject();
re = /^\s*$/;
re1 = /^([0-9a-zA-Z])+$/;
re2 = /^\d+$/;
re3= /([^<)\s]+@\S+\.[^>(\s]+)/;
re4 = /^[\d \-\+\(\),]+$/;
///////////////////////////////////////////////////////////////////////////////// 
///////////////////////////          Ajax        ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////// 
function createRequestObject()
{
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer") ro = new ActiveXObject("Microsoft.XMLHTTP");
    else ro = new XMLHttpRequest();
    return ro;
}
function handleResponse()
{
    if(http.readyState == 4)
	{
        var response = http.responseText;
        var update = new Array();
        if(response.indexOf('|' != -1))
		{
            update = response.split('|');
			re = /DOCTYPE/i;
			re2 = /reg=([0-9]{1,2})/i;
//			if (re.test(update[0])) location.href="http://nevesta.ua/";
			if (re2.test(update[0]))
			{
				var s = update[0];
				var re2 = /.*?reg=([0-9]{1,2}).*/i;
				reg=s.replace(re2, "$1");
				location.href="http://nevesta.ua/registration/?reg="+reg;
			}
			length_=update.length;
			for (i=0; i<=length_; i=i+2)
			{
//				alert(update[i]+"--"+update[i+1])
				if (document.getElementById(update[i])) document.getElementById(update[i]).innerHTML = update[i+1];
				if (update[i]=="popuptxt") Hidden("popup", "inline");
				if (update[i]=="favorites_body") Hidden("favorites", "inline");
			}
        }
    }
}
function goAjax(url)
{
//	alert(url);
    http.open("get", url);
   	http.onreadystatechange = handleResponse;
    http.send(null);
}

///////////////////////////////////////////////////////////////////////////////// 
///////////////////////////         \/Ajax        ///////////////////////////////
///////////////////////////////////////////////////////////////////////////////// 

///////////////////////////////////////////////////////////////////////////////// 
///////////////////////////			Меню		 ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////// 
function OVER(num, level)
{
	clearTimeout(pr);
	for (i=0; i<b.length; i++)
	{
		if (document.getElementById("m"+b[i])) document.getElementById("m"+b[i]).style.visibility="hidden";
	}
	if (document.getElementById("m"+num)) document.getElementById("m"+num).style.visibility="visible";
}
function OUT()
{
	for (i=0; i<b.length; i++)
	document.getElementById("m"+b[i]).style.visibility="hidden";
	clearTimeout(pr);
}
function DELAYS()
{
	pr=setTimeout("OUT()", 100);
}
///////////////////////////////////////////////////////////////////////////////// 
///////////////////////////			/Меню		 ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////// 

///////////////////////////////////////////////////////////////////////////////// 
/////////////////////////// Новости на стартовой ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////// 
function Hide2news() // функция запускается по время загрузки страницы
{
	if (ie4) document.getElementById("newi2").style.filter = "alpha(opacity=0)";
	else document.getElementById("newi2").style.opacity=0;
}
function ShowNews(id)
{
	if (id!=active_news)
	{
		news_id=id;
		n=3;
		while(n>0)
		{
			if (ie4)
			{
				level_light=100;
				document.getElementById("newi"+n).style.filter = "alpha(opacity=0)";
				document.getElementById("newi"+active_news).style.filter = "alpha(opacity=100)";
			}
			else
			{
				level_light=1.0;
				document.getElementById("newi"+n).style.opacity=0;
				document.getElementById("newi"+active_news).style.opacity=1.0;
			}
			n--;
		}
		clearInterval(pr_levels);
		clearTimeout(pr);
		pr=setTimeout("ChangeNews()", 100);
	}
}
function ChangeNews()
{
	clearTimeout(pr);
	pr_levels=setInterval("Levels()", 30);
}
function Levels()
{
	if (ie4)
	{
		document.getElementById("newi"+active_news).style.filter = "alpha(opacity="+level_light+")";
		level_light-=10;
		level_light2=100-level_light;
		document.getElementById("newi"+news_id).style.filter = "alpha(opacity="+level_light2+")";
	}
	else
	{
		document.getElementById("newi"+active_news).style.opacity = level_light;
		level_light-=0.1;
		level_light2=1.0-level_light;
		document.getElementById("newi"+news_id).style.opacity = level_light2;
	}
	if (level_light<=0)
	{
		if (ie4) document.getElementById("newi"+active_news).style.filter = "alpha(opacity=0)";
		document.getElementById("newi"+active_news).style.opacity=0;
		clearInterval(pr_levels);
		active_news=news_id;
	}
}
///////////
///////////

function Hide2news_a() // функция запускается по время загрузки страницы
{
	if (ie4) document.getElementById("newi2_a").style.filter = "alpha(opacity=0)";
	else document.getElementById("newi2_a").style.opacity=0;
}
function ShowNews_a(id)
{
	if (id!=active_news_a)
	{
		news_id_a=id;
		n=3;
		while(n>0)
		{
			if (ie4)
			{
				level_light_a=100;
				document.getElementById("newi"+n+"_a").style.filter = "alpha(opacity=0)";
				document.getElementById("newi"+active_news_a+"_a").style.filter = "alpha(opacity=100)";
			}
			else
			{
				level_light_a=1.0;
				document.getElementById("newi"+n+"_a").style.opacity=0;
				document.getElementById("newi"+active_news_a+"_a").style.opacity=1.0;
			}
			n--;
		}
		clearInterval(pr_levels_a);
		clearTimeout(pr_a);
		pr_a=setTimeout("ChangeNews_a()", 100);
	}
}
function ChangeNews_a()
{
	clearTimeout(pr_a);
	pr_levels_a=setInterval("Levels_a()", 30);
}
function Levels_a()
{
	if (ie4)
	{
		document.getElementById("newi"+active_news_a+"_a").style.filter = "alpha(opacity="+level_light_a+")";
		level_light_a-=10;
		level_light2=100-level_light_a;
		document.getElementById("newi"+news_id_a+"_a").style.filter = "alpha(opacity="+level_light2+")";
	}
	else
	{
		document.getElementById("newi"+active_news_a+"_a").style.opacity = level_light_a;
		level_light_a-=0.1;
		level_light2=1.0-level_light_a;
		document.getElementById("newi"+news_id_a+"_a").style.opacity = level_light2;
	}
	if (level_light_a<=0)
	{
		if (ie4) document.getElementById("newi"+active_news_a+"_a").style.filter = "alpha(opacity=0)";
		document.getElementById("newi"+active_news_a+"_a").style.opacity=0;
		clearInterval(pr_levels_a);
		active_news_a=news_id_a;
	}
}

///////////////////////////////////////////////////////////////////////////////// 
/////////////////////////// \Новости на стартовой ///////////////////////////////
///////////////////////////////////////////////////////////////////////////////// 
function Hidden(id, style)
{
	if (document.getElementById(id))
	{
		if (style == "table-row")
		{
				if (ie4) document.getElementById(id).style.display="inline";
				else document.getElementById(id).style.display=style;
		}
		else
		document.getElementById(id).style.display=style;
	}
}

function OnFocus(always, object, mode)
{
	if (mode==1)
	{
		if (object.value==always) object.value="";
	}
	else
	{
		if (object.value=="")
		{
			object.value=always;
			 if (always=="Искать") document.SearchForm.is_keyword.value=0; // только для поиска присваиваем переменную
		}
		else if (always=="Искать") document.SearchForm.is_keyword.value=1; // только для поиска присваиваем переменную
	}
}
///////////////////////////////////////////////////////////////////////////////// 
///////////////////////////\\Новости на стартовой////////////////////////////////
///////////////////////////////////////////////////////////////////////////////// 

function Participate()
{
	re = /^\s*$/;
	flag=true;
	with (document.DownloadPhoto)
	{
		if (re.test(photo.value))
		{
			if (document.getElementById("typecompetition").value!=591)
			{
				alert("Загрузите фотографию");
				photo.focus();
				return;
			}
		}
		if (re.test(name.value))
		{
			alert("Введите имя/имена участников");
			name.focus();
			return;
		}
		if (re.test(datewedding.value))
		{
			alert("Выберите дату свадьбы");
			datewedding.focus();
			return;
		}
		submit();
	}
}
function Vote(id, cat_id, event)
{
	for(key in nid)
	Hidden("vote"+key, "none");
	if (!event) event=window.event;
	coorY=event.clientY-350;
	document.getElementById("popup").style.top=document.documentElement.scrollTop+coorY+"px";
	url="/misc/vote.php?id="+id+"&cat_id="+cat_id;
	goAjax(url);
//	Hidden("vote", "none");
}
function hideDhtmlPop(num)
{
	Hidden("popup", "none");
}
function Horo()
{
	document.Horo.submit();
}
//////////////////// For registration /////////////////////////
function save(mode)
{
	re2 = /^\d+$/;
	flag=true;
	with (document.Form)
	{
		if (document.getElementById("registrant_type"))
		{
			if (document.getElementById("registrant_type").value==0)
			{
				alert("Выберите тип регистрации");
				return;
			}
		}
/*		if (document.getElementById("company"))
		{
			if (re.test(company.value) && document.getElementById("registrant_type").value==2)
			{
				alert("Введите название компании");
				company.focus();
				return;
			}
		}*/
		if (document.getElementById("name"))
		{
			if (re.test(name.value))
			{
				alert("Введите имя");
				name.focus();
				return;
			}
		}
		if (document.getElementById("secondname"))
		{
			if (re.test(secondname.value))
			{
				alert("Введите фамилию");
				secondname.focus();
				return;
			}
		}
		if (document.getElementById("city"))
		{
			if (city.value==0)
			{ 
				alert("Выберите город");
				return;
			}
		}
		if (document.getElementById("email"))
		{
			if (!re3.test(email.value))
			{ 
				alert("Введите email");
				email.focus();
				return;
			}
		}
		if (document.getElementById("content"))
		{
			if (re.test(content.value))
			{
				alert("Введите текст сообщения");
				content.focus();
				return;
			}
		}
		if (document.getElementById("question"))
		{
			if (re.test(question.value))
			{
				alert("Введите вопрос");
				question.focus();
				return;
			}
		}
		if (document.getElementById("comment"))
		{
			if (re.test(comment.value))
			{
				alert("Введите комментарий");
				comment.focus();
				return;
			}
		}
		if (document.getElementById("music_title"))
		{
			if (re.test(music_title.value))
			{
				alert("Введите название музыкального произведения");
				music_title.focus();
				return;
			}
		}
		if (document.getElementById("music_performer"))
		{
			if (re.test(music_performer.value))
			{
				alert("Введите имя исполнителя");
				music_performer.focus();
				return;
			}
		}
		if (document.getElementById("login"))
		{
			if (re.test(login.value))
			{
				alert("Введите логин");
				login.focus();
				return;
			}
			if ((login.value.length<4)||(login.value.length>15))
			{
				alert("Логин должен быть более 4 и менее 15 символов!");
				login.focus();
				return;
			}
		}
		if (document.getElementById("pass"))
		{
			if (re.test(pass.value) || (pass.value=="******")) 
			{
				alert("Введите пароль");
				pass.focus();
				return;
			}
			if ((pass.value.length<6)||(pass.value.length>15)) 
			{
				alert("Пароль должен быть более 6 и менее 15 символов!");
				pass.focus();
				return;
			}
			if (pass.value!=re_passwd.value)
			{
				alert("Несовпадение паролей");
				re_passwd.focus();
				return;
			}
		}
		if (document.getElementById("question"))
		{
			if (re.test(question.value) || question.value=="")
			{
				alert("Вопрос отсутствует");
				question.focus();
				return;
			}
		}
		if (document.getElementById("checknum"))
		{
			if (!re2.test(checknum.value) || checknum.value=="")
			{
				alert("Введите проверочный текст");
				checknum.focus();
				return;
			}
		}
		if (document.getElementById("sent")) document.getElementById("sent").value=1;
		submit();
	}
}
////////////////////////////////////////////////////////////////

/////////////////////// Autorissation //////////////////////////
function GO(mode)
{
	if (mode=="exit")
	{
		document.formlogin.mode.value=mode;
		document.formlogin.action="/registration/?reg=11";
		document.formlogin.submit();
	}
	else
	{
		if (mode!="sendpass") document.formlogin.mode.value=mode;
		if (mode=="reg")  document.formlogin.action="/registration/";
		if (mode=="send") document.formlogin.action="/registration/?mode="+mode;
		if (mode=="sendpass") document.SendPasswd.submit();
		else document.formlogin.submit();
	}
}
////////////////////////////////////////////////////////////////
function SUBMITT3(num, mode) // используется в регистрации
{
	if (mode==3 || mode==2) // страны в регистрации
	{
		if (document.getElementById("sel_id_"+num).options[document.getElementById("sel_id_"+num).selectedIndex].value==0)
		num--;
		if (num==0) num++;
		local_city=document.getElementById("sel_id_"+num).options[document.getElementById("sel_id_"+num).selectedIndex].value;
		document.Form.city.value=local_city
		url="/misc/edit_change_s.php?cat_id="+local_city+"&mode="+mode;
	}
	goAjax(url);
}
function SUBMITT3a(city) // используется в регистрации
{
	url="/misc/edit_change_s.php?cat_id="+city+"&mode=3";
	goAjax(url);
}
function Search(mode)
{
	switch(mode)
	{
		case 1:
			document.Form.submit();
		break;
	}
}
function GoToPage(type, id)
{
	location.href="/"+type+"/"+id+"/";
}
function GoGoro()
{
	if (document.getElementById("he_goro").value && document.getElementById("she_goro").value) document.Goro.submit();
}
function Forum(mode, id)
{
	flag=false;
	if (mode=="delete" && confirm("Хотите удалить сообщение?")) flag=true;
	if (mode=="edit") flag=true;
	if (mode=="newtopic") // создание тем на форуме
	{
		flag=1;
		if (re.test(document.Forum.title.value))
		{
			alert("Введите тему форума");
			title.focus();
			flag=0;
			return;
		}
		if (re.test(document.Forum.message.value)) // Сообщение
		{
			alert("Введите сообщение");
			message.focus();
			flag=0;
			return;
		}
	}
	if (mode=="send_message")
	{
		flag=1;
		if (re.test(document.Forum.title.value))
		{
			alert("Введите тему письма");
			title.focus();
			flag=0;
			return;
		}
		if (re.test(document.Forum.message.value)) // Сообщение
		{
			alert("Введите сообщение");
			message.focus();
			flag=0;
			return;
		}
	}
	
	if (flag)
	{
		document.Forum.mode.value=mode;
		document.Forum.id.value=id;
		document.Forum.submit();
	}
}
function CalendarDate(day, month, year)
{
	
	document.getElementById("wintxt").innerHTML="Информация загружается";
	Hidden("window_content", "inline");
	url="/misc/calendar.php?day="+day+"&month="+month+"&year="+year;
	goAjax(url);
}

function Wedding(num)
{
	Hidden("lovestory", "none"); Hidden("story_wedding", "none"); Hidden("story_journey", "none"); Hidden("budget_wedding", "none");
	switch(num)
	{
		case 1: Hidden("lovestory", "inline"); break;
		case 2: Hidden("story_wedding", "inline"); break;
		case 3: Hidden("story_journey", "inline"); break;
		case 4: Hidden("budget_wedding", "inline"); break;
	}
	location.href="#buts1";
}

function Wedding2(num, login)
{
	location.href="/wedding/"+login+"&buts="+num;
}
////// Опросы //////
var check;
var q_id;
function Opros(curr_question_id, question_id)
{
	url="/misc/opros.php?curr_question_id="+curr_question_id+"&question_id="+question_id+"&check="+check;
	check=0;
//	alert(url);
	goAjax(url);
}

function OprosCheckSet(id)
{
	check=id;
}

function CloseOpros(opros_id)
{
	Hidden("OprosMain", "none");
	url="/misc/opros_done.php?opros_id="+opros_id;
	goAjax(url);
}
////////////////////

//#############################################################
//##########          Бюджетный калькулятор          ##########
//#############################################################
var FlagCalc=0;
function AddToCalculator(cat_id)
{
	url="/misc/addcalc.php?cat_id="+cat_id+"&flag_calc="+FlagCalc;
	FlagCalc++;
	goAjax(url);
}
function Calculate(num)
{
	window.open("", "calcs"+num, "width=450, height=630, top=100, left=200, location=no, titlebar=no, toolbar=no, status=no, scrollbars=no, menubar=yes, directories=no");
	//document.Calculator.submit();
}
//#############################################################
//#############################################################

function AddToFavorites(id, mode)
{
	if (mode=="delete" || mode=="deletepresent") Hidden("t_fav_"+id, "none");
	url="/misc/addtofavorites.php?id="+id+"&modes="+mode;
	goAjax(url);
}
function ChangeCity()
{
	city=document.getElementById("gen_city").options[document.getElementById("gen_city").selectedIndex].value;
	if (city>0)
	{
		url="/misc/changecity.php?city="+city;
		goAjax(url);
		pr_city=setTimeout("RefreshForCity()", 100);
	}
}
function RefreshForCity()
{
//	location.href=document.getElementById("url_city").value;
	clearTimeout(pr_city);
	document.Cities.submit();
}
function SetStart(id, mode)
{
	if (mode==1) Hidden("err_lamp", "none");
	else Hidden("err_lamp", "inline");
	url="/misc/setstart.php?id="+id+"&mode="+mode;
	goAjax(url);
}
function Sign(forum_id)
{
	url="/misc/sign_forum.php?forum_id="+forum_id;
	goAjax(url);
}
function SendInvitings()
{
	if (document.Data.email.value=="")
	{
		alert("Необходимо ввести электронные адреса");
		return;
	}
	else document.Data.submit();
}
function ShowForm()
{
	Hidden("form_guests", "inline");
	Hidden("form_guests_link", "none");
}
function GuestEnter()
{
	if (document.FormGuest.password.value=="")
	{
		alert("Введите пароль");
		return;
	}
	else document.FormGuest.submit();
}
function Guest(cat_id, pass, mode)
{
	if (mode==1)
	{
		checked=document.getElementById("r"+cat_id).checked;
		if (checked) document.getElementById("txt"+cat_id).innerHTML="Подарок забронирован <strong>Вами</strong>";
		else document.getElementById("txt"+cat_id).innerHTML="";
	}
	else if (mode==2)
	{
		checked=document.getElementById("ro2"+cat_id).checked;
		if (checked) document.getElementById("txt2"+cat_id).innerHTML="Подарок забронирован <strong>Вами</strong>";
		else document.getElementById("txt2"+cat_id).innerHTML="";
	}
	url="/misc/guest.php?cat_id="+cat_id+"&pass="+pass+"&checked="+checked+"&mode="+mode;
	goAjax(url);
}