
function getXmlHttp() {
    var xmlHttp = false;

   // Internet Explorer (5.0+)
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlHttp = false;
      }

   }
   // Mozilla veya Safari
   if ( !xmlHttp && typeof XMLHttpRequest != 'undefined' ) {

     try{
        xmlHttp = new XMLHttpRequest();
     }catch(e) {
        xmlHttp = false;
     }
   }
   // Diger (IceBrowser)
   if ( !xmlHttp && window.createRequest ) {
	 try{
        xmlHttp = window.createRequest();
     }catch(e) {
        xmlHttp = false;
     }
   }
	return xmlHttp;
}

function JXP(yukleniyor, yer, dosya, sc) {
	xmlHttp = new getXmlHttp();

	if (xmlHttp) {
	   	xmlHttp.onreadystatechange = function () {}
	   	xmlHttp.abort();
	}

    xmlHttp.onreadystatechange = function () {	Loading(yukleniyor, yer) }

	xmlHttp.open('POST', dosya, true)
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
   	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8')
    xmlHttp.setRequestHeader("Content-length", sc.length)
    xmlHttp.setRequestHeader("Connection", "close")
    xmlHttp.send(sc)

}

function Loading(yukleniyor, yer) {
	if(yukleniyor == 1 && yer != 'no_id' ) {
		if( xmlHttp.readyState == 1 || xmlHttp.readyState == 2 || xmlHttp.readyState == 3 ) {

		}
	}
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
            document.getElementById(yer).innerHTML = xmlHttp.responseText;
        } else {
            document.getElementById(yer).innerHTML = '<strong>HATA:</strong> ' + xmlHttp.statusText;
        }
		function getXmlHttp() {};
    }
}

function Sehir_Sec(ulke) {
    var sc = "ulkeadi=" + ulke;
    sc += "&iop=ulkesec";
    JXP(1, "sehiryeri", "../includes/islem.php", sc);
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) 	{
		while (obj.offsetParent) 		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) 	{
		while (obj.offsetParent) 		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function Nick_kontrolu(kullanici) {
 var sc = "mesajid=" + kullanici + "&iop=nickkontrol";
    JXP(1, "nickikontrol", "../includes/islem.php", sc);

}

function closeMessageDialog() {
	var dialog = document.getElementById('messageDialog');
	dialog.style.visibility = 'hidden'
	messageDialogVisible = false;
}

function Yon_Siparis_Kontrol(n) {
	var dialog = document.getElementById('messageDialog');

	var x = findPosX(document.getElementById('messageIcon'+n)) ;
	var y = findPosY(document.getElementById('messageIcon'+n)) + 24;

    dialog.style.top = y + 'px';
    dialog.style.left = x + 'px';
	dialog.style.visibility = 'visible';
    var sc = "mesajid=" + n + "&iop=siparisgoster";
    JXP(1, "messageDialog", "includes/islem.php", sc);
}

function Preorder_Urunleri_Sil(silinecek_idler,kalan_urunsayisi) {
   var sc = "silinenidler=" + silinecek_idler + "&iop=urunpreorder_sil";
   JXP(1, "anasepet_yeri", "../includes/islem.php", sc);
   document.getElementById('sepet_sayisi').innerHTML=kalan_urunsayisi;
}

function Select_JXP(yer, dosya, sc) {
// bu fonksiyon select'in içeriğini doldurmak için yazıldı
xmlHttp = new getXmlHttp();

	if (xmlHttp) {
	   	xmlHttp.onreadystatechange = function () {}
	   	xmlHttp.abort();
	}

    xmlHttp.onreadystatechange = function () {	Select_Loading(yer) }

	xmlHttp.open('POST', dosya, true)
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
   	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8')
    xmlHttp.setRequestHeader("Content-length", sc.length)
    xmlHttp.setRequestHeader("Connection", "close")
    xmlHttp.send(sc)

}

function Select_Loading(yer) {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            var list=document.getElementById(yer);
            var ayrac=response.split('|');

            while (list.childNodes[0]) {
              list.removeChild(list.childNodes[0])
            }

            for (i=1; i<ayrac.length; i++) {

            // gelen değer |118,deniz YIKILMAZ şeklidendir
            // | işareti id ve isim birleşik önce bunu ayırıyoyoruz
            // , işareti ise önce select option value = degerayrac[0] değer sonraki ise optionda gözüken bölüm
               var degerayrac=ayrac[i].split(',');

               var x=document.createElement('option');
              // var y=document.createTextNode(ayrac[i]);
               var y=document.createTextNode(degerayrac[1]);

               x.appendChild(y);
               list.appendChild(x);
               x.value = degerayrac[0];

               }
        }
    }
}

function AltKategori_Secimi(ustkategori) {
var sc = "ustkategori=" + ustkategori + "&iop=altkategorisec";
Select_JXP("altcat", "includes/islem.php", sc);
}

function Arama_AltKategori_Secimi(ustkategori) {
var sc = "ustkategori=" + ustkategori + "&iop=aramaaltkategorisec";
Select_JXP("altcat", "../includes/islem.php", sc);
}

function AnaMenuGoster(menuno,menusayisi) {

    for (var i=0;i<menusayisi;i++) {

      if (i != menuno){
        document.getElementById('sagmenu_altkategorioncesi_'+i).style.display = 'none';
      } else {
        document.getElementById('sagmenu_altkategorioncesi_'+i).style.display = 'block';
      }


    }
}


/* sepet için özel JXP yazıldı */

function JXPDZ(yer, dosya, sc) {
	xmlHttp = new getXmlHttp();

	if (xmlHttp) {
	   	xmlHttp.onreadystatechange = function () {}
	   	xmlHttp.abort();
	}

    xmlHttp.onreadystatechange = function () {	DZLoading(yer) }

	xmlHttp.open('POST', dosya, true)
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
   	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8')
    xmlHttp.setRequestHeader("Content-length", sc.length)
    xmlHttp.setRequestHeader("Connection", "close")
    xmlHttp.send(sc)

}

function DZLoading(yer) {

    if( xmlHttp.readyState == 1 || xmlHttp.readyState == 2 || xmlHttp.readyState == 3 ) {
        var loading = '<img src="../images/loading.gif" width="16" height="16" alt="Yukleniyor ..." />'
    	document.getElementById(yer).innerHTML = loading;

    }

	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
            document.getElementById(yer).innerHTML = xmlHttp.responseText;
            window.location='../sepet/';
        } else {
            document.getElementById(yer).innerHTML = '<strong>HATA:</strong> ' + xmlHttp.statusText;
        }
		function getXmlHttp() {};
    }
}

function Ucret_Preorder_bilgisi(adet,fiyati,urunid) {
 var sc = "urunid=" + urunid + "&fiyati=" + fiyati + "&urunadet=" + adet + "&iop=urunpreorder";
 JXPDZ("sepet_sayisi", "../includes/islem.php", sc);
}

function Urun_Aktif_Pasif_Yap(urunid,aktiflik) {
   var sc = "urunid=" + urunid + "&aktiflik=" + aktiflik + "&iop=urunaktifpasif";
   JXP(1, "urunaktifpasifyeri_" + urunid, "includes/islem.php", sc);
}
