//-----------------------------------------------------------------------------
// VALIDATION FUNCTIONS
//-----------------------------------------------------------------------------

function CheckIfNum(form_field)  // I was trying to achieve the same result with isNum()... But it didn't work.
{

	var isNum = true;
	var toCheck = form_field.value ;
	var msg = "Здесь должно быть цифровое значение" ;
	if (Lang == "en")
		msg = "Wrong input. A number is expected" ;

	if (!((toCheck == null) || (toCheck == "")))
	{

		for (j = 0; j < toCheck.length; j++)
		{
			if ((toCheck.substring(j,j+1) != "0") &&
			(toCheck.substring(j,j+1) != "1") &&
			(toCheck.substring(j,j+1) != "2") &&
			(toCheck.substring(j,j+1) != "3") &&
			(toCheck.substring(j,j+1) != "4") &&
			(toCheck.substring(j,j+1) != "5") &&
			(toCheck.substring(j,j+1) != "6") &&
			(toCheck.substring(j,j+1) != "7") &&
			(toCheck.substring(j,j+1) != "8") &&
			(toCheck.substring(j,j+1) != "9"))
			{
				isNum = false;
				alert(msg) ;
				form_field.select() ;
			}
		}
	}
	return isNum;
}

function validateNumber3(field)
{
	pattern = /\d{3}/;

	if (!pattern.test(field.value))
	{
		return false;
	}
	return true;
}

function validateNumber4(field)
{
	pattern = /\d{4}/;

	if (!pattern.test(field.value))
	{
		return false;
	}
	return true;
}

function ValidateTicketForm (ccForm)
{
	nameStr = "" ;
	nameStrEn = "" ;
	total = 0 ;
	first_free_field = "q1" ;

	for (i=1; i<= ccForm.elements["Rows"].value ; i++)
	{
		pName = "p" + i + "ru" ;
		pNameEn = "p" + i + "en" ;
		cName = "c" + i ;
		qName = "q" + i ;

		lPrice = ccForm.elements[cName].value ;
		if (lPrice == 0)
			continue ;
		lCount = ccForm.elements[qName].value ;
		if ((lCount == "") && (first_free_field == ""))
			first_free_field = qName;
		if (lCount > 0)
		{
			if (nameStr.length)
				nameStr += ", " ;
			if (nameStrEn.length)
				nameStrEn += ", " ;

			nameStr += lCount ;
			nameStrEn += lCount ;
			switch (lCount % 10)
			{
			case 1:
				if (lCount == 11)
					nameStr += " билетов" ;
				else
					nameStr += " билет" ;
				break ;
			case 2: case 3: case 4:
				if (lCount >= 12 && lCount <=14)
					nameStr += " билетов" ;
				else
					nameStr += " билета" ;
				break ;
			default:
				nameStr += " билетов" ;
				break ;
			}
			if (lCount == 1)
				nameStrEn += " ticket" ;
			else
				nameStrEn += " tickets" ;
			nameStr += " по $" + lPrice + " в поясе " + i ;
			nameStr += " (" + ccForm.elements[pName].value + ")" ;
			nameStrEn += " for $" + lPrice + " in the region " + i ;
			nameStrEn += " (" + ccForm.elements[pNameEn].value + ")" ;
			total += lPrice * lCount ;
		}
	}
	ccForm.item_name.value = nameStr ;
	ccForm.item_nameEn.value = nameStrEn ;

	ccForm.subtotal.value = total ;
	if (total == 0)
	{
		if (Lang == "ru")
			alert("Вы не указали количество билетов, которое Вы хотите заказать") ;
		else
			alert("You did not specify the quantity of the tickets you'd like to order") ;
		ccForm.elements[first_free_field].select();
		return false ;
	}
	if (Lang == "ru")
	{
		if (ccForm.preferenceRu.value == "pref1")
		{
			alert("\nВы должны выбрать Ваши предпочтительные места.");
			ccForm.preferenceRu.focus() ;
			return false ;
		}
		else
			ccForm.seating.value = ccForm.preferenceRu.value ;
	}
	else
	{
		if (ccForm.preferenceEn.value == "pref1")
		{
			alert("\nYou must сhoose your seating preferences.");
			ccForm.preferenceEn.focus() ;
			return false ;
		}
		else
			ccForm.seating.value = ccForm.preferenceEn.value ;
	}
	ccForm.Lang.value = Lang ;

	return true ;
}

