// sets the account variable for Omniture metrics
//last edited January 4, 2012

/*global document, URL, getElementsByTagName, s_account */
s_account = "wlggoretest";

//a separate file allows the account to be changed without republishing the site.
//this also provides the flexibility to use the same metrics code for microsites, but put the data in other report suites. 


// Meta values

//Reading the meta names on the page allow them to be used in logic to define the report suites for s_account.  
//These variables will also be used in the file s_metrics.js

var gmetrics = {}; //object to hold all meta information passed on the page or in URL  Will migrate the variables below to this over time.

var templocale = "";
var tempassettype = "";
var tempcategory0 = "";
var tempcategory1 = "";
var tempcategory2 = "";
var tempcategory3 = "";
var tempcategory0value = "";
var tempcategory1value = "";
var tempcategory2value = "";
var tempcategory3value = "";
var tempflexdefinition = "";
var tempassetname = "";
var tempindustryvalue = "";
var temprevisiondate = "";
var tempi1master = "";
var tempi2master = "";
var tempassetid = "";
var tempsource = "";

var tempparam1 = "";
var tempparam2 = "";
var tempparam3 = "";
var tempparam4 = "";
var tempparam5 = "";
var tempparam6 = "";
var tempparam7 = "";
var tempparam8 = "";
var tempparam9 = "";


function checkMeta() {
    "use strict";  //added due to jslint.  See http://www.yuiblog.com/blog/2010/12/14/strict-mode-is-coming-to-town/
    var metas = document.getElementsByTagName('meta'), i, j;
    for (i = 0; i < metas.length; i += 1) {
        if (metas[i].getAttribute('name')) { //check for meta vars without name field- if name doesn't exist, then won't enter this block
            j = metas[i].getAttribute('name');
            switch (j) {
            case 'Locale':
                templocale = metas[i].getAttribute('content');
                break;
            case 'AssetType':
                tempassettype = metas[i].getAttribute('content');
                break;
            case 'Category0':
                tempcategory0 = metas[i].getAttribute('content');
                break;
            case 'Category0Value':
                tempcategory0value = metas[i].getAttribute('content');
                break;
            case 'Category1':
                tempcategory1 = metas[i].getAttribute('content');
                break;
            case 'Category1Value':
                tempcategory1value = metas[i].getAttribute('content');
                break;
            case 'Category2':
                tempcategory2 = metas[i].getAttribute('content');
                break;
            case 'Category2Value':
                tempcategory2value = metas[i].getAttribute('content');
                break;
            case 'Category3':
                tempcategory3 = metas[i].getAttribute('content');
                break;
            case 'Category3Value':
                tempcategory3value = metas[i].getAttribute('content');
                break;
            case 'FlexDefinition':
                tempflexdefinition = metas[i].getAttribute('content');
                break;
            case 'AssetName':
                tempassetname = metas[i].getAttribute('content');
                break;
            case 'IndustryValue':
                tempindustryvalue = metas[i].getAttribute('content');
                break;
            case 'revisiondate':
                temprevisiondate = metas[i].getAttribute('content');
                break;
            case 'I1_Master':
                tempi1master = metas[i].getAttribute('content');
                break;
            case 'I2_Master':
                tempi2master = metas[i].getAttribute('content');
                break;
            case 'AssetId':
                tempassetid = metas[i].getAttribute('content');
                break;
            case 'Source':
                tempsource = metas[i].getAttribute('content');
                break;
            case 'pubdate':
                gmetrics.pubdate = metas[i].getAttribute('content');
                break;
            case 'param1':
                tempparam1 = metas[i].getAttribute('content');
                break;
            case 'param2':
                tempparam2 = metas[i].getAttribute('content');
                break;
            case 'param3':
                tempparam3 = metas[i].getAttribute('content');
                break;
            case 'param4':
                tempparam4 = metas[i].getAttribute('content');
                break;
            case 'param5':
                tempparam5 = metas[i].getAttribute('content');
                break;
            case 'param6':
                tempparam6 = metas[i].getAttribute('content');
                break;
            case 'param7':
                tempparam7 = metas[i].getAttribute('content');
                break;
            case 'param8':
                tempparam8 = metas[i].getAttribute('content');
                break;
            case 'param9':
                tempparam9 = metas[i].getAttribute('content');
                break;
            }

        }
    }
}
checkMeta();

