// <script>

// Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Distribute this code, any part or any modified version of it.
//     Instead, you can link to the homepage of this code:
//     http://www.php-development.ru/javascripts/smart-forms.php.
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as a part of another product provided that
//     its main use is not creating javascript menus.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.

// If you find my script useful, you can support my site in the following ways:
// 1. Vote for the script at HotScripts.com (you can do it on my site)
// 2. Link to the homepage of this script or to the homepage of my site:
//    http://www.php-development.ru/javascripts/smart-forms.php
//    http://www.php-development.ru/
//    You will get 50% commission on all orders made by your referrals.
//    More information can be found here:
//    http://www.php-development.ru/affiliates.php


// ----- Popup Control ---------------------------------------------------------

var appArray = new Array();

function at_display(x)
{
  win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- Show Aux -----

function at_show_aux(parent, child)
{
if(document.getElementById){
	var p = document.getElementById(parent);
	var c = document.getElementById(child);
	if(macflg) {
	var f = document.getElementById('fl');
	var im = document.getElementById('flim');
	}
}else if(document.all){
	var p = document.all(parent);
	var c = document.all(child);
	if(macflg) {
	var f = document.all('fl');
	var im = document.all('flim');
	}
}else if(document.layers){
	//var p = document.layers[kaisou].layers[parent];
	//var c = document.layers[kaisou].layers[child];
	var p= getelem_ns4(parent,document);
	var c= getelem_ns4(child,document);
	if(macflg) {
	var f = document.layers['fl'];
	var im = document.layers['flim'];
	}
}

  var top  = (c["at_position"] == "y") ? p.offsetHeight+1 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +1 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

	if(c["at_child"]=="mcom"){
		left-=36;
	}

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
  if(macflg) {
	  if(f){
	  f.style.visibility = "hidden";
	  im.style.visibility = "visible";
	  callExternalInterface();
	  }
  }
}

// ----- Show -----

function at_show()
{
//alert(this["at_parent"]);
if(document.getElementById){
	p = document.getElementById(this["at_parent"]);
	c = document.getElementById(this["at_child" ]);
	//alert("1");
}else if(document.all){
	p = document.all(this["at_parent"]);
	c = document.all(this["at_child" ]);
	//alert("2");
}else if(document.layers){
	//p = document.layers[kaisou].layers[this["at_parent"]];
	//c = document.layers[kaisou].layers[this["at_child" ]];
	p= getelem_ns4(this["at_parent"],document);
	c= getelem_ns4(this["at_child" ],document);
	alert(p);
}
  	if(macflg) {
  	appArray.push(1);
	}
  
   at_show_aux(p.id, c.id);

  clearTimeout(c["at_timeout"]);
}

// ----- Hide -----





function at_hide(){
	if(document.getElementById){
		c = document.getElementById(this["at_child"]);
	}else if(document.all){
		c = document.all(this["at_child"]);
	}else if(document.layers){
		//c = document.layers[kaisou].layers[this["at_child"]];
		c= getelem_ns4(this["at_child"],document);
	}
	if(macflg) {
	appArray.shift();
	}
	c["at_timeout"] = setTimeout("at_hide_timeout('"+c.id+"')", 50);
}


function at_hide_timeout(child){

	if(document.getElementById){
		c = document.getElementById(child);
		if(macflg) {
		var f = document.getElementById('fl');
		var im = document.getElementById('flim');
		}
	}else if(document.all){
		c = document.all(child);
		if(macflg) {
		var f = document.all('fl');
		var im = document.all('flim');
		}
	}else if(document.layers){
		//c = document.layers[kaisou].layers[child];
		c=getelem_ns4(child,document);
		if(macflg) {
		var f = document.layers['fl'];
		var im = document.layers['flim'];
		}
	}
	

	c.style.visibility = "hidden";
	if(macflg) {
		if(!appArray.length){
			if(f){
				f.style.visibility = "visible";
  				im.style.visibility = "hidden";
  			}
		}
	}

}

// ----- Click -----

function at_click()
{

if(document.getElementById){
	p = document.getElementById(this["at_parent"]);
	c = document.getElementById(this["at_child" ]);
}else if(document.all){
	p = document.all(this["at_parent"]);
	c = document.all(this["at_child" ]);
}else if(document.layers){
	//p = document.layers[kaisou].layers[this["at_parent"]];
	//c = document.layers[kaisou].layers[this["at_child" ]];
	p=getelem_ns4(this["at_parent"],document);
	c=getelem_ns4(this["at_child" ],document);
}
if((document.getElementById) || (document.all)){
  if (c.style.visibility != "visible") at_show_aux(p.id, c.id);
  else c.style.visibility = "hidden";
}else if(document.layers){
if (c.visibility != 'show') at_show_aux(p.id, c.id);
  else c.visibility = 'hide';
}
  return false;
}

// ----- Attach -----

// PARAMETERS:
// parent   - id of visible html element
// child    - id of invisible html element that will be dropdowned
// showtype - "click" = you should click the parent to show/hide the child
//            "hover" = you should place the mouse over the parent to show
//                      the child
// position - "x" = the child is displayed to the right of the parent
//            "y" = the child is displayed below the parent
// cursor   - Omit to use default cursor or check any CSS manual for possible
//            values of this field


function at_attach(parent, child, showtype, position, cursor,kaisou)
{
//alert(kaisou);

if(document.getElementById){
	p = document.getElementById(parent);
	c = document.getElementById(child);
	//alert("1");
}else if(document.all){
	p = document.all[parent];
	c = document.all[child];
	//alert("2");
}else if(document.layers){
	if(parent=="nav01"){
		p=document.layers["maindiv"].document.images["hmn1"];
	}
	if(parent=="nav02"){
		p=document.layers["maindiv"].document.images["hmn2"];
	}
	if(parent=="nav03"){
		p=document.layers["maindiv"].document.images["hmn3"];
	}
	if(parent=="nav04"){
		p=document.layers["maindiv"].document.images["hmn4"];
	}
	if(parent=="nav05"){
		p=document.layers["maindiv"].document.images["hmn5"];
	}
	c=document.layers["menudiv"].document.layers[child];

}



  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;
  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  //if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

function getelem_ns4(id,doc){
        if(!doc.layers) return 0;
        for(var i=0;i<doc.layers.length;i++){
                if(doc.layers[i].id==id) return doc.layers[i];
                if(doc.layers[i].document){
                        var t=getelem_ns4(id,doc.layers[i].document);
                        if(t) return t;
                }
        }
        return 0;
}
