/*
* dodaje do koszyka oferte
*/

function addToBasket( offer, nodeCheckbox ) {

	if ( nodeCheckbox.checked )
	{
		strOperation = "add";
		showWindow( 'BasketNote', nodeCheckbox, 'Dodano do schowka', 800  );
	}
	else
	{
		strOperation = "delete";
		showWindow( 'BasketNote', nodeCheckbox, 'Usunięto ze schowka', 800  );
	}
	
	advAJAX.get({
	  url : "basket.php",
		//onSuccess : changeBasketCount, // dynamiczna zmiana liczby w koszyku
	  parameters : {
	    "offer" : offer,
	  	"oper" : strOperation  
	  }
	  
	}
	);
}

function changeBasketCount( obj ) 
{
	intValue = parseInt(obj.responseText);
	
	objBasketCount = document.getElementById('BasketCount');
	objBasketContener = document.getElementById('BasketContener');
	if ( intValue > 0 )
	{
		objBasketContener.className = 'menu-koszyk';
		objBasketCount.replaceChild( document.createTextNode( intValue ), objBasketCount.firstChild );
	}
	else
	{
		objBasketContener.className = 'menu-koszyk-brak';
		objBasketCount.replaceChild( document.createTextNode( 'brak' ), objBasketCount.firstChild );
	}
};

objWindowTime = new Array();
function showWindow( strWindowID, nodeCheckbox, strNote, intTime )
{
	nodeWindow = document.getElementById( strWindowID );
	if ( objWindowTime[strWindowID] )
	{
		clearTimeout( objWindowTime[strWindowID] ); 
	} 	
	nodeCheckbox.parentNode.appendChild( nodeWindow );
	nodeWindow.style.display = 'block';
	nodeWindow.replaceChild( document.createTextNode( strNote ), nodeWindow.firstChild );
	objWindowTime[strWindowID] = setTimeout( 'hideWindow( "' + strWindowID + '" )', intTime );
}

function hideWindow( strWindowID )
{
	nodeWindow = document.getElementById( strWindowID );	
	nodeWindow = document.getElementById( 'BasketNote' );
	nodeWindow.style.display = 'none';
}