// $Date: 2009/02/03 15:11:05 $
// $Name: v1_r1_rc $
// $Revision: 1.6.2.1 $
// $State: Exp $

/* 
Bootstrap js for product API
*/

var ProductBranding = {
	APIversion:  '1.0',
	classPrefix: 'ProductBranding',
	qamode: 'live',
	debuglevel: 0,
	localUrlOverride: '',
	countryUrl: {
		fr: {
			live: 'themes.aol.fr/ProductAPI/',
			qa:   'themes.qa.aol.fr/ProductAPI/',
			livesecure: 'themes.aol.fr/ProductAPI/',
			qasecure: 'themes.qa.aol.fr/ProductAPI/'
		},
		de: {
			live: 'www.aol.de/js/productbranding.js',
			qa:   'aol.awe-hl3ld-002.labhh.aol.de/js/productbranding.js',
			livesecure: 'secure.aol.de/js/productbranding.js',
			qasecure: 'aol.awe-hl3ld-002.labhh.aol.de/js/productbranding.js'
		},
		uk: {
			live: 'www.aol.co.uk/partner/productapi.adp',
			qa:   'www-qa.aol.co.uk/partner/productapi.adp',
			livesecure: 'www.aol.co.uk/partner/productapi.adp',
			qasecure: 'www-qa.aol.co.uk/partner/productapi.adp'
		},
		ref: {
			live: 'o.aolcdn.com/art/eu/productbranding/reference_implementation.js',
			qa:   'o.aolcdn.com/art/eu/productbranding/reference_implementation.js',
			livesecure: 's.aolcdn.com/art/eu/productbranding/reference_implementation.js',
			qasecure: 's.aolcdn.com/art/eu/productbranding/reference_implementation.js'
		}
	},

	hat: function ( divId ) { return true; },
	
	hatLinks: function () { return [];},

	signinout: function ( divId ) { return true; },

	ad: function ( divId , spotNumber ) { return true; },

	brand: function ( divId ) { return true; },

    footer: function ( divId ) { return true; },

    tracking: function ( properties ) { return true; },

	behaviouralTracking: function () { return true; },

	behaviouralTrackingSearch: function ( searchKeywords ) { return true; },

    initqa: function ( pid , version , area , country ) {
	  ProductBranding.qamode = 'qa';
	  ProductBranding.init ( pid , version , area , country );
	},

	init: function ( pid , version , area , country ) {
	  var loc = document.location;
	  ProductBranding.initArgs = {
		  pid: pid,
		  version: version,
		  area: area,
		  country: country
	  }
      if (country == undefined)
      {
		  var domain = loc.hostname.split('.');
		  country = domain[domain.length - 1];
      }
	  ProductBranding.country = country.toLowerCase();

	  if (ProductBranding.localUrlOverride == '')
	  {
	  	  var urlSpec = ProductBranding.countryUrl[country];
	      if (urlSpec == null) return false;
	      var qamode = ProductBranding.qamode;
	      var protocol = 'http:';	      
	      if (loc.protocol == 'https:') {
		     protocol = 'https:';
	         qamode += 'secure';
	      }
		  urlStem = protocol + '//' + urlSpec[qamode];
	  }
	  else
		  urlStem = ProductBranding.localUrlOverride;

      var qstring = 'pid='+pid+'&version='+version+'&area='+area;
	  var connector = urlStem.indexOf('?') == -1 ? '?' : '&';
	  ProductBranding.localUrl = urlStem + connector + qstring;
	  document.write ('<script src='+ProductBranding.localUrl+'></scr'+'ipt>');
	  return true;
	},

	write: function ( divId , content , classSpec ) {
		if (divId == '')
		{
			divId = null;
		}
		var classString = ProductBranding.classPrefix + ' ' + ProductBranding.classPrefix + classSpec;
		var div = document.getElementById ( divId );
		var idStr = divId == null ? '' : 'id=' + divId;
		if (div == null)
		{
			document.write ( '<div ' + idStr + ' class="'+classString+'">'+content+'</div>');
		}
		else
		{
			if (content.toLowerCase().search(/<scr/) != -1)
			{
				classString += ' ' + div.className;
				div.innerHTML = '';
				document.write ( '<div class="'+classString+'">'+content+'</div>');
			}
			else
			{
				div.className += ' ' + classString;
				div.innerHTML = content;
			}
		}
	},
	setLocalUrl: function ( url ) {
		ProductBranding.localUrlOverride = url;
	}

};

