//JavaScript by Damien
if (String(location).toLowerCase().indexOf("mediamanager_rq1.aspx")!=-1||String(location).toLowerCase().indexOf("mediamanager_rq2.aspx")!=-1) {debug=true}else{debug=false}

boxesloaded=0;
titleinfo_array=[];
selectlist_array=[];
dlstatusarray=[];
similars=[];

whatsthis=[];
whatsthis.push('<i>Licenses Used:</i><br/><br/>The "Licenses Used" information shows you on how many different locations have you downloaded and watched your movies.<br/><br/>All the videos you purchased or rented from Cinemanow are stored in your online Media Library. Depending on whether you purchased or rented a video, you get the ability to download and play on several PC\'s, portables or other Cinemanow enabled devices. Typically, if you rent a video, you can watch it on one location. If you buy a video, you can watch it on up to 3 locations. You can also sync a purchased video to a compatible portable device.<br/><br>Note: Due to licensing restrictions, this information may change per title.')
whatsthis.push('<i>File Types:</i><br/><br/>Cinemanow Videos may be available in different formats, optimized for different devices. Choose the right file type, depending on where you plan on watching your video.<br/><br/>Premium: optimized for PC or TV viewing<br/>Portable: optimized for portable devices <br/><br/>For portables, look for the Microsoft "PlaysForSure" sticker on the package to ensure compatibility.')
whatsthis.push('<i>Locations:</i><br/><br/>"Locations" will keep track of any PC, portable or other Cinemanow enabled device that you stored and watched your video on.')

loc = String(location);
server = loc.substring(loc.indexOf("//")+2,loc.indexOf("/",loc.indexOf("//")+2));
protocol=(loc.indexOf("https")==-1)?"http":"https";
webservices = protocol+"://"+server+"/api/";

if (document.domain.toString().indexOf("corp.cinemanow.com") != -1) {
    webservices = protocol+"://"+server+"/currentBuild/WebServices/api/";
}

firstload=true;
starttmr = 0;


function startrq() {
//this is little hack is neccessary due to buggy Firefox rendering of PNG images
	newbox = document.createElement("span");
	newbox.setAttribute("id","newwhatsthis");
	document.forms[0].appendChild(newbox);
	getwhatsthis = dg("firefoxfix").innerHTML;
	dg("firefoxfix").innerHTML="";
	newbox.innerHTML = getwhatsthis;

	if (browser=="ff") {document.body.style.overflow="-moz-scrollbars-vertical"}

	ajl(webservices+"remoteq.asmx/LibraryRequest",libraryrequest_callback,"UserID="+userID,ajaxerror,true);
	ajl(webservices+"remoteq.asmx/DownloadStatusLookup",downloadstatus_callback,"",ajaxerror,true);
	ajl(webservices+"remoteq.asmx/GetDestinationsByUser",destinations_callback,"UserID="+userID,ajaxerror,true);

	statusloop();
	unselectable(dg("mainmmDiv"));
	startloop();
	doresize();
}

function startloop() {
	if (
		statusloaded == true			&&
		libraryarray.length>0			&&
		destinationarray.completed == true	&&
		dlstatusarray.completed==true
	) {
		dg("loadingDiv").style.display="none";
		tabclick("queue");
	} else {
		setTimeout("startloop()",500);
	}
}


currenttab="";
function tabclick(thistab) {
	if (thistab==currenttab) {return}
	selectlist_array=[]
	dg("titleInfoDiv").style.display="none"
	dg("infoboximgDiv").innerHTML = '<img id="infoboximg" src="img/spacer.gif"  border="0"/>'
	dg("infoboxmirrorfade").style.backgroundImage="url(img/spacer.gif)"

	try{
		dg(currenttab+"tabimg").src = "img/mmgr/tab_"+currenttab+"_off.gif"
		dg(currenttab+"tabon").src = "img/spacer.gif"
		dg(currenttab+"Div").style.display="none"
	}catch(e){}
	dg(thistab+"tabimg").src = "img/mmgr/tab_"+thistab+"_on.gif"
	dg(thistab+"tabon").src = "img/mmgr/tab_on_lower.gif"
	dg(thistab+"Div").style.display="block"
	currenttab = thistab
	if (thistab=="queue") {
		drawqueue(libraryarray)
		if (currenttab=="queue") {
			doresize()
			setTimeout('try{dg("topqueue").getElementsByTagName("TR")[0].onclick();}catch(e){}',250)
		}

		if (firstload==false&&currenttab=="library") {
			alertbox("You have no items in your queue.")
		}

	} else {
		dg("searchbox").value="Search"
		lastsearch=""
		drawlibrary(libraryarray)
		doresize()
		setTimeout('try{dg("scrollhead").getElementsByTagName("TR")[0].onclick();}catch(e){}',250)
	}

	closedestination()
	closefiletype()
	setTimeout("firstload=false",500)

}

function tabover(thistab) {
	if (thistab==currenttab) {return}
	dg(thistab+"tabimg").src="img/mmgr/tab_"+thistab+"_over.gif"
}

function tabout(thistab) {
	if (thistab==currenttab) {return}
	dg(thistab+"tabimg").src="img/mmgr/tab_"+thistab+"_off.gif"
}

function thisover(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	if (evtsrc.tagName!="IMG") {return true}
	try{evt.preventDefault()}catch(e){}
	if (evtsrc.src.indexOf("_on.")!=-1) {return}
	evtsrc.src = String(evtsrc.src).replace(/\_on\./g,"_over.")
	evtsrc.src = String(evtsrc.src).replace(/\_off\./g,"_over.")
	evtsrc.src = String(evtsrc.src).replace(/\_pressed\./g,"_over.")
}

function thisoff(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	if (evtsrc.tagName!="IMG") {return true}
	try{evt.preventDefault()}catch(e){}
	if (evtsrc.src.indexOf("_on.")!=-1) {return}
	evtsrc.src = String(evtsrc.src).replace(/\_on\./g,"_off.")
	evtsrc.src = String(evtsrc.src).replace(/\_over\./g,"_off.")
	evtsrc.src = String(evtsrc.src).replace(/\_pressed\./g,"_off.")
}

function thison(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	if (evtsrc.tagName!="IMG") {return true}
	try{evt.preventDefault()}catch(e){}
	evtsrc.src = String(evtsrc.src).replace(/\_over\./g,"_on.")
	evtsrc.src = String(evtsrc.src).replace(/\_off\./g,"_on.")
	evtsrc.src = String(evtsrc.src).replace(/\_pressed\./g,"_on.")
}

function thispress(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	if (evtsrc.tagName!="IMG") {return true}
	try{evt.preventDefault()}catch(e){}
	evtsrc.src = String(evtsrc.src).replace(/\_on\./g,"_pressed.")
	evtsrc.src = String(evtsrc.src).replace(/\_over\./g,"_pressed.")
	evtsrc.src = String(evtsrc.src).replace(/\_off\./g,"_pressed.")
}

function filetypedrop(thisobj) {
	setopacity("filetypedropdownDiv",100)
	dg("filetypeslide").style.top="-800px"
	dg("filetypedropdownDiv").style.display="block"
	ftypeheight = dg("filetypeslide").offsetHeight
	dg("filetypeslide").style.top= "-"+ftypeheight+"px"
	dg("filetypedropdownDiv").style.height = ftypeheight+"px"
	dg("filetypedropdownDiv").style.left = (getleft(thisobj)+7)+"px"
	dg("filetypedropdownDiv").style.top = (gettop(thisobj)+24)+"px"
	fx("filetypeslide",10,fx_slidein,"filetypeopen=true","top,-"+ftypeheight+",0")
}

function destinationdrop(thisobj) {
	setopacity("destinationdropdownDiv",100)
	dg("destinationslide").style.top="-800px"
	dg("destinationdropdownDiv").style.display="block"
	destheight = dg("destinationslide").offsetHeight
	if (destheight+gettop(thisobj)+24<dbch) {
		dg("destinationslide").style.top= "-"+destheight+"px"
		dg("destinationdropdownDiv").style.height = destheight+"px"
		dg("destinationdropdownDiv").style.left = (getleft(thisobj)+7)+"px"
		dg("destinationdropdownDiv").style.top = (gettop(thisobj)+24)+"px"
		fx("destinationslide",10,fx_slidein,"destinationopen=true","top,-"+destheight+",0")
	} else {
		dg("destinationslide").style.top = destheight+"px"
		dg("destinationdropdownDiv").style.height = destheight+"px"
		dg("destinationdropdownDiv").style.left = (getleft(thisobj)+7)+"px"
		dg("destinationdropdownDiv").style.top = (gettop(thisobj)-destheight)+"px"
		fx("destinationslide",10,fx_slidein,"destinationopen=true","top,"+destheight+",0")
	}
}

filetypeopen = false
currentfiletype = -1
function newfiletype(thissort) {
	if (thissort==currentfiletype) {return}
	try{dg("filetype_"+currentfiletype).className = "droplistoff"}catch(e){}
	try{
		dg("filetype_"+thissort).className = "dropliston"
		currentfiletype=thissort
		closefiletype()
		dg("filetypebox").innerHTML = dg("filetype_"+thissort).innerHTML
	}catch(e){}
}

function closefiletype() {
	filetypeopen=false
	fx("filetypedropdownDiv",5,false,'filetypeopen=false;dg("filetypedropdownDiv").style.display="none"',"opacity,100,0")
}

function closedestination() {
	destinationopen=false
	fx("destinationdropdownDiv",5,false,'destinationopen=false;dg("destinationdropdownDiv").style.display="none"',"opacity,100,0")
	dg("destinationdropdownDiv").style.display='none'
}

currentlistf = ""
function listf(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	try{evt.preventDefault()}catch(e){}
	if (evtsrc==currentlistf) {return}
	try{currentlistf.className = "alphaselect"}catch(e){}
	evtsrc.className = "alphaselected"
	currentlistf = evtsrc

	if (evtsrc.innerHTML == "All") {
		searcharray=[]
		dg("searchbox").value="Search"
		searchlist("")
		currentlistf = ""
		return
	}

	if (evtsrc.innerHTML =="| 0-9 |") {
		dg("searchbox").value="0-9"
		searchlist("0-9")
		return
	}

	dg("searchbox").value = evtsrc.innerHTML
	searchlist(evtsrc.innerHTML)
}

function unselectable(thisparent) {
	if (browser!="ie") {return}
	docall = thisparent.getElementsByTagName("TR")
	for (i=0;i<docall.length;i++) {
		docall[i].unselectable="on";
	}
	docall = thisparent.getElementsByTagName("TD")
	for (i=0;i<docall.length;i++) {
		docall[i].unselectable="on";
	}
}

function removenullnodes(thisparent) {// We must save Firefox from itself..
	if (browser=="ie"){return}
	var con = thisparent;
	for (var idiv=0;idiv<con.childNodes.length;idiv++) {
		if (con.childNodes[idiv].id==undefined) {
			con.removeChild(con.childNodes[idiv]);
		}
	}
}

currentview = "list"
function changeview(thisview) {
	if (thisview=="list") {
		dg("viewlistimg").src="img/mmgr/view_list_on.gif"
		dg("viewboximg").src = "img/mmgr/view_box_off.gif"
		for (var i=0;i<topcount;i++) {
			try{dg("listimg"+i).style.display="none"}catch(e){}
		}
	}

	if (thisview=="box") {
		dg("viewlistimg").src="img/mmgr/view_list_off.gif"
		dg("viewboximg").src = "img/mmgr/view_box_on.gif"
		for (var i=0;i<topcount;i++) {
			try{dg("listimg"+i).style.display="block"}catch(e){}
		}
	}
	currentview = thisview
	dg("scroller").style.top="0px"
	doresize()
}

