function getCookie(name) {  
	var startLoc = document.cookie.indexOf("; " + name + "=") + 2;  
	 if (startLoc == 1) {  
		startLoc = document.cookie.indexOf(name + "=");  
		if (startLoc != 0) return("");  
	}  
	var endLoc = document.cookie.indexOf(";", startLoc);  
	if( endLoc == -1) { endLoc = document.cookie.length; }  
	return unescape(document.cookie.substring(startLoc + name.length + 1, endLoc));  
} 

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : ";path=/" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : ";path=/") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function getUrlVar(name) {
	ignoreCaseUrl =  location.search.toUpperCase();
	startLoc = ignoreCaseUrl.indexOf(name + "=");  
    if (startLoc == -1) { return(""); } 
	var endLoc = location.search.indexOf("&", startLoc);
	if( endLoc == -1) { endLoc = location.search.length; }  
	return(location.search.substring(startLoc + name.length + 1, endLoc));  
}

<!-- check if new session -->
if(!getCookie('session')){
	var newSession = true;
	setCookie('session', true);
	var source = getSource();
	setCookie('refer', escape(document.referrer));
}

<!-- get set source or refer url -->
function getSource() {
	source = getUrlVar('S');
	if (source == 'CJ'){
		setCookie('keyword', "AID=" + getUrlVar('AID')+"|PID=" + getUrlVar('PID')+"|SID=" + getUrlVar('SID'), 30);
	}else if (source != ''){
		setCookie('keyword', getUrlVar('K'),30);
	}else{
		if (document.referrer != ''){
			var start = document.referrer.indexOf("://")+3;
			var end = document.referrer.indexOf("/", start);
			if (end == -1) end = document.referrer.length;
			source = escape(document.referrer.substring(start, end));
		}else{
			source = 'noRefer';
		}
	}
	if (source != 'noRefer'){ 
		setCookie('source', source, 30);
	}
	setCookie('sourcePath', getCookie('sourcePath')+source+'|', 120);
}

<!-- Omniture Code -->
<!-- this function removes all characters between & and ;. This creates Omniture friendly strings -->
function removeSymbols(string) {
    for (var i=0, output='', goodChar=true; i<string.length; i++){
		if (string.charAt(i) == '&'){
			goodChar=false;
		}
		if (goodChar){
			output += string.charAt(i)
		}
		if (string.charAt(i) == ';'){
			goodChar=true;
		}
	}
	return output;
}

<!-- Omniture Code -->
if(s_pageName==null){ var s_pageName=removeSymbols(document.title);}
var s_server="ecom2";
if(s_channel==null){var s_channel="Shopping";}
var s_account="iconpowerbell";
if(getUrlVar('S')){var s_campaign=getUrlVar('S') +' - '+ getUrlVar('K');}
var s_code=s.t();if(s_code)document.write(s_code)
<!-- End Omniture Code -->