var varWelcome;

String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "")
}

function buttonRollover(thisImgSrc)
{
	return thisImgSrc.replace("_off.", "_on.");
}

function buttonRolloff(thisImgSrc)
{
	return thisImgSrc.replace("_on.", "_off.");
}

function UpdateIncludeNearby(selectedObj, checkBoxName)
{ 
	//check if the 'All' option was selected, if so disable the check box
	if(selectedObj.options[selectedObj.selectedIndex].value == "-1")
	{
		document.forms[0][checkBoxName].disabled = true;
		document.forms[0][checkBoxName].checked = false;
	}
	else
	{
		document.forms[0][checkBoxName].removeAttribute('disabled');
		document.forms[0][checkBoxName].parentElement.removeAttribute('disabled');
		//document.forms[0][checkBoxName].disabled = false;
	}
}

function DestinationChanged(ddDestination, chSurraoundingAreas)
{
	d = document.getElementById(ddDestination);
	n = document.getElementById(chSurraoundingAreas);

	if(d!=null)
	{
		var selDestination = d.options[d.selectedIndex].value;
		if(selDestination == "-1")
		{
			n.disabled = true;
			n.checked = bPreviousIncludeChecked;
		}
		else
		{
			if(SearchSurroundingContains(parseInt(selDestination)))
			{
				n.checked = true;
				n.removeAttribute('disabled');
				n.parentElement.removeAttribute('disabled');
			}
			else
			{
				n.checked = bPreviousIncludeChecked;
				n.removeAttribute('disabled');
				n.parentElement.removeAttribute('disabled');
			}
		}
	}
	
}	

function SurroundingAreasChange(ddDestination, chSurraoundingAreas)
{
	n = document.getElementById(chSurraoundingAreas);
	d = document.getElementById(ddDestination);
	var selDestination = d.options[d.selectedIndex].value;
	bPreviousIncludeChecked = n.checked;
}


//This function checks if the date control needs to be enabled or disabled and
//then does so accordingly.
function UpdateDateControl(selectedObj, controlName)
{
	//stores the current control name
	var currentControlName = "";
	var link = "";

	//if this is checked, then we need to disable the date control
	if(selectedObj.checked == true)
	{
		//loop though the forms and all elements in the form
		for (var form_loop=0; form_loop<document.forms.length; form_loop++) 
		{
			//this will disable the drop down boxes
			for (var elems=0; elems<document.forms[form_loop].length; elems++)
			{
				if (document.forms[form_loop].elements[elems].name != "")
				{
					currentControlName = document.forms[form_loop].elements[elems].name;
					//alert(document.forms[form_loop].elements[elems].type);
					if(currentControlName.indexOf(controlName) == 0)
					{
						document.forms[form_loop][currentControlName].disabled = true;
					}
				}
			}
		}
		
		//now loop through the links to disable the calendar popup
		for(var i=0; i<document.links.length; i++)
		{
			link = document.links[i].href;
			if(link.indexOf(controlName) >= 0)
			{
				//alert("Match found = " + controlName + " " + link);
				document.links[i].disabled = true;
				document.links[i].onclick = function(){return false;}
				if(document.links[i].style)
					document.links[i].style.cursor = 'default';
				
			}
		}
	}
	else
	{
		//check box not checked, so the date control needs to be enabled
		//loop though the forms and all elements in the form and enable the appropriate drop downs
		for (var form_loop=0; form_loop<document.forms.length; form_loop++) 
		{
			for (var elems=0; elems<document.forms[form_loop].length; elems++)
			{
				if (document.forms[form_loop].elements[elems].name != "")
				{
					currentControlName = document.forms[form_loop].elements[elems].name;
					//alert('Control = ' + currentControlName + '  looking for = ' + controlName);
					if(currentControlName.indexOf(controlName) == 0)
					{
						//alert("Match Found = " + currentControlName);
						document.forms[form_loop][currentControlName].disabled = false;
						//document.forms[form_loop][currentControlName].removeAttribute('disabled');
						//document.forms[form_loop][currentControlName].parentElement.removeAttribute('disabled');
					}
				}
			}
		}
		
		//now loop through the links to ensable the calendar popup
		for(var i=0; i<document.links.length; i++)
		{
			link = document.links[i].href;
			if(link.indexOf(controlName) >= 0)
			{
				//alert("Match found = " + controlName + " " + link);
				document.links[i].disabled = false;
				document.links[i].onclick = null;
				if(document.links[i].style)
					document.links[i].style.cursor = document.all ? 'hand' : 'pointer';
			}
		}
	
	}
}


