﻿//Constants
var MinutesYearStart = 2005;
var AdminDivs = 3;

//Vars
var PicSwitch = false;

function CenterBkg()
{
	var imagediv = document.getElementById("TowersBkg");
	var lft = eval((document.body.offsetWidth - 1242)/2);
	imagediv.style.left = lft;
}

function mouseOverMainPics(sw, picNo)
{
	var pic = document.getElementById("mainImg" + picNo);
	if (sw)
	{
		if (!PicSwitch)
		{
			pic.src = "images/mainImg" + picNo + "white.png";
			document.getElementById("mainDiv" + picNo).style.display = "block";
			PicSwitch = true;
			if (picNo != 2)
			{
				HidePic(2, true);
			}
		}
	}
	else
	{
		PicSwitch = false;
		if (picNo == 2)
			setTimeout("HidePic(" + picNo + ");", 2);
		else
			HidePic(picNo);
	}
}

function HidePic(picNo, overr)
{
	var pic = document.getElementById("mainImg" + picNo);
	if (!PicSwitch || overr)
	{
		pic.src = "images/mainImg" + picNo + ".png";
		document.getElementById("mainDiv" + picNo).style.display = "none";
	}
}

function ShowUserInfo(Username)
{
	document.getElementById('mainLoginDiv').style.display = 'none';
	document.getElementById('secondaryLoginDiv').style.display = 'block';
	//document.getElementById('logoutTD').innerHTML = 'You are currently signed in as ' + Username;
}

function SignOut()
{
	document.getElementById('mainLoginDiv').style.display = 'block';
	document.getElementById('secondaryLoginDiv').style.display = 'none';
	ShowAdminLinks(0);
}

var pic1, pic2, pic3, pic4, pic5;
	
function PreloadImages()
{
    pic1 = new Image(142,217);
    pic1.src = "images/mainImg1white.png";
    pic2 = new Image(142,217);
    pic2.src = "images/mainImg2white.png";
    pic3 = new Image(142,217);
    pic3.src = "images/mainImg3white.png";
    pic4 = new Image(142,217);
    pic4.src = "images/mainImg4white.png";
    pic5 = new Image(142,217);
    pic5.src = "images/mainImg5white.png";
}

function InitializeGMap()
{
	
	if (GBrowserIsCompatible()) {
		var gmap = new GMap2(document.getElementById("GMapsDiv"));
		gmap.setUIToDefault();
		gmap.setCenter(new GLatLng(49.265572,-123.007956), 15);

		var RTIcon = new GIcon(G_DEFAULT_ICON);
		RTIcon.iconSize = new GSize(30, 30);

		RTIcon.image = "images/ricon.png";       
		markerOptions = { icon:RTIcon };

		var point = new GLatLng(49.265572,-123.007956);
		var newMarker = new GMarker(point, markerOptions);
		gmap.addOverlay(newMarker);
	}


}

function InitializeBMap()
{

	var bmap = new VEMap("BMapsDiv");
	var latLon = new VELatLong(49.265572,-123.007956); 
	bmap.LoadMap(latLon, 1, VEMapStyle.Oblique, 0, VEMapMode.Mode2D, 1);
}

