

var isLoaded = false;
function PreLoadImage() { 
	var l = PreLoadImage.arguments.length 
    for (var i = 0; i < l; i++) 
	{
		this[i+1] = new Image();
		this[i+1].src = PreLoadImage.arguments[i];
	}	 
  isLoaded = true;
}

function ShowImage(name,img)
{
	 document.images[name].src = img
   	 return 1;
}

function top()
{
	if (parent.main)
		parent.main.location.hash = "top";
}

function mySubmit(f,url)
{
	if (url != "")
	{ 
		f.action = url
		f.submit();
	}	
}

function wOpen(myPage,w,h,s)
{
	var wnd 
	wnd = window.open(myPage,'BAT','width='+ w +',height=' + h + ',top=40,left=40,resizable,scrollbars=' + s +',toolbar=no,status=no,directories=no,menubar=no,location=no');
}

function OpenWin(helpname,width,height)
{	
	var wnd
	wnd = window.open(helpname,'NT','width=' + width + ',height=' + height + ',top=100,left=300,resizable,scrollbars=yes,toolbar=no,status=no,directories=no,menubar=no,location=no');
	//wnd.opener = window;
	//return 1;
}

function radioSelect(myForm, src){
	var counter = 0;
	var objLength = myForm[src].length;
	
	for (i=0; i<objLength; i++){
		if (myForm[src][i].checked){
			counter = counter +1;
		}
	}
	if (!objLength) {
		counter = (myForm[src].checked) ? 1 : 0;
	}
	return counter ;
}
var selected_box;
function box_select(i)
{
	selected_box = i;
	if(i == 'dieta')
	{
		document.getElementById('box_dieta_tygodnia').style.display = "block";
		document.getElementById('dieta').style.backgroundPosition = "left top";
	}
	else
	{
		document.getElementById('box_dieta_tygodnia').style.display = "none";
		document.getElementById('dieta').style.backgroundPosition = "left bottom";
	}
	
	if(i == 'bmi')
	{
		document.getElementById('box_wskaznik_bmi').style.display = "block";
		document.getElementById('bmi').style.backgroundPosition = "left top";
	}
	else
	{
		document.getElementById('box_wskaznik_bmi').style.display = "none";
		document.getElementById('bmi').style.backgroundPosition = "left bottom";
	}
	
	if(i == 'kalorie')
	{
		document.getElementById('box_co_zjadles').style.display = "block";
		document.getElementById('kalorie').style.backgroundPosition = "left top";
	}
	else
	{
		document.getElementById('box_co_zjadles').style.display = "none";
		document.getElementById('kalorie').style.backgroundPosition = "left bottom";
	}
	
	if(i == 'fitness')
	{
		document.getElementById('box_gdzie_schudnac').style.display = "block";
		document.getElementById('fitness').style.backgroundPosition = "left top";
	}
	else
	{
		document.getElementById('box_gdzie_schudnac').style.display = "none";
		document.getElementById('fitness').style.backgroundPosition = "left bottom";
	}
	
	// ukrywamy wynik bmi jesli przechodzimy do inego boxa
	document.getElementById('box_wynik_bmi').style.display = "none";
}

function toogle_tab(menu_item, sel_box, state)
{
	if(sel_box != selected_box)
	{
		if(state == 1)
		{
			document.getElementById(menu_item).style.backgroundPosition = "left top";
		}
		else
		{
			document.getElementById(menu_item).style.backgroundPosition = "left bottom";
		}
	}
}


function onKeyPressNumbers(e)
{
   var key = window.event ? e.keyCode : e.which;
   var keychar = String.fromCharCode(key);
   reg = /\D/;			// nie liczba
   
   // jesli wcisnieto cos innego niz liczba lub Backspace (kod 8) wynikiem jest false
   return !reg.test(keychar) || key == 8 || key == 44 || key == 46 || key == 0;
}


function valid_email(email) {
var bad_char;
var bad_chars = " !#$%^&*()+|\=?/:,;";
 
      if (email == "") { 
			return false; 
		}
		
      for (i=0; i<bad_chars.length; i++) {		
      	bad_char=bad_chars.charAt(i)
	      if (email.indexOf(bad_char) != -1) {
	         return false;
	      }
      }
		
		if (email.indexOf("@") <= 0){
			return false;
		}
		
		 if (email.indexOf("@", email.indexOf("@")+1) != -1) { 
		 	return false; 
		}
		
		if (email.indexOf(".",email.indexOf("@")+1) == email.indexOf("@")+1) { // znak . zaraz po znaku @ w adresie email
   			 return false; 
		 }

		
		if (email.indexOf(".") <= 0){
			return false;
		}
		
      if((email.indexOf(".")+3) > email.length) { 
			return false; 
		} 

      return true
}