//***************************************************************************//
// IFrame functions
//***************************************************************************//
function getDocHeight(doc) 
{
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) 
  {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

// sets height of a parent IFrame (id=LinkFrame) from the child document
function goSetHeight(extraHeight) 
{
  if (parent == window) return;
  else 
  {
	var iframeEl = window.parent.document.getElementById? window.parent.document.getElementById('LinkFrame'): window.parent.document.all? window.parent.document.all['LinkFrame']: null;
	if ( iframeEl ) 
	{
		iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
		var docHt = getDocHeight(this.document);

		// need to add to height to be sure it will all show
		if (docHt) iframeEl.style.height = docHt + extraHeight + "px";
	}
  }
}

//***************************************************************************//
// open window functions
//***************************************************************************//
// open new window
function openWindow( newPage, pageName, newheight, newwidth)
{
	var w = getScreenwWidth();
	var h = getScreenwHeight();
	var leftPos = (w-newwidth)/2, topPos = (h-newheight)/2;
	var popup = window.open(newPage,pageName,'width=' + newwidth + ',height=' + newheight + ',resizable,scrollbars,top='+topPos+',left='+leftPos);

	//terry(21Mar2007): check for pop-up blocking
	if (!popup)
		alert("This application uses pop-up windows. Advertising or pop-up window blocking must be disabled.")
}

// open new window (scrollbars optional)
function openNSwindow( newPage, pageName, newheight, newwidth, newscrollbars)
{
	var w = getScreenwWidth();
	var h = getScreenwHeight();
	var leftPos = (w-newwidth)/2, topPos = (h-newheight)/2;
	var popupNS = window.open(newPage,pageName,'width=' + newwidth + ',height=' + newheight + ',resizable,status=yes,scrollbars=' + newscrollbars +',top='+topPos+',left='+leftPos);
	
	//terry(21Mar2007): check for pop-up blocking
	if (!popupNS)
		alert("This application uses pop-up windows. Advertising or pop-up window blocking must be disabled.")
	else
		popupNS.focus();
}

//***************************************************************************//
// sign permit application functions
//***************************************************************************//
// number of signs switching code
function loadNumberOfSigns(signCountDropDown, signTypeDropDown) 
{
	//try 
	//{
		var signCountList = eval('document.forms[0].' + signCountDropDown + '.options');
		var signTypeList = eval('document.forms[0].' + signTypeDropDown + '.options');
		var signType = signTypeList[signTypeList.selectedIndex].value;
		var signCountIndex = signCountList.selectedIndex;
		var intCount = 4;
		
		// clear list
		for (var i = signCountList.length; i > -1; i--) 
			signCountList[i] = null;
			
		//default: show "Is this the right sign type?" link
		document.getElementById('aViewSign').style.display = 'block';
			
		switch (signType) 
		{
			// 4 SIGNS MAX: Awning, Facia, Facia Electronic
			case '4590' : 
			intCount = 4;
			break;
			case ('4570'): 
			intCount = 4;
			break;
			case ('4922'): 
			intCount = 4;
			break;
			
			// 3 SIGNS MAX: Canopy, Marquee
			case '4610' : 
			intCount = 3;
			break;
			case '4917' : 
			intCount = 3;
			break;
			
			// 2 SIGNS MAX: Freestanding, Freestanding Electronic
			case '4560' : 
			intCount = 2;
			break;
			case '4921' : 
			intCount = 2;
			break;
			
			//hide "Is this the right sign type?" link
			default :
			document.getElementById('aViewSign').style.display = 'none';
			break;
		}
		
		//update signCountList with max count
		for(var i=0;i<intCount;i++)
		{
			var number = i+1;
			signCountList[i] = new Option(number.toString(), i+1);
		}
		
		if ((signCountIndex > intCount-1)||(signCountIndex == -1))
			signCountList.selectedIndex = 0;
		else
			signCountList.selectedIndex = signCountIndex;
	//}
	//catch(err) 
	//{
		// do nothing
	//}
}

//***************************************************************************//
// business licence application functions
//***************************************************************************//
function onProvinceChange(dropValue, txtBox, lbl)
{
	if (dropValue == 'XX')
	{
		//OTHER
		var other = document.getElementById(txtBox);
		other.style.display = "";
		other.value = "";
		document.getElementById(lbl).style.display = "";
	}
	else
	{
		var other = document.getElementById(txtBox);
		other.style.display = "none";
		other.value = "XX";
		document.getElementById(lbl).style.display = "none";
	}
}
			
function selectStreetName()
{
	var slct = document.getElementById('streetname');
	if (slct) 
	{ for (i=0; i < slct.options.length; i++) 
			{ if (slct.options[i].text == document.getElementById('hdnStreetName').value)
			slct.options[i].selected=true; 
		}
	}
}


//***************************************************************************//
// general functions
//***************************************************************************//
// print contents of window from button
function printWindow()
{
  window.print();
}

function getScreenwWidth()
{
	var w = screen.availWidth;
	if ((!w) || (w < 480)) w = 480
	return w;
}

function getScreenwHeight()
{
	var h = screen.availHeight;
	if ((!h) || (h < 340)) h = 340
	return h;
}

function limitTextarea(textareaID, maxlength) 
{
	var textarea = document.getElementById(textareaID);
	if (textarea.value.length > maxlength)
		textarea.value = textarea.value.substring(0, maxlength);
}

// for searching dropdowns
function filtery(pattern,list)
{
	pattern = new RegExp('^'+pattern,"i"); 
	i=0;
	sel=0;
	while(i<list.options.length)
	{
		if(pattern.test(list.options[i].text)){sel=i;break}
		i++;
	}
	list.options.selectedIndex=sel;
}

function setStreetnameDrp()
{
	var drp = document.getElementById('streetname');
	if (drp == null)
		drp = document.getElementsByName('streetname')[0]; 
	drp.options[0].text = '-- Pick Streetname --';
	drp.selectedIndex = 0;
}




