// SITELIB.JS
// (C) 2004 Yaroslav Chupikov
// www.design.fanspace.com
// freeworld@mail.ru

// ==========================
// ===[ DATA & VARIABLES ]====================================================
// ==========================

var HOME_PAGE    = "../main.html";
var CONTACT_PAGE = "../contact.html";
var NEXT_PAGE    = "";

var LINK_OWNER  = "http://www.aviko-lux.ru";
var MAIL_OWNER  = "mailto:info@aviko-lux.ru";
var LINK_AUTHOR = "http://www.design.fanspace.com";
var MAIL_AUTHOR = "mailto:freeworld@mail.ru";

var KEYWORDS = "";

var marker_n = new Image(); marker_n.src = "images/marker.gif";
var marker_s = new Image(); marker_s.src = "images/marker_a.gif";

// ============================
// ===[ USER AGENT & FLASH ]==================================================
// ============================

var isIE = (document.all != null);
var isNN = !(isIE);

var CLIENT_UNKNOWN = 0;
var CLIENT_IE      = 1;
var CLIENT_NN      = 2;
var CLIENT_OP      = 3;
var CLIENT_MZ      = 4;

var BROWSER        = CLIENT_UNKNOWN;
if (navigator.userAgent.indexOf("Opera") > -1) {
   BROWSER = CLIENT_OP;
   } else if (navigator.userAgent.indexOf("Netscape") > -1) {
   BROWSER = CLIENT_NN;
   } else if (navigator.userAgent.indexOf("Gecko/") > -1) {
   BROWSER = CLIENT_MZ;
   } else if (document.all) {
   BROWSER = CLIENT_IE;
   }

// ===================
// ===[ FUNCTIONS ]===========================================================
// ===================

//---[ samplelink ]-----------------------------------------------------------

function samplelink() {
  window.alert("This is sample link!\nLinks will be available in the server version.");
  }

//---[ hilight ]--------------------------------------------------------------

function hilight(obj) {
  if (obj != null) {
     obj.style.color = "#FFFFFF";

     obj.style.borderColor = "#999999";
     obj.style.backgroundColor = "#333333";
     }
  }

//---[ unhilight ]------------------------------------------------------------

function unhilight(obj) {
  if (obj != null) {
     obj.style.color = "#CCCCCC";

     obj.style.borderColor = "#000000";
     obj.style.backgroundColor = "#000000";
     }
  }

//---[ select ]---------------------------------------------------------------

function select(img) {
  if (img != null) {
     img.src = eval(img.name + "_s.src;");
     }
  }

//---[ unselect ]-------------------------------------------------------------

function unselect(img) {
  if (img != null) {
     img.src = eval(img.name + "_n.src;");
     }
  }

//---[ mselect ]--------------------------------------------------------------

function mselect(imgname) {
  var img = eval("document.all." + imgname);
  if (img != null) {
//     img.src = marker_s.src;
     }
  }

//---[ munselect ]------------------------------------------------------------

function munselect(imgname) {
  var img = eval("document.all." + imgname);
  if (img != null) {
//     img.src = marker_n.src;
     }
  }

//---[ comment ]--------------------------------------------------------------

function comment(text) {
  if (isIE) {
     if (text != null) {
        if (text.length > 0) {
           document.all.comment.style.borderStyle = "solid";
           document.all.comment.innerHTML = text;
           } else {
           uncomment();
           }
        }
     }
  }

//---[ uncomment ]------------------------------------------------------------

function uncomment() {
  if (isIE) {
     document.all.comment.style.borderStyle = "none";
     document.all.comment.innerHTML = "";
     }
  }

//---[ goBack ]---------------------------------------------------------------

function goBack() {
  if (history.length > 0) {
     history.back();
     }
  }

//---[ goNext ]---------------------------------------------------------------

function goNext() {
  if (NEXT_PAGE.length > 0) {
     document.location = NEXT_PAGE;
     }
  }

//---[ goHome ]---------------------------------------------------------------

function goHome() {
  if (HOME_PAGE.length > 0) {
     document.location = HOME_PAGE;
     }
  }

//---[ goContact ]------------------------------------------------------------

function goContact() {
  if (CONTACT_PAGE.length > 0) {
     document.location = CONTACT_PAGE;
     }
  }

//---[ OpenURL ]--------------------------------------------------------------

function OpenURL(URL) {
  if (URL != null) {
     if (URL.length > 0) {
        document.location = URL;
        } else {
        alert("Ссылка не указана!\nОбратитесь к разработчику.");
        }
     } else {
     alert("Пустая ссылка (null)!\nОбратитесь к разработчику.");
     }
  }

//---[ showDetails ]----------------------------------------------------------

function showDetails(idx) {
  if (idx != null) {
     if (idx.length > 0) {
        var URL = "details.php?index=" + idx;
        win     = window.open(URL, "win", "toolbar=no,scrollbars=yes,resizable=yes,width=700,height=450");
        } else {
        alert("Индекс товара не указан!\nОбратитесь к разработчику.");
        }
     } else {
     alert("Пустой индекс товара (null)!\nОбратитесь к разработчику.");
     }
  }

//---[ show ]-----------------------------------------------------------------
// Open new window and show image "img".

function show(img) {
  if (img != null) {
     window.open("gimage.php?image=" + img, "", "width=900,height=700");
     }
  }

//---[ sendQuery ]------------------------------------------------------------

