dom = (document.getElementById) ? true : false;
nn4 = (document.layers) ? true : false;
ie = (document.all) ? true : false;
ie4 = ie && !dom;

//==============================================================================
function openwindow(url, name, width, height)
{
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    var windowProperties = "width="+width+",height="+height+",left="+left+",top="+top;
	win = window.open(url, name, windowProperties +",resizable=no,toolbar=0,location=0,status=yes,menubar=0,directories=0,scrollbars=yes");
	win.focus();
}

//==============================================================================
function homepage(url)
{
	if (typeof window.external != "object") 
		{ alert("Your browser is not supported this function!"); return false; }
	document.body.style.behavior="url(#default#homepage)";
	document.body.setHomePage(url);
	return true;
}

//==============================================================================
function addBookmark(url, title)
{
	if (!url) url = location.href;
	if (!title) title = document.title;
 
	//Gecko
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
		{ window.sidebar.addPanel (title, url, ""); }
	//IE4+
	else if (typeof window.external == "object") { window.external.AddFavorite(url, title); }
	//Opera7+
	else if (window.opera && document.createElement)
	{
		var a = document.createElement('A');
		if (!a) return false; //IF Opera 6
		a.setAttribute('rel','sidebar');
		a.setAttribute('href',url);
		a.setAttribute('title',title);
		a.click();
	}
	else { alert("Your browser is not supported this function!"); }
	
	return true;
}

//==============================================================================
function defPosition(event)
{
    if (document.attachEvent!=null)
	{
        this.x = window.event.clientX + d.documentElement.scrollLeft + d.body.scrollLeft;
        this.y = window.event.clientY + d.documentElement.scrollTop + d.body.scrollTop;
    }
    if (!document.attachEvent && document.addEventListener)
	{
        this.x = event.clientX + window.scrollX;
        this.y = event.clientY + window.scrollY;
    }
    return {x:this.x, y:this.y};
}

//==============================================================================
function checkemail(str)
{
	if (str == "") return false;
	var reg = new RegExp("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\\.)+[a-z]{2,4}$");
	if (reg.exec(str)) { return 1; } else { return 0; }
}

//==============================================================================
function checkform(formname)
{
	var msg; var ok = 1;
	var obj = document.forms[formname].elements;	
	
	if (obj.fio.value.length == "") { ok = 0; msg = "Укажите Вашу фамилию, имя"; }
	if (ok == 1 && checkemail(obj.mail.value) == 0) { ok = 0; msg = "Email некорректный! Укажите Ваш Email для связи с вами"; }	
	if (ok == 1 && obj.msg.value.length < 3) { ok = 0; msg = "Укажите Ваш вопрос"; }	
	if (ok == 1 && obj.country.value.length < 3) { ok = 0; msg = "Укажите Вашу страну"; }	
	if (ok == 1 && obj.town.value.length < 3) { ok = 0; msg = "Укажите Ваш город"; }		
	if (ok == 1) { document.forms[formname].submit(); } else { alert(msg); }
}

//==============================================================================
function checkform1(formname)
{
	var msg; var ok = 1;
	var obj = document.forms[formname].elements;	
	
	for (i = 0; i < obj.length; i++) 
	{		
		if (obj[i].getAttribute("important") == null) continue;		
		if (ok == 1 && (obj[i].value == "" || obj[i].value == "Выбор из списка")) { ok = 0; msg = "Заполните поле!"; form = obj[i]; }	
	}
	if (ok == 1 && checkemail(obj.email.value) == 0) { ok = 0; msg = "Email некорректный! Укажите Ваш Email для связи с вами"; }	
	if (ok == 1) { document.forms[formname].submit(); } else { alert(msg); form.focus(); }
}

//==============================================================================
function show_block(objname)
{
	var obj = document.getElementById(objname)
	if (obj.style.display == "none") { obj.style.display = "block";} else { obj.style.display = "none";}
}