// グローバル変数
var agent = navigator.userAgent.toLowerCase();
var ispc = (agent.indexOf("windows") != -1);
var ismac = (agent.indexOf("mac") != -1);
var gecko = agent.indexOf("gecko") != -1;
var opera = agent.indexOf("opera",0) != -1;
var safari = agent.indexOf("safari") != -1;
var ns = agent.indexOf("netscape") != -1;
var ie = agent.indexOf("msie") != -1 && !opera;
var ie5win = (agent.indexOf("msie 5.0") != -1) && ispc;
var ie55win = (agent.indexOf("msie 5.5") != -1) && ispc;
var ie5mac = (agent.indexOf("msie") != -1) && ismac;

var undefined;
var sBrowser = ((navigator.appName == "Microsoft Internet Explorer") && (navigator.platform == "Win32")) ? "IE" : "nonIE";
// This is a javascript pseudo-class implementation of a stack structure

function Stack(nSize) {
	if (nSize == undefined) nSize = 128;
	this.MAX_SIZE = 1024;
	this.stackPtr = -1;
	this.array = new Array(nSize);
}
new Stack();

function Stack_Push(value) {
	if (this.stackPtr == this.array.length - 2)
		this.resize();
		this.stackPtr++;
		this.array[this.stackPtr] = value;
		return true;
}
Stack.prototype.push = Stack_Push;

function Stack_PushArray(inArray) {
	var i;
	for (i=0; i<inArray.length; i++) {
		this.push(inArray[i]);
	}
}
Stack.prototype.pushArray = Stack_PushArray;

function Stack_Pop() {
	if (this.stackPtr == -1) return false;
	this.stackPtr--;
}
Stack.prototype.pop = Stack_Pop;

function Stack_Top() {
	if (this.stackPtr == -1) return false;
	return this.array[this.stackPtr];
}
Stack.prototype.top = Stack_Top;

function Stack_Resize() {
	var i;
	if (this.array.length > this.MAX_SIZE) {
		alert('Stack Overflow');
	} else {
		var nNewSize = this.array.length * 2;
		var newArray = new Array(nNewSize);
	
		for (i=0; i<this.array.length - 1; i++) {
			newArray[i] = this.array[i];
		}
		delete this.array;
		this.array = newArray;
	}
}
Stack.prototype.resize = Stack_Resize;

function Stack_Size() {
	return this.stackPtr + 1;
}
Stack.prototype.size = Stack_Size;


function changeSel(obj) {
	var val = obj.options[obj.selectedIndex].value
	if (val == "") {
		obj.selectedIndex = 0;
	}else{
		location = val;
	}
}

function WM_preloadImages() {
  if (document.images) {
    if (typeof(document.WM) == 'undefined'){
      document.WM = new Object();
    }
    document.WM.loadedImages = new Array();
    // Loop through all the arguments.
    var argLength = WM_preloadImages.arguments.length;
    for(arg=0;arg<argLength;arg++) {
      // For each arg, create a new image.
      document.WM.loadedImages[arg] = new Image();
      // Then set the source of that image to the current argument.
      document.WM.loadedImages[arg].src = WM_preloadImages.arguments[arg];
    }
  }
}

function WM_imageSwap(daImage, daSrc){
  var objStr,obj;

  if(document.images){
    // Check to see whether you are using a name, number, or object
    if (typeof(daImage) == 'string') {
     
      objStr = 'document.' + daImage;
      obj = eval(objStr);
      obj.src = daSrc;
    } else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
      daImage.src = daSrc;
    }
  }
}

var MenuStack = new Stack();
var nMenuTimeout = 0;
var nTimoutID = 0;
var bTimerOn = false;

function HasChildren(guid) {
	var i=0;
	for (i=0; i<NavItems.size(); i++) {
		NavItem=String(NavItems.array[i]).split(';');
		if (guid==NavItem[1]) return true;
	}
	return false
}


