function getE(name)
{
	return document.getElementById(name);
}
function pprint()
{
	window.print();
	return false;
}
function sb1(id1,id2)
{
	getE(id1).style.background = '#F1F4FD';
	getE(id2).style.background = '#F1F4FD';
}
function sb2(id1,id2)
{
	getE(id1).style.background = '#E2E7FA';
	getE(id2).style.background = '#ccdef2';
}
function documentwrite(text){
	document.write(text);
}
function mover(index,top)
{
	document.getElementById("menu"+index).style.backgroundImage = "url(/images/menu_button_over.jpg)";
	element = document.getElementById("submenu"+index);
	if ( element != null )
		element.style.display = "block";
}

function mout(index)
{
	document.getElementById("menu"+index).style.backgroundImage = "url(/images/menu_button_out.jpg)";
	element = document.getElementById("submenu"+index);
	if ( element != null )
		element.style.display = "none";
}
function mover1(element)
{
	element.style.background = "#6F84BD";
}

function mout1(element)
{
	element.style.background = "#5264AE";
	window.status = "";
}
function go2page(link)
{
	document.location = link;
}

function fshow1(index, max){
	for ( i = 1  ;  i <= max  ;  i++ ){
		el = document.getElementById("subpart"+i);
		el1 = document.getElementById("subimg"+i);
		if (el != null)
			el.style.display = "none";
		if (el1 != null)
			el1.src = "/images/table1_header2.gif";
	}
	el = document.getElementById("subpart"+index);
	el1 = document.getElementById("subimg"+index);
	if (el != null)
		el.style.display = "block";
	if (el1 != null)
		el1.src = "/images/table1_header1.gif";
}
function gallery1(path,a,image)
{
	el = document.getElementById("pict_gallery");
	if (el != null){
		el.src = path;
	} else {
		path = "/lineup/matiz:"+a+"/gallery:"+image;
		document.location = path;
	}
}
function gallery2(path,a,image)
{
	el = document.getElementById("pict_gallery");
	if (el != null){
		el.src = path;
	} else {
		path = "/lineup/nexia:"+a+"/gallery:"+image;
		document.location = path;
	}
}
function color1(path)
{
	el = document.getElementById("pict_colors");
	if (el != null){
		el.src = path;
	}
}
function vote(f)
{
	id = f.id.value;
	answer = f.rsel.value;
	if (answer >= 0 ){
		JsHttpRequest.query(
	        '/inc/ajax.php',
	        {
	        	'function' : "vote_send",
	        	'id' : id,
	        	'answer' : answer
	        },
	        function(result, errors) {
				if (result)
				{
					if (result["dont"])
						alert("Ваш голос не учитывается, так как вы уже голосовали.")
					for( a in result["stat"] ){
						el = getE( "vote_result"+a );
						if (el != null)
							getE( "vote_result"+a ).innerHTML = result["stat"][a]+"%";
					}
					getE("vote_block").style.display = "none";
					getE("vote_result_block").style.display = "block";
				}
				else
				{
					//alert("Error, can't load postits.");
				}
	        },
	        true
	    );
	}
}
function checklength(elem,min,max,name)
{
	l = elem.length;
	if ( l < min ){
		return "Поле \""+name+"\" должно быть не короче "+min+" символов.\r\n";
	}
	if ( l > max ){
		return "Поле \""+name+"\" должно быть не длинее "+max+" символов.\r\n";
	}
	return "";
}
function isValidEmail(email,name)
{
	if (!(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email))
		return "Поле "+name+" заполнено не правильно.\r\n";
	return "";
}
function guestformsubmit()
{
	errors = "";
	errors += checklength( document.getElementById("guestform").fio.value ,4 ,255, "Ф.И.О.");
	errors += checklength( document.getElementById("guestform").gorod.value ,2 ,64, "Город");
	errors += isValidEmail( document.getElementById("guestform").email.value, "E-mail");
	errors += checklength( document.getElementById("guestform").message.value ,5 ,65535, "Сообщение");
	if (errors.length == 0) document.getElementById("guestform").submit();
	else alert(errors);
}
function guesttimer1(sec)
{
	str = "";
	if (sec == 0) str = sec + " секунд";
	if (sec == 1) str = sec + " секунду";
	if (sec >= 2) str = sec + " секунды";
	if (sec >= 5) str = sec + " секунд";
	
	document.getElementById("guesttimer").innerHTML = str;
	sec--;
	if (sec > 0)
		setTimeout("guesttimer1("+sec+");",1000);
	else 
		setTimeout("document.location = \"/guest\"", 1000);
}
