/*
Common JavaScript code for "The Denver Tea Room" website.
Copyright 2007 Charles D. Montgomery.
All U.S. and International rights reserved.
*/

var inmenu=false;
var btype="";
var bLeftOffset=0;
var bTopOffset=0;
var bWidthAdj=0;
var tmp=0;
var mPosX=0;
var mPosY=0;
var oldmenu='';
var lastmenu='';
var tglFlag=0;
var x=0,y=0;

	var path=document.URL;
	var fparts=path.split('/');
	var page=fparts[fparts.length - 1];
	if(navigator.appName.indexOf("Netscape")>-1)
	{
		btype="Netscape";
		if (page != 'index.php') {
			bLeftOffset=0; //-73;
		} else {
			bLeftOffset=0; //-50;
		}
		bTopOffset=20;
		bWidthAdj=-7;
	} else if((navigator.appName.indexOf("Microsoft")>-1) || (navigator.appName.indexOf("MSIE")>-1)) {
		btype="Microsoft Internet Explorer";
		if (page != 'index.php') {
			bLeftOffset=-73;
		} else {
			bLeftOffset=-50;
		}
		bTopOffset=20;
		bWidthAdj=-10;
	} else if(navigator.appName.indexOf("Opera")>-1) {
		btype="Opera";
		if (page != 'index.php') {
			bLeftOffset=-73;
		} else {
			bLeftOffset=-50;
		}
		bTopOffset=20;
		bWidthAdj=-10;
	} else {
		make="unknown";
	}

	var svcoffsettophp = 80;
	var infooffsettophp = 105;
	var svcoffsetlefthp = 608;
	var infooffsetlefthp = 610;

	var svcoffsettop = 35;
	var infooffsettop = 35;
	var svcoffsetleft = 648;
	var infooffsetleft = 705;
	var loc=document.URL;
	if (loc.indexOf('/articles') > -1) {
		svcoffsetleft+=6;
		infooffsetleft+=6;
	}
	
function Menu(current) {
    if (!document.getElementById) return;
	x=0;y=0;
    getAnchorPosition('menu-' + current);
	var adj=0;
	//adjustments for precision box alignment	
    inmenu=true;
    oldmenu=lastmenu;
    lastmenu=current;
    if (oldmenu) Erase(oldmenu);

    box=document.getElementById('menu-' + current);
	if ((loc.indexOf('index.php') > -1 && loc.indexOf('articles') < 1) || loc.indexOf('.php') < 1) {
		if (current == "services") {
			box.style.left = svcoffsetlefthp;
			box.style.top = svcoffsettophp;
		} else {
			box.style.left = infooffsetlefthp;
			box.style.top = infooffsettophp;
		}
	} else {
		if (current == "services") {
			box.style.left = svcoffsetleft;
			box.style.top = svcoffsettop;
		} else {
			box.style.left = infooffsetleft;
			box.style.top = infooffsettop;
		}
	}
    box.style.visibility="visible";
    box.style.backgroundColor="AliceBlue";
    tmp = '100px'; //bWidthAdj + "px";
}
function Erase(current) {
   if (!document.getElementById) return;
   if (inmenu && lastmenu==current) {
	  return;
   }
   box=document.getElementById('menu-' + current);
   box.style.visibility="hidden";
}
function ForceErase(current) {
   box=document.getElementById('menu-' + current);
   box.style.visibility="hidden";
}
function Timeout(current) {
   inmenu=false;
   window.setTimeout("Erase('" + current + "');",100);
}
function Highlight(menu,item) {
   if (!document.getElementById) return;
   inmenu=true;
   lastmenu=menu;
   obj=document.getElementById(item);
   obj.style.backgroundColor="AliceBlue";
}
function UnHighlight(menu,item) {
   if (!document.getElementById) return;
   Timeout(menu);
   obj=document.getElementById(item);
   obj.style.backgroundColor="AliceBlue";
}


function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	mPosX=x;
	mPosY=y;

	}
// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
	
		
	var search = 'genalert=';
	var CookieString = document.cookie;
	var result = '';
	var i=0;
	var slcnt=0;
	var tmp=document.URL;
	for (i = 8; i < tmp.length;i++)
	{
		if (tmp.charAt(i) == "/") slcnt++;
	}
	//Setup a default referral message
	var emailText='';
	emailText='mailto:?subject=Web page of interest\&body=I found the following web page titled: ' + document.title + ' - and thought you might be interested in what it says. The page is located at: ' + document.URL;

	if (CookieString.length > 0) { 
	    offset = CookieString.indexOf(search);
	    if (offset != -1) { 
	        offset += search.length;
	        end = CookieString.indexOf(';', offset);
	        if (end == -1) {
	           end = CookieString.length };
	        result = unescape(CookieString.substring(offset, end)); 
	   } 
	}
	var showIt = 'hidden';
	if (!msgPresent)
		var msgPresent='NO';
		
	if (result=='')
	{
		if (msgPresent == 'YES')
		{
			showIt = 'visible';
		}
	}
	//(Inline) Set a cookie

    var futuredate = new Date();		//Get the current time and date
    var expdate = futuredate.getTime();  //Get the milliseconds since Jan 1, 1970
    expdate += 3600*1000;  //expires in 1 hour(milliseconds)
    futuredate.setTime(expdate);
    var newCookie='genalert=Set; path=/;';	//Set the new cookie values up
    newCookie += ' expires=' + futuredate.toGMTString(); //expire it in a hour or so
    window.document.cookie=newCookie; //Write the cookie

