// baza-svetofor.ru :: java-functions. 
// (C) Smirnoff 2008

function open_image(image_name, size_x, size_y, title_text, alt_text) {
  // image_name - file name, in folder "images"
  // close window by click on image
  // pos_x, pos_y - position of window. In left top corner of screen
  pos_x = Math.round((screen.width - size_x)/4);
  pos_y = Math.round((screen.height - size_y)/4);
  sb = 0; // normal. scrollbars off
  ww = size_x;
  wh = size_y;
  if (size_y > screen.height) {
    // image very height
    sb = 1; // scrollbars on
	ww = size_x + 20; // window width
	wh = screen.height - 60; // window height
	pos_y = 0;
  }
  alt_text = alt_text + '. Закрыть окно'
  // nw - new window
  nw=open("","","width="+ww+",height="+wh+",left="+pos_x+",location=0,resizable=0,scrollbars="+sb+",status=0,toolbar=0,menubar=0,top="+pos_y);
  nw.document.open();
  nw.document.writeln("<html><head><title>"+title_text+"</title></head>");
  nw.document.writeln("<body bgcolor='#FFFFFF' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
  nw.document.writeln("<a href='javascript: window.close();'><img src='images/"+image_name+"' width='"+size_x+"' height='"+size_y+"' border='0' alt='"+alt_text+"' title='"+alt_text+"'></a>");
  nw.document.writeln("</body></html>");
  nw.document.close();  
}

			
function showContent(cID) {
  // show or hidden contentblock
  var content = cID + "_link"
  if (window.document.all(content).style.display == "none")
  {
    window.document.all(content).style.display = "";
  }
  else
  {
    window.document.all(content).style.display = "none";			
  }
}


function check_email(email_addr) {
  // syntax check of email_addr
var re, re2;
re = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/
re2 = /^.+\@\[?(\w|[-.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/
if (email_addr.search(re) == -1 ) {
	if (email_addr.search(re2) != -1) {
		return(true);
	}
}
return(false);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_preloadImages() { //v3.0
  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 MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