function ValidateNameForm (ccForm)
{
	if (ccForm.sname.value == "")
	{
		if (Lang == "ru")
			alert ("Введите Ваше имя") ;
		else
			alert ("Enter your name") ;
		ccForm.elements["sname"].select() ;
		return (false) ;
	}
	if (ccForm.saddress1.value == "")
	{
		if (Lang == "ru")
			alert ("Введите Ваш правильный адрес") ;
		else
			alert ("Enter your correct address") ;
		ccForm.elements["saddress1"].select() ;
		return (false) ;
	}
	if (ccForm.scity.value == "")
	{
		if (Lang == "ru")
			alert ("Введите Ваш город") ;
		else
			alert ("Enter your city") ;
		ccForm.elements["scity"].select() ;
		return (false) ;
	}
	if (ccForm.szip.value == "" || isNaN (ccForm.szip.value) || ccForm.szip.value.length < 5)
	{
		if (Lang == "ru")
			alert ("Введите правильно Ваш почтовый индекс") ;
		else
			alert ("Enter your correct zip code") ;
		ccForm.elements["szip"].select() ;
		return (false) ;
	}
	ccForm.phone.value = "" ;
	if (!validateNumber3(ccForm.phone_code))
	{
		if (Lang == "ru")
			alert ("Введите правильно Ваш телефон") ;
		else
			alert ("Enter your correct phone number") ;
		ccForm.elements["phone_code"].select() ;
		return (false) ;
	}
	if (!validateNumber3(ccForm.phone_prefix))
	{
		if (Lang == "ru")
			alert ("Введите правильно Ваш телефон") ;
		else
			alert ("Enter your correct phone number") ;
		ccForm.elements["phone_prefix"].select() ;
		return (false) ;
	}
	if (!validateNumber4(ccForm.phone_last4))
	{
		if (Lang == "ru")
			alert ("Введите правильно Ваш телефон") ;
		else
			alert ("Enter your correct phone number") ;
		ccForm.elements["phone_last4"].select() ;
		return (false) ;
	}
	ccForm.phone.value = ccForm.phone_code.value + "-" + ccForm.phone_prefix.value + "-" + ccForm.phone_last4.value ;
	return true ;
}

function ValidateNameFormX (ccForm, save_cookie, scookie)
{
	if (ValidateNameForm (ccForm))
	{
		ccForm.fax.value = "" ;
		if (!(ccForm.fax_code.value == "") || !(ccForm.fax_prefix.value == "") || !(ccForm.fax_last4.value == ""))
		{
			if (!validateNumber3(ccForm.fax_code))
			{
				if (Lang == "ru")
					alert ("Введите правильно Ваш факс") ;
				else
					alert ("Enter your correct fax number") ;
				ccForm.elements["fax_code"].select() ;
				return (false) ;
			}
			if (!validateNumber3(ccForm.fax_prefix))
			{
				if (Lang == "ru")
					alert ("Введите правильно Ваш факс") ;
				else
					alert ("Enter your correct fax number") ;
				ccForm.elements["fax_prefix"].select() ;
				return (false) ;
			}
			if (!validateNumber4(ccForm.fax_last4))
			{
				if (Lang == "ru")
					alert ("Введите правильно Ваш факс") ;
				else
					alert ("Enter your correct fax number") ;
				ccForm.elements["fax_last4"].select() ;
				return (false) ;
			}
			ccForm.fax.value = ccForm.fax_code.value + "-" + ccForm.fax_prefix.value + "-" + ccForm.fax_last4.value ;
		}
		if (ccForm.email.value == "" || !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(ccForm.email.value)))
		{
			if (Lang == "ru")
				alert ("Введите Ваш e-mail") ;
			else
				alert ("Enter your e-mail") ;
			ccForm.elements["email"].select() ;
			return (false) ;
		}
		if (save_cookie)
		{
			setCookie ("sname", ccForm.sname.value, exp, null, null, scookie) ;
			setCookie ("saddress1", ccForm.saddress1.value, exp, null, null, scookie) ;
			setCookie ("saddress2", ccForm.saddress2.value, exp, null, null, scookie) ;
			setCookie ("scity", ccForm.scity.value, exp, null, null, scookie) ;
			setCookie ("sstate", ccForm.sstate.value, exp, null, null, scookie) ;
			setCookie ("szip", ccForm.szip.value, exp, null, null, scookie) ;
			setCookie ("phone", ccForm.phone.value, exp, null, null, scookie) ;
			setCookie ("fax", ccForm.fax.value, exp, null, null, scookie) ;
			setCookie ("email", ccForm.email.value, exp, null, null, scookie) ;
		}
		return true ;
	}
	return false ;
}