/* On page load the following is fall-through code that will always be executed
   This code binds similar event handlers to this page. This eliminates one
   setup step. Specifically, there is no need for an installer to include a
   "onload=..." statement in the <body tag.
*/
if (window.addEventListener) {
	window.addEventListener("load",adjDspFrame,false);
} else {
    window.attachEvent("onload", adjDspFrame);
}

function SetDspFrameSize(id) {
    var DspFrame = document.getElementById(id);
    if (DspFrame) {
        if (DspFrame.contentDocument && DspFrame.contentDocument.body.offsetHeight) {
            // FireFox, Mozilla, et. al. (W3C) syntax
            DspFrame.height = DspFrame.contentDocument.body.offsetHeight;    
        } else { //if (DspFrame.Document && DspFrame.Document.body.scrollHeight) {
            // MSIE syntax
            DspFrame.height = DspFrame.Document.body.scrollHeight;
        }
		/* For FF/NS class browsers (and possibly others) add some additional height
		to kill off the vertical scroll bar (shows up even if SCROLLING="NO"; go figure...)
		The next line casts the string to an integer, which may or may not be adjusted. */		
		var adj=DspFrame.height / 1; 
		if (!document.all)     /* Returns TRUE unless MSIE (inverted logic)*/
			adj+=40; 	       /* For any browser other than MSIE add 16 pixels to the height. Even
							      if it turns out that we end up overadjusting for a few browsers,
							      the likelihood that 16 pixels of space will cause a problem is
							      pretty remote. */
		DspFrame.height = adj;
		if (DspFrame.addEventListener) {
            DspFrame.addEventListener("load", adjDspFrame, false);
        } else {
			DspFrame.detachEvent("onload", adjDspFrame); //MSIE needs hand-holding...
            DspFrame.attachEvent("onload", adjDspFrame);
        }
   }
}
function adjDspFrame(evt) { //retaining the event (evt) for possible future expansion; not used
	SetDspFrameSize('DisplayFrame');
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
	var winW = (window.innerWidth) ? window.innerWidth : document.body.offsetWidth;
	var rLeft = (winW - rtpWidth) / 2;
	rTop = document.body.scrollTop + (rtpHeight * VerticalOffset);
    if(document.layers) {	   					//NN4+
		var layer = document.layers[szDivID];
    	layer.top = rTop;
		layer.left = rLeft;
		document.layers[szDivID].visibility = iState ? "show" : "hide";
    } else if(document.getElementById)	{  		//gecko(NN6) + IE 5+ 
        var layer = document.getElementById(szDivID);
		layer.style.top = rTop;
		layer.style.left = rLeft;
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    } else if(document.all)	{ 					// IE 4
		document.all[szDivID].style.posLeft = rLeft;
		document.all[szDivID].style.posTop = rTop;
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
var tglFlag=0;
function ToggleBkg(cell)
{
   box=document.getElementById(cell);
   if (tglFlag == 0)
   	{
		tglFlag=1;
		box.style.backgroundColor="#F4FFF4";
	} else {
		tglFlag=0;
		box.style.backgroundColor="";
	}
}

function SetFrame(turl) {
	var url=document.URL;
	var parts=url.split('/');
	var nurl = parts[0] + '//' + parts[2];
	if (parts[2] == 'cdmx') {
		nurl += '/job';
	}
	document.getElementById('DisplayFrame').src=nurl + '/' + turl;
	document.location.href="#frmtop";

}

/* Driver for Drop out menu lists
   Copyright 2007, Charles D. Montgomery */

var lastID='';
function kudos(id) {
	var ua = window.navigator.userAgent;
	var msie = ua.indexOf ( "MSIE " );
	var dspType='table-cell';
	if ( msie > 0 )      // If Internet Explorer, use this
		dspType='inline';  	
	/* must identify each cell uniquely (e.g. add a "t" for each different cell like: ttt1)
	   In general:
	       t1 === the cell id where the testimonial appears
		   tt1 === the "spacer" cell on the same row in the table
		   ttt1 === the <a href id=ttt<n> 
	*/
	if (lastID != '') {
		document.getElementById(lastID).style.display = 'none';
		document.getElementById(lastID + 'I').innerHTML='<p align="right"><a href=javascript:kudos(\'' + lastID + '\');><img border="0" src="images/' + lastID + '-on.jpg" width="188" height="30"></a>';
	}
	if (id != lastID) {
		document.getElementById(id).style.display=dspType;
		document.getElementById(id + 'I').innerHTML='<p align="right"><a href=javascript:kudos(\'' + id + '\');><img border="0" src="images/' + id + '-off.jpg" width="188" height="30"></a>';
		lastID = id;
	}  else {
		lastID='';
	}
	var a = lastID; //for testing
}
/* To open the first testimonial item on page load, put the following
   snippet at the BOTTOM of the page; just before </body>:
   
<script language="javascript"><!--
kudos('t1');
//--></script>


function changeScreenSize() {
	if (screen.width > 1024) 
	    window.resizeTo( 1024, 768 )
}
if (window.addEventListener) {
	window.addEventListener("load",changeScreenSize,false);
	window.addEventListener("resize",changeScreenSize,false);
} else {
    document.attachEvent("onload", changeScreenSize());
    document.attachEvent("onResize", changeScreenSize());
}
changeScreenSize();
*/