currentinfoview = ""
function changeinfoview(thisview) {
	dg("titleInfoDiv").style.display="block"
	if (thisview==currentinfoview) {return}
	if (dg("info_"+thisview+"_tab").src.indexOf("ghost")!=-1) {return}
	if (dg("info_"+thisview+"_tab").style.cursor!="pointer") {return}
	if (dg("info_downloads_tab").src.indexOf("ghost")==-1) {
		try{dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_off.gif"}catch(e){}
	}
		try{dg("info_downloads_select").src="img/spacer.gif"}catch(e){}
		try{dg("info_downloadsDiv").style.display="none"}catch(e){}
	if (dg("info_titleinfo_tab").src.indexOf("ghost")==-1) {
		try{dg("info_titleinfo_tab").src="img/mmgr/tab_info_titleinfo_off.gif"}catch(e){}
	}
		try{dg("info_titleinfo_select").src="img/spacer.gif"}catch(e){}
		try{dg("info_titleinfoDiv").style.display="none"}catch(e){}
	if (dg("info_similar_tab").src.indexOf("ghost")==-1) {
		try{dg("info_similar_tab").src="img/mmgr/tab_info_similar_off.gif"}catch(e){}
	}
		try{dg("info_similar_select").src="img/spacer.gif"}catch(e){}
		try{dg("info_similarDiv").style.display="none"}catch(e){}
	dg("info_"+thisview+"_tab").src="img/mmgr/tab_info_"+thisview+"_on.gif"
	dg("info_"+thisview+"_select").src="img/mmgr/tab_info_selected.gif"
	dg("info_"+thisview+"Div").style.display="block"
	currentinfoview = thisview
	if (selectlist_array.length==0) {
		dg("titleInfoDiv").style.display="none"
	}
	doresize()
}

//===============================================================

function titlescallback(gettitlexml) {
//--------------------------------
// Parses XML into TitleList array

	var titledom = gettitlexml.documentElement;
	try{
		var titlelist = new Object();
		var titlelistXML = titledom.childNodes;

			var titlelistslist = titlelist;
			for (idx=0;idx<titlelistXML.length;idx++) {
				if (titlelistXML[idx].tagName==undefined) {continue};
					titlesubname = titlelistXML[idx].tagName;
					if (titlelistXML[idx].childNodes.length==0) {eval("titlelistslist."+titlesubname+"=null");continue};
					titlelistsubXML = titlelistXML[idx].getElementsByTagName("anyType");
					if (titlelistsubXML.length>0) {
						eval("titlelistslist."+titlesubname+"=[]");
						for (ixs=0;ixs<titlelistsubXML.length;ixs++) {
							titleitemtext = titlelistsubXML[ixs].childNodes.item(0).nodeValue;
							eval("titlelistslist."+titlesubname+".push(titleitemtext)");
						}
					} else {
						try{
							titleitemtext = titlelistXML[idx].childNodes.item(0).nodeValue;
							eval("titlelistslist."+titlesubname+"=titleitemtext");
						}catch(e){}
					}
			}

	}catch(e){}

	titleinfo_array[titlelist.TitleID]=titlelist
	drawtitleinfo(titlelist)
}

function drawtitleinfo(thisinfo) {

	try{
		synopsis = thisinfo.ShortSynopsis
	}catch(e){
		try{
			synopsis = thisinfo.Description
		}catch(e){
			try{
				synopsis = thisinfo.DescriptionLong
			} catch(e) {
				synopsis = ""
			}
		}
	}

	if (synopsis==null) {synopsis=""}

	thissynopsis = synopsis.replace(/\&lt\;FONT.*?\&gt\;/g,"").replace(/\<FONT.*?\>/g,"").replace(/\&lt\;\/FONT\&gt\;/g,"").replace(/\<\/FONT\>/g,"")

	newinfo = []

	newinfo.push(' <div id="info_titlename" align="left" style="font-size:18px;">'+thisinfo.Name+'</div>')
	if (thisinfo.UserRating>0) {
		newinfo.push(' <div id="info_userrating" align="left">Average Customer Rating: <img src="img/mmgr/stars2_'+thisinfo.UserRating+'.gif" border="0"/></div>')
	}

	if (thissynopsis!="") {
		newinfo.push(' <div id="info_synopsis" align="left" style="line-height:19px;"><span style="font-weight:700;">Synopsis:</span>&nbsp;'+thissynopsis+'</div>')
	}

	newinfo.push('<div align="left"><table cellpadding="3" cellspacing="0" border="0" id="infotable">')

	if (thisinfo.Rating!=null) {
		newinfo.push(' <tr><td valign="top"><strong>Rating:</strong></td><td valign="top">'+thisinfo.Rating+'</td></tr>')
	}
	if (thisinfo.ReleaseYear!=null) {
		newinfo.push(' <tr><td valign="top"><strong>Released:</strong></td><td valign="top">'+thisinfo.ReleaseYear+'</td></tr>')
	}
	if (thisinfo.Directors!=null) {
		if (thisinfo.Directors.length>1) {plural="s"}else{plural=""}
		for (var i=0;i<thisinfo.Directors.length;i++) {
			if (i==0) {
			newinfo.push(' <tr><td><strong>Director'+plural+':</strong></td><td><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thisinfo.Directors[i])+'">'+thisinfo.Directors[i]+'</a></td></tr>')
			} else {
			newinfo.push(' <tr><td></td><td><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thisinfo.Directors[i])+'">'+thisinfo.Directors[i]+'</a></td></tr>')
			}
		}
	}
	if (thisinfo.Starring!=null) {
		for (var i=0;i<thisinfo.Starring.length;i++) {
			if (i==0) {
			newinfo.push(' <tr><td><strong>Starring:</strong></td><td><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thisinfo.Starring[i])+'">'+thisinfo.Starring[i]+'</a></td></tr>')
			} else {
			newinfo.push(' <tr><td></td><td><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thisinfo.Starring[i])+'">'+thisinfo.Starring[i]+'</a></td></tr>')
			}
		}
	}
	if (thisinfo.Producers!=null) {
		if (thisinfo.Producers.length>1) {plural="s"}else{plural=""}
		for (var i=0;i<thisinfo.Producers.length;i++) {
			if (i==0) {
			newinfo.push(' <tr><td><strong>Producer'+plural+':</strong></td><td><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thisinfo.Producers[i])+'">'+thisinfo.Producers[i]+'</a></td></tr>')
			} else {
			newinfo.push(' <tr><td></td><td><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thisinfo.Producers[i])+'">'+thisinfo.Producers[i]+'</a></td></tr>')
			}
		}
	}
	if (thisinfo.Writers!=null) {
		if (thisinfo.Writers.length>1) {plural="s"}else{plural=""}
		for (var i=0;i<thisinfo.Writers.length;i++) {
			if (i==0) {
			newinfo.push(' <tr><td><strong>Writer'+plural+':</strong></td><td><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thisinfo.Writers[i])+'">'+thisinfo.Writers[i]+'</a></td></tr>')
			} else {
			newinfo.push(' <tr><td></td><td><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thisinfo.Writers[i])+'">'+thisinfo.Writers[i]+'</a></td></tr>')
			}
		}
	}
	if (thisinfo.RunningTimeSeconds!=null) {
		if (thisinfo.RunningTimeSeconds>0) {
			newinfo.push(' <tr><td><strong>Run Time:</strong></td><td>'+Math.round(thisinfo.RunningTimeSeconds/60)+' Minutes</td></tr>')
		}
	}
	if (thisinfo.Copyright!=null) {
		newinfo.push(' <tr><td valign="top"><strong>Copyright:</strong></td><td valign="top">'+thisinfo.Copyright+'</td></tr>')
	}

	newinfo.push('</table></div>')

	dg("info_titleinfoDiv").innerHTML = newinfo.join("")

	doresize()
}

//===============================================================

function drawdownloads(thisinfo) {
	newdlinfo=[]
	newdlinfo.push('<div align="left" style="margin-left:15px;cursor:default;"><table cellpadding="0" cellspacing="0" border="0" width="300" style="color:#60676c">')

	if (selectlist_array.length==1) {

		thislocsarr = []
		thisPassID = thisinfo.PassID
		for (var i=0;i<libraryarray.length;i++) {
			if (libraryarray[i].Episodes==undefined) {
				if (libraryarray[i].PassID==thisPassID) {
					thislocsarr = libraryarray[i].DDIDS.split(",")
				}
			} else {
				for (var ix=0;ix<libraryarray[i].Episodes.length;ix++) {
					if (libraryarray[i].Episodes[ix].PassID==thisPassID) {
						thislocsarr = libraryarray[i].Episodes[ix].DDIDS.split(",")
					}
				}
			}
		}

		newdlinfo.push('<tr><td align="left" valign="top" width="112"><strong>Purchased:</strong></td><td valign="top">'+thisinfo.PurchasedDate+'</td></tr>')
		newdlinfo.push('<tr height="5"><td></td><td></td></tr>')

		var locsortarr=[]
		for (var i=0;i<thislocsarr.length;i++) {
			locsortarr.push(thislocsarr[i].split("|").reverse().join("|"))
		}
		locsortarr.sort()

		currentloc = 0
		var  locationarr=[]
		for (var i=0;i<locsortarr.length;i++) {
			if (currentloc!=locsortarr[i].split("|")[0]) {
				locationarr.push(locsortarr[i].split("|")[0]+","+locsortarr[i].split("|")[1])
				currentloc = locsortarr[i].split("|")[0]
			} else {
				locationarr[locationarr.length-1]=locationarr[locationarr.length-1]+"|"+locsortarr[i].split("|")[1]
			}
		}

		thisfiletype=""
		locs="<strong>Locations:</strong>"
		for (var i=0;i<locationarr.length;i++) {

			var thisloc = locationarr[i].split(",")[0]
			if (thisloc!=-1) {
			var thislocskus = locationarr[i].split(",")[1].split("|")
			thisfiletype = "("
			for (var iskus=0;iskus<thislocskus.length;iskus++) {
				thisfiletype += getfiletypenamefromPassIDSKU(thisPassID,thislocskus[iskus])
				if (iskus<thislocskus.length-1) {thisfiletype+=", "}
			}
			thisfiletype+=")"
			} else {thisfiletype=""}
			newdlinfo.push('<tr><td align="left" valign="top">'+locs+'</td><td valign="top"><strong>'+getDestinationNameByDDID(locsortarr[i].split("|")[0])+'</strong> '+thisfiletype+'</td></tr>')

		locs=""
		}

		licavailable = thisinfo.LicAvailable
		liccount = thisinfo.LicCount
	//	if (licavailable>3) {licavailable=3}
	//	if (licavailable==0) {licavailable=3}
	//	if (liccount>licavailable) {liccount=licavailable}
		licused = liccount+" of "+licavailable

		newdlinfo.push('<tr height="5"><td></td><td></td></tr>')
		newdlinfo.push('<tr><td align="left" valign="top"><strong>Licenses Used:</strong><div style="font-size:9px;color:#5988be;cursor:pointer;" onclick="openwhatsthis(0)">what\'s this?</div></td><td valign="top">'+licused+'</td></tr>')
		newdlinfo.push('<tr height="15"><td></td><td></td></tr>\n\n')
	}

	if (thisinfo.DLCount>=10) {
		newdlinfo.push('</table><div align="center" style="margin-top:15px;width:266px;border:1px solid red;padding:8px;font-size:12px;color:black;">You have reached the limit of available licenses for this file. If you want to download it again, please purchase another copy.</div>')
	} else {
		if (destinationarray.length==1&&thisguid!=""&&parseFloat(destinationarray[0].Ver.substr(0,3))<1.3) {
			newdlinfo.push('</table><div align="center" style="margin-top:15px;width:266px;border:1px solid red;padding:8px;font-size:12px;color:black;">An older version of media manager has been detected. Please upgrade your media manager installation or install the browser plug-in at the top of your screen if one is present.<br/><br/><a href="MediaManagerInstall.aspx?ReturnUrl=MediaManager_rq.aspx"><img src="img/mmgr/button_updatenow.gif" border="0"/></a></div>')
		} else {

			newdlinfo.push('<tr><td align="left" valign="top"><strong>Select File Type:</strong><div style="font-size:9px;color:#5988be;cursor:pointer;" onclick="openwhatsthis(1)">what\'s this?</div></td><td align="left" valign="top">')
			newdlinfo.push(' <div id="filetypeDiv" class="dropgadgetDiv" onmousedown="filetypedrop(this)" onmouseover="dg(\'filetypegadget\').className=\'dropgadgetover\'" onmouseout="dg(\'filetypegadget\').className=\'dropgadgetoff\'">')
			newdlinfo.push('  <table cellpadding="0" cellspacing="0" border="0" id="filetypeselector">')
			newdlinfo.push('  <tr>')
			newdlinfo.push('  <td><div id="filetypebox" class="dropbox"><span style="color:#7a7a7a;">Select Filetype..</span></div></td>')
			newdlinfo.push('  <td width="21"><img id="filetypegadget" src="img/spacer.gif" width="21" height="19" class="dropgadgetoff" border="0"/></td>')
			newdlinfo.push('  </tr>')
			newdlinfo.push('  </table>')
			newdlinfo.push(' </div>')

			newdlinfo.push('</td></tr>')
			newdlinfo.push('<tr height="15"><td></td><td></td></tr>')
			newdlinfo.push('<tr><td align="left" valign="top"><strong>Select Destination:</strong><div style="font-size:9px;color:#5988be;cursor:pointer;" onclick="openwhatsthis(2)">what\'s this?</div></td><td>')

			newdlinfo.push(' <div id="destinationDiv" class="dropgadgetDiv" onmousedown="destinationdrop(this)" onmouseover="dg(\'destinationgadget\').className=\'dropgadgetover\'" onmouseout="dg(\'destinationgadget\').className=\'dropgadgetoff\'">')
			newdlinfo.push('   <table cellpadding="0" cellspacing="0" border="0" id="destinationselector">')
			newdlinfo.push('   <tr>')
			newdlinfo.push('   <td><div id="destinationbox" class="dropbox"><span style="color:#7a7a7a;">Select a destination</span></div></td>')
			newdlinfo.push('   <td width="21"><img id="destinationgadget" class="dropgadgetoff" src="img/spacer.gif" width="21" height="19" border="0"/></td>')
			newdlinfo.push('   </tr>')
			newdlinfo.push('   </table>')
			newdlinfo.push(' </div>')

			newdlinfo.push('</td></tr>')
			newdlinfo.push('</table></div>')
			if (selectlist_array.length>1) {
				newdlinfo.push('<br/><div style="width:250px;"><strong>Please Note:</strong> Clicking Download will apply to all your selected videos.</div>')
			}

			newdlinfo.push('<br/><img id="downloadbuttonimg" src="img/mmgr/button_download.gif" onclick="if (this.src.indexOf(\'ghost\')==-1) {assigndownloads()}" style="cursor:pointer;" border="0"/>')

		}
	}

	dg("info_downloadsDiv").innerHTML = newdlinfo.join("")


	drawfiletypes()
	drawdestinations()
	doresize()
}

function getfiletypenamefromPassIDSKU(thispass,thissku) {
	foundobj=""
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			if (libraryarray[i].PassID==thispass) {
				foundobj = libraryarray[i]
				break
			}
		} else {
			for (var ei=0;ei<libraryarray[i].Episodes.length;ei++) {
				if (libraryarray[i].Episodes[ei].PassID==thispass) {
					foundobj = libraryarray[i].Episodes[ei]
					break
				}
			}
		}
	}
	if (foundobj=="") {return ""}
	foundDDIDSarr = foundobj.DDIDS.split(",")
	foundsku = ""
	for (var i=0;i<foundDDIDSarr.length;i++) {
		if (foundDDIDSarr[i].split("|")[1]==thissku) {
			foundsku = foundDDIDSarr[i].split("|")[1]
		}
	}
	if (foundsku=="") {return ""}
	foundTYPES = foundobj.FileType.split(",")
	foundtype = ""
	for (var i=0;i<foundTYPES.length;i++) {
		if (foundsku==foundTYPES[i].split(":")[1]) {
			foundtype = foundTYPES[i].split(":")[0]
		}
	}

	return foundtype
}

//===============================================================

function drawsimilar_callback(simxml) {
	var simdom 	= simxml.documentElement;
	getsim	= simdom.getElementsByTagName("rp")
	var simlist 	= []
	simlist.completed = false

	try{
		thisSKUID = simdom.getElementsByTagName("SKUID")[0].firstChild.nodeValue

		for (var i=0;i<getsim.length;i++) {
			simlist.push(new Object())
			var simtl = simlist[simlist.length-1]
			for (ic=0;ic<getsim[i].childNodes.length;ic++) {
				try{var simtext = getsim[i].childNodes.item(ic).childNodes.item(0).nodeValue}catch(e){var simtext=null}
				eval("simtl."+getsim[i].childNodes.item(ic).tagName+"=simtext")
			}
		}

		simlist.completed = true
		similars[thisSKUID] = simlist
		drawsimilar(thisSKUID)
	}catch(e){
		dg("info_similar_tab").src="img/mmgr/tab_info_similar_ghost.gif"
		dg("info_similar_tab").style.cursor="default"
		dg("info_similarDiv").innerHTML = ""
	}
}

function drawsimilar(thisdqid) {
	thissimilar = similars[thisdqid]
	newsimilar=[]
	newsimilar.push('<div align="center" style="padding-left:40px;text-align:center;">')
	for (var i=0;i<thissimilar.length;i++) {
		newsimilar.push('<div align="center" style="width:104px;margin:8px;float:left;"><a href="/Buy/Movies/1007,0,5,,1,2,'+thissimilar[i].TitleID+'/'+thissimilar[i].TitleName.replace(/[^a-zA-Z0-9]/g,"-")+'.htm"><img src="'+protocol+'://www.cinemanow.com/images/boxart/95/'+thissimilar[i].ABBR+'95.jpg" border="0"/></a><div style="padding:4px;">'+thissimilar[i].TitleName+'</div></div>')
		if (i&1){newsimilar.push('<br style="clear:both;"/>')}
	}
	newsimilar.push('<br style="clear:both;"/></div>')
	dg("info_similarDiv").innerHTML = newsimilar.join("")
	if (thissimilar.length>0) {
		dg("info_similar_tab").src="img/mmgr/tab_info_similar_off.gif"
		dg("info_similar_tab").style.cursor="pointer"
	} else {
		dg("info_similar_tab").src="img/mmgr/tab_info_similar_ghost.gif"
		dg("info_similar_tab").style.cursor="default"
	}
}

//===============================================================

currentheadselect = "listhead1"
function listheadover(thishead) {
	if (thishead.id==currentheadselect) {return}
	dg(thishead.id).className = "listheadover"
}

function listheadout(thishead) {
	if (thishead.id==currentheadselect) {return}
	dg(thishead.id).className = "listhead"
}

function listheadclick(thishead) {
	if (thishead.id==currentheadselect) {return}
	dg(currentheadselect).className = "listhead"
	dg(thishead.id).className = "listheadselect"
	currentheadselect = thishead.id

	if (searcharray.length>0) {
		drawlibrary(searcharray)
	} else {
		drawlibrary(libraryarray)
	}
	doresize()
}

function openwhatsthis(texttype) {

	dg("whatsthistext").innerHTML = whatsthis[texttype]

	dg("whatsthisDiv").style.display="block"
	try{dg("whatsthisbgimg").style.display="block"}catch(e){}

	dg("whatsthisDiv").style.left = Math.round(dbcw/2-(360/2))+"px"
	try{dg("whatsthisbgimg").style.left = Math.round(dbcw/2-(471/2))+"px"}catch(e){}

	if (browser=="safari") {
		dg("whatsthisDiv").style.top = Math.round((dbch/2)-(265/2)+document.body.scrollTop)+"px"
		try{dg("whatsthisbgimg").style.top = Math.round((dbch/2)-(374/2)+document.body.scrollTop)+"px"}catch(e){}
	} else {
		dg("whatsthisDiv").style.top = Math.round((dbch/2)-(265/2)+document.documentElement.scrollTop)+"px"
		try{dg("whatsthisbgimg").style.top = Math.round((dbch/2)-(374/2)+document.documentElement.scrollTop)+"px"}catch(e){}
	}
}


lastboxart=""
function loadnewboxes(boxart) {
	dg("infoboximgDiv").innerHTML = '<img id="infoboximg" src="'+protocol+'://www.cinemanow.com/images/boxart/175/'+boxart+'175.jpg" width="175" onload="loadboxes(this,0)" border="0"/>'
	dg("infoboxmirrorfade").style.backgroundImage='url('+protocol+'://www.cinemanow.com/images/boxart/175v/'+boxart+'175.jpg)'
}

function loadcnbox() {
	dg("infoboximgDiv").innerHTML = '<img id="infoboximg" src="img/mmgr/cnbox.jpg" onload="loadboxes(this,0)" onerror="loadboxes(this,1)" border="0"/>'
	dg("infoboxmirrorfade").style.backgroundImage="url(img/mmgr/cnbox_v.jpg)"
}

function errorloadboxes(boxart) {
}

function loadboxes(thisimg,test) {
	if (thisimg.id=="infoboximg"&&browser=="ie") {//IE6 and IE7 screw up JPGs when opacity is applied to them - these browsers turn #00000 to #ffffff in the JPGs. weird!
		if(thisimg.src.indexOf("spacer.gif")==-1){
			thisimg.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+thisimg.src+"', sizingMethod='image')";
			thisimg.src="img/spacer.gif"
		}
	}

	fx("infoboximgDiv",4,false,null,"opacity,0,100")
	fx("infoboxmirrorfade",4,false,null,"opacity,0,100")
}

lastselectlist=[]
function isselectlistthesame() {
	sameselect=[]
	for (var i=0;i<selectlist_array.length;i++) {
		sameselect.push(selectlist_array[i].id)
	}
	if (sameselect==lastselectlist) {return true} else {lastselectlist=sameselect;return false}
}

function dothrow(){throw "test"}
function dotest() {}

function ajaxerror(errobj) {}


//===========================================================================
tabledivider='<td class="listrx" width="1"><div></div></td>'
thiscount = 0
topcount = 0
function drawlibrary(thisarray) {
	if (currenttab=="queue") {return}
	dg("statusDiv").innerHTML = ""

	thiscount = 0
	topcount = 0

	boxview = (currentview=="box")?"inline":"none"

	drawarray=[]

	titlelocs=[]

	for (var i=0;i<thisarray.length;i++) {
		if (thisarray[i].Episodes==undefined) {
			if (titlelocs[thisarray[i].PassID]==undefined) {titlelocs[thisarray[i].PassID] = []}
			lDDIDS = thisarray[i].DDIDS.split(",")
			for (var ild=0;ild<lDDIDS.length;ild++) {
				if (titlelocs[thisarray[i].PassID].join(",").indexOf(lDDIDS[ild].split("|")[2])==-1) {
					titlelocs[thisarray[i].PassID].push(lDDIDS[ild].split("|")[2])
				}
			}
		} else {
			for (iz=0;iz<thisarray[i].Episodes.length;iz++) {
				if (titlelocs[thisarray[i].Episodes[iz].PassID]==undefined) {titlelocs[thisarray[i].Episodes[iz].PassID] = []}
				lDDIDS = thisarray[i].Episodes[iz].DDIDS.split(",")
				for (var ild=0;ild<lDDIDS.length;ild++) {
					if (titlelocs[thisarray[i].Episodes[iz].PassID].join(",").indexOf(lDDIDS[ild].split("|")[2])==-1) {
						titlelocs[thisarray[i].Episodes[iz].PassID].push(lDDIDS[ild].split("|")[2])
					}
				}
			}
		}
	}

	sortarray=[]
	for (i=0;i<thisarray.length;i++) {

		if (currentheadselect=="listhead1") {sortrow=""}
		if (thisarray[i].Episodes==undefined) {

			if (currentheadselect=="listhead2") {sortrow=thisarray[i].Rating}
			if (currentheadselect=="listhead3") {sortrow=thisarray[i].Type}
			if (currentheadselect=="listhead4") {sortrow=thisarray[i].DDIDS.split(",")[0].split("|")[0]}
			if (currentheadselect=="listhead5") {sortrow=thisarray[i].PurchasedDate.split(" ")[0].split("/")[2]+"_"+thisarray[i].PurchasedDate.split(" ")[0].split("/")[0]+"_"+thisarray[i].PurchasedDate.split(" ")[0].split("/")[1]}
		} else {

			if (currentheadselect=="listhead2") {sortrow=thisarray[i].Episodes[0].Rating}
			if (currentheadselect=="listhead3") {sortrow=thisarray[i].Episodes[0].Type}
			if (currentheadselect=="listhead4") {sortrow=thisarray[i].Episodes[0].DDIDS.split(",")[0].split("|")[0]}
			if (currentheadselect=="listhead5") {sortrow=thisarray[i].Episodes[0].PurchasedDate.split(" ")[0].split("/")[2]+"_"+thisarray[i].Episodes[0].PurchasedDate.split(" ")[0].split("/")[0]+"_"+thisarray[i].Episodes[0].PurchasedDate.split(" ")[0].split("/")[1]}
		}

		sortarray.push(sortrow+" "+thisarray[i].Name+" __~~"+i)
	}

	if (currentheadselect=="listhead2"||currentheadselect=="listhead5") {
		sortarray.sort(reverseSort);
	} else {
		sortarray.sort();
	}


	tlist = []
	tlist.push('<table cellpadding="0" cellspacing="0" border="0" class="listtable"><thead id="scrollhead">')

	newselectlist = []

	rowcolor = 1
	for (var iz=0;iz<thisarray.length;iz++) {

		i = parseInt(sortarray[iz].split("__~~")[1],10)


		if (thisarray[i].Episodes!=undefined) {
			episodenumbers = thisarray[i].EpisodeNumbers.split(",")
			foldersize = episodenumbers.length

			for (var ien=0;ien<episodenumbers.length;ien++) {
				episodenumbers[ien] = "0000000000"+String(episodenumbers[ien])
				episodenumbers[ien] = episodenumbers[ien].substring(episodenumbers[ien].length-4)
			}
			episodenumbers.sort()
			for (var ien=0;ien<episodenumbers.length;ien++) {
				episodenumbers[ien] = parseInt(episodenumbers[ien],10)
			}
			episodenums = []
			for (var ien=0;ien<episodenumbers.length;ien++) {
				if (String(","+episodenums.join(",")+",").indexOf(","+episodenumbers[ien]+",")==-1) {
					episodenums.push(episodenumbers[ien])
				}
			}
			episodenumbers = episodenums
			hasfolder=","+foldersize
			if (foldersize==1) {
				episodelist = " - Episode "+episodenumbers[0]
			} else {
			episodelist= " - Episodes "
			for (ix=0;ix<episodenumbers.length;ix++) {
				if (ix<episodenumbers.length-1) {
					episodelist += episodenumbers[ix]
					if (episodenumbers.length>2) {episodelist+=", "}
				} else {
					episodelist += " and "+episodenumbers[ix]
				}
			}
			}
		} else {
			foldersize=0
			hasfolder=""
			episodelist=""
		}

		if (thisarray[i].Episodes==undefined) {thiscount++}

		if (thisarray[i].Episodes==undefined) {
			thislang = thisarray[i].TitleID+"_"+thisarray[i].DDIDS+"_"+thisarray[i].PassID+"_"+i

			rowcolor++
			bgcolor = (rowcolor&1)?"ffffff":"f0f4f7"

			thisdestlist=[]
			for (var itl=0;itl<titlelocs[thisarray[i].PassID].length;itl++) {
				thisdestlist.push(getDestinationNameByDDID(titlelocs[thisarray[i].PassID][itl]))
			}
			if (isthisselected(thislang)) {newselectlist.push("listrow_0"+iz);rowclass="selectlist"}else{rowclass="selectlistoff"}

			tlist.push('<tr id="listrow_0'+iz+'" iteminfo="'+thislang+'" onclick="selectlist(this,'+thisarray[i].TitleID+',\''+thisarray[i].BoxArt+'\''+hasfolder+')" class="'+rowclass+'" style="cursor:pointer;background-color:#'+bgcolor+';" onmouseover="rowover(this,\''+bgcolor+'\')" onmouseout="rowout(this,\''+bgcolor+'\')">')
			tlist.push('<td class="listr1" valign="top"><table width="248" cellpadding="0" cellspacing="0" border="0" class="listtablebox"><tr><td valign="top"><img id="listimg'+topcount+'" src="'+protocol+'://www.cinemanow.com/images/boxart/65/'+thisarray[i].BoxArt+'65.jpg" style="display:'+boxview+';" border="0"/></td><td width="5"></td><td valign="top" width="244">'+thisarray[i].Name+episodelist+'</td></tr></table></td>')
			tlist.push('<td class="listrx" width="1"><div></div></td>')
			if (thisarray[i].Rating>0) {
				thisrating='<img src="img/mmgr/stars_'+thisarray[i].Rating+'.gif" border="0"/>'
			} else {
				thisrating='<span id="listrow_0'+iz+'_starspan"><img id="listrow_0'+iz+'_star" src="img/mmgr/stars_'+thisarray[i].Rating+'.gif" onclick="starclick(event)" onmousemove="starmove(event)" onmouseout="starout(event)" border="0"/></span>'
			}
			tlist.push('<td class="listr2" valign="top" width="56">'+thisrating+'</td>')
			tlist.push(tabledivider)
			tlist.push('<td class="listr3" valign="top" width="63">'+thisarray[i].Type+'</td>')
			tlist.push(tabledivider)
			tlist.push('<td class="listr4" valign="top" width="93">'+thisdestlist.join('<br/>')+'</td>')
			tlist.push(tabledivider)
			tlist.push('<td class="listr5" valign="top" align="left" style="padding-left:4px;" width="52">'+thisarray[i].PurchasedDate.split(" ")[0].replace(/\/200/g,"/0").replace(/\/201/g,"/1")+'</td>')
			tlist.push('</tr>')
			topcount++
		} else {
			rowcolor++
			bgcolor = (rowcolor&1)?"ffffff":"f0f4f7"

			thislang = thisarray[i].TitleID
			if (hasrowsselected(thislang)) {rowclass="selectlist"}else{rowclass=""}

			tlist.push('<tr id="listrow_0'+iz+'" iteminfo="'+thislang+'" class="'+rowclass+'" width="552" onclick="selectlist(this,'+thisarray[i].TitleID+',\''+thisarray[i].BoxArt+'\''+hasfolder+')" style="cursor:pointer;background-color:#'+bgcolor+';" onmouseover="rowover(this,\''+bgcolor+'\')" onmouseout="rowout(this,\''+bgcolor+'\')">')
			tlist.push('<td class="listr1" width="552" valign="top" colspan="9"><table cellpadding="0" cellspacing="0" border="0" width="520" class="listtablebox"><tr><td valign="top"><img id="listimg'+topcount+'" src="'+protocol+'://www.cinemanow.com/images/boxart/65/'+thisarray[i].BoxArt+'65.jpg" onerror="if(this.src.indexOf(\'/210\')==-1) {this.src=this.src.replace(/\\/65/g,\'/210\').replace(/\\_65\./g,\'_210.\');this.width=100}else{this.src=\'img/spacer.gif\'}" style="display:'+boxview+';" border="0"/></td><td width="5"></td><td valign="top">'+thisarray[i].Name+episodelist+'</td></tr></table></td></tr>')
			topcount++
		}

		if (thisarray[i].Episodes!=undefined) {
			thislang = thisarray[i].TitleID+"|"+foldersize
			if (isthisselectedfoldergadgetopen(thislang)) {folderopen="foldergadgetopened"}else{folderopen="foldergadget"}
			if (hasrowsselected(thislang)) {rowclass="selectlistfolderrow"}else{rowclass="listfolderrow"}
			tlist.push('<tr id="listrow_0'+iz+'_folder" width="552" iteminfo="'+thislang+'" class="'+rowclass+'" style="background-color:#'+bgcolor+';" onmouseover="rowover(this,\''+bgcolor+'\')" onmouseout="rowout(this,\''+bgcolor+'\')">')
			tlist.push('<td colspan="9" width="552" style="padding-left:15px;font-size:11px;cursor:pointer;" onclick="togglefolder(this,\'listrow_0'+iz+'\','+foldersize+')" ><img class="'+folderopen+'" name="foldergadget" id="listrow_0'+iz+'_foldergadget" iteminfo="'+thislang+'" src="img/spacer.gif" width="12" height="12" style="cursor:pointer;" border="0" unselectable="on"/> select individual episodes from this season</td>')
			tlist.push('</tr>')
			for (ix=0;ix<thisarray[i].Episodes.length;ix++) {
				thiscount++
				thislang = thisarray[i].Episodes[ix].TitleID+"_"+thisarray[i].Episodes[ix].DDIDS+"_"+thisarray[i].Episodes[ix].PassID+"_"+ix
				thisdestlist=[]
				for (var itl=0;itl<titlelocs[thisarray[i].Episodes[ix].PassID].length;itl++) {
					thisdestlist.push(getDestinationNameByDDID(titlelocs[thisarray[i].Episodes[ix].PassID][itl]))
				}

				if (isthisselected(thislang)) {newselectlist.push("listrow_0"+iz+"_sub_"+ix);rowclass="selectlist"}else{rowclass="selectlistoff"}
				showsub = isthisselectedfolderopen(thislang)
				tlist.push('<tr id="listrow_0'+iz+'_sub_'+ix+'" iteminfo="'+thislang+'" class="'+rowclass+'" onclick="selectlist(this,'+thisarray[i].Episodes[ix].TitleID+',\''+thisarray[i].Episodes[ix].BoxArt+'\')" style="display:'+showsub+';cursor:pointer;background-color:#'+bgcolor+';" onmouseover="rowover(this,\''+bgcolor+'\')" onmouseout="rowout(this,\''+bgcolor+'\')">')
				tlist.push('<td class="listr1" valign="top" style="padding-left:30px;">'+thisarray[i].Episodes[ix].Name+'</td>')
				tlist.push('<td class="listrx" width="1"><div></div></td>')
				if (thisarray[i].Episodes[ix].Rating>0) {
					thisrating='<img src="img/mmgr/stars_'+thisarray[i].Episodes[ix].Rating+'.gif" border="0"/>'
				} else {
					thisrating='<span id="listrow_0'+iz+'_sub_'+ix+'_starspan"><img id="listrow_0'+iz+'_sub_'+ix+'_star" src="img/mmgr/stars_'+thisarray[i].Episodes[ix].Rating+'.gif" onclick="starclick(event)" onmousemove="starmove(event)" onmouseout="starout(event)" border="0"/></span>'
				}
				tlist.push('<td class="listr2" valign="top" width="56">'+thisrating+'</td>')
				tlist.push(tabledivider)
				tlist.push('<td class="listr3" valign="top" width="63">'+thisarray[i].Episodes[ix].Type+'</td>')
				tlist.push(tabledivider)
				tlist.push('<td class="listr4" valign="top" width="93">'+thisdestlist.join('<br/>')+'</td>')
				tlist.push(tabledivider)
				tlist.push('<td class="listr5" valign="top" align="left" style="padding-left:4px;" width="52">'+thisarray[i].Episodes[ix].PurchasedDate.split(" ")[0].replace(/\/200/g,"/0").replace(/\/201/g,"/1")+'</td>')
				tlist.push('</tr>')
			}
		}
	}

	tlist.push('</thead></table>')
	dg("scroller").innerHTML = tlist.join("")

	unselectable(dg("scroller"))
	removenullnodes(dg("scrollhead"))

	if (dg("scroller").clientHeight<dg("scrollDiv").clientHeight) {
		dg("scrollbuttons").style.display="none"
	} else {
		dg("scrollbuttons").style.display="block"
	}

	dg("scroller").style.top="0px"
	dg("countDiv").innerHTML = "Titles in library: "+thiscount

	selectlist_array=[]
	for (var i=0;i<newselectlist.length-1;i++) {
		selectlist_array.push(dg(newselectlist[i]))
	}

	if (newselectlist.length>0) {
		ctrlstate=true
		dg(newselectlist[newselectlist.length-1]).onclick()
		ctrlstate=false
	}

	doresize()
}

function isthisselected(thislang) {
	for (var i=0;i<selectlist_array.length;i++) {
		if (selectlist_array[i].getAttribute("iteminfo")==thislang) {return true}
	}
	return false
}

function isthisselectedfolderopen(thislang) {
	getlistdom = dg("scroller").getElementsByTagName("TR")
	for (var i=0;i<getlistdom.length;i++) {
		thislisttr = getlistdom[i]
		if (thislisttr.id==""||thislisttr.id==undefined) {continue}
		if (String(thislisttr.getAttribute("iteminfo"))=="null") {continue}
		if (
			thislisttr.getAttribute("iteminfo").split("_")[0]==thislang.split("_")[0] &&
			thislisttr.getAttribute("iteminfo").split("_")[2]==thislang.split("_")[2]
		) {
			return thislisttr.style.display
		}
	}
	return "none"
}

function isthisselectedfolderopen_queue(thislang) {
	getlistdom = dg("statusDiv").getElementsByTagName("TR")
	for (var i=0;i<getlistdom.length;i++) {
		if (getlistdom[i].id==""||getlistdom[i].id==undefined) {continue}
		if (String(getlistdom[i].getAttribute("iteminfo"))=="null") {continue}
		if (
			getlistdom[i].getAttribute("iteminfo").split("_")[0]==thislang.split("_")[0] &&
			getlistdom[i].getAttribute("iteminfo").split("_")[2]==thislang.split("_")[2]
		) {
			return getlistdom[i].style.display
		}
	}
	return ""
}

function hasrowsselected(thislang) {
	for (var i=0;i<selectlist_array.length;i++) {
		try{if (dg("listrow_"+selectlist_array[i].id.split("_")[1]).getAttribute("iteminfo").split("|")[0]==thislang.split("|")[0]) {return true}}catch(e){}
		try{if (dg("listrow_"+selectlist_array[i].id.split("_")[1]+"_folder").getAttribute("iteminfo").split("|")[0]==thislang.split("|")[0]) {return true}}catch(e){}
	}
	return false
}

function isthisselectedfoldergadgetopen(thislang) {
	getlistdom = document.getElementsByName("foldergadget")
	for (var i=0;i<getlistdom.length;i++) {
		if (getlistdom[i].getAttribute("iteminfo")==thislang) {
			if (getlistdom[i].className=="foldergadgetopened") {return true}
		}
	}
	return false
}

function isthisselectedfoldergadgetopen_queue(thislang) {
	getlistdom = document.getElementsByName("foldergadget")
	for (var i=0;i<getlistdom.length;i++) {
		if (getlistdom[i].getAttribute("iteminfo")==thislang) {
			if (getlistdom[i].className=="foldergadgetopened") {return true}
		}
	}
	return false
}

function starmove(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	try{event.cancelBubble = true;evt.returnValue = false}catch(e){evt.preventDefault()}
	parentrow = String(evtsrc.id).substr(0,evtsrc.id.indexOf("_star"))
	if (parentrow=="") {return false}
	if (dg(parentrow).className!="selectlist"){return false}
	newdragx = (evt.clientX||evt.x)
	thisrate = Math.round((newdragx-getleft(evtsrc))/10)
	if (thisrate==0) {thisrate=1}
	evtsrc.src = 'img/mmgr/stars_'+thisrate+'_vote.gif'
}

ratestar = ""
function starclick(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	try{event.cancelBubble = true;evt.returnValue = false}catch(e){evt.preventDefault()}
	parentrow = evtsrc.id.substr(0,evtsrc.id.indexOf("_star"))
	if (dg(parentrow).className!="selectlist"){dg(parentrow).onclick();return false}
	thisrating = evtsrc.src.split("_")[1]
	//libraryarray[dg(parentrow).getAttribute("iteminfo").split("_")[3]].Rating = thisrating
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			if (libraryarray[i].PassID==dg(parentrow).getAttribute("iteminfo").split("_")[2]) {
				libraryarray[i].Rating = thisrating
			}
		} else {
			for (var ei=0;ei<libraryarray[i].Episodes.length;ei++) {
				if (libraryarray[i].Episodes[ei].PassID==dg(parentrow).getAttribute("iteminfo").split("_")[2]) {
					libraryarray[i].Episodes[ei] = thisrating
				}
			}
		}
	}
	thisid = String(dg(parentrow).getAttribute("iteminfo")).split("_")[0]
	ratestar = evtsrc
	dg(evtsrc.id+"span").innerHTML = '<img src="img/mmgr/stars_'+thisrating+'.gif" border="0"/>'
	ajl(protocol+"://"+server+"/Handler/RateIt.ashx?rating="+evtsrc.src.split("_")[1]+"&titleid="+thisid+"&_=&now="+Date.parse(new Date()),rating_callback,"",ajaxerror,true)
}

function rating_callback(thisxml,thistxt,thishead) {
	ratestar.src = 'img/mmgr/stars_'+thistxt.split(",")[0]+'.gif'
}

function starout(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	try{event.cancelBubble = true;evt.returnValue = false}catch(e){evt.preventDefault()}
	evtsrc.src = 'img/mmgr/stars_0.gif'
}

function reverseSort(a, b) {
   if(a > b){return -1}
   if(a < b){return 1}
   return 0;
}

function getDestinationNameByDDID(thisDDID) {
	if (thisDDID==-1) {return "Unassigned"}
	returndest = ""
	for (var i=0;i<destinationarray.length;i++) {
		if (destinationarray[i].DDID==thisDDID) {
			returndest = destinationarray[i].Loc
		}
	}
	if (returndest==""){returndest="Unknown"}
	return returndest
}
function getDestinationByDDID(thisDDID) {
	if (thisDDID==-1) {return ""}
	returndest = ""
	for (var i=0;i<destinationarray.length;i++) {
		if (destinationarray[i].DDID==thisDDID) {
			returndest = destinationarray[i]
		}
	}
	if (returndest==""){returndest=""}
	return returndest
}

function isselected(thislang) {
	langselect = false
	for (var i=0;i<selectlist_array.length;i++) {
		if (thislang==selectlist_array[i].getAttribute("iteminfo")) {langselect=true;break}
	}
	return langselect
}

function togglefolder(thisgadget,thisrow,foldersize) {
	if (thisgadget.childNodes[0].className=="foldergadget") {
		thisgadget.childNodes[0].className="foldergadgetopened"
		for (var i=0;i<foldersize;i++) {
			if (browser=="ie") {
				try{dg(thisrow+"_sub_"+i).style.display="block"}catch(e){}
			} else {
				try{dg(thisrow+"_sub_"+i).style.display="table-row"}catch(e){}
			}
		}
	} else {
		thisgadget.childNodes[0].className="foldergadget"
		for (var i=0;i<foldersize;i++) {
			try{dg(thisrow+"_sub_"+i).style.display="none"}catch(e){}
		}
	}
	doresize()
}

function rowover(thisrow,thiscolor) {
	var rowid = thisrow.id.split("_")
	thisrow.style.backgroundColor="#eaeaea"
	try{dg(thisrow.id+"_folder").style.backgroundColor="#eaeaea"}catch(e){}
	try{dg(thisrow.id.split("_folder")[0]).style.backgroundColor="#eaeaea"}catch(e){}
}

function rowout(thisrow,thiscolor) {
	var rowid = thisrow.id
	thisrow.style.backgroundColor="#"+thiscolor
	try{dg(rowid+"_folder").style.backgroundColor="#"+thiscolor}catch(e){}
	try{dg(rowid.split("_folder")[0]).style.backgroundColor="#"+thiscolor}catch(e){}
}

//===========================================================================
statusimgarray=[]
statusimgarray.push("img/spacer.gif")//null
statusimgarray.push("img/mmgr/status_waiting.png")//initialized
statusimgarray.push("img/mmgr/status_downloading.gif")
statusimgarray.push("img/mmgr/status_downloading.gif")
statusimgarray.push("img/mmgr/status_downloading.gif")
statusimgarray.push("img/mmgr/status_ok.png")
statusimgarray.push("img/mmgr/status_attention.png")
statusimgarray.push("img/mmgr/status_attention.png")
statusimgarray.push("img/mmgr/status_initialized.png")
statusimgarray.push("img/spacer.gif")
statusimgarray.push("img/spacer.gif")
statusimgarray.push("img/spacer.gif")
statusimgarray.push("img/mmgr/status_downloading.gif")
statusimgarray.push("img/spacer.gif")
statusimgarray.push("img/spacer.gif")
statusimgarray.push("img/spacer.gif")

dqidarray=[]
function drawqueue(thisarray) {
	if (currenttab=="library") {return}

	if (dg("statusDiv").innerHTML=="") {firstdraw=true}else{firstdraw=false}

	toparray=[]
	midarray=[]
	botarray=[]

	//movies - create copies of libarray objects in the appropriate sorting arrays for the status types found within
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			thisDDIDSarr = libraryarray[i].DDIDS.split(",")
			hasStatusOne = false
			hasStatusOther = false
			hasStatusDL = false
			for (var ids=0;ids<thisDDIDSarr.length;ids++) {
				qlibstat = libraryarray[i].Status[thisDDIDSarr[ids].split("|")[0]]
				if (qlibstat==1) {hasStatusOne=true}
				if (qlibstat==5||qlibstat==6||qlibstat==7||qlibstat==8) {hasStatusOther=true}
				if (qlibstat==2||qlibstat==3||qlibstat==4||qlibstat==12) {hasStatusDL=true}
			}
			if (hasStatusOne==true) {
				toparray.push(libraryarray[i])
			}
			if (hasStatusOther==true) {
				midarray.push(libraryarray[i])
			}
			if (hasStatusDL==true) {
				botarray.push(libraryarray[i])
			}
		}
	}

	//bundles - create copies of libarray objects in the appropriate sorting arrays for the status types found within
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes!=undefined) {
			hasStatusOne = false
			hasStatusOther = false
			hasStatusDL = false
			for (var ei=0;ei<libraryarray[i].Episodes.length;ei++) {
				thisDDIDSarr = libraryarray[i].Episodes[ei].DDIDS.split(",")
				for (var ids=0;ids<thisDDIDSarr.length;ids++) {
					qlibstat = libraryarray[i].Episodes[ei].Status[thisDDIDSarr[ids].split("|")[0]]
					if (qlibstat==1) {hasStatusOne=true}
					if (qlibstat==5||qlibstat==6||qlibstat==7||qlibstat==8) {hasStatusOther=true}
					if (qlibstat==2||qlibstat==3||qlibstat==4||qlibstat==12) {hasStatusDL=true}
				}
			}
			if (hasStatusOne==true) {
				notinmidarray = true
				for (var ita=0;ita<midarray.length;ita++) {
					if (midarray[ita].TitleID==libraryarray[i].TitleID) {notinmidarray=false}
				}
				if (notinmidarray==true) {
					toparray.push(libraryarray[i])
				}
			}
			if (hasStatusOther==true) {
				notintoparray = true
				for (var ita=0;ita<toparray.length;ita++) {
					if (toparray[ita].TitleID==libraryarray[i].TitleID) {notintoparray=false}
				}
				if (notintoparray==true) {
					midarray.push(libraryarray[i])
				}
			}
			if (hasStatusDL==true) {
				botarray.push(libraryarray[i])
			}
		}
	}

	if (toparray.length==0&&midarray.length==0) {dg("dlqueue_attention").style.display="none";dg("statusDiv").style.display="none"}else{dg("dlqueue_attention").style.display="inline";dg("statusDiv").style.display="block"}
	if (botarray.length==0) {dg("dlqueue_downloads").style.display="none"}else{dg("dlqueue_downloads").style.display="inline"}

	statcount = 0
	newselectlist = []

	for (ify=0;ify<3;ify++) {
		if (ify==0) {
			rowgrp=0
			drawarray = toparray
			tlist=[]
			tlist.push('<table cellpadding="0" cellspacing="0" border="0" class="queuetable" unselectable="on"><thead id="topqueue" unselectable="on">')
		}
		if (ify==1) {
			rowgrp=1
			drawarray = midarray
		}
		if (ify==2) {
			rowgrp=2
			drawarray = botarray
			tlist=[]
			tlist.push('<table cellpadding="0" cellspacing="0" border="0" class="queuetable" unselectable="on"><thead id="botqueue" unselectable="on">')
		}

		cidx = 0
		for (var i=0;i<drawarray.length;i++) {
			statcount++
			if (drawarray[i].Episodes==undefined) {
				qDDIDSarr = drawarray[i].DDIDS.split(",")
				subcount=0
				for (var isa=0;isa<qDDIDSarr.length;isa++) {
					idq = qDDIDSarr[isa].split("|")[0]
					thisstatus = drawarray[i].Status[idq]

					if (thisstatus=="") {continue}
					if (thisstatus==undefined) {thisstatus=1}
					if (ify==0) {
						if (thisstatus!=1) {continue}
					}
					if (ify==1) {
						if (thisstatus!=5&&thisstatus!=6&&thisstatus!=7&&thisstatus!=8) {continue}
					}
					if (ify==2) {
						if (thisstatus!=2&&thisstatus!=3&&thisstatus!=4&&thisstatus!=12) {continue}
					}

					thisdate = drawarray[i].PurchasedDate.split(" ")[0]
					thislang = drawarray[i].TitleID+"_"+idq+"_"+drawarray[i].PassID
					thisdest = getDestinationNameByDDID(qDDIDSarr[isa].split("|")[2])
					thisstatusmessage = dlstatusarray[thisstatus-1].Lookup_Desc
					if (thisstatus==2) {thisstatusmessage+=" "+thisdest}
					if (thisstatus==12) {thisstatusmessage+=" "+thisdest}
					if (thisstatus==3) {thisstatusmessage+=" "+thisdest}
					if (thisstatus==4) {thisstatusmessage+=" "+thisdest+" ("+drawarray[i].Message[idq]+"% Downloaded)";}
					if (thisstatus==5) {thisstatusmessage=thisstatusmessage.replace(/\sat/g," at "+thisdest)}
					if (thisstatus==6) {thisstatusmessage=thisstatusmessage.replace(/\sat/g," at "+thisdest)}
					if (thisstatus==7) {thisstatusmessage+=" at "+thisdest}
					if (thisstatus==8) {thisstatusmessage=thisstatusmessage.replace(/\[\]/g,thisdest)}
					bgcolor = (cidx&1)?"ffffff":"f0f4f7";cidx++
					if (ify==0||ify==1) {
						cclick='onclick="selectlist(this,'+drawarray[i].TitleID+',\''+drawarray[i].BoxArt+'\')"'
						cmouse='onmouseover="rowover(this,\''+bgcolor+'\')" onmouseout="rowout(this,\''+bgcolor+'\')"'
						cpoint='cursor:pointer;'
					} else {
						cclick=''
						cmouse=''
						cpoint='cursor:default;'
					}
					if (debug==true) {
					imgalt='alt="Status:'+thisstatus+'  PassID:'+drawarray[i].PassID+'  DQID:'+idq+'"'
					} else {imgalt=""}
					if (rowgrp==0||rowgrp==1) {
						if (firstdraw==false) {
							if (isthisselected(thislang)) {
								newselectlist.push("listrow_"+String(rowgrp)+String(i)+subcount)
								rowclass="selectlist"
							}else{
								rowclass="selectlistoff"
							}
						} else {
							rowclass="selectlistoff"
						}
					} else {
						rowclass="selectlistoff"
					}
					thisfiletype=" ("+getfiletypenamefromPassIDSKU(drawarray[i].PassID,qDDIDSarr[isa].split("|")[1])+")"
					tlist.push('<tr id="listrow_'+String(rowgrp)+String(i)+subcount+'" iteminfo="'+thislang+'" '+cclick+' class="'+rowclass+'" style="'+cpoint+'background-color:#'+bgcolor+';" '+cmouse+' unselectable="on">')
					tlist.push('<td class="listr1" valign="top" width="552"><table cellpadding="0" cellspacing="0" border="0""><tr><td><img '+imgalt+' src="'+statusimgarray[thisstatus]+'" onload="if (this.src.indexOf(\'.png\')!=-1){fixpng()}" border="0" unselectable="on"/></td><td width="5"></td><td width="500" unselectable="on"><div style="font-size:11px;" unselectable="on">'+thisdate+'</div>&nbsp;<strong unselectable="on">'+drawarray[i].Name+'</strong>'+thisfiletype+': '+thisstatusmessage+'</td></tr></table></td></tr>')
					subcount++
				}
			}

			if (drawarray[i].Episodes!=undefined) {

			bgcolor = (cidx&1)?"ffffff":"f0f4f7";cidx++
			subcount=0
			subarr=[]
			for (var epx=0;epx<2;epx++) {
				if (ify==2&&epx==1) {break}
				if (ify==1&&epx==1) {break}
				for (ix=0;ix<drawarray[i].Episodes.length;ix++) {
					qDDIDSarr = drawarray[i].Episodes[ix].DDIDS.split(",")
					for (var isa=0;isa<qDDIDSarr.length;isa++) {
						idq = qDDIDSarr[isa].split("|")[0]
						thisstatus = drawarray[i].Episodes[ix].Status[idq]

						if (thisstatus=="") {continue}
						if (thisstatus==undefined) {thisstatus=1}

						if (ify==0&&epx==0) {
							if (thisstatus!=1) {continue}
						}
						if (ify==0&&epx==1) {
							if (thisstatus!=5&&thisstatus!=6&&thisstatus!=7&&thisstatus!=8) {continue}
						}
						if (ify==1&&epx==0) {
							if (thisstatus!=5&&thisstatus!=6&&thisstatus!=7&&thisstatus!=8) {continue}
						}
						if (ify==2) {
							if (thisstatus!=2&&thisstatus!=3&&thisstatus!=4&&thisstatus!=12) {continue}
						}

						thisdate = drawarray[i].Episodes[ix].PurchasedDate.split(" ")[0]
						thislang = drawarray[i].Episodes[ix].TitleID+"_"+idq+"_"+drawarray[i].Episodes[ix].PassID
						thisdest = getDestinationNameByDDID(qDDIDSarr[isa].split("|")[2])
						thisstatusmessage = dlstatusarray[thisstatus-1].Lookup_Desc
						if (thisstatus==2) {thisstatusmessage+=" "+thisdest}
						if (thisstatus==12) {thisstatusmessage+=" "+thisdest}
						if (thisstatus==3) {thisstatusmessage+=" "+thisdest}
						if (thisstatus==4) {thisstatusmessage += " "+thisdest+" ("+drawarray[i].Episodes[ix].Message[idq]+"% Downloaded)"}
						if (thisstatus==5) {thisstatusmessage=thisstatusmessage.replace(/\sat/g," at "+thisdest)}
						if (thisstatus==6) {thisstatusmessage=thisstatusmessage.replace(/\sat/g," at "+thisdest)}
						if (thisstatus==7) {thisstatusmessage += " at "+thisdest}
						if (thisstatus==8) {thisstatusmessage=thisstatusmessage.replace(/\[\]/g,thisdest)}
						if (ify==0||ify==1) {
							cclick='onclick="selectlist(this,'+drawarray[i].Episodes[ix].TitleID+',\''+drawarray[i].Episodes[ix].BoxArt+'\')"'
							cmouse='onmouseover="rowover(this,\''+bgcolor+'\')" onmouseout="rowout(this,\''+bgcolor+'\')"'
							cpoint='cursor:pointer;'
						} else {
							cclick=''
							cmouse=''
							cpoint='cursor:default;'
						}
						if (debug==true) {
							imgalt='alt="Status:'+thisstatus+'  PassID:'+drawarray[i].Episodes[ix].PassID+'  DQID:'+idq+" - "+ify+" - "+epx+'"'
						} else {imgalt=""}

						if (rowgrp==0||rowgrp==1) {
							if (firstdraw==false) {
								if (isthisselected(thislang)) {
									newselectlist.push("listrow_"+String(rowgrp)+String(i)+"_sub_"+subcount);
									rowclass="selectlist"
								}else{
									rowclass="selectlistoff"
								}
								showsub = isthisselectedfolderopen_queue(thislang)
							} else {
								rowclass="selectlistoff"
								if (browser=="ff") {
									showsub="table-row"
								} else {
									showsub="block"
								}
							}
						} else {
							rowclass="selectlistoff"
							showsub="block"
						}
						thisfiletype=" ("+getfiletypenamefromPassIDSKU(drawarray[i].Episodes[ix].PassID,qDDIDSarr[isa].split("|")[1])+")"
						subarr.push('<tr id="listrow_'+String(rowgrp)+String(i)+'_sub_'+subcount+'" iteminfo="'+thislang+'" class="'+rowclass+'" '+cclick+' style="display:'+showsub+';'+cpoint+'background-color:#'+bgcolor+';" '+cmouse+' unselectable="on">')
						subarr.push('<td class="listr1" valign="top" style="padding-left:30px;" unselectable="on"><table cellpadding="0" cellspacing="0" border="0""><tr><td><img '+imgalt+' src="'+statusimgarray[thisstatus]+'" onload="if (this.src.indexOf(\'.png\')!=-1){fixpng()}" border="0" unselectable="on"/></td><td width="5" unselectable="on"></td><td unselectable="on" width="480"><div style="font-size:11px;" unselectable="on">'+thisdate+'</div><strong unselectable="on">'+drawarray[i].Episodes[ix].Name+'</strong>'+thisfiletype+': '+thisstatusmessage+'</td></tr></table></td></tr>')
						subcount++
					}
				}
			}

			thislang = drawarray[i].TitleID
			if (rowgrp==0||rowgrp==1) {
				if (firstdraw==false) {
					if (hasrowsselected(thislang)) {rowclass="selectlist"}else{rowclass=""}
				} else {
					rowclass=""
				}
			} else {
				rowclass=""
			}
			if (ify==0||ify==1) {
				if (subcount>0) {subfolders=","+subcount}
				tlist.push('<tr id="listrow_'+String(rowgrp)+String(i)+'" iteminfo="'+thislang+'" class="'+rowclass+'" width="552" onclick="selectlist(this,'+drawarray[i].TitleID+',\''+drawarray[i].BoxArt+'\''+subfolders+')" style="cursor:pointer;background-color:#'+bgcolor+';" onmouseover="rowover(this,\''+bgcolor+'\')" onmouseout="rowout(this,\''+bgcolor+'\')" unselectable="on">')
			} else {
				tlist.push('<tr id="listrow_'+String(rowgrp)+String(i)+'" iteminfo="'+thislang+'" width="552" style="cursor:default;background-color:#'+bgcolor+';" unselectable="on">')
			}
			tlist.push('<td class="listr1" width="552" valign="top" style="padding-top:14px;padding-bottom:10px;">'+drawarray[i].Name+'</td></tr>')

			if (ify==0||ify==1) {
				cmouse='onmouseover="rowover(this,\''+bgcolor+'\')" onmouseout="rowout(this,\''+bgcolor+'\')"'
				cpoint='cursor:pointer;'
			} else {
				cmouse=''
				cpoint='cursor:pointer;'
			}

			thislang = drawarray[i].TitleID+"|"+subcount
			if (rowgrp==0||rowgrp==1) {
				if (firstdraw==false) {
					if (isthisselectedfoldergadgetopen_queue(thislang)) {folderopen="foldergadgetopened"} else {folderopen="foldergadget"}
					if (hasrowsselected(thislang)) {rowclass="selectlistfolderrow"}else{rowclass="listfolderrow"}
				} else {
					folderopen="foldergadgetopened"
					rowclass="listfolderrow"
				}
			} else {
				folderopen="foldergadgetopened"
				rowclass="listfolderrow"
			}
			tlist.push('<tr id="listrow_'+String(rowgrp)+String(i)+'_folder" iteminfo="'+thislang+'" width="552" class="'+rowclass+'" style="background-color:#'+bgcolor+';" '+cmouse+' unselectable="on">')
			tlist.push('<td width="552" style="padding-left:15px;font-size:11px;'+cpoint+'" onmousedown="togglefolder(this,\'listrow_'+String(rowgrp)+String(i)+'\','+subcount+')" unselectable="on"><img id="listrow_'+String(rowgrp)+String(i)+'_foldergadget" class="'+folderopen+'" name="foldergadget" iteminfo="'+thislang+'" src="img/spacer.gif" width="12" height="12" style="cursor:pointer;" border="0" unselectable="on"/> select individual episodes from this season</td></tr>')
			tlist = tlist.concat(subarr)

			}
		}

		if (ify==1) {
			tlist.push('</thead></table>')
			dg("statusDiv").innerHTML = tlist.join("")
		}
		if (ify==2) {
			dg("downloadDiv").innerHTML = tlist.join("")
		}
	}

	if (statcount==0) {
		if (currenttab!="library") {
			tabclick("library")
		}
	} else {
		dg("scroller").innerHTML = ""
		unselectable(dg("statusDiv"))
		unselectable(dg("downloadDiv"))
		removenullnodes(dg("statusDiv"))
		removenullnodes(dg("downloadDiv"))

		if (dg("scroller").clientHeight<dg("scrollDiv").clientHeight) {
			dg("scrollbuttons").style.display="none"
		} else {
			dg("scrollbuttons").style.display="block"
		}

		dg("scroller").style.top="0px"

		selectlist_array=[]
		for (var i=0;i<newselectlist.length-1;i++) {
			selectlist_array.push(dg(newselectlist[i]))
		}

		if (newselectlist.length>0) {
			ctrlstate=true
			dg(newselectlist[newselectlist.length-1]).onclick()
			ctrlstate=false
		}
	}
	doresize()
}

//===========================================================================
//===========================================================================
//===========================================================================
//===========================================================================
currentPassID = ""
lastselected = ""
function selectlist(thisselect,titleid,boxart,hasfolder) {
	//if (ctrlstate==false&&lastselected==thisselect) {return}
	//lastselected=thisselect
	//if (thisselect.id.split("_")[1].substr(0,1)=="1") {ctrlstate=false}	//downlaod queue has no ctrl state

	currentinfoview=""

	if (currenttab=="queue") {
		if ((thisselect.id.split("_")[1].substr(0,1)=="2"&&selectlist_array.length>0)) {
			for (var i=0;i<selectlist_array.length;i++) {
				try{selectlist_array[i].className = "selectlistoff"}catch(e){}
				try{dg("listrow_"+selectlist_array[i].id.split("_")[1]+"_folder").className="listfolderrow"}catch(e){}

				if (selectlist_array[i].id.indexOf("_sub_")!=-1) {
					dg("listrow_"+selectlist_array[i].id.split("_")[1]).className = "selectlistoff"
					dg("listrow_"+selectlist_array[i].id.split("_")[1]+"_folder").className = "listfolderrow"
				}
			}
			selectlist_array=[]
		}

		selectlist_array_ids = ""
		for (var i=0;i<selectlist_array.length;i++) {
			selectlist_array_ids += selectlist_array[i].id+"|"
		}
		if ((thisselect.id.split("_")[1].substr(0,1)=="0"||thisselect.id.split("_")[1].substr(0,1)=="1")&&selectlist_array_ids.indexOf("listrow_2")!=-1) {
			for (var i=0;i<selectlist_array.length;i++) {
				if (selectlist_array[i].id.indexOf("listrow_1")!=-1) {
					try{selectlist_array[i].className = "selectlistoff"}catch(e){}
					try{dg("listrow_"+selectlist_array[i].id.split("_")[1]).className = "selectlistoff"}catch(e){}
					try{dg("listrow_"+selectlist_array[i].id.split("_")[1]+"_folder").className = "listfolderrow"}catch(e){}
				}
			}
			selectlist_array=[]
		}
	}


	if (ctrlstate==false) {
		if (selectlist_array.length>0) {
			for (var i=0;i<selectlist_array.length;i++) {
				try{selectlist_array[i].className = "selectlistoff"}catch(e){}
				try{dg("listrow_"+selectlist_array[i].id.split("_")[1]+"_folder").className="listfolderrow"}catch(e){}

				if (selectlist_array[i].id.indexOf("_sub_")!=-1) {
					dg("listrow_"+selectlist_array[i].id.split("_")[1]).className = "selectlistoff"
					dg("listrow_"+selectlist_array[i].id.split("_")[1]+"_folder").className = "listfolderrow"
				}
			}
		}
		selectlist_array=[]
	}

	selectfound=-1
	if (hasfolder) {
		for (var i=0;i<selectlist_array.length;i++) {
			for (ix=0;ix<hasfolder;ix++) {
				if (dg(thisselect.id+"_sub_"+ix)==selectlist_array[i]) {
					selectfound=i
					break
				}
			}
		}
	} else {
		for (var i=0;i<selectlist_array.length;i++) {
			if (thisselect==selectlist_array[i]) {
				selectfound=i
				break
			}
		}
	}

	if (selectfound!=-1) { // turn it off

		thisselect.className = "selectlistoff"
		if (hasfolder) {
			dg("listrow_"+thisselect.id.split("_")[1]+"_folder").className="listfolderrow"
			for (ixf=0;ixf<hasfolder;ixf++) {
				try{dg("listrow_"+thisselect.id.split("_")[1]+"_sub_"+ixf).className="selectlistoff"}catch(e){}
			}
			try{dg("listrow_"+thisselect.id.split("_")[1]).className="selectlistoff"}catch(e){}
		}

		var removearray=[]
		if (hasfolder) {
			selectbase = String(thisselect.id)
			for (var i=0;i<selectlist_array.length;i++) {
				if (  String(selectlist_array[i].id).indexOf(selectbase+"_sub_")!=-1) {
					removearray.push(i)
				}
			}
		} else {
			removearray.push(selectfound)
		}

		for (var i=removearray.length-1;i>-1;i--) {
			selectlist_array.splice(removearray[i],1)
		}

		if (thisselect.id.indexOf("_sub_")!=-1) {
			anyleft = false
			getlang = parseInt(dg("listrow_"+thisselect.id.split("_")[1]+"_folder").getAttribute("iteminfo").split("|")[1],10)
			for (i=0;i<selectlist_array.length;i++) {
				for (var ix=0;ix<getlang;ix++) {
					if (selectlist_array[i]==dg("listrow_"+thisselect.id.split("_")[1]+"_sub_"+ix)) {
						anyleft = true
					}
				}
			}
			if (anyleft==false) {
				dg("listrow_"+thisselect.id.split("_")[1]).className = "selectlistoff"
				dg("listrow_"+thisselect.id.split("_")[1]+"_folder").className = "listfolderrow"
			}
		}
	} else { // turn it on
		if (hasfolder) {
			for (i=0;i<hasfolder;i++) {
				if (i>0&&destinationarray.length==1&&parseFloat(destinationarray[0].Ver.substr(0,3))<1.4&&destinationarray[0].Loc==machinename) {continue}	// version <1.4 do not accept multiples
				if (!alreadythere(dg(thisselect.id+"_sub_"+i))) {
					try{
						dg(thisselect.id+"_sub_"+i).className="selectlist"
						selectlist_array.push(dg(thisselect.id+"_sub_"+i))
					}catch(e){}
				}
			}
			dg("listrow_"+thisselect.id.split("_")[1]).className="selectlist"
			dg("listrow_"+thisselect.id.split("_")[1]+"_folder").className="selectlistfolderrow"
		} else {
			if (thisselect.id.indexOf("_sub")!=-1) {
				if (!alreadythere(thisselect)) {
					selectlist_array.push(thisselect)
					thisselect.className="selectlist"
					dg("listrow_"+thisselect.id.split("_")[1]).className = "selectlist"
					dg("listrow_"+thisselect.id.split("_")[1]+"_folder").className = "selectlistfolderrow"

				}
			} else {
				if (!alreadythere(thisselect)) {
					selectlist_array.push(thisselect)
					thisselect.className="selectlist"
				}
			}
		}
	}

	dg("info_status").innerHTML = ""
	dg("info_status").style.display="none"

	allalone=true
	if (selectlist_array.length==1) {
		if (selectlist_array[0].id!=thisselect.id) {
			newselect = selectlist_array[0]
			selectlist_array=[]
			try{newselect.click()}catch(e){newselect.onclick()}
		} else {
			currentPassID = selectlist_array[0].getAttribute("iteminfo").split("_")[2]
			getitem = getitemfromPassID(currentPassID)

			if (getitem==undefined) {
				itemstatus=0
			} else {
				itemstatus = getitem.Status
			}

			if (dg("infoboximg").src.indexOf(boxart)==-1) {

				drawdownloads(getitemfromPassID(currentPassID))

				if (itemstatus==1||itemstatus==6||itemstatus==7) {
					dg("info_titleinfo_tab").style.cursor="pointer"
				} else {
					dg("info_titleinfo_tab").src="img/mmgr/tab_info_titleinfo_on.gif"
					dg("info_titleinfo_tab").style.cursor="pointer"

					if (thisselect.id.split("_")[1].substr(0,1)=="2") {
						dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_ghost.gif"
					} else {
						dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_off.gif"
					}
				}

				if (titleinfo_array[titleid]==undefined) {
					ajl(webservices+"Titles.asmx/GetTitle",titlescallback,'TitleID='+titleid,ajaxerror,true);
				} else {
					drawtitleinfo(titleinfo_array[titleid])
				}

				loadboxart(boxart)

				similaritem = getobjfromPassID(currentPassID)
				similarSKUID = similaritem.DDIDS.split(",")[0].split("|")[1]
				if (similars[similarSKUID]==undefined) {
					ajl(webservices+"remoteq.asmx/GetRelatedPurchases",drawsimilar_callback,'SKUID='+similarSKUID,ajaxerror,true);
				} else {
					drawsimilar(similarSKUID)
				}

			}
		}

		dg("countDiv").innerHTML = "Selected 1 of "+thiscount
		if (thisselect.id.split("_")[1].substr(0,1)=="2") {
			dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_ghost.gif"
		} else {
			dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_off.gif"
		}
		if (itemstatus==1||itemstatus==6||itemstatus==7||itemstatus==undefined) {

			if (currentinfoview!="downloads") {
				changeinfoview('downloads')
			} else {
				dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_on.gif"
				dg("info_titleinfo_tab").src="img/mmgr/tab_info_titleinfo_off.gif"
				dg("info_titleinfo_tab").style.cursor="pointer"
			}
		} else {
			changeinfoview("titleinfo")
		}
	} else {
		if (selectlist_array.length==0) {// unselect everything
			dg("titleInfoDiv").style.display="none"
			dg("countDiv").innerHTML = ""
			dg("infoboximgDiv").innerHTML = '<img id="infoboximg" src="'+protocol+'://www.cinemanow.com/img/spacer.gif" border="0"/>'
			dg("infoboxmirrorfade").style.backgroundImage='url('+protocol+'://www.cinemanow.com/img/spacer.gif)'
			dg("countDiv").innerHTML = "Titles in library: "+thiscount
			dg("info_status").innerHTML = ""
			dg("info_status").style.display="none"
		} else {
		/*
			if (thisselect.id.split("_")[1].substr(0,1)=="2") {
				dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_ghost.gif"
			} else {
				dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_off.gif"
			}
		*/
			if (selectlist_array.length>1) {
				allalone = true // are all selected part of a tv season?
				aloneidx = -1
				for (i=0;i<selectlist_array.length;i++) {
					if (i==0) {
						aloneidx = selectlist_array[i].id.split("_")[1]
						continue
					}
					if (aloneidx!=selectlist_array[i].id.split("_")[1]) {
						allalone = false
						break
					}
				}

				if (allalone == true) {
					alonebox = String(selectlist_array[0].onclick).replace(/\"/g,"'").match(/\'.*?\'/g)[0].replace(/\'/g,"")
					if (dg("infoboximg").src.indexOf(boxart)==-1) {
						dg("info_titleinfo_tab").src="img/mmgr/tab_info_titleinfo_on.gif"
						dg("info_titleinfo_tab").style.cursor="pointer"
						loadboxart(alonebox)
						if (titleinfo_array[titleid]==undefined) {
							ajl(webservices+"Titles.asmx/GetTitle",titlescallback,'TitleID='+titleid,ajaxerror,true);
						} else {
							drawtitleinfo(titleinfo_array[titleid])
						}
					}

					similaritem = getobjfromPassID(selectlist_array[0].getAttribute("iteminfo").split("_")[2])
					similarSKUID = similaritem.DDIDS.split(",")[0].split("|")[1]
					if (similars[similarSKUID]==undefined) {
						ajl(webservices+"remoteq.asmx/GetRelatedPurchases",drawsimilar_callback,'SKUID='+similarSKUID,ajaxerror,true);
					} else {
						drawsimilar(similarSKUID)
					}

				} else {
					try{cnboxfilt=dg("infoboximg").style.filter.indexOf("cnbox.jpg")}catch(e){cnboxfilt=-1}
					if (dg("infoboximg").src.indexOf("cnbox.jpg")==-1&&cnboxfilt==-1) {
						loadboxart("cnbox")
					}
				}

				drawdownloads(getitemfromPassID(selectlist_array[0].getAttribute("iteminfo").split("_")[2]))
				dg("info_downloads_tab").src="img/mmgr/tab_info_downloads_on.gif"
				dg("info_titleinfo_tab").src="img/mmgr/tab_info_titleinfo_off.gif"
				dg("info_titleinfo_tab").style.cursor="pointer"
				changeinfoview("downloads")

				dg("countDiv").innerHTML = "Selected "+selectlist_array.length+" of "+thiscount

				dg("info_status").innerHTML = ""
				dg("info_status").style.display="none"

			} else {
				try{cnboxfilt=dg("infoboximg").style.filter.indexOf("cnbox.jpg")}catch(e){cnboxfilt=-1}
				if (dg("infoboximg").src.indexOf("cnbox.jpg")==-1&&cnboxfilt==-1) {
					loadboxart("cnbox")
				}
				drawdownloads(getitemfromPassID(selectlist_array[0].getAttribute("iteminfo").split("_")[2]))
				changeinfoview("downloads")
				dg("countDiv").innerHTML = "Selected "+selectlist_array.length+" of "+thiscount
			}
		}
		dg("info_titleinfo_tab").src="img/mmgr/tab_info_titleinfo_ghost.gif"
		dg("info_similar_tab").src="img/mmgr/tab_info_similar_ghost.gif"
		dg("info_titleinfo_tab").style.cursor="default"
		dg("info_similar_tab").style.cursor="default"
	}

	warningmessages()

	doresize()
	drawfiletypes()
	changeinfoview("downloads")
}

function warningmessages() {
	var warnmsg = []
	DQIDmsgs = []
	for (var i=0;i<selectlist_array.length;i++) {

		for (var il=0;il<libraryarray.length;il++) {
			if (libraryarray[il].Episodes==undefined) {
				if (selectlist_array[i].getAttribute("iteminfo").split("_")[2]==libraryarray[il].PassID) {
					thislib = libraryarray[il]
					break
				}
			} else {
				for (var ei=0;ei<libraryarray[il].Episodes.length;ei++) {
					if (selectlist_array[i].getAttribute("iteminfo").split("_")[2]==libraryarray[il].Episodes[ei].PassID) {
						thislib = libraryarray[il].Episodes[ei]
						break
					}
				}
			}
		}

		var thisDDIDSarr = thislib.DDIDS.split(",")
		for (var ids=0;ids<thisDDIDSarr.length;ids++) {
			if (String(","+DQIDmsgs.join(",")+",").indexOf(","+thisDDIDSarr[ids].split("|")[0]+",")!=-1) {continue}
			DQIDmsgs.push(thisDDIDSarr[ids].split("|")[0])
			var DDIDstat = thislib.Status[thisDDIDSarr[ids].split("|")[0]]
			try{if(DDIDstat=="") {continue}}catch(e){}
			if (DDIDstat==undefined) {continue}
			var DDISmsg  = thislib.Message[thisDDIDSarr[ids].split("|")[0]]
			var thisdest = getDestinationNameByDDID(thisDDIDSarr[ids].split("|")[2])
			var thisstatusmessage = dlstatusarray[DDIDstat-1].Lookup_Desc
			thisstatusmessage = thislib.Name+": "+thisstatusmessage
			if (DDIDstat==6) {thisstatusmessage =  thisstatusmessage.replace(/\sat/g," at "+thisdest)}
			if (DDIDstat==7) {thisstatusmessage += " at "+thisdest}

			if (DDIDstat==2) {thisstatusmessage+=" "+thisdest}
			if (DDIDstat==12) {thisstatusmessage+=" "+thisdest}
			if (DDIDstat==3) {thisstatusmessage+=" "+thisdest}
			if (DDIDstat==4) {thisstatusmessage+=" "+thisdest+" ("+DDISmsg+"% Downloaded)";}
			if (DDIDstat==5) {thisstatusmessage=thisstatusmessage.replace(/\sat/g," at "+thisdest)}
			if (DDIDstat==6) {thisstatusmessage=thisstatusmessage.replace(/\sat/g," at "+thisdest)}
			if (DDIDstat==7) {thisstatusmessage+=" at "+thisdest}
			if (DDIDstat==8) {thisstatusmessage=thisstatusmessage.replace(/\[\]/g,thisdest)}

			if (DDIDstat!=5) {
				if (debug==true) {imgalt='alt="Status:'+DDIDstat+'"'}else{imgalt=''}
				warnmsg.push('<tr height="28"><td width="28"><img '+imgalt+' src="'+statusimgarray[DDIDstat]+'" onload="if (this.src.indexOf(\'.png\')!=-1){fixpng()}" border="0"/></td><td width="5"></td><td align="left">'+thisstatusmessage+'</td></tr>')
			}
		}
	}

	if (warnmsg.length>0) {
		dg("info_status").innerHTML = '<table width="250" cellpadding="0" cellspacing="0" border="0">'+warnmsg.join("")+'</table>'
		dg("info_status").style.display="block"
	} else {
		dg("info_status").innerHTML = ""
		dg("info_status").style.display="none"
	}
}

lastboxart = ""
function loadboxart(boxart) {

	if (lastboxart==boxart&&dg("titleInfoDiv").style.display!="none") {return}
	lastboxart=boxart

	if (isselectlistthesame()) {return}

	boxesloaded = 0
	fx("infoboximgDiv",4,false,null,"opacity,100,0")
	if (boxart=="cnbox") {
		fx("infoboxmirrorfade",4,false,'loadcnbox()',"opacity,100,0")
	} else {
		fx("infoboxmirrorfade",4,false,'loadnewboxes("'+boxart+'")',"opacity,100,0")
	}
}

//===========================================================================
//===========================================================================
//===========================================================================

function getobjfromDQID(thisDQID) {
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			var libDQarr = libraryarray[i].DDIDS.split(",")
			for (idq=0;idq<libDQarr.length;idq++) {
				if (libDQarr.split("|")[0]==thisDQID) {
					return libraryarray[i];
					break
				}
			}
		} else {
			for (var ix=0;ix<libraryarray[i].Episodes.length;ix++) {
				var libDQarr = libraryarray[i].Episodes[ix].DDIDS.split(",")
				for (var idq=0;idq<libDQarr.length;idq++) {
					if (libDQarr.split("|")[0]==thisDQID) {
						return libraryarray[i].Episodes[ix];
						break
					}
				}
			}
		}
	}
	return {}
}
//===========================================================================