function ValidateBuyForm (ccForm, cvv)
{
	if ((eval(ccForm.buy[0]) != null && ccForm.buy[0].checked) ||
		(eval(ccForm.buy.value) != null && ccForm.buy.value == "visa"))
	{
		if (ccForm.cardnumber.value == "" || isNaN (ccForm.cardnumber.value) || ccForm.cardnumber.value.length < 16)
		{
			if (Lang == "ru")
				alert ("Введите правильно номер кредитной карты") ;
			else
				alert ("Enter correctly your credit card number") ;
			ccForm.elements["cardnumber"].select() ;
			return (false) ;
		}
		if (cvv && (ccForm.cvmvalue.value == "" || isNaN (ccForm.cvmvalue.value) || ccForm.cvmvalue.value.length <3))
		{
			if (Lang == "ru")
				alert ("Введите правильно трехзначный номер. Этот номер напечатан на обратной стороне кредитной карты") ;
			else
				alert ("Enter correctly your 3-digit CVV2 code. This code is printed on the back of your card") ;
			ccForm.elements["cvmvalue"].select() ;
			return (false) ;
		}
		if (ccForm.name.value == "")
		{
			if (Lang == "ru")
				alert ("Введите имя владельца кредитной карты") ;
			else
				alert ("Enter the cardholder's name") ;
			ccForm.elements["name"].select() ;
			return (false) ;
		}
		if (ccForm.ccaddress.value == "" ||
		parseInt(ccForm.ccaddress.value) == 0||
		isNaN(parseInt(ccForm.ccaddress.value)))
		{
			if (Lang == "ru")
				alert ("Введите Ваш правильный адрес, начиная с номера дома") ;
			else
				alert ("Enter your correct billing address, starting with the building number") ;
			ccForm.elements["ccaddress"].select() ;
			return (false) ;
		}
		ccForm.addrnum.value = parseInt(ccForm.ccaddress.value) ;
		if (ccForm.zip.value == "" || isNaN (ccForm.zip.value) || ccForm.zip.value.length < 5)
		{
			if (Lang == "ru")
				alert ("Введите правильно Ваш почтовый индекс") ;
			else
				alert ("Enter the correct billing zip code") ;
			ccForm.elements["zip"].select() ;
			return (false) ;
		}
	}
	if (!ccForm.agree.checked)
	{
		if (Lang == "ru")
			alert ("Подтвердите, что Вы согласны с условиями контракта на покупку билетов") ;
		else
			alert ("Confirm your agreement with the terms of the ticket purchase contract") ;
		ccForm.elements["agree"].select() ;
		return (false) ;
	}
	subtotal = parseInt(ccForm.subtotal.value) ;
	handling = parseInt(ccForm.handling.value) ;
	shipping = parseInt(ccForm.shipping.value) ;
	chargetotal = subtotal + handling ;
	usertotal = chargetotal + shipping ;
	ccForm.chargetotal.value = chargetotal + ".00" ;
	if (Lang == "ru")
		return confirm ("Отправить заказ на общую сумму $" + usertotal + "?") ;
	else
		return confirm ("Submit the order totalling $" + usertotal + "?") ;
}

