function submitForm(e) {
	$("#" + e.id).parent("FORM").submit();
}
function submitForm2(e) {
   $("#" + e).submit();
}

function setDate(date) {
	now = new Date();
	$("#target_date").attr({value : date});
	$("#cal_date").text(date);
   Date.format = 'yyyy-mm-dd';
   d = Date.fromString(date);

	if (d > now) {
		$(".ds").hide();
	} else {
		$(".ds").show();
	}
}

function setActive(e) {
	$(".cdays").each(function() {
		if ($(this).hasClass("c-active")) {
			$(this).removeClass("c-active");
		}
	})
	$(e).addClass("c-active");
}

function setData(e) {
	targ = $(e).find("SUP").text();
	
	clone = $(e).find("SPAN").clone();
	
	clone.find("SUP").empty();
	steps = clone.text();
	
	$("#cal_target_count").attr({
		value : targ
	});
	$("#cal_step_count").attr({
      value : steps
   });
   $("#cal_sport_count").empty();
	
}

function deleteAccount(id, cb_id) {
	if ($("#"+cb_id+":checked").val() !== null ) {
		$("#"+id).submit();
	}
}

function getElement(id) {
			var el = (document.all) ? document.all[id] : document.getElementById(id);
			return el;
}

function toggleElement(id) {
	if (id != null) {
		var el = getElement(id);
		if (el != null) {
			if (el.style.display == "none") {
				showElement(id);
			} else {
				hideElement(id);
			}
		}
	}
}

function toggleTeamResults() {
   var tbl = $("#results_team");
   tbl.find("DD").each(function(enumerator, el) {
      $(el).show();
   });
   tbl.find("DT").each(function(enumerator, el) {
      $(el).show();
   });
   $("#btn_show_teams").hide();
}

function toggleUserResults() {
var tbl = $("#results_user");
   tbl.find("DD").each(function(enumerator, el) {
      $(el).show();
   });
   tbl.find("DT").each(function(enumerator, el) {
      $(el).show();
   });
   $("#btn_show_users").hide();
}

function showElement(id) {
			getElement(id).style.display = 'block';
}


function hideElement(id) {
			getElement(id).style.display = 'none';
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
} 