
function RefreshBid(prd_id, member_id)
{
	var stamp = new Date();
	jQuery.ajax({
        url: "http://www.world-auctions.org/refresh/refresh_bid.php?prd_id="+prd_id+"&mem_id="+member_id+"&tm="+stamp,
        dataType: 'jsonp',
        type: 'GET',
        timeout: 200
	});
}

function AddWatchList(member_id, prd_id)
{
	var stamp = new Date();
	jQuery.get("http://www.world-auctions.org/refresh/add_watch_list.php?prd_id="+prd_id+"&mem_id="+member_id+"&tm="+stamp);
}

function change_photo(pic_file)
{
	document.prdimg.src = pic_file;
}

function RefreshToPublicUser(targets)
{
	if ( IsRefreshCookie() == false )
	{
		return;
	}

	return RefreshNEW(targets);
}

function RefreshDetailToPublicUser(prd_id, member_id)
{
	if ( IsRefreshCookie() == false )
	{
		return;
	}

	return RefreshDetailNEW(prd_id, member_id);
}

function IsRefreshCookie()
{
	var objDate = new Date();
	var str_cookie = document.cookie;
	var matches = str_cookie.match(/refresh_limit=([0-9]*)/);
	if ( matches != null )
	{
		if ( parseInt(objDate.getTime()) > parseInt(matches[1]) )
		{
			return false;
		}
	}
	return true;
}

function RewriteCookie()
{
	var objDate = new Date();
	var str_cookie = document.cookie;
	var matches = str_cookie.match(/refresh_interval=([0-9]*)/);
	if ( matches != null )
	{
		var limit_time = parseInt(objDate.getTime()) + parseInt(matches[1]);
		document.cookie = 'refresh_limit=' + limit_time + '; ';
	}
}

function ListRefresh(json)
{
	for(i=0; i<json.length; i++)
	{
		var item_no = "#item_" + json[i][0];
		
		var target		= jQuery(item_no + " span.price").html();
		var new_price	= json[i][6];
			
		jQuery(item_no + " span.id").html(json[i][0]);
		jQuery(item_no + " span.end_time").html(json[i][2]);
		jQuery(item_no + " span.status").html(json[i][5]);
		jQuery(item_no + " span.bid_count").html(json[i][1]);
		jQuery(item_no + " span.type").html(json[i][3]);
		jQuery(item_no + " span.last_bidder").html(decodeURI(json[i][4]));
		jQuery(item_no + " span.rest_time").html(json[i][7]);
			
		if (json[i][8] <= 10)
		{
			jQuery(item_no + " span.rest_time").css('color','red');
		}
		else
		{
			jQuery(item_no + " span.rest_time").css('color','blue');
		}
		jQuery(item_no + " span.price").html(json[i][6]);
			
		var current_price_id		= "current_price_"		 + json[i][0];
		var current_last_bidder_id	= "current_last_bidder_" + json[i][0];
			
			
		if (target != new_price)
		{
//				new Effect.Highlight(current_price_id, {startcolor:'#FFCCCC', endcolor:'#FFCCCC', from:0.0, to:1.0, duration:1});
		}
	}
}

function RefreshNEW(targets)
{
	var stamp = new Date();
	jQuery.ajax({
        url: "http://www.world-auctions.org/refresh/refresh2.php?targets="+targets+"&tm="+stamp,
        dataType: 'jsonp',
        type: 'GET',
        timeout: 200
	});
	
}


