function checkEmpty (val){
	if (val=="" || val.search(/[^\s]+/)==-1) {
		return false;
	}
	return true;
}

function RestoreColor()
	{
	document.MessageForm.name.style.background="#ffffff";	
	document.MessageForm.content.style.background="#ffffff";	
	document.MessageForm.contacts.style.background="#ffffff";	
	}

function SubmitMessage()
{
	sm=true;
	if (!checkEmpty(document.MessageForm.name.value)) 
		{
	document.MessageForm.name.style.background="#FFA329";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.contacts.value)) 
		{
	document.MessageForm.contacts.style.background="#FFA329";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.content.value)) 
		{
	document.MessageForm.content.style.background="#FFA329";
	sm=false;	
		}
	if (sm==true) {document.MessageForm.submit();}		
}


var CurImg = 1;
var CurPage = 1;
var CurStart = 1;
var CurPos = 1;



function ShowImg(path,num,nn)
{
	
	
	x=1; flag = true;
	
	while (flag == true)
	{
		if (document.getElementById('rm'+x))
		{
			document.getElementById('rm'+x).className = 'R100';
		} else
			{
				flag = false;
			}
		x++;
	}

	
	
	
	
	document.getElementById('foto').innerHTML = '<img src="'+path+'" width="'+fwidth[nn]+'" height="'+fheight[nn]+'">';
	document.getElementById('CurrentPhoto').value = fid[nn];
	document.getElementById('rm'+num).className = 'R100X';
	document.getElementById('phn').innerHTML = nn;	
	document.getElementById('phcom').innerHTML = fcom[nn];	
	


	CurImg = nn;
	CurPos = num;
	
	if (CurImg==(fprev.length-1)) {document.getElementById('frw').style.display = 'none';} else {document.getElementById('frw').style.display = 'block';}
	if (CurImg==1) {document.getElementById('bck').style.display = 'none';} else {document.getElementById('bck').style.display = 'block';}
	
	

}


function GR()
{

	CurPos = 1;
	CurPage = CurPage+1;
	start = (CurPage-1)*5+1;

	
		
	
	if ((start+5)>fprev.length) 
	{
		start = start - ((start+5)-fprev.length);
		document.getElementById('gor').style.display = 'none';
	}
	
	CurStart = start;
	
	x=1;
	
	zz = '';
	for (i=start; i<start+5; i++)
	{
		if (fprev[CurImg] == fprev[i]) CurPos = i-start+1;
		document.getElementById('prv'+x).innerHTML = '<img src="'+fprev[i]+'" onclick=ShowImg("'+fpath[i]+'",'+x+','+fnum[i]+')><div class="R100'+zz+'" id="rm'+x+'"></div><div class="Shadow'+zz+'" id="shad'+x+'" onclick=ShowImg("'+fpath[i]+'",'+x+','+fnum[i]+')>';
		x++;	
	}
	
	document.getElementById('rm'+CurPos).className = 'R100X';
	
	CurImg = CurStart+CurPos-1;
			
	
	document.getElementById('foto').innerHTML = '<img src="'+fpath[CurImg]+'" width="'+fwidth[CurImg]+'" height="'+fheight[CurImg]+'">';
	document.getElementById('CurrentPhoto').value = fid[CurImg];
	document.getElementById('phn').innerHTML = fnum[CurImg];	
	document.getElementById('gol').style.display = 'block';
	document.getElementById('bck').style.display = 'block';
	document.getElementById('phcom').innerHTML = fcom[CurImg];	

}


