
function keyPressHandler()
{
  	if (window.event.keyCode == '27')
  		hideShoppingCart();
}
function checkAddToShoppingCart(product_id)
{
	var elm = document.getElementById('stock_type');
	if (elm.value == '')
	{
		alert('Lütfen Almak İstediğiniz Ürünün Niteliklerini Seçiniz!');
		elm.focus();
		return false;
	}
	addToShoppingCart(product_id,elm.value);
	return true;
}
function addToShoppingCart(idx,stock_id)
{
	showShoppingCartStatus = 1;
	showTransparentLayer();
	centerElement('img_loading');
	addShoppingCart(idx,stock_id);
	
	return false;
}
function delAllShoppingCart()
{
	showShoppingCartStatus = 1;
	cleanShoppingCart();
	
	//showShoppingCart();
	return false;
}
function editShoppingCartCount(idx, stock_id, type)
{
	if(window.parent.location.href.indexOf('shopping_cart') != '-1')
		window.parent.location = 'basket.php?op=edit&id=' + idx + '&stock_id=' + stock_id + '&type=' + type;
	else
		window.location = 'basket.php?op=edit&id=' + idx + '&stock_id=' + stock_id + '&type=' + type;
	return false;
}
function deleteFromShoppingCart(idx, stock_id)
{
	window.location = 'basket.php?op=del&id=' + idx + '&stock_id=' + stock_id;
	return false;
}
function showFeatProdInfo(content)
{
	document.getElementById('feat_prod_info_inner').innerHTML = content;
	document.getElementById('feat_prod_info').style.display = 'block';
}
function hideFeatProdInfo()
{
	document.getElementById('feat_prod_info').style.display = 'none';	
}

/* HTTP REQUEST FUNCTIONS */

var xmlHttp;
var elmDiv;
var elmImg;
var showShoppingCartStatus = 0;
var refIsShowShoppingCart = 0;

function GetXmlHttpObject()
{
	var xmlHttp = null;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
	
	if (xmlHttp == null)
	{
		alert ('Internet Tarayıcınız HTTP REQUEST Desteklemiyor!');
		return false;
	}
	
	return xmlHttp;
}
function stateChanged()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.status == 200) 
		{
			document.getElementById(elmDiv).style.display = 'block';
			document.getElementById(elmDiv).innerHTML = xmlHttp.responseText;
			document.getElementById(elmImg).style.display = 'none';
			
			if(refIsShowShoppingCart)
			{
				refIsShowShoppingCart = 0;
				shoppingCartScroll();
			}
			
			if(showShoppingCartStatus)
			{
				showShoppingCartStatus = 0;
				showShoppingCart();
			}
		}
		else
		{
			alert('Hata Oluştu!');
		}
	}
}
function showProductDescription(idx)
{ 
	xmlHttp = GetXmlHttpObject()
	if(!xmlHttp)
	{
		return;
	}
	
	elmDiv = 'tab_body';
	elmImg = 'img_loading_2';

	document.getElementById(elmImg).style.display = 'block';
	
	var url = 'product_detail_tab.php?type=DES&id=' + idx;
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
}
function showProductComments(idx)
{ 
	xmlHttp = GetXmlHttpObject()
	if(!xmlHttp)
	{
		return;
	}
	
	elmDiv = 'tab_body';
	elmImg = 'img_loading_2';

	document.getElementById(elmImg).style.display = 'block';
	
	var url = 'product_detail_tab.php?type=COM&id=' + idx;
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
}
function showProductInstalments(idx)
{ 
	xmlHttp = GetXmlHttpObject()
	if(!xmlHttp)
	{
		return;
	}
	
	elmDiv = 'tab_body';
	elmImg = 'img_loading_2';

	document.getElementById(elmImg).style.display = 'block';
	
	var url = 'product_detail_tab.php?type=INS&id=' + idx;
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
}
/**/
/**/
/**/
function addShoppingCart(idx,stock_id)
{ 
	xmlHttp = GetXmlHttpObject()
	if(!xmlHttp)
	{
		return;
	}
	
	elmDiv = 'shopping_cart';
	elmImg = 'img_loading';
	
	document.getElementById(elmImg).style.display = 'block';
	
	var url = 'basket.php?op=add&id=' + idx + '&stock_id=' + stock_id;
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open('GET', url, true);
	xmlHttp.send(null);
}
function cleanShoppingCart()
{ 
	xmlHttp = GetXmlHttpObject()
	if(!xmlHttp)
	{
		return;
	}
	
	elmDiv = 'shopping_cart';
	elmImg = 'img_loading';

	document.getElementById(elmImg).style.display = 'block';
	
	var url = 'basket.php?op=delAll';
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
}
function showShoppingCart()
{
	refIsShowShoppingCart = 1;
	
	xmlHttp = GetXmlHttpObject()
	if(!xmlHttp)
	{
		return;
	}
	
	elmDiv = 'shopping_cart';
	elmImg = 'img_loading';
	
	showTransparentLayer();
	centerElement('img_loading');
	document.getElementById(elmImg).style.display = 'block';
	
	var url = 'shop_frame.php';
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open('GET', url, true);
	xmlHttp.send(null);
}
function hideShoppingCart()
{
	hideTransparentLayer();
	
	showSelectElement();
	
	document.getElementById('shopping_cart').style.display = 'none';
}
function shoppingCartScroll()
{
	//showTransparentLayer();
	
	hideSelectElement();
	
	centerElement('shopping_cart');
	/*tmp = document.getElementById('shopping_cart');
	
	_body = (!window.opera && document.compatMode && document.compatMode!='BackCompat')? document.documentElement : document.body
	
	docwidth = document.getElementById('base').offsetWidth;
	docheight = Math.min(_body.scrollHeight, _body.clientHeight);
	
	_top = _body.scrollTop + Math.ceil((docheight - tmp.clientHeight) / 2);
	_left = _body.scrollLeft + Math.ceil((docwidth - tmp.clientWidth) / 2);
	
	tmp.style.top = _top + 'px';
	tmp.style.left = _left + 'px';*/
}
function centerElement(elm)
{
	tmp = document.getElementById(elm);
	
	_body = (!window.opera && document.compatMode && document.compatMode!='BackCompat')? document.documentElement : document.body
	
	docwidth = document.getElementById('base').offsetWidth;
	docheight = Math.min(_body.scrollHeight, _body.clientHeight);
	
	_top = _body.scrollTop + Math.ceil((docheight - tmp.clientHeight) / 2);
	_left = _body.scrollLeft + Math.ceil((docwidth - tmp.clientWidth) / 2);
	
	tmp.style.top = _top + 'px';
	tmp.style.left = _left + 'px';	
}
function showTransparentLayer()
{
	_body = (!window.opera && document.compatMode && document.compatMode!='BackCompat')? document.documentElement : document.body
	
	tmp = document.getElementById('transparent_layer');

	tmp.style.width = _body.scrollWidth;
	tmp.style.height = _body.scrollHeight;
	
	tmp.style.display = 'block';
}
function hideTransparentLayer()
{
	tmp = document.getElementById('transparent_layer').style.display = 'none';
}
function showSelectElement()
{
	elms = document.getElementsByTagName('select');
	
	for(i=0; i<elms.length; i++)
	{
		elms[i].style.display = 'block';
	}
}
function hideSelectElement()
{
	elms = document.getElementsByTagName('select');
	
	for(i=0; i<elms.length; i++)
	{
		elms[i].style.display = 'none';
	}
}