function Redirect(strRedirectURL)
{
	//alert(strRedirectURL);
	window.location.href = strRedirectURL;
}

function doLoad(strRedirectURL)
{
    setTimeout( "Redirect('" + strRedirectURL + "')", 10*1000 );
}

function ProvinceChanged(ddProvinceName, ddCountryName)
{
	var ddProvince = document.getElementById(ddProvinceName);
	var selProvince = ddProvince.options[ddProvince.selectedIndex].value;
	var ddCountry = document.getElementById(ddCountryName);
	
	if(selProvince!=-1)
	{
		var varCountryID = selProvince.split("|")[0];
		
		for(var i = 0; i < ddCountry.options.length; i++)
		{				
			if (ddCountry.options[i].value == varCountryID)
			{
				ddCountry.options.selectedIndex = i;
				break;
			}
		}
	}
	else
		ddCountry.options.selectedIndex = 0;
}

function CountryChanged(ddProvinceName, ddCountryName)
{
	var ddProvince = document.getElementById(ddProvinceName);
	var ddCountry = document.getElementById(ddCountryName);
	var selCountry = ddProvince.options[ddProvince.selectedIndex].value;
	
	if(selCountry!=1 && selCountry!=2)
	{
		ddProvince.options.selectedIndex = 0;
	}
}
function launchPopup(whichWindow) {
	if (whichWindow != "") {
		objWin = window.open(whichWindow,"popWindow","status=0,toolbar=0,location=0,menubar=1,directories=0,resizable=1,scrollbars=1,height=400,width=790");
	}
}

function launchPopupWindow(url, status, toolbar, location, menubar, resizable, scrollbars, width, height, id)
{
	var windowOptions = "status="+status;
	windowOptions += ",toolbar="+toolbar;
	windowOptions += ",location="+location;
	windowOptions += ",menubar="+menubar;
	windowOptions += ",resizable="+resizable;
	windowOptions += ",scrollbars="+scrollbars;
	windowOptions += ",width="+width;
	windowOptions += ",height="+height;

	objWin = window.open(url, null, windowOptions);
}

function loadIFrame(iFrameURL, iFrameID)
{
	var objIFrame = document.createElement("iframe");
	objIFrame.id = iFrameID;
	objIFrame.src = iFrameURL
	document.body.appendChild(objIFrame);
	document.getElementById(iFrameID).style.display = 'none';
}

function removeElement(id)
{
	var el = document.getElementById(id);
	if(el!=null)
		document.body.removeChild(el);
	return true;
}

function HideJavaScriptDisabledMessage(formitem)
{
	if (document.getElementById)
	{
		// this is the way the standard browsers work
		var style2 = document.getElementById(formitem).style;
		style2.display = "none";
	}
	else if (document.all)
	{
		// this is the way msie versions work
		var style2 = document.all[formitem].style;
		style2.display = "none";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[formitem].style;
		style2.display = "none";
	}
}

//deselects all radio buttons in the radio button group specified by radiobuttongroupname
//on the form specified by formname
function RadioButtonGroupDeselectAll(formname, radiobuttongroupname)
{
	if(formname!=null&&radiobuttongroupname!=null) 
	{
		//get the radio button list from the form
		var radioGroup = document.forms[formname].elements[radiobuttongroupname];
		
		//if the radioGroup is null, just return
		if(!radioGroup)
			return "";
	
		//get the number of buttons in the group
		var radioLength = radioGroup.length;
		
		//if the number of buttons is undefined, return
		if(radioLength == undefined) 
			return "";
			
		//if there is only one button, uncheck it
		if(radioGroup.checked) 
		{
			radioGroup.checked = false;
			return "";
		}

		//otherwise, uncheck all the buttons in the group
		for(var i = 0; i < radioLength; i++) 
		{
			radioGroup[i].checked = false;
		}
		return "";
	}
}

