/*
* 20 July 2011
* M. Powe
* Technology Leaders
*
****EDITS*****
*8/11/2011 : Added additional domains to dcsids - TJR
*
****END EDITS*****
* To deploy:
*
* <script type="text/javascript">
* //<![CDATA[
* var _tag = new WebTrends();
* var _pjm = new PJM();
*
* _pjm.setDcsId(window.location.hostname);
*
* //]]>
* </script>
*/

function PJM(){
    this.dcsids = {
    "www.test.pjm.com": ["dcs0sx9ng4g96gspytcl29y6s_8m9v", "sdc.test.pjm.com", ".pjm.com", "Dev Servers"],
    "www.pjm.com": ["dcs5w0txb10000wocrvqy1nqm_6n1p", "sdc.pjm.com", ".pjm.com", "Production"],
    "pjm.com": ["dcs5w0txb10000wocrvqy1nqm_6n1p", "sdc.pjm.com", ".pjm.com", "Production"],
    "pjw03wwt": ["dcs0sx9ng4g96gspytcl29y6s_8m9v", "sdc.test.pjm.com", ".pjm.com", "Dev Servers"],
    "pjw02wwt": ["dcs0sx9ng4g96gspytcl29y6s_8m9v", "sdc.test.pjm.com", ".pjm.com", "Dev Servers"],
    "localhost:1537": ["dcs0sx9ng4g96gspytcl29y6s_8m9v", "sdc.test.pjm.com", ".pjm.com", "Dev Servers"],
    "pjw04wwt": ["dcssxooyh3g96gcl8eigc9y6s_4o3s", "sdc.test.pjm.com", ".pjm.com", "QA Servers"],
    "pjw05wwt": ["dcssxooyh3g96gcl8eigc9y6s_4o3s", "sdc.test.pjm.com", ".pjm.com", "QA Servers"],
    "pjm-eis.test.pjm.com": ["dcsdpjsix4g96gkfxzicicoiu_2l5r", "sdc.test.pjm.com", ".pjm.com", "Test"],
    "www.pjm-eis.test.pjm.com": ["dcsdpjsix4g96gkfxzicicoiu_2l5r", "sdc.test.pjm.com", ".pjm.com", "Test"],
    "pjm-eis.test.runtime.pjm.com" : ["dcs8rvmuo3g96g8aha8a1zoiu_4y4h", "sdc.test.pjm.com", ".pjm.com", "Test"],
    "www.pjm-eis.test.runtime.pjm.com" : ["dcs8rvmuo3g96g8aha8a1zoiu_4y4h", "sdc.test.pjm.com", ".pjm.com", "Test"],
    "pjm-eis.qa.cms.pjm.com" : ["dcst3cr234g96gsx44ojo8piu_8t2e", "sdc.test.pjm.com", ".pjm.com", "QA"],
    "www.pjm-eis.qa.cms.pjm.com" : ["dcst3cr234g96gsx44ojo8piu_8t2e", "sdc.test.pjm.com", ".pjm.com", "QA"],
    "pjm-eis.qa.runtime.pjm.com" : ["dcscche5m3g96g8irrysagpiu_2f6t", "sdc.test.pjm.com", ".pjm.com", "QA"],
    "www.pjm-eis.qa.runtime.pjm.com" : ["dcscche5m3g96g8irrysagpiu_2f6t", "sdc.test.pjm.com", ".pjm.com", "QA"],
    "cms.pjm-eis.pjm.com" : ["dcsmijiv63g96g435tz5olpiu_9h7v","sdc.pjm.com", ".pjm.com", "Production"],
    "www.cms.pjm-eis.pjm.com" : ["dcsmijiv63g96g435tz5olpiu_9h7v","sdc.pjm.com", ".pjm.com", "Production"],
    "pjm-eis.com" : ["dcs4bw9574g96ggsoedh7vpiu_1l1r","sdc.pjm.com", ".pjm-eis.com", "Production"],
    "www.pjm-eis.com" : ["dcs4bw9574g96ggsoedh7vpiu_1l1r","sdc.pjm.com", ".pjm-eis.com", "Production"],
    "pji02wwp" : ["dcscmjmh14g96gsd57nenbqiu_8g4o","sdc.pjm.com", ".pjm.com", "Production"],
    "wired.pjm.com" : ["dcscmjmh14g96gsd57nenbqiu_8g4o","sdc.pjm.com", ".pjm.com", "Production"],
    "www.wired.pjm.com" : ["dcscmjmh14g96gsd57nenbqiu_8g4o","sdc.pjm.com", ".pjm.com", "Production"],
    "pji02wwt" : ["dcsygrvii4g96gcpzlqxh6qiu_6p4j", "sdc.test.pjm.com", ".pjm.com", "Test"]
    //"host4": ["dcsid4", "sdc domain info", "FirstPartyCookie Domain", "description of host4"]
    }
}

/*
 * Set the dcsid and the SDC server based on the hostname from which the page is served.
 */
PJM.prototype.setDcsId = function(host) {
    for (h in this.dcsids) {
        if (host.indexOf(h, 0) != -1 && host.indexOf(h, 0) == 0) {
		_tag.dcsid = this.dcsids[h][0];
		_tag.domain = this.dcsids[h][1];
                _tag.fpcdom = this.dcsids[h][2];
            break;
        }
    }
}

PJM.prototype.getContentGroup = function() {
    var path = window.location.pathname;
    var cg = "";
    var elements;
    if (path.charAt(0) == '/') {
        path = path.substring(1);
    }

    if (path.length > 0) {
        elements = path.split('/');
        if (elements[0].indexOf('.') != -1) {
            cg = elements[0].split('.')[0];
        } else {
            cg = elements[0];
        }
    } else {
        cg = "home";
    }
    return cg;
}

PJM.prototype.getSubgroup = function() {
    var path = window.location.pathname;
    var sg = "";
    var elements;
    if (path.charAt(0) == '/') {
        path = path.substring(1);
    }
    if (path.length > 0) {
        elements = path.split('/');
        if (elements.length > 1) {
            if (elements[1].indexOf('.') != -1) {
                sg = elements[1].split('.')[0];
            } else {
                sg = elements[1];
            }
        }
    } else {
        sg = "";
    }
    return sg;
}
