/** 
 * CNETHeader provides a way to retrieve the main product information (manufacturer, part number etc...) which needs to be
 * dynamically inserted into the page.
 * The response needs to be a JSON structure as it'll be evaluated upon return to create an in-memory data structure that is
 * used to fetch individual data elements from:
 * 
 * Example
 * Query: http://c12-ch-tcdev01:81/productdetails/ProductInfo.ashx?Prod=2719915&what=header&lang=no
 * Response: 
 * { manufacturer: 'Sony Ericsson Mobile Communications', 
 *   partNumber: 'DPY1012834/33', 
 *   productLine: 'Sony Ericsson', 
 *   model: 'K750i', 
 *   longTitle: 'Sony Ericsson K750i - Mobiltelefon med digitalkamera / digitalspiller / FM-radio - GSM - oksidert svart', 
 *   shortTitle: 'Sony Ericsson K750i - mobiltelefon med digitalkamera / digitalspiller / FM-radio - GSM', 
 *   images: { small: 'http://c12-ch-tcdev01/digitalcontent/JPG_200x150/8D99347E-40A6-4975-8E24-5EF8F94AFF1E.jpg', 
 *             smallHosted: 'http://digitalcontent.cnetchannel.com/8d/99/8d99347e-40a6-4975-8e24-5ef8f94aff1e.jpg', 
 *             large: 'http://c12-ch-tcdev01/digitalcontent/JPG_400x300/018450EB-EDB4-453D-8884-36A88984463A.jpg', 
 *             largeHosted: 'http://digitalcontent.cnetchannel.com/01/84/018450eb-edb4-453d-8884-36a88984463a.jpg', 
 *             thumbnail: 'http://c12-ch-tcdev01/digitalcontent/THUMBNAIL/8D99347E-40A6-4975-8E24-5EF8F94AFF1E.jpg' 
 *           } 
 * }
 * 
 * after this is evaliuated in parseResponseAndPopulateUIObjects(), we end up with a data structure which can be accessed like so:
 *  var smallImageURL = cnetHdr.images.small 
 */
 

var CNETSpecification= Base.extend({
    product    : null,
    language   : null,
    servletURL : "../ProductDetails/ProductInfo.ashx",
    header     : null,
    redrawCallback: null,
                                    
	initialize: function() {
	}, 
	
	setServletURL: function(_servletURL) 
	{
	   this.servletURL = _servletURL;
	},
	
	setProduct: function (_product)
	{
	   this.product = encodeURIComponent(_product);
	}
	,
	setLanguage: function (_language) 
	{
	   this.language = _language;
	},
	
	exists: function ()
	{
	   return (this.header.manufacturer != null)
	},
	
    getHeader: function(redrawCallback)
     {
     
	    if(this.product == null || this.language == null) 
	    {
	       throw (new Exception("Set product/language before calling CNETSpecification.getHeader()"));
	    } 
	    else 
	    {
	        this.redrawCallback = redrawCallback;
		    var ajaxRequest = new Ajax.Request();
		    ajaxRequest.setOptions (
		    {method: 'get',
		          parameters: "&lang="+this.language+"&what=header&format=JSON&Prod="+this.product,
		          onSuccess: (function (req) { this.onHeaderReception(req.responseText);}).bind(this)
		          });
    		  
  

		    //ajaxRequest.respondToReadyState = {onComplete : this.onHeaderReception(ajaxRequest)};
		    //Ajax.Responders.register(
            //     { onComplete: this.onHeaderReception});
	
	        ajaxRequest.request(this.servletURL);
        }
      },
                
    onHeaderReception: function(response) 
      {
           // the response comes back as a JSON string - it translates directly into a memory structure when evaluated
           eval("this.header = "+response);
           this.redrawCallback();
      },
      
    displayx: function (withinDiv) {}

});


    


	
	
  
