var selectedProvince = null;
var TblSearchOpen = false;
var aMapImages = new Array(13);

function mapInit()
{
	//make sure the current page is the main page or don't bother preloading the images.
	if(window.location.href.indexOf("index.php") > -1 || window.location.href == "http://www.canadiancottagedirectory.com/")
	{
		aMapImages[0] = new Image();
		aMapImages[0].src = "images/map.jpg";
		
		aMapImages[1] = new Image();
		aMapImages[1].src = "images/mapNL.jpg";
		
		aMapImages[2] = new Image();
		aMapImages[2].src = "images/mapPE.jpg";
		
		aMapImages[3] = new Image();
		aMapImages[3].src = "images/mapNS.jpg";
		
		aMapImages[4] = new Image();
		aMapImages[4].src = "images/mapNB.jpg";
		
		aMapImages[5] = new Image();
		aMapImages[5].src = "images/mapNU.jpg";
		
		aMapImages[6] = new Image();
		aMapImages[6].src = "images/mapNT.jpg";
		
		aMapImages[7] = new Image();
		aMapImages[7].src = "images/mapQC.jpg";
		
		aMapImages[8] = new Image();
		aMapImages[8].src = "images/mapON.jpg";
		
		aMapImages[9] = new Image();
		aMapImages[9].src = "images/mapMB.jpg";
		
		aMapImages[10] = new Image();
		aMapImages[10].src = "images/mapSK.jpg";
		
		aMapImages[11] = new Image();
		aMapImages[11].src = "images/mapAB.jpg";
		
		aMapImages[12] = new Image();
		aMapImages[12].src = "images/mapYT.jpg";
		
		aMapImages[13] = new Image();
		aMapImages[13].src = "images/mapBC.jpg";		
	}
}

function changeImage(sNewImage)
{	
	eImage = document.getElementById("imgMap"); 
	
	eImage.src = sNewImage;
}

function setProvince(sProv, sProvFullName)
{
	selectedProvince = sProv;
	
	var eTblSearch       = document.getElementById("tblSearch");
	var eTDSearch1       = document.getElementById("TDSearch1");	
	var eTDSearch2       = document.getElementById("TDSearch2");
	var eMapProvinceSale = document.getElementById("MapProvinceSale");
	var eMapProvinceRent = document.getElementById("MapProvinceRent");

	eMapProvinceSale.innerHTML = sProvFullName;
	eMapProvinceRent.innerHTML = sProvFullName;
	eTblSearch.style.display = "inline";

	eTDSearch1.onclick = function() { TblSearchOpen = true; }
	eTDSearch2.onclick = function() { TblSearchOpen = true; }	

	TblSearchOpen = false;
	
	document.body.onclick = function() { closeTblSearchSelection(); closeAdTypeSelection(); closeProvinceSelection(); };	
	
	window.scrollTo(0, 100);
}

function closeTblSearchSelection()
{	
	if(TblSearchOpen) { TblSearchOpen = false; return;}
	
	var eTblSearch = document.getElementById("tblSearch");

	eTblSearch.style.display = "none";
	
}

function map_changeLocation(sLocation)
{	
	sLocation += "&province=" + selectedProvince;	

	//set browser to new url location.
	window.location.href = sLocation;
}