// JScript File
var gctWindow = null;
var gctCallBack = null;
var gctIsCallBack = null;
var gctOverlay = null;
var GCTWindow = new GCTWINDOW();
var IsEffect = 'true';
var GCTAutoScroll = false;
function GCTWINDOW ()
{
 this.open = OpenWindow;
 this.close = closeGCTWindow ;
 this.customOpen = OpenCustomWindow;
 this.noEffect = function() { IsEffect = 'false'};
 this.SetPosition = ReposGCTWindow;
 this.setBounds = setHeightWidth;
 this.fromScrollTop = false;
}

function setHeightWidth(height, width)
{
	var gctwin = document.getElementById("GCTWINDOW");
	gctwin.style.height = height + "px";
	gctwin.style.width = width + "px";
	 var Pagesize = getPageSize();
	var top = (Pagesize.height - height)/2 + Pagesize.scrollTop;
	if(top >= 0)  gctwin.style.top = top  + 'px';
    else   gctwin.style.top = '0px';
    gctwin.style.left = (Pagesize.width - width)/2 + 'px';
	height -= 18;
	document.getElementById('GCTIFrame').style.height = height + 'px';
	document.getElementById('GCTIFrame').style.width = width + 'px';
}

function OpenWindow (url,title,width,height,modal) 
{
    var Pagesize = getPageSize();
    var gctOver = null;
    var gctwin = null;
    if (document.getElementById('GCTOVERLAY') == null)
    {
        gctOver = document.createElement('div');
        document.body.appendChild(gctOver);
        gctwin = document.createElement('div');
        document.body.appendChild(gctwin);
        
        gctOver.setAttribute('id','GCTOVERLAY');	
        gctwin.setAttribute('id','GCTWINDOW');
        gctOver.style.position = 'absolute';
        gctOver.style.zindex = 3001;
        gctwin.style.position = 'absolute';
        gctwin.style.zindex = 3002;
        gctwin.style.opacity = 0;
        gctwin.style.MozOpacity = 0;
        gctwin.style.KhtmlOpacity = 0;
        gctwin.style.filter = "alpha(opacity=0)";
        gctOver.style.left = '0px';
        gctOver.style.top = '0px';    
        gctOver.style.opacity = 0;
        gctOver.style.MozOpacity = 0;
        gctOver.style.KhtmlOpacity = 0;
        gctOver.style.filter = "alpha(opacity=0)";
    
    }
    else
    {
      gctOver = document.getElementById('GCTOVERLAY');
      gctwin = document.getElementById('GCTWINDOW');
    }
	    gctOver.className = 'GctOverlay';
        gctwin.className = 'GctWindow';
    gctWindow = 'GCTWINDOW';
    gctOverlay = 'GCTOVERLAY'; 
    gctwin.style.width = width + 'px';
    gctwin.style.height = height + 'px';
    
    if(modal == 'True' || modal == 'true' )
    {
    gctOver.style.display = '';
   
    opacity(gctOverlay ,0,50,0);
    if(document.body.offsetHeight > window.screen.height)
    gctOver.style.height = document.body.offsetHeight + 'px';
    else
    gctOver.style.height =  window.screen.height + 'px';
    
    gctOver.style.height = Pagesize.pageHeight + "px";

    if(document.body.offsetWidth > window.screen.width)
     gctOver.style.width = document.body.offsetWidth + 'px';
    else
     gctOver.style.width =  window.screen.width - 23 + 'px';
    } 
    //gctOver.innerHTML += "<!--[if lte IE 6.5]><iframe class='GCTMask'></iframe><![endif]-->";
	gctwin.style.display = '';  
	var top = (Pagesize.height - height)/2 + Pagesize.scrollTop;
	if(GCTWindow.fromScrollTop) top = Pagesize.scrollTop;
	if(top >= 0)
    gctwin.style.top = top  + 'px';
    else
    gctwin.style.top = '0px';
    gctwin.style.left = (Pagesize.width - width)/2 + 'px';

   	height -= 18;
	gctwin.innerHTML = "<div  class='GctTitleRow' ><span unselectable='on' class='GctTitle'>" + title +"</span><span id='btnclose' class='GctClose' unselectable='on' onClick='closeGCTWindow();'><b>Close</b></span></div><iframe id='GCTIFrame' class='GctWindowFrame' height='" + height + "' width='" + width + "' frameborder='0'  />";
	opacity(gctWindow ,0,100,1000);
	document.getElementById('GCTIFrame').src = url;
	if(GCTAutoScroll) window.scrollTo(0,0);
}
var fireFox = navigator.userAgent.indexOf("Firefox")>-1;
var LocFire =  location.href;
function OpenCustomWindow (htm,title,width,height,modal) 
{
    
    var LocCal = LocFire.indexOf("EventCalender/scheduler.aspx?")>-1; 
    var GctCalWin = htm.indexOf("GctCalenderWindow")>-1;
    var gctOver = null;
    var gctwin = null;
   if (document.getElementById('GCTOVERLAY') == null)
    {
        gctOver = document.createElement('div');
        document.body.appendChild(gctOver);
        gctwin = document.createElement('div');
        document.body.appendChild(gctwin);
        gctOver.setAttribute('id','GCTOVERLAY');
        gctwin.setAttribute('id','GCTWINDOW');
        gctOver.style.position = 'absolute';
        gctOver.style.zindex = 3001;
        gctwin.style.position = 'absolute';
        gctwin.style.zindex = 3002;
        gctwin.style.opacity = 0;
        gctwin.style.MozOpacity = 0;
        gctwin.style.KhtmlOpacity = 0;
        gctwin.style.filter = "alpha(opacity=0)";
        gctOver.style.left = '0px';
        gctOver.style.top = '0px';    
        gctOver.style.opacity = 0;
        gctOver.style.MozOpacity = 0;
        gctOver.style.KhtmlOpacity = 0;
        gctOver.style.filter = "alpha(opacity=0)";
    }
    else
    {
      gctOver = document.getElementById('GCTOVERLAY');
      gctwin = document.getElementById('GCTWINDOW');
    }
	  gctOver.className = 'GctOverlay';
        gctwin.className = 'GctWindow';
    gctWindow = 'GCTWINDOW';
    gctOverlay = 'GCTOVERLAY';  
    if(modal == 'True' || modal == 'true')
    {
    gctOver.style.display = '';
     if(IsEffect == 'true') 
    opacity(gctOverlay ,0,70,0);
    else
	{
	var object = document.getElementById(gctOverlay).style; 
	object.opacity = (100 / 100);
	object.MozOpacity = (100 / 100);
	object.KhtmlOpacity = (100 / 100);
	object.filter = "alpha(opacity=" + 100 + ")";
	}
    if(document.body.offsetHeight > window.screen.height)
     gctOver.style.height = document.body.offsetHeight + 'px';
    else
     gctOver.style.height =  window.screen.height + 'px';
   //  gctOver.style.height = document.body.scrollHeight + "px";

    if(document.body.offsetWidth > window.screen.width)
     gctOver.style.width = document.body.offsetWidth + 'px';
    else
     gctOver.style.width =  window.screen.width - 23 + 'px';
    } 
    gctOver.innerHTML += "<!--[if lte IE 6.5]><iframe class='GCTMask'></iframe><![endif]-->";
	gctwin.style.display = '';
	gctwin.innerHTML = "<div  class='GctTitleRow' ><span unselectable='on' class='GctTitle'>" + title +"</span><span class='GctClose' unselectable='on' onClick='closeWindow();'><b>Close</b></span></div>" + htm;
	gctwin.style.width = width + 'px';
    gctwin.style.height = height + 'px'; 
    if(fireFox && LocFire && GctCalWin)
    {
    window.scrollTo(0,0);
    gctwin.style.top = ((window.screen.height - height)/4) - 10 + 'px';
    gctwin.style.left = ((document.body.clientWidth - width  )/3) + 150 + 'px';
    }
    else{ 
	gctwin.style.top = (window.screen.height - height)/3 + 'px';
    gctwin.style.left = (document.body.clientWidth - width  )/2 + 'px';}
	 if(IsEffect == 'true') 
	opacity(gctWindow ,0,100,1000);
	else
	{
	var object = document.getElementById(gctWindow).style; 
	object.opacity = (100 / 100);
	object.MozOpacity = (100 / 100);
	object.KhtmlOpacity = (100 / 100);
	object.filter = "alpha(opacity=" + 100 + ")";
	}
	if(GCTAutoScroll) window.scrollTo(0,0);
}

