//-----------------------------------------------------------------------------
// BROWSER DETECTION
//-----------------------------------------------------------------------------

var type = "IE";	//Variable used to hold the browser name

function BrowserSniffer()	//detects the capabilities of the browser
{

	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";		//Opera

	else if (document.all) type="IE";														//Internet Explorer e.g. IE4 upwards

	else if (document.layers) type="NN";													//Netscape Communicator 4

	else if (!document.all && document.getElementById) type="MO";							//Mozila e.g. Netscape 6 upwards

	else type = "IE";		//I assume it will not get here

}

//BrowserSniffer();


//-----------------------------------------------------------------------------
// 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 < 15)
		{
			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 ("Введите правильно CCV2 номер.\n\nVisa, Mastercard и Discover имеют этот номер на обратной стороне кредитной карты.\nAmerican Express - на лицевой") ;
			else
				alert ("Enter correctly your 3-digit CVV2 code.\n\nOn Visa, MasterCard and Discover credit cards, the number is located on the back of the card in the signature area.\nOn American Express cards, the number is located on the front of the card, just above the card number, usually on the right") ;
			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(e, id, horiz_position)
{

// evnt.clientX - returns the horizontal coordinate (according to the client area) of the mouse pointer when an event was triggered
// evnt.clientY - returns the vertical coordinate (according to the client area) of the mouse pointer when an event was triggered
// scrollHeight - the distance between the top and bottom edges of the object's content

	var evnt = window.event || e;
	var tooltipOBJ = document.getElementById(id);
	var tooltipOffsetTop = tooltipOBJ.scrollHeight + 35;
	var testTop = (document.body.scrollTop + evnt.clientY) - tooltipOffsetTop;
	var testLeft = evnt.clientX - horiz_position;
	var tooltipAbsLft = (testLeft < 0) ? (testLeft + 50) : testLeft;
	var tooltipAbsTop = (testTop < document.body.scrollTop) ? document.body.scrollTop + 10 : testTop;
	tooltipOBJ.style.position = "absolute";
	tooltipOBJ.style.marginLeft = tooltipAbsLft;
	tooltipOBJ.style.marginTop = tooltipAbsTop;
	tooltipOBJ.style.visibility = "visible";
}

/*=================================================================
Function: HideTooltip
Purpose:  set visibility attribute of tooltip to hidden
Input:    none
Returns:  undefined
==================================================================*/
function HideTooltip(id)
{
	var tooltipOBJ = document.getElementById(id);
	tooltipOBJ.style.visibility = "hidden";
}

function showHide(method, section, disp_style)
{
	if ((document.all) || (window.chrome))
	{
		if (eval("document.all."+section) != null)
		{
			if (method == "open_div" )
			{
				eval( section + ".style.display = 'inline'" );
			}
			else if (method == "close_div")
			{
				eval( section + ".style.display = 'none'" );
			}
		}
	}
	else
	{
		if (disp_style == null)
			disp_style = 'inline' ;

		if (eval("'document.getElementById('+section+')'") != null)
		{
			if (method == "open_div" )
			{
				document.getElementById(section).style.display = disp_style;
			}
			else
			{
				if ((method == "close_div") & (section != null))
				{
					document.getElementById(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_div', 'll' + i + '_' + LangOff) ;
		showHide('open_div', '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.getElementById(NameEn).value = xmlhttp.responseText ;
			}
		}
		document.getElementById(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);
}

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() ;
}

function setTextContent(element, text) {
    while (element.firstChild!==null)
        element.removeChild(element.firstChild); // remove all existing content
    element.appendChild(document.createTextNode(text));
}