function PopulateMinutesBox(yearIn)
{
	var MonthsArray=new Array( "January","February","March","April","May","June","July","August","September","October","November","December");
	var mainDivBox = document.getElementById('mainDiv2');
	if (!mainDivBox)
		return;
	mainDivBox.innerHTML = '';
	for (var i = new Date().getFullYear(); i >= MinutesYearStart; i--)
	{
		var yearDiv = document.createElement("div");
		var customHeight = 0;

		yearDiv.id = "divYear" + i;
		if (yearIn == i)
			yearDiv.className = "yearDiv190";
		else
			yearDiv.className = "yearDiv20";

		var yearBullet = document.createElement("img");
		yearBullet.src = "images/bullet.png";
		yearBullet.className = "imageMiddleAlign";
		yearDiv.appendChild(yearBullet);
		var yearText = document.createElement("a");
		yearText.className = 'yearText';
		yearText.setAttribute('onclick','PopulateMinutesBox(' + i + ')');
		yearText.appendChild(document.createTextNode("\u00A0Minutes " + i));
		yearDiv.appendChild(yearText);
		if (yearIn == i)
		{
			var monthDiv = document.createElement('div');
			monthDiv.className = 'monthBox';
			monthDiv.id = 'divMonths';
			for (var j = 0; j < 12; j++)
			{
				var monthBullet = document.createElement('img');
				monthBullet.src = "images/bulletsmall.png";
				monthBullet.className = 'imageMiddleAlign';
				monthDiv.appendChild(monthBullet);
				monthDiv.appendChild(document.createTextNode('\u00A0'));
				var monthText = document.createElement("a");
				monthText.target = "_blank";
				var NAText = '';
				if (MDump.indexOf('|' + i.toString().substr(2,2) + ((j<9?'0':'') + (j + 1)).toString() + '|') == -1)
				{
					NAText = ' N/A';
					monthText.className = "mainBoxMonthsDisabled";
				}
				else
				{
					monthText.setAttribute('href','servepdf.aspx?docid=min' + i + (j<9?'0':'') + (j + 1));
					monthText.className = "mainBoxMonths";
				}
				monthText.appendChild(document.createTextNode(MonthsArray[j] + NAText));
				monthDiv.appendChild(monthText);
				monthDiv.appendChild(document.createElement('br'));
			}
			yearDiv.appendChild(monthDiv);
		}
		mainDivBox.appendChild(yearDiv);  
	}
}

function PopulateAGMBox()
{
	var mainDivBox = document.getElementById('mainDiv1');
	if (!mainDivBox)
		return;

	var ChangesMade = true;
	while (ChangesMade)
	{
		ChangesMade = false;
		for (var i = 0; i < AGMDump.length -1; i++)
		{
			if (AGMDump[i] < AGMDump[i + 1])
			{
				var tmp = AGMDump[i];
				AGMDump[i] = AGMDump[i + 1];
				AGMDump[i + 1] = tmp;
				ChangesMade = true;
			}
		}
	}

	for (var i = 0; i < AGMDump.length; i++)
	{
		var yearBullet = document.createElement("img");
		yearBullet.src = "images/bullet.png";
		yearBullet.className = "imageMiddleAlign";
		mainDivBox.appendChild(yearBullet);
		mainDivBox.appendChild(document.createTextNode('\u00A0'));

		var yearText = document.createElement("a");
		yearText.className = 'yearText';
		yearText.setAttribute('href','servepdf.aspx?docid=agm' + AGMDump[i]);
		yearText.setAttribute('target','_blank');
		yearText.appendChild(document.createTextNode("\u00A0AGM\u00A0 " + AGMDump[i]));
		mainDivBox.appendChild(yearText);
		mainDivBox.appendChild(document.createElement('br'));
		mainDivBox.appendChild(document.createElement('br'));
	}
}

function ShowAdminLinks(ShowHide)
{
	for (var i = 1; i <= AdminDivs; i++)
	{
		document.getElementById("divAdmin" + i).style.display = (ShowHide == 1?"block":"none");
	}
}

function GetDelButton(IsAdmin, QID)
{
	var SelectedCat = "";
	if (IsAdmin == 1)
	{
		SelectedCat = getQuerystring('catid');
		document.write('<a href="addqa.aspx?dqid=' + QID + '"><img title="Edit question" style="vertical-align:middle" src="images/editButton.png" /></a><a style="color:red; font-weight:bold" href="faq.aspx?dqid=' + QID + '&catid=' + SelectedCat + '"><img style="vertical-align:middle" title="Delete question" border="0" src="images/deleteButton.png" /></a>');
	}
}

function getQuerystring(key, default_)
{
	if (default_==null) default_="0"; 
		key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	
	var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	var qs = regex.exec(window.location.href);
	
	if(qs == null)
		return default_;
	else
		return qs[1];
}

var newsSlotDelay = 10000;
var newsScrollDelay = 10;
var currentNewsSlot = 0;
var currentNewsEntry = 0;
var scrollPos = 0;
var scrollStep = 3;

