
function calc_bodyfat(div) {
    vals = new Array();
    els = div.parentNode.getElementsByTagName("input");
    for (i=0;i<els.length;i++) {
	if (els[i].className.indexOf('box') !== -1) vals.push(els[i].value * 1); 
    }
    target = document.getElementById('ezcoa-347_body_fat');
    putin = get_body_fat_percentage(vals, (document.getElementById('ezcoa-345_age').value * 1));
    target.value = putin;
}

get_body_fat_percentage = function(skinfold, age)
{
var skinfold_sum = 0;
      for (var prop in skinfold)
   {
    skinfold_sum += skinfold[prop];
   }

    var bd = 1.112 - (0.00043499 * skinfold_sum) + (0.00000055 * Math.pow(skinfold_sum, 2)) - (0.00028826 * age);

    return (((4.95 / bd) - 4.5) * 100).toFixed(1);
}



 function EventWorker() {
   this.addHandler = EventWorker.addHandler;
 }


 EventWorker.addHandler = function (eventRef, func) {
  var eventHandlers = eval(eventRef);
  if (typeof eventHandlers == 'function') {
   eval(eventRef + " = function(event) {eventHandlers(event); func(event);}");  
  } else {
   eval(eventRef + " = func;");
  }
 }

 function getElementsByClass(node,searchClass,tag) {
   var classElements = new Array();
   var els = node.getElementsByTagName(tag); // use "*" for all elements
   var elsLen = els.length;
   var pattern = new RegExp("\\b"+searchClass+"\\b");
   for (i = 0, j = 0; i < elsLen; i++) {
     if ( pattern.test(els[i].className) ) {
       classElements[j] = els[i];
       j++;
     }
   }
   return classElements;
 }

 function firstRealSib(obj) {
   var output = obj;
   while (output == obj || output.nodeType == 3) {
      output = output.nextSibling;
   }
   return output;
 }

 function firstRealChild(obj) {
   var output = obj.firstChild;
   while (output.nodeType == 3) {
      output = output.nextSibling;
   }
   return output;
 }


function hideleft(obj) {
   var myAnim = new YAHOO.util.Anim(obj, { height: { to: 0 } }, .4, YAHOO.util.Easing.easeOut);
   myAnim.onComplete.subscribe(function(){ obj=this.getEl();obj.style.height = 'auto';obj.style.left = '-5000px';obj.style.position = 'absolute';});
   myAnim.animate(); 
}

function antihideleft(obj) {
   var start_height = obj.offsetHeight;
   obj.style.height = '0px';
   obj.style.left = '0px';
   obj.style.display = 'block';
   obj.style.position = 'relative';
   var myAnim = new YAHOO.util.Anim(obj, { height: { to: start_height } }, .4, YAHOO.util.Easing.easeOut);
   myAnim.animate(); 
}


function erase_text( thisForm, thisItem, thisText )
{
	document.forms[thisForm][thisItem].value = document.forms[thisForm][thisItem].value.replace(thisText, "");
}

fauxselect = function() {
   var uls = getElementsByClass(document, 'selectReplacement', 'UL');
   for (i in uls) {
   ul = uls[i];
   if (window.attachEvent) ul.onmouseover = function() {
      this.className += ' selHover';
    }
   if (window.attachEvent) ul.onmouseout = function() {
      this.className =
        this.className.replace(new RegExp(" selHover\\b"), '');
    }
   var opts = ul.getElementsByTagName('li');
   for (var i=0; i<opts.length; i++) {
   var li = opts[i]; 
      if (window.attachEvent) li.onmouseover = function() {
        this.className += ' selHover';
      }
      if (window.attachEvent) li.onmouseout = function() {
        this.className =
          this.className.replace(new RegExp(" selHover\\b"), '');
      }
      if (i>0) li.onclick = function() {document.flagform.reason.value = this.innerHTML;ajax_flagme();showwarns(this, 0)}
   }
   }
}

function showwarns(obj, id) {
    while (obj.className != 'attribute-name' &&  obj.className != 'flagme') {
	obj = obj.parentNode;
    }
    if (obj.className == 'attribute-name') obj = obj.nextSibling;
    if (obj.style.display == 'block') {
    obj.style.display = 'none';	
    } else {
    obj.style.display = 'block';	
    }
    obj.style.height = "180px";
    document.flagform.node_id.value = id;
}

function ajax_flagme(){
	var ajaxRequest;
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var flag_response = ajaxRequest.responseText;
			if (flag_response) {alert('Your complaint has been submitted. Thank you!');} else {alert('Request transmission error - please contact an administrator.');}
		}
	}
	ajaxRequest.open("GET", "/flagimage/submit/" + document.flagform.node_id.value + '/' + document.flagform.reason.value, true);
	ajaxRequest.send(null); 
}

