function resizeme(){
	var left_size = document.getElementById("left").offsetHeight;
	var right_size = document.getElementById("right").offsetHeight;

	if(left_size<right_size){
		document.getElementById("left").style.height = right_size+20+"px";
	}
}

function printContents() {
	iWidth = window.screen.width;
	iHeight = window.screen.height;
    wt = 630;
    ht = 460;
    lt = (iWidth - wt) / 2;
    tp = (iHeight - ht) / 2;
    window.open("print.php", '', 'height='+ht+',width='+wt+',top='+tp+',left='+lt+',toolbar=no,resizable=no,scrollbars=yes'); 
}

function printFlash(file, width, height, id, transparency)
{
	if (transparency == true) {

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
					+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '
					+ 'width="'+width+'" height="'+height+'" id="'+id+'" align="middle">'
					+ '<param name="allowScriptAccess" value="sameDomain" />'
					+ '<param name="movie" value="'+file+'" />'
					+ '<param name="quality" value="high" />'
					+ '<param name="bgcolor" value="#ffffff" />'
					+ '<param name="wmode" value="transparent" />'
					+ '<embed src="'+file+'" quality="high" bgcolor="#ffffff" wmode="transparent"'
					+ ' width="'+width+'" height="'+height+'" name="'+id+'" align="middle"'
					+ ' allowScriptAccess="sameDomain" type="application/x-shockwave-flash"'
					+ ' pluginspage="http://www.macromedia.com/go/getflashplayer" />'
					+ '</object>');
	}
					
	else {

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
					+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '
					+ 'width="'+width+'" height="'+height+'" id="'+id+'" align="middle">'
					+ '<param name="allowScriptAccess" value="sameDomain" />'
					+ '<param name="movie" value="'+file+'" />'
					+ '<param name="quality" value="high" />'
					+ '<param name="bgcolor" value="#ffffff" />'
					+ '<param name="wmode" value="transparent" />'
					+ '<embed src="'+file+'" quality="high" bgcolor="#ffffff"'
					+ ' width="'+width+'" height="'+height+'" name="'+id+'" align="middle"'
					+ ' allowScriptAccess="sameDomain" type="application/x-shockwave-flash"'
					+ ' pluginspage="http://www.macromedia.com/go/getflashplayer" />'
					+ '</object>');
	}				
	
}

function preview(file, desc, width, height) {
 if (desc == null) {
   desc = '';
 }
 var left = (screen.width - width) / 2;
 var top = (screen.height - height + 20) / 2;
 window.open("preview.php?file="+file+"&desc="+desc, "_preview_", "width="+width+",height="+height+",top="+top+",left="+left);
}

var timer = null;

function startTimer() {
    timer = setTimeout('hideLocked()',1000);
}

function hideLocked() {
	var dymek = document.getElementById('dymek');
	dymek.style.visibility = 'hidden';
	clearTimer();
}

function locked(evt) {
	var dymek = document.getElementById('dymek');
	if (evt.pageX) {
		dymek.style.left = evt.pageX - 4 + 'px';
		dymek.style.top = evt.pageY - 4 + 'px';
	} else {
		dymek.style.left = evt.clientX + document.body.scrollLeft - 4 + 'px';
		dymek.style.top = evt.clientY + document.body.scrollTop - 4 + 'px';
	}
	dymek.style.visibility = 'visible';
	clearTimer();
}

function clearTimer() {
	if (timer != null) {
       clearTimeout(timer);
       timer = null;
    }
}

function getWindowHeight() {
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    return window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    return document.body.clientHeight;
  }
  return 0;
}
function getWindowWidth() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
//    return window.innerWidth - 20;
    return window.innerWidth;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    return document.body.clientWidth;
  }
  return 0;
}