function ValidatePostalCode(ddCountry, txtPostalCode)
{
	var bIsvalid = true;
	var ddCountry = document.getElementById(ddCountry);
	var selCountry = "";
	if(ddCountry!=null)
		selCountry = ddCountry.options[ddCountry.selectedIndex].value;
	var varPostalCodeValue = document.getElementById(txtPostalCode).value; 
				
	var trimmedPostalCode = "";
	if(varPostalCodeValue!=null&&varPostalCodeValue.length>0)
		trimmedPostalCode = varPostalCodeValue.replace(" ","");
					
	if(selCountry!=null&&(selCountry=="1" || selCountry=="2"))
	{
		if(trimmedPostalCode!=null && trimmedPostalCode.length>0)
		{
			if((selCountry=="1"&&trimmedPostalCode.length<6)||(selCountry=="2"&& trimmedPostalCode.length<5))
				bIsvalid = false; 
			else
			{
				var result;
				if(selCountry=="1")
				{
					var objRegExp  = /^\D{1}\d{1}\D{1}\-?\d{1}\D{1}\d{1}$/;
					result = objRegExp.test(trimmedPostalCode);
				}
				if(selCountry=="2")
				{
					var objRegExp  = /(^\d{5}([\-]\d{4})?$)/;
					result = objRegExp.test(trimmedPostalCode);
				}
				
				if(result!=null)
					bIsvalid = true; 
				else
					bIsvalid = false; 		
			}	
		}
	}
	else
		bIsvalid = true; 	

	return bIsvalid;				
}
function ShowHideComments() {

	var style;
	var style2;
	
	if (document.getElementById)
	{
		// this is the way the standard browsers work
		style = document.getElementById('CommentPublishingContainer').style;
		style2 = document.getElementById('BlogEntryContainer').style;		
	}
	else if (document.all)
	{
		// this is the way msie versions work
		style = document.all['CommentPublishingContainer'].style;
		style2 = document.all['BlogEntryContainer'].style;
		//style.display = "none";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		style = document.layers['CommentPublishingContainer'].style;
		style2 = document.layers['BlogEntryContainer'].style;
		//style.display = "none";
	}

	if(style.display == "none")
		style.display = "";
	else
		style.display = "none"
		
	if(style2.display == "none")
		style2.display = "";
	else
		style2.display = "none";
}

//submits the form when user hits the ENTER key.  This function is necessary to override the google search global event.
//It has to be called from the onkeydown event of every input element for which you wish to submit the form
//instead of submitting a search to the google box.
function SubmitMyForm(e, submitButtonName) 
{	
	var keynum;
	var keychar;
	var numcheck;
	
	var button = document.getElementById(submitButtonName);
	if(window.event) // IE
	{
		keynum = e.keyCode
		if (keynum == 13&&button!=null)
		{
			button.click();
		}
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
		if (keynum == 13&&button!=null)
		{
			button.click();
		}
	}
}

function ValidateYesNoRadioControls(ControlNameYes, ControlNameNo)
{
	var varControlYes = document.getElementById(ControlNameYes);
	var varControlNo = document.getElementById(ControlNameNo);
	if(varControlYes!=null && varControlNo && (varControlYes.checked || varControlNo.checked))
		return true;
	else
		return false;	
}

function SayHello(ElementId, UserIDCookieName)
{
	varWelcome = document.getElementById(ElementId);
	var UserId = Get_Cookie(UserIDCookieName);

	if (varWelcome != null)
	{
		if (UserId != null)
				ManageTravelBase.SayHelloToUser(UserId, SayHelloToUser_CallBack);
	}	
}

function SayHelloToUser_CallBack(response)
{
	if (response.error != null)
	{
		//alert(response.error);
		varWelcome.innerHTML = 'Hello'; 
	}
	else
	{	
		var oMsg = response.value;
		varWelcome.innerHTML = oMsg;
	}
}

