var timer;
function check_email_timeout(email)
{
	clearTimeout(timer);
	timer = setTimeout("$('div#email_check').load('/ajax.php?act=email_check&email="+email+"');",1000);
}

function expand(submenu_id, menu_obj) {
	d = document.getElementById('submenu' + submenu_id);
	if (d.style.display == 'block') {
		d.style.display = 'none';
		menu_obj.className = menu_obj.className.substring(0, menu_obj.className.length - ' active-submenu'.length);
		inner = d.getElementsByTagName('div');
		for (i=0; i<inner.length; i++) {
			if (inner[i].id.indexOf('submenu') == 0) inner[i].style.display = 'none';
			if (inner[i].className.indexOf(' active-submenu') != -1) inner[i].className = inner[i].className.substring(0, inner[i].className.length - ' active-submenu'.length)
		}
	}
	else {
		d.style.display = 'block';
		menu_obj.className += ' active-submenu'
	}
}

function show_pic(img_src, icon_obj, img_width, img_height) {
	clearTimeout(t)
	d = document.getElementById('show-pic');
	if (!d) {
		try {
			// ie
			d = document.createElement('<div id="show-pic" onmouseover="keep_pic()" onmouseout="hide_pic()" />');
		}
		catch (e) {
			//firefox & others
			d = document.createElement("div");
			d.setAttribute("id", "show-pic");
			d.onmouseover = keep_pic;
			d.onmouseout = hide_pic;
		}
		document.getElementsByTagName('body')[0].appendChild(d);
	}
	d.style.display = 'none';
	d.innerHTML = '<img src="' + img_src + '">';
	d.style.left = absPosition(icon_obj).x + 19 + 'px';
	d.style.width = img_width + "px";
	d.style.height = img_height + "px";
	y = absPosition(icon_obj).y;
	d.style.top = absPosition(icon_obj).y + 'px';
	d.style.display = 'block';

	safariScrollTop = window.pageYOffset;
	if (y+d.clientHeight-(safariScrollTop?safariScrollTop:document.documentElement.scrollTop) > document.documentElement.clientHeight)
		d.style.top = (safariScrollTop?safariScrollTop:document.documentElement.scrollTop) + document.documentElement.clientHeight - d.clientHeight - 2 + 'px';
}

var t;
function keep_pic() {
	clearTimeout(t)
}

function hide_pic() {
	t = setTimeout("document.getElementById('show-pic').style.display = 'none'", 200)
}

function absPosition(obj) {
	  var x = y = 0;
	  while(obj) {
			x += obj.offsetLeft;
			y += obj.offsetTop;
			obj = obj.offsetParent;
	  }
	  return {x:x, y:y};
}

function email_address(par_1,par_2,par_3)
{
	email = par_1 + "%40" + par_2 + "." + par_3;
	return email;
}

function email_href(par_1,par_2,par_3)
{
	email = 'm'+'a'+'i'+'l'+'t'+'o'+':' + email_address(par_1,par_2,par_3);
	window.location.href = email;
}

function openWIN(URL,WNAME,w,h,scr)
{
	sw = screen.width-100;
	sh = screen.availHeight-100;
	mtw = (screen.width-w)/2;
	mth = (screen.availHeight-h)/2;
	popup = window.open(URL,WNAME,"width="+w+",height="+h+",top="+mth+",left="+mtw+",status=no,toolbar=no,scrollbars="+scr+",resizable=no,menubar=no");
	popup.focus();
}

var popup;
function openIMG(URL,WNAME,w,h)
{
	if (popup != null && !popup.closed) popup.close();  
	sw = screen.width-100;
	sh = screen.availHeight-100;
	if (w > sw || h > sh)
	{
		if (w > sw) {w1 = sw;} else {w1 = w+17;}
		if (h > sh) {h1 = sh;} else {h1 = h+17;}
		mtw1 = (screen.width-w1)/2;
		mth1 = (screen.availHeight-h1)/2;
		popup = window.open('',WNAME,"width="+w1+",height="+h1+",top="+mth1+",left="+mtw1+",status=no,toolbar=no,scrollbars=yes,resizable=no,menubar=no");
		popup.focus();
	}
	else
	{
		mtw = (screen.width-w)/2;
		mth = (screen.availHeight-h)/2;
    	popup = window.open('',WNAME,"width="+w+",height="+h+",top="+mth+",left="+mtw+",status=no,toolbar=no,scrollbars=no,resizable=no,menubar=no");
		popup.focus();
	}
  	popup.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Русский Фейерверк</title></head><body style="margin: 0px;"><a href="javascript:window.close();"><img src="'+URL+'" border=0 width="'+w+'" height="'+h+'" alt="Закрыть окно"></a></body></html>');
}

function submit2popup(fn1,fn2)
{
	openWIN('',fn1,375,175);
	document.getElementById(fn2).submit();
}

function showVIDEO(URL)
{
	document.writeln('<embed src="'+URL+'" width=320 height=285 hspace=0 vspace=0 autostart=true></embed>');
}

function bla_bla (fn)
{
	document.getElementById(fn).style.display='none';
}

function Check_Length_Str(MaxLen, field, field_num)
{
	inputStr = field.value;
	strlength = 0;
	var newStr = "";
	for (var i=0; i < inputStr.length; i++)
	{
		var oneChar = inputStr.charAt(i);
		strlength++;
		if (strlength < MaxLen)
		newStr += oneChar;
 	}
 	if (strlength > MaxLen)
	{
 		field.value=newStr;
    	field_num.value = MaxLen;
 	}
	else
	{
		field_num.value = (MaxLen - strlength);
	}
}
