
// max # number of price grids (it's ok if there are less than this # on the page)
var numPriceGrids = 8;

// run setupTabs() from page before analytics code runs, so that menus work sooner
//addLoadEvent(setupTabs);

function updatePriceGrid(div) {
	// hide all price grids and reset all grid tabs to class name "grid-tab"
	for (i = 1; i <= numPriceGrids ; i++){
		g = "providergrid-" + i;
		if ($e(g)) {
			$e(g).style.display = "none";
		}
		gt = "grid-tab-" + i;
		if ($e(gt)) {
			$e(gt).className = "grid-tab";
		}
	}	
	// show the right one
	iDiv = (div.id).replace(/grid-tab-/,"");
	iDiv = "providergrid-" + iDiv;
	$e(iDiv).style.display = "block";
	div.className='grid-tab-selected';
}

function setupTabs() {

	tabs = getElementsByClass("tab");
	for (i=0;i<tabs.length;i++) {	
		tabs[i].onmouseover = function() {
			this.className='tab-on';
		}
		tabs[i].onmouseout = function() {
			this.className='tab';
		}
	}
	tabsActive = getElementsByClass("tab-active");
	for (i=0;i<tabsActive.length;i++) {
		tabsActive[i].onmouseover = function() {
			this.className='tab-active-on';
		}
		tabsActive[i].onmouseout = function() {
			this.className='tab-active';
		}
	}	

// Provider Grid Tabs
	if (getElementsByClass("grid-tab")) {
		gridTabs = getElementsByClass("grid-tab");
		for (i=0;i<gridTabs.length;i++) {	
			gridTabs[i].onmouseover = function() {
				if (this.className != 'grid-tab-selected') {
					this.className='grid-tab-over';
				}
			}
			gridTabs[i].onmouseout = function() {
				if (this.className != 'grid-tab-selected') {
					this.className='grid-tab';
				}
			}
			gridTabs[i].onclick = function() {
				if (this.className != 'grid-tab-selected') {
					updatePriceGrid(this);
				}
			}
		}
	}
	// above grabs elements by class name "grib-tab" - we also need to setup "grid-tab-active" w/ mouseover, etc.
	if (getElementsByClass("grid-tab-selected")) {
		gridTabSelected = getElementsByClass("grid-tab-selected");
		gridTabSelected[0].onmouseover = function() {
			if (this.className != 'grid-tab-selected') {
				this.className='grid-tab-over';
			}		
		}
		gridTabSelected[0].onmouseout = function() {
			if (this.className != 'grid-tab-selected') {
				this.className='grid-tab';
			}	
		}
		gridTabSelected[0].onclick = function() {
			if (this.className != 'grid-tab-selected') {
				updatePriceGrid(this);
			}
		}
	}

} 

function showLightBox(planType,scKey,packageID,scpId) {
	$s('lightbox').display='block';
	$s('fade').display='block';
	
	if (!planType) {
		planType = "Enter Your Address to Get Exact Plans and Prices";
	}
	if (!scKey) {
		scKey = "bundleMyServices";
	}

	lbForm = $e('LB-selfReg');
	actionUrl = lbForm.action.replace(/\?.*/,'');
	newAction = actionUrl + '?scKey=' + scKey;
	lbForm.action = newAction;	

	if (packageID) {
		$e('LB-packageID').value = packageID;
	}
	if (scpId) {
		$e('LB-scpId').value = scpId;
	}
	if (planType) {
		$e('LB-plan-type').innerHTML = planType;
	}
	
	// detect if IE6 or earlier, if so we have to use javascript to replicate the CSS property - position:fixed;
	var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	if (IE6) {
		
		// if ie, there are 2 ways to get scroll offset (depending on 'standards compliance mode').  check for first, if not found use the second
		if (document.documentElement.scrollTop) {
			yScroll = document.documentElement.scrollTop;
		} else {
			yScroll = document.body.scrollTop;
		}

		top = parseInt(yScroll) + 180;
		$s('lightbox').position = "absolute";
		$s('lightbox').top = top + "px";
		
	}		
	
	var x,y,x1,y1,x2,y2;
	
	// get body dimensions
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		x1 = document.body.scrollWidth;
		y1 = document.body.scrollHeight;
	}
	else // Explorer Mac;
	     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		x1 = document.body.offsetWidth;
		y1 = document.body.offsetHeight;
	}
	
	// get window dimensions
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		x2 = window.innerWidth;
		y2 = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		x2 = document.documentElement.clientWidth;
		y2 = document.documentElement.clientHeight;
	} 

	// whichever is larger (body or window dimensions), use that value to set width + height of black overlay
	x = (x1 > x2) ? x1 : x2;
	y = (y1 > y2) ? y1 : y2;
	
	w = x + "px";
	h = y + "px";
	
	$s('fade').width = w;
	$s('fade').height = h;
}

function hideLightBox() {
	$s('lightbox').display='none';
	$s('fade').display='none';
}

function showLoadingBox() {
	$s('lightbox').display='none';
	$s('loading-box').display='block';
	// this need to be here for non-lightbox pages (that don't already have fade showing)
	$s('fade').display='block';
}

function hideLoadingBox() {
	$s('loading-box').display='none';
	$s('fade').display='none';	
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	if (classElements.length > 0) {
		return classElements;
	} else {
		return false;
	}
}

function $e(id) {
	return document.getElementById(id);
}

function $s(id) {
	return document.getElementById(id).style;
}

function hide(id) {
	$s(id).display = "none";
}

function show(id) {
	$s(id).display = "block";
}
function toggle(v) { 
	$s(v).display=($s(v).display=='none'?'block':'none'); 
}