function ReposGCTWindow(left,top)
{
    var gctwin = document.getElementById(gctWindow);
    gctwin.style.top = top + 'px';
    gctwin.style.left = left + 'px';
} 

function closeGCTWindow(callbackfunction)
{
   if(gctWindow != null)
   {
    if(IsEffect == 'true') 
    {
   opacity(gctOverlay,50,0,2000);
   opacity(gctWindow,100,0,1000);
   }
    else
    {
    document.getElementById(gctOverlay).style.display = 'none';
    document.getElementById(gctWindow).style.display = 'none';    
    }
   }
	ReloadPage();
   if(callbackfunction != null && callbackfunction != '')
   eval(callbackfunction + "();");
   
}
  
function opacity(id, opacStart, opacEnd, millisec) 
{
	var speed = Math.round(millisec / 100);
	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++;		}	}
	
}
 var ov = 'false';
 var op = 'false';
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 + ")";
	
    if (id == gctOverlay && ov == 'true' && opacity == 0)    {   
        document.getElementById(gctOverlay).style.display = 'none';
	  ov = 'mid';     }
    if (id == gctWindow && op == 'true' && opacity == 0)    {   
        document.getElementById(gctWindow).style.display = 'none';
	  op = 'mid';    }
    if (id == gctWindow && op != 'mid')    {    op = 'true';   }
    else if(id == gctWindow && op == 'mid') { op ='false'; } 
    if (id == gctOverlay && ov != 'mid')    {    ov = 'true';   }
    else if(id == gctOverlay && ov == 'mid') { ov ='false'; } 
}