function GetDepth(guid) {
	var i;
	if (guid=="") return -1;
	
	for (i=0; i<NavItems.size(); i++) {
		NavItem=NavItems.array[i].replace(/\&amp;/gi, "&");
		NavItem = NavItem.split(';');
		if (guid==NavItem[0]) {
			return (1 + GetDepth(NavItem[1]));
		}
	}
	return -1;
}

function ShowMenu(obj, guid) {
	var strMenuItems = "";
	var NavItem;
	var nCount = 0;
	var i=0;
	var top = obj.offsetTop;
	var left;
	var offsetParent = obj.offsetParent;
	
	var depth = GetDepth(guid);
	if (depth < MenuStack.size()) {
		HideMenu(depth);
	}	
	
	if (document.all["id_" + guid] == undefined) {
		while (offsetParent != document.body) {
			top += offsetParent.offsetTop;
			offsetParent = offsetParent.offsetParent;
		}
		strMenuItems = "<table cellspacing=0 cellpadding=0 width='100%' class='MenuTable'>"
		for (i=0; i<NavItems.size(); i++) {
			NavItem=NavItems.array[i].replace(/\&amp;/gi, "&");
			NavItem = NavItem.split(';');
			if (guid==NavItem[1]) {
				if (HasChildren(NavItem[0])) {
					if (nCount==0)
						strMenuItems += "<tr><td class='MenuItemFirst' onclick='location=\"" + NavItem[3] + "\"' onmouseout='this.className=\"MenuItemFirst\"' onmouseover='ShowMenu(this,\"" + NavItem[0] + "\"); this.className=\"MenuItemOverFirst\"'>" + NavItem[2] + "</td><td class='MenuItemMoreFirst' onclick='location=\"" + NavItem[3] + "\"' onmouseover='ShowMenu(this,\"" + NavItem[0] + "\")' align='right'><img height='10' width='10' src='img/tri_pullout.gif' /></td></tr>";
					else
						strMenuItems += "<tr><td class='MenuItem' onclick='location=\"" + NavItem[3] + "\"' onmouseout='this.className=\"MenuItem\"' onmouseover='ShowMenu(this,\"" + NavItem[0] + "\"); this.className=\"MenuItemOver\"'>" + NavItem[2] + "</td><td class='MenuItemMore' onclick='location=\"" + NavItem[3] + "\"' onmouseover='ShowMenu(this,\"" + NavItem[0] + "\")' align='right'><img height='10' width='10' src='img/tri_pullout.gif' /></td></tr>";
				} else {
					if (nCount==0)
						strMenuItems += "<tr><td colspan=2 class='MenuItemFirst' onclick='location=\"" + NavItem[3] + "\"' onmouseout='this.className=\"MenuItemFirst\"' onmouseover='HideMenu(" + (MenuStack.size() + 1) + "); this.className=\"MenuItemOverFirst\"'>" + NavItem[2] + "</td></tr>";
					else
						strMenuItems += "<tr><td colspan=2 class='MenuItem' onclick='location=\"" + NavItem[3] + "\"' onmouseout='this.className=\"MenuItem\"' onmouseover='HideMenu(" + (MenuStack.size() + 1) + "); this.className=\"MenuItemOver\"'>" + NavItem[2] + "</td></tr>";
					
				}
				nCount++;
			}
		}
		
		var oDiv = document.createElement("DIV");
		oDiv.id = "id_" + guid;
		oDiv.className = "MenuFrame";
		oDiv.innerHTML = strMenuItems;
		oDiv.onmouseout = StartMenuTimeout;
		oDiv.onmouseover = StopMenuTimeout;
		oDiv.style.top = top;
		
		document.body.appendChild(oDiv);
		if (MenuStack.size() > 0) {
			//var MenuObj = document.all[MenuStack[MenuStack.length - 1]];
			var MenuObj = document.all[MenuStack.top()];
			left = parseInt(MenuObj.style.left) + 170;
			oDiv.style.left = left - 1;
		} else {
			oDiv.style.left = 160;
		}
	}
	else {
		document.all["id_" + guid].style.display = '';
	}
	
	var objTop = parseInt(document.all["id_" + guid].style.top);
	var objHeight = parseInt(document.all["id_" + guid].clientHeight);
	var bodyHeight = parseInt(document.body.clientHeight) + parseInt(document.body.scrollTop);
	if ((bodyHeight - objTop - objHeight < 0)) {
		window.scrollBy(0, -(bodyHeight - objTop - objHeight));
	}

	
	if (!OnStack(guid)) {
		MenuStack.push("id_" + guid);	
		StartMenuTimeout(15);
		}
}

