var delay_time=250;
var tOut2;
var tOut;
var totalNum = 2;
var ie;
var leftOffset;
var topOffset;
var pre='';
var post='';
var loc;



//окно alert
function FormAlert(al,name,j)
{
var width, height;
if (j<7)
{width=250; height=250;}
else
{width=250; height=350;}

//	window.open('/win_new.htm?text=<center>Пожалуйста, заполните поля:</center><br>'+al, name,'width='+width+', height='+height+',resizable=0,scrollbars=0,menubar=0,status=0, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2));
        newWindow2('/win_new.htm?text=<center><b>Пожалуйста, заполните поля:</b></center><br>'+al,name,width,height);
}


//проверка форм
function CheckFields(fname,form_num)
{
var form_name=eval('document.'+fname);
var li='<li>';
var br='';
	var al='';
	var j='';
	var al_post='';
temp_f=eval('f'+form_num+'_Fld');	
temp_a=eval('f'+form_num+'_Alrt');	

for (i=0; i<temp_f.length; i++)
{
	var item = eval('document.'+fname+'.'+temp_f[i]);
  re1 = new RegExp("^ +$","g");
	if (item.value=='' || re1.test(item.value))
 {
		al_post=al;
		al+=li+temp_a[i]+br;
		j++;
	}
}

if (al != '')
{
	FormAlert(al, fname, j);
	return false;
	exit;
}

form_name.submit();
return true;
};