//set s_account based on locales. 
if (templocale === "en_xx") {
    s_account = "wlggoreus";
  // set s_account for multisuite tagging 
  // multisuite tagging for recruiting, products/businesses (electronics, filtration, sealants, venting, surveys, battery, fuel cells, fibers
  //??any stores, ??pharmbioconfig will need to point to this in the future based on their code 
    if (tempcategory0 === "05 Careers") {s_account = "wlggoreus,wlgrecruitus,wlgrecruitglob";
        } else {  //in en_xx and not careers, so see if there are any subset reports suites to send data to     


        switch (tempcategory1) {
        case '2 cable':
            s_account = "wlggoreus,wlgelectronicsus";
            break;

        case '3 electronic':
            if ((tempcategory2 !== "3.4 fuel cells") && (tempcategory2 !== "3.5 battery")) {s_account = "wlggoreus,wlgelectronicsus"; } else if (tempcategory2 === "3.4 fuel cells") {s_account = "wlggoreus,wlgfuelcellsus"; } else if (tempcategory2 === "3.5 battery") {s_account = "wlggoreus,wlgbatteryus"; }
            break;

        case '2 cable, 3 electronic':
            s_account = "wlggoreus,wlgelectronicsus"; //for pages like mfg reps that cross boundaries
            break;

        case '4 fibers':
            s_account = "wlggoreus,wlgfibersus";
            break;

        case '5 filtration':
            s_account = "wlggoreus,wlgdryfiltrationus";
            break;

        case '6 geochemical':
            s_account = "wlggoreus,wlgsurveysus";
            break;

        case '8 sealants':
            if (tempcategory2 === "8.5 skyflex") {s_account = "wlggoreus,wlgelectronicsus"; } else {s_account = "wlggoreus,wlgsealantsus"; }
            break;

        case '9 venting':
            s_account = "wlggoreus,wlgventingus";
            break;


        }
    }
}




if (templocale !== "en_xx") {

    switch (templocale) {
    case 'de_de':
        s_account = "wlggorede";
        if (tempcategory1 === "8 sealants") {s_account = "wlggorede,wlgsealantsde"; }
        if (tempcategory0 === "05 Careers") {s_account = "wlggorede,wlgrecruitde,wlgrecruitglob"; }
        break;
    case 'en_gb':
        s_account = "wlggoreuk";
        if (tempcategory0 === "05 Careers") {s_account = "wlggoreuk,wlgrecruituk,wlgrecruitglob"; }
        break;
    case 'zh_cn':
        s_account = "wlggorecn";
        if (tempcategory0 === "05 Careers") {s_account = "wlggorecn,wlgrecruitcn,wlgrecruitglob"; }
        break;
    case 'ko_kr':
        s_account = "wlggorekr";
        break;
    case 'it_it':
        s_account = "wlggoreit";
        if (tempcategory1 === "8 sealants") {s_account = "wlggoreit,wlgsealantsit"; }
        break;
    case 'es_es':
        s_account = "wlggorees";
        if (tempcategory1 === "8 sealants") {s_account = "wlggorees,wlgsealantses"; }
        break;
    case 'ja_jp':
        s_account = "wlggorejp";
        if (tempcategory0 === "05 Careers") {s_account = "wlggorejp,wlgrecruitjp,wlgrecruitglob"; }
        break;
    case 'zh_tw':
        s_account = "wlggoretw";
        break;


    }
}

//finally, if this is staging, set it to a test account for all locales
//if the string content.wlgore.com is in the URL, we are on staging, and in production the indexOf the string will ==-1 and in staging will not==-1
if (document.URL.indexOf('content.wlgore.com', 0) !== -1) {s_account = "wlggoretest2"; }