function getitemfromdqid(thisdqid) {
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			if (libraryarray[i].DQID==thisdqid) {
				return libraryarray[i]
			}
		} else {
			for (var ix=0;ix<libraryarray[i].Episodes.length;ix++) {
				if (libraryarray[i].Episodes[ix].DQID==thisdqid) {
					return libraryarray[i].Episodes[ix]
				}
			}
		}
	}
}
//===========================================================================

function getobjfromPassID(thisPassID) {
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			if (libraryarray[i].PassID==thisPassID) {return libraryarray[i];break}
		} else {
			for (var ix=0;ix<libraryarray[i].Episodes.length;ix++) {
				if (libraryarray[i].Episodes[ix].PassID==thisPassID) {return libraryarray[i].Episodes[ix];break}
			}
		}
	}
	return {}
}


//===========================================================================

function getitemfromPassID(thispassid) {
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			if (libraryarray[i].PassID==thispassid) {
				return libraryarray[i]
			}
		} else {
			for (var ix=0;ix<libraryarray[i].Episodes.length;ix++) {
				if (libraryarray[i].Episodes[ix].PassID==thispassid) {
					return libraryarray[i].Episodes[ix]
				}
			}
		}
	}
}

//===========================================================================

function alreadythere(thisselect) {
	isthere = false
	for (var i=0;i<selectlist_array.length;i++) {
		if (thisselect==selectlist_array[i]) {
			isthere = true
			break;
		}
	}
	return isthere
}

