function raktar(darab, id, von)
{
 $.post("http://www.szafarisport.hu/include/ajax/raktarkeszlet.php", {"db": darab, "id": id, "von": von});
}

function eladasdarab(id, darab)
{
 $.post("http://www.szafarisport.hu/include/ajax/eladas.php", {"id": id, "db": darab});
}

function vonalkod(kod){
 var table   = document.getElementById("kassza");
 var uressor = table.insertRow(1);
 
 var xmlhttp;
 try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
 catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
 catch (e) { try { xmlhttp = new XMLHttpRequest(); }
 catch (e) { xmlhttp = false; }}}
 xmlhttp.onreadystatechange=function()
  {
   if (xmlhttp.readyState==4 && xmlhttp.status==200){uressor.innerHTML=xmlhttp.responseText;}
  }
 xmlhttp.open("GET","./include/ajax/kassza.php?kod="+kod,true);
 xmlhttp.send(); 
 
 var mezok  = document.getElementById("vkod");
 mezok.focus();
 mezok.select();
}

function confirmbox(label,link)
	{
	if(confirm(label))
		{
		location.href=link;
		}
	}
	
function uresCheck(){


var szo = document.getElementById('keresoszo').value.replace(/^\s+|\s+$/g, '') ;
if (szo=="" || szo=="Termék keresés"){ 
  alert("Nem adtál meg keresőszót!");
  document.getElementById('keresoszo').focus();
  return false;
}
else{
  return true;
}

}

function calculateRowValue(id, mid, von){
 
    var egysegar   = document.getElementById('egysegar'+von+'_'+id+mid).value;    
    var darab      = document.getElementById('db'+von+'_'+id+mid).options[document.getElementById('db'+von+'_'+id+mid).selectedIndex].value;       
    var reszValue  = document.getElementById('reszar'+von+'_'+id+mid);

   //Pontozás részár 
   var rosszeg = ""+(egysegar * darab)+"";
   var prosszeg ="";
   if (rosszeg.length > 3)
   {
   for ( var i = 1; i <= rosszeg.length; i++) {
   prosszeg=rosszeg.charAt(rosszeg.length-i)+prosszeg;
   if ((i % 3 == 0) && i!=rosszeg.length) {prosszeg="."+prosszeg; }
   }
   reszValue.innerHTML = prosszeg + ' Ft';
   }
   else
   {
   reszValue.innerHTML = rosszeg + ' Ft';
   }        
    
    var totalValue = document.getElementById('osszar');
    var postaValue = document.getElementById('postakoltseg');

    var total = 0;  
    for (var i = 0; i < document.form_kosar.length; i++){   
    var ar = document.forms[0].elements[i].value;   
    var db = document.forms[0].elements[i+1].value;
    total = total + (ar * db);
    i=i+1;
    }  
     
    //postaköltség korigálás
    var posta = 0;
    if ( total <= 18000){ posta = 1700;}
    else if( total > 18000 && total <= 48000){ posta = 2000;}
    else if( total > 48000 && total <= 96000){ posta = 3500;}
    else { posta = 4500;}
    //Ajax frissítés
    $.post("http://www.szafarisport.hu/session.php", {"db": darab, "id": id, "von": von, "summa": total, "mid": mid});

    total = total + posta;
    
    var pposta;
    if (posta==1700) {pposta="1.700";}
    else if (posta==2000) {pposta="2.000";}
    else if (posta==3500) {pposta="3.500";}
    else {pposta="4.500";}
    postaValue.innerHTML = pposta + ' Ft';
    // --
    //Summa összeg
    var osszeg = ""+total+"";
    var posszeg ="";
    if (osszeg.length > 3)
    {
    for ( var i = 1; i <= osszeg.length; i++) {
    posszeg=osszeg.charAt(osszeg.length-i)+posszeg;
    if ((i % 3 == 0) && i!=osszeg.length) {posszeg="."+posszeg; }
    }
    }
    totalValue.innerHTML = '<b>' + posszeg + ' Ft</b>';
    //----  
} 

function rendezes(sport,alsport){
var rend = document.getElementById("rendezes").value;
if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();
}
else{xmlhttp=new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200){document.getElementById("termek").innerHTML=xmlhttp.responseText;}
}
xmlhttp.open("GET","./data/rendezes.php?sport=sport&alsport=alsport&rend="+rend,true);
xmlhttp.send();
} 

function leiras(von, id, lap){

var feher ='#F1F1F1';
var kek   ='#FFFFFF';

if(lap==2){
document.getElementById("title1").style.backgroundColor=feher;
document.getElementById("title2").style.backgroundColor=kek;
document.getElementById("title3").style.backgroundColor=feher;
}
else if(lap==1){
document.getElementById("title1").style.backgroundColor=kek;
document.getElementById("title2").style.backgroundColor=feher;
document.getElementById("title3").style.backgroundColor=feher;
}
else if(lap==3){
document.getElementById("title1").style.backgroundColor=feher;
document.getElementById("title2").style.backgroundColor=feher;
document.getElementById("title3").style.backgroundColor=kek;
}

if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();
}
else{xmlhttp=new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200){document.getElementById("leiras").innerHTML=xmlhttp.responseText;}
}
xmlhttp.open("GET","./data/leiras.php?von="+von+"&id="+id+"&lap="+lap,true);
xmlhttp.send();
} 

