/**
 * 
 */

var subMenuCounts = new Array();

function showInfo(pageName) {
//	var pageName = window.location.hash.substr(1);
	
	window.location.hash = "#" + pageName;
	
	jQuery.get("infotexts/" + pageName + ".php", function(data) {
		document.getElementById("InfoText").innerHTML=data;
	});
	
};

function showSubNavBar() {
	var element = document.getElementById("Navigation");
	element.innerHTML += "\
			<div class=\"SubPageNavPane\">\
	 			<div onMouseOver=\"showSubMenu('info-why')\" onMouseOut=\"hideSubMenu('info-why')\" class=\"SubPageEntry\">\
	 				<a href=\"info-why.php\">Miksi mitata kehoa</a>\
	 				<div class=\"SubCategory\" id=\"info-why\">\
		 				<div><a href=\"info-why-exercise.php\">Liikuntatottumusten&nbsp;vaikutus</a></div>\
		 				<div><a href=\"info-why-nutrition.php\">Ruokailutottumusten&nbsp;vaikutus</a></div>\
		 			</div>\
				</div>\
	 			<div class=\"SubPageEntry\">\
				 	<a href=\"info-example-printout.php\">Malliraportti</a> \
				</div>\
				<div onMouseOver=\"showSubMenu('info-figures')\" onMouseOut=\"hideSubMenu('info-figures')\" class=\"SubPageEntry\">\
					<a href=\"info-figures.php\">Figuurit</a>\
		 			<div class=\"SubCategory\" id=\"info-figures\">\
			 			<div><a href=\"info-figures-display-female.php\">Naisfiguurit</a></div>\
			 			<div><a href=\"info-figures-display-male.php\">Miesfiguurit</a></div>\
		 			</div>\
				</div>\
				<div onMouseOver=\"showSubMenu('info-measurement')\" onMouseOut=\"hideSubMenu('info-measurement')\" class=\"SubPageEntry\">\
		 			<a href=\"info-measurement.php\">Figunet-mittaus</a>\
		 			<div class=\"SubCategory\" id=\"info-measurement\">\
			 			<div><a href=\"info-measurement-bioimpedance.php\">Tietoa&nbsp;bioimpedanssimittauksesta</a></div>\
		 			</div>\
	 			</div>\
		 </div>";
}

function showSubMenu(menuName) {
	if (isNaN(subMenuCounts[menuName])) {
		subMenuCounts[menuName] = 0;
	}
	subMenuCounts[menuName] += 1;
	checkSubMenu(menuName);
}

function hideSubMenu(menuName) {
	subMenuCounts[menuName] -= 1;
	checkSubMenu(menuName);
}

function checkSubMenu(menuName) {
	if (subMenuCounts[menuName] > 0) {
		document.getElementById(menuName).style.visibility = 'visible';
	} else {
		document.getElementById(menuName).style.visibility = 'hidden';
	}
}

function showInfoBox(e, component) {
	var evt = e || window.event;
	var infobox = document.getElementById("InfoBox");
	
	if (component == "Hints") {
		infobox = document.getElementById("InfoBoxLarge");
	}
	
	infobox.style.visibility = 'visible';
	infobox.innerHTML = document.getElementById(component + "Text").innerHTML;
	infobox.style.left = (evt.clientX + 20) + "px";
	infobox.style.top = (evt.clientY - 10) + "px";
}

function hideInfoBox() {
	document.getElementById("InfoBox").style.visibility = 'hidden';
	document.getElementById("InfoBoxLarge").style.visibility = 'hidden';
}

function getWindowSize() {
	var size = new Array();
  	if( typeof( window.innerWidth ) == 'number' ) {
  	  //Non-IE
  		size[0] = window.innerWidth;
    	size[1] = window.innerHeight;
  	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
    	size[0] = document.documentElement.clientWidth;
    	size[1] = document.documentElement.clientHeight;
    }
	return size;
}

function showRegister() {
	var winSize = getWindowSize();
	var rwindow = document.getElementById("RegisterWindow");
	
	var left = ((winSize[0] - 450) / 2);
	var top = ((winSize[1] - 500) / 2);
	if (left < 0) {
		left = 0;
	}
	if (top < 0) {
		top = 0;
	}
		
	rwindow.style.left = left + "px"
	rwindow.style.top = top + "px"
	rwindow.style.visibility = 'visible';
}

function hideRegister() {
	document.getElementById("RegisterWindow").style.visibility = 'hidden';
	document.RegisterForm.reset();
}

function checkAll(caller, name) {
	var list = caller.form.elements;
	for (i = 0; i < list.length; ++i) {
		if (list[i].name == name) {
			list[i].checked = caller.checked;
		}
	}
	
}

function confirmRemove(caller, name) {
	var list = caller.form.elements;
        var mids = new Array();
        
	for (i = 0; i < list.length; ++i) {
		if (list[i].name == name && list[i].checked) {
			mids[mids.length] = list[i].value;
		}
	}

        var text = "Haluatko varmasti poistaa omista mittauksistasi valitsemasi ";
        
        if (mids.length == 1) {
            text += "mittauksen " + mids[0] + "?";
        } else if (mids.length > 1) {
            text += mids.length + " mittausta?";
        } else {
            return;
        }
        
        var answer = confirm(text);
        if (answer) {
            document.forms["MeasurementForm"].elements['remove'].value = true;
//            var elem = document.createElement('<input type=hidden name=remove />');
//            document.forms["MeasurementForm"].appendChild(elem);
            document.forms["MeasurementForm"].submit();
//            caller.form.submit();
        }
}

function PrintTrends(server) {
    window.open("http://" + server + "/vercon/printtrendpage.php");
}

