function isEmpty(str) {
	for (var j=0; j<str.length; j++) {
		if (" " != str.charAt(j)) return false;
	}
	return true;
}

function checkForm(f)
{
	for (var i=0; i<f.elements.length; i++) {
		if (null!=f.elements[i].getAttribute("forcheck")) {
		if (isEmpty(f.elements[i].value) || f.elements[i].value == f.elements[i].getAttribute("forcheck")) {
				alert(f.elements[i].getAttribute("forcheck") + ' field empty!');
				f.elements[i].focus();
				return false;
		}
		}
	}
	//f.go.disabled = true;
	return true;
}

function tfocus(el)
{
	if (el.value == el.getAttribute("default")) {
		el.value = '';
		el.style.color = '#333';
	}
}

function tblur(el)
{
	if (isEmpty(el.value)) {
		el.value = el.getAttribute("default");
		el.style.color = '#959595';
	}
}

function checkMail(mt)
{
	var reg = new RegExp("^[A-Za-z0-9_-]{1,20}@(([A-Za-z0-9-]+\\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})$");
	if(!reg.test(mt)) {
		return false;
	} else {
		return true;
	}
}

function displayDiv(id)
{
	obj = document.getElementById(id);
	obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
}

function searchOnFocus(obj)
{
	obj.className = 'searchtext'; 
	obj.value='';
}
function searchOnBlur(obj)
{
	if(obj.value==''){
		obj.className = 'searchtxt'; 
		obj.value='search';
	}
}