//===========================================================================
function hidetitleinfo() {
	fx("titleInfoDiv",8,fx_slideout,"hidtitleinfo_hidden()","opacity,100,0")
}
function hidtitleinfo_hidden() {
	try{dg("infoboximgDiv").innerHTML = '<img id="infoboximg" src="'+protocol+'://www.cinemanow.com/img/spacer.gif" border="0"/>'}catch(e){}
	try{dg("infoboxmirrorfade").style.backgroundImage='url('+protocol+'://www.cinemanow.com/img/spacer.gif)'}catch(e){}
	dg("titleInfoDiv").style.display="none"
	setopacity("titleInfoDiv",100)
}

lastsearch=""
searcharray=[]
function searchlist(thissearch) {
	if (lastsearch==thissearch){return}
	lastsearch=thissearch

	hidetitleinfo()
	selectlist_array=[]

	searcharray=[]

	if (thissearch==""||thissearch=="Search") {
		drawlibrary(libraryarray);
		return
	}

	if (thissearch=="0-9") {
		for (var i=0;i<libraryarray.length;i++) {
			thisname = libraryarray[i].Name
			namesplit = thisname.split(" ")
			for (ix=0;ix<namesplit.length;ix++) {
				if (
					namesplit[ix].substr(0,1)=="0"||
					namesplit[ix].substr(0,1)=="1"||
					namesplit[ix].substr(0,1)=="2"||
					namesplit[ix].substr(0,1)=="3"||
					namesplit[ix].substr(0,1)=="4"||
					namesplit[ix].substr(0,1)=="5"||
					namesplit[ix].substr(0,1)=="6"||
					namesplit[ix].substr(0,1)=="7"||
					namesplit[ix].substr(0,1)=="8"||
					namesplit[ix].substr(0,1)=="9"
				) {
					valid=true
					for (iy=0;iy<searcharray.length;iy++) {
						if (searcharray[iy].Name==libraryarray[i].Name) {valid=false;break}
					}
					if (valid==true) {
						searcharray.push(libraryarray[i])
					}
				}
			}
		}
	} else {
		thissearch = thissearch.toLowerCase()
		for (var i=0;i<libraryarray.length;i++) {
			thisname = libraryarray[i].Name.toLowerCase()
			namesplit = thisname.split(" ")
			for (ix=0;ix<namesplit.length;ix++) {
				if (namesplit[ix].substr(0,thissearch.length) == thissearch) {
					valid=true
					for (iy=0;iy<searcharray.length;iy++) {
						if (searcharray[iy].Name==libraryarray[i].Name) {valid=false;break}
					}
					if (valid==true) {
						searcharray.push(libraryarray[i])
					}
				}
			}
		}
	}

	if (searcharray.length>0) {
		drawlibrary(searcharray)
		dg("countDiv").innerHTML = "Search results: "+searcharray.length
	} else {
		dg("scroller").style.top = "0px"
		dg("scroller").innerHTML = '<div style="padding:20px;width:522px;font-size:14px;font-weight:700;color:#777a7d" align="center">Sorry, no results found for &quot;'+thissearch+'&quot;</div>'
		dg("countDiv").innerHTML = "Search results: 0"
	}

	searchcount = 0
	for (i=0;i<searcharray.length;i++) {
		searchcount++
		if (searcharray[i].Episodes!=undefined) {
			searchcount+=searcharray[i].Episodes.length-1
		}
	}
	doresize()
	dg("countDiv").innerHTML = "Total search results: "+searchcount
}

