var ajaxObj;
var el;
var gourl;

function addBucket(session_id, user_id, product_id,amount, price, rootbucketURL)
{ 	
	if(typeof(document.forms.variation) != 'undefined')
	{
		_form = document.forms.variation.elements;
		_element_names = "VariationNames[]";
		_element_values = "VariationValues[]";
		
		//ürün varyasyonlari adi/degeri
		
		 variation_names =  _form[_element_names];
		 variation_values =  _form[_element_values];
		
		//çok varyasyon varsa burası çalışır
		 if(typeof(variation_names[0]) != 'undefined')
		 {
			 if(typeof(variation_names[0]) != 'undefined')
				 name1 = variation_names[0].value;
			
			 if(typeof(variation_names[1]) != 'undefined')		 
				 name2 = variation_names[1].value;
			
			 if(typeof(variation_names[2]) != 'undefined')
				name3 = variation_names[2].value;
		 }
		 //tek varyasyon varsa burası çalışır
		 else
		 {
		      name1 = variation_names.value;	 
		 }
		 
		 if(typeof(variation_values[0].options) != 'undefined')
		 {
			 if(typeof(variation_values[0]) != 'undefined')
				value1 = selectedValue(variation_values[0]);
				
			 if(typeof(variation_values[1]) != 'undefined')
				value2 = selectedValue(variation_values[1]);
			 
			 if(typeof(variation_values[2]) != 'undefined')
				value3 = selectedValue(variation_values[2]);
		 }
		 else
		 {
			   _el = _form[0];
			   value1 = _el.options[_el.selectedIndex].value;
		 }
	}
	
	ajaxObj=GetXmlHttpObject()
	if (ajaxObj==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	if(user_id=='')
		user_id=0;
	
	gourl = rootbucketURL;
	var bucketURL= rootbucketURL + "/bucket/addBucket.php"
	bucketURL = bucketURL + "?s="+session_id
	bucketURL = bucketURL + "&u="+user_id
	bucketURL = bucketURL + "&p="+product_id
	bucketURL = bucketURL + "&a="+amount
	bucketURL = bucketURL + "&pr="+price
	
	//ürün varyasyonlari adlari
	if(typeof(name1) != 'undefined')
		bucketURL = bucketURL + "&name1=" + name1
	if(typeof(name2) != 'undefined')	
		bucketURL = bucketURL + "&name2=" + name2
	if(typeof(name3) != 'undefined')	
		bucketURL = bucketURL + "&name3=" + name3
	
	//ürün varyasyonlari adlari
	if(typeof(value1) != 'undefined')	
		bucketURL = bucketURL + "&value1=" + value1
	if(typeof(value2) != 'undefined')
		bucketURL = bucketURL + "&value2=" + value2
	if(typeof(value3)!= 'undefined')
		bucketURL = bucketURL + "&value3=" + value3
	
	bucketURL=bucketURL+"&sid=" + Math.random()
	ajaxObj.onreadystatechange=stateChangedBucket 
	ajaxObj.open("GET",bucketURL,true)
	ajaxObj.send(null)
}


function stateChangedBucket() 
{ 
	if (ajaxObj.readyState==4 || ajaxObj.readyState=="complete")
	{
		if(ajaxObj.responseText == "OK")
		{
			document.location.href = gourl + "?q=bd";
		}
		document.location.href = gourl + "?q=bd";
	}
	if(document.getElementById('loader'))
	{
		document.getElementById('loader').style.display= 'none';
	}
}

function addProductToBucket(productId, productName)
{
	tableBucket = document.getElementById('bucket').style.display=="none";
	if(tableBucket)
		tableBucket.style.display=="block";	
	var tBodyEl = tableBucket;
	var trEl, tdEl1,tdEl2;
	trEl = tBodyEl.insertRow(tBodyEl.rows.length);
	//trEl.className = "";
	tdEl1 = trElem.insertCell(trEl.cells.length);
	tdEl1.innerHTML = productName;
	tdEl2 = trElem.insertCell(trEl.cells.length);
	tdEl2.innerHTML = "Sil";	
	
}