
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 Noktaya_donustur(yer) {
 var xx = document.getElementById(yer).value;
 var yenixx = xx.replace(",",".");
    document.getElementById(yer).value = yenixx
}

function closeMessageDialog() {
	var dialog = document.getElementById('messageDialog');
	dialog.style.visibility = 'hidden'
	messageDialogVisible = false;
}

function messageDialog(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=mesajgoster";
    JXP(1, "messageDialog", "includes/islem.php", sc);
}

function closeZdefteriDialog() {
	var dialog = document.getElementById('messageDialog');
	dialog.style.visibility = 'hidden'
	messageDialogVisible = false;
}

function ZdefteriDialog(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=zdefterigoster";
    JXP(1, "messageDialog", "includes/islem.php", sc);
}


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;
}

/* 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 ) {

    }

	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
		   if (yer==0)
                window.location='bolum.php?name=urunler&s_op=sepet';
           else if (yer==1)
                window.location='bolum.php?name=urunler&s_op=sepet';
           else
              document.getElementById(yer).innerHTML = xmlHttp.responseText;
        }
		function getXmlHttp() {};
    }
}

function AnaSayfa_Ucret_Preorder_bilgisi(adet,fiyati,urunid,yer) {
 var sc = "urunid=" + urunid + "&fiyati=" + fiyati + "&urunadet=" + adet + "&iop=urunpreorder";
 if(yer==0)
     JXPDZ('0',"includes/islem.php", sc);
 else if(yer==1)
     JXPDZ('1',"includes/islem.php", sc);
 else
    JXPDZ('sepet_sayisi',"includes/islem.php", sc);
}



/* FLying to basket */

var flyingSpeed = 25;

var shopping_cart_div = false;
var flyingDiv = false;
var currentProductDiv = false;

var shopping_cart_x = false;
var shopping_cart_y = false;

var slide_xFactor = false;
var slide_yFactor = false;

var diffX = false;
var diffY = false;

var currentXPos = false;
var currentYPos = false;

var ajaxObjects = new Array();


function shoppingCart_getTopPos(inputObj)
{
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}

function shoppingCart_getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}


function addToBasket(adet,fiyati,urunid,yer)
{
	if(!shopping_cart_div)shopping_cart_div = document.getElementById('blok_sepet_main');
	if(!flyingDiv){
		flyingDiv = document.createElement('DIV');
		flyingDiv.style.position = 'absolute';
		document.body.appendChild(flyingDiv);
	}

	shopping_cart_x = shoppingCart_getLeftPos(shopping_cart_div);
	shopping_cart_y = shoppingCart_getTopPos(shopping_cart_div);

	currentProductDiv = document.getElementById('slidingProduct' + urunid);

	currentXPos = shoppingCart_getLeftPos(currentProductDiv);
	currentYPos = shoppingCart_getTopPos(currentProductDiv);

	diffX = shopping_cart_x - currentXPos;
	diffY = shopping_cart_y - currentYPos;



	var shoppingContentCopy = currentProductDiv.cloneNode(true);
	shoppingContentCopy.id='';
	flyingDiv.innerHTML = '';
	flyingDiv.style.left = currentXPos + 'px';
	flyingDiv.style.top = currentYPos + 'px';
	flyingDiv.appendChild(shoppingContentCopy);
	flyingDiv.style.display='block';
	flyingDiv.style.width = currentProductDiv.offsetWidth + 'px';
	flyToBasket(adet,fiyati,urunid,yer);
}


function flyToBasket(adet,fiyati,urunid,yer)
{

	var maxDiff = Math.max(Math.abs(diffX),Math.abs(diffY));
	var moveX = (diffX / maxDiff) * flyingSpeed;;
	var moveY = (diffY / maxDiff) * flyingSpeed;

	currentXPos = currentXPos + moveX;
	currentYPos = currentYPos + moveY;

	flyingDiv.style.left = Math.round(currentXPos) + 'px';
	flyingDiv.style.top = Math.round(currentYPos) + 'px';


	if(moveX>0 && currentXPos > shopping_cart_x){
		flyingDiv.style.display='none';
	}
	if(moveX<0 && currentXPos < shopping_cart_x){
		flyingDiv.style.display='none';
	}

	if(flyingDiv.style.display=='block') {
        setTimeout('flyToBasket('+adet+','+fiyati+','+urunid+',"'+yer+'")',10);
       // alert('flyToBasket("' + adet + ',' + fiyati + ',' + urunid + ',' + yer + '")');
	} else {
        AnaSayfa_Ucret_Preorder_bilgisi(adet,fiyati,urunid,yer);
	}

}