
	
var div_id = 'szukanie';    //nazwa przesuwanego menu

var top_offset = 0;   //pozycja po przesunieciu
var absolute_top = 0; //pozycja startowa
var offset_ie=0;

var xstep = .4;        //im wiecej tym szybciej porusza sie menu - dlugosc kroku
var delay_time = 50;   //im wiecej tym wolniejszy ruch - opoznienie pomiedzy krokami

//rozpoznanie przegladarki
var ie=document.all?1:0;
var ns4=document.layers?1:0;
var w3c=document.getElementById?1:0;
var mac_ie=ie&&((navigator.appVersion.indexOf("Mac")!=-1)&&(navigator.appVersion.substring(0,3)>=4.5)&&(navigator.appVersion.substring(0,1)<=5))?1:0;

var ie6=ie&&(navigator.appVersion.indexOf("MSIE 6")!=-1);

//uruchomienie ruchu
function onloader(){

	div_idel=document.getElementById(div_id);

	if(mac_ie)window.onscroll=loopfunc;
	else setInterval('loopfunc()',delay_time);
	
	
}
//funkcja ruchu
function loopfunc(){

	if(mac_ie){
		if(document.body.scrollTop<absolute_top)
			div_idel.style.pixelTop=absolute_top;
		else
			div_idel.style.pixelTop=document.body.scrollTop+top_offset;
	}else if(ie){
		if(document.body.scrollTop<absolute_top){	
			var dif=parseInt((absolute_top-div_idel.offsetTop)*xstep);
		} else {
			if(offset_ie==0){
				offset_ie=parseInt(div_idel.style.top);
			}		
			if(ie6){
				var dif=parseInt((parseInt(document.body.scrollTop)-parseInt(div_idel.style.top))*xstep);							
			} else {
				var dif=parseInt((parseInt((document.documentElement||document.body).scrollTop)-parseInt(div_idel.style.top))*xstep);	
			}
		}		

		if(dif!=0){
			div_idel.style.top=(parseInt(div_idel.style.top)+dif)+"px";		
			//div_idel.style.pixelTop+=dif;		
		}

	}else if(ns4){
		if (window.pageYOffset<absolute_top)
			var dif=parseInt((absolute_top-eval('document.'+div_id+'.top'))*xstep);
		else
			var dif=parseInt((window.pageYOffset+top_offset-eval('document.'+div_id+'.top'))*xstep);
		if(!isNaN(dif)&&(dif!=0))eval('document.'+div_id+'.pageY+='+dif);
	}else if(w3c){
		if (window.pageYOffset<absolute_top)
			var dif=parseInt((absolute_top-parseInt(div_idel.style.top))*xstep);
		else
			var dif=parseInt((window.pageYOffset+top_offset-parseInt(div_idel.style.top))*xstep);
		if(dif&&(dif!=0)) {
			div_idel.style.top=(parseInt(div_idel.style.top)+dif)+"px";
		}
	}
}



function returnValid(){

  if ( document.Muesli.ItemsUsed.value > 16 && tval >0 ) {
		alert("You are exciding 100%, please check values!\n\rYou should use no more then 16 ingredients!");	
 		return false;			
	} else if (document.Muesli.recName.value=="" ){
  	alert("Please type in the name for your recipe!");
 		return false;
 	} else if (document.Muesli.PercUsed.value<100 ){
  	alert("Please fill 100% of your recipe!");
 		return false;		
	}	else {
		return true;
	}	
}

function CutDigits (dval, dig){
	x=dval*dig;
	y=x % 10;
	x=x-y;
	if (y>=5) { 
		x=x+10;
	}
	x=x/dig; 
	return x; 		
}

storePerc=0;
storeItems=0;
storePrice=0;

function ValueCheck (tval, pval){
  if (tval.value!=0) {
   	storePerc=parseFloat(tval.value);
   	storeItems=1; 
   	storePrice=(((parseFloat(pval.value))*parseFloat(tval.value))/100);
  } else {
   	tval.value="";
  }		
}

function ValueCheck2 (wval, tval, pval){

  wval.value=parseFloat(wval.value);		
	if (wval.value==0) {
		wval.value="";
		tval.value="0";
	} else {
		tval.value=Math.round(wval.value/10);
	}
	
	ValueCheck (tval, pval);
	
}


function MainT(tval, pval, wobj, cval,pobj){

	//} else {
	
  	if (tval!="0") { 
      document.Muesli.ItemsUsed.value = parseFloat(document.Muesli.ItemsUsed.value)+1-storeItems; 
    } else {
      if (storePerc!=tval) {
      	document.Muesli.ItemsUsed.value= parseFloat(document.Muesli.ItemsUsed.value)-storeItems;
      }
    }     
    
    wobj.value=parseFloat(tval)*10;        
		document.Muesli.PercUsed.value= CutDigits((parseFloat(document.Muesli.PercUsed.value)+parseFloat(tval)-storePerc),1000);
    document.Muesli.PercLeft.value= CutDigits((100-parseFloat(document.Muesli.PercUsed.value)),100);

    if (cval.value!=13){
      document.Muesli.Fruit.value= CutDigits((parseFloat(document.Muesli.Fruit.value)+parseFloat(tval)-storePerc),1000);
    }
    document.Muesli.PriceM.value= CutDigits((parseFloat(document.Muesli.PriceM.value)+(((parseFloat(pval.value))*parseFloat(tval))/100)-storePrice),10000);

	//}
	
  if ( document.Muesli.ItemsUsed.value > 16 && tval >0 ) {
	
  	//alert("Number of ingredients can not exceed 16!");
    //pobj.value="0";
		//wobj.value=0;
		alert("You are exciding 100%, please check values!\n\rYou should use no more then 16 ingredients!");
		
	}
				

}

function ValueUpdate2 (pobj, pval, wobj, cval){

	wval=wobj.value;
	
	if (isNaN(wval)  || (wval<0) ) {
	
		alert("Please make sure that the field contains only numerical values!");
	 	wobj.value=storePerc*10;
		pobj.value=Math.round(wval/10);		
			
	} else {
	
		wval=parseFloat(wval);	
		pobj.value=Math.round(wval/10);
		if(isNaN(pobj.value)){
			pobj.value=0;
		}
		ValueUpdate (pobj, pval, wobj, cval);
	
	}
	
   storePerc=0;
   storeItems=0; 
   storePrice=0;		
		
}	

function ValueUpdate (pobj, pval, wobj, cval){

	if(pobj.value==''){
		pobj.value=0;
	}		
	
	tval=pobj.value;		
	tval=parseFloat(tval)
			
	
	if (isNaN(tval)  || (tval<0) ) {
	
		alert("Please make sure that the field contains only numerical values!");
	 	pobj.value=storePerc;
		wobj.value=storePerc*10;
		
	} else {
	
	  if (tval==""){
	    pobj.value="0";
	    tval="0";
	  }
		
	  x=CutDigits((parseFloat(document.Muesli.PercUsed.value)+parseFloat(tval)-storePerc),1000);
		
	  if (x>100){
		
	  	alert("Inserted percentage can not exceed 100!");
	   	pobj.value=storePerc;
			wobj.value=storePerc*10;
			
	  } else {
	    MainT(tval, pval, wobj, cval,pobj);
	  }
		
	}
	
   storePerc=0;
   storeItems=0; 
   storePrice=0;

}

