function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showHelp(url) {
  popupWin = window.open(url, 'Help','width=300,height=300,left=150,top=150,toolbar=no,status=no,scrollbars=yes,location=no');
}


// Used for expand/collapse of a div. 
// Corresponding images use the same ID as the div, but are
//	prefixed with "img_".
function ToggleDisplayElement(id)
{
	var path = "/Images/";

	if (document.getElementById)
	{
		thisElement = document.getElementById(id);
		thisImage = document.getElementById("img_" + id);
		
    	if (thisElement.style.display == "none")
		{
			thisElement.style.display = "block";
			thisImage.src = path + "arrowCollapse.gif";
		} 
		else 
		{
			thisElement.style.display = "none";
			thisImage.src = path + "arrowExpand.gif";
		}
		return false;
	}
}


// Redirect user to another page as specified in the value 
//	of selected item.
function JumpMenu(obj)
{
	var url = obj.options[obj.selectedIndex].value;
	if (url != null && url != "")
	{
		window.location.href = url;
	}
}

// 
function ResizeIFrame(iframeName, height)
{
	try 
	{
		//alert("before " + document.domain);
		document.domain = "transmission.bchydro.com";	
		//alert("after " + document.domain);
		if (document.getElementById)
		{
			var iframe = document.getElementById(iframeName);
			iframe.height = height + 20;  // add 20px to adjust for Mozilla/Netscape.
		}
	}
	catch (e) 
	{	}
}
/* -- This function needs to be available to the iframe source documents.
// Call parent page's resize method; pass in the parent's iframe name.
//	Use source document's body 
function CallParentResize(iframeName)
{
	try 
	{
		document.domain = "transmission.bchydro.com"; 

		if (iframeName == null || iframeName == "")
			iframeName = "htmlIFrame";
		
		if (document.getElementById)
		{
			var iFrame = window.parent.document.getElementById(iframeName);
			
			// If the specified (iframe) object is found, call the ResizeIFrame method.
			if (iFrame)
				window.top.ResizeIFrame(iFrame.name, document.body.scrollHeight);
		}
	}
	catch (e) 
	{	}
}
*/

// Redirect to search page with search key
function goSearch (searchFieldId)
{
	var searchField = document.getElementById(searchFieldId);
	var searchKey = searchField.value;
	if (searchKey.length > 0) {
		var searchUrl = "/_utilities/searchresults?queryText=" + searchKey;
		document.location = searchUrl;
	}
	else {
		alert ('Please enter a keyword to search');
	}	
}

// Redirect to search page with search key and search scope
function goScopeSearch (searchFieldId, scopeFieldId)
{
	var searchField = document.getElementById(searchFieldId);
	var searchKey = searchField.value;
	var scopeField = document.getElementById(scopeFieldId);
	var scope = scopeField.value;
	if (searchKey.length > 0) {
		var searchUrl = "/_utilities/searchresults?queryPrefix=url:" + scope + "&queryText=" + searchKey;
		document.location = searchUrl;
	}
	else {
		alert ('Please enter a keyword to search');
	}
}

function searchKeyEventHandler (e, isScope)
{
	var is_ie   = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
	var charCode = (is_ie) ? e.keyCode : e.which;
	if (charCode == 13) {
		if (isScope == null) {
			// global search (header user control)
			goSearch ('searchBox');
		}
		else {
			// scope search (search user control)
			goScopeSearch ('scopeSearchBox', 'Search_scopeUrl');
		}

		// cancel event - this removes the annoying ring
		if (is_ie)
			e.keyCode = 0;
		else
			e.which = 0;
	}
	return true;
}

function Redirect(url)
{
	var redirectionTextDivTag = document.getElementById('redirectionTextDiv');
	if (redirectionTextDivTag != null)
	{
		var html = redirectionTextDivTag.innerHTML;
		var anchor = "<a href='" + url + "'>here</a>";
		html = html.replace("{0}", anchor);
		redirectionTextDivTag.innerHTML = html;
		redirectionTextDivTag.style.display = "block";
		// alert (html);
	}

	var jsCommand = "window.location='" + url + "';"
	window.setTimeout(jsCommand, 5000);
}


function ShowAuthoringLabels()
{
	var divTags = document.getElementsByTagName("div");
	for (i=0; i < divTags.length; i++)
	{
		var thisDivTag = divTags.item(i);
		if (thisDivTag.id.toLowerCase().indexOf("authoringlabel") > -1)
		{
			// alert (thisDivTag.innerHTML);
			thisDivTag.style.display = "block";
		}
	}
	
/*
	var controlsCount = document.form.length;
	alert(controlsCount);
	for (i=0; i < controlsCount; i++)
	{
		if (form[i].id.toLowerCase().indexOf("authoringlabel") > -1)
		{
			alert (form[i].id);
			alert (form[i].value);
			alert (form[i].innerHTML);
			form[i].style.display = "block";
		}
	}
*/
}

		
	function ElementRequired(id)
{
	var tdTag = document.getElementById(id + "Required");
	if (tdTag != null)
	{
		tdTag.className = "required";
		switch (id)
		{
			case "Email" :
				var otherTdTag = document.getElementById("phoneRequired");
				if (otherTdTag != null)
					{
					otherTdTag.className = "";
					}
				break;
				
			case "Phone" :
				var otherTdTag = document.getElementById("emailRequired");
				if (otherTdTag != null)
					{
					otherTdTag.className = "";
					}
				break;
		}
	}
}
		