//=====================================
var useQueryCache=false;

var SetBasketCount = null;


function SetSuccessStatus2Basket(r){
  Query.SetResult(r, Query.STATE_COMPLETE, SetBasketCount);
}

function SetFailedStatus2Basket(r){
  Query.SetResult(r, Query.STATE_FAILED, SetBasketCount);
}

var qParams = {
    'ReQueryIfEmpty' : false,
    'ReQueryIfFail' : false
};

SetBasketCount = new Query(SetSuccessStatus2Basket, SetFailedStatus2Basket, qParams);

var countTimerID = null;
var cntcnt = 0;


//SendBasketCount();

function SendBasketCount(param)
{
if (!param){param = '';}
var HttpGet='/catalog/view/add_item1.php?ID='+param;
SetBasketCount.SendQuery(HttpGet);
CountStartReq();
//Element.setStyle($('order'),{'left':'50%','top':'65%','display':'block'});

}



function ShowResultsCount()
{
   var Result = GetContentCount();
	if (Result!=''&&Result) {
	if (Result=='0')
		{SetBasketDisable();}
	else
		{SetBasketEnable();$("img_basket_count").innerHTML = Result;}
	}
    //setCount();

}

function SetBasketEnable()
{
	$('mini_basket_td').className = "bg_basket";
	$('order_but').style.display = 'block';

}

function SetBasketDisable()
{

	$('mini_basket_td').className = "bg_basket_0";
	$('order_but').style.display = 'none';
}

function GetContentCount() 
	{
		if (SetBasketCount instanceof Query) 
		{
			if (SetBasketCount.GetStatus() == Query.STATE_LOADING) 
			{
				
				return '';
			}
			if (SetBasketCount.GetStatus() == Query.STATE_COMPLETE) 
			{
				resXml = SetBasketCount.GetResult();
				return resXml;
			}
		}
	}



function CountStopReq() {
	if (countTimerID) clearInterval(countTimerID);
	countTimerID = null;
}

function CountStartReq() {

	CountStopReq();
	CountShowReq();
}

function CountShowReq() {
	
	    	ShowResultsCount();
		if (SetBasketCount.GetStatus() == Query.STATE_COMPLETE||SetBasketCount.GetResult() != null) 
		{
			
			SetBasketCount.SetStatus(Query.STATE_EMPTY); 
			//Debug.Notice('Result Complete');
			CountStopReq();
			return;
		}  
	
	countTimerID = setTimeout(CountShowReq, 1500); 
	cntcnt++;
}

//function add_basket_item(count){
//	$('img_basket_count').innerHTML = count;
//}
