function imgOn(imgName) {
	if (document.images) {
		document.images[imgName].src = eval(imgName + '1.src');
	}
}

function imgOff(imgName) {
	if (document.images) {
		document.images[imgName].src = eval(imgName + '0.src');
	}
}


// calendar rollover function
// 'tpos' = top position of rollover box; add or subtract 24 per row for mincal, 58 for cal
// 'lpos' = left position of rollover box; add or subtract 26 per column for mincal, 74 for cal

function calRollover(tpos,lpos) {
	if (document.getElementById) {
		document.getElementById('cal-rollover').style.display = 'block';
		document.getElementById('cal-rollover').style.marginTop = tpos + 'px';
		document.getElementById('cal-rollover').style.marginLeft = lpos + 'px';
	}
}

function calHide() {
	if (document.getElementById) {
		document.getElementById('cal-rollover').style.display = 'none';
	}
}


function lnavSearchSelect(linkName) {
	if (document.getElementById) {
		document.getElementById(linkName).style.color = '#000000';
		document.getElementById(linkName).style.fontWeight = 'bold';
		document.getElementById(linkName).style.textDecoration = 'none';
	}
}

function communitiesGo() {
Url=document.communities.com1[document.communities.com1.selectedIndex].value;
document.location = Url;
}

function locationGo() {
Url=document.communities.loc1[document.communities.loc1.selectedIndex].value;
document.location = Url;
}


$(document).ready(function() {

	if (document.getElementById('sub1')) {
		document.getElementById('sub1').style.display = 'block';
	}
	if (document.getElementById('sub2')) {
		document.getElementById('sub2').style.display = 'block';
	}

	var containerHeight = $('.content-gray').height();

	var modulesHeight = 0;
	$('.content-lc').children().each(function() {
							  modulesHeight = modulesHeight + $(this).height();
							});

	var lastModuleHeight = $(".content-lc .box-lc:last-child").height();

	$(".content-lc .box-lc:last-child").height(lastModuleHeight + (containerHeight - modulesHeight) - 14);

});

// Analytics tracking code for documents and external links
function setupAnalyticsTracking() {
	var links       = document.getElementsByTagName('a');

	var setup_link;
	for (var i = links.length; i != 0; i--) {
		setup_link = false;
		var a = links[i-1];
		if (!a.href) continue;

		// Track external links
		if(a.href.indexOf('http') != -1 &&
			a.href.indexOf(window.location.hostname) == -1){
			setup_link = true;
		}else if(isEmail(a.href)){
			setup_link = true;
		}else{
			// Track documents
			setup_link = isDocument(a.href);
		}

		if (setup_link){
			a.onclick = function() {
				track_url(this.href);
				return true;
			}

		}
	}
}

function isDocument(href){
	var track_files = new Array('.pdf', '.doc', '.PDF', '.DOC');
	for(var f = 0; f < track_files.length; f++){
		if(href.indexOf(track_files[f]) == (href.length - track_files[f].length)){
			return true;
		}
	}

	return false;
}

function isEmail(href){
	if(href.indexOf('mailto:') != -1){
		return true;
	}else{
		return false;
	}
}

function removeDomain(href){
	if(href.indexOf('http') != -1 && href.indexOf(window.location.hostname) != -1){
		href = href.substring((window.location.hostname.length + 7));
	}
	return href;
}

function removeHTTP(href){
	if(href.indexOf('http') != -1){
		href = href.substring(7);
	}
	return href;
}

function removeMailTo(href){
	if(href.indexOf('mailto:') != -1){
		href = href.substring(7);
	}
	return href;
}

function track_url(href) {
	if(window._gaq){
		if(isDocument(href)){
			_gaq.push(['_trackEvent', 'Misc Clicks', 'Document', href]);
		}else if(isEmail(href)){
			_gaq.push(['_trackEvent', 'Misc Clicks', 'MailTo', href]);
		}else{
			_gaq.push(['_trackEvent', 'Misc Clicks', 'External url', href]);
		}
	}
}


function setupExternalLinks() {
  var links = document.getElementsByTagName('a');
  for (var i = links.length; i != 0; i--) {
	var a = links[i-1];
	if (!a.href) continue;

	if (
			(a.href.indexOf('http') != -1 &&
			a.href.indexOf(window.location.hostname) == -1 &&
			!excludeUrl(a.href)) ||
			isDocument(a.href)
		)
	{
		a.target = "_blank";

	}
  }
}

function excludeUrl(url){
  var excludeUrls = Array(
			  );

  for(var l = 0; l < excludeUrls.length; l++){
	if(url.indexOf(excludeUrls[l]) == 0){
	  return true;
	}
  }

  return false;
}

function restoreInputFile(field_id){
	$('#' + field_id + '-input').show();
	$('#' + field_id + '-display').hide();
	$('#remove_' + field_id).attr('value', '1');
}

function openIEEEtv(URL) {
	newWindow = window.open(URL,"ieeeTV","scrollbars=no,resizable=no,HEIGHT=579,WIDTH=765");
	newWindow.focus();
	track_url(URL);
}

function showRWParticipants(type, location_id){
	if(type == "restaurants"){
		$('#restaurants-loc'+location_id).show(); 
		$('#retailers-loc'+location_id).hide();
		$('#restaurants-but-loc'+location_id).addClass('selected');
		$('#retailers-but-loc'+location_id).removeClass('selected');
	}else{
		$('#restaurants-loc'+location_id).hide(); 
		$('#retailers-loc'+location_id).show();
		$('#restaurants-but-loc'+location_id).removeClass('selected');
		$('#retailers-but-loc'+location_id).addClass('selected');
	}
	
}