function ValidateSubmit (ccForm, cvv)
{
	if (ValidateBuyForm (ccForm, cvv))
		ccForm.submit() ;
	return false ;
}

//-----------------------------------------------------------------------------
// SHOW/HIDE/TOOLTIP FUNCTIONS
//-----------------------------------------------------------------------------

//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
function openpopup(place,hight)
{
	var popurl="q&a.html#" + place ;
	var winsize="width=470,height=" + hight ;
	winpops=window.open(popurl,"",winsize) ;
}

/*=================================================================
Function: ShowTooltip
Purpose:  position, draw, and display tooltip element
Input:    fArg - indexes text array to display
Returns:  undefined
==================================================================*/
function ShowTooltip(id,horiz_position)
{
	var tooltipOBJ = eval("document.all[id]");
	var tooltipOffsetTop = tooltipOBJ.scrollHeight + 35;
	var testTop = (document.body.scrollTop + event.clientY) - tooltipOffsetTop;
	var testLeft = event.clientX - horiz_position;
	var tooltipAbsLft = (testLeft < 0) ? (testLeft + 50) : testLeft;
	var tooltipAbsTop = (testTop < document.body.scrollTop) ? document.body.scrollTop + 10 : testTop;
	tooltipOBJ.style.posLeft = tooltipAbsLft;
	tooltipOBJ.style.posTop = tooltipAbsTop;
	tooltipOBJ.style.visibility = "visible";
}

/*=================================================================
Function: HideTooltip
Purpose:  set visibility attribute of tooltip to hidden
Input:    none
Returns:  undefined
==================================================================*/
function HideTooltip(id)
{
	var tooltipOBJ = eval("document.all[id]");
	tooltipOBJ.style.visibility = "hidden";
}

function showHide(method,section)
{
	if (eval("document.all."+section) != null)
	{
		if (method == "open" )
		{
			eval( section + ".style.display = 'inline'" );
		}
		else if (method == "close")
		{
			eval( section + ".style.display = 'none'" );
		}
	}
}

//-----------------------------------------------------------------------------
// AUTOJUMP FUNCTIONS
//-----------------------------------------------------------------------------

var downStrokeField;

function autojump(fieldName,nextFieldName,fakeMaxLength)
{
	var myForm=document.forms[document.forms.length - 1];
	var myField=myForm.elements[fieldName];
	myField.nextField=myForm.elements[nextFieldName];
	if (myField.maxLength == null)
		myField.maxLength=fakeMaxLength;
	myField.onkeydown=autojump_keyDown;
	myField.onkeyup=autojump_keyUp;
}

function autojump_keyDown()
{
	this.beforeLength=this.value.length;
	downStrokeField=this;
}

function autojump_keyUp()
{
	if (
	(this == downStrokeField) &&
	(this.value.length > this.beforeLength) &&
	(this.value.length >= this.maxLength)
	)
		this.nextField.focus();
	downStrokeField=null;
}

//-----------------------------------------------------------------------------
// COOKIE FUNCTIONS
//-----------------------------------------------------------------------------

document.cookie = "companyname=TMCONCERT" ;
var exp = new Date() ;
FixCookieDate (exp) ;
var oneYearFromNow = exp.getTime() + (365*24*60*60*1000) ;
exp.setTime(oneYearFromNow) ;

function getCookieData (label)
{
	var labelLen = label.length ;
	var cLen = document.cookie.length
	var i = 0 ;
	var cEnd ;
	while (i < cLen)
	{
		if (document.cookie.substring  (i, k) == label)
		{
			cEnd = document.cookie.indexOf (";", j)
			if (cEnd == -1)
			{
				cEnd = document.cookie.length ;
			}
			return unescape (document.cookie.substring (j, cEnd)) ;
		}
		i++ ;
	}
	return "" ;
}

