<!--
/*
 * www.kicc.us Global Tag Logic
 */

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function cmIndexOfDomain (domain) {
	return document.URL.indexOf(domain);
}
function cmIndexOfReferrer (domain) {
	return document.referrer.indexOf(domain);
}

if (cmIndexOfDomain("kicc.us") != -1) {
	if (cmIndexOfReferrer("66.179.5.110") < 0)	{   // don't send forms to prod if originated from staging
		cmSetProduction();
	}
}

var cmpageviewcatID = cmGetCatID();

if (cmIndexOfDomain("www.kicc.us/index.php") != -1)  {
	  cmCreatePageviewTag("index.html", cmpageviewcatID);
}

else { 
	cmCreatePageviewTag(null, cmpageviewcatID); }

function cmGetCatID() {
	var pageName = window.location.href;
	pageName = pageName.substr(0,pageName.length);
	for(var i = (pageName.lastIndexOf("/") - 1); i > -1; i--) {
		if (pageName.charAt(i) == "/") {
			i = i + 1;
			cmpageviewcatID = pageName.substring(i,pageName.lastIndexOf("/"));
			return(cmpageviewcatID);
		}
	} 
}

if (cmExtractParameter("thankyou",document.location.href) || cmExtractParameter("request_info_thanks",document.location.href) 
	|| cmExtractParameter("application_thanks",document.location.href))
	{		// Form submitted: thank-you page

	orderID = "RANDOM_ORDER_NUM_" + dt.getTime()%10000000;
	productID = cmExtractParameter("id=",document.location.href);
	productName = cmExtractParameter("id=",document.location.href);

	cmgetCookievalues();

	cmCreateConversionEventTag(cmExtractParameter("id=",document.location.href), "2", cmExtractParameter("cmcat=",document.location.href), "10"); 

	cmCreateShopAction9Tag(productID,productName,"1","10.00",customerID,orderID,"10.00",cmExtractParameter("cmcat=",document.location.href));
	cmDisplayShop9s();

	cmCreateOrderTag(orderID,"10.00","0",customerID,null,cmregState);

	cmCreateRegistrationTag(customerID,cmregEmail,cmregState,cmregCountry,cmpurchase_timeframe,cmjob_function,cmrole,cmpage_views,
		cmrevenue,cmsearch_spend,cmindustry);

	cmCreateCustomRingLeadTag(customerID,cmregState,cmregCountry,cmregIam,cmregFirstName,
				cmregLastName,cmregTitle,cmregCompany,cmregPhone,productID,cmExtractParameter("cmcat=",document.location.href),
				 "10"); 
} else {
	if (cmExtractParameter("id=",document.location.href))
	{		// Form loaded
		
		productID = cmExtractParameter("id=",document.location.href);
		productName = cmExtractParameter("id=",document.location.href);

		cmCreateProductviewTag(productID, productName, cmExtractParameter("cmcat=",document.location.href), "N");

		cmCreateConversionEventTag(cmExtractParameter("id=",document.location.href), "1", cmExtractParameter("cmcat=",document.location.href), "10"); 
	}
}

function cmgetCookievalues() {
	var first_name = readCookie('first_name')
	var last_name = readCookie('last_name')
	var title = readCookie('title')
	var company = readCookie('company')
	var email = readCookie('email')
	var phone = readCookie('phone')
	var state = readCookie('state')
	var country = readCookie('country')
	var i_am = readCookie('i_am')
	var purchase_timeframe = readCookie('purchase_timeframe')
	var job_function = readCookie('job_function')
	var role = readCookie('role')
	var page_views = readCookie('page_views')
	var revenue = readCookie('revenue')
	var search_spend = readCookie('search_spend')
	var industry = readCookie('industry')
	if (first_name) {
		cmregFirstName = first_name;
	}
	if (last_name) {
		cmregLastName = last_name;
	}
	if (title) {
		cmregTitle = title;
	}
	if (company) {
		cmregCompany = company;
	}
	if (email) {
		cmregEmail = email;
		customerID = email;
	}
	if (phone) {
		cmregPhone = phone;
	}
	if (state) {
		cmregState = state;
	}else {
		cmregState = null;
	}
	if (country) {
		cmregCountry = country;
	}
	if (i_am) {
		cmregIam = i_am;
	} else {
		cmregIam = null;
	}
	if (purchase_timeframe) {
		cmpurchase_timeframe = purchase_timeframe;
	} else {
		cmpurchase_timeframe = null;
	}
	if (job_function) {
		cmjob_function = job_function;
	} else {
		cmjob_function = null;
	}
	if (role) {
		cmrole = role;
	} else {
		cmrole = null;
	}
	if (page_views) {
		cmpage_views = page_views;
	} else {
		cmpage_views = null;
	}
	if (revenue) {
		cmrevenue = revenue;
	} else {
		cmrevenue = null;
	}
	if (search_spend) {
		cmsearch_spend = search_spend;
	} else {
		cmsearch_spend = null;
	}
	if (industry) {
		cmindustry = industry;
	} else {
		cmindustry = null;
	}
}

//-->