var checkedChannels=0;

function $(id){
	return document.getElementById(id);	
}

function gotoProjectArchive(){
	url=document.getElementById('arch-year').value;
	document.location="http://ont.by/projects/data/"+url+"/";
}
function gotoProjectArchive2(){
	url=$('arch-path').value+$('arch-year').value+"/";
	document.location=url;
}

function gotoArchive(){
	if ($('arch-day').value=='' || $('arch-month').value=='' || $('arch-year').value==''){
		alert('Заполните все поля даты!');
		return false;
	}
	url=$('arch-path').value+$('arch-year').value+"-"+$('arch-month').value+"-"+$('arch-day').value+"-"+"arc"+"/";
	document.location=url;
}

function openVideo(o){
	openPopup ('/plugins/popups/video.php?title='+o.title+'&path='+o.href, 'video', o.title, 400, 430);
	return false;
}

function openAudio(o){
	openPopup ('/plugins/popups/audio.php?title='+o.title+'&path='+o.href, 'video', o.title, 400, 180);
	return false;
}


/* *************************************************************************
*
*  function openPopup (_url, _name, _title, _width, _height, _posX, _posY)
*
************************************************************************* */

function openPopup (_url, _name, _title, _width, _height, _posX, _posY)
{
	var strParams = 0,
		idWindow = null;

	_posX = Math.round ((window.screen.availWidth / 2) - (_width / 2));

	if (window.screen.availHeight - 24 < _height)
	{
		_posY = 0;
		_width += 17;
		_height = window.screen.availHeight - 24;
	}
	else
	{
		_posY = Math.round ((window.screen.availHeight / 2) - (_height / 2 + 12));
	}

	strParams = "scrollbars=yes,status=yes,resizable=1,width=" + _width + ",height=" + _height + ",left=" + _posX + ",top=" + _posY;

	idWindow = window.open (_url, _name, strParams);

	return idWindow;
}

function checkShortSubscribeForm(){
	if($("userEmail").value==''){
		$("subscribeErrorArea").innerHTML='Введен некорректный e-mail';
		return false;		
	}
	reEmail  = /^([\w\.\-])+\@(([\w\-])+\.)+([a-zA-Z0-9]{2,4})+$/i;	 
	if(!reEmail.test($("userEmail").value) && $("userEmail").value!=''){
		$("subscribeErrorArea").innerHTML='Введен некорректный e-mail';
		return false;
	}
	return true;
}

function checkFullSubscribeForm(){	
	if($("userEmail").value==''){
		$("subscribeErrorArea").innerHTML='Введен некорректный e-mail';
		return false;		
	}
	reEmail  = /^([\w\.\-])+\@(([\w\-])+\.)+([a-zA-Z0-9]{2,4})+$/i;	 
	if(!reEmail.test($("userEmail").value) && $("userEmail").value!=''){
		$("subscribeErrorArea").innerHTML='Введен некорректный e-mail';
		return false;
	}
	if(!checkedChannels){
		$("subscribeErrorArea").innerHTML='Не выбраны каналы для подписки';
		return false;		
	}
	return true;	
}


function showHighLight(id){
	$(id).className="highlight";
}

function hideHighLight(id){
	if ($(id).value!='') $(id).className="";
}

function checkQuestion(){
	var mandatoryFields = new Array('name','email','message');
	var error=0,i;
	var msg="";
	for (i=0;i<mandatoryFields.length;i++)
	{
		if(document.questionform[mandatoryFields[i]] && document.questionform[mandatoryFields[i]].name && !document.questionform.elements[mandatoryFields[i]].value)
		{
			error=1;
			showHighLight(document.questionform[mandatoryFields[i]].id);
			msg="Необходимо заполнить, отмеченные поля.";
		}
	}
	
	if(!error && !document.questionform.email.value.match(/^[a-zA-Z\d][a-zA-Z_\.\-\d]*@[a-zA-Z_\.\-\d]+\.[a-zA-Z]{2,4}$/))
	{
		error=1;
		showHighLight(document.questionform.email.id);
		msg="Неправильный формат E-mail.";
	}

	if(error==1)
	{
		$("formErrorArea").innerHTML=msg;
		$("formErrorArea").style.display="block";
		return false;
	}
	else
	{
		return true;
	}
}

function checkHot(){
	var mandatoryFields = new Array('name','city','tel','message');
	var error=0,i;
	var msg="";
	for (i=0;i<mandatoryFields.length;i++)
	{
		if(document.questionform[mandatoryFields[i]] && document.questionform[mandatoryFields[i]].name && !document.questionform.elements[mandatoryFields[i]].value)
		{
			error=1;
			showHighLight(document.questionform[mandatoryFields[i]].id);
			msg="Необходимо заполнить, отмеченные поля.";
		}
	}
	
	if(!error && document.questionform.email.value!='' && !document.questionform.email.value.match(/^[a-zA-Z\d][a-zA-Z_\.\-\d]*@[a-zA-Z_\.\-\d]+\.[a-zA-Z]{2,4}$/))
	{
		error=1;
		showHighLight(document.questionform.email.id);
		msg="Неправильный формат E-mail.";
	}

	if(error==1)
	{
		$("formErrorArea").innerHTML=msg;
		$("formErrorArea").style.display="block";
		return false;
	}
	else
	{
		return true;
	}
}