function getCookieVal (offset)
{
	var endStr = document.cookie.indexOf (";", offset) ;
	if (endStr == -1)
	{
		endStr = document.cookie.length ;
	}
	return unescape (document.cookie.substring (offset, endStr)) ;
}

// Function to correct for 2.x Mac date bug.
// Must be called only once for any given date object
function FixCookieDate (date)
{
	var base = new Date (0) ;
	var skew = base.getTime () ;
	if (skew > 0)
		date.setTime (date.getTime () - skew) ;
}

function getCookie (name)
{
	var arg = name + "=" ;
	var alen = arg.length ;
	var clen = document.cookie.length ;
	var i = 0 ;
	while (i , clen)
	{
		var j = i + alen ;
		if (document.cookie.substring (i, j) == arg)
			return getCookieVal (j) ;
		i = document.cookie.indexOf (" ", i) + 1 ;
		if (i == 0) break ;
	}
	return null ;
}

function setCookie (name, value, expires, path, domain, secure)
{
	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "") ;
}

function deleteCookie (name, path, domain)
{
	if (getCookie (name))
	{
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT" ;
	}
}

//-----------------------------------------------------------------------------
// LANGUAGE SUPPORT FUNCTIONS
//-----------------------------------------------------------------------------

function FlipLanguage ()
{
	if (Lang == "ru")
		Lang = "en" ;
	else
		Lang = "ru" ;
	setCookie ("Lang", Lang, exp, "/", null, false) ;
	SetLanguage () ;
}

function SetLanguage ()
{
	if (Lang == "ru")
		LangOff = "en" ;
	else
		LangOff = "ru" ;
	for (i=1; i<=DivCount; i++)
	{
		showHide('close', 'll' + i + '_' + LangOff) ;
		showHide('open', 'll' + i + '_' + Lang) ;
	}
}

function translate (str)
{
	var xmlhttp ;
	try
	{
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP") ;
	}
	catch (e)
	{
		try
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") ;
		}
		catch (E)
		{
			xmlhttp=false ;
		}
	}

	if (xmlhttp)
	{
		data2send = "" ;
		for (i=0; i<str.length; i++)
			data2send += "@" + str.charCodeAt(i)
		data2send = "xlate=" + data2send ;
		xmlhttp.open("GET", "scripts.php?"+data2send, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.all.NameEn.value = xmlhttp.responseText ;
			}
		}
		document.all.NameEn.value = "TRANSLATING..." ;
		xmlhttp.send(null)
	}
	else
	{
		alert ("Unable to create the translation object") ;
	}
	return false ;
}

function transliterate (str)
{
	var newstr = "" ;
	for (i=0; i<str.length; i++)
	{
		newstr += letter (str.substring(i,i+1));
	}
	return (newstr);
}