function ScrollIntoView(obj) {

}

function OnStack(guid) {
	var i;
	for (i=0; i<MenuStack.size(); i++) {
		if (MenuStack.array[i] == ("id_" + guid)) return true;
	}
	return false;
}

function StartMenuTimeout(count) {
	if (count==undefined) count=6;
	if (!bTimerOn) {
		nMenuTimeout = count;
		nTimeoutID = window.setInterval("TimeoutMenu()", 150);
		bTimerOn = true;
	}
}

function StopMenuTimeout() {
	if (bTimerOn) {
		window.clearInterval(nTimeoutID);
		bTimerOn = false;
	}
}

function TimeoutMenu() {
	if (nMenuTimeout == 0) {
		HideMenu(0);
		 StopMenuTimeout()
	} else {
		nMenuTimeout--;
	}
}

function HideMenu(depth) {
	while(MenuStack.size() > depth) {
		document.all[MenuStack.top()].style.display='none';
		MenuStack.pop();
	}
}


function ProdFind(strType, strText, strIndex)
{
    if (strIndex == "")
    {
        return;
    }    

    if (strType == "technology")
    {
        document.location = "pageloader.aspx?type=product_finder&stype=technology&text=" + strText + "&id=" + strIndex;
    }
    if (strType == "industry")
    {
        document.location = "pageloader.aspx?type=product_finder&stype=industry&text=" + strText + "&id=" + strIndex;
    }
}

function SubmitSearch()
{
    document.location = "pageloader.aspx?type=search&searchstr=" + document.pageform.searchstr.value;
    return true;
}

function SubmiAdvancedSearch()
{
    var strCat = "";
    if (document.pageform.cat_all.checked)
    {
        strCat += "cat_all=yes&";
    } else {
        strCat += "cat_all=no&";    
    }

    if (document.pageform.cat_prod.checked)
    {
        strCat += "cat_prod=yes&";
    } else {
        strCat += "cat_prod=no&";    
    }
   
    if (document.pageform.cat_press.checked)
    {
        strCat += "cat_press=yes&";
    } else {
        strCat += "cat_press=no&";    
    }

    if (document.pageform.cat_events.checked)
    {
        strCat += "cat_events=yes&";
    } else {
        strCat += "cat_events=no&";    
    }
    
    document.location = "pageloader.aspx?type=search&searchstr=" + document.pageform.searchstr.value + "&" + 
                        strCat + 
                        "orgid=" + document.pageform.orgid[document.pageform.orgid.selectedIndex].value + "&" + 
                        "method=" + document.pageform.method[document.pageform.method.selectedIndex].value + "";
    return true;

}

function PrintIt()
{
    var strLocation = document.location;
    var strURL = strLocation + "&print=yes";
       	
    if (strURL.indexOf('.html') > 0) {
    strURL = strURL.substring(0,strURL.indexOf(".html")) + "~print~yes.html";
  }
    window.open(strURL,'printwin','width=600,height=600,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1');  
    return;
}


function email(name,domain) {
	var undefined
	if (domain == undefined) {
		window.open("mailto:" + name + "@" + "hitachi-koki.com");
	} else {
		window.open("mailto:" + name + "@" + domain);
	}
}

function openWin(url,wname,w,h,scroll){
		if(safari){w += 15;h += 45;}
		if(ispc && ie){w += (scroll)? 16:0;h -= 19;}
		var str = 'width=' + w+ ',height=' + h;
			str += ',location=0,toolbar=0,menubar=0,scrollbars=' + scroll + ',resizable=1';
		swin = window.open(url,wname,'width=' + w + ',height=' + h + str);
		swin.focus();
}

	