// ---------------------
// -- White Gull scripts
// -- http://wgull.ru
// ---------------------

// Возвращает версию браузера
user_agent = new get_browser();
function get_browser() {
  this.ver = navigator.appVersion;
  this.agent = navigator.userAgent.toLowerCase();
  this.dom = document.getElementById ? 1 : 0;
  this.ns4 = (!this.dom && document.layers) ? 1 : 0;
  this.op = window.opera;
  this.moz = (this.agent.indexOf("gecko") > -1 || window.sidebar);
  this.ie = this.agent.indexOf("msie") > -1 && !this.op;

  if(this.op) {
    this.op5 = (this.agent.indexOf("opera 5") > -1 || this.agent.indexOf("opera/5") > -1);
    this.op6 = (this.agent.indexOf("opera 6") > -1 || this.agent.indexOf("opera/6") > -1);
    this.op7 = this.dom && !this.op5 && !this.op6;
  }
  else if (this.moz)
    this.ns6 = 1;
  else if (this.ie) {
    this.ie4 = !this.dom && document.all;
    this.ie5 = (this.agent.indexOf("msie 5") > -1);
    this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5") > -1);
    this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55;
  }
  this.user_agent = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7);
  this.px = this.dom && !this.op5 ? "px" : "";

  return this;
}

// ============================================================================

function openImage(imgName, wt, ht, top, left) {
  if (!top) top = (screen.height) ? ((screen.height - ht)/2 - 50) : 0;
  if (!left) left = (screen.width) ? (screen.width - wt)/2 : 0;

  image=window.open("","fullImage","width=" + (wt+20) + ",height=" + (ht+20) + ",top=" + top + ",left=" + left + ",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes");
  image.focus();
  image.document.open();
  image.document.write("<html>\n<head>\n<title>" + imgName + "</title>\n");
  image.document.write("<meta name=\"robots\" content=\"noindex,nofollow\">\n");
  image.document.write("<script type=\"text/javascript\" language=\"javascript\">function resizeToContent(img) {  	var hSpace = 0; 	var vSpace = 0; 	 	var height; 	var width;  	if ((self.innerWidth) && (self.outerWidth)) { 	 		hSpace = self.outerWidth - self.innerWidth + 12; 		vSpace = self.outerHeight - self.innerHeight + 6; 	} 	else if (self.screenTop) {  		self.moveTo(0, 0); 		hSpace = self.screenLeft + 12; 		vSpace = self.screenTop + 28; 	} 	 	width = img.offsetWidth + 10 + hSpace; 	height = img.offsetHeight + 10 + vSpace;  	if (window.screen) { 	 		var left = (screen.width - width)/2; 		var top = (screen.height - height)/2 - 50; 		 		self.moveTo(left, top); 	}  	self.resizeTo(width, height); }</script>\n");
  image.document.write("<style type=\"text/css\">body { padding: 0px; margin: 5px; text-align: center } </style>\n");
  image.document.write("<a href=\"javascript: window.close();\"><img src=\"" + imgName + "\" border=\"0\" alt=\"закрыть окно\" onload=\"javascript: resizeToContent(this)\"></a>\n");
  image.document.write("\n</body></html>");
  image.document.close();
}

function openNews(date, title, text) {
  news=window.open("", "news1", "top=250,left=150,width=450,height=150,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
  news.focus();
  news.document.open();
  news.document.write("<html>\n<head>\n<title>" + date + "</title>\n");
  news.document.write("<LINK REL=\"StyleSheet\" HREF=\"/inc/css/syntone.css\" type=\"text/css\">\n");
  news.document.write("<meta name=\"robots\" content=\"noindex,nofollow\">\n");
  news.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1251\">\n");
  news.document.write("<base target=\"_blank\">\n");
  news.document.write("</head>\n");
  news.document.write("<body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\"");
  <!-- FFE5B8 -->
  news.document.write("<table bgcolor=\"#FFFFFF\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n");
  news.document.write("<tr><td width=\"100%\">\n");
  news.document.write("<h4>" + title + "</h4>\n");
  news.document.write(text);
  news.document.write("\n</td></tr>\n");
  news.document.write("</table>\n");
  news.document.write("\n</body></html>");
  news.document.close();
}

function openTree(id) {
  document.getElementById(id).style.display =
    (document.getElementById(id).style.display == "inline") ? ("none") : ("inline");
}

function openAll(id_list) {
  id = id_list.split(',');

  for (i=0; i<id.length; i++) {
    document.getElementById(id[i]).style.display = "inline";
  }
}

function closeAll(id_list) {
  id = id_list.split(',');

  for (i=0; i<id.length; i++) {
    document.getElementById(id[i]).style.display = "none";
  }
}

// ============================================================================

// state - показать(1) / спрятать (0) / переключить (2)
function setDIVDisplay(divId, state, display_on) {
  state1 = false; state2 = false;
  if (!display_on) display_on = 'block';

  display = document.getElementById(divId).style.display;
  vis = document.getElementById(divId).style.visibility;

  if(state === false) state = 2;

  if (state == 2) {
    if (user_agent.ie && display_on == 'table-row')  // IE не знает этого значения
      display_on = 'block';

    if (display)
      state1 = (display == 'none') ? display_on : 'none';
    else
      state1 = 'none';

    if (vis)
      state2 = (vis == 'hidden') ? 'visible' : 'hidden';
  }
  else {
    state1 = (state == 1) ? display_on : 'none';
    state2 = (state == 1) ? 'visible' : 'hidden';
  }

  document.getElementById(divId).style.display = state1;
  if (vis) document.getElementById(divId).style.visibility = state2;
}

// ============================================================================

// защита от спам-роботов
function code_email(login, server, domain) {
  eml = login + "@" + server + "." + domain;
  return eml;
}

function code_mailto(login, server, domain, subj) {
  eml = "mailto:" + code_email(login, server, domain);
  if (subj) eml += '?subject=' + subj;

  window.location.href = eml;
}

// добавление страницы в закладки
function addBookmark(element) {

	var href = window.location.href;
	var title = document.title;

	if (window.sidebar) {
	
		window.sidebar.addPanel(title, href, "");
	}
	else if (window.opera) {
	
		element.href = href;
		element.title = title;
	}
	else if (window.external) {
	
		window.external.AddFavorite(href, title);
	}
	else {
	
		alert("Ваш браузер не поддерживает автоматическое создание закладок. Вы можете добавить закладку вручную, используя предлагаемые браузером средства.");
	
		return false;
	}
	
	return true;
}

// делаем страницу стартовой
function makePageStart(element) {

	if (window.external) {
	
		element.style.behavior = "url(#default#homepage)"; 
		element.setHomePage(window.location.href);
	}
	else {
	
		alert("Ваш браузер не позволяет задать стартовую страницу автоматически. Вы можете сделать страницу стартовой вручную, используя предлагаемые браузером средства.");
	}
	
	return false;
}