menuLeftTdImg      = new Image()
menuLeftTdImg.src  = 'img/tdLeft.gif';
menuRightTdImg     = new Image()
menuRightTdImg.src = 'img/tdRight.gif';


function openEvent(eID) {
	str = "resizeable=1,status=0,scrollbars=0,width=500,height=500";

  myWin = window.open("eventDetails.php?eID="+eID,"largeWin", str);
		
	myWin.focus();
//  myWin.resizeTo(400, 400);
}
function openWeightPlanner(eID) {
	str = "resizeable=1,status=0,scrollbars=0,width=500,height=500";

  myWin = window.open("WeightPlanner.php?eID="+eID,"largeWin", str);
		
	myWin.focus();
//  myWin.resizeTo(400, 400);
}
function openEcoPlanner(eID) {
	str = "resizeable=1,status=0,scrollbars=1,width=900,height=700";

  myWin = window.open("ecoPlanner.php?eID="+eID,"largeWin", str);
		
	myWin.focus();
//  myWin.resizeTo(400, 400);
}

function menuOver(idNo){
		document.getElementById("tdL"+idNo).style.backgroundImage   ="url('img/tdLeft.gif')";
    document.getElementById("tdL"+idNo).style.backgroundPosition="right";
    document.getElementById("tdL"+idNo).style.backgroundRepeat  ="no-repeat";
		document.getElementById("tdR"+idNo).style.backgroundImage   ="url('img/tdRight.gif')";
    document.getElementById("tdR"+idNo).style.backgroundPosition="left";
    document.getElementById("tdR"+idNo).style.backgroundRepeat  ="no-repeat";
}
function menuOut(idNo) {
		document.getElementById("tdL"+idNo).style.backgroundImage="none";
		document.getElementById("tdR"+idNo).style.backgroundImage="none";
}

function getEmail(pID) {
	str = "status=0,scrollbars=0,width=380,height=230";

  myWin = window.open("email.php?pID="+pID,"largeWin", str);
		
	myWin.focus();
  myWin.resizeTo(380, 230);
    
}
function getElementByName(pnt, str) {

  for(i=0;i<pnt.elements.length;i++) {
    if(pnt.elements[i].name == str) 
      return pnt.elements[i];
	}
}

function calcWeight() {
  var pnt = document.weightForm;
	var j=0;
	var noArr = Array();
	
	var incl = false;
	var sum = 0;
	var relIncrease = 0;
	
  for(var i=0;i<pnt.elements.length;i++) {
	  if(pnt.elements[i].name=='ID') {
		  noArr[j] = pnt.elements[i].value;
			j++;
		}
	}
		
  for(i=0;i<noArr.length;i++) {
	  obj = getElementByName(pnt,'ID'+noArr[i]);
		if(obj.checked) {
  	  obj  = getElementByName(pnt,'weight'+noArr[i]);
		  sum += (1*obj.value);
		}
	}

	totObj = getElementByName(pnt,'total');
	totObj.value = sum;
	
	targObj = getElementByName(pnt,'target');
	relIncrease = totObj.value/targObj.value;
	
  for(i=0;i<noArr.length;i++) {
	  obj = getElementByName(pnt,'ID'+noArr[i]);
		if(obj.checked) {
  	  objSug  = getElementByName(pnt,'weightSuggest'+noArr[i]);
  	  objInc  = getElementByName(pnt,'weightIncrease'+noArr[i]);
  	  obj     = getElementByName(pnt,'weight'+noArr[i]);
		  objSug.value = Math.round(obj.value/relIncrease*10)/10; 
		  objInc.value = Math.round((obj.value/relIncrease-obj.value*1)*10)/10;
			if(objInc.value>0)
			  objInc.value = '(+'+objInc.value+' kg)';
			else
			  objInc.value = '('+objInc.value+' kg)';
		}
	}
	
}
