/*
 * Baynote Observer for support.intuit.ca
 * Last updated: 3/11/09
 */
function bn_isNotEmpty(name) {
	return (name != null) && (name != "");
}

function bn_showObserver() {
	/* 1. set customer id */
	bn_customerId = "intuit";
	/* 2. set customer code */
	bn_code = baynote_setCustCode();
	
	var bn_locHref = window.location.href;
	if(baynote_tag.url) bn_locHref=baynote_tag.url;
	if (bn_locHref.indexOf("https://") == 0) {
		baynote_tag.server = "https://" + bn_customerId + "-" + bn_code + ".baynote.net";
	} else {
		baynote_tag.server = "http://" + bn_customerId + "-" + bn_code + ".baynote.net";
	}
	baynote_tag.customerId = bn_customerId;
	baynote_tag.code = bn_code;
	baynote_tag.type = "baynoteObserver";
	
	baynote_setAttributes("bn-coverage-temporal,bn-platforms,bn-edition,bn-product-types,DC.subject,DC.rights,errorcode,content-id,site,DC.language");
	baynote_tag.summary=baynote_getSummary();
	
	if(bn_locHref.search(/\/search\/index\.jsp/) != -1)
		baynote_setSearchEvAttr(bn_locHref);

	/* 3. set customer domain (optional) */
	baynote_globals.cookieDomain = "intuit.ca";
	baynote_globals.cookieSubDomain = bn_code;
	
	baynote_tag.show();
}
if (typeof(baynote_tag)!="undefined") {
	bn_showObserver();
}

function baynote_setCustCode(){
	var metas = document.getElementsByTagName("meta");
	for (var i = 0; i < metas.length; i++) {
	    if (metas[i] && (metas[i].name =="DC.language")) {
	        if( metas[i].content == "fr_CA" ) {
	            return "ca_fr";
	        }
			else return "ca";
    }
	}
}

function baynote_setSearchEvAttr(bn_locHref){

	if(bn_locHref.search(/https?:\/\/support\.intuit\.ca\/(quickbooks|succespme)\/((en-ca|fr-ca)\/)?search\/index\.jsp/) == 0)
		baynote_tag.attrs.searchType = "QuickBooks";
	else if(bn_locHref.search(/https?:\/\/support\.intuit\.ca\/(quicktax|impotrapide)\/((en-ca|fr-ca)\/)?search\/index\.jsp/) == 0)
		baynote_tag.attrs.searchType = "QuickTax";
	else if(bn_locHref.search(/https?:\/\/support\.intuit\.ca\/quicken\/((en-ca|fr-ca)\/)?search\/index\.jsp/) == 0)
		baynote_tag.attrs.searchType = "Quicken";
	else if(bn_locHref.search(/https?:\/\/support\.intuit\.ca\/profile\/((en-ca|fr-ca)\/)?search\/index\.jsp/) == 0)
		baynote_tag.attrs.searchType = "Profile";
}

function baynote_setAttributes(names) {
	var toCapture = names.split(",");
	var metas = document.getElementsByTagName("meta");
	if (!metas) {return;}
	
	for (var i = 0; i < toCapture.length; i++) { 
		for (var j = 0; j < metas.length; j++) {
			if (metas[j] && metas[j].name == toCapture[i]) {
				baynote_tag.docAttrs[toCapture[i]] = metas[j].content;

			}
		}
	}
}

function baynote_getSummary() {
        var metas=document.getElementsByTagName("meta");
        if (!metas) return;
        
        var summary="";
        for (var i=0; i < metas.length; i++) {
			if (!metas[i]) return;
			if (metas[i].name == "DC.description") {
				return metas[i].content;
			}
        }
	}
	