
//Add current bid for an amount
function addBid(amount)
{
    var currentBid = parseInt($("myBid").innerHTML);
    var highestBid = parseInt($("highestBid").innerHTML);

    if(currentBid < highestBid)
        currentBid = highestBid;
    
    currentBid = parseInt(currentBid) + amount;
    
    $("myBid").innerHTML = currentBid;
    
    if(currentBid < 0 || currentBid < highestBid )
        $("myBid").innerHTML = highestBid;   
   
}

// send bid to server
function bid(productId, siteUrl)
{
    if(confirm("Are you sure you want to place a bid for $"+$('myBid').innerHTML+"?"))
    {
	    new Ajax.Updater('lastBid', '/bid?amount='+$('myBid').innerHTML+'&productId='+productId, 
	    {
	        asynchronous:true, 
	        evalScripts:true, 
	        onComplete:function(request, json)
	        {Element.hide('indicator');new Effect.Highlight('lastBid', {}); }, 
	        onLoading:function(request, json)
	        {Element.show('indicator');},
	        onSuccess:function(transport)
	        {
	           /*if(transport.responseText != "You are still the highest bidder")
	           {
		           $("FlashBox").innerHTML = "";
		           var so = new SWFObject("/swf/auctioneer_dude.swf", "mymovie", "370", "200", "8");
				   so.addVariable("productId", productId);
				   so.addVariable("siteUrl", siteUrl);
				   so.addVariable("isBidding", "true");
				   so.addParam("wmode", "transparent");
				   so.write("FlashBox");
			   }*/
	        }
	    }
	    )
	    return false;
	}
}

function resetBid()
{
    $("myBid").innerHTML = "0";
}

function writeFlash(productId)
{
    var so = new SWFObject("/swf/auctioneer_dude.swf", "mymovie", "370", "200", "8");
    so.addVariable("productId", productId);
    
    so.addParam("wmode", "transparent");
    so.write("FlashBox");
}

function toggleWatch(productId, isAuth)
{
    if(isAuth != false)
    {
	    new Ajax.Request('/toggleWatch?id='+productId,
	    {     
	        method:'get',     
	        onSuccess: function(transport){       
	            var response = transport.responseText || "no response text";
	            $('watch').innerHTML = response;
	        },     
	        onFailure: function(){ alert('Something went wrong...') }   });
	}
	else
	   alert("You need to login or register first before watching items");
}

function toggleDetails(more)
{
    if(more)
    {
        var str = $('fullDesc').value +"<span id='details' onclick='toggleDetails(false)'>(Less Details) </span>";;
        var newdiv = document.createElement("div");
        newdiv.innerHTML = str;
        $('productDescription').innerHTML = "";
        $('productDescription').appendChild(newdiv);
        new Effect.Highlight($('highlight_area'));
    }
    else
    {
        var str = ($('fullDesc').value).substr(0, 400) +"... <span id='details' onclick='toggleDetails(true)'>(More Details) </span>";
        var newdiv = document.createElement("div");
        newdiv.innerHTML = str;
        $('productDescription').innerHTML = "";
        $('productDescription').appendChild(newdiv);
        new Effect.Highlight($('highlight_area'));
    }
}