function sendQuery() {
  var msg = "";
  var i   = 0;

  if (document.MainForm.qname.value.length == 0) {
     i++;
     msg = msg + i + ". Фамилия, Имя.\n";
     }
  if (document.MainForm.qfirm.value.length == 0) {
     i++;
     msg = msg + i + ". Название предприятия.\n";
     }
  if (document.MainForm.qemail.value.length == 0) {
     i++;
     msg = msg + i + ". Электронная почта.\n";
     }
  if (document.MainForm.qphone.value.length == 0) {
     i++;
     msg = msg + i + ". Телефон.\n";
     }
  if (document.MainForm.qaddress.value.length == 0) {
     i++;
     msg = msg + i + ". Адрес доставки.\n";
     }

  if (i > 0) {
     msg = "Необходимо заполнить следующие поля:\n\n" + msg;
     alert(msg);
     } else {
     msg = msg + "\nФамилия, Имя: " + document.MainForm.qname.value;
     msg = msg + "\nНазвание предприятия: " + document.MainForm.qfirm.value;
     msg = msg + "\nЭлектронная почта: " + document.MainForm.qemail.value;
     msg = msg + "\nТелефон: " + document.MainForm.qphone.value;
     msg = msg + "\nАдрес доставки: " + document.MainForm.qaddress.value;

     msg = "Проверьте правильность заполнения формы\n" + msg + "\n\nПослать запрос?";
     if (confirm(msg)) {
        document.MainForm.submit();
        }
     }
  }

// =========================
// ===[ PRINT FUNCTIONS ]======================================================
// =========================

//---[ printMenu ]------------------------------------------------------------

function printMenu() {
  with (document) {
    writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
    writeln('<tr><td><a href=""><img name="m_01" src="../images/m_01_n.gif" border="0" onMouseOver="select(this); comment(\'зМБЧОБС УФТБОЙГБ\');" onMouseOut="unselect(this); uncomment();"></a></td></tr>');
    writeln('<tr><td><a href=""><img name="m_02" src="../images/m_02_n.gif" border="0" onMouseOver="select(this); comment(\'п УЕВЕ...\');" onMouseOut="unselect(this); uncomment();"></a></td></tr>');
    writeln('<tr><td><a href=""><img name="m_03" src="../images/m_03_n.gif" border="0" onMouseOver="select(this); comment(\'рПУМЕДОЙЕ ОПЧПУФЙ\');" onMouseOut="unselect(this); uncomment();"></a></td></tr>');
    writeln('<tr><td><a href=""><img name="m_04" src="../images/m_04_n.gif" border="0" onMouseOver="select(this); comment(\'тЕЛМБНОЩЕ ФЕИОПМПЗЙЙ\');" onMouseOut="unselect(this); uncomment();"></a></td></tr>');
    writeln('<tr><td><a href=""><img name="m_05" src="../images/m_05_n.gif" border="0" onMouseOver="select(this); comment(\'юБКИБОБ\');" onMouseOut="unselect(this); uncomment();"></a></td></tr>');
    writeln('<tr><td><a href=""><img name="m_06" src="../images/m_06_n.gif" border="0" onMouseOver="select(this); comment(\'лПОФБЛФОБС ЙОЖПТНБГЙС\');" onMouseOut="unselect(this); uncomment();"></a></td></tr>');
    writeln('</table>');
    }
  }

//---[ printCopyright ]-------------------------------------------------------

function printCopyright() {
  with (document) {
    writeln('<table bgcolor="#000000" width="100%" border="0" cellspacing="0" cellpadding="5">');
    writeln('<tr>');
    writeln('<td align="left">');
    writeln('<a href="' + MAIL_OWNER + '" class="copyright">&copy; 2004</a>');
    writeln('</td>');
    writeln('<td align="right">');
    writeln('<a href="' + LINK_AUTHOR + '" class="copyright">дЙЪБКО, ЧЕТУФЛБ, РТПЗТБННЙТПЧБОЙЕ: сТПУМБЧ юХРЙЛПЧ</a>');
    writeln('</td>');
    writeln('</tr>');
    writeln('</table>');
  }
}

//---[ printComment ]---------------------------------------------------------

function printComment() {
  with (document) {
    writeln('<div name="comment" id="comment" style="position: absolute; left: 5px; top: 310px; width:200px; padding: 5px; margin: 5px; margin-top: 20px; border: 1px none #FF0000; color: white; font-weight: bold"></div>');
    }
  }

// =========================
// ===[ DHTML FUNCTIONS ]======================================================
// =========================

//---[ getLayer ]-------------------------------------------------------------

function getLayer(name) {
  if (isNN) {
     return findLayer(name, document);
     } else if (isIE) {
     return eval('document.all.' + name);
     } else {
     return null;
     }
  }

//---[ findLayer ]------------------------------------------------------------

function findLayer(name, doc) {
  var i, layer;

  for (i = 0; i < doc.layers.length; i++) {
    layer = doc.layers[i];
    if (layer.name == name) {return layer;}
    if (layer.document.layers.length > 0) {
       if ((layer = findLayer(name, layer.document)) != null) {
          return layer;
          }
       }
    }
  return null;
  }

//---[ getPageWidth ]---------------------------------------------------------

function getPageWidth() {
  if (isNN) {
     return document.width;
     } else if (isIE) {
     return document.body.scrollWidth;
     } else {
     return -1;
     }
  }

//---[ hetPageHeight ]--------------------------------------------------------

function getPageHeight() {
  if (isNS) {
     return document.height;
     } else if (isIE) {
     return document.body.scrollHeight;
     } else {
     return -1;
     }
  }

//---[ moveLayerTo ]----------------------------------------------------------

function moveLayerTo(layer, x, y) {
  if (isNN) {
     layer.moveTo(x, y);
     } else if (isMinIE4) {
     layer.style.left = x;
     layer.style.top  = y;
     }
  }