function letter (ch)
{
	var newch;
	switch (ch)
	{
	case "А": newch = ("A"); break ;
	case "а": newch = ("a"); break ;
	case "Б": newch = ("B"); break ;
	case "б": newch = ("b"); break ;
	case "В": newch = ("V"); break ;
	case "в": newch = ("v"); break ;
	case "Г": newch = ("G"); break ;
	case "г": newch = ("g"); break ;
	case "Д": newch = ("D"); break ;
	case "д": newch = ("d"); break ;
	case "Е": newch = ("E"); break ;
	case "е": newch = ("e"); break ;
	case "Ё": newch = ("YO"); break ;
	case "ё": newch = ("yo"); break ;
	case "Ж": newch = ("ZH"); break ;
	case "ж": newch = ("zh"); break ;
	case "З": newch = ("Z"); break ;
	case "з": newch = ("z"); break ;
	case "И": newch = ("I"); break ;
	case "и": newch = ("i"); break ;
	case "Й": newch = ("Y"); break ;
	case "й": newch = ("y"); break ;
	case "К": newch = ("K"); break ;
	case "к": newch = ("k"); break ;
	case "Л": newch = ("L"); break ;
	case "л": newch = ("l"); break ;
	case "М": newch = ("M"); break ;
	case "м": newch = ("m"); break ;
	case "Н": newch = ("N"); break ;
	case "н": newch = ("n"); break ;
	case "О": newch = ("O"); break ;
	case "о": newch = ("o"); break ;
	case "П": newch = ("P"); break ;
	case "п": newch = ("p"); break ;
	case "Р": newch = ("R"); break ;
	case "р": newch = ("r"); break ;
	case "С": newch = ("S"); break ;
	case "с": newch = ("s"); break ;
	case "Т": newch = ("T"); break ;
	case "т": newch = ("t"); break ;
	case "У": newch = ("U"); break ;
	case "у": newch = ("u"); break ;
	case "Ф": newch = ("F"); break ;
	case "ф": newch = ("f"); break ;
	case "Х": newch = ("KH"); break ;
	case "х": newch = ("kh"); break ;
	case "Ц": newch = ("TS"); break ;
	case "ц": newch = ("ts"); break ;
	case "Ч": newch = ("CH"); break ;
	case "ч": newch = ("ch"); break ;
	case "Ш": newch = ("SH"); break ;
	case "ш": newch = ("sh"); break ;
	case "Щ": newch = ("SCH"); break ;
	case "щ": newch = ("sch"); break ;
	case "Ъ":
	case "ъ":
	case "Ь":
	case "ь": newch = ("`"); break ;
	case "Ы": newch = ("Y"); break ;
	case "ы": newch = ("y"); break ;
	case "Э": newch = ("E"); break ;
	case "э": newch = ("e"); break ;
	case "Ю": newch = ("YU"); break ;
	case "ю": newch = ("yu"); break ;
	case "Я": newch = ("YA"); break ;
	case "я": newch = ("ya"); break ;
	default: newch = ch; break ;
	}
	return(newch);
}

//-----------------------------------------------------------------------------
// DYNAMIC ANIMATION FUNCTIONS
//-----------------------------------------------------------------------------
dynamicanimAttr = "dynamicanimation" ;
animateElements = new Array() ;
currentElement = 0 ;
speed = 50 ;
stepsZoom = 8 ;
stepsWord = 8 ;
stepsFly = 12 ;
stepsSpiral = 16 ;
steps = stepsZoom ;
step = 0 ;
outString = "" ;