function Init(page)
{

//alert(window.navigator.userAgent);
//(page==1) ? leftOffset=204:leftOffset=187;
//(page==1) ? topOffset=20:topOffset=16

(page==1) ? leftOffset=90:leftOffset=187;
(page==1) ? topOffset=20:topOffset=12;

if (window.navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
if (page == 1) leftOffset=204;


var browser_name = navigator.appName;
var browser_version = parseFloat(navigator.appVersion); 

ie=1;

if (browser_name == "Microsoft Internet Explorer" && browser_version >= 4.0) ie=1;

if(ie){
  pre='all';
  post='style.';
  document.onmouseover=Check;
} else {

  pre='layers';
  post='';
  delay_time=350;

}
return true;
} 

function Check()
{
if(!pre) return 0;
clearTimeout(tOut);
if(ie){
  whichEl = event.srcElement;
  while ((whichEl.id.indexOf("item") == -1)&&(whichEl.id.indexOf("drop") == -1)){
    whichEl = whichEl.parentElement;
    if (whichEl == null) { 
    clearTimeout(tOut);
    clearTimeout(tOut2);
    eval('tOut = setTimeout("Delay()", delay_time)');
  return 0;}
  if (whichEl.id.indexOf("drop") != -1) clearTimeout(tOut2);
  }
} else { return 0;}
return true;
}

function findPosX(id)
{
  
  if(!pre) return 0;
  var curleft = 0;
  
  if (document.getElementById || document.all)
  {
  
  obj=eval('document.all["' + id +'"]');
    while (obj.offsetParent)
    {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  else {
    obj=eval('document.anchors["' + id +'"]');
    curleft += obj.x;
    
  }
  return curleft;
}

function findPosY(id)
{
  if(!pre) return 0;
  var curtop = 0;
  if (document.getElementById || document.all)
  {
  obj=eval('document.all["' + id +'"]');
    while (obj.offsetParent)
    {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else{
    obj=eval('document.anchors["' + id +'"]');
    curtop += obj.y;
    
  }
  return curtop;
}

function Menu(num)
{
//pos = getElementPosition("item1"); 
//var left = pos.left;
//alert(left);
//iks=getOffsetRect(document.all["item1"]).left;
//igrek=getOffsetRect(document.all["item1"]).top;
//alert(ie);

if(!pre) return 0;

clearTimeout(tOut2);
clearTimeout(tOut);
for(i=1; i<=totalNum; i++){
  if(i!=num) eval('document.'+pre+'["drop'+i+'"].'+post+'visibility="hidden"');
}

if (ie)
{
eval('iks=findPosX("anch1")');
eval('igrek=findPosY("anch1")');
}
else
{
iks=getOffsetRect(document.all["item1"]).left;
igrek=getOffsetRect(document.all["item1"]).top;
}


iks += leftOffset;
igrek -= topOffset;

eval('document.'+pre+'["drop'+num+'"].'+post+'top='+igrek);
eval('document.'+pre+'["drop'+num+'"].'+post+'left='+iks);
eval('document.'+pre+'["drop'+num+'"].'+post+'visibility="visible"');

return true;
}

function Delay()
{if(!pre) return 0;
for(i=1; i<=totalNum; i++){
  eval('document.'+pre+'["drop'+i+'"].'+post+'visibility="hidden"');
}
return true;
}

function MenuOut(num)
{
if(!pre) return 0;
clearTimeout(tOut2);
eval('tOut2 = setTimeout("Delay()", delay_time)');
return true;
}

function SndLevel(num, layerNum)
{
if(!pre) return 0;
clearTimeout(tOut2);
clearTimeout(tOut);
if(!ie){
  obj=eval('document.layers["drop' + layerNum + '"].document.anchors["snd' + num +'"]');
  objParnt=eval('document.layers["drop' + layerNum + '"]');
  igrek = obj.y + objParnt.y;
  iks = obj.x + objParnt.x;
  iks -= 12;
  igrek += 3;
}else{
eval('iks=findPosX("snd'+num+'")');
eval('igrek=findPosY("snd'+num+'")');
iks -= 12;
igrek += 3;
}
eval('document.'+pre+'["pointer"].'+post+'top='+igrek);
eval('document.'+pre+'["pointer"].'+post+'left='+iks);
eval('document.'+pre+'["pointer"].'+post+'visibility="visible"');
//alert(ie);

return true;
}

function SndLevOut(num)
{
if(!pre) return 0;
clearTimeout(tOut2);
eval('document.'+pre+'["pointer"].'+post+'visibility="hidden"');
if(!ie){
  eval('tOut2 = setTimeout("Delay()", delay_time)');
}
return true;
}

  function Winopen(url)
  {
  var width=250;
  var height=150;
  new_win = window.open(url, "new_win", 'width = '+width+' , height = '+height+',resizable=0,scrollbars=0,menubar=0,status=0, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2));
  }

function msgwin(al,name)
{
var width=250;
var height=150;
  window.open('/win_new.htm?text='+al+'', name,'width='+width+', height='+height+',resizable=0,scrollbars=0,menubar=0,status=0, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2));
}

function msgwin1(al,name)
{
var width=250;
var height=150;
  window.open('/win_new1.htm?text='+al+'', name,'width='+width+', height='+height+',resizable=0,scrollbars=0,menubar=0,status=0, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2));
}

  function descrwin(id)
  {
  var width=400;
  var height=300;
  new_win = window.open("descr.htm?id="+id, "new_win", 'width = '+width+' , height = '+height+',resizable=0,scrollbars=1,menubar=0,status=0, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2));
  }
  
function newWindow(id)
{
var url="descr.htm?id="+id;
var width=400;
var height=300;

if (!id) url="";

if (loc!="new_win")
{
  zoom=window.open(url, "new_win", 'width = '+width+' , height = '+height+',resizable=0,scrollbars=1,menubar=0,status=1, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2))
  loc="new_win";
}
else 
{
  if(document.all) zoom.close();
    else if(zoom.document) zoom.close();
  zoom=window.open(url, "new_win", 'width = '+width+' , height = '+height+',resizable=0,scrollbars=1,menubar=0,status=1, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2))
}
}

function newWindow2(url,id,width,height)
{
if (loc!=id)
{
	zoom=window.open(url, id, 'width = '+width+' , height = '+height+',resizable=0,scrollbars=0,menubar=0,status=0, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2))
	loc=id;
}
else 
{
	zoom.close();
	zoom=window.open(url, id, 'width = '+width+' , height = '+height+',resizable=0,scrollbars=0,menubar=0,status=0, left='+Math.max(0,(screen.width-width)/2)+', top='+Math.max(0,(screen.height-height)/2))
}
}