﻿function printPage() {
    var agt = navigator.userAgent.toLowerCase(); 
    var is_win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    var is_mac    = (agt.indexOf("mac")!=-1);
    var macos  = (is_mac && ((agt.indexOf("mac os") != -1) || (agt.indexOf("macos") != -1) || this.ie));
    var macosx = (macos && ((agt.indexOf("os x") != -1) || (agt.indexOf("osx") != -1)));

	if(macosx || is_win ){
		window.print();
	} else {
		alert("To print this page, press 'command+P'.")
	}
}

function swapSearchLayer(whichDirection) {
	if (whichDirection == "over") {
		document.getElementById('searchContainer').style.zIndex = 9999;
		document.getElementById('searchListContent').style.zIndex = 999;
		document.getElementById('searchMapContainer').style.zIndex = 999;
		document.getElementById('searchTabs').style.zIndex = 999;
	} else {
		document.getElementById('searchContainer').style.zIndex = 999;
		document.getElementById('searchListContent').style.zIndex = 9999;
		document.getElementById('searchMapContainer').style.zIndex = 9999;
		document.getElementById('searchTabs').style.zIndex = 9999;
	}
}

function toggleResults(whichView) {
	if (whichView == "map") {
		document.getElementById('searchListContent').style.display = 'none';
		document.getElementById('searchMapContainer').style.display = 'block';
		document.getElementById('tab_glo_list').setAttribute("src", "images/tab_glo_list_off.gif");
		document.getElementById('tab_glo_map').setAttribute("src", "images/tab_glo_map_on.gif");
	} else {
		document.getElementById('searchListContent').style.display = 'block';
		document.getElementById('searchMapContainer').style.display = 'none';
		document.getElementById('tab_glo_list').setAttribute("src", "images/tab_glo_list_on.gif");
		document.getElementById('tab_glo_map').setAttribute("src", "images/tab_glo_map_off.gif");
	}
}

function rollover(whichImage, status) {
	if (status)
		document.getElementById(whichImage).setAttribute("src","images/" + whichImage + "_on.gif");
	else
		document.getElementById(whichImage).setAttribute("src","images/" + whichImage + "_off.gif");
}

function showCommuteStart() {
	document.getElementById('ctl00_panelCommuteResults').style.display = 'none';
	document.getElementById('ctl00_panelCommute').style.display = 'block';
}

function showAJAXOverlay(whichOverlay, resetOverlay) {
	boxWidth = 480;
	
	if (whichOverlay == "question")
		boxHeight = 315;
	else if (whichOverlay == "commute")
		boxHeight = 400;
	else
		boxHeight = 340;

	screenWidth = document.all?document.body.clientWidth:window.innerWidth;
	screenHeight = document.all?document.body.clientHeight:window.innerHeight;

	xPos = (screenWidth - boxWidth) * 0.5;
	yPos = (screenHeight - boxHeight) * 0.5;

	document.getElementById(whichOverlay).style.left = xPos + "px";
	document.getElementById(whichOverlay).style.top = yPos + "px";

	document.getElementById('fade').style.display = 'block';
	document.getElementById('fade').style.visibility = 'visible';
	currentOpac('fade', 70, 1000);
	
	verticallyCenter(whichOverlay);
	document.getElementById(whichOverlay).style.visibility = 'visible';
	document.getElementById(resetOverlay).style.display = 'block';
}

function closeAJAXOverlay(whichOverlay, resetOverlay) {
	document.getElementById('fade').style.display = 'none';
	document.getElementById('fade').style.visibility = 'hidden';
	changeOpac(0, 'fade');
	document.getElementById(whichOverlay).style.visibility = 'hidden';
	document.getElementById(resetOverlay).style.display = 'none';
}

