// teplotim.ru :: functions. (C) Smirnoff 2007-2009

function p_menu(alias) {
  // print menu of production. string alias - name of current menu position (ex. "m-100")

var base = new Array(
"m-100",
"m1-100",
"ppzh-200",
"timruf",
"timlak-1",
"timlak-1v",
"timlak-2",
"timlak-2v",
"p-75",
"p-125",
"p-175",
"profnastil");

var runame = new Array(
"Плиты М-100",
"Маты М1-100",
"Плиты ППЖ-200",
"Плиты ТИМ РУФ",
"Плиты ТИМЛАК-1",
"Плиты ТИМЛАК-1В",
"Плиты ТИМЛАК-2",
"Плиты ТИМЛАК-2В",
"Плиты П-75",
"Плиты П-125",
"Плиты П-175",
"Профнастил, металлочерепица");

document.writeln("<table width='85%' border='0' cellspacing='0' cellpadding='10' bgcolor='#DAE6F4'>");
document.writeln("<tr><td><p>Продукция:</p>");
for (i=0; i<base.length; i++) {
  if (alias==base[i]) {
    document.write("<b>"+runame[i]+"</b> <img src='images/rt.gif' width='8' height='10' border='0'><br>");
  } else {
    document.write("<a href='"+base[i]+".html'>"+runame[i]+"</a><br>");
  }
}
document.writeln("</td></tr></table>");
}

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 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 check_zakaz() {
  // check fields of zakaz form "fb"
  if (fb.cname.value == "" ) {
    alert("Введите НАЗВАНИЕ компании и свое ИМЯ");
	fb.cname.focus();
	return false;
  }
  if (fb.cemail.value == "" ) {
    alert("Введите E-MAIL");
	fb.cemail.focus();
	return false;
  }
  if (!check_email(fb.cemail.value)) {
    alert("Неправильно введен адрес E-MAIL");
	fb.cemail.focus();
	return false;
  }
  if (fb.ctel.value == "" ) {
    alert("Введите ТЕЛЕФОН");
	fb.ctel.focus();
	return false;
  }
  if (fb.cprod.value == "" ) {
    alert("Введите название ПРОДУКЦИИ для заказа");
	fb.cprod.focus();
	return false;
  }
  if (fb.cq.value == "" ) {
    alert("Введите КОЛИЧЕСТВО");
	fb.cq.focus();
	return false;
  }

  return true;
}

function print_date() {
var dayNames = new Array(
"Воскресение",
"Понедельник",
"Вторник",
"Среда",
"Четверг",
"Пятница",
"Суббота");
var monthNames = new Array(
"января",
"февраля",
"марта",
"апреля",
"мая",
"июня",
"июля",
"августа",
"сентября",
"октября",
"ноября",
"декабря");
var now = new Date();
var day = now.getDay();
var month = now.getMonth();
var year = now.getYear();
var date = now.getDate();
if (year == 99)
    year = 1999;
else if (year > 99 && year <2000)
    year = 1900 + year;
var date = now.getDate(); 
document.write(dayNames[day] + ", " + date + " " + monthNames[month] + " " + year + " г."); 
}

function open_help(topic) {
  url = "help_" + topic + ".html";
  window.open(url,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=100,top=50,width=500,height=300');
}

function win_ral(hex, ral) {
  size_x = 300;
  size_y = 150;
  pos_x = Math.round((screen.width - size_x)/4);
  pos_y = Math.round((screen.height - size_y)/4);
  if ((ral=="1013")||(ral=="1016")||(ral=="9001")||(ral=="9003")||(ral=="9010")||(ral=="9016")) {
    num_color = "#000000";
  } else {
    num_color = "#FFFFFF";
  }
  // nw - new window
  nw=open("","","width="+size_x+",height="+size_y+",left="+pos_x+",location=0,resizable=0,scrollbars=0,status=0,toolbar=0,menubar=0,top="+pos_y);
  nw.document.open();
  nw.document.writeln("<html><head><title>"+ral+"</title></head>");
  nw.document.writeln("<body bgcolor='#"+hex+"' leftmargin='10' topmargin='10' marginwidth='10' marginheight='10' title='Закрыть окно' onClick='javascript: window.close();'>");
  nw.document.writeln("<font face='Arial' size='+3' color='"+num_color+"'>"+ral+"</font>");
  nw.document.writeln("</body></html>");
  nw.document.close();  
}

