// CLICKTORCH INCLUDE MOVIEGOODS.COM V1.61 Website makeover

// first party cookie to record clicks and show previous views

function profilerLink() 
	{ document.cookie = "profilerCookie=true;path=/"; }

function profilerRepeat(session) {
	var date = new Date();
	date.setTime(date.getTime()+(60*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = "profilerRepeat=" + session + expires + ";path=/";
}

function readCookie() { 
	var nameEQ = "profilerCookie="; 
	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 "END"; }


// tracking code to get meta data

function getmetaContents(mn) {
	var m = document.getElementsByTagName('meta');   
	for(var i in m){    if(m[i].name == mn){      return m[i].content;  
  }   } }

document.getElementsByClass = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes) && elem[i].innerHTML) { retnode.push(elem[i]);
return elem[i].innerHTML; }
}
return "";
}; 

var profSearchRef = "&PROFPROD=0";

if (document.body.innerHTML.match(/main_product_image/i)) // check for product page
{

profSearchRef = "&PROFPROD=1";

// get product name
if(document.getElementsByTagName("h1")){
var profprodname = document.getElementsByTagName("h1")[0].innerHTML;

if (profprodname.match(/href/i)) {
profprodname = profprodname.replace(/</g, '^');
profprodname = profprodname.replace(/>/g, '^');
var profprodarray = profprodname.split('^');
if(profprodarray[2] && profprodarray[4]) profprodname = profprodarray[0] + profprodarray[2] + profprodarray[4];
}

profSearchRef = profSearchRef + "&prodname=" + profprodname;
}


// get image
var profprodimage = document.body.innerHTML;
if (profprodimage != "" && profprodimage.match(/poster_image_area/i)) {
profprodimage = profprodimage.replace(/poster_image_area/i, '^');
var imagearray = profprodimage.split('^');
imagearray[1] = imagearray[1].replace(/src=/ig, "^");
var imagearray1 = imagearray[1].split('^');
if(imagearray1[1]){
var imagearray2 = imagearray1[1].split('"');
if(imagearray2[1]){
profprodimage = imagearray2[1];
profSearchRef = profSearchRef + "&prodimage=" + profprodimage;
}
}
}

// get product price
var profprodcode = document.body.innerHTML;
if (profprodcode != "" && profprodcode.match(/main_product_image/i)) {
profprodcode = profprodcode.replace(/Price:/i, '^');
var pricearray0 = profprodcode.split('^');
if(pricearray0[1]){
var pricearray = pricearray0[1].split('$');
if(pricearray[1]){
var pricearray2 = pricearray[1].split('<');
profprodcode = pricearray2[0];
profSearchRef = profSearchRef + "&prodprice=" + profprodcode;
}
}
}

}

var profilerCookieValue = "FALSE";
profilerCookieValue = readCookie();
document.cookie = "profilerCookie=false;path=/";
// test to check if cookies are enabled
if (readCookie() == "END") profilerCookieValue = "noCookiesEnabled";
var profTitle = document.title.replace("'", "");

// clean url
var urlprof = document.location.href;
var urlprofarray = urlprof.split("#");
urlprof = urlprofarray[0];

// send data to server

if (!document.location.href.match("https:")) {
document.write("<s" + "cript language='javascript' src='http://profilertracking3.com/moviegoods/recordClicks_inside.asp?HREF=" + urlprof + "&TITLE=" + profTitle + "&PLINK=" + profilerCookieValue + profSearchRef + "&REF=" + document.referrer + "'></sc" + "ript>"); 
} else {
document.write("<s" + "cript language='javascript' src='https://profilertracking3.com/moviegoods/recordClicks_inside.asp?HREF=" + urlprof + "&TITLE=" + profTitle + "&PLINK=" + profilerCookieValue + profSearchRef + "&REF=" + document.referrer + "'></sc" + "ript>"); 
}

var profloadedobjects=""

function loadobjsprof(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (profloadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".asp")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
profloadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

// END Script for profiler tracking link recording