function dynAnimation()
{
	var ms = navigator.appVersion.indexOf("MSIE") ;
	ie4 = (ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+6)) >= 4) ;
	if(!ie4)
	{
		if((navigator.appName == "Netscape") &&
		(parseInt(navigator.appVersion.substring(0, 1)) >= 4))
		{
			for (index=document.layers.length-1; index >= 0; index--)
			{
				layer=document.layers[index] ;
				if (layer.left==10000)
					layer.left=0 ;
			}
		}
		return ;
	}
	for (index=document.all.length-1; index >= document.body.sourceIndex; index--)
	{
		el = document.all[index] ;
		animation = el.getAttribute(dynamicanimAttr, false) ;
		if(null != animation)
		{
			if(animation == "dropWord" || animation == "flyTopRightWord" || animation == "flyBottomRightWord")
			{
				ih = el.innerHTML ;
				outString = "" ;
				i1 = 0 ;
				iend = ih.length ;
				while(true)
				{
					i2 = startWord(ih, i1) ;
					if(i2 == -1)
						i2 = iend ;
					outWord(ih, i1, i2, false, "") ;
					if(i2 == iend)
						break ;
					i1 = i2 ;
					i2 = endWord(ih, i1) ;
					if(i2 == -1)
						i2 = iend ;
					outWord(ih, i1, i2, true, animation) ;
					if(i2 == iend)
						break ;
					i1 = i2 ;
				}
				document.all[index].innerHTML = outString ;
				document.all[index].style.posLeft = 0 ;
				document.all[index].setAttribute(dynamicanimAttr, null) ;
			}
			if(animation == "zoomIn" || animation == "zoomOut")
			{
				ih = el.innerHTML ;
				outString = "<SPAN " + dynamicanimAttr + "=\"" + animation + "\" style=\"position: relative; left: 10000;\">" ;
				outString += ih ;
				outString += "</SPAN>" ;
				document.all[index].innerHTML = outString ;
				document.all[index].style.posLeft = 0 ;
				document.all[index].setAttribute(dynamicanimAttr, null) ;
			}
		}
	}
	i = 0 ;
	for (index=document.body.sourceIndex; index < document.all.length; index++)
	{
		el = document.all[index] ;
		animation = el.getAttribute(dynamicanimAttr, false) ;
		if (null != animation)
		{
			if(animation == "flyLeft")
			{
				el.style.posLeft = 10000-offsetLeft(el)-el.offsetWidth ;
				el.style.posTop = 0 ;
			}
			else if(animation == "flyRight")
			{
				el.style.posLeft = 10000-offsetLeft(el)+document.body.offsetWidth ;
				el.style.posTop = 0 ;
			}
			else if(animation == "flyTop" || animation == "dropWord")
			{
				el.style.posLeft = 0 ;
				el.style.posTop = document.body.scrollTop-offsetTop(el)-el.offsetHeight ;
			}
			else if(animation == "flyBottom")
			{
				el.style.posLeft = 0 ;
				el.style.posTop = document.body.scrollTop-offsetTop(el)+document.body.offsetHeight ;
			}
			else if(animation == "flyTopLeft")
			{
				el.style.posLeft = 10000-offsetLeft(el)-el.offsetWidth ;
				el.style.posTop = document.body.scrollTop-offsetTop(el)-el.offsetHeight ;
			}
			else if(animation == "flyTopRight" || animation == "flyTopRightWord")
			{
				el.style.posLeft = 10000-offsetLeft(el)+document.body.offsetWidth ;
				el.style.posTop = document.body.scrollTop-offsetTop(el)-el.offsetHeight ;
			}
			else if(animation == "flyBottomLeft")
			{
				el.style.posLeft = 10000-offsetLeft(el)-el.offsetWidth ;
				el.style.posTop = document.body.scrollTop-offsetTop(el)+document.body.offsetHeight ;
			}
			else if(animation == "flyBottomRight" || animation == "flyBottomRightWord")
			{
				el.style.posLeft = 10000-offsetLeft(el)+document.body.offsetWidth ;
				el.style.posTop = document.body.scrollTop-offsetTop(el)+document.body.offsetHeight ;
			}
			else if(animation == "spiral")
			{
				el.style.posLeft = 10000-offsetLeft(el)-el.offsetWidth ;
				el.style.posTop = document.body.scrollTop-offsetTop(el)-el.offsetHeight ;
			}
			else if(animation == "zoomIn")
			{
				el.style.posLeft = 10000 ;
				el.style.posTop = 0 ;
			}
			else if(animation == "zoomOut")
			{
				el.style.posLeft = 10000 ;
				el.style.posTop = 0 ;
			}
			else
			{
				el.style.posLeft = 10000-offsetLeft(el)-el.offsetWidth ;
				el.style.posTop = 0 ;
			}
			el.initLeft = el.style.posLeft ;
			el.initTop = el.style.posTop ;
			animateElements[i++] = el ;
		}
	}
	window.setTimeout("animate();", speed) ;
}

function offsetLeft(el)
{
	x = el.offsetLeft ;
	for (e = el.offsetParent; e; e = e.offsetParent)
		x += e.offsetLeft ;
	return x ;
}

function offsetTop(el)
{
	y = el.offsetTop ;
	for (e = el.offsetParent; e; e = e.offsetParent)
		y += e.offsetTop ;
	return y ;
}

function startWord(ih, i)
{
	for(tag = false; i < ih.length; i++)
	{
		c = ih.charAt(i) ;
		if(c == '<')
			tag = true ;
		if(!tag)
			return i ;
		if(c == '>')
			tag = false ;
	}
	return -1 ;
}

