// !pageName
var pageName = jQuery('#page-title').html();
// !pageName > adjustments
if (pageName == "Page Not Found") pageName = "404";
if (pageName == "dedicated-hosting-gp/default" || pageName == "dedicated-hosting-gp") pageName = "Dedicated PPC";

// !catID
if (jQuery('#breadcrumb-menu').children().size() > 2 ) {
	var catID = jQuery('ul#breadcrumb-menu li:nth-child(2) a').html();
} else if (pageName == "Search") {
	var catID = "SEARCH";
} else if (pageName == "404") {
	var catID = "ERROR";
} else {
	var catID = "ThePlanet.com";
}

// !searchTerm
if (jQuery('.CMSSearchDialogSearchForTextBox').length) {
	var searchTerm = jQuery('.CMSSearchDialogSearchForTextBox').val();
} else {
	var searchTerm = null;
}

// !searchResults
if (jQuery('.PagerResults').length) {
	var resultCount = jQuery('.PagerResults').html();
	var tempA = new Array();
	tempA = resultCount.split('(of');
	var tempB = tempA[1];
	var tempC = new Array();
	tempC = tempB.split(')');
	var searchResults = tempC[0];
} else {
	var searchResults = null;
}

// !pageName(Search)
if (pageName == "Search" && searchResults != null) {
	var searchPageName = "Search Results: Successful page ";
	var searchPage = jQuery('.SelectedPage').html();
	pageName = searchPageName + searchPage;
} else if (pageName == "Search" && searchResults == null) {
	pageName = "Search Results: Unsuccessful"
}

// !pageName(Shopping Cart)
var pageNameCart = window.location.pathname.replace(/.aspx/g, '');
if (pageNameCart == "/servers/" || pageNameCart == "/SERVERS/" || pageNameCart == "/SERVERS/default" || pageNameCart == "/servers/default") pageNameCart = "Servers";
if (pageNameCart == "/servers/configure" || pageNameCart == "/SERVERS/configure") pageNameCart = "Configure";
if (pageNameCart == "/servers/cart" || pageNameCart == "/SERVERS/cart") pageNameCart = "Review";
if (pageNameCart == "/servers/checkout"  || pageNameCart == "/SERVERS/checkout") pageNameCart = "Checkout";
if (pageNameCart == "/servers/success" || pageNameCart == "/SERVERS/success") pageNameCart = "Success";

// !product view > productID
if (pageNameCart == "Configure") {
	var getURLElements = new Array();
	getURLElements = window.location.href.split('?');
	var getProductInfoString = getURLElements[1];
	var getProductID = new Array ();
	getProductID = getProductInfoString.split('&');
	var productID = getProductID[0].replace(/id=/g, '');
} else {
	var productID = null;
}

// !product view > productName
if (jQuery('#cart-summary-specs').length) {
	var productName = jQuery('#cart-summary-specs h3').html().trim();
} else {
	var productName = "All Servers";	
}

// !product view > productcatID
if (pageNameCart == "Configure") {
	var productcatID = getProductID[2].replace(/series=/g, '');
	if (productcatID == "15") {
		productcatID = "Single Processor Single Core";
	} else if (productcatID == "16") {
		productcatID = "Single Processor Multi Core";
	} else if (productcatID == "17") {
		productcatID = "Multi Processor Single Core";
	} else if (productcatID == "18") {
		productcatID = "Multi Processor Multi Core";
	} else if (productcatID == "31") {
		productcatID = "Multi-Server Environment";
	} else if (productcatID == "41") {
		productcatID = "London Multi-Server Environment";
	} else if (productcatID == "42") {
		productcatID = "Cloud Servers";
	} else {
		var productcatID = null;
	}
}

