function sayfaAcilis() {

	pideKutulari = document.getElementsByTagName('input');
	for (i=0; i<pideKutulari.length; i++) {
		if (pideKutulari[i].type == "text") {
			pideKutulari[i].value = '0';	
		}
	}
	
	document.getElementById('toplamTutar').value = '0';
	
	MM_preloadImages('butonlar/buton_r1_c2_f2.gif','butonlar/buton_r3_c2_f2.gif','butonlar/buton_r5_c2_f2.gif','butonlar/buton_r7_c2_f2.gif','butonlar/buton_r9_c2_f2.gif','butonlar/buton_r11_c2_f2.gif','butonlar/buton_r13_c2_f2.gif','butonlar/buton_r15_c2_f2.gif');
	
}

function sepetEkle(pideNo) {
	
	toplamTutar = parseFloat(document.getElementById('toplamTutar').value);
	
	pideFiyatKutusu = 'fiyat_'+pideNo;
	pideFiyati = parseFloat(document.getElementById(pideFiyatKutusu).value);
	
	toplamTutar = toplamTutar+pideFiyati; 		
	
	pideKutusu = 'pide_'+pideNo;
	pideSayisi = document.getElementById(pideKutusu).value;
	document.getElementById(pideKutusu).value = parseFloat(pideSayisi)+1;
	document.getElementById('toplamTutar').value = toplamTutar.toFixed(2);
	document.getElementById('toplam').innerHTML = toplamTutar.toFixed(2); 
	
}

function sepetSil(pideNo) {
	
	pideKutusu = 'pide_'+pideNo;
	pideSayisi = document.getElementById(pideKutusu).value;
	
	pideFiyatKutusu = 'fiyat_'+pideNo;
	pideFiyati = document.getElementById(pideFiyatKutusu).value; 	
	
	if (pideSayisi != '0') {
		document.getElementById(pideKutusu).value = parseFloat(pideSayisi)-1;
		toplamTutar = parseFloat(document.getElementById('toplamTutar').value);
		toplamTutar = toplamTutar-pideFiyati;
		document.getElementById('toplamTutar').value = toplamTutar.toFixed(2);
		document.getElementById('toplam').innerHTML = toplamTutar.toFixed(2);	
	}
}

function siparisCheck() {

	if (parseFloat(document.getElementById('toplamTutar').value) == 0) {
		alert ('L'+String.fromCharCode(252)+'tfen sipari'+String.fromCharCode(351)+' etmek istedi'+String.fromCharCode(287)+'iniz pidelerin adedini yanlar'+String.fromCharCode(305)+'nda bulunan + ve - dü'+String.fromCharCode(287)+'melerine t'+String.fromCharCode(305)+'klayarak belirleyiniz ve a'+String.fromCharCode(351)+'a'+String.fromCharCode(287)+String.fromCharCode(305)+'da bulunan "Sipari'+String.fromCharCode(351)+' Ver" dü'+String.fromCharCode(287)+'mesine t'+String.fromCharCode(305)+'klay'+String.fromCharCode(305)+'n'+String.fromCharCode(305)+'z.');
		return false;
	} else {
		
		var siparisPideler = new Array();
		
		for (i=0; i<2; i++) {
			pideId = 'pide_'+i;
			if (parseFloat(document.getElementById(pideId).value) > 0) {
				siparisPideler[i] = Array();
				nameId = 'name_'+i;
				fiyatId = 'fiyat_'+i;
				pideTutar = parseFloat(document.getElementById(pideId).value)*parseFloat(document.getElementById(fiyatId).value);
				pideTutar = pideTutar.toFixed(2);
				siparisPideler[i]['isim'] = document.getElementById(nameId).value;
				siparisPideler[i]['miktar'] = document.getElementById(pideId).value;
				siparisPideler[i]['tutar'] = pideTutar;
			}
		}
		
		document.getElementById('siparisPideler').value = serialize(siparisPideler);
		document.forms.pidelerimiz.method = "POST";
		document.forms.pidelerimiz.action = "siparis.php";
		document.forms.pidelerimiz.submit();
	}	
}

function serialize( mixed_value ) {
    var _getType = function( inp ) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {
            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            match = cons.match(/(\w+)\(/);
            if (match) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {
        case "function": 
            val = ""; 
            break;
        case "undefined":
            val = "N";
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
            val = "s:" + mixed_value.length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") { 
                    continue; 
                }
                
                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
                vals += serialize(okey) +
                        serialize(mixed_value[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
    }
    if (type != "object" && type != "array") {
      val += ";";
  }
    return val;
}