function submitBMI() {
	height = document.getElementById('height').value;
	weight = document.getElementById('weight').value;

	var error = 0;
	document.getElementById('weight_err').innerHTML = document.getElementById('height_err').innerHTML = '';
	var err = '';
	var bmi = 0.0;
	var comment = '';
	var objRegExp = /^\d{2,3}$/
	if(!objRegExp.test(weight)) {
		error = 1;
		document.getElementById('weight_err').innerHTML = 'Niepoprawna wartość wagi<br>';
	}
	if(!objRegExp.test(height)) {
		error = 1;
		document.getElementById('height_err').innerHTML = 'Niepoprawna wartość wzrostu<br>';
	}
	if (error == 0) {
		bmi = Math.round(((10000 * weight) / (height * height)) * 10);
		if (bmi < 185) {
			comment = 'niedowaga';
		} else if (bmi < 250) {
			comment = 'prawidłowa masa ciała';
		} else if (bmi < 300) {
			comment = 'nadwaga';
		} else if (bmi < 350) {
			comment = 'I stopień otyłości';
		} else if (bmi < 400) {
			comment = 'II stopień otyłości';
		} else {
			comment = 'III stopień otyłości (ekstremalna)';
		}
		err = "Twój BMI: <span class='bmiscore'>" + (bmi / 10) + "</span> - " + comment;
	}
	document.getElementById('bmiscore').innerHTML = err;
	return false;
}

function submitWHR() {
	var waist = document.getElementById('waist').value;
	var hip = document.getElementById('hip').value;
	var gender = 'none';
	var error = 0;
	document.getElementById('waist_err').innerHTML = document.getElementById('hip_err').innerHTML = '';
	var err = '';
	var objRegExp = /^\d{2,3}$/
  var whr = 0.0;
	var comment = '';

	if (document.getElementById('male').checked) {
		gender = 'male';
	} else if (document.getElementById('female').checked) {
		gender = 'female';
	}

	if(!objRegExp.test(waist)) {
		error = 1;
		document.getElementById('waist_err').innerHTML = 'Niepoprawna wartość obwodu w talii<br>';
	}
	if(!objRegExp.test(hip)) {
		error = 1;
		document.getElementById('hip_err').innerHTML = 'Niepoprawna wartość obwodu w biodrach<br>';
	}
	if (gender == 'none') {
		err = err + 'Nie wybrano płci<br>';
	}
	if (error == 0) {
		whr = waist / hip;
		if (gender == 'male') {
			if (whr < 1.0) {
				comment = 'otyłość udowo-pośladkowa';
			} else {
				comment = 'otyłość wisceralna (brzuszna)';
			}
		} else {
			if (whr < 0.8) {
				comment = 'otyłość udowo-pośladkowa';
			} else {
				comment = 'otyłość wisceralna (brzuszna)';
			}
		}
		err = "Twój WHR: <span class='whrscore'>" + (Math.round(+whr * 100) / 100) + "</span> - " + comment;
	}
	document.getElementById('whrscore').innerHTML = err;
	return false;
}


with (navigator) if (appName.indexOf('Microsoft')!=-1 && appVersion.indexOf('Mac')==-1)
{
	document.write('<scr'+'ipt language="VBScript">\nMM_flash = NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash"))\n</scr'+'ipt>');
}

function MM_checkPlugin(plgIn)
{
  	var result = false;

 	if (navigator.appName.indexOf('Microsoft')==-1 || (navigator.plugins && navigator.plugins.length))
  	{
  		result = navigator.plugins[plgIn] != null ? true : false;
  	}
  	else
  	{
  		if (navigator.appName.indexOf('Microsoft')!=-1 && navigator.appVersion.indexOf('Mac')==-1)
		{
			result = MM_flash;
		}
	}
	result = result == true ? true : false;
	return result;  		
}

var flashExists = MM_checkPlugin("Shockwave Flash");


