// minimum menu rendeles az akcios arhoz - PHP bol lehet allitani
var minMenuCount = 0;

// menu ar - PHP bol lehet allitani
var menuPrice = 0;

// kosar ossz ertek dekl.
var sumPrice = 0;

// az osszes normal menu ar amit a sumPrice-hez hozzaadott, ha menu ar valtas van, akkor ezt vonja le
var menuPriceSum = 0;

// osszes rendelt menu
var omcS = 0;

// mar menuarral szamol?
var menuCh = false;

// felso ársáv beállítás
function setSumPrice(minus, plus) 
{
    var sumPrice = document.getElementById('sumPrice');
    //alert('setSumPrice: ' + minus + ' - ' + plus);
    sumPrice.value = parseInt(parseInt(sumPrice.value) - minus);
    sumPrice.value = parseInt(parseInt(sumPrice.value) + plus);
}

function opbp(href,w,h,title){
  var rand= 'ra'+Math.floor(Math.random()*1000000);
  body='<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">';
  body+='<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"hu\" xml:lang=\"hu\">';
  body+='<head><title>'+title+'</title></head><body style=\"margin: 0; width: 100%; overflow: hidden;\">';
  body+='<img src=\"'+href+'\" />';
  body+='</body>';
  body+='</html>';
  pu=window.open('',rand,'width='+w+',height='+h);
  pu.document.write(body);
}

function chbg(col){
  document.bgColor="#ffffff";
}

function opu(href,w,h){
  var rand= 'ra'+Math.floor(Math.random()*1000000);
  window.open(href,rand,'width='+w+',height='+h);
}
/*
function ocu(id,aktiv){
  var st = 'oc_' + id;
  var x = document.getElementById(st);

  if (id.charAt(0)=='d' && id.substr(1,1)=='1') {
    // osszes rendelt menu
    omcS++;
  }
  
  // ha menu es 0 van belole rendelve es menu1
  if (id.charAt(0)=='d' && parseInt(x.value)==0 && id.substr(1,1)=='1'){
    // globalis megrendelt menuk szamanak novelese
    omc++;
    // ha tobb mint 4 glob. megrendelt menu van, akkor akcios arat allit
    if (omc==minMenuCount){
      for (i=0; i<menus.length; i++){
        wit('mpr_'+menus[i],'580 Ft<br><br><a href="#miert"><span style="font-size: 10px; font-weight: normal; font-decoration: underline; font-color: blue;">Miért 580 Ft?</span></a>');
      }
      
    }
  }
  
  // osszertek allitas
  var prO = eval('fPrice' + id);
  // ha menu es menu1
  if (id.charAt(0)=='d' && id.substr(1,1)=='1') {
    
    //alert('omcS:' + omcS + '; omc: ' + omc + '; minMenuCount: ' + minMenuCount + '; menuPrice: ' + menuPrice);
    
    // ha pont most valtott FEL
    if (omc == minMenuCount && omcS >= minMenuCount && !menuCh) {  
    
        menuCh = true;
        
        //alert('A MENU1 ára ' + menuPrice + ' FT lett');
        // levonja az eddigi normál menu arakat
        setSumPrice(menuPriceSum, 0);
        // hozzaadja tobbszor az akcios menu arat
        setSumPrice(0, omcS * menuPrice);

        // a menu normal arat hozzaadja mindig
        menuPriceSum += parseInt(prO);
        
    // ha akcios ar
    } else if (omc >= minMenuCount && menuCh) {
        //alert('akcios ar');
        setSumPrice(0, menuPrice);     

        // a menu normal arat hozzaadja mindig
        menuPriceSum += parseInt(prO);
        
    // normal ar
    } else {
        //alert('normal ar');
        setSumPrice(0, parseInt(prO));

        // a menu normal arat hozzaadja
        menuPriceSum += parseInt(prO);
    }

  } else {
    setSumPrice(0, parseInt(prO));
  }
  
  //alert('normal arak osszesen: ' + menuPriceSum);
  
  //if (parseInt(x.value) < 9) 
  x.value = parseInt(x.value) + 1;
  ch_obj_cla('mc_'+id, aktiv);  
}*/