//======================================================================================================================
//======================================================================================================================
//======================================================================================================================

laststatustime = Date.parse(new Date())
racecondition = false
libraryarray=[]
function libraryrequest_callback(thisxml) {
	libraryarray = parselibraryrequest(thisxml)
	if (libraryarray.length!=0) {
		if (browser=="ie") {
			dg("toptabs").style.display="block"
		} else {
			dg("toptabs").style.display="table"
		}

		//race prevention
		if (Date.parse(new Date())-laststatustime<10000) {racecondition=true} else {racecondition=false}
		laststatustime = Date.parse(new Date())

		if (racecondition==false&&currenttab!="") {
			ajl(webservices+"remoteq.asmx/StatusRequest",status_callback,"userID="+userID,ajaxerror,true)
			if (currenttab=="library"){
				if (searcharray.length>0) {
					drawlibrary(searcharray)
				} else {
					drawlibrary(libraryarray)
				}
			}
		}
	} else {
		dg("toptabs").style.display="none"
		dg("loadingDiv").innerHTML = "<br/><br/><br/><br/>No items found in your library."
	}
}

function parselibraryrequest(libxml) {
	var libdom 	= libxml.documentElement;
	var librarylist 	= []
	librarylist.completed = false

	libpasses	= libdom.getElementsByTagName("Passes")
	libpassarr	= libpasses.item(0).getElementsByTagName("Pass")
	for (var i=0;i<libpassarr.length;i++) {
		librarylist.push(new Object())
		var libraryitem = librarylist[librarylist.length-1]
		for (ic=0;ic<libpassarr[i].childNodes.length;ic++) {
			try{var librarytext = libpassarr[i].childNodes.item(ic).childNodes.item(0).nodeValue}catch(e){var librarytext=null}
			eval("libraryitem."+libpassarr[i].childNodes.item(ic).tagName+"=librarytext")
		}
		thisDDIDS=librarylist[librarylist.length-1].DDIDS.split(",")
		if (librarylist[librarylist.length-1].Status==undefined) {
			librarylist[librarylist.length-1].Status=[]
			librarylist[librarylist.length-1].Message=[]
			for (idd=0;idd<thisDDIDS.length;idd++) {
				if (thisDDIDS[idd].split("|")[0]!=-1) {

					librarylist[librarylist.length-1].Status[thisDDIDS[idd].split("|")[0]] = ""
					librarylist[librarylist.length-1].Message[thisDDIDS[idd].split("|")[0]] = ""
				}
			}
		}
	}

	bundlecollection = libdom.getElementsByTagName("Bundle")
	getbundles = bundlecollection.item(0).getElementsByTagName("S")
	for (var i=0;i<getbundles.length;i++) {
		librarylist.push(new Object())
		var libraryitem = librarylist[librarylist.length-1]
		for (ic=0;ic<getbundles[i].childNodes.length;ic++) {
			try{librarytext = getbundles[i].childNodes.item(ic).childNodes.item(0).nodeValue}catch(e){var librarytext=null}
			eval("libraryitem."+getbundles[i].childNodes.item(ic).tagName+"=librarytext")
		}
		var episodes = getbundles[i].getElementsByTagName("Pass")
		if (episodes.length>0) {
			libraryitem.Episodes=[]
			for (var ei=0;ei<episodes.length;ei++) {
				libraryitem.Episodes.push(new Object())
				for (ic=0;ic<episodes[ei].childNodes.length;ic++) {
					try{var librarytext = episodes[ei].childNodes.item(ic).childNodes.item(0).nodeValue}catch(e){var librarytext=null}
					eval("libraryitem.Episodes[libraryitem.Episodes.length-1]."+episodes[ei].childNodes.item(ic).tagName+"=librarytext")
				}
				eval("libraryitem.Episodes[libraryitem.Episodes.length-1].isEpisode=true")
				thisDDIDS=libraryitem.Episodes[libraryitem.Episodes.length-1].DDIDS.split(",")
				if (libraryitem.Episodes[libraryitem.Episodes.length-1].Status==undefined) {
					libraryitem.Episodes[libraryitem.Episodes.length-1].Status=[]
					libraryitem.Episodes[libraryitem.Episodes.length-1].Message=[]
					for (idd=0;idd<thisDDIDS.length;idd++) {
						if (thisDDIDS[idd].split("|")[0]!=-1) {
							libraryitem.Episodes[libraryitem.Episodes.length-1].Status[thisDDIDS[idd].split("|")[0]] = ""
							libraryitem.Episodes[libraryitem.Episodes.length-1].Message[thisDDIDS[idd].split("|")[0]] = ""
						}
					}
				}
			}
		}
	}

	librarylist.completed = true
	return librarylist
}


