var icExelateSegments = new icHash(
	'15', 'gender=female;', '16', 'gender=male;',
	'18', 'age=18-24;','19', 'age=25-34;', '20', 'age=35-44;', '21', 'age=45-54;', '22', 'age=55-64;', '23', 'age=65+;'
);

var intICAdWidth = 0
var intICAdHeight = 0

var icSearchRegExMatch = /http:\/\/[^\/]*(google)|(askjeeves)|(altavista)|(yahoo)|(bing)|(ask).*/i;

function icSetCookie(name,value,expiredays,expiremin,domain)
{
  var exdate=new Date();
  exdate.setMinutes(exdate.getMinutes()+expiremin);
  exdate.setDate(exdate.getDate()+expiredays);
  if(domain == null || domain == "")
    document.cookie=name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +"; Path=/";
  else
    document.cookie=name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +"; Path=/; Domain=" + domain;
}

function icIsFromSearchEngine(strTagType){
  try
    {
      if(strTagType == 'html'){
        if(icSearchRegExMatch.test(parent.document.referrer))
          return true;
        else
          return false;
      }
      else{
        if(icSearchRegExMatch.test(document.referrer))
          return true;
        else
          return false;
      }
    }
  catch(err)
    {
      return false;
    }
}

function icPrepareKeyword(prefix)
{
  var regex = "";
  var strCookie = "";
  var strKeyword = "";
  var strShortKey;
  regex = new RegExp(prefix + "\\S+=[^;]*", "gi");
  strCookie = document.cookie + ";";
  arrayCookie = strCookie.match(regex);
  var strTemp;

  for (var i=0;arrayCookie != null && i<arrayCookie.length;i++)
  {
    strTemp = arrayCookie[i].substring(prefix.length,arrayCookie[i].indexOf("="));
    strShortKey = strTemp.slice(0,strTemp.indexOf("_")).toString().toLowerCase();
    strKeyword=strKeyword + strShortKey+"=" + arrayCookie[i].substring(prefix.length,arrayCookie[i].indexOf("=")) +";";
  }
  return strKeyword;
}


function icIncrementViewCounter(strSite,intPageNum)
{
  /* ignoring for Safari Browser*/
  if(navigator.vendor != null && navigator.vendor.indexOf("Apple") >= 0)
    return "";
  var intCookieTimeOut= 30;
  var intViewCounterMaxValue= 99;
  var regex = "";
  var strCookie = "";
  var intViewCounter= 0;
  var strViewCounter= "";
  var strCookieName = "icviewcount_"+strSite;
  var strCookieValue = "";
  //	alert(document.cookie);
  regex = new RegExp(strCookieName+"="+"\\S+;","gi");
  strCookie = document.cookie + ";";
  arrayCookie = strCookie.match(regex);
  if(arrayCookie != null)
    strViewCounter = arrayCookie[0].replace(strCookieName+"=","").replace(";","");

  if(strViewCounter != "" && !isNaN(strViewCounter))
    intViewCounter = parseInt(strViewCounter);

  if(intViewCounter < intViewCounterMaxValue && intPageNum ==-1)
    intViewCounter= intViewCounter+1;

  strViewCounter = (intViewCounter < 10) ? ("0" + intViewCounter) : intViewCounter;
  icSetCookie(strCookieName,intViewCounter,0,intCookieTimeOut,".investingchannel.com");
  return strViewCounter;
}

function icQuerystring(qs)
{
  this.params = {};

  if (qs == null) qs = location.search.substring(1, location.search.length);
  if (qs.length == 0) return;

  qs = qs.replace(/\+/g, ' ');
  var args = qs.split('&'); // parse out name/value pairs separated via &

  for (var i = 0; i < args.length && args[i].length>0; i++)
  {
    //separate name and value
    if (args[i].indexOf("=") >=0)
    {
      var name = args[i].substring(0,args[i].indexOf("=")).toLowerCase();
      var value = args[i].substring(args[i].indexOf("=")+1);
    }
    else
    {
      var name = args[i].toLowerCase();
      var value = "";
    }
    this.params[name] = value;
  }
}