//továbbfejlesztett ocu a féladagok miatt
function ocu(id,aktiv,tipus){
	var st = 'oc_' + tipus + "_" + id;
	var x = document.getElementById(st);

	if (id.charAt(0)=='d' && id.substr(1,1)=='1') {
		// osszes rendelt menu
		omcS++;
	}

	// ha menu es 0 van belole rendelve es menu1
	if (id.charAt(0)=='d' && parseInt(x.value)==0 && id.substr(1,1)=='1'){
		// globalis megrendelt menuk szamanak novelese
		omc++;
		// ha tobb mint 4 glob. megrendelt menu van, akkor akcios arat allit
		if (omc==minMenuCount){
			for (i=0; i<menus.length; i++){
				wit('mpr_'+menus[i],'580 Ft<br><br><a href="#miert"><span style="font-size: 10px; font-weight: normal; font-decoration: underline; font-color: blue;">Miért 580 Ft?</span></a>');
			}

		}
	}

	// osszertek allitas
	if(tipus == 'egesz')
	{
		var prO = eval('fPrice_egesz_' + id);
	}
	else if (tipus == 'fel')
	{
		var prO = eval('fPrice_fel_' + id);
		//prO = Math.round(parseInt(prO)/2);
	}
	// ha menu es menu1
	if (id.charAt(0)=='d' && id.substr(1,1)=='1') {

		//alert('omcS:' + omcS + '; omc: ' + omc + '; minMenuCount: ' + minMenuCount + '; menuPrice: ' + menuPrice);

		// ha pont most valtott FEL
		if (omc == minMenuCount && omcS >= minMenuCount && !menuCh) {

			menuCh = true;

			//alert('A MENU1 ára ' + menuPrice + ' FT lett');
			// levonja az eddigi normál menu arakat
			setSumPrice(menuPriceSum, 0);
			// hozzaadja tobbszor az akcios menu arat
			setSumPrice(0, omcS * menuPrice);

			// a menu normal arat hozzaadja mindig
			menuPriceSum += parseInt(prO);

			// ha akcios ar
		} else if (omc >= minMenuCount && menuCh) {
			//alert('akcios ar');
			setSumPrice(0, menuPrice);

			// a menu normal arat hozzaadja mindig
			menuPriceSum += parseInt(prO);

			// normal ar
		} else {
			//alert('normal ar');
			setSumPrice(0, parseInt(prO));

			// a menu normal arat hozzaadja
			menuPriceSum += parseInt(prO);
		}

	} else {
		setSumPrice(0, parseInt(prO));
	}

	//alert('normal arak osszesen: ' + menuPriceSum);

	//if (parseInt(x.value) < 9)
	x.value = parseInt(x.value) + 1;
	ch_obj_cla('mc_'+id, aktiv);
}


// ujratoltes utan ha a globalisan megrendelt menuk szama tobb mint negy akkor atallitja az akcios arat
function chk_postomc(){
    if (omc == minMenuCount) {
        for (i = 0; i < menus.length; i++){
            wit('mpr_'+menus[i], '580 Ft<br><br><a href="#"><span style="font-size: 10px; font-weight: normal; font-decoration: underline; font-color: blue;">Miért 580 Ft?</span></a>');
        }
        menuCh = true;
    }
}