function Get_Cookie(name) 
{
		
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


// HBX strip special characters function

function _hbxStrip(a) {    //  I called it _hbxStrip here, may be renamed if desired just keep it consistent
   a = a.split("|").join("");
   a = a.split("/").join("");
   a = a.split("!").join("");
   a = a.split("&").join("");
   a = a.split("'").join("");
   a = a.split("#").join("");
   a = a.split("$").join("");
   a = a.split("%").join("");
   a = a.split("^").join("");
   a = a.split("*").join("");
   a = a.split(":").join("");
   a = a.split("~").join("");
   //a = a.split(";").join("");  // you might want to remove this line as the “;” is used for the account value split for global
   a = a.split(" ").join("+");
   return a;
}

function ShowHideElement(elementToShow, elementToHide) 
{
	var style;
	var style2;
	
	if (document.getElementById)
	{
		// this is the way the standard browsers work
		style = document.getElementById(elementToShow).style;
		style2 = document.getElementById(elementToHide).style;		
	}
	else if (document.all)
	{
		// this is the way msie versions work
		style = document.all[elementToShow].style;
		style2 = document.all[elementToHide].style;
		//style.display = "none";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		style = document.layers[elementToShow].style;
		style2 = document.layers[elementToHide].style;
		//style.display = "none";
	}
		style.display = "";
		style2.display = "none";	
}

//hide the "Manage Users Link" in the ManageTravel Menu
function HideManageUsersLink()
{
	var varHideUsers = document.getElementById('idMngUsersFlip');
	if(varHideUsers!=null) 
		varHideUsers.style.display = "none";
}

// COUNTRY SELECTOR FUNCTIONS
var UserCountryCode = 'CA';
function getXmlHttpRequestObject() {	
	if (window.XMLHttpRequest) {		
		return new XMLHttpRequest(); //Not IE	
	} 
	else if(window.ActiveXObject) {		
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE	
	}}
	
var receiveReq = getXmlHttpRequestObject();

function showMoreText(){
	jQuery("a#showMoreLink").css("display","none");
	jQuery("span#introMore").fadeIn("slow");
	return false;
}
function showLessText(){
	jQuery("span#introMore").fadeOut("slow");
	jQuery("a#showMoreLink").css("display","inline");
	return false;
}

function showCountrySelector() {
	document.getElementById("countrySelectorList").style.display = "block";
}
function hideCountrySelector() {
	document.getElementById("countrySelectorList").style.display = "none";
}

function SelectCountry(CookieName, selectedCountrySpanID, countryListUnorderedList, QueryStringCountry)
{
	var CookieValue;

	if(QueryStringCountry!=null && QueryStringCountry!='')
	{
		CookieValue = QueryStringCountry;
		SetCookie ('CountryCode', CookieValue, null, '/', window.location.hostname);
	}
	else
	{
		CookieValue = Get_Cookie(CookieName);
		if(CookieValue==null || CookieValue=='')
		{
			CookieValue = UserCountryCode;
			/*
			if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {		
			//Setup the connection as a GET call to FetchUserCountryCode.aspx.		
			//True explicity sets the request to asyncronous (default).		
				receiveReq.open("GET", '/TBCCW/ajax/Pages/FetchUserCountryCode.aspx', true);		
			//Set the function that will be called when the XmlHttpRequest objects state changes.		
			receiveReq.onreadystatechange = function ResetCountryCodeByUserIPAddress(){
					if (receiveReq.readyState == 4) {		
						if(receiveReq.responseText !=null){
							CookieValue = receiveReq.responseText;
							SetCookie ('CountryCode', CookieValue, null, '/', window.location.hostname);
							//SelectCountryCodeIndex(d, CookieValue);
						}
						else
						{
							CookieValue = UserCountryCode;
							//SelectCountryCodeIndex(d, CookieValue);
						}
					}}; 		
				//Make the actual request.		
				receiveReq.send(null);	
			}
			else
			{
				CookieValue = UserCountryCode;
				//SelectCountryCodeIndex(d, CookieValue);
			}
			*/
		}	
	}
	
	var unordredList = document.getElementById(countryListUnorderedList);
	var selectedCountrySpan = document.getElementById(selectedCountrySpanID);
	
	if(unordredList!=null && CookieValue !=null){
		//alert(CookieValue);
		for(i=0; i<unordredList.getElementsByTagName("li").length; i++){
			//alert(unordredList.childNodes[i].style);
			var currentListItem = unordredList.getElementsByTagName("li")[i];
			currentListItem.style.display = "block";
			if(currentListItem.innerHTML.toLowerCase().indexOf("cc="+CookieValue.toLowerCase()+"\"")>-1)
			{
				//alert(currentListItem.innerHTML);
				currentListItem.style.display = "none";
				var startCountryDisplayName = currentListItem.innerHTML.toLowerCase().indexOf(">");
				var endCountryDisplayName = currentListItem.innerHTML.toLowerCase().indexOf("</a>");
				//alert(startCountryDisplayName+"-" + endCountryDisplayName);
				
				if(startCountryDisplayName>-1 && endCountryDisplayName>-1)
				{
					//alert(currentListItem.innerHTML.substring(startCountryDisplayName+1, endCountryDisplayName));
					selectedCountrySpan.innerHTML = currentListItem.innerHTML.substring(startCountryDisplayName+1, endCountryDisplayName);
					
				}
			}
		}  
	}

	/*
	
	
	if (d!=null && CookieValue !=null)
	{
		for(var i = 0; i < d.options.length; i++)
		{				
			if (d.options[i].value.indexOf("|" + CookieValue+"|")>-1)
			{
				d.options.selectedIndex = i;
				break;
			}
		}
	}

	if(QueryStringCountry!=null && QueryStringCountry!='')
	{
		if(d!=null)
		{
			var vSelected = d.value;
			var CountryCode = vSelected.substring(vSelected.indexOf("|")+1);
			CountryCode = CountryCode.substring(0, 2);
			SetCookie ('CountryCode', CountryCode, null, '/', window.location.hostname);
		}
	}
	*/
}

function showLightbox() {
	thisImageLink = document.getElementById("imageLink_" + idCurrentPhoto);
	Lightbox.start(thisImageLink);
}

function writeCurrentPhotoPaging() {
	if (idCurrentPhoto != "" && idTotalPhotos != "") {
		if (document.getElementById("LBPhotoPaging")) {
			document.getElementById("LBPhotoPaging").innerHTML = idCurrentPhoto + " of " + idTotalPhotos;
		}
		/*if (idCurrentPhoto > 1) {
			document.getElementById("linkLBPrevious").className = "visible";
		} else {
			document.getElementById("linkLBPrevious").className = "hidden";
		}
		if (idCurrentPhoto == idTotalPhotos) {
			document.getElementById("linkLBNext").className = "hidden";
		} else {
			document.getElementById("linkLBNext").className = "visible";
		}*/
		//thisImageHeight = document.getElementById("image_" +idCurrentPhoto).height;
		//document.getElementById("image_" +idCurrentPhoto).style.marginTop = (190 - thisImageHeight)/2 + "px";
	}
}

function nextLBPhoto() {
	if (idCurrentPhoto < idTotalPhotos) {
		//document.getElementById("imageLink_" + idCurrentPhoto).style.display = "none";
		document.getElementById("lbContentItem_" + idCurrentPhoto).style.display = "none";
		idCurrentPhoto++;
		//document.getElementById("imageLink_" + idCurrentPhoto).style.display = "inline";
		document.getElementById("lbContentItem_" + idCurrentPhoto).style.display = "block";
		writeCurrentPhotoPaging();
	} else {
		//document.getElementById("imageLink_" + idCurrentPhoto).style.display = "none";
		document.getElementById("lbContentItem_" + idCurrentPhoto).style.display = "none";
		idCurrentPhoto = 1;
		//document.getElementById("imageLink_" + idCurrentPhoto).style.display = "inline";
		document.getElementById("lbContentItem_" + idCurrentPhoto).style.display = "block";
		writeCurrentPhotoPaging();
	}
}

function previousLBPhoto() {
	if (idCurrentPhoto > 1) {
		//document.getElementById("imageLink_" + idCurrentPhoto).style.display = "none";
		document.getElementById("lbContentItem_" + idCurrentPhoto).style.display = "none";
		idCurrentPhoto--;
		//document.getElementById("imageLink_" + idCurrentPhoto).style.display = "inline";
		document.getElementById("lbContentItem_" + idCurrentPhoto).style.display = "block";
		writeCurrentPhotoPaging();
	} else {
		//document.getElementById("imageLink_" + idCurrentPhoto).style.display = "none";
		document.getElementById("lbContentItem_" + idCurrentPhoto).style.display = "none";
		idCurrentPhoto = idTotalPhotos;
		//document.getElementById("imageLink_" + idCurrentPhoto).style.display = "inline";
		document.getElementById("lbContentItem_" + idCurrentPhoto).style.display = "block";
		writeCurrentPhotoPaging();
	}
}

var YellowIcon		= "images/icons/yellow_icon_dot.gif";
var RedIcon			= "images/icons/red_icon.gif";
var PurpleIcon		= "images/icons/purple_icon.gif";
var BlueIcon		= "images/icons/turquoise_icon_dot.gif";
var GreenIcon		= "images/icons/green_icon.gif";
var OrangeIcon		= "images/icons/orange_icon_dot.gif";
var VICIcon			= "images/icons/icon_vic_blank.gif";
var EntityList = [];
var bMapCreated 	= false;

function callAjax(loc, feat, type, clientid)
{
	var key = loc+'_'+feat+'_'+type;
	if(!EntityList[key])
		FeaturedEntitiesControlBase.GetFeaturedInformation(loc, feat, type, clientid, call_back);
	else
	{
		fillContent(EntityList[key].Title, EntityList[key].Details, EntityList[key].More, EntityList[key].Children, clientid);
	}
}


function call_back(response)
{
	var details = response.value
	if(details != null && details.length> 0)
	{
		fillContent(details[1],details[2],details[3],details[5], details[6])
		
		var newEntity = new FeaturedEntity(details[0]);
		newEntity.Title = details[1];
		newEntity.Details = details[2];
		newEntity.More = details[3];
		newEntity.Children = details[5];
		newEntity.ClientId = details[6];
		EntityList[newEntity.Key]=newEntity;	//associative array
	}
}


//This method does the work of filling in the content
function fillContent(title, details, more, children, clientId)
{
	var element = getElement(clientId+'_litColumn1Title');
	element.innerHTML = title;
	element = getElement(clientId+'_litDetails');
	element.innerHTML = details;
	element = getElement(clientId+'_litMoreTag');
	element.innerHTML = more;
	element = getElement(clientId+'_litChildList');
	var childList = '<ul>';
	if(!children)
		children = [];
	if(children && children != null && children != undefined)
	{
		for(var i=0; i < children.length; i++)
		{
			childList = childList + children[i];
		}
	}
	childList = childList + '</ul>';
	element.innerHTML = childList;
}

function callVideoAjax(vidId, plId)
{
	var key = vidId+'_'+plId;
	if(!EntityList[key])
		VideoPlayListControlBase.GetVideoInformation(vidId, plId, video_call_back);
	else
	{
		fillVideoContent(EntityList[key].Title, EntityList[key].PlayListTitle, EntityList[key].Description, EntityList[key].EmbedHtml, EntityList[key].Width, EntityList[key].Height, EntityList[key].PlayerLink, EntityList[key].SeeMoreLink);
	}
}

function video_call_back(response)
{
	var details = response.value
	if(details != null && details.length> 0)
	{
		fillVideoContent(details[1],details[2],details[3],details[4],details[5],details[6],details[7],details[8])

		var newEntity = new VideoEntity(details[0]);
		newEntity.Title = details[1];
		newEntity.PlayListTitle = details[2];
		newEntity.Description = details[3];
		newEntity.EmbedHtml = details[4];
		newEntity.Width = details[5];
		newEntity.Height = details[6];
		newEntity.PlayerLink = details[7];
		newEntity.SeeMoreLink = details[8];
		EntityList[newEntity.Key]=newEntity;	//associative array
	}
}

//This method does the work of filling in the content
function fillVideoContent(title, playlisttitle, description, embedhtml, width, height, playerlink, seeMoreLink)
{
	var element = getElement('featureVideoItem');
	try{
		
		if (playerlink != null && playerlink.length > 0)
		{
			$("featureVideoItem").style.display = "";
			$("featureImageItem").style.display = "none";
			
			makeMovie( playerlink, width, height, 'featureVideoItem', true);
		}
		else
		{
			$("featureImageItem").innerHTML = embedhtml;
			$("featureVideoItem").style.display = "none";
			$("featureImageItem").style.display = "";
		}

		element = getElement('videoCategory');
		element.innerHTML = playlisttitle.replace("&", "&amp;");
		element = getElement('featureVideoTitle');
		element.innerHTML = title;
		element = getElement('featureVideoTextContent');
		element.innerHTML = description;
		if(description.indexOf("featureVideoTextRemainingContent") > 0)
			$("featureVideoContainerVisibleToggle").style.display = "";
		else
			$("featureVideoContainerVisibleToggle").style.display = "none";
		element = getElement('spSeeMoreLink');
		element.innerHTML = seeMoreLink;
	}catch(err){}
}

//get the specified element off the page
function getElement(elName){
	var el = null;
	if (document.getElementById)
		el = document.getElementById(elName);
	else if (document.all)
		el = document.all[elName];
	return el;			
}

//custom object to hold the data
function FeaturedEntity(key)
{
	this.Key = key;
	this.Title = "";
	this.Details = "";
	this.More = "";
	this.Map = "";
	this.Children = new Array();
	this.ClientId = "";
}

//custom object to hold the data
function VideoEntity(key)
{
	this.Key = key;
	this.Title = "";
	this.PlayListTitle = "";
	this.Description = "";
	this.EmbedHtml = "";
	this.Width = 0;
	this.Height = 0;
	this.PlayerLink = "";
	this.SeeMoreLink = "";
}

// Set the center of the map and place the icon. If offset is set then we adjust the center
// by that amount of pixels - used when setting the center while the map is hidden.
function SetMapCenter(lat, long, name, regionid,  map, hosturl, targetURL, offsetx, offsety)
{
	map.checkResize();
	var icon = new GIcon(G_DEFAULT_ICON);  
	icon.image = hosturl + YellowIcon;
	map.clearOverlays();
	if(lat != 0 && long != 0)
	{
		var latlong = new GLatLng(lat, long);
		var marker = new GMarker(latlong, icon); 
		map.setCenter(latlong, 5);
		map.addOverlay(marker);
		GEvent.addListener(marker, "click", function()
		{
			window.location=targetURL;
		});
	}
	else
	{
		var address = name + ', BC, CA';
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(address,  function(point) 
		{
			if (!point) 
			{
				var defaultCentre = new GLatLng(54.22671256, -125.7585085);
				map.setCenter(defaultCentre, 4);
			}
			else 
			{
				var marker = new GMarker(point, icon); 
				map.addOverlay(marker);
				map.setCenter(point, 5);
				GEvent.addListener(marker, "click", function()
				{
					window.location=targetURL;
				});
			}
		})
	}
	if(targetURL)
	{
		var MapObject = map.getContainer();
		MapObject.onclick = new Function("window.location='"+targetURL+"';");
	}
	if((offsetx && offsetx > 0) || (offsety && offsety > 0)){
		var currCenter = map.fromLatLngToContainerPixel(map.getCenter());
		currCenter.x = currCenter.x - offsetx;
		currCenter.y = currCenter.y - offsety;
		map.setCenter( map.fromContainerPixelToLatLng(currCenter) );
	}
	HighlightRegionFromEncoded(regionid, false, false, map);
}

	
	
//Highlights the region specified by regionid
function HighlightRegionFromEncoded(regionid, centerandzoom, usemapdefaults, map)
{
	var source = "";
	var shape = null;
	
	//hide all regions except the selected one
	for(i=0;i<RegionInfoArray.length;i+=1) 
	{
		//do not remove BC outline
		if(i!=BCRegionID) 
		{
			if(RegionInfoArray[i])
			{
				RegionInfoArray[i].showRegion = false;
				if(RegionInfoArray[i].shape)
				{
					map.removeOverlay(RegionInfoArray[i].shape);
				}
			}
		}
	}
	//check if we have this overlay cached
	if(RegionInfoArray[regionid].shape)
	{
		RegionInfoArray[regionid].showRegion = true;
	}
	else 
	{
		var mypolygon = new GPolygon.fromEncoded({
				polylines: [
				{points: RegionInfoArray[regionid].encodedString,
				levels: RegionInfoArray[regionid].levels,
				color: RegionInfoArray[regionid].colour,
				opacity: 0.7,
				weight: 1,
				numLevels: RegionInfoArray[regionid].numlevels,
				zoomFactor: RegionInfoArray[regionid].zoomFactor}],
			fill: true,
			color: RegionInfoArray[regionid].colour,
			opacity: RegionInfoArray[regionid].opacity,
			outline: false
		});
		map.addOverlay(mypolygon);
		RegionInfoArray[regionid].shape = mypolygon;	
		RegionInfoArray[regionid].showRegion = true;	
	}
	
	//Draw the regions
	DrawRegions(map);
	if(centerandzoom)
	{
		if(usemapdefaults)
			map.setCenter(defaultCentre, defaultZoomLevel); 
		else
			map.setCenter(RegionInfoArray[regionid].centrePoint, RegionInfoArray[regionid].defaultZoomLevel);
	}
}

//STATIC: Draws regions whose LocationInfo.showRegion property is set to true
function DrawRegions(mapObject)
{
	for(i=0;i<RegionInfoArray.length;i+=1)
	{
		if(RegionInfoArray[i])
		{
			if(RegionInfoArray[i].showRegion == true)
			{
				mapObject.addOverlay(RegionInfoArray[i].shape);
			}
		}
	}
}


function getCookieVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
        endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
    }

    
    function GetCookie (name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
          return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
      }
      
      return null;
    }

    
    function SetCookie (name, value) {
      var argv = SetCookie.arguments;
      var argc = SetCookie.arguments.length;
      var expires = (argc > 2) ? argv[2] : null;
      var path = (argc > 3) ? argv[3] : null;
      var domain = (argc > 4) ? argv[4] : null;
      var secure = (argc > 5) ? argv[5] : false;
      document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
    }

	function DeleteCookie (name) {
      var exp = new Date();
      exp.setTime (exp.getTime() - 1);  // This cookie is history
      var cval = GetCookie (name);
      alert(cval);
      document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
    
function makeMovie( vidLink, width, height, divTag, allowFullScreen)
{
	/*
	var so = new SWFObject(vidLink, "", width, height, "8", "#000000" ); 
	if(allowFullScreen)
		so.addParam("allowFullScreen", "true"); 
	else	//daily motion cant be full screen if the wmode is opaque, this this must be excluded
		so.addParam("wmode", "opaque"); 

	so.addParam("allowscriptaccess", "always");
	so.addParam("redirectUrl", "http://www.adobe.com/go/getflashplayer");
	so.write(divTag); 
	*/
	
	var params = 
	{
		"wmode": "opaque",
		"allowscriptaccess": "always",
		"redirectUrl": "http://www.adobe.com/go/getflashplayer"
	}
	swfobject.embedSWF(vidLink, divTag, width, height, '8', '', '', params);
}


function ConfirmGeneratePDFListings(ConfirmationMessage, NavigateURL)
{
	if(confirm(ConfirmationMessage))location.href = NavigateURL;
}

function PreviewImage(imgURLTextField, headerImgSrc)
{
	jQuery(document).ready(function(){
	if(imgURLTextField!=null && jQuery("#" +imgURLTextField).val()!=null 
		&& jQuery("#" +imgURLTextField).val().length>0){ 
		var imgURL = jQuery("#" +imgURLTextField).val();
		jQuery("#" + headerImgSrc).attr("src", imgURL);
		if(jQuery("#" + headerImgSrc).css("display")=="none")
			jQuery("#" + headerImgSrc).show("slow");
		else
			jQuery("#" + headerImgSrc).hide("slow");
			
    }
  });
}

function ValidateOrder(ImageListName)
{
	var returnValue = true;
	var sequenceNumbersList="";
	jQuery("input[name*='txtImageOrder']").each(function (i) {
			if(sequenceNumbersList.indexOf("|" + jQuery(this).val())>-1){
				returnValue = false;
				alert("The order of the images needs to be unique.");
			}else{
				sequenceNumbersList=sequenceNumbersList+"|" + jQuery(this).val();
			}
      });

	return returnValue;
}

function validateFreeTextbox(id, expr, label)
{
	var str = "";
	var isValid = true;
	var errorLabel = document.getElementById(label);
	try{
		if (FTB_API != null){
			var objFTBControl = FTB_API[id];
			if (objFTBControl){
				str = objFTBControl.GetHtml();
			}
		}
		isValid = validate(stripHTML(str), expr);
		setErrorLabel(errorLabel, isValid);
	}
	catch(e){
		isValid = false;
		setErrorLabel(errorLabel, isValid);
	}
	return isValid;
}

function validateForm()
{


	var isValid = true;
	var isFieldValid = true;
	
	if(document.forms[0])
	{
		for(var i = 0; i < document.forms[0].elements.length; i++)
		{
			var el = document.forms[0].elements[i];
		
			if(el)
			{
				var expression = el.getAttribute("expression");
				var errorLabel = el.getAttribute("errorLabel");
				if(expression)
				{
					switch(el.type)
					{
						case "select-one":
							var operation = el.getAttribute("operation");
							if(!(isFieldValid=validateSelect(el, operation, expression)))
								isValid = false;
							break;
						case "text": case "textarea": case "hidden":
							if(!(isFieldValid=validate(el.value, expression)))
								isValid = false;
							break;
					}
					if(errorLabel)
						setErrorLabel(document.getElementById(errorLabel), isFieldValid);
				}
			}
		}
	}
	if(!isValid)
		alert("Please correct the highlighted fields");
	return isValid;
}

function validate(value, expr)
{
	var regExp = new RegExp(expr);
	return (value.length > 0 &&  value.search(regExp) > -1);
}

function validateSelect(el, operation, expr)
{
	var isValid = true;
	if(el)
	{
		switch(operation.toLowerCase())
		{
			case "greater than":
				isValid = (el.options[el.selectedIndex].value > expr);
				break;
		}
	}
	return isValid;
}

function setErrorLabel(el, isValid)
{
	if(el != null)
	{
		if(!isValid) el.className = "error";
		else el.className = "";
	}
}

function stripHTML(str)
{
	return str.replace(/(<([^>]+)>)/ig,""); 
}

function getFirstNumOfChars(str, maxlength)
{
	var words = str.split(" ");
	var returnStr = "";
	
	if(words != null)
	{
		for(var i = 0; i < words.length; i++)
		{
			var word = words[i];
			if(returnStr.length + word.length < maxlength){
				returnStr += word + " ";
			}
			else
				break;
		}
	}
	returnStr = returnStr.trim() + "...";
	return returnStr;
}

function addCommasToNumber(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}