function showOverlay(whichOverlay) {
	boxWidth = 680;
	boxHeight = 480;

	screenWidth = document.all?document.body.clientWidth:window.innerWidth;
	screenHeight = document.all?document.body.clientHeight:window.innerHeight;

	xPos = (screenWidth - boxWidth) * 0.5;
	yPos = (screenHeight - boxHeight) * 0.5;

	document.getElementById(whichOverlay).style.left = xPos + "px";
	document.getElementById(whichOverlay).style.top = yPos + "px";

	document.getElementById('fade').style.display = 'block';
	document.getElementById('fade').style.visibility = 'visible';
	currentOpac('fade', 70, 1000);
	
	verticallyCenter(whichOverlay);
	document.getElementById(whichOverlay).style.visibility = 'visible';
}

function closeOverlay(whichOverlay) {
	document.getElementById('fade').style.display = 'none';
	document.getElementById('fade').style.visibility = 'hidden';
	changeOpac(0, 'fade');
	document.getElementById(whichOverlay).style.visibility = 'hidden';
}

function closeSearchOverlays() {
	document.getElementById('fade').style.display = 'none';
	document.getElementById('fade').style.visibility = 'hidden';
	changeOpac(0, 'fade');
	document.getElementById('appointment').style.visibility = 'hidden';
	document.getElementById('ctl00_panelAppointmentThanks').style.display = 'none';
	document.getElementById('ctl00_panelAppointmentError').style.display = 'none';
	document.getElementById('question').style.visibility = 'hidden';
	document.getElementById('ctl00_panelQuestionThanks').style.display = 'none';
	document.getElementById('ctl00_panelQuestionError').style.display = 'none';
	document.getElementById('email').style.visibility = 'hidden';
	document.getElementById('ctl00_ContentPlaceHolder2_panelEmailThanks').style.display = 'none';
	document.getElementById('ctl00_ContentPlaceHolder2_panelEmailError').style.display = 'none';
	document.getElementById('commute').style.visibility = 'hidden';
	document.getElementById('ctl00_panelCommuteResults').style.display = 'none';
	document.getElementById('floorplan').style.visibility = 'hidden';
	document.getElementById('photos').style.visibility = 'hidden';
}

function closeUtilityOverlays() {
	document.getElementById('fade').style.display = 'none';
	document.getElementById('fade').style.visibility = 'hidden';
	changeOpac(0, 'fade');
	document.getElementById('email').style.visibility = 'hidden';
	document.getElementById('ctl00_panelEmailThanks').style.display = 'none';
	document.getElementById('ctl00_panelEmailError').style.display = 'none';
}

function opacity(id, opacStart, opacEnd, millisec) { 
    var speed = Math.round(millisec / 200); 
    var timer = 0; 

    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
}

function currentOpac(id, opacEnd, millisec) { 
    var currentOpac = 0; 
     
    if(document.getElementById(id).style.opacity > 0) { 
        currentOpac = document.getElementById(id).style.opacity * 100; 
    } 

    opacity(id, currentOpac, opacEnd, millisec) 
} 

function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function viewportSize(side) {
	var viewportWidth;
	var viewportHeight;

	// for standards compliant browsers (mozilla/netscape/opera/IE7)     
	if (typeof window.innerWidth != 'undefined') {
		viewportWidth = window.innerWidth,
		viewportHeight = window.innerHeight
	}        
	// IE6 in standards compliant mode (i.e. with a valid doctype)    
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		viewportWidth = document.documentElement.clientWidth,
		viewportHeight = document.documentElement.clientHeight
	}        
	// older versions of IE
	else {
		viewportWidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportHeight = document.getElementsByTagName('body')[0].clientHeight
	}  

	return (side == 'width' ? viewportWidth : viewportHeight);
} 

function verticallyCenter(id) {
	var elementHeight=document.getElementById(id).offsetHeight;
	var elementWidth=document.getElementById(id).offsetWidth;

	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}

	document.getElementById(id).style.top = (viewportSize('height')-elementHeight)/2+ ScrollTop + "px";
	document.getElementById(id).style.left = (viewportSize('width')-elementWidth)/2+"px";        
}