function SubmitSearch()
{
        window.parent.SubmitPage(window); 
}

function CloseWind()   
{  
    window.parent.GCTWindow.close(''); 
} 
  
var ie = navigator.userAgent.indexOf("MSIE")>-1;
var ie7 = navigator.userAgent.indexOf("MSIE 7")>-1;
var safari = navigator.userAgent.indexOf("Safari")>-1;
var macintosh = navigator.userAgent.indexOf("Macintosh")>-1;
var fireFox = navigator.userAgent.indexOf("Firefox")>-1;

 function getPageSize() 
 {
	var iebody = document.compatMode && document.compatMode != "BackCompat" 
		? document.documentElement : document.body;	
	var b = document.body;
	var xScroll = (window.innerWidth && window.scrollMaxX) 
			? window.innerWidth + window.scrollMaxX :
				(b.scrollWidth > b.offsetWidth ? b.scrollWidth : b.offsetWidth),
		yScroll = (window.innerHeight && window.scrollMaxY) 
			? window.innerHeight + window.scrollMaxY :
				(b.scrollHeight > b.offsetHeight ? b.scrollHeight : b.offsetHeight),
		pageWidth = ie ? iebody.scrollWidth :
			(document.documentElement.clientWidth || self.innerWidth);
      	pageHeight = ie? iebody.clientHeight : 
			(document.documentElement.clientHeight || self.innerHeight);
	
	var width = ie ? iebody.clientWidth : 
			(document.documentElement.clientWidth || self.innerWidth),
		height = ie ? iebody.clientHeight : self.innerHeight;
	
	return {
		pageWidth: xScroll < pageWidth ? pageWidth : xScroll,
		pageHeight: yScroll < pageHeight ? pageHeight : yScroll,
		width: width,
		height: height,		
		scrollLeft: ie ? iebody.scrollLeft : pageXOffset,
		scrollTop:  ie ? iebody.scrollTop : pageYOffset
	    }
}    
     
function openWindow()
{
	var pos	= getPageSize();
	var objOverlay = document.getElementById("myWindowOverlay").style;
	objOverlay.opacity = .5;
    objOverlay.MozOpacity = .5;
    objOverlay.KhtmlOpacity = .5;
	objOverlay.filter = "alpha(opacity=50)"
	objOverlay.height = pos.pageHeight + "px";
	objOverlay.width = pos.width + "px";
	objOverlay.display = "";
	var obj = document.getElementById("myWindow").style;
	obj.left = (pos.width - 500)/2 + 'px';
	obj.top =  (pos.height - 530)/2 + pos.scrollTop + 'px';
	obj.display = "";
	initialize();
}
function closeWindows()
{
	document.getElementById("myWindowOverlay").style.display = "none";
	document.getElementById("myWindow").style.display = "none";
}

var map = null;
var geocoder = null;
var strAddress = '';
var strPopupSring = '';
function initialize() 
{
    if (GBrowserIsCompatible()) 
    {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    geocoder = new GClientGeocoder();
    showAddress(strAddress);
    }
}

function listen(evnt, elem, func)
{
	if (elem.addEventListener)  // W3C DOM
		elem.addEventListener(evnt,func,false);
	else if (elem.attachEvent) 
	{ // IE DOM
		var r = elem.attachEvent("on"+evnt, func);
	return r;
	}
	else window.alert('listen function not working');
}

function showAddress(address) {
    if (geocoder) {
    geocoder.getLatLng(
        address,
        function(point) {
        if (!point) {
            alert(address + "- Google API unable to find this address");
        } else {
            map.setCenter(point, 13);
            var marker = new createMarker(point,strPopupSring);
            map.addOverlay(marker);
            marker.openInfoWindowHtml(strPopupSring);
        }
        }
    );
    }
}

function createMarker(point, number) 
{
    var marker = new GMarker(point);
    var html = number;    
    GEvent.addListener(marker, "mouseover", function() { marker.openInfoWindowHtml(html); } );    
    return marker;
}