strTopNavOn = '';
strSubMenuOn = '';
strLeftNavOn = '';
strOnID = '0';
mouseOn = 0;

function topNavOn (strID) {
	mouseOn = 1;
	
	if (document.getElementById('subselected'))	document.getElementById('subselected').style.visibility = 'hidden';

	if (strTopNavOn != '') {
		document.images['top' + strOnID].src = strTopNavOn;
	}
	strTopNavOn = String(document.images['top' + strID].src);
	document.images['top' + strID].src = strTopNavOn.substr(0, strTopNavOn.length-4) + '_ro.gif';

	if (strSubMenuOn != '')	document.getElementById(strSubMenuOn).style.visibility = 'hidden';

	if (document.getElementById('sub' + strID)) {
		document.getElementById('sub' + strID).style.visibility = 'visible';
		strSubMenuOn = 'sub' + strID;
	}
	else
		strSubMenuOn = '';

	strOnID = strID
}


function topNavOff () {
	mouseOn = 0;
	setTimeout('checkOff()', 250);
}


function subNavOn () {
	mouseOn = 1;
}


function subNavOff () {
	mouseOn = 0;
	setTimeout('checkOff()', 250);
}


function checkOff () {
	if (!mouseOn) {
		if (document.getElementById('subselected'))	document.getElementById('subselected').style.visibility = 'visible';
		if (strTopNavOn != '') document.images['top' + strOnID].src = strTopNavOn;
		if (strSubMenuOn != '') {
			document.getElementById(strSubMenuOn).style.visibility = 'hidden';
		}
	}
}

function leftNavOn (strID) {
	strLeftNavOn = String(document.images['ind' + strID].src);
	document.images['ind' + strID].src = strLeftNavOn.substr(0, strLeftNavOn.length-4) + '_ro.gif';
}

function leftNavOff (strID) {
	if (strLeftNavOn != '') document.images['ind' + strID].src = strLeftNavOn;
}

function InsightProduction() 
{ 
	var height = window.screen.availHeight - 55;
	var width = window.screen.availWidth - 10;
	eval("window.open('https://bi2.polk.com/insight.htm','PolkInsight_Production','width= " + width + ",height=" + height + ",top=1,left=1,toolbar=no,directories=no,menubar=no,resizable=yes, scrollbars=yes,status=yes,titlebar=yes');");
}


/////////////////////////////////////////////////////////////////////////////
// Search Functions

function SearchClickCMS ()
{
	var strTerms = document.getElementById('textSearch').value;
	if (strTerms != '') {
		window.location = '/Site/search.htm?terms=' + escape(strTerms);
	}
	else {
		alert('Please enter your search terms');
	}
}

function SearchKeyPressCMS(e, objText)
{
	var strTerms = objText.value;
	if (getKey(e) == 13) {
		StopBubbling(e);
		if (strTerms != '') {
			window.location = '/Site/search.htm?terms=' + escape(strTerms);
			return false;
		}
		else {
			alert('Please enter your search terms');
			return false;
		}
	}
	else {
		return true;
	}
}

function SearchClick ()
{
	var strTerms = document.getElementById('textSearch').value;
	if (strTerms != '') {
		window.location = '/Site/search_results.asp?terms=' + escape(strTerms);
	}
	else {
		alert('Please enter your search terms');
	}
}

function SearchKeyPress(e, objText)
{
	var strTerms = objText.value;
	if (getKey(e) == 13) {
		StopBubbling(e);
		if (strTerms != '') {
			window.location = '/Site/search_results.asp?terms=' + escape(strTerms);
			return false;
		}
		else {
			alert('Please enter your search terms');
			return false;
		}
	}
	else {
		return true;
	}
}

function getKey(e)
{
	if (window.event) {
		return window.event.keyCode;
	}
	else if (e) {
		return e.which;
	}
	else {
		return null;
	}
}

function StopBubbling(e)
{
	if(window.event && window.event.cancelBubble != null) {
		window.event.cancelBubble = true;
	}
	else if(e && e.stopPropogation) {
		e.stopPropogation();
	}
}	


/////////////////////////////////////////////////////////////////////////////
// Ugly hack to get IE to make TrafficBuilders fill 100% of the left column 
// below the left nav area (Mozilla and Opera work fine without this)

function setHeight()
{
     ht1 = document.getElementById('main').offsetHeight - document.getElementById('left').offsetHeight;
     ht2 = document.getElementById('hack').offsetHeight;
     if (ht2 < ht1)
	     document.getElementById('hack').style.height = ht1 +'px';
}


/////////////////////////////////////////////////////////////////////////////
// Value Calcluator Functions

var my = window.document.all;

function format(num, type) {
  var s;
  var t = parseFloat(num);
  t=isNaN(t)?0:t;
  if (t<0) {s='-';t=-1*t;} else s='';
  t = t.toString();
  var i = t.indexOf('.');
  if (type=='A') 
    {if (i<0) {i=t.length;t=t+'.00';} else {t=(t+'00').substr(0,i+3);}}
  else
    {if (i<0) i=t.length;}
  if (i>12) t=t.substr(0,i-12)+','+t.substr(i-12,3)+','+t.substr(i-9,3)+','+t.substr(i-6,3)+','+t.substr(i-3);
  else if (i>9) t=t.substr(0,i-9)+','+t.substr(i-9,3)+','+t.substr(i-6,3)+','+t.substr(i-3);
  else if (i>6) t=t.substr(0,i-6)+','+t.substr(i-6,3)+','+t.substr(i-3);
  else if (i>3) t=t.substr(0,i-3)+','+t.substr(i-3);
  return s+t; 
}

function calc() {

  if (my.rep_num.value=="" || my.sale_price.value=="")
  {
    alert("Please enter numbers for Value A and Value B.");
    return;
  }  
  
  var r, re;
  re = new RegExp("[$,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]");
  r = my.rep_num.value.match(re);
  if (r!=null)
  {
    alert("The Value A can only contain numbers.");
    my.rep_num.focus();
    return;
  }
  r = my.sale_price.value.match(re);
  if (r!=null)
  {
    alert("The Value B can only contain numbers.");
    my.sale_price.focus();
    return;
  }
 
  var n = parseInt(my.rep_num.value);
  var p = parseFloat(my.sale_price.value);

  if (isNaN(n) || isNaN(p)) return; 
  
  var c1 = n * p * 4.0;
  var c2 = n * p * 12.0;

  var t1 = "$" + format(c1,'A');
  var t2 = "$" + format(c2,'A');  

  my.calc1.innerText = t1;
  my.calc2.innerText = t2;  
  
  my.summary.innerHTML = "<b>Summary:</b> Using Polk Automotive data could produce "+ t1 +" to " + t2 + " in new revenue annually!";

  return;
}