function DetailRefresh(json)
{
	var item_no = "#item_" + json[0];
	var target		= jQuery(item_no + " span.price").html();
	var new_price	= json[6];
	
	jQuery(item_no + " span.id").html(json[0]);
	jQuery(item_no + " span.end_time").html(json[2]);
	jQuery(item_no + " span.status").html(json[5]);
	jQuery(item_no + " span.bid_count").html(json[1]);
	jQuery(item_no + " span.type").html(json[3]);
	jQuery(item_no + " span.last_bidder").html(decodeURI(json[4]));
	jQuery(item_no + " span.rest_time").html(json[7]);
	
	if (json[8] <= 10)
	{
		jQuery(item_no + " span.rest_time").css('color','red');
	}
	else
	{
		jQuery(item_no + " span.rest_time").css('color','blue');
	}
	
	jQuery(item_no + " span.price").text(json[6]);
	jQuery(item_no + " span.my_bid_count").html(json[13]);
	
	jQuery(item_no + " span.mem_coins").html(json[17]);
	jQuery(item_no + " span.ab_count").html(json[12]);
	jQuery(item_no + " span.discount_price").html(json[9]);
	jQuery(item_no + " span.discount_rate").html(json[10]);
	
	jQuery("#bid_log_price_0").html(json[14][0]);
	jQuery("#bid_log_name_0").html(json[15][0]);
	jQuery("#bid_log_type_0").html(json[16][0]);
	
	jQuery("#bid_log_price_1").html(json[14][1]);
	jQuery("#bid_log_name_1").html(json[15][1]);
	jQuery("#bid_log_type_1").html(json[16][1]);

	jQuery("#bid_log_price_2").html(json[14][2]);
	jQuery("#bid_log_name_2").html(json[15][2]);
	jQuery("#bid_log_type_2").html(json[16][2]);

	jQuery("#bid_log_price_3").html(json[14][3]);
	jQuery("#bid_log_name_3").html(json[15][3]);
	jQuery("#bid_log_type_3").html(json[16][3]);

	jQuery("#bid_log_price_4").html(json[14][4]);
	jQuery("#bid_log_name_4").html(json[15][4]);
	jQuery("#bid_log_type_4").html(json[16][4]);

	jQuery("#bid_log_price_5").html(json[14][5]);
	jQuery("#bid_log_name_5").html(json[15][5]);
	jQuery("#bid_log_type_5").html(json[16][5]);

	jQuery("#bid_log_price_6").html(json[14][6]);
	jQuery("#bid_log_name_6").html(json[15][6]);
	jQuery("#bid_log_type_6").html(json[16][6]);

	jQuery("#bid_log_price_7").html(json[14][7]);
	jQuery("#bid_log_name_7").html(json[15][7]);
	jQuery("#bid_log_type_7").html(json[16][7]);

	jQuery("#bid_log_price_8").html(json[14][8]);
	jQuery("#bid_log_name_8").html(json[15][8]);
	jQuery("#bid_log_type_8").html(json[16][8]);

	jQuery("#bid_log_price_9").html(json[14][9]);
	jQuery("#bid_log_name_9").html(json[15][9]);
	jQuery("#bid_log_type_9").html(json[16][9]);

	jQuery("#bid_log_price_10").html(json[14][10]);
	jQuery("#bid_log_name_10").html(json[15][10]);
	jQuery("#bid_log_type_10").html(json[16][10]);
		
	jQuery("#bid_log_price_11").html(json[14][11]);
	jQuery("#bid_log_name_11").html(json[15][11]);
	jQuery("#bid_log_type_11").html(json[16][11]);
	
	jQuery("#bid_log_price_12").html(json[14][12]);
	jQuery("#bid_log_name_12").html(json[15][12]);
	jQuery("#bid_log_type_12").html(json[16][12]);
	
	if (target != new_price)
	{
//			new Effect.Highlight("current_price" , {startcolor:'#CCCCFF', endcolor:'#FFFFFF', restorecolor:'#FFFFFF', duration:1});
//			new Effect.Highlight("current_last_bidder" , {startcolor:'#CCCCFF', endcolor:'#FFFFFF', restorecolor:'#FFFFFF', duration:1});
	}
}

function RefreshDetailNEW(prd_id, member_id)
{
	var stamp = new Date();
	jQuery.ajax({
        url: "http://www.world-auctions.org/refresh/refresh_detail2.php?prd_id="+prd_id+"&mem_id="+member_id+"&tm="+stamp,
        dataType: 'jsonp',
        type: 'GET',
        timeout: 200
	});
	
}

function CoinRefresh(json)
{
	var item_no		= "#member_" + json.mem_id;
	var member_name = decodeURI(json.mem_handle);
		
	jQuery(item_no + " span.mem_handle").html(json.mem_handle);
	jQuery(item_no + " span.coin2").html(json.mem_coins);
}

function RefreshCoins(member_id)
{
	var stamp = new Date();
	jQuery.ajax({
        url: "http://www.world-auctions.org/refresh/refresh_coins2.php?mem_id="+member_id+"&tm="+stamp,
        dataType: 'jsonp',
        type: 'GET',
        timeout: 200
	});
}

function ShortageAlert(member_id, session)
{
	var ret = confirm('コインが足りません。コインを購入しますか？');
	if ( ret == true )
	{
		location.href = '/buy_coins_new.php?session='+session;
	}
}

function ShortageModalWindow(member_id, session)
{
	jQuery("body").append("<div id=\"modal_items\"><div id=\"glayLayer\"></div><div id=\"overLayer\"><img src=\"images/modal_window.jpg\"><img src=\"images/modal_close.gif\" class=\"close\"><img src=\"images/modal_buy.gif\" class=\"buy\"><img src=\"images/modal_cancel.gif\" class=\"cancel\"></div></div>");
	jQuery("#glayLayer").show();
	jQuery("#overLayer").show();

	jQuery("#overLayer img.close").click(function()
	{
		jQuery("#modal_items").remove();
	});

	jQuery("#overLayer img.buy").click(function()
	{
		jQuery("#modal_items").remove();
		location.href = '/buy_coins_new.php?session='+session;
	});

	jQuery("#overLayer img.cancel").click(function()
	{
		jQuery("#modal_items").remove();
	});
}

