//	customEvents.js
// Gathers pageName and Page Product catagory if present and
// sends them back to the event service.

document.write("<script src='/qcms/qCmsRepository/Global/Javascript/Base64.js'></script>");

	var eventPageName = "";
	var productCatagory = "";
	var eventServicePageNameUrl = "";
	var eventServiceProdCatUrl = "";

/**
* Function checks which omniture page name is set
* and uses the one present.  Then checks for a patterne
* in the name to get the Product Catagory. And Submits
* back to the Event Service in Tcat.
**/
function getProductCatagory() {					
		if (typeof s != "undefined") {
			if(typeof s.pageName != "undefined") {
				eventPageName = s.pageName;
				//alert("Using s.pageName");
				}
			} 
			
		if (typeof s_pageName != "undefined") {
				eventPageName = s_pageName;
				//alert("Using s_pageName");
			}
			
			eventPageName = eventPageName.toUpperCase();
			if(eventPageName.indexOf("INTERNET") > -1 || eventPageName.indexOf("BROADBAND") > -1) {
				productCatagory = "INTERNET";
			} else if(eventPageName.indexOf("LD") > -1) {
				productCatagory = "LONGDISTANCE";
			} else if(eventPageName.indexOf("PHONE") > -1) {
				productCatagory = "LOCAL";
			} else if(eventPageName.indexOf("TV") > -1) {
				productCatagory = "DTV";
			} else if(eventPageName.indexOf("WIRELESS") > -1) {
				productCatagory = "WIRELESS";
			} else {
				productCatagory = "";
			}

	if(eventPageName != "") {
			var urlEncodedEventPageName = Base64.encode(eventPageName);
			eventServicePageNameUrl = '/MasterWebPortal/customize/trackingId/subTrackingId/eventKey/PAGE_NAME/eventValue/' + urlEncodedEventPageName + '/customEvent?x=' + (new Date()).getTime();
			//customEventCall(eventServicePageNameUrl);
		}
	if (productCatagory != "") {
			eventServiceProdCatUrl = '/MasterWebPortal/customize/trackingId/subTrackingId/eventKey/PRODUCT_CATEGORY/eventValue/' + productCatagory + '/customEvent?x=' + (new Date()).getTime();			
			//customEventCall(eventServiceProdCatUrl);
		}
			
	}

/**
* Function adds a new onload event.
* Much like jquery but with less overhead.
* example: addLoadEvent(myfunction());
* Note: this will appened to the onload Event
* not over-ride it.
**/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
			try{
				func();
			}catch(e){}
        }
    }
}

