/*
 * SiteCatalyst implementation for axa.ca
 * SHamel@immeria.net
 * v0.1 Initial implementation
 * SiteCatalyst code version: H.20.2.
 */
function SCTags(url, htmlContent){
    // account
    s.dynamicAccountSelection = true;
    s.dynamicAccountList = "axanbciprod=nbc-insurance.ca,myinsurancerebate.ca;axabncaprod=assurances-bnc.ca,maremise.ca";
    
    // url, HTML content, advanced tracking for transactions - use defaults or parameters    
    if (!url) 
        url = location.href;
    if (!htmlContent) 
        htmlContent = document.body.innerHTML;
    
    // Clean up the URL
    // - keep only pathname
    var sFixed = url.match(/(https*:\/\/)*[^\/]+([^?#,]+)/i);
    if (sFixed && sFixed[2]) 
        url = sFixed[2];
    // - convert to lowercase, strip file extension (.jsp)
    url = url.substring(1, url.lastIndexOf(".") == -1 ? Infinity : url.lastIndexOf("."));
    url = url.toLowerCase().replace(/\//g, ":");
    // - make sure a filename is always included, if URL ends with /, append "index"
    if (/\:$/.test(url) || /^\s*$/.test(url)) 
        url += "index";
    
    // Get the language from URL, if none default to "all"
    // - language: fr|en
    var reLang = new RegExp("(en|fr):");
    var sLang = url.match(reLang);
    sLang = sLang ? sLang[1] : "all";
    s.pageName = url.replace(reLang, "");
    if (/searchengine/.test(s.pageName)) 
        sLang = s.getQueryParam('ln');
    
    sProvince = "qc";
    
    ////////// Page, sections, hierarchy 
    // pageName - language:category[:subcategory:sub-subcategory...]:page name
    s.pageName = sLang + ":" + sProvince + ":" + s.pageName;
    
    // hier1 - Content hiearchy (without localization) - skip the first two ":" (language & province)
    s.hier1 = s.pageName.substring(s.pageName.indexOf(":") + 1, Infinity);
    s.hier1 = s.hier1.replace(/:/g,"/").substring(s.hier1.indexOf(":") + 1, Infinity);
    // hier2 - Content hierarchy with localization
    s.hier2 = s.pageName.replace(/:/g,"/");
    
    // channel (Section)
    var pathSplit = s.pageName.split(/:/);
    if (pathSplit.length > 1) 
        s.channel = pathSplit[2];
    
    ////////// Traffic variables (Custom Insights) (props)
    // prop1 - Sub-Section (Level 2)
    if (pathSplit.length > 3 && pathSplit[4] != undefined) 
        s.prop1 = pathSplit[4];
    // prop2 - Sub-Section (Level 3)
    if (pathSplit.length > 4 && pathSplit[5] != undefined) 
        s.prop2 = pathSplit[5];
    // prop3 - Sub-Section (Level 4) - not used
    // prop4 - Sub-Section (Level 5) - not used
    
    // Special handling for Search Result page
    // prop5 - Internal Search Term
    // prop6 - Null results
    if (/searchengine/.test(s.pageName)) {
        s.channel = "search";
		var k = s.getQueryParam('qr');
		k = k.toLowerCase();
        // Match Title tag string, search phrase and number of results returned
        if (m = htmlContent.match(/<font class="headval">([^<]+)<\/font> results were found/i)) 
            if (m[1] == "0") 
                 s.prop5 = "null:" + k, s.prop6 = k;
            else 
                s.prop5 = k;
        if (m = htmlContent.match(/a retourn([^<]+)<font class="headval">([^<]+)<\/font>/i))
			if (m[2] == "Aucun ")
				s.prop5 = "null:" + k, s.prop6 = k;
			else 
				s.prop5 = k;
    }
    
    // prop7 - Download File Name - value of eVar7 is set in s_code
    // prop8 - Set On download Click OR on download thank you page
    if (s.eVar7) 
        s.prop7 = s.eVar7, s.prop8 = s.pageName;
    
    // prop9 - Self-Service Tool name - out of scope
    // prop10 - Form analysis - set in s_code - not used
    // prop11 - Search Origination Page - set in s_code
    // prop12 - Company
    s.prop12 = "nbci";
    // prop13 - Language
    s.prop13 = sLang;
    // prop14 - Product Line
    s.prop14 = "individual";
    // prop15 - Province
    s.prop15 = "qc";
    // prop16 - Product Interest
    if (m = s.pageName.match(":([^:]+)_insurance:*")) {
        s.prop16 = m[1];
        s.events = s.apl(s.events, "event7", ",", 2);
    }
    if (m = s.pageName.match(":assurance_([^:]):*")) {
        s.prop16 = m[1];
        s.events = s.apl(s.events, "event7", ",", 2);
    }
    // prop17 - User Type
    s.prop17 = "client";
    // prop18 - User ID - for extranet/intranet only
    // prop19 - Absolute Page Name - not used for now
    // prop20 - Template Name - not used for now
    // prop21 - Internal Campaign Id - set in s_code
    // prop22 - New vs. Repeat - set in s_code
    // prop23 - Visit Frequency - set in s_code
    // prop24 - Visit Number - set in s_code
    // prop25 - Form Validation Errors - out of scope
    // prop26 - Transaction Errors - out of scope
    // prop27 - Transaction Name - out of scope
    // prop28 - Transaction Step - out of scope
    // prop29 - Transaction Number - out of scope
    // prop30 - Postal Code - out of scope
    // prop31 - Insurance Type - out of scope
    // prop32 - Target Group - out of scope

    ////////// Conversion variables (eVars)
    // eVar1 - Lead Type (not used)
    // eVar2 - Support Request Type (not used)
    // eVar3 - Direct Influence Page - set in s_code
    // eVar4 - Internal campaign - set in s_code
    // eVar5 - Internal Search Term - set in s_code
    // eVar6 - Partner Name
    // eVar7 - Download File Name - set in s_code
    // eVar8 - Company - set in s_code
    // eVar9 - Language - set in s_code
    // eVar10 - Product Line - set in s_code
    // eVar11 - Province - set in s_code
    // eVar12 - Product Interest - set in s_code
    // eVar13 - User Type - set in s_code
    // eVar14 - User Id - set in s_code
    // eVar15 - Absolute Page Name - set in s_code
    // eVar16 - Template Name - set in s_code
    // eVar17 - New vs. Repeat - set in s_code
    // eVar18 - Visit Frequency - set in s_code
    // eVar19 - Visit Number - set in s_code
    // eVar20 - Form Validation Erros - set in s_code
    // eVar21 - Transaction Errors - set in s_code
    // eVar22 - Transaction - set in s_code
    // eVar23 - Transaction Step - set in s_code
    // eVar24 - Transaction Number - set in s_code
    // eVar25 - Postal Code - set in s_code
    // eVar26 - Insurance Type - set in s_code
    // eVar27 - Target Group - out of scope

    // event1 - Leads Initiated - out of scope
    // event2 - Leads Completed - out of scope
    // event3 - Support Request - not used
    // event4 - File Downloads - set in s_code
    // event5 - Onsite Search - set in s_code
    // event6 - Partner Referrals - out of scope
    // event7 - Product Details Views
};