// !shop5
function Shop5() {
	var shopFiveProductID;
	var shopFiveProductName;
	var shopFiveQuantity;
	var shopFiveUnitPrice;
	var shopFiveCatID;

	var packages = jQuery('table#ctl00_ContentMain_Summary th, span.product_id, .standard td.description, .standard td.quantity input, .standard td.cost-mrr').each(function(index)
	{
		//shopFiveProductID
		if (jQuery(this).hasClass('product_id') && shopFiveProductID == null) shopFiveProductID = jQuery(this).html();
		//shopFiveProductName
		if (jQuery(this).hasClass('description') && shopFiveProductName == null)
		{
			shopProductName = jQuery(this).text();
			var shopProductArray = new Array();
			var shopProductArrayTwo = new Array();
			shopProductArray = shopProductName.split('.');
			shopProductArrayTwo = shopProductArray[1].split(' - ');
			shopFiveProductName = shopProductArrayTwo[0];

			shopFiveUnitPrice = null;
			shopFiveQuantity = null;
		}
		//shopFiveQuantity
		if (jQuery(this).val() != '' && shopFiveQuantity == null) shopFiveQuantity = jQuery(this).val();
		//shopFiveUnitPrice
		if (jQuery(this).hasClass('cost-mrr') && shopFiveUnitPrice == null) shopFiveUnitPrice = jQuery(this).html().replace("$", "");
		//shopFiveCatID
		if (jQuery(this).hasClass('single_processor_single_core') && shopFiveCatID == null)
		{
			shopFiveCatID = "Single Processor, Single Core";
		}
			else if (jQuery(this).hasClass('single_processor_multi_core') && shopFiveCatID == null)
		{
			shopFiveCatID = "Single Processor, Multi Core";
		}
			else if (jQuery(this).hasClass('multi_processor_single_core') && shopFiveCatID == null)
		{
			shopFiveCatID = "Multi Processor, Single Core";
		}
			else if (jQuery(this).hasClass('multi_processor_multi_core') && shopFiveCatID == null)
		{
			shopFiveCatID = "Multi Processor, Multi Core";
		}
			else if (jQuery(this).hasClass('multi-server_environment') && shopFiveCatID == null)
		{
			shopFiveCatID = "Multi-Server Environment";
		}
			else if (jQuery(this).hasClass('london_multi-server_environment') && shopFiveCatID == null)
		{
			shopFiveCatID = "London Multi-Server Environment";
		}
			else if (jQuery(this).hasClass('cloud_servers') && shopFiveCatID == null)
		{
			shopFiveCatID = "Cloud Servers";
		}
		if (shopFiveProductName != null && shopFiveQuantity != null && shopFiveUnitPrice != null)
		{
			cmCreateShopAction5Tag(shopFiveProductID, shopFiveProductName, shopFiveQuantity, shopFiveUnitPrice, shopFiveCatID);
			cmDisplayShop5s();
			shopFiveProductID = null;
			shopFiveProductName = null;
			shopProductName = null;
			shopProductArray = null;
			shopFiveCatID = null;
		}
  });
}

// !registration
function Registration() {
	var customerID;
	var customerEmail = jQuery('#ctl00_ContentMain_Email').html();
	var customerCity = jQuery('#ctl00_ContentMain_City').html();
	var customerState = jQuery('#ctl00_ContentMain_State').html();
	var customerPostalCode = jQuery('#ctl00_ContentMain_Postal').html(); 
	var customerCountry = jQuery('#ctl00_ContentMain_Country').html();
	var customerExtras = "Full Name: " + jQuery('#ctl00_ContentMain_FullName').html() + "-_-" + "Company Name: " + jQuery('#ctl00_ContentMain_Company').html();	
	
	if (jQuery('#ctl00_ContentMain_CustomerId').length) {
		customerID = jQuery('#ctl00_ContentMain_CustomerId').html();
	} else {
		customerID = "FirstTimeBuyingOnline";
	}
	cmCreateRegistrationTag(customerID, customerEmail, customerCity, customerState, customerPostalCode, customerCountry, customerExtras);
}

// !shop9

// made the following into global variables so LivePerson could also use the info
var orderSubtotal;
var shopNineOrderID;

function Shop9() {
	//shop9 vars
	var shopNineProductID;
	var shopNineProductName;
	var shopNineQuantity;
	var shopNineUnitPrice;
	var shopNineCustomerID;
	var shopNineSubtotal;
	var shopNineCatID;

	//orderID vars
	var customerCity = jQuery('#ctl00_ContentMain_City').html();
	var customerState = jQuery('#ctl00_ContentMain_State').html();
	var customerPostalCode = jQuery('#ctl00_ContentMain_Postal').html(); 
	orderSubtotal = jQuery('#ctl00_ContentMain_Total').html().replace("$", "");
	var orderShipping = "0.00";
	var orderExtras = "Full Name: " + jQuery('#ctl00_ContentMain_FullName').html() + "-_-" + "Company Name: " + jQuery('#ctl00_ContentMain_Company').html() + "-_-" + "Email: " + jQuery('#ctl00_ContentMain_Email').html();

	var packages = jQuery('table#ctl00_ContentMain_Summary th, span.product_id, span.description, span.quantity, td.sub-total-mrr').each(function(index)
	{
		//shopNineProductID
		if (jQuery(this).hasClass('product_id') && shopNineProductID == null) shopNineProductID = jQuery(this).html();
		//shopNineProductName
		if (jQuery(this).hasClass('description') && shopNineProductName == null) shopNineProductName = jQuery(this).html();
		//shopNineQuantity
		if (jQuery(this).hasClass('quantity') && shopNineQuantity == null) shopNineQuantity = jQuery(this).html();
		//shopNineSubtotal and shopNineUnitPrice
		if (jQuery(this).hasClass('sub-total-mrr') && shopNineSubtotal == null)
		{
			shopNineSubtotal = jQuery(this).html().replace("$", "");
			shopNineUnitPrice = shopNineSubtotal/shopNineQuantity;
		}
		//shopNineCustomerID
		if (jQuery('#ctl00_ContentMain_CustomerId').length) {
			shopNineCustomerID = jQuery('#ctl00_ContentMain_CustomerId').html();
		} else {
			shopNineCustomerID = "FirstTimeBuyingOnline";
		}
		//shopNineOrderID
		if (jQuery('#ctl00_ContentMain_OrderId').length) {
			shopNineOrderID = jQuery('#ctl00_ContentMain_OrderId').html();
		} else {
			shopNineOrderID = "111111";
		}
		//shopNineCatID
		if (jQuery(this).hasClass('single_processor_single_core') && shopNineCatID == null)
		{
			shopNineCatID = "Single Processor, Single Core";
		}
			else if (jQuery(this).hasClass('single_processor_multi_core') && shopNineCatID == null)
		{
			shopNineCatID = "Single Processor, Multi Core";
		}
			else if (jQuery(this).hasClass('multi_processor_single_core') && shopNineCatID == null)
		{
			shopNineCatID = "Multi Processor, Single Core";
		}
			else if (jQuery(this).hasClass('multi_processor_multi_core') && shopNineCatID == null)
		{
			shopNineCatID = "Multi Processor, Multi Core";
		}
			else if (jQuery(this).hasClass('multi-server_environment') && shopNineCatID == null)
		{
			shopNineCatID = "Multi-Server Environment";
		}
			else if (jQuery(this).hasClass('london_multi-server_environment') && shopNineCatID == null)
		{
			shopNineCatID = "London Multi-Server Environment";
		}
			else if (jQuery(this).hasClass('cloud_servers') && shopNineCatID == null)
		{
			shopNineCatID = "Cloud Servers";
		}
		//call the shop9 tag
		if (shopNineProductName != null && shopNineQuantity != null && shopNineUnitPrice != null)
		{
			cmCreateShopAction9Tag(shopNineProductID, shopNineProductName, shopNineQuantity, shopNineUnitPrice, shopNineCustomerID, shopNineOrderID, shopNineSubtotal, shopNineCatID, null);
			cmDisplayShop9s();
			shopNineProductID = null;
			shopNineProductName = null;
			shopNineSubtotal = null;
			shopNineQuantity = null;
			shopNineUnitPrice = null;
			shopNineCatID = null;
		}
  });
  cmCreateOrderTag(shopNineOrderID, orderSubtotal, orderShipping, shopNineCustomerID, customerCity, customerState, customerPostalCode, orderExtras);
}

// !conversion events
function conversionTwo(conversionType, obj) {
	if (conversionType == "pdf") {
			var eventID = jQuery(obj).html();
			var eventCatID = "Document";
	} else if (conversionType == "video") {
			var eventIdUrl = jQuery(obj).attr('href');
			var eventIdArray = new Array();
			eventIdArray = eventIdUrl.split('&');
			var eventIdFileName = new Array();
			eventIdFileName = eventIdArray[0].split('/');
			var eventID = eventIdFileName[eventIdFileName.length-1];
			if (eventID == "theplanet.swf") eventID = "Data Center Tour";
			var eventCatID = "Video";
	}	else {
		var eventID = "Unlabeled Event";
		var eventCatID = "Unlabeled Category";
	}
	cmCreateConversionEventTag(eventID, "2", eventCatID, null, null);
}
jQuery("a[href$=pdf]").click(function () { 
      conversionTwo('pdf', this);
    });
jQuery("a[href$=flv]").click(function () { 
      conversionTwo('video', this);
    });
jQuery("a[href$=swf]").click(function () { 
      conversionTwo('video', this);
    });