//======================================================================================================================
//======================================================================================================================
//======================================================================================================================

statustmr = 0
sleepcount = 0
sleeping = false
function statusloop() {

	if(movecount==0&&libraryarray.length>0) {
		sleepcount++
	}
	movecount=0
	if (sleepcount>20) {
		sleepcount=0
		sleeping=true
		dg("timeoutimg").style.left = Math.round((dbcw/2)-(383/2))+"px"
		dg("timeoutimg").style.top  = Math.round(400+document.body.scrollTop)+"px"
		dg("timeoutimg").style.display="block";
		return
	}
	if (libraryarray.length==0) {
		setTimeout("statusloop()",200)
	} else {
		ajl(webservices+"remoteq.asmx/StatusRequest",status_callback,"userID="+userID,ajaxerror,true)
		statustmr = setTimeout("statusloop()",30000)
	}
}

statusloaded = false
function status_callback(statusxml) {
	var statusdom 	= statusxml.documentElement;

	getstatusxml	= statusdom.getElementsByTagName("DQCol").item(0).getElementsByTagName("DQ")

	updatelibrary = false
	updatequeue = false
	for (var idq=0;idq<getstatusxml.length;idq++) {

	var qPassID	= getstatusxml[idq].getElementsByTagName("PassID")[0].childNodes.item(0).nodeValue
	var qDQID	= getstatusxml[idq].getElementsByTagName("DQID")[0].childNodes.item(0).nodeValue
	var qDDID	= getstatusxml[idq].getElementsByTagName("DDID")[0].childNodes.item(0).nodeValue
	var qStatus	= getstatusxml[idq].getElementsByTagName("Status")[0].childNodes.item(0).nodeValue
	try{var qMessage= getstatusxml[idq].getElementsByTagName("Message")[0].childNodes.item(0).nodeValue}catch(e){var qMessage=""}

		DQPASSarr = []
		PassIDexists = false
		libDQIDexists = false
		libDDIDexists = false
		for (var i=0;i<libraryarray.length;i++) {
			if (libraryarray[i].Episodes==undefined) {
				if (libraryarray[i].PassID==qPassID) {
					DQPASSarr.push(qPassID+"|"+qDQID)
					PassIDexists = true
					if (libraryarray[i].Status[qDQID]==undefined) {updatequeue=true;}
					if (libraryarray[i].Status[qDQID]!=undefined) {libDQIDexists=true}
					libDDIDSarr=libraryarray[i].DDIDS.split(",")
					for (var ldr=0;ldr<libDDIDSarr.length;ldr++) {
						if (libDDIDSarr[ldr].split("|")[2]==qDDID) {libDDIDexists=true}
					}
					if (qStatus==-1) {continue}
					if (
						libraryarray[i].Status[qDQID]!=qStatus ||
						libraryarray[i].Message[qDQID]!=qMessage
					) {
						updatequeue = true
						libraryarray[i].Status[qDQID]=qStatus
						try{
							libraryarray[i].Message[qDQID]=qMessage
						}catch(e){
							libraryarray[i].Message[qDQID]=""
						}
						if (libraryarray[i].PassID==currentPassID) {
							warningmessages()
						}
					}
				}
			} else {
				for (var ix=0;ix<libraryarray[i].Episodes.length;ix++) {
					if (libraryarray[i].Episodes[ix].PassID==qPassID) {
						DQPASSarr.push(qPassID+"|"+qDQID)
						PassIDexists = true
						if (libraryarray[i].Episodes[ix].Status[qDQID]==undefined) {updatequeue=true;}
						if (libraryarray[i].Episodes[ix].Status[qDQID]!=undefined) {libDQIDexists=true}
						libDDIDSarr=libraryarray[i].Episodes[ix].DDIDS.split(",")
						for (var ldr=0;ldr<libDDIDSarr.length;ldr++) {
							if (libDDIDSarr[ldr].split("|")[2]==qDDID) {libDDIDexists=true}
						}
						if (qStatus==-1) {continue}
						if (
							libraryarray[i].Episodes[ix].Status[qDQID]!=qStatus ||
							libraryarray[i].Episodes[ix].Message[qDQID]!=qMessage
						) {
							updatequeue = true
							libraryarray[i].Episodes[ix].Status[qDQID]=qStatus
							try{
								libraryarray[i].Episodes[ix].Message[qDQID]=qMessage
							}catch(e){
								libraryarray[i].Episodes[ix].Message[qDQID]=""
							}
							if (libraryarray[i].Episodes[ix].PassID == currentPassID) {
								warningmessages()
							}
						}
					}
				}
			}
		}
		if (PassIDexists==false||libDQIDexists==false||libDDIDexists==false) {updatelibrary=true}
	}

	//Set status for DQIDs not present in the status request to "" (null, or no status - will not be shown in queue)
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			if (libraryarray[i].Status!=undefined) {
				var thisDDIDSarr = libraryarray[i].DDIDS.split(",")
				for (var ids=0;ids<thisDDIDSarr.length;ids++) {
					thisDQID=thisDDIDSarr[ids].split("|")[0]
					try{if (libraryarray[i].Status[thisDQID]==undefined) {continue}}catch(e){continue}

					nodqid=true
					for (var idq=0;idq<getstatusxml.length;idq++) {
						var qDQID = getstatusxml[idq].getElementsByTagName("DQID")[0].childNodes.item(0).nodeValue
						if (qDQID==thisDQID) {nodqid=false}
					}
					if (nodqid==true) {
						if (libraryarray[i].Status[thisDQID]!="") {
							libraryarray[i].Status[thisDQID] = ""
							libraryarray[i].Message[thisDQID] = ""
							updatelibrary=true
						}
					}
				}
			}

		} else {
			for (var ei=0;ei<libraryarray[i].Episodes.length;ei++) {
				if (libraryarray[i].Episodes[ei].Status!=undefined) {
					var thisDDIDSarr = libraryarray[i].Episodes[ei].DDIDS.split(",")
					for (var ids=0;ids<thisDDIDSarr.length;ids++) {
						thisDQID=thisDDIDSarr[ids].split("|")[0]
						try{if (libraryarray[i].Episodes[ei].Status[thisDQID]==undefined) {continue}}catch(e){continue}

						nodqid=true
						for (var idq=0;idq<getstatusxml.length;idq++) {
							var qDQID = getstatusxml[idq].getElementsByTagName("DQID")[0].childNodes.item(0).nodeValue
							if (qDQID==thisDQID) {nodqid=false}
						}
						if (nodqid==true) {
							if (libraryarray[i].Episodes[ei].Status[thisDQID]!="") {
								libraryarray[i].Episodes[ei].Status[thisDQID] = ""
								libraryarray[i].Episodes[ei].Message[thisDQID] = ""
								updatelibrary=true
							}
						}
					}
				}
			}
		}
	}
	statusloaded = true

	if (updatelibrary==true) {
		if (Date.parse(new Date())-laststatustime>5000) {
			ajl(webservices+"remoteq.asmx/LibraryRequest",libraryrequest_callback,'UserID='+userID,ajaxerror,true);
		}
		drawqueue(libraryarray)
	} else {
		if (updatequeue==true&&currenttab=="queue") {drawqueue(libraryarray)}
	}

	if (updatequeue==true) {
		if (selectlist_array.length>0) {
			drawdownloads(getitemfromPassID(selectlist_array[0].getAttribute("iteminfo").split("_")[2]))
		}
	}
}

