// Created 5/26/08, Bugzilla 4838
// ALL CODE IN THIS ROUTINE IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SAVICOM, INC.
// No reproduction or unauthorized use without express written permission

// This file only contains routines called in child navigation IFRAME.
// Other routines accessed by main page included in common.js

// function doMouseOut(evt) -- performs mouse out event for main menu bar -- called in child frame
//		Checks if cursor is outside of currently active menu item and dropdown, and if so, erases dropdown
function doMouseOut(evt) {
	if (activeMenu) {
		if ((! inDropDown(evt)) && (! inMenuBar(evt,activeMenu))) clearDropDown();
	}
}

// function clearDropDown() -- deletes the currently displayed dropdown menu -- called in child frame
function clearDropDown() {
	parent.document.getElementById('d1').style.display = 'none';
	activeMenu='';
}

// function inDropDown() -- check to see if cursor is in dropDown menu -- called in child frame
function inDropDown(evt) {
	var cursor = {x:0, y:0};
	cursor=getPosition(evt);
//alert('cursor x,y: '+cursor.x+','+cursor.y+' origin x,y: '+ddXOrigin+','+ddYOrigin+' size x,y: '+ddXSize+','+ddYSize);
	if ((cursor.x>=(ddXOrigin+ddXSize))||(cursor.y>=(ddYOrigin+ddYSize))||(cursor.x<ddXOrigin)||(cursor.y<(ddYOrigin))) {
		return(false);
	} else {
		return(true);
	}
}

function inMenuBar(evt,menuItem) {
	var cursor = {x:0, y:0};
	cursor=getPosition(evt);
	if ((cursor.x>=mbXOrigin) && (cursor.y>=(mbYOrigin))) {
// alert('cursor x,y: '+cursor.x+','+cursor.y+' origin x,y: '+mbXOrigin+','+mbYOrigin+' size x,y: '+mbXSize+','+mbYSize);
		if ((cursor.x<(mbXOrigin+mbXSize)) && (cursor.y<(mbYOrigin+mbYSize))) return(true);
		else return(false);
	} else return(false);
}

var ddXOrigin=0;
var ddYOrigin=0;
var ddXSize=0;
var ddYSize=0;

var mbXOrigin=0;
var mbYOrigin=0;
var mbXSize=0;
var mbYSize=menuBarHeight+1;

var activeMenu='';

// function doMouseOver(menuItem) -- handles mouseOver event for main menu bar -- called in child frame
//		builds navigation panel in parent's div and turns on visibility
function doMouseOver(menuItem) {
	if ((activeMenu==menuItem)&&(parent.document.getElementById('d1').style.display != 'none')) {
		return(false);
	}
	activeMenu=menuItem;
	
	mbXOrigin=findPosX(document.getElementById(menuItem));
	mbYOrigin=findPosY(document.getElementById(menuItem));
	mbXSize=findWidth(document.getElementById(menuItem));
	
	ddXOrigin=mbXOrigin;
	ddYOrigin=mbYOrigin+menuBarHeight+1;
	eval('ddXSize='+menuItem+'_width;');
	ddXSize+=dropShadow;
	eval('ddYSize='+menuItem+'_menuitems.length;');
	ddYSize=ddYSize*rowHeight+dropShadow;

	writeDropdownHTML(parent.document.getElementById('d1'),menuItem,parent.pathToTop);

	parent.document.getElementById('d1').width = ddXSize + "px";
	parent.document.getElementById('d1').height = ddYSize + "px";
	parent.document.getElementById('d1').style.position = "absolute";
	//parent.document.getElementById('d1').style.zIndex = "50";

	parent.document.getElementById('d1').style.left = ddXOrigin + "px";
	parent.document.getElementById('d1').style.top = ddYOrigin + "px";
	parent.document.getElementById('d1').style.display = 'block';
}

// function writeDropdownHTML(myElement,menuItem,ddPathToTop) -- writes HTML code into parent's <DIV>
//		Called in child frame
function writeDropdownHTML(myElement,menuItem,ddPathToTop) {
	var items=0;
	var i=0;
	var url='';
	var txt='';
	var innerWidth=0;
	var outerWidth=0;
	var newHTML='';
	eval('items='+menuItem+'_menuitems.length;');
	eval('innerWidth='+menuItem+'_width;');
	outerWidth=innerWidth+dropShadow;
	newHTML+='<table width="'+outerWidth+'" border="0" cellspacing="0" cellpadding="0"><tr><td colspan="2" rowspan="2">';
	newHTML+='	<table width="'+innerWidth+'" border="0" cellspacing="0" cellpadding="2" onMouseOut="doMouseOutDD(event,\''+menuItem+'\');">';
	for (i=0; i<items; i++) {
		eval('txt='+menuItem+'_menuitems[i]');
		eval('url='+menuItem+'_urls[i]');
		url=ddPathToTop+url;
		newHTML+='<tr><td class="dropdown">&nbsp;<a href="'+url+'" target="_top" class="dropdown">'+txt+'</a></td></tr>';
	}
	newHTML+='</table></td><td><img src="'+ddPathToTop+'images/dotclear.gif" alt="" width="'+dropShadow+'" height="'+dropShadow+'" border="0"></td></tr>';
	var shortHeight=items*rowHeight-dropShadow;
	newHTML+='<tr><td><img src="'+ddPathToTop+'images/blackpixel.gif" alt="" width="'+dropShadow+'" height="'+shortHeight+'" border="0" class="dropshadow"></td></tr>';
	newHTML+='<tr>';
	var shortWidth=innerWidth-dropShadow;
	newHTML+='<td><img src="'+ddPathToTop+'images/dotclear.gif" alt="" width="'+dropShadow+'" height="'+dropShadow+'" border="0"></td>';
	newHTML+='<td><img src="'+ddPathToTop+'images/blackpixel.gif" alt="" height="'+dropShadow+'" width="'+shortWidth+'" border="0" class="dropshadow"></td>';
	newHTML+='<td><img src="'+ddPathToTop+'images/blackpixel.gif" alt="" width="'+dropShadow+'" height="'+dropShadow+'" border="0" class="dropshadow"></td></tr></table>';
	myElement.innerHTML=newHTML;
}

