/*
itari javascript
2009/04/07
*/

var lng = 1;
function stopError() 
{
  return true;
}

window.onerror = stopError;

function trim(str)
{
  return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}

function formCheck(form)
{
	var checkTags = new Array('textarea','input');
	var txt = new Array();
	txt[1] = "Пожалуйста, заполните обязательное поле ";
	txt[2] = "Please, fill the required field ";
	for(i=0;i<checkTags.length;++i)
	{
		field = form.getElementsByTagName(checkTags[i]);
		if(field)
		{
			for(j=0;j<field.length;++j)
			{
				if(field[j].getAttribute("required"))
				{
					if(trim(field[j].value).length==0)
					{
						fieldName = field[j].getAttribute("description") ? '"' + field[j].getAttribute("description") + '"' : '';
						alert(txt[lng] + fieldName);
						field[j].focus();
						return false;
					}
				}
			}
		}
	}
	for(j=0; j<form.elements.length;++j)
	{
		ch = form.elements[j];
		if(ch.onsubmitfunc)
		{
			eval("res = " + ch.onsubmit + "(ch);");
			if(!res) return false;
		}
	}
	subb = form.getElementsByTagName("input");
	if(subb)
	{
		for(i=0;i<subb.length;++i)
		{
			if(subb[i].attributes)
			{
				var but;
				for(j=0;j<subb[i].attributes.length;++j)
				{
					if(subb[i].attributes[j].name == "id")
					{
						but = subb[i].attributes[j].value;
					}
					if(subb[i].attributes[j].name == "type" && subb[i].attributes[j].value == "submit")
					{
						var l = subb[i].attributes.length;
						sbut = document.getElementById(but);
						if(sbut)
						{
							sbut.disabled = true;
						}
					}
				}
			}
		}
	}
	return true;
}

function emailCheck(mailForm) 
{
	var email = mailForm.value;
	var res = true;
	if(mailForm.value)
	{
		var txt = new Array();
		txt[1] = "Пожалуйста, введите E-mail правильно!!";
		txt[2] = "Please, reenter your E-mail correctly!!";
		if (email.indexOf('@') < 1 ) res=false;
		if (email.lastIndexOf('.') < email.indexOf('@')) res=false;
		if (email.length - email.lastIndexOf('.') <= 2) res=false;
		if (email.indexOf(' ') != -1) res=false;
		if (res == false) 
		{
			alert(txt[lng]);
			mailForm.focus();
		}
	}
	return res;
}

function fCompare(id1,id2)
{
	field1 = document.getElementById(id1);
	field2 = document.getElementById(id2);
	var txt = new Array();
	txt[1] = "Значения не совпадают!!";
	txt[2] = "Different values!!";
	if(field1.value == field2.value) return true;
	else
	{
		field1.value = field2.value = "";
		alert(txt[lng]);
		field1.focus();
		return false;
	}
}

function showImage(url)
{
	var txt = new Array();
	txt[1] = "закрыть";
	txt[2] = "close";
	var shi = document.getElementById("showimg");
	if(document.body.scrollTop != 0) 
	{
		shi.style.top = document.body.scrollTop + 50;
	}
	else if(window.scrollY) 
	{
		shi.style.top = window.scrollY + 50;
	}
	shi.style.visibility = "visible";
	shi.innerHTML = "<img src='" + url + "' /><br /><a href='#' onclick='hideImage();return false;'>" + txt[lng] + "</a>";
}

function hideImage()
{
var shi = document.getElementById("showimg");
shi.style.visibility = "hidden";
}