// JavaScript Document

var d=document;

function e(id)
{
	return document.getElementById(id);
}

function diffMonths(date1,date2)
{
	/* Return the number of months including the range of two date objects. */
	if(date1>date2)
	{
		var temp=date1;
		
		date1=date2;
		
		date2=temp;
	}
	else if(date1==date2)
	{
		return 1;
	}
	
	var numMonths=(date2.getFullYear()-date1.getFullYear()-1)*12;
	
	numMonths+=12-date1.getMonth();

	numMonths+=date2.getMonth()+1;
	
	return numMonths;
}

function verifyIP(IPvalue)
{
	errorString = "";
	theName = "IP Address";

	var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var ipArray = IPvalue.match(ipPattern);

	if (IPvalue == "0.0.0.0")
		errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	else if (IPvalue == "255.255.255.255")
		errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	if (ipArray == null)
		errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
	else {
		for (i = 0; i < 4; i++) {
			thisSegment = ipArray[i];
			if (thisSegment > 255) {
				errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
				i = 4;
			}
			if ((i == 0) && (thisSegment > 255)) {
				errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
				i = 4;
			}
		}
	}
	extensionLength = 3;
	
	if(errorString=="")
	{
		return true;
	}
	else
	{
		alert (errorString);
		
		return false;
	}
}

function createSpanLink(text,onclick,onmouseover,onmouseout)
{
	return'<span class="spanLink" onclick="'+onclick+'" onmouseover="this.className=\'spanLink_Hover\';'+onmouseover+'" onmouseout="this.className=\'spanLink\';'+onmouseout+'">'+text+'</span>';
}

function createSpanLink2(text,onclick)
{
	var element=document.createElement('span');
	
	element.className='spanLink';
	
	element.innerHTML=text;
	
	if(element.addEventListener)
	{
		element.addEventListener('click',onclick,false);
		element.addEventListener('mouseover',function(){element.className='spanLink_Hover';},false);
		element.addEventListener('mouseout',function(){element.className='spanLink';},false);
	}
	else if(element.attachEvent)
	{
		element.attachEvent('onclick',onclick);
		element.attachEvent('onmouseover',function(){element.className='spanLink_Hover';});
		element.attachEvent('onmouseout',function(){element.className='spanLink';});
	}
	
	return element;
}

function createSpanLink3(text,onclick,onmouseover,onmouseout)
{
	var element=document.createElement('span');
	
	element.className='spanLink';
	
	element.innerHTML=text;
	
	if(element.addEventListener)
	{
		element.addEventListener('click',onclick,false);
		element.addEventListener('mouseover',function(){element.className='spanLink_Hover';onmouseover();},false);
		element.addEventListener('mouseout',function(){element.className='spanLink';onmouseout();},false);
	}
	else if(element.attachEvent)
	{
		element.attachEvent('onclick',onclick);
		element.attachEvent('onmouseover',function(){element.className='spanLink_Hover';onmouseover();});
		element.attachEvent('onmouseout',function(){element.className='spanLink';onmouseout();});
	}
	
	return element;
}

function createSpanText(text)
{
	var element=document.createElement('span');
	
	element.innerHTML=text;
	
	return element;
}

function Panel()
{
}

Panel.prototype.getMaxWidth=function()
{
	var width;

	if(d.getElementById)
	{
		if(d.documentElement&&d.documentElement.clientWidth)
		{
			width=d.documentElement.clientWidth;
		}
		else
		{
			width=(d.all)?d.body.clientWidth:window.innerWidth;
		}
	}
	else if(d.layers)
	{
		width=window.innerWidth;
	}
	
	return width;
}

Panel.prototype.getMaxHeight=function()
{
	var height;
	
	if(d.getElementById)
	{
		if(d.documentElement&&d.documentElement.clientHeight)
		{
			height=d.documentElement.clientHeight;
		}
		else
		{
			height=(d.all)?d.body.clientHeight:window.innerHeight;
		}
	}
	else if(d.layers)
	{
		height=window.innerHeight;
	}
	
	return height;
}