function CycleNews()
{
	if (NewsEntries.length > 1)
	{
		setTimeout("ScrollNextSlot();", newsSlotDelay);
		
	}
}
function ScrollNextSlot()
{
	currentNewsSlot = Math.abs(currentNewsSlot - 1);
	
	if (currentNewsEntry == NewsEntries.length - 1)
		currentNewsEntry = 0;
	else
		currentNewsEntry++;
	
	//alert(NewsEntries[currentNewsEntry]);
	document.getElementById('newsScroller' + currentNewsSlot).innerHTML = NewsEntries[currentNewsEntry];

	scrollPos = 0;
	ScrollNews();
}

function ScrollNews()
{
	var scrollDivLower = document.getElementById('newsScroller' + currentNewsSlot);
	var scrollDivUpper = document.getElementById('newsScroller' + Math.abs(currentNewsSlot - 1));
	if (scrollPos > -180)
	{
		scrollPos -= scrollStep;
		scrollDivUpper.style.top = scrollPos + "px";
		scrollDivLower.style.top = (scrollPos + 180) + "px";
		setTimeout("ScrollNews()", newsScrollDelay);
	}
	else
	{
		scrollDivUpper.style.top = "181px";
		setTimeout("ScrollNextSlot()", newsSlotDelay);
	}
}

	
//	var scroller = document.getElementById('newsScroller');
//	if (!scroller)
//		return;
//	if (currentNewsSlot == newsSlots)
//	{
//		scroller.style.top = 0;
//		scrollNewsPos = 0;
//		nextNewsSlotTop = scrollNewsHeight;
//		currentNewsSlot = 1;
//		if (currentNewsSlot != newsSlots)
//			setTimeout("ScrollNews()", newsSlotDelay);
//	}
//	else
//	{
//		nextNewsSlotTop = (currentNewsSlot + 1) * scrollNewsHeight;
//		currentNewsSlot += 1;
//		ScrollNews();
//	}


//function ScrollNews()
//{
//	var scroller = document.getElementById('newsScroller');
//	if (!scroller)
//		return;

//	if (scrollNewsPos > nextNewsSlotTop)
//	{
//		window.status = nextNewsSlotTop + "," + scrollNewsPos;
//		scrollNewsPos -= 3;
//		scroller.style.top = scrollNewsPos + "px";
//		setTimeout("ScrollNews()", newsScrollDelay);
//	}
//	else
//	{
//		setTimeout("NextNews()", newsSlotDelay);
//	}
//}

function CheckPasswordMatch(P1TextID, P2TextID, imgID)
{
	var P1txt = document.getElementById(P1TextID);
	var P2txt = document.getElementById(P2TextID);
	var MatchImage = document.getElementById(imgID);
	if(!P1txt || !P2txt || !MatchImage)
		return;
	
	if (P1txt.value == P2txt.value && P1txt.value != "")
		MatchImage.src = "images/checkmark.png";
	else
		MatchImage.src = "images/deleteButton.png";
}


var UploadPane = 1;
function ToggleUploadPane()
{
	var pane = document.getElementById('UploadDocTD');
	var image = document.getElementById('UploadDocIMG');
	if (!pane)
		return;

	if (UploadPane == 1)
	{
		pane.style.display = 'none';
		image.src = 'images/openSectionButton.png';
	}
	else
	{
		pane.style.display = 'block';
		image.src = 'images/closeSectionButton.png';
	}
		
	UploadPane = Math.abs(UploadPane - 1);
}

function ToggleReplySection(SectionID)
{
	var toggleImage = document.getElementById("ReplyImg" + SectionID);
	if (toggleImage.src.indexOf("open") >= 0)
	{
		document.getElementById("ReplySection" + SectionID).style.display = "block";
		toggleImage.src = "images/closeSectionButton.png";
		document.getElementById("OpenSection").value = SectionID;
	}
	else
	{
		document.getElementById("ReplySection" + SectionID).style.display = "none";
		toggleImage.src = "images/openSectionButton.png";
	}
}

function ChangeNature(DDLCtl, LabelID)
{
	if (DDLCtl.options[DDLCtl.selectedIndex].text.indexOf('Classifieds') >= 0 && document.getElementById('LoggedIn').value == "0")
	{
		document.getElementById(LabelID).style.display = 'inline';
		document.getElementById(LabelID).innerHTML = 'Login required';
	}
	else
	{
		document.getElementById(LabelID).style.display = 'none';
		document.getElementById(LabelID).innerText = '';
	}
}