

function em(box, server, zone)
{
	var at = String.fromCharCode(64);
	return '<a href="'+'mai'+'lto'+':'+box+at+server+'.'+zone+'">'+box+at+server+'.'+zone+'<'+'/a>';
}

document.onclick = function(e)
{
	var target, external;
	target = e ? e.target : window.event.srcElement;

	while (target && !/^(body|a)$/i.test(target.nodeName))
		target = target.parentNode;

	if (target && typeof(target.rel)!='undefined' && target.rel== 'external')
	{
		external = window.open(target.href);
		return external.closed;
	}

	return true;
}

function open_request_window(window_url, width, height)
{
	var left = Math.round((screen.width-width)/2), top = Math.round((screen.height-height)/2)-30
	var window_param =	'ontop=yes,status=yes,menubar=no,toolbar=no,directories=no,resizable=yes,scrollbars=yes,location=no,'+
						'width='+width+',height='+height+','+
						'left='+left+',top='+top;
	var window_name = 'win_'+Math.floor(Math.random()*1000);
	var win = window.open(window_url, window_name, window_param);
	win.focus();
	return false;
}

function request_submit(form)
{
	message_present = false;
	var controls = new Array("name", "company", "phone", "addr");
	reset_highlight(form, controls);
	return process_check(form, controls);
}

function request_any_submit(form)
{
	message_present = false;
	var controls = new Array("name", "phone", "addr", "equipment");
	reset_highlight(form, controls);
	return process_check(form, controls);
}

function check_name(form)
{
	return check_length(form, "name", 3, -1, "Представьтесь, пожалуйста!");
}

function check_company(form)
{
	return check_length(form, "company", 3, -1, "Не указано название Вашей организации!");
}

function check_equipment(form)
{
	return check_length(form, "equipment", 5, -1, "Укажите оборудование!");
}

function check_phone(form)
{
	return check_length(form, "phone", 5, -1, "Укажите контактный номер телефона!");
}

function check_addr(form)
{
	if (!valid_email(form.addr.value))
	{
		if (!message_present)
		{
			alert("Некорректный адрес электронной почты!");
			message_present = true;
		}
		highlight_control(form.addr, !message_present);
		return false;
	}
	return true;
}

function valid_email(addr)
{
	if (addr.length==0)
		return false;
	return addr.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
}