//flashExists = false;
function printTrialBase()
{
	document.write('<div class="tbbaner"><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+
					  'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"'+
					  'WIDTH="400" HEIGHT="100" id="trialbase" ALIGN="">'+
					  '<PARAM NAME=movie VALUE="images/trialbase.swf">'+
					  '<param name="wmode" value="transparent">'+
					  '<PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="images/trialbase.swf" wmode="transparent" quality=high bgcolor=#FFFFFF  WIDTH="400" HEIGHT="100" NAME="trialbase" ALIGN=""'+
					  'TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" wmode="transparent"></EMBED>'+
					  '</OBJECT></div>');
}
function printMovie(movie, mini, title)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
					+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '
					+ 'width="300" height="258" id="atero_tv" align="middle">'
					+ '<param name="allowScriptAccess" value="sameDomain" />'
					+ '<param name="movie" value="images/player_atero.swf" />'
					+ '<param name="quality" value="high" />'
					+ '<param name="bgcolor" value="#ffffff" />'
					+ '<param name="flashVars" value="film='+movie+'|'+title+'|'+mini+'" />'
					+ '<embed src="images/player_atero.swf" quality="high" bgcolor="#005586"'
					+ ' flashVars="film='+movie+'|'+title+'|'+mini+'"'
					+ ' width="300" height="258" name="atero_tv" align="middle"'
					+ ' allowScriptAccess="sameDomain" type="application/x-shockwave-flash"'
					+ ' pluginspage="http://www.macromedia.com/go/getflashplayer" />'
					+ '</object>');
}



function showNode(nazwa)
{
	element = document.getElementById(nazwa);
 
   if(element.style) {
      if(element.style.display == 'block' ){
         element.style.display = 'none';
      } else {
         element.style.display = 'block';
      }
   }
}

var calc = {
	score: function() {
		$('#submitScore').click(function(){
			$('#scoreForm').submit();
		}).hover(
			function(){
				$(this).removeClass('off').addClass('on');
			},
			function(){
				$(this).removeClass('on').addClass('off');
			}
		);
		$('#backScore').click(function(){
			$('#scoreBox').removeClass('scoreBack2').addClass('scoreBack1');
			$('#scoreRes').hide();
			$('#scoreBox .score2').hide();
			$('#scoreForm').show();
			$('#scoreBox .score1').show();
			$('#scoreForm #plecK').attr('checked', true);
			$('#scoreForm #wiek').getSetSSValue(1);
			$('#scoreForm #skurczowe').getSetSSValue(1);
			$('#scoreForm #cholesterol_mmol').getSetSSValue(1);
			$('#scoreForm #cholesterol_mg').getSetSSValue(1);
			$('#scoreForm #cholesterol_jedn').getSetSSValue(1);
			$('#scoreForm #paliN').attr('checked', true);
		}).hover(
			function(){
				$(this).removeClass('off').addClass('on');
			},
			function(){
				$(this).removeClass('on').addClass('off');
			}
		);
		$('#cholesterol_jedn').change(function(){
			if ($(this).val() == 'mmol') {
				$('#cholesterol_mg').next().hide();
				$('#cholesterol_mmol').next().show();
				$('#cholesterol_mmol').getSetSSValue($('#cholesterol_mg').getSetSSValue());
			}
			if ($(this).val() == 'mg') {
				$('#cholesterol_mmol').next().hide();
				$('#cholesterol_mg').next().show();
				$('#cholesterol_mg').getSetSSValue($('#cholesterol_mmol').getSetSSValue());
			}
		});
	    var options = { 
			target: '#scoreRes', 
 		    success: function(responseText, statusText, xhr, $form) {
				$('#scoreBox').removeClass('scoreBack1').addClass('scoreBack2');
				$('#scoreForm').hide();
				$('#scoreBox .score1').hide();
				$('#scoreRes').show();
				$('#scoreBox .score2').show();
			} 
		}; 
		$('#scoreForm').ajaxForm(options);
		$('#scoreForm input:radio').checkbox();
		$('#scoreForm select').sSelect();
		$('#scoreForm #cholesterol_mg').next().hide();
	}
}