icQuerystring.prototype.get = function(key, default_)
{
  var value = this.params[key];
  return (value != null) ? value : default_;
}

icQuerystring.prototype.contains = function(key)
{
  var value = this.params[key];
  return (value != null);
}

function icReadCookie(cookieName)
{
  cookieName = cookieName.toLowerCase() + "=";
  var strCookie = document.cookie;
  var args = strCookie.split("; ");

  for (var i = 0; i < args.length && args[i].length>0; i++) {
    if (args[i].toLowerCase().indexOf(cookieName) == 0 )
    {
      var value = unescape(args[i].substring(cookieName.length,args[i].length));
      return value;
    }
  }
  return "";
}

function icHash()
{
  this.length = 0;
  this.items = new Array();
  for (var i = 0; i < arguments.length; i += 2) {
    if (typeof(arguments[i + 1]) != 'undefined') {
      this.items[arguments[i]] = arguments[i + 1];
      this.length++;
    }
  }
  this.getItem = function(in_key) {
    return this.items[in_key];
  }
  this.hasItem = function(in_key){
    return typeof(this.items[in_key]) != 'undefined';
  }
}

function icIsHttps(){
  return(location.protocol =='https:' ||location.protocol =='https://' || location.protocol =='https' )
}

function icGetProtocol(){
  if(icIsHttps())
    return "https://";
  else
    return "http://";
}
function icGetAdTagUrl(){
  //return icGetProtocol() + "http://ads.investingchannel.com/adtags";
  return "http://ads.investingchannel.com/adtags";
}

function icIsObjectEmpty(obj) {
  var prop;
  var propCount = 0;

  for (prop in obj) {
    propCount++;
    if(propCount >= 1){
      return false;
    }
  }
  return true;
}

function icSplitAdsize(ad){
  if(ad=='' || ad==null){
    return
  }
  else{
    arrAdSize = [];
    arrAdSize = ad.split('x');
    intICAdWidth = arrAdSize[0];
    intICAdHeight = arrAdSize[1];
  }
}
//Bizo
function icBizoDemographics(){
  var bizo_ad_key = "18d8c7d8c4d04d1588a9cf479a85164e";
  var str_bizo_cs = '';
  var str_bizo_sn = '';
  var str_bizo_fa = '';
  var str_bizo_in = '';

  if(strICBizoKvals==''){
    // make the api request that calls the "load_ad_callback" method
    
    document.write("<scr" + "ipt src='http://api.bizographics.com/v1/profile.json?callback=load_ad_callback&api_key=" + bizo_ad_key + "' type='text/javascript'><\/scr" + "ipt>");
  }
}

function load_ad_callback(bizo_data){
  if (icIsObjectEmpty(bizo_data.bizographics))
    return;

  if (bizo_data.bizographics.company_size)
    strICBizoKvals += "co_size=" + bizo_data.bizographics.company_size.code + ";";

  if (bizo_data.bizographics.seniority)
    strICBizoKvals += "seniority=" + bizo_data.bizographics.seniority.code + ";";

  if (bizo_data.bizographics.functional_area)
    for (var i = 0; i < bizo_data.bizographics.functional_area.length; i++) {
      strICBizoKvals = strICBizoKvals + "func_area=" + bizo_data.bizographics.functional_area[i].code + ";";
    }

  if (bizo_data.bizographics.industry)
    for (var i = 0; i < bizo_data.bizographics.industry.length; i++) {
      strICBizoKvals = strICBizoKvals + "industry=" + bizo_data.bizographics.industry[i].code + ";";
    }

  if(strICBizoKvals == undefined || strICBizoKvals == '')
    return;

  document.write('<img src="http://ads.investingchannel.com/adtags/set_cookie?name=ic_bizo&value=' + escape(strICBizoKvals) + '" height="1" width="1" border="0" style="display:none;height:1px;width:1px;border:none;" />');
}