// OrderedCountDown
/*function ocd(id,rendelheto){
  st='oc_'+id;
  x=document.getElementById(st);
  

  if (id.charAt(0)=='d' && id.substr(1,1)=='1') {
    // osszes rendelt menu
    omcS--;
  }  
  
  // ha menu es minimum egy van rendelve belole es menu1
  if (id.charAt(0)=='d' && parseInt(x.value)==1 && id.substr(1,1)=='1'){
    // globalis megrendelt menuk szamanak csokkentese
    omc--;
    var omcC = true;
    // ha kevesebb mint 4 menu van rendelve globalisan akkor visszaall az eredeti arra
    if (omc < minMenuCount) {
      for (i=0; i<menus.length; i++){
        wit('mpr_'+menus[i],oprice[menus[i]]+' Ft');
      }
    }
  } else {
    var omcC = false;
  }
   
  // osszertek allitas
  if (parseInt(x.value) > 0) {
      var prO = eval('fPrice' + id);
      // ha menu es menu1
      if (id.charAt(0)=='d' && id.substr(1,1)=='1') {
      
        // ha pont most valtott LE
        if (omc == minMenuCount - 1 && omcC && menuCh) {
            
            //alert('menuSumPrice: ' + menuPriceSum + '; menuPrice: ' + menuPrice + '; omc: ' + omc + '; omcS: ' + omcS);
            
            menuCh = false;
            
            menuPriceSum -= parseInt(prO);
            //alert('valtas lefele - minus: ' + (omcS + 1);
            // levonja tobbszor az akcios menu arat
            setSumPrice((omcS + 1) * menuPrice, 0);
            // hozzáadja a normal arakat
            setSumPrice(0, menuPriceSum);
            
        // ha meg mindig akcios, levonja az akcios arat
        } else if (omc >= minMenuCount) {
            setSumPrice(menuPrice, 0);     
            menuPriceSum -= parseInt(prO);    
            
        // normal ar
        } else {
            setSumPrice(parseInt(prO), 0);
            menuPriceSum -= parseInt(prO);    
        }

      } else {
        setSumPrice(parseInt(prO), 0);
      }
  }
  
  if (parseInt(x.value)>0) x.value = parseInt(x.value)-1;
  if (parseInt(x.value)==0) ch_obj_cla('mc_'+id,rendelheto);
  
}*/
// OrderedCountDown továbbfejlesztve a féladagok miatt
function ocd(id,rendelheto,tipus){
	var st = 'oc_' + tipus + "_" + id;
	x=document.getElementById(st);
	
	var st2;
	if (tipus == "egesz")
	{
		st2 = 'oc_fel_' + id;
	}
	else if (tipus == "fel")
	{
		st2 = 'oc_egesz_' + id;
	}
	
	var x2 = document.getElementById(st2);
	
	if (id.charAt(0)=='d' && id.substr(1,1)=='1') {
		// osszes rendelt menu
		omcS--;
	}

	// ha menu es minimum egy van rendelve belole es menu1
	if (id.charAt(0)=='d' && parseInt(x.value)==1 && id.substr(1,1)=='1'){
		// globalis megrendelt menuk szamanak csokkentese
		omc--;
		var omcC = true;
		// ha kevesebb mint 4 menu van rendelve globalisan akkor visszaall az eredeti arra
		/*if (omc < minMenuCount) {
			for (i=0; i<menus.length; i++){
				wit('mpr_'+menus[i],oprice[menus[i]]+' Ft');
			}
		}*/
	} else {
		var omcC = false;
	}

	// osszertek allitas
	if (parseInt(x.value) > 0) {
		// osszertek allitas
		if(tipus == 'egesz')
		{
			var prO = eval('fPrice_egesz_' + id);
		}
		else if (tipus == 'fel')
		{
			var prO = eval('fPrice_fel_' + id);
			//prO = Math.round(parseInt(prO)/2);
		}
		// ha menu es menu1
		if (id.charAt(0)=='d' && id.substr(1,1)=='1') {

			// ha pont most valtott LE
			if (omc == minMenuCount - 1 && omcC && menuCh) {

				//alert('menuSumPrice: ' + menuPriceSum + '; menuPrice: ' + menuPrice + '; omc: ' + omc + '; omcS: ' + omcS);

				menuCh = false;

				menuPriceSum -= parseInt(prO);
				//alert('valtas lefele - minus: ' + (omcS + 1);
				// levonja tobbszor az akcios menu arat
				setSumPrice((omcS + 1) * menuPrice, 0);
				// hozzáadja a normal arakat
				setSumPrice(0, menuPriceSum);

				// ha meg mindig akcios, levonja az akcios arat
			} else if (omc >= minMenuCount) {
				setSumPrice(menuPrice, 0);
				menuPriceSum -= parseInt(prO);

				// normal ar
			} else {
				setSumPrice(parseInt(prO), 0);
				menuPriceSum -= parseInt(prO);
			}

		} else {
			setSumPrice(parseInt(prO), 0);
		}
	}

	if (parseInt(x.value)>0) x.value = parseInt(x.value)-1;
	if ((parseInt(x.value)==0)&&(parseInt(x2.value)==0)) ch_obj_cla('mc_'+id,rendelheto);

}
function ocum(id,arr){
  for (i=0; i<arr.length; i++) ocu(arr[i]);
  st='oc_'+id;
  x=document.getElementById(st);
  if (parseInt(x.value)<9) x.value=parseInt(x.value)+1;
  ch_obj_cla('mc_'+id,'m_v2');
}

function ocdm(id,arr){
  for (i=0; i<arr.length; i++) ocd(arr[i]);
  st='oc_'+id;
  x=document.getElementById(st);
  if (parseInt(x.value)>0) x.value=parseInt(x.value)-1;
  if (parseInt(x.value)==0) ch_obj_cla('mc_'+id,'m_v1');
}

function wit(id,text){
	if (document.getElementById){
    obj = document.getElementById(id);
    obj.innerHTML = '';
		obj.innerHTML = text;
	}
	else if (document.all){
		obj = document.all[id];
		obj.innerHTML = text;
	}
	else if (document.layers){
		obj = document.layers[id];
		obj.document.open();
		obj.document.write(text);
		obj.document.close();
	}
}

function ch_obj_cla(id,bgcolor){
	if (document.getElementById){
        var x = document.getElementById(id);
        x.style.backgroundColor = bgcolor;
        //x.className = cla;
	}
}


var menus = new Array(0);
var omc = 0;
var oprice = new Array(0);

