﻿function PhCardDetails( root_elm, data_source )
{
	this.m_oAjax			= new PhAjaxJson();
	this.m_oRootElement		= root_elm;
	this.m_strDataSource	= data_source;
	
	this.m_oImgElm			= null;
	this.m_oNameElm			= null;
	this.m_oYearElm			= null;
	this.m_oBrandElm		= null;
	this.m_oProdElm			= null;
	this.m_oBvElm			= null;
	this.m_oDescElm			= null;
	
	this.InitObject();
}

PhCardDetails.prototype.InitObject = function()
{ 
	this.m_oImgElm		= document.getElementById( 'card_image' );
	this.m_oNameElm		= document.getElementById( 'elmPlayerName' );
	this.m_oYearElm		= document.getElementById( 'elmYear' );
	this.m_oBrandElm	= document.getElementById( 'elmBrand' );
	this.m_oProdElm		= document.getElementById( 'elmProduct' );
	this.m_oBvElm		= document.getElementById( 'elmBookValue' );
	this.m_oDescElm		= document.getElementById( 'elmDescription' );
}

PhCardDetails.prototype.LoadCard = function( card_id )
{
	var me = this;
	
	this.m_oAjax.SendRequest( this.m_strDataSource, 'card_id='+card_id, null, function( obj ){me.LoadCardCallback( obj );} );
}

PhCardDetails.prototype.LoadCardCallback = function( obj )
{
	this.m_oImgElm.src			= obj.card_image.file_path;
	this.m_oNameElm.innerHTML	= obj.player.first_name+' '+obj.player.last_name;
	this.m_oYearElm.innerHTML	= obj.product.year;
	this.m_oBrandElm.innerHTML	= obj.product.brand_name;
	this.m_oProdElm.innerHTML	= obj.product.name;
	this.m_oBvElm.innerHTML		= '$'+parseFloat(obj.book_value).toFixed(2);
	this.m_oDescElm.innerHTML	= obj.description;
	
	this.m_oRootElement.style.visibility = 'visible';
}

PhCardDetails.prototype.HideCard = function()
{
	this.m_oImgElm.src						= 'behaviors/transparent.gif';
	this.m_oRootElement.style.visibility	= 'hidden';
}