//Exelate
function icExelateDemographics(){
  if (strICExelateKvals == '') {
    // make the api request that calls the "callback_function" method
    document.write("<scr" + "ipt src='http://load.exelator.com/load/?p=104&g=220&j=jf' + type='text/javascript'><\/scr" + "ipt>");
  }
}

function callback_function(data){
  if ((data.service == 'on') && (data.segments.length > 0)) {
    for (var i = 0; i < data.segments.length; i++) {
      strICExelateKvals = strICExelateKvals + (icExelateSegments.getItem(data.segments[i]).toString());
    }
    document.write('<img src="http://ads.investingchannel.com/adtags/set_cookie?name=ic_exelate_new&value=' + escape(strICExelateKvals) + '" height="1" width="1" border="0" style="display:none;height:1px;width:1px;border:none;"/>');
  }
}


//Crowdcontrol/Lotame
function icCrowdsControlDemographics(){
  if (strICCrowdControlKvals == '') {
    // make the api request that calls the "ic_processauds_callback" method
    document.write("<scr" + "ipt src='http://ad.crwdcntrl.net/5/c=581/pe=y/callback=ic_processauds_callback' + type='text/javascript'><\/scr" + "ipt>");
  }
}

function ic_processauds_callback(data){
  if(data.Profile.Audiences.Audience.length>0){
    for (var i = 0; i < data.Profile.Audiences.Audience.length; i++) {
      strICCrowdControlKvals = strICCrowdControlKvals + "audience=" + data.Profile.Audiences.Audience[i].abbr + ";";
      }
    document.write('<img src="http://ads.investingchannel.com/adtags/set_cookie?name=ic_crowdcontrol&value=' + escape(strICCrowdControlKvals) + '" height="1" width="1" border="0" style="display:none;height:1px;width:1px;border:none;"/>');
  }
}