//---------------------------
var modeStatus = new Array(10);
for(var i = 0; i<10; i++) modeStatus[i] = new Array('0', '0');
var showTimer;
var timerShow = new Array();
var timerHide = new Array();
var xMouse, yMouse;
var eventName;
var waitId;
	// инициализация блоков
	function InitMenuStatus(ids, idfull)
	{
		var idsArr = ids.split(',');
		var cPro = idsArr.length;
		for(var i = 0; i<cPro; i++) {
			modeStatus[i][0] = idsArr[i];
			modeStatus[i][1] = (idsArr[i]==idfull) ? 3 : 1;
		}
		for(var i = 0; i<cPro; i++){
			var pro1        = document.getElementById('pro_' + idsArr[i]);
			var pro2        = document.getElementById('pro2_' + idsArr[i]);
			var pronamediv  = document.getElementById('pronamediv_' + idsArr[i]);
			var prodescr    = document.getElementById('prodescr_' + idsArr[i]);
			var promenulist = document.getElementById('promenulist_' + idsArr[i]);
			var proHmin     = pronamediv.offsetHeight + prodescr.offsetHeight + 15;
			var proHmax     = pronamediv.offsetHeight + prodescr.offsetHeight + promenulist.offsetHeight + 25;
			if(modeStatus[i][1]!=3){
				pro1.style.height = proHmin + 'px';
				pro2.style.height = proHmin - 11 +'px';
			} else {
				pro1.style.height = proHmax + 'px';
				pro2.style.height = proHmax - 11 +'px';
			}
		}
	}
	// проверка положения мыши внутри блока с id
	function isMouseInDiv(id)
	{
		var inDiv  = 1;
		var brouser= navigator.appName;
		var obj    = document.getElementById("pro_" + id);
		var pos    = getAbsPos('pro_' + id);
		if(xMouse>=pos[0] && xMouse<=(pos[0] + obj.offsetWidth) && yMouse>=pos[1] && yMouse<=(pos[1] + obj.offsetHeight)) inDiv = 2;
		return inDiv;
	}
	// показ блока
	function showDiv(id, h1, h2){
		for(var j = 0; j<10;j++) if(modeStatus[j][0]==id) var stat = j;
		if(modeStatus[stat][1]==1){
			if(isMouseInDiv(id)==2) modeStatus[stat][1]=4;
		}
		if(modeStatus[stat][1]==4){
			if(isMouseInDiv(id)==2){
				var pro1 = document.getElementById('pro_' + id);
				var pro2 = document.getElementById('pro2_' + id);
				if(h1<h2){
					pro1.style.height = h1 + 'px';
					pro2.style.height = h1 - 11 +'px';
					var step = 3;
					if(navigator.appName=='Microsoft Internet Explorer') step = 10;
					if(navigator.appName=='Netscape') step = 5;
					h1 = h1 + step;
					var v = parseInt(100/(h2 - h1));
					if(navigator.appName=='Microsoft Internet Explorer') v = 0;
					timerShow[id] = setTimeout("showDiv("+id+","+h1+","+h2+")", v);
				} else {
					for(var i = 0; i<10; i++)
						if(modeStatus[i][0]==id) modeStatus[i][1] = 2;
				}
			} else {
				for(var j = 0; j<10; j++) if(timerShow[j]!=null) clearTimeout(timerShow[j]);
				var pro1        = document.getElementById('pro_' + id);
				var pronamediv  = document.getElementById('pronamediv_' + id);
				var prodescr    = document.getElementById('prodescr_' + id);
				var promenulist = document.getElementById('promenulist_' + id);
				var proH        = pro1.offsetHeight;
				var proHmin     = pronamediv.offsetHeight + prodescr.offsetHeight + 12;
				var proHmax     = pronamediv.offsetHeight + prodescr.offsetHeight + promenulist.offsetHeight + 25;
				modeStatus[stat][1] = 2;
				hideDiv(id, proHmin, proH);
			}
		}
	}
	// скрытие блока
	function hideDiv(id, h1, h2){
		for(var j = 0; j<10;j++) if(modeStatus[j][0]==id) var stat = j;
		if(modeStatus[stat][1]==2){
			if(isMouseInDiv(id)!=2) modeStatus[stat][1]=5;
		}
		if(modeStatus[stat][1]==5){
			var pro1 = document.getElementById('pro_' + id);
			var pro2 = document.getElementById('pro2_' + id);
			if(h1<h2){
				pro1.style.height = h2 + 'px';
				pro2.style.height = h2 - 11 +'px';
				var step = 3;
				if(navigator.appName=='Microsoft Internet Explorer') step = 10;
				if(navigator.appName=='Netscape') step = 5;
				h2 = h2 - step;
				var v = parseInt(100/(h2 - h1));
				timerHide[id] = setTimeout("hideDiv("+id+","+h1+","+h2+")", v);
				if(h1>=h2){
					for(var j = 0; j<10; j++) if(timerHide[j]!=null) clearTimeout(timerHide[j]);
					modeStatus[stat][1] = 1;
				}
			} else {
				for(var j = 0; j<10; j++) if(timerHide[j]!=null) clearTimeout(timerHide[j]);
				modeStatus[stat][1] = 1;
			}
		}
	}
	// главная функция
	function displayLeftMenu(ev)
	{
		if(document.getElementById('allblock').style.visibility != 'visible'){
			var brouser= navigator.appName;
			eventName = (brouser=='Netscape') ? ev : '';
			for(var i = 0; i<10; i++){
				id = modeStatus[i][0];
				if(id!=0){
					var pro1        = document.getElementById('pro_' + id);
					var pronamediv  = document.getElementById('pronamediv_' + id);
					var prodescr    = document.getElementById('prodescr_' + id);
					var promenulist = document.getElementById('promenulist_' + id);
					var proH        = pro1.offsetHeight;
					var proHmin     = pronamediv.offsetHeight + prodescr.offsetHeight + 12;
					var proHmax     = pronamediv.offsetHeight + prodescr.offsetHeight + promenulist.offsetHeight + 25;
					xMouse = (brouser=='Netscape') ? eventName.pageX : window.event.clientX;
					yMouse = (brouser=='Netscape') ? eventName.pageY : window.event.clientY + document.documentElement.scrollTop;
					/*if(brouser=='Microsoft Internet Explorer') yMouse += document.documentElement.scrollTop;
					if(brouser=='Opera') yMouse = yMouse + document.documentElement.scrollTop;*/

					if(isMouseInDiv(id)==2){
						if(modeStatus[i][1]==1){
							for(var j = 0; j<10; j++) if(timerHide[j]!=null) clearTimeout(timerHide[j]);
							/*for(var j = 0; j<10; j++) if(timerShow[j]!=null) clearTimeout(timerShow[j]);*/
							if(showTimer!=null) clearTimeout(showTimer);
							showTimer = setTimeout("showDiv("+id+","+proHmin+","+proHmax+")", 200);
						}
					} else{
						if(modeStatus[i][1]==2){
							for(var j = 0; j<10; j++) if(timerShow[j]!=null) clearTimeout(timerShow[j]);
							if(showTimer!=null) clearTimeout(showTimer);
							hideDiv(id, proHmin, proH);
						}
					}
				}
			}
		}
	}
	// получение абсолютных координат объекта
	function getAbsPos(objName)
	{
		var pos = new Array();
		var obj = document.getElementById(objName);
		var x = y = 0; 
		while(obj) { 
			x  += obj.offsetLeft; 
			y  += obj.offsetTop; 
			obj = obj.offsetParent; 
		}
		pos[0] = x;
		pos[1] = y
		return pos;
	}
//-------------------------------