function endWord(ih, i)
{
	nonSpace = false ;
	space = false ;
	while(i < ih.length)
	{
		c = ih.charAt(i) ;
		if (c != ' ')
			nonSpace = true ;
		if (nonSpace && c == ' ')
			space = true ;
		if (c == '<')
			return i ;
		if (space && c != ' ')
			return i ;
		i++ ;
	}
	return -1 ;
  }

function outWord(ih, i1, i2, dyn, anim)
{
	if(dyn)
		outString += "<SPAN " + dynamicanimAttr + "=\"" + anim + "\" style=\"position: relative; left: 10000;\">" ;
	outString += ih.substring(i1, i2) ;
	if(dyn)
		outString += "</SPAN>" ;
}

function animate()
{
	el = animateElements[currentElement] ;
	animation = el.getAttribute(dynamicanimAttr, false) ;
	step++ ;
	if(animation == "spiral")
	{
		steps = stepsSpiral ;
		v = step/steps ;
		rf = 1.0 - v ;
		t = v * 2.0*Math.PI ;
		rx = Math.max(Math.abs(el.initLeft), 200) ;
		ry = Math.max(Math.abs(el.initTop),  200) ;
		el.style.posLeft = Math.ceil(-rf*Math.cos(t)*rx) ;
		el.style.posTop  = Math.ceil(-rf*Math.sin(t)*ry) ;
	}
	else if(animation == "zoomIn")
	{
		steps = stepsZoom ;
		el.style.fontSize = Math.ceil(50+50*step/steps) + "%" ;
		el.style.posLeft = 0 ;
	}
	else if(animation == "zoomOut")
	{
		steps = stepsZoom ;
		el.style.fontSize = Math.ceil(100+200*(steps-step)/steps) + "%" ;
		el.style.posLeft = 0 ;
	}
	else
	{
		steps = stepsFly ;
		if(animation == "dropWord" || animation == "flyTopRightWord" || animation == "flyBottomRightWord")
			steps = stepsWord ;
		dl = el.initLeft / steps ;
		dt = el.initTop  / steps ;
		el.style.posLeft = el.style.posLeft - dl ;
		el.style.posTop = el.style.posTop - dt ;
	}
	if (step >= steps)
	{
		el.style.posLeft = 0 ;
		el.style.posTop = 0 ;
		currentElement++ ;
		step = 0 ;
	}
	if(currentElement < animateElements.length)
		window.setTimeout("animate();", speed) ;
}

function popUp_Map (url)
{
	just_a_date = new Date() ;
	unique_num = just_a_date.getTime() ;

	windowNew = 'W' + unique_num ;  // Unique window name
	
// Detect a client screen resolution and format our new window depending on it
	if (screen.width > 800)
	{
		width = '800' ;
		height = '600' ;
	}
	else
	{
		width = '700' ;
		height = '500' ;
	}

// In the 3rd parameter no space allowed!
	newWindow=window.open (
url,
'windowNew',
'width=' + width + ',height=' + height + ',status=no,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,screenX=50,screenY=10,left=50,top=10'
);

newWindow.focus();
}


//-----------------------------------------------------------------------------
// MISCELLANEOUS FUNCTIONS
//-----------------------------------------------------------------------------

function TimeoutJmp(page)
{
	if (Lang == "ru")
		alert ("Вы ждали слишком долго, пожалуйста сделайте заказ сначала") ;
	else
		alert ("You waited too long, please restart your order") ;
	location.assign (BaseDir + '/' + page) ;
}

function ChangeCheckBoxColor (CheckBox, defstate)
{
	if ((CheckBox.checked && defstate == 0) ||
		(!CheckBox.checked && defstate == 1))
		CheckBox.style.backgroundColor='red' ;
	else
		CheckBox.style.backgroundColor='#ffffcc' ;
}

function Jump_to_Rows ()
{
	document.forms["addform"].elements["p1"].focus() ;
	if (document.forms["addform"].elements["p1"].value == "Анонс")
		document.forms["addform"].elements["p1"].select() ;
}