Panel.prototype.dimToNum=function(dim)
{
	return Number(dim.replace('px',''));
}

function RPCObj()
{
	this.busy=false;

	this.iframeObj=document.createElement('iframe');
	
	this.iframeObj.style.width='0px';
	
	this.iframeObj.style.height='0px';
	
	document.body.appendChild(this.iframeObj);
	
	var thisObj=this;

	if(this.iframeObj.addEventListener)
	{
		this.iframeObj.addEventListener('load',function()
		{
			if(thisObj.isBusy())
			{
				thisObj.completeCall();
			}
		},false);
	}
	else if(this.iframeObj.attachEvent)
	{
		this.iframeObj.attachEvent('onload',function()
		{
			if(thisObj.isBusy())
			{
				thisObj.completeCall();
			}
		});
	}
}

RPCObj.prototype.removeElement=function()
{
	var element=this.iframeObj;
	
	setTimeout(function(){document.body.removeChild(element);},1);
}

RPCObj.prototype.getIFrame=function()
{
	return this.iframeObj;
}

RPCObj.prototype.getElementById=function(id)
{
	return this.iframeObj.contentWindow.document.getElementById(id);
}

RPCObj.prototype.call=function(URL,functionPointer)
{
	this.busy=true;
	
	this.functionPointer=functionPointer;
	
	this.iframeObj.contentWindow.document.location.replace(URL);
}

RPCObj.prototype.completeCall=function()
{
	this.busy=false;
	
	this.functionPointer();
}

RPCObj.prototype.isBusy=function()
{
	return this.busy;
}