function MM_preloadImages() {
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


// ------------- показ скринщотов ------------
function setOpacity(obj, value) {
	obj.style.opacity = value/10;
	obj.style.filter = 'alpha(opacity=' + value*10 + ')';
}
function svetUp(div)
{
	obj = document.getElementById(div);
	for (var i=0;i<11;i++) setTimeout('setOpacity(obj,'+i+')', 15*i);
}

function svetDown(div)
{
	obj = document.getElementById(div);
	for (var i=10;i>=0;i--) setTimeout('setOpacity(obj,'+i+')', 10*Math.abs(i-15));
}

function closeImage(ev)
{
	var inDiv  = 1;
	var brouser= navigator.appName;
	var obj    = document.getElementById("load");
	var pos    = getAbsPos('load');
	var xM = (brouser=='Netscape') ? ev.pageX : window.event.clientX;
	var yM = (brouser=='Netscape') ? ev.pageY - document.documentElement.scrollTop: window.event.clientY;
	var pattern = /MSIE 6/;
	if(brouser=="Microsoft Internet Explorer" && navigator.appVersion.search(pattern)!=-1) pos[1] = pos[1] - document.documentElement.scrollTop;
	var oW = parseInt(pos[0]) + parseInt(obj.offsetWidth);
	var oH = parseInt(pos[1]) + parseInt(obj.offsetHeight);
	if(xM>=pos[0] && xM<=oW && yM>=pos[1] && yM<=oH) inDiv = 2;
	if(inDiv==1) navigateImage(2);
}

function navigateImage(mode)
{
	// открытие
	if(mode==1){
		var main = document.getElementById('main');
		document.getElementById('allblock').style.height = main.offsetHeight + "px";
		document.getElementById('allblock').style.visibility = 'visible';
	}
	// закрытие
	if(mode==2){
		document.getElementById('allblock').style.visibility = 'hidden';
		document.getElementById('photo').style.display = 'none';
		document.getElementById('photo').src = '/i/sn.gif';
		window.currentId = null;
		window.start = null;
		window.waveProcess = false;
	}
	// предыдущая
	if(mode==3){
		//alert(window.currentId);
		if(window.currentId != null && window.currentId>0) viewImage(window.currentId - 1);
	}
	// следующая
	if(mode==4){
		if(window.currentId != null && window.currentId<screenArr.length - 1) viewImage(window.currentId + 1);
	}
}

var start = null;
var waveProcess = false;

function viewImage(num)
{
	div = 'photo';
	id = num;

	navigateImage(1);

	document.getElementById(div).onload = "";
	
	if (window.waveProcess)
	{
		document.getElementById('load').className = 'not_loader';
		window.waveProcess = false;
	}

	window.imageId = id;
	window.imageCheck = (window.start) ? false : true;
	window.start = id;
	url = "/imagemanager/images/" + screenArr[id];

	document.getElementById('empty').src = url;
	document.getElementById('empty').onload = function() {
		window.imageCheck = true;
	}

	setTimeout("if (window.imageCheck == false) { wave('"+div+"', '"+id+"', '"+url+"'); } else { simple('"+div+"', '"+id+"', '"+url+"'); }", 200);
	document.getElementById('prevscr').style.cursor = (id==0) ? "default" : "hand";
	document.getElementById('nextscr').style.cursor = (id==(screenArr.length - 1)) ? "default" : "hand";
	document.getElementById("prevscr").className = (num==0) ? "noprevimg" : "previmg";
	document.getElementById("nextscr").className = (num==(screenArr.length - 1)) ? "nonextimg" : "nextimg";

	window.currentId = id;
}

function simple(div, id, url)
{
	document.getElementById(div).style.display = 'block';
	document.getElementById(div).src = url;
	document.getElementById('load').style.height = document.getElementById(div).offsetHeight + 20 + "px";
	document.getElementById('load').style.width  = document.getElementById(div).offsetWidth  + 20 + "px";

	var number = parseInt(1) + parseInt(id);
	document.getElementById('scrinfo').innerHTML = number + " / " + screenArr.length;
	document.getElementById('load').style.marginLeft = '-' + parseInt(document.getElementById(div).offsetWidth / 2 + 10) + "px";
	
	setOpacity(document.getElementById(div), 10);
}

function wave(div, id, url)
{
	window.waveProcess = true;
	document.getElementById(div).style.display = 'block';
	//if (window.imageId == id)
	//{
		svetDown(div);
		document.getElementById('load').className = 'not_loader';

		document.getElementById(div).onload = function() {
			document.getElementById('load').className = 'not_loader';
			svetUp('photo');
			window.waveProcess = false;
			document.getElementById('load').style.height = document.getElementById('photo').offsetHeight + 20 + "px";
			document.getElementById('load').style.width  = document.getElementById('photo').offsetWidth  + 20 + "px";
			document.getElementById('load').style.marginLeft = '-' + parseInt(document.getElementById('photo').offsetWidth / 2 + 10) + "px";
		}
		document.getElementById('load').style.height = document.getElementById(div).offsetHeight + 20 + "px";
		document.getElementById('load').style.width  = document.getElementById(div).offsetWidth  + 20 + "px";
		simple(div, id, url);
	//}
}
//--------------------------------------------