function GL()
{
	CurPos = 1;
	CurPage = CurPage-1;
	start = (CurPage-1)*5+1;
	
	CurStart = start;
	
	if (start==1) 
	{
		document.getElementById('gol').style.display = 'none';
		document.getElementById('bck').style.display = 'none';
	}

	x=1;
	for (i=start; i<start+5; i++)
	{
		if (x==1) {zz='X';} else {zz='';}
		document.getElementById('prv'+x).innerHTML = '<img src="'+fprev[i]+'" onclick=ShowImg("'+fpath[i]+'",'+x+','+fnum[i]+')><div class="R100'+zz+'" id="rm'+x+'"></div><div class="Shadow'+zz+'" id="shad'+x+'" onclick=ShowImg("'+fpath[i]+'",'+x+','+fnum[i]+')>';
		x++;	
	}


	CurImg = start;	

	document.getElementById('foto').innerHTML = '<img src="'+fpath[start]+'" width="'+fwidth[start]+'" height="'+fheight[start]+'">';
	document.getElementById('CurrentPhoto').value = fid[start];
	document.getElementById('phn').innerHTML = fnum[start];	
	document.getElementById('gor').style.display = 'block';
	document.getElementById('frw').style.display = 'block';
	document.getElementById('phcom').innerHTML = fcom[start];
}

function GLX()
{
	CurPos = 5;
	CurPage = CurPage-1;
	start = (CurPage-1)*5+1;
	
	curpos = CurImg - start;
	
	CurPos = 5 - (5 - curpos - 1);
	


	CurStart = start;
	
	if (start==1) 
	{
		document.getElementById('gol').style.display = 'none';
	}

	x=1;
	for (i=start; i<start+5; i++)
	{
		if (x==curpos+1) {zz='X';} else {zz='';}
		document.getElementById('prv'+x).innerHTML = '<img src="'+fprev[i]+'" onclick=ShowImg("'+fpath[i]+'",'+x+','+fnum[i]+')><div class="R100'+zz+'" id="rm'+x+'"></div><div class="Shadow'+zz+'" id="shad'+x+'" onclick=ShowImg("'+fpath[i]+'",'+x+','+fnum[i]+')>';
		x++;	
	}


	document.getElementById('foto').innerHTML = '<img src="'+fpath[start+curpos]+'" width="'+fwidth[start+curpos]+'" height="'+fheight[start+curpos]+'">';
	document.getElementById('CurrentPhoto').value = fid[start+curpos];
	document.getElementById('phn').innerHTML = fnum[start+curpos];	
	document.getElementById('phcom').innerHTML = fcom[start+curpos];
	document.getElementById('gor').style.display = 'block';
	document.getElementById('frw').style.display = 'block';
}

function Forward()
{
	
	CurPos = CurPos+1;
	CurImg = CurImg+1;	
	
	
	if (CurImg==fprev.length-1) document.getElementById('frw').style.display = 'none';

	
	if (CurPos<6)
	{
	
		x=1; flag = true;
	
		while (flag == true)
		{
			if (document.getElementById('rm'+x))
			{
				document.getElementById('rm'+x).className = 'R100';
			} else
				{
					flag = false;
				}
			x++;
		} 

		


		

		document.getElementById('foto').innerHTML = '<img src="'+fpath[CurImg]+'" width="'+fwidth[CurImg]+'" height="'+fheight[CurImg]+'">';
		document.getElementById('CurrentPhoto').value = fid[CurImg];
		document.getElementById('rm'+CurPos).className = 'R100X';
		document.getElementById('phn').innerHTML = fnum[CurImg];	
		document.getElementById('bck').style.display = 'block';
		document.getElementById('phcom').innerHTML = fcom[CurImg];
		
	} else		
		{
			GR(0);
		}
}

function Back()
{
	CurPos = CurPos-1;
	CurImg = CurImg-1;		

	
	if (CurImg==1) document.getElementById('bck').style.display = 'none';

	if (CurImg<fprev.length) document.getElementById('frw').style.display = 'block';
	
	if (CurPos>0)
	{
	
		x=1; flag = true;
	
		while (flag == true)
		{
			if (document.getElementById('rm'+x))
			{
				document.getElementById('rm'+x).className = 'R100';
			} else
				{
					flag = false;
				}
			x++;
		} 

		if (document.getElementById('auname')) document.getElementById('auname').innerHTML = fauthor[CurImg];	
		
		document.getElementById('foto').innerHTML = '<img src="'+fpath[CurImg]+'" width="'+fwidth[CurImg]+'" height="'+fheight[CurImg]+'">';
		document.getElementById('CurrentPhoto').value = fid[CurImg];
		document.getElementById('rm'+CurPos).className = 'R100X';
		document.getElementById('phn').innerHTML = fnum[CurImg];
		document.getElementById('phcom').innerHTML = fcom[CurImg];	
	
	} else		
		{
			GLX();
		}

}

function ShowHint(id)
{
	ha = document.getElementById('HintArea');
	ha.innerHTML = hints[id];
}

function HideHint()
{
	ha = document.getElementById('HintArea');
	ha.innerHTML = '';
}

function ShowPopup()
{
	int = document.getElementById('interlaced');
	int.style.height = document.documentElement.scrollHeight + 'px';
	int.style.visibility = 'visible';
	k = document.getElementById('kdr');
	k.style.display = 'block';
}

function HidePopup()
{
	k = document.getElementById('kdr');
	k.style.display = 'none';
	int = document.getElementById('interlaced');
	int.style.visibility = 'hidden';
}

function ShowPhoto(path,width,height)
{
	int = document.getElementById('interlaced');
	int.style.height = document.documentElement.scrollHeight + 'px';
	int.style.visibility = 'visible';
	view = document.getElementById('ViewPhoto');
	vd = document.getElementById('Vdiv');
	foto = document.getElementById('Fotka');
	foto.innerHTML = '<img src="'+path+'" onclick="HidePhoto();">';
	view.style.width = width + 'px';
	vd.style.width = width + 'px';
	view.style.height = height + 30 + 'px';
	view.style.marginLeft = -Math.round(width/2) + 'px';
	view.style.marginTop = -Math.round(height/2) - 35 + document.documentElement.scrollTop + 'px';
	view.style.display = 'block';
}

function HidePhoto()
{
	view = document.getElementById('ViewPhoto');
	view.style.display = 'none';
	int = document.getElementById('interlaced');
	int.style.visibility = 'hidden';
}

function RestoreColorX()
	{
	document.MessageForm.fio.style.background="#ffffff";	
	document.MessageForm.back.style.background="#ffffff";	
	document.MessageForm.dop.style.background="#ffffff";	
	document.MessageForm.country1.style.background="#ffffff";	
	document.MessageForm.country2.style.background="#ffffff";	
	document.MessageForm.country3.style.background="#ffffff";	
	}

function SubmitMessageX()
{
	sm=true;
	if (!checkEmpty(document.MessageForm.fio.value)) 
		{
	document.MessageForm.fio.style.background="#FFA329";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.back.value)) 
		{
	document.MessageForm.back.style.background="#FFA329";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.dop.value)) 
		{
	document.MessageForm.dop.style.background="#FFA329";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.country1.value)) 
		{
	document.MessageForm.country1.style.background="#FFA329";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.country2.value)) 
		{
	document.MessageForm.country2.style.background="#FFA329";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.country3.value)) 
		{
	document.MessageForm.country3.style.background="#FFA329";
	sm=false;	
		}
	if (sm==true) {document.MessageForm.submit();}		
}


function RestoreColorZ()
	{
	document.MessageForm.name.style.background="#ffffff";	
	document.MessageForm.response.style.background="#ffffff";	
	}

function SubmitMessageZ()
{
	sm=true;
	if (!checkEmpty(document.MessageForm.name.value)) 
		{
	document.MessageForm.name.style.background="#FFA329";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.response.value)) 
		{
	document.MessageForm.response.style.background="#FFA329";
	sm=false;	
		}
	if (sm==true) {document.MessageForm.submit();}		
}