﻿// CLICKTORCH INCLUDE MOVIEGOODS.COM V1.62 Website makeover layout folder shop cart include
//
//FUNCTION DISPLAY DETAILS IN A DIV: ajaxpage(gotoURL, 'contentarea')
/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

if (!profilerCookieValue) var profilerCookieValue = "END";

function ajaxpage2(url, containerid){
var page_request = false
var tempArray = url.split("|")
url = tempArray[0]
var product = tempArray[1]
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage3(page_request, url, product, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}


function loadpage3(page_request, url, product, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
      if (page_request.responseText.match("Page Not Found") || !page_request.responseText.match("main_product_image")) {
      getNextID(containerid)
      }
      else {
	var finalContent = getContent(url, product, page_request.responseText)
      document.getElementById(containerid).innerHTML= finalContent
      }
}
}

function getNextID(containerid)
{
if(ContentCount < ContentList.length-1)
	{
	var contentnum = ContentCount;
	ContentCount++;
	ajaxpage2(ContentList[contentnum], containerid);
	}
}


function getContent(page_url, product_details, response_text)
{
// check test urls
var tempURL = "" + document.location;
if(tempURL.match("www.moviegoods.com")){
tempURL = page_url.replace("http://www.moviegoods.com","http://www.moviegoods.com");
page_url = tempURL; 
}
product_details = product_details.replace("undefined", " ");
product_details = product_details.replace("<prodname>", "");	// 0 = name
product_details = product_details.replace("<prodprice>", "|");	// 1 = price
product_details = product_details.replace("<prodimage>", "|");	// 2 = image

var prodArray = product_details.split("|");

// get product name
var profprodname = response_text;
if (profprodname != ""  && profprodname.match(/<H1>/i)) {
profprodname = profprodname.replace(/<H1>/i, "^");
profprodname = profprodname.replace(/<\/H1>/i, "^");
var namearray = profprodname.split('^');
if(namearray[1]){
profprodname = namearray[1];
if(profprodname != "") prodArray[0] = profprodname;
}
}

// get image
var profprodimage = response_text;
if (profprodimage != "" && profprodimage.match(/main_product_image/i)) {
profprodimage = profprodimage.replace(/main_product_image/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;
}
}
}

// need to put small image in
prodArray[2] = prodArray[2].replace(/1010/g, "1000");

// get rid of year brackets
prodArray[0] = prodArray[0].replace(/ \(.+?\)/, "");

var innerContent = '<BR><A href="' +  page_url + '" onClick="profilerLink()"><IMG class="poster_thumbnail_img" src="' +  prodArray[2] + '" title="' +  prodArray[0] + '"><BR>' +  prodArray[0] + '</A><BR>';
if (document.body.innerHTML.match("Empty Shopping Cart")){
innerContent = '<A href="' +  page_url + '" onClick="profilerLink()"><IMG src="' +  prodArray[2] + '" title="' +  prodArray[0] + '"><BR><SPAN style="FONT: 11px Arial">' +  prodArray[0] + '</SPAN></A><BR>';
}
return innerContent;
}


function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.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)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}


function writeDivs()
{
var content = '<DIV class=poster_thumbnail id="Profiler1"></DIV><DIV class=poster_thumbnail id="Profiler2"></DIV><DIV class=poster_thumbnail id="Profiler3"></DIV><br>';
if (document.body.innerHTML.match("Empty Shopping Cart")){
content = '<DIV class=new_posters_option id="Profiler1"></DIV><DIV class=new_posters_option id="Profiler2"></DIV><DIV class=new_posters_option id="Profiler3"></DIV><DIV class=new_posters_option id="Profiler4"></DIV><DIV class=new_posters_option id="Profiler5"></DIV>';
}
document.getElementById("whole").innerHTML=content;
}

var profDisplayTitle = document.title.replace("'", "");//check for cart empty

var profSearchRef = "&PROFPROD=0";
if (document.body.innerHTML.match("Empty Shopping Cart")){
profSearchRef = "&PROFPROD=ProfCartEmpty";
}

if (document.getElementById('whole')) {

if (!document.location.href.match("https:")) {
var target = "http://profilertracking3.com/moviegoods/suggestPages_inside_moviegoods2.asp?HREF=" + document.location.href + "&TITLE=" + profDisplayTitle + profSearchRef + "&PLINK=" + profilerCookieValue;
} else {
var target = "https://profilertracking3.com/moviegoods/suggestPages_inside_moviegoods2.asp?HREF=" + document.location.href + "&TITLE=" + profDisplayTitle + profSearchRef + "&PLINK=" + profilerCookieValue;
}
loadobjs(target);
}