// IXI Data
/*
AA	Total Assets Digital	0 - 17, (blank) : Numeric
AB	Total Deposits Digital	0 - 8, (blank): Numeric
AC	Financial Cohorts Digital	0 - 61, (blank): Numeric
AY	Active Traders:  Discount Brokers	0 - 2, (blank): Numeric
AZ	Active Traders: Full-Service Brokers	0 - 2, (blank): Numeric
EA	Income360 Digital	1 - 24, (blank): Numeric
EB	Discretionary Spending Digital	1 - 24, (blank): Numeric
EC	Economic Cohorts Digital	1 - 71, (blank): Numeric
ED	Ability to Pay Digital	0 - 24, (blank): Numeric
EE	Economic Spectrum Digital	1 - 17, (blank): Numeric
*/

		IC_IXI_DATA_SEGMENTS = {
		  'AA':{
		    'Type':'ti_assets',
			'Description':'WealthComplete Total Investible Assets',
			'ReturnTypes':{
				'0':'',
				'1': '25M_plus',
				'2': '10M_23M',
				'3': '5M_9M',
				'4': '3M_4M',
				'5': '2M_3M',
				'6': '1M_1M',
				'7': '750K_999K',
				'8': '500K_749K',
				'9': '250K_499K',
				'10': '100K_249K',
				'11': '75K_99K',
				'12': '50K_74K',
				'13': '25K_49K',
				'14': '10K_24K',
				'15': '5K_9K',
				'16': '1K_4K',
				'17': '0K',
				'NA':'',
				'':''
			}
		  },
		  'AB':{
		    'Type':'w_deposits',
			'Description':'WealthComplete Deposits',
			'ReturnTypes':{
				'0':'',
				'1': '250K_plus',
				'2': '100K_249K',
				'3': '50K_99K',
				'4': '25K_49K',
				'5': '10K_24K',
				'6': '3K_9K',
				'7': '1K_2K',
				'8': '0K',
				'NA':'',
				'':''
			}
		  },
		  'AC':{
		    'Type':'f_cohorts',
			'Description':'Financial Cohorts',
			'ReturnTypes':{
				'0':'',
				'1': 'A1',
				'2': 'A2',
				'3': 'A3',
				'4': 'A4',
				'5': 'B5',
				'6': 'B6',
				'7': 'B7',
				'8': 'B8',
				'9': 'C9',
				'10': 'C10',
				'11': 'C11',
				'12': 'C12',
				'13': 'D13',
				'14': 'D14',
				'15': 'D15',
				'16': 'D16',
				'17': 'E17',
				'18': 'E18',
				'19': 'E19',
				'20': 'E20',
				'21': 'F21',
				'22': 'F22',
				'23': 'F23',
				'24': 'F24',
				'25': 'G25',
				'26': 'G26',
				'27': 'G27',
				'28': 'G28',
				'29': 'H29',
				'30': 'H30',
				'31': 'H31',
				'32': 'I32',
				'33': 'J33',
				'34': 'J34',
				'35': 'J35',
				'36': 'J36',
				'37': 'K37',
				'38': 'K38',
				'39': 'K39',
				'40': 'L40',
				'41': 'L41',
				'42': 'L42',
				'43': 'M43',
				'44': 'M44',
				'45': 'M45',
				'46': 'M46',
				'47': 'M47',
				'48': 'N48',
				'49': 'N49',
				'50': 'N50',
				'51': 'N51',
				'52': 'O52',
				'53': 'O53',
				'54': 'P54',
				'55': 'P55',
				'56': 'P56',
				'57': 'P57',
				'58': 'Q58',
				'59': 'Q59',
				'60': 'Q60',
				'61': 'R61',
				'NA':'',
				'':''
			}
		  },
		  'AY':{
		    'Type':'sid_brokers',
			'Description':'Sophisticated Investors: Discount Brokers',
			'ReturnTypes':{
				'0':'',
				'1':'no',
				'2':'yes',
				'NA':'',
				'':''
			}
		  },
		  'AZ':{
		    'Type':'sif_brokers',
			'Description':'Sophisticated Investors: Full Service Brokers',
			'ReturnTypes':{
				'0':'',
				'1':'no',
				'2':'yes',
				'NA':'',
				'':''
			}
		  },
		  'EA':{
		    'Type':'i360',
			'Description':'Income360 Digital	1 - 24, (blank): Numeric',
			'ReturnTypes':{
				'0': '',
				'1': '254K_plus',
				'2': '187K_253K',
				'3': '161K_186K',
				'4': '145K_160K',
				'5': '132K_144K',
				'6': '118K_131K',
				'7': '107K_117K',
				'8': '98K_106K',
				'9': '90K_97K',
				'10': '83K_89K',
				'11': '77K_82K',
				'12': '71K_76K',
				'13': '66K_70K',
				'14': '61K_65K',
				'15': '56K_60K',
				'16': '52K_55K',
				'17': '47K_51K',
				'18': '43K_46K',
				'19': '38K_42K',
				'20': '33K_37K',
				'21': '29K_32K',
				'22': '25K_28K',
				'23': '20K_24K',
				'24': '19K_less',
				'NA': '',
				'': ''
			}
		  },
		  'EB':{
		    'Type':'dis_spend',
			'Description':'Discretionary Spending Digital	1 - 24, (blank): Numeric',
			'ReturnTypes':{
				'0': '',
				'1': '183K_plus',
				'2': '140K_182K',
				'3': '119K_139K',
				'4': '95K_118K',
				'5': '81K_94K',
				'6': '73K_80K',
				'7': '61K_72K',
				'8': '53K_60K',
				'9': '47K_52K',
				'10': '43K_46K',
				'11': '40K_42K',
				'12': '37K_39K',
				'13': '35K_36K',
				'14': '33K_34K',
				'15': '31K_32K',
				'16': '30K_30K',
				'17': '28K_29K',
				'18': '25K_27K',
				'19': '22K_24K',
				'20': '19K_21K',
				'21': '15K_18K',
				'22': '11K_14K',
				'23': '9K_10K',
				'24': '8K_less',
				'NA':'',
				'':''
			}
		  },
		  'EC':{
		    'Type':'e_cohorts',
			'Description':'Economic Cohorts Digital',
			'ReturnTypes':{
				'0': '',
				'1': 'A1',
				'2': 'A2',
				'3': 'A3',
				'4': 'A4',
				'5': 'A5',
				'6': 'A6',
				'7': 'B7',
				'8': 'B8',
				'9': 'B9',
				'10': 'B10',
				'11': 'B11',
				'12': 'B12',
				'13': 'C13',
				'14': 'C14',
				'15': 'C15',
				'16': 'C16',
				'17': 'C17',
				'18': 'D18',
				'19': 'D19',
				'20': 'D20',
				'21': 'D21',
				'22': 'E22',
				'23': 'E23',
				'24': 'E24',
				'25': 'E25',
				'26': 'E26',
				'27': 'E27',
				'28': 'F28',
				'29': 'F29',
				'30': 'F30',
				'31': 'F31',
				'32': 'F32',
				'33': 'F33',
				'34': 'G34',
				'35': 'G35',
				'36': 'G36',
				'37': 'G37',
				'38': 'G38',
				'39': 'H39',
				'40': 'H40',
				'41': 'H41',
				'42': 'H42',
				'43': 'I43',
				'44': 'I44',
				'45': 'I45',
				'46': 'I46',
				'47': 'I47',
				'48': 'I48',
				'49': 'J49',
				'50': 'J50',
				'51': 'J51',
				'52': 'J52',
				'53': 'J53',
				'54': 'J54',
				'55': 'K55',
				'56': 'K56',
				'57': 'K57',
				'58': 'K58',
				'59': 'K59',
				'60': 'L60',
				'61': 'L61',
				'62': 'L62',
				'63': 'L63',
				'64': 'M64',
				'65': 'N65',
				'66': 'N66',
				'67': 'N67',
				'68': 'O68',
				'69': 'O69',
				'70': 'P70',
				'71': 'P71',
				'NA':'',
				'': ''
			}
		  },
		  'ED':{
		    'Type':'ability_pay',
			'Description':'Ability to Pay Digital	0 - 24, (blank): Numeric',
			'ReturnTypes':{
				'0':'',
				'1': '980_1000',
				'2': '957_979',
				'3': '924_956',
				'4': '891_923',
				'5': '858_890',
				'6': '826_857',
				'7': '772_825',
				'8': '707_771',
				'9': '644_706',
				'10': '582_643',
				'11': '520_581',
				'12': '459_519',
				'13': '399_458',
				'14': '330_398',
				'15': '262_329',
				'16': '195_261',
				'17': '139_194',
				'18': '102_138',
				'19': '84_101',
				'20': '67_83',
				'21': '50_66',
				'22': '33_49',
				'23': '17_32',
				'24': '0_16',
				'NA':'',
				'':''
			}
		  },
		  'EE':{
		    'Type':'e_spectrum',
			'Description':'Economic Spectrum',
			'ReturnTypes':{
				'0':'',
				'1': 'A_ES',
				'2': 'A_PS',
				'3': 'EA_PS',
				'4': 'EA_BS',
				'5': 'EA_MS',
				'6': 'MA_BS',
				'7': 'MA_MS',
				'8': 'MA_LS',
				'9': 'MS_MS',
				'10': 'MS_LS',
				'11': 'MS_TS',
				'12': 'D_LS',
				'13': 'D_TS',
				'14': 'D_SS',
				'15': 'MEM_TS',
				'16': 'MEM_SS',
				'17': 'MEM_MS',
				'NA':'',
				'':''
			}
		  }
		};


function icIXIDemographics(){
  if (strICIXIKvals == '') {
    // make the api request that calls the "callback_function" method
    document.write("<scr" + "ipt src='"+ icGetProtocol() +"s.ixiaa.com/digi/AB87AD41-4FB7-4932-BA42-7F02ED267F41/jsonp.html?jsonp=icIXICallback'  + type='text/javascript'><\/scr" + "ipt>");
  }
}

function icIXICallback(_icIXIData){
    icIXIStrResult='';
    for(var icIXIKey in _icIXIData){
      try{
        icIXIRetVal = IC_IXI_DATA_SEGMENTS[icIXIKey]["ReturnTypes"][_icIXIData[icIXIKey]+''];
        if(icIXIRetVal != '')
          icIXIStrResult += IC_IXI_DATA_SEGMENTS[icIXIKey]["Type"] + '='+icIXIRetVal +";";
      }
      catch(e){
        // do nothing ignore erronous values
      }
    }
    if(icIXIStrResult != '')
      document.write('<img src="'+ icGetAdTagUrl() +'/set_cookie?name=ic_ixi&value=' + escape(icIXIStrResult) + '" height="1" width="1" border="0" style="display:none;height:1px;width:1px;border:none;"/>');
}











function icCrowdscienceDemographics(){
  if (strICCrowdscienceKvals == '') {
    // make the api request that calls the "callback_function" method
    document.write("<scr" + "ipt src='"+ icGetProtocol() +"static.crowdscience.com/max-824d28492f.js?callback=icCrowdscienceCallback'  + type='text/javascript'><\/scr" + "ipt>");
  }
}

function icCrowdscienceCallback(_ic_crowdscience_data){
  // This method is only invoked on occurrence of a value
  icCrowdscienceStrResult='';

  try{
    icCrowdscienceStrResult = _ic_crowdscience_data.segments.join("=1;");
    if(icCrowdscienceStrResult !='')
      icCrowdscienceStrResult += "=1;";

  }
  catch(icCrowdscienceException){
    //do nothing
  }

  if(icCrowdscienceStrResult != '')
    document.write('<img src="'+ icGetAdTagUrl() +'/set_cookie?name=ic_crowdscience&value=' + escape(icCrowdscienceStrResult) + '" height="1" width="1" border="0" style="display:none;height:1px;width:1px;border:none;"/>');

}



var strICExelateKvals = '';
var strICBizoKvals = '';
var strICIXIKvals = '';
var strICCrowdscienceKvals = '';
var strICCrowdControlKvals = '';

if(!intICPageNum) var intICPageNum = -1;
if (intICPageNum == -1) intICPageNum = Math.round(Math.random() * 100000000000000);

if(!intICTile) var intICTile = 0;

intICTile++;
var icFromSearchEngineFlag = icIsFromSearchEngine('js');

var dartUrl = 'biblemoneymatters/home;kw=;viewcount_biblemoneymatters=01;kval=home;dcopt=ist;' + strICBizoKvals + strICExelateKvals + strICIXIKvals + strICCrowdscienceKvals + strICCrowdControlKvals + 'tkr=;tile=' + intICTile + ';sz=728x90;viewcount=01;is_search=' + icFromSearchEngineFlag + ';ord=' + intICPageNum + '?'



document.write('<scr' + 'ipt type="text/javascript" src="http://ad.doubleclick.net/adj/invc.' + dartUrl + '">'+'</scr' + 'ipt>');
document.write('<img src="http://ads.investingchannel.com/adtags/log_dart_url?url=' + escape(dartUrl) + '" height="1" width="1" border="0" style="display:none;height:1px;width:1px;border:none;"/>');

    
      /* Bizo Implementation*/
      
        icBizoDemographics();
      

      /* Exelate Implementation*/
      

      /* IXI Implementation*/
      
	  icIXIDemographics();
      

      /* Crowdscience Implementation*/
      
	  icCrowdscienceDemographics();
      

      /* CrowdControl/Lotame Implementation*/
      
	  icCrowdsControlDemographics();
      

      /* Target Rules*/
      
        
      

    

