function SetBox(BoxID, ElementID){
	UnsetAllBoxes(BoxID);
	document.getElementById(ElementID + 'Button').className="Active";
	document.getElementById(ElementID + 'Button').firstChild.firstChild.src = StringReplace('box-title-inactive/', 'box-title/', document.getElementById(ElementID + 'Button').firstChild.firstChild.src);
	document.getElementById(ElementID + 'Box').style.display="block";
	ActiveArray[BoxID] = ElementID;
}

function UnsetAllBoxes(BoxID){
	for(k=0; k<BoxArray[BoxID].length; k++){
		document.getElementById(BoxArray[BoxID][k] + 'Button').className="Inactive";
		document.getElementById(BoxArray[BoxID][k] + 'Button').firstChild.firstChild.src = StringReplace('box-title/', 'box-title-inactive/', document.getElementById(BoxArray[BoxID][k] + 'Button').firstChild.firstChild.src);
		document.getElementById(BoxArray[BoxID][k] + 'Box').style.display="none";
	}
	ActiveArray[BoxID] = "";
}

function InitBox(BoxID, ElementID){
	if(typeof(BoxArray[BoxID]) == "undefined"){
		BoxID = BoxArray.length;
		BoxArray[BoxArray.length] = new Array();
		
		ActiveArray[ActiveArray.length] = new Array();
		ActiveArray[BoxID] = ElementID;
	}
	BoxArray[BoxID].push(ElementID);
}

function StringReplace(Needle, Patch, Haystack){
	Haystack = new String(Haystack);
	while(Haystack.indexOf(Needle)!= -1){
		Haystack = Haystack.substring(0, Haystack.indexOf(Needle)) + Patch + Haystack.substr(Haystack.indexOf(Needle)+Needle.length);
	}
	return Haystack;
}

function NextBox(BoxID){
	CurrentElement = ActiveArray[BoxID];
	UnsetAllBoxes(BoxID);
	for(k=0; k<BoxArray[BoxID].length; k++){
		if(BoxArray[BoxID][k] == CurrentElement){
			k++;
			if(k == BoxArray[BoxID].length) k = 0;
			SetBox(BoxID, BoxArray[BoxID][k]);
			return;
		}
	}
	return;
}

function PreviousBox(BoxID){
	CurrentElement = ActiveArray[BoxID];
	UnsetAllBoxes(BoxID);
	for(k=0; k<BoxArray[BoxID].length; k++){
		if(BoxArray[BoxID][k] == CurrentElement){
			k--;
			if(k == -1) k = BoxArray[BoxID].length-1;
			SetBox(BoxID, BoxArray[BoxID][k]);
			return;
		}
	}
	return;
}


function SubmitForm(FormID){
	document.getElementById(FormID).submit();	
}

function SendPage(){
	var SendWindow;
	SendWindow = window.open(BasePath + 'includes/site-send.php?url=' + escape(location.href), 'SendWindow', 'height=500, width=400');
}

function CalculateBMI(){
	Value = Math.round(document.getElementById('BodyWeight').value / (document.getElementById('BodyHeight').value/100 * document.getElementById('BodyHeight').value/100));
	document.getElementById('TableRESULT').innerHTML = Value;
	
	if(document.getElementById('BodyMALE').checked == true){
		document.getElementById('TableMALE').style.display = "block";
		document.getElementById('TableFEMALE').style.display = "none";
	} else if(document.getElementById('BodyFEMALE').checked == true){
		document.getElementById('TableMALE').style.display = "none";
		document.getElementById('TableFEMALE').style.display = "block";
	}
	
	document.getElementById('TableTotal').style.display = "block";
}