//======================================================================================================================
//======================================================================================================================
//======================================================================================================================

function downloadstatus_callback(getdlstatxml) {
	dlstatusarray = parsedlstatus(getdlstatxml)
}

function parsedlstatus(dlstatxml) {
	var dlstatdom 	= dlstatxml.documentElement;
	var dlstatarr	= []
	dlstatarr.completed=false
	dlstatlist	= dlstatdom.getElementsByTagName("StatusLookup")
	for (var i=0;i<dlstatlist.length;i++) {
		dlstatarr.push(new Object())
		var thisdlstat = dlstatarr[dlstatarr.length-1]
		thisdlstat.Status_ID	= dlstatlist[i].getElementsByTagName("Status_ID")[0].childNodes.item(0).nodeValue
		thisdlstat.Lookup_Code	= dlstatlist[i].getElementsByTagName("Lookup_Code")[0].childNodes.item(0).nodeValue
		thisdlstat.Lookup_Desc	= dlstatlist[i].getElementsByTagName("Lookup_Desc")[0].childNodes.item(0).nodeValue
		thisdlstat.IsError	= dlstatlist[i].getElementsByTagName("IsError")[0].childNodes.item(0).nodeValue
	}
	dlstatarr.completed = true
	return dlstatarr
}

//======================================================================================================================
//======================================================================================================================
//======================================================================================================================

currentDDID = -1
destinationarray=[]
function destinations_callback(getdestxml) {
	destinationarray = parsedestinations(getdestxml)
	if (destinationarray.length>0) {
		dg("screenblockDiv").style.display="none"
		dg('whatsthisDiv').style.display='none';
		try{dg('whatsthisbgimg').style.display='none';}catch(e){}
		drawdestinations()
		if(getCookie("mm_rq_dest")==null||getCookie("mm_rq_dest")=="undeifned") {
			setCookie("mm_rq_dest",destinationarray[0].DDID)
		}
	} else {
		dg("screenblockDiv").style.display="block"
		adddestination()
		dg("mmalertclosebutton").style.display="none"
	}
}

function parsedestinations(destxml) {
	var destdom 	= destxml.documentElement;
	getdests	= destdom.getElementsByTagName("dd")
	var destlist=[]
	destlist.completed = false
	for (var i=0;i<getdests.length;i++) {
		destlist.push(new Object())
		var desttl = destlist[destlist.length-1]
		for (ic=0;ic<getdests[i].childNodes.length;ic++) {
			try{var desttext = getdests[i].childNodes.item(ic).childNodes.item(0).nodeValue}catch(e){var desttext=null}
			eval("desttl."+getdests[i].childNodes.item(ic).tagName+"=desttext")
		}
	}
	destlist.completed = true
	return destlist
}

function hovershow(thisobj,thistxt) {
	dg("hovershowDiv").innerHTML = thistxt
	dg("hovershowDiv").style.top = (gettop(thisobj)+1)+"px"
	dg("hovershowDiv").style.left = (getleft(thisobj)-128)+"px"
	dg("hovershowDiv").style.display="block"
}

function closehovershow() {
	dg("hovershowDiv").style.display="none"
}

function drawdestinations() {
	desthtml=[]
	desthtml.push('<table id="destinationslide" cellpadding="0" cellspacing="0" border="0" class="dropdowntable">')
	samei=-1
	defaultdest = getCookie("mm_rq_dest")
	for (var i=0;i<destinationarray.length;i++) {
		if (destinationarray[i].DDID==defaultdest) {currentDDID=defaultdest;break}
	}

	for (var i=0;i<destinationarray.length;i++) {

		if ((parseFloat(destinationarray[i].Ver.substr(0,3))<1.4&&destinationarray[i].Loc!=machinename)) {
			thisclass="droplistghost"
			nodlmsg = "You must upgrade the Media Manager application on "+destinationarray[i].Loc+" before it will accept remote downloads."
		} else {
			if ((parseFloat(destinationarray[i].Ver.substr(0,3))<1.4&&destinationarray[i].Loc==machinename&&selectlist_array.length>1)) {
				thisclass="droplistghost"
				nodlmsg = "You must upgrade the Media Manager application on this computer before it will accept multiple downloads."
			}else{
				thisclass="droplistoff"
				nodlmsg = ""
			}
		}
		if (String(destinationarray[i].Loc)=="null") {continue}

		if (destinationarray[i].DDID==currentDDID) {
			samei=i
			sameddid=destinationarray[i].DDID
			sameuid=destinationarray[i].DestUniqueID
		}

		desthtml.push('<tr><td nowrap><div id="destination_'+i+'" class="'+thisclass+'" onmouseover="if (this.className!=\'dropliston\'&&this.className!=\'droplistghost\'){this.className=\'droplistover\'};if (this.className==\'droplistghost\'){hovershow(this,\''+nodlmsg+'\');}" onmouseout="if (this.className!=\'dropliston\'&&this.className!=\'droplistghost\'){this.className=\'droplistoff\'};if (this.className==\'droplistghost\'){closehovershow()}" onclick="if (this.className==\'droplistover\'){newdestination('+i+','+destinationarray[i].DDID+',\''+destinationarray[i].DestUniqueID+'\')}">'+destinationarray[i].Loc+'</div></td></tr>')

	}
	if (thisguid=="") {
		desthtml.push('<tr><td><div id="destination_'+i+'" class="droplistoff" onmouseover="this.className=\'droplistover\'" onmouseout="this.className=\'droplistoff\'" onclick="adddestination()">Add this computer..</div></td></tr>')
	}
	desthtml.push('</table>')
	dg("destinationdropdownDiv").innerHTML = desthtml.join("")

	if (samei!=-1) {
		newdestination(samei,sameddid,sameuid)
	}
}

function adddestination() {
	dg("installmmDiv").innerHTML = "To download videos to this computer, please install the latest version of CinemaNow's free Media Manager."
	dg("screenblockDiv").style.display="block"
	dg("mmalertDiv").style.display="block"
	doresize()
}

destinationopen = false
currentdestination = -1
downloadtolocal = false
function newdestination(thissort,newDDID,DestUniqueID) {
	try{dg("destination_"+currentdestination).className = "droplistoff"}catch(e){}
	dg("destination_"+thissort).className = "dropliston"
	currentdestination=thissort
	closedestination()
	try{dg("destinationbox").innerHTML = dg("destination_"+thissort).innerHTML}catch(e){}
	currentDDID = newDDID
	setCookie("mm_rq_dest",currentDDID)
	defaultdest = currentDDID
	if (DestUniqueID==thisguid) {downloadtolocal=true} else {downloadtolocal=false}
}

filetypearray=[]
function drawfiletypes() {

	filetypearray=[]
	ftypes=[]
	for (var i=0;i<selectlist_array.length;i++) {
		for (var ix=0;ix<libraryarray.length;ix++) {
			if (libraryarray[ix].Episodes==undefined) {
				if (selectlist_array[i].getAttribute("iteminfo").split("_")[2]==libraryarray[ix].PassID) {
					thistype = String(libraryarray[ix].FileType+",").replace(/\:.*?\,/g,"|")
					thistype=thistype.substr(0,thistype.length-1)
					filetypearray.push(thistype)
					thistypes=thistype.split("|")
					for (var iz=0;iz<thistypes.length;iz++){
						if(ftypes.join(",").indexOf(thistypes[iz])==-1) {
							ftypes.push(thistypes[iz])
						}
					}
				}
			} else {
				for (ixe=0;ixe<libraryarray[ix].Episodes.length;ixe++) {
					if (selectlist_array[i].getAttribute("iteminfo").split("_")[2]==libraryarray[ix].Episodes[ixe].PassID) {
						thistype = String(libraryarray[ix].Episodes[ixe].FileType+",").replace(/\:.*?\,/g,"|")
						thistype=thistype.substr(0,thistype.length-1)
						filetypearray.push(thistype)
						thistypes=thistype.split("|")
						for (var iz=0;iz<thistypes.length;iz++){
							if(ftypes.join(",").indexOf(thistypes[iz])==-1) {
								ftypes.push(thistypes[iz])
							}
						}
					}
				}
			}
		}
	}

	ftypearray = []
	for (var i=0;i<ftypes.length;i++) {ftypearray.push([])}
	for (var i=0;i<filetypearray.length;i++) {
		var thisftypes = filetypearray[i].split("|")
		for(var ix=0;ix<thisftypes.length;ix++) {
			for (var iz=0;iz<ftypes.length;iz++){
				if (thisftypes[ix]==ftypes[iz]) {
					ftypearray[iz].push(thisftypes[ix])
				}
			}
		}
	}

	ftypelist=[]
	for (var i=0;i<ftypearray.length;i++) {
		if (ftypearray[i].length==selectlist_array.length) {
			ftypelist.push(ftypearray[i][0])
		}
	}

	if (ftypelist.length>0) {
		currentfiletype = -1
		ftypehtml=[]
		ftypehtml.push('<table id="filetypeslide" cellpadding="0" cellspacing="0" border="0" class="dropdowntable">')
		for (var i=0;i<ftypelist.length;i++) {
			ftypehtml.push('<tr><td><div id="filetype_'+i+'" class="droplistoff" onclick="newfiletype('+i+')" onmouseover="if (this.className!=\'dropliston\'){this.className=\'droplistover\'}" onmouseout="if (this.className!=\'dropliston\'){this.className=\'droplistoff\'}">'+ftypelist[i]+'</div></td></tr>')
		}
		ftypehtml.push('</table>')
		dg("filetypedropdownDiv").innerHTML = ftypehtml.join("")
		newfiletype(0)
	} else {
		if (selectlist_array.length>0) {
			dg("info_downloadsDiv").innerHTML = ""
			dg("info_status").innerHTML = "Wrong file type selection. Files must have similar filetypes."
			dg("info_status").style.display="block"
		} else {
			dg("info_downloadsDiv").innerHTML = ""
			dg("info_status").innerHTML = ""
			dg("info_status").style.display="none"
			dg("titleInfoDiv").style.display="none"
		}
	}
}

//===========================================================================
function ischild(thisobj,idtype) {if (thisobj.tagName=="INPUT"){return null};do{try{tobj=String(thisobj.id)}catch(e){tobj=""};try{if(tobj.indexOf(idtype)!=-1){break};thisobj=thisobj.offsetParent;}catch(e){break}}while(tobj!="BODY");return thisobj}
//===========================================================================

function domousewheel(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	if (!ischild(objover,"scroller")) {return true}
	try{event.cancelBubble = true;evt.returnValue = false}catch(e){evt.preventDefault()}

	if (dg("scroller").clientHeight<dg("scrollDiv").clientHeight) {return}

	if (browser=="ie"||browser=="safari") {
		var wheelspeed = parseInt(evt.wheelDelta)/10
	} else {
		var wheelspeed = -parseInt(evt.detail)
	}

	var newy = (wheelspeed + parseInt(  gettop(dg("scroller"))-gettop(dg("scrollDiv"))   ))
	if (newy>0) {newy=0}
	if (newy<-dg("scroller").clientHeight+parseInt(dg("scrollDiv").style.height,10)) {newy=-dg("scroller").clientHeight+parseInt(dg("scrollDiv").style.height,10)}
	dg("scroller").style.top = Math.round(newy)+"px"
	scrollerclick(newy)
}

ctrlstate = false
function floatdown(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	if (destinationarray.length==1&&parseFloat(destinationarray[0].Ver.substr(0,3))<1.4) {
		ctrlstate=false
	} else {
		ctrlstate = evt.ctrlKey
	}

	if (!ischild(objover,"scroller")&&!ischild(objover,"statusDiv")&&!ischild(objover,"downloadDiv")) {return true}
	try{event.cancelBubble = true;evt.returnValue = false}catch(e){evt.preventDefault()}
}

objover = ""
movecount = 0
function floatmove(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	objover = evtsrc

	checktimeout()

	if (filetypeopen==true&&(!ischild(evtsrc,"filetypedropdownDiv")&&!ischild(evtsrc,"filetypeDiv")&&!ischild(evtsrc,"filetypebox")&&!ischild(evtsrc,"filetypegadget")&&!ischild(evtsrc,"filetypeselector"))) {
		closefiletype()
	}

	if (destinationopen==true&&(!ischild(evtsrc,"destinationdropdownDiv")&&!ischild(evtsrc,"destinationDiv")&&!ischild(evtsrc,"destinationbox")&&!ischild(evtsrc,"destinationgadget")&&!ischild(evtsrc,"destinationselector"))) {
		closedestination()
	}
}

function checktimeout() {
	movecount++
	if (sleeping==true) {
		sleeping=false;
		sleepcount=0
		dg("timeoutimg").style.display="none";
		statusloop()
	}
}