function OverMapWindow(className_Header,className_Body,mapPanel)
{
	var thisObj=this;

	this.div_Header=document.createElement('div');
	
	this.div_Header_Title=document.createElement('div');
	
	this.div_Header_CloseButton_Holder=document.createElement('div');
	
	this.span_Header_CloseButton_Button=createSpanLink2('Close [x]',function(){thisObj.hide();});
	
	this.div_Body=document.createElement('div');
	
	this.div_Header_Title.style.position='absolute';
	
	this.div_Header_CloseButton_Holder.style.textAlign='right';

	this.div_Header.className=className_Header;
	
	this.div_Body.className=className_Body;
	
	document.body.appendChild(this.div_Header);
	
	document.body.appendChild(this.div_Body);
	
	this.div_Header.appendChild(this.div_Header_Title);
	
	this.div_Header.appendChild(this.div_Header_CloseButton_Holder);
	
	this.div_Header_CloseButton_Holder.appendChild(this.span_Header_CloseButton_Button);
	
	this.mapPanel=mapPanel;
	
	if(window.addEventListener)
	{
		window.addEventListener('resize',function(){thisObj.resize();},false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent('onresize',function(){thisObj.resize();});
	}
	
	this.resize();
}

OverMapWindow.prototype=new Panel();

OverMapWindow.prototype.getForm=function(formName)
{
	var thisObj=this;
	
	var functionPointer=function()
	{
		thisObj.show(formName,this.getIFrame().contentWindow.document.getElementById('formHolder').innerHTML);
		
		this.removeElement();
	}
	
	var RPC=new RPCObj();
	
	switch(formName)
	{
		case'Add Station':
			RPC.call('getForm.php?heading='+formName+'&body=addStation',functionPointer);
		break;
		case'Add Online Station':
			RPC.call('getForm.php?heading='+formName+'&body=addOnlineStationForm',functionPointer);
		break;
		case'Add Offline Station':
			RPC.call('getForm.php?heading='+formName+'&body=addOfflineStationForm',functionPointer);
		break;
		case'Remove Station':
			RPC.call('getForm.php?heading='+formName+'&body=removeStation',functionPointer);
		break;
		case'Change Station Status':
			RPC.call('getForm.php?heading='+formName+'&body=changeStationStatus',functionPointer);
		break;
		case'Station Settings':
			RPC.call('getForm.php?heading='+formName+'&body=stationSettings',functionPointer);
		break;
	}
}

OverMapWindow.prototype.resize=function()
{
	/* Resize header div. */
	this.div_Header.style.left=(this.dimToNum(this.mapPanel.div.style.left)+10)+'px';

	this.div_Header.style.top=(this.dimToNum(this.mapPanel.div.style.top)+10)+'px';
	
	if(this.dimToNum(this.mapPanel.div.style.width)-50>=0)
	{
		this.div_Header.style.width=(this.dimToNum(this.mapPanel.div.style.width)-50)+'px';
	}
	
	/* Resize body div. */
	this.div_Body.style.left=(this.dimToNum(this.mapPanel.div.style.left)+10)+'px';

	this.div_Body.style.top=(this.dimToNum(this.mapPanel.div.style.top)+10+50)+'px';
	
	if(this.dimToNum(this.mapPanel.div.style.width)-20-5*2-20>=0)
	{
		this.div_Body.style.width=(this.dimToNum(this.mapPanel.div.style.width)-20-5*2-20)+'px';
	}
	
	if(this.dimToNum(this.mapPanel.div.style.height)-20-50-5-20>=0)
	{
		this.div_Body.style.height=(this.dimToNum(this.mapPanel.div.style.height)-20-50-5-20)+'px';
	}
}

OverMapWindow.prototype.show=function(windowTitle,windowBody)
{
	this.div_Header_Title.innerHTML=windowTitle;
	
	this.div_Body.innerHTML=windowBody;
	
	this.div_Header.style.display='block';
	this.div_Body.style.display='block';
}

OverMapWindow.prototype.hide=function()
{
	this.div_Header.style.display='none';
	this.div_Body.style.display='none';
}

function PreviewWindow(){}

PreviewWindow.prototype=new Panel();

PreviewWindow.prototype.setWH=function(w,h)
{
	if(this.YUIPanel)
	{
		var maxW=this.getMaxWidth();
		var maxH=this.getMaxHeight();
		
		// Adjust w and h if the panel will be too big.
		if(maxW-60<w+20)
		{
			w=maxW-80;
		}
		if(maxH-60<h+45)
		{
			h=maxH-105;
		}
		
		// Adjust the content holder.
		this.contentHolder.style.width=w+'px';
		this.contentHolder.style.height=h+'px';
		
		// Adjust the panel to fit the content holder.
		// 20 and 45 may change with the css properties of the panel.
		this.YUIPanel.cfg.setProperty('width',w+20+'px');
		this.YUIPanel.cfg.setProperty('height',h+45+'px');
		
		this.YUIPanel.center();
	}
}

PreviewWindow.prototype.setW=function(w)
{
	if(this.YUIPanel)
	{
		var maxW=this.getMaxWidth();
		
		// Add code to adjust w if the panel will be too big.
		
		// Adjust the content holder.
		this.contentHolder.style.width=w+'px';
		
		// Adjust the panel to fit the content holder.
		// 20 may change with the css properties of the panel.
		this.YUIPanel.cfg.setProperty('width',w+20+'px');
		
		this.YUIPanel.center();
	}
}

PreviewWindow.prototype.show=function(headerEl,bodyEl)
{
	if(!this.YUIPanel)
	{
		this.contentHolder=document.createElement('div');
		
		this.contentHolder.className='previewWindowContentHolder';
		
		this.contentHolder.appendChild(bodyEl);
		
		this.elementID='previewWindow_1';
		
		var counter=2;
		
		while(document.getElementById(this.elementID))
		{
			this.elementID='previewWindow_'+counter;
			
			counter++;
		}
		
		this.YUIPanel=new YAHOO.widget.Panel(this.elementID,{
			modal:false,
			constraintoviewport:true,
			draggable:true
		});
		
		this.YUIPanel.setHeader(headerEl);
		
		this.YUIPanel.setBody(this.contentHolder);
	
		this.YUIPanel.render(document.body);
		
		var oThis=this;
		
		this.YUIPanel.hideEvent.subscribe(
			function()
			{
				// Find a way to completely remove panel from DOM and memory after the panel is hidden.
				// destroy() doesn't seem to work without giving an error. Investigate this further.
				// Try removeChild().
				oThis.YUIPanel.element.parentNode.removeChild(oThis.YUIPanel.element);
			}
		);
		
		this.YUIPanel.center();
	}
}

function OverMapWindow2()
{
	var oThis=this;

	if(window.addEventListener)
	{
		window.addEventListener('resize',function(){oThis.resize();},false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent('onresize',function(){oThis.resize();});
	}
}

OverMapWindow2.prototype=new Panel();

OverMapWindow2.prototype.getForm=function(formName)
{
	var thisObj=this;
	
	var functionPointer=function()
	{
		thisObj.show(formName,this.getIFrame().contentWindow.document.getElementById('formHolder').innerHTML);
		
		this.removeElement();
	}
	
	var RPC=new RPCObj();
	
	switch(formName)
	{
		case'Add Station':
			RPC.call('getForm.php?heading='+formName+'&body=addStation',functionPointer);
		break;
		case'Add Online Station':
			RPC.call('getForm.php?heading='+formName+'&body=addOnlineStationForm',functionPointer);
		break;
		case'Add Offline Station':
			RPC.call('getForm.php?heading='+formName+'&body=addOfflineStationForm',functionPointer);
		break;
		case'Remove Station':
			RPC.call('getForm.php?heading='+formName+'&body=removeStation',functionPointer);
		break;
		case'Change Station Status':
			RPC.call('getForm.php?heading='+formName+'&body=changeStationStatus',functionPointer);
		break;
		case'Station Settings':
			RPC.call('getForm.php?heading='+formName+'&body=stationSettings',functionPointer);
		break;
	}
}

OverMapWindow2.prototype.resize=function()
{
	/*
	Resize YUIPanel.
	We want 100px of space around the panel.
	*/
	if(this.YUIPanel)
	{
		if(this.getMaxWidth()-200>=0)
		{
			this.YUIPanel.cfg.setProperty('width',(this.getMaxWidth()-200)+'px');
		}
		
		if(this.getMaxHeight()-200>=0)
		{
			this.YUIPanel.cfg.setProperty('height',(this.getMaxHeight()-200)+'px');
		}
		
		this.YUIPanel.body.style.height=(document.getElementById(this.YUIPanel.id).style.height.replace(/px/,'')-29)+'px';
	
		this.YUIPanel.center();
	}
}

OverMapWindow2.prototype.show=function(windowTitle,windowBody)
{
	this.YUIPanel=new YAHOO.widget.Panel('YUIPanel',{
		modal:true,
		constraintoviewport:false,
		draggable:false
	});
	
	this.YUIPanel.setHeader(windowTitle);
	
	this.YUIPanel.setBody(windowBody);

	this.YUIPanel.render(document.body);
	
	this.resize();
	
	var oThis=this;
	
	this.YUIPanel.hideEvent.subscribe(
		function()
		{
			oThis.close();
		}
	);
}

OverMapWindow2.prototype.close=function()
{
	this.YUIPanel.destroy();
	
	this.YUIPanel=null;
}

function DisclaimerPopup(){}

DisclaimerPopup.prototype=new Panel();

DisclaimerPopup.prototype.show=function()
{
	this.YUIPanel=new YAHOO.widget.Panel('disclaimerPopup',{draggable:false,width:'300px',modal:true,fixedcenter:true});
	
	this.YUIPanel.setHeader('Please note:');
	
	this.YUIPanel.setBody('Due to licensing restrictions, only one product is available for interactive preview during this demonstration. The same product will be displayed each time the "Interactive Preview" button is clicked.');
	
	this.YUIPanel.render(document.body);
	
	var oThis=this;
	
	this.YUIPanel.hideEvent.subscribe(function(){oThis.close();});
}

DisclaimerPopup.prototype.close=function()
{
	this.YUIPanel.destroy();
	
	this.YUIPanel=null;
}

function YUIPanelIFrame()
{
	var oThis=this;

	if(window.addEventListener)
	{
		window.addEventListener('resize',function(){oThis.resize();},false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent('onresize',function(){oThis.resize();});
	}
}

YUIPanelIFrame.prototype=new Panel();

YUIPanelIFrame.prototype.resize=function()
{
	/*
	Resize YUIPanel.
	We want 100px of space around the panel.
	*/
	if(this.YUIPanel)
	{
		if(this.getMaxWidth()-200>=0)
		{
			this.YUIPanel.cfg.setProperty('width',(this.getMaxWidth()-200)+'px');
		}
		
		if(this.getMaxHeight()-200>=0)
		{
			this.YUIPanel.cfg.setProperty('height',(this.getMaxHeight()-200)+'px');
		}
		
		this.YUIPanel.body.style.height=(document.getElementById(this.YUIPanel.id).style.height.replace(/px/,'')-29)+'px';
	
		if(this.IFrame)
		{
			this.IFrame.setAttribute('width',this.getMaxWidth()-200-8);
		
			this.IFrame.setAttribute('height',(document.getElementById(this.YUIPanel.id).style.height.replace(/px/,'')-29));
		}
		
		this.YUIPanel.center();
	}
}

YUIPanelIFrame.prototype.show=function(header,url)
{
	this.YUIPanel=new YAHOO.widget.Panel('YUIPanelIFrame',{
		modal:true,
		constraintoviewport:false,
		draggable:false
	});
	
	this.YUIPanel.setHeader(header);
	
	/* Create an iframe. */
	this.IFrame=document.createElement('iframe');
	
	this.IFrame.setAttribute('src',url);
	
	this.IFrame.setAttribute('frameborder',0);
	
	/* Place the iframe in the panel body. */
	this.YUIPanel.setBody(this.IFrame);
	
	this.YUIPanel.render(document.body);
	
	this.resize();
	
	var oThis=this;
	
	/* Remove the iframe if the panel is closed. */
	this.YUIPanel.hideEvent.subscribe(
		function()
		{
			oThis.YUIPanel.destroy();
			
			oThis.YUIPanel=null;
		}
	);
	
}

function MapPanel(className)
{
	this.div=document.createElement('div');

	this.div.className=className;
	
	document.body.appendChild(this.div);
	
	var thisObj=this;
	
	if(window.addEventListener)
	{
		window.addEventListener('resize',function(){thisObj.resize();},false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent('onresize',function(){thisObj.resize();});
	}
	
	this.resize();
}

MapPanel.prototype=new Panel();

MapPanel.prototype.resize=function()
{
	if(!this.div.style.left)
	{
		var monkey=new CSSMonkey();
		
		this.div.style.left=monkey.get('.'+this.div.className,'left');
		this.div.style.top=monkey.get('.'+this.div.className,'top');
	}
	
	var maxWidth=this.getMaxWidth();
	var maxHeight=this.getMaxHeight();
	
	if(maxWidth-this.dimToNum(this.div.style.left)>=0)
	{
		this.div.style.width=(maxWidth-this.dimToNum(this.div.style.left))+'px';
	}
	else
	{
		this.div.style.width='0px';
	}

	/*
	Map panel should be 50px from the bottom.
	The height of the bottom panel is 50px.
	*/
	if(maxHeight-this.dimToNum(this.div.style.top)>=50)
	{
		this.div.style.height=(maxHeight-this.dimToNum(this.div.style.top)-50)+'px';
	}
	else
	{
		this.div.style.height='0px';
	}
}

function TitlePanel(className,text)
{
	this.div=document.createElement('div');
	
	this.div.className=className;
	
	document.body.appendChild(this.div);
	
	this.div.appendChild(document.createTextNode(text));
	
	var oThis=this;
	
	if(window.addEventListener)
	{
		window.addEventListener('resize',function(){oThis.resize();},false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent('onresize',function(){oThis.resize();});
	}
	
	this.resize();
}

TitlePanel.prototype=new Panel();

TitlePanel.prototype.resize=function()
{
	var monkey=new CSSMonkey();
	
	this.div.style.width=this.getMaxWidth()-Number(monkey.get('.'+this.div.className,'left').replace(/px/,''))+'px';
}

function BottomPanel(className,className_Heading,className_Body)
{
	this.div=document.createElement('div');
	
	this.div.className=className;
	
	document.body.appendChild(this.div);
	
	this.className_Heading=className_Heading;
	
	this.className_Body=className_Body;
	
	var thisObj=this;
	
	if(window.addEventListener)
	{
		window.addEventListener('resize',function(){thisObj.resize();},false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent('onresize',function(){thisObj.resize();});
	}
	
	this.resize();
}

BottomPanel.prototype=new Panel();

BottomPanel.prototype.resize=function()
{
	if(!this.div.style.left)
	{
		var monkey=new CSSMonkey();
		
		this.div.style.left=monkey.get('.'+this.div.className,'left');
	}
	
	var maxWidth=this.getMaxWidth();
	var maxHeight=this.getMaxHeight();
	
	/* First, adjust the width of the panel. */
	if(maxWidth-this.dimToNum(this.div.style.left)>=0)
	{
		this.div.style.width=(maxWidth-this.dimToNum(this.div.style.left))+'px';
	}
	else
	{
		this.div.style.width='0px';
	}
	
	/* Adjust the vertical location of the panel. */
	this.div.style.top=(maxHeight-50)+'px';
}

BottomPanel.prototype.set=function(heading,content)
{
	this.heading=document.createElement('div');
	
	this.heading.className=this.className_Heading;
	
	this.content=document.createElement('div');
	
	this.content.className=this.className_Body;
	
	this.div.appendChild(this.heading);
	
	this.div.appendChild(this.content);
	
	this.heading.appendChild(heading);
	
	this.content.appendChild(content);
}

function Menu(className,itemClassName_highlighted,itemClassName_selected)
{
	this.selected=false;
	this.itemClassName_highlighted=itemClassName_highlighted;
	this.itemClassName_selected=itemClassName_selected;
	this.initialClassName_Selected='';
	this.initialClassName_Highlighted='';
	
	this.div=document.createElement('div');
	
	this.div.className=className;
	
	document.body.appendChild(this.div);
	
	var thisObj=this;
	
	if(window.addEventListener)
	{
		window.addEventListener('resize',function(){thisObj.resize();},false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent('onresize',function(){thisObj.resize();});
	}
	
	this.resize();
}

Menu.prototype=new Panel();

Menu.prototype.addItem=function(HTML)
{
	this.div.innerHTML+=HTML;
}

Menu.prototype.addItem_Element=function(element)
{
	this.div.appendChild(element);
}

Menu.prototype.highlightItem=function(element)
{
	if(element.className!=this.itemClassName_selected&&!this.initialClassName_Highlighted)
	{
		this.initialClassName_Highlighted=element.className;
	}
	
	element.className=this.itemClassName_highlighted;
	
	if(this.selected)
	{
		this.selected.className=this.itemClassName_selected;
	}
}

Menu.prototype.lowlightItem=function(element)
{
	element.className=this.initialClassName_Highlighted;
		
	if(this.selected)
	{
		this.selected.className=this.itemClassName_selected;
	}
}

Menu.prototype.selectItem=function(element)
{
	if(this.selected)
	{
		this.selected.className=this.initialClassName_Selected;
	}
	
	this.initialClassName_Selected=this.initialClassName_Highlighted;
	
	this.selected=element;
	
	this.selected.className=this.itemClassName_selected;
}

Menu.prototype.clear=function()
{
	/* Redo this. Don't use innerHTML. */
	this.div.innerHTML='';
}

Menu.prototype.resize=function()
{
	if(!this.div.style.top)
	{
		var monkey=new CSSMonkey();
		
		this.div.style.top=monkey.get('.'+this.div.className,'top');
	}
	
	var maxHeight=this.getMaxHeight();
	
	if(maxHeight-this.dimToNum(this.div.style.top)>=0)
	{
		this.div.style.height=(maxHeight-this.dimToNum(this.div.style.top))+'px';
	}
	else
	{
		this.div.style.height='0px';
	}
}

function CSSMonkey()
{
}

CSSMonkey.prototype.get=function(selector,attribute)
{
	return eval('this.getStyleObject(selector).'+attribute);
}

CSSMonkey.prototype.set=function(selector,attribute,value)
{
	eval('this.getStyleObject(selector).'+attribute+'=value');
}

CSSMonkey.prototype.getStyleObject=function(selector)
{
	for(var i=0;i<document.styleSheets.length;i++)
	{
		if(document.styleSheets[0].cssRules==undefined)
		{
			/* Internet Explorer */
			for(var j=0;j<document.styleSheets[i].rules.length;j++)
			{
				if(selector==document.styleSheets[i].rules[j].selectorText)
				{
					return document.styleSheets[i].rules[j].style;
				}
			}
		}
		else
		{
			/* Firefox */
			for(var j=0;j<document.styleSheets[i].cssRules.length;j++)
			{
				if(selector==document.styleSheets[i].cssRules[j].selectorText)
				{
					return document.styleSheets[i].cssRules[j].style;
				}
			}
		}
	}
	
	return false;
}

function TopPanel(className,className_Menu)
{
	this.div=document.createElement('div');
	
	this.div_Menu=document.createElement('div');
	
	this.div.className=className;
	
	this.div_Menu.className=className_Menu;
	
	document.body.appendChild(this.div);

	this.div.appendChild(this.div_Menu);
}

TopPanel.prototype=new Panel();

TopPanel.prototype.setMenu=function(HTML)
{
	this.div_Menu.innerHTML=HTML;
}

function LogoHolder(src,alt)
{
	this.div=document.createElement('div');
	
	this.div.className='logoHolder';
	
	this.div.innerHTML='<a href="http://gcgcusm.com/"><img src="'+src+'" alt="'+alt+'" border="0" /></a>';
	
	document.body.appendChild(this.div);
}

function Rectangle(lat,lng)
{
	this.lat_=lat;
	this.lng_=lng;
}

Rectangle.prototype=new GOverlay();

Rectangle.prototype.initialize=function(mapObj)
{
	var div=document.createElement('div');
	
	mapObj.getPane(G_MAP_MAP_PANE).appendChild(div);
	
	this.map_=mapObj;
	this.div_=div;
}

Rectangle.prototype.remove=function()
{
	this.div_.parentNode.removeChild(this.div_);
}

Rectangle.prototype.copy=function()
{
	return new Rectangle(this.lat_,this.lng_);
}

Rectangle.prototype.redraw=function(force)
{
	if(!force)
	{
		return;
	}

	this.div_.style.left=this.map_.fromLatLngToDivPixel(new GLatLng(this.lat_,this.lng_)).x+'px';
	this.div_.style.top=this.map_.fromLatLngToDivPixel(new GLatLng(this.lat_,this.lng_)).y+'px';
}

function MapLabel(lat,lng,text)
{
	this.lat_=lat;
	this.lng_=lng;
	this.text_=text;
}

MapLabel.prototype=new Rectangle();

MapLabel.prototype.initialize=function(mapObj)
{
	var div=document.createElement('div');
	div.className='mapLabel';
	div.innerHTML=this.text_;
	
	mapObj.getPane(G_MAP_MAP_PANE).appendChild(div);
	
	this.map_=mapObj;
	this.div_=div;
}

MapLabel.prototype.copy=function()
{
	return new Rectangle(this.lat_,this.lng_,this.text_);
}
