﻿// JScript File
var rb1_e;
function rb1_load() {

//  8/16/2007 Dean Singh
//  Added vtDate to bust the cache on the Handler
var dtDate;
dtDate = new Date();

        BASE_URL = basePath;
        var loc = String(location);
		var server = loc.substring(loc.indexOf("//")+2,loc.indexOf("/",loc.indexOf("//")+2));
		var protocol=(loc.indexOf("https")==-1)?"http":"https";
		var rbUri = protocol+"://"+server+"/Handler/RecentlyBrowsed.ashx?bustCache=";
		
		if (document.domain.toString().indexOf("corp.cinemanow.com") != -1 || loc.indexOf("CurrentBuild") !=-1) 
		{
		    rbUri = protocol+"://"+server+"/CurrentBuild/StoreFront/Handler/RecentlyBrowsed.ashx?bustCache=";
		}
		loc = null;
		server = null;
		protocol = null;
		BASE_URL = rbUri;
		
        if (!rb1_e) {
            return new AJAXRequest("GET", BASE_URL + escape(dtDate), "", rb1_cb);	 
            }   

}


var forceDropDownOpen = false;
function rb1_cb( a ) {

     if (a.readyState == 4) { 

    if (a.status == 200) {
      //logger( a.responseText );
      xml = a.responseXML;
      // We wan to call the AJAXRequest request everytime now so remming out the line below
      //rb1_e = true;
      
      if (xml.documentElement) {
            var tbl = document.getElementById("rbcont"); 
            //Loaded too soon, Reissue request to come back again in 2 ms.
			if(tbl == null)
			{
				forceDropDownOpen = true;
				window.setTimeout(rb1_load, 2);
				return;
			}
			
			tbl.innerHTML = "";
       
            var titleCollection = xml.getElementsByTagName("TitleCollection")[0];
            var titleElements = titleCollection.getElementsByTagName("Title");
            var myHTML = '<table cellpadding="0" cellspacing="6" id="rbtbl" style="border-collapse:separate;" width="100%" class="a10">';
            for (var i=0; i<titleElements.length; i++) {
   
			    var titleID = titleElements[i].getElementsByTagName("titleID")[0].firstChild.nodeValue;
			    var titleName = titleElements[i].getElementsByTagName("name")[0].firstChild.nodeValue;
			    var titlePurchaseText = titleElements[i].getElementsByTagName("purchaseText")[0].firstChild.nodeValue;
			    var titlePurchaseLink = titleElements[i].getElementsByTagName("purchaseLink")[0].firstChild.nodeValue;

                myHTML += '<tr><td align="left"><a href="'+ titlePurchaseLink +'" class="linkblue">';
                myHTML += titleName +'</a></td><td align="right" style="color:#0058c0">';
                myHTML += titlePurchaseText +'</td></tr>'
            }
            
            if (titleElements.length == 0 ) {
                myHTML += '<tr><td>No content has been viewed yet.</td></tr>';
            }
            myHTML += '</table><div style="text-align:right;padding:8px;" class="a11b"><a href="RecentlyBrowsed.aspx" class="linkgray">View All &gt;</a></div>';
            if (tbl) 
			{ 
				tbl.innerHTML += myHTML;
				if(forceDropDownOpen == true)
				{
					forceDropDownOpen = false;
					rbdropopen();
				}
			}
            //alert(myHTML);
      }
    } 
    else {
        //alert("There was a problem retrieving the XML data:\n" + a.statusText);
    }
  }

}