newscrollheight = 0
function doresize() {
	if (browser=="ie"&&bver<7) {
		dbch = document.documentElement.clientHeight
		dbcw = document.documentElement.clientWidth
	} else {
		dbch = document.body.clientHeight
		dbcw = document.body.clientWidth
	}

	checktimeout()

	closedestination()
	closefiletype()

	blkw = dg("mainmmDiv").offsetWidth
	blkh = dg("mainmmDiv").offsetHeight
	if (browser=="ie"&&bver>6) {blkw+=5}
	dg("screenblockDiv").style.width = blkw+"px"
	dg("screenblockDiv").style.height = blkh+"px"
	dg("screenblockDiv").style.left = getleft(dg("mainmmDiv"))+"px"
	dg("screenblockDiv").style.top = gettop(dg("mainmmDiv"))+"px"

	mainmmDivtop = gettop(dg("mainmmDiv"))

	dg("mmalertDiv").style.left = Math.round((dbcw/2)-(562/2))+"px"
	if (browser=="safari") {
		dg("mmalertDiv").style.top = Math.round((dbch/2)-(314/2)+document.body.scrollTop)+"px"
	} else {
		dg("mmalertDiv").style.top = Math.round((dbch/2)-(314/2)+document.documentElement.scrollTop)+"px"
	}

	dg("mmpopupDiv").style.left = Math.round((dbcw/2)-(363/2))+"px"
	if (browser=="safari") {
		poptop = Math.round((dbch/2)-(194/2)+document.body.scrollTop)
		if (poptop<150) {poptop=160}
		dg("mmpopupDiv").style.top = poptop+"px"
	} else {
		poptop=Math.round((dbch/2)-(194/2)+document.documentElement.scrollTop)
		if (poptop<150) {poptop=160}
		dg("mmpopupDiv").style.top = poptop+"px"
	}

	if (dg("titleInfoDiv").clientHeight+gettop(dg("titleInfoDiv"))>dbch-150) {scroffset=60} else {scroffset=165}
	scroffset=60
	newscrollheight = (dbch-gettop(dg("scrollDiv"))-scroffset)
	if (newscrollheight>dg("scroller").clientHeight) {newscrollheight=dg("scroller").clientHeight;dg("scroller").style.top="0px";}
	if (newscrollheight<250) {newscrollheight=250}

	setTimeout('doresize2('+newscrollheight+')',100)

	if (currenttab=="library") {

		if (dg("scroller").clientHeight<=newscrollheight) {
			dg("scrollbarFloat").style.display="none"
			dg("scrollrace").style.display="none"
		} else {
			try{dg("scrollbarFloat").style.left = (getleft(dg("scrollDiv"))+552)+"px"}catch(e){}
			try{dg("scrollbarFloat").style.top = (gettop(dg("scrollDiv")))+"px"}catch(e){}
			try{dg("scrollbarFloat").setAttribute("dragfx","{'float':true,'xmin':0,'ymin':"+gettop(dg("scrollDiv"))+",'xmax':0,'ymax':"+(newscrollheight+gettop(dg("scrollDiv"))-65-23)+",'report':'scrollbartweak'}")}catch(e){}
			try{dg("scrollbarheight").style.height = (newscrollheight-10-23)+"px"}catch(e){}
			try{dg("scrollrace").style.left = (getleft(dg("scrollDiv"))+552)+"px"}catch(e){}
			try{dg("scrollrace").style.display="block"}catch(e){}
			try{dg("scrollbarFloat").style.display="block"}catch(e){}
			try{dg("scrollrace").style.top = gettop(dg("titlelistDiv"))+"px"}catch(e){}
		}

		try{scrollerclick(gettop(dg("scroller"))-gettop(dg("scrollDiv")))}catch(e){}
	} else {
		dg("scrollbarFloat").style.display="none"
		dg("scrollrace").style.display="none"
	}

}

function doresize2(newscrollheight) {
	dg("scrollDiv").style.height= newscrollheight+'px'
	if (dg("scroller").clientHeight<=dg("scrollDiv").clientHeight) {
		dg("scrollbuttons").style.display="none"
	} else {
		dg("scrollbuttons").style.display="block"
	}

	if ( (gettop(dg("scroller"))+dg("scroller").clientHeight) < ( gettop(dg("listbottom"))) && (dg("scroller").clientHeight > dg("scrollDiv").clientHeight)    ) {
		dg("scroller").style.top = (gettop(dg("listbottom"))-dg("scroller").clientHeight-gettop(dg("scrollDiv")))+"px"
		scrollerclick(gettop(dg("scroller"))-gettop(dg("scrollDiv")))
	}
	try{dg("scrollbarFloat").style.left = (getleft(dg("scrollDiv"))+552)+"px"}catch(e){}
	try{dg("scrollrace").style.left = (getleft(dg("scrollDiv"))+552)+"px"}catch(e){}

}

function scrolltop() {
	fx("scroller",20,fx_slidein,null,"top,"+parseInt(dg("scroller").style.top,10)+",0,scrollerclick")
}

function scrollup() {
	scrollertop = gettop(dg("scrollDiv"))
	listitems = dg("scrollhead").childNodes

	listitem = ""
	for (var i=0;i<listitems.length;i++) {
		if (listitems[i].innerHTML.indexOf("select individual")!=-1) {continue}
		if (listitems[i].style.display=="none") {continue}
		if ((gettop(listitems[i])-scrollertop)<0) {
			listitem = listitems[i]
		}
		if ((gettop(listitems[i])-scrollertop)>=0) {
			break
		}
	}

	if (listitem!="") {
		newtop = (gettop(listitem)-scrollertop)
		if (newtop>-8) {dg("scroller").style.top=(parseInt(dg("scroller").style.top,10)-newtop)+"px";scrollup();return}
		fx("scroller",10,fx_slidein,null,"top,"+parseInt(dg("scroller").style.top,10)+","+(parseInt(dg("scroller").style.top,10)-newtop)+",scrollerclick")
	}
}

function scrolldown() {
	scrollertop = gettop(dg("scrollDiv"))
	listitems = dg("scrollhead").childNodes

	listitem = ""
	for (var i=0;i<listitems.length;i++) {
		if (listitems[i].innerHTML.indexOf("select individual")!=-1) {continue}
		if (listitems[i].style.display=="none") {continue}

		try{
			if (listitems[i+1].innerHTML.indexOf("select individual")!=-1) {
				if ( (gettop(listitems[i+1])+listitems[i+1].clientHeight-scrollertop)>dg("scrollDiv").clientHeight) {
					listitem = listitems[i+1];break
				}
			}
		}catch(e){}

		if ( (gettop(listitems[i])+listitems[i].clientHeight-scrollertop)>dg("scrollDiv").clientHeight) {
			listitem = listitems[i];break
		}
	}

	if (listitem!="") {
		newtop = dg("scrollDiv").clientHeight - (gettop(listitem)-scrollertop) - listitem.clientHeight
		if (newtop>-8) {dg("scroller").style.top = (parseInt(dg("scroller").style.top,10)+newtop)+"px";scrolldown();return;}
		fx("scroller",10,fx_slidein,null,"top,"+parseInt(dg("scroller").style.top,10)+","+(parseInt(dg("scroller").style.top,10)+newtop)+",scrollerclick")

	}
}

function scrollbottom() {
	dg("scroller").style.borderBottom="1px solid transparent"//firefox voodoo - scroller will be wrong clientheight unless we alter it with borderbottom ??huh??
	fx("scroller",20,fx_slidein,null,"top,"+parseInt(dg("scroller").style.top,10)+","+(-dg("scroller").clientHeight+dg("scrollDiv").clientHeight)+",scrollerclick")
}

function scrollbartweak(x,y) {
	if (y==undefined){y=x}
	try{
		topy = y-gettop(dg("scrollDiv"))
		maxsy = (newscrollheight)
		newtopy = Math.round(((dg("scroller").clientHeight-newscrollheight)/(newscrollheight-65-23))*topy)
		dg("scroller").style.top = (-newtopy)+"px"
	}catch(e){}
}

function scrollerclick(scrollval) {
	try{
		newbartop = Math.round(((newscrollheight-65-23)/(dg("scroller").clientHeight-newscrollheight))*-scrollval)+gettop(dg("scrollDiv"))
		dg("scrollbarFloat").style.top = (newbartop)+"px"
	}catch(e){}
}

function raceclick(evt) {
	try{evtsrc=event.srcElement;evt=event}catch(e){evtsrc=evt.target}
	rmousey = (evt.clientY||evt.y);

	gadgettop = gettop(dg("scrollbarFloat"))

	if (rmousey<gadgettop) {
		fx("scrollbarFloat",10,fx_slidein,null,"top,"+gadgettop+","+rmousey+",scrollbartweak")
	}

	if (rmousey>gadgettop+65) {
		if (rmousey>(gettop(dg("scrollbarheight"))+dg("scrollbarheight").offsetHeight-65)) {rmousey=(gettop(dg("scrollbarheight"))+dg("scrollbarheight").offsetHeight-65)}
		fx("scrollbarFloat",10,fx_slidein,null,"top,"+gadgettop+","+rmousey+",scrollbartweak")
	}

}

//===========================================================================

function assigndownloads() {
	if (currentDDID == -1) {alertbox("Please select a download destination");return}
	if (currentfiletype == -1) {alertbox("Please select a File Type to download");return}

	thisdltype = dg("filetypebox").innerHTML

	var errmsg = []
	var dlskus = []

	//de-duplicate downloads (only get one if there are similar SKUs for download)
	for (var i=0;i<selectlist_array.length;i++) {
		for (var ix=0;ix<libraryarray.length;ix++) {
			if (libraryarray[ix].Episodes==undefined) {
				if (selectlist_array[i].getAttribute("iteminfo").split("_")[2]==libraryarray[ix].PassID) {
					var thisftypes = libraryarray[ix].FileType.split(",")
					for (var ixx=0;ixx<thisftypes.length;ixx++) {
						if (thisftypes[ixx].split(":")[0]==thisdltype) {
							if (dlskus.join(",").indexOf(thisftypes[ixx].split(":")[1])==-1) {
								dlskus.push(thisftypes[ixx].split(":")[1]+"|"+String(libraryarray[ix].PassID))
							}
						}
					}
				}
			} else {
				for (ixe=0;ixe<libraryarray[ix].Episodes.length;ixe++) {
					if (selectlist_array[i].getAttribute("iteminfo").split("_")[2]==libraryarray[ix].Episodes[ixe].PassID) {
						var thisftypes = libraryarray[ix].Episodes[ixe].FileType.split(",")
						for (var ixx=0;ixx<thisftypes.length;ixx++) {
							if (thisftypes[ixx].split(":")[0]==thisdltype) {
								if (dlskus.join(",").indexOf(thisftypes[ixx].split(":")[1])==-1) {
									dlskus.push(thisftypes[ixx].split(":")[1]+"|"+String(libraryarray[ix].Episodes[ixe].PassID))
								}
							}
						}
					}
				}
			}
		}
	}

	for (var i=dlskus.length-1;i>-1;i--) {
		var thisobj = getobjfromPassID(dlskus[i].split("|")[1])
		if (thisobj.LicCount<thisobj.LicAvailable) {continue}
		errmsg.push('You currently do not have enough licenses to add "'+thisobj.Name+'" to your queue.<br/>')
		dlskus.splice(i,1)
	}

	for (var i=dlskus.length-1;i>-1;i--) {
		for (var il=0;il<libraryarray.length;il++) {
			if (dlskus.length==0||dlskus[i]==undefined) {break}
			if (libraryarray[il].Episodes==undefined) {
				if (libraryarray[il].PassID==dlskus[i].split("|")[1]) {
					var thisDDIDSarr = libraryarray[il].DDIDS.split(",")
					for (var ild=0;ild<thisDDIDSarr.length;ild++) {
						if (thisDDIDSarr[ild].split("|")[2]==currentDDID&&thisDDIDSarr[ild].split("|")[1]==dlskus[i].split("|")[0]) {
							if (thisDDIDSarr[ild].split("|")[0]!=-1) {
								var rstat = libraryarray[il].Status[thisDDIDSarr[ild].split("|")[0]]
								if (rstat!=5&&rstat!=-1&&rstat!=""&&rstat!=1) {
									errmsg.push('Did not assign "'+getobjfromPassID(dlskus[i].split("|")[1]).Name+'" for download because it is already assigned to this destination.<br/>')
									dlskus.splice(i,1)
									break
								}
							}
						}
					}
				}
			} else {
				for (var ei=0;ei<libraryarray[il].Episodes.length;ei++) {
					if (dlskus.length==0||dlskus[i]==undefined) {break}
					if (libraryarray[il].Episodes[ei].PassID==dlskus[i].split("|")[1]) {
						var thisDDIDSarr = libraryarray[il].Episodes[ei].DDIDS.split(",")
						for (var ild=0;ild<thisDDIDSarr.length;ild++) {
							if (thisDDIDSarr[ild].split("|")[2]==currentDDID&&thisDDIDSarr[ild].split("|")[2]==dlskus[i].split("|")[0]) {
								if (thisDDIDSarr[ild].split("|")[0]!=-1) {
									var rstat = libraryarray[il].Episodes[ei].Status[thisDDIDSarr[ild].split("|")[0]]
									if (rstat!=5&&rstat!=-1&&rstat!=""&&rstat!=1) {
										errmsg.push('Did not assign "'+getobjfromPassID(dlskus[i].split("|")[1]).Name+'" for download because it is already assigned to this destination.<br/>')
										dlskus.splice(i,1)
										break
									}
								}
							}
						}
					}
				}
			}
		}
	}

	if (errmsg.length>0) {
		dg("info_status").innerHTML = errmsg.join("<br/>")
		dg("info_status").style.display="block"
	} else {
		dg("info_status").innerHTML = ""
		dg("info_status").style.display="none"
	}

	if (dlskus.length>0) {
		if (parseFloat(getDestinationByDDID(currentDDID).Ver.substr(0,3))>1.3) {
			for (var i=dlskus.length-1;i>-1;i--) { // reverse order to fix the order from previous loops
				ajl(webservices+"remoteq.asmx/AssignPassToDest",assignpass_callback,'UserID='+userID+"&PassID="+dlskus[i].split("|")[1]+"&DDID="+currentDDID+"&SKUID="+dlskus[i].split("|")[0],ajaxerror,true);
			}
			setTimeout('ajl(webservices+"remoteq.asmx/StatusRequest",status_callback,"userID="+userID,ajaxerror,true)',1000)
		} else {
			_mm_appid = getDestinationByDDID(currentDDID).DestUniqueID
			_mm_skuid = dlskus[0].split("|")[0]
			mmDoAction("downloadLegacy", dlskus[0].split("|")[1])
		}

		dg("downloadbuttonimg").src="img/mmgr/button_download_ghost.gif"
		setTimeout('ajl(webservices+"remoteq.asmx/StatusRequest",status_callback_download,"userID="+userID,ajaxerror,true)',2000)
		alertbox("Items were added to your Video Queue")
		fx("titleInfoDiv",8,fx_slideout,null,"opacity,100,0")
	}
}

function assignpass_callback(thisxml,thistxt,thishead) {
	if (downloadtolocal==true) {
		mmctrl.GetNewDownloads() //in mediamanager.js include file
		setTimeout("mmctrl.GetNewDownloads()",5000) // call it twice, just in case
	}
}

function status_callback_download(statdlxml) {
	status_callback(statdlxml)
	dg("infoboximgDiv").innerHTML = '<img id="infoboximg" src="'+protocol+'://www.cinemanow.com/img/spacer.gif" border="0"/>'
	dg("infoboxmirrorfade").style.backgroundImage='url('+protocol+'://www.cinemanow.com/img/spacer.gif)'
	dg("titleInfoDiv").style.display="none"
	setopacity("titleInfoDiv",100)

	selectlist_array=[]
	drawqueue(libraryarray)

	nextdqid=""
	for (var i=0;i<libraryarray.length;i++) {
		if (libraryarray[i].Episodes==undefined) {
			nDDIDSarr=libraryarray[i].DDIDS.split(",")
			for (var nids=0;nids<nDDIDSarr.length;nids++) {
				if (libraryarray[i].Status[nDDIDSarr[nids].split("|")[0]]==1) {
					nextdqid = nDDIDSarr[nids].split("|")[0]
				}
			}
			if (nextdqid!="") {break}
		} else {
			for (var ei=0;ei<libraryarray[i].Episodes.length;ei++) {
				nDDIDSarr=libraryarray[i].Episodes[ei].DDIDS.split(",")
				for (var nids=0;nids<nDDIDSarr.length;nids++) {
					if (libraryarray[i].Episodes[ei].Status[nDDIDSarr[nids].split("|")[0]]==1) {
						nextdqid = nDDIDSarr[nids].split("|")[0]
						break
					}
				}
			}
			if (nextdqid!="") {break}
		}
	}

	getqdom=dg("statusDiv").getElementsByTagName("TR")
	for (var domi=0;domi<getqdom.length;domi++) {
		if (String(getqdom[domi].getAttribute("iteminfo"))=="null") {continue}
		if (getqdom[domi].getAttribute("iteminfo").split("_")[1]==nextdqid) {
			getqdom[domi].onclick()
			break
		}
	}
}

function nullfunc() {}

function alertbox(thistext) {
	dg("standardtextDiv").innerHTML = thistext
	dg("mmpopupDiv").style.display="block"
}

//===========================================================================
//events
try{window.addEventListener("resize", doresize, false);}catch(e){document.body.onresize = doresize}
try{window.addEventListener("DOMMouseScroll", domousewheel, false) }catch(e){document.attachEvent("onmousewheel",domousewheel)}


function fx_drag_down_chain(evt) {
	floatdown(evt)
}

function fx_drag_move_chain(evt) {
	floatmove(evt)
}

function fx_drag_up_chain(evt) {
}

//===========================================================================

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(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;
}

//===========================================================================
