//-----------------------------------------------------------------------------------------
// AJAX OBJECT & HTML ARRAY
//-----------------------------------------------------------------------------------------

var req = new empireAJAX();
var _html = new Array();

//-----------------------------------------------------------------------------------------
// PARSE XML
//-----------------------------------------------------------------------------------------

function parseXML(){
	
	var _xml = new REXML(req.getResponseText());		
	
	var l_html = '';
						
	// Create the html and store it in the array - store the item elements				
	if ( _xml.rootElement.name == 'tab' ){		
	
		// ---- AUDIO ----		
		if ( site == 43 | site == 12 )
		{
			// ---- Open the Container Table ----
			l_html = l_html + '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="border-left:#D7DDE7 1px solid;border-right:#D7DDE7 1px solid;border-bottom:#D7DDE7 1px solid;padding-top:10px;padding-bottom:12px;padding-left:7px;padding-right:7px;background-color:#FFFFFF">';
				
			// ---- Open the 1st Table ----
			l_html = l_html + '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>';
		
			// ---- Open the 2nd Table ----
			l_html = l_html + '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>';
		
			// ---- Open the Item Table ----
			l_html = l_html + '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
							
			// ---- Set the Loop Counter ----				
			var _cnt = 0;			
					
			// ---- Loop through and get the item elements ----
			for (j = 0; j < _xml.rootElement.childElements.length; j++){
				
				if (_xml.rootElement.childElements[j].name == 'item'){				
							
					// ---- Increment the Loop Counter ---
					_cnt = _cnt + 1;
					
					// ---- Open the 1st row ----		
					if ( _cnt == 1 || _cnt == 2 || _cnt == 3 ){
						l_html = l_html + '<tr>';
					}
								
					// ---- Open the Column ----
					l_html = l_html + '<td width="33%" valign="top" align="center" class="fontsmall2">';
						
					// ---- Item: Image ----
					l_html = l_html + '<a href="/Exec/v4_item.asp?userid=' + userid + '&site_id=' + site + '&item_id=' + _xml.rootElement.childElements[j].childElement("item_id").text + '">';
					
					// ---- Large Image ----				
					if ( _cnt == 1 || _cnt == 2 ){											
						l_html = l_html + '<img src="http://images.dvdempire.com/gen/movies/' + _xml.rootElement.childElements[j].childElement("item_id").text + '.jpg" border="0" hspace="5" vspace="2" align="center"></a>';
					}
					// ---- Small Image ----
					else {																	
						l_html = l_html + '<img width="75" height="75" src="http://images.dvdempire.com/gen/movies' + _xml.rootElement.childElements[j].childElement("item_image").text + '" border="0" hspace="5" vspace="2" align="center"></a>';
					}	
														
					if ( _cnt == 1 || _cnt == 2 ) {
						l_html = l_html + '</td></tr>';	
						l_html = l_html + '<tr><td class="fontsmall2" align="center">';	
					}
					else {
						l_html = l_html + '<br />';
					}							
											
					// ---- Item: Title ----			
					l_html = l_html + '<a href="/Exec/v4_item.asp?userid=' + userid + '&item_id=' + _xml.rootElement.childElements[j].childElement("item_id").text + '">';
					l_html = l_html + _xml.rootElement.childElements[j].childElement("item_title").text + '</a><br />';
						
					// --- Item: Price ----
					l_html = l_html + '<font color="#C02020" class="fontsmall1"><b>$' + _xml.rootElement.childElements[j].childElement("item_price").text + '</b></font>';
						
					// ---- Buy Button ----
					l_html = l_html + '<a href="/Exec/v4_item.asp?userid=' + userid + '&item_id=' + _xml.rootElement.childElements[j].childElement("item_id").text + '">';
					l_html = l_html + '<img src="http://images.dvdempire.com/gen/pm/de_buy004_20051110.gif" alt="Buy" width="40" height="12" border="0" align="absmiddle" vspace="2" hspace="5"></a>';
						
					if ( _cnt == 1){
						l_html = l_html + '</td></tr>';	
						l_html = l_html + '<tr><td>&nbsp;</td></tr>';	
					}					
					if ( _cnt == 2){
						l_html = l_html + '</td></tr></table></td></tr></table></td>';
						l_html = l_html + '<td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>';
						l_html = l_html + '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
					}									
					if ( _cnt == 3 || _cnt == 5 || _cnt == 7){
						l_html = l_html + '</td>';
					}			
					if ( _cnt == 4 || _cnt == 6 ){
						l_html = l_html + '</tr><tr><td colspan="3">&nbsp;</td></tr>';
					}		
					if ( _cnt == 8 ){
						l_html = l_html + '</tr></table></td></tr></table></td></tr></table>';
					}									
				}
			}	
		}		
		// ---- VIDEO and GAMES ---- 				
		else if ( site == 4 | site == 2 | site == 58 ) 
		{				
			// ---- Open the Container Table ----
			l_html = l_html + '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="border-left:#D7DDE7 1px solid;border-right:#D7DDE7 1px solid;border-bottom:#D7DDE7 1px solid;padding-top:10px;padding-bottom:12px;padding-left:7px;padding-right:7px;background-color:#ffffff">';
					
			// ---- Open the Item Table ----
			l_html = l_html + '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
												
			// ---- Open Row ----		
			l_html = l_html + '<tr>';				
					
			// ---- Set the Loop Counter ----				
			var _cnt = 0;			
				
			// ---- Loop through and get the item elements ----
			for (j = 0; j < _xml.rootElement.childElements.length; j++){
				
				if (_xml.rootElement.childElements[j].name == 'item'){				
							
					// ---- Increment the Loop Counter ---
					_cnt = _cnt + 1;					
					
					// ---- Open the Column ----
					l_html = l_html + '<td width="33%" valign="top" align="center" class="fontsmall2">';
					
					// ---- Item: Image ---					
					l_html = l_html + '<a href="/Exec/v4_item.asp?userid=' + userid + '&site_id=' + site + '&item_id=' + _xml.rootElement.childElements[j].childElement("item_id").text + '">';
					l_html = l_html + '<img src="http://images.dvdempire.com/gen/movies' + _xml.rootElement.childElements[j].childElement("item_image").text + '" hspace="5" vspace="2" align="center" border="0"></a><br />';
									
					// ---- Item: Title ----			
					l_html = l_html + '<a href="/Exec/v4_item.asp?userid=' + userid + '&item_id=' + _xml.rootElement.childElements[j].childElement("item_id").text + '">';
					l_html = l_html + _xml.rootElement.childElements[j].childElement("item_title").text + '</a><br />';
							
					// --- Item: Price ----
					l_html = l_html + '<font color="#C02020" class="fontsmall1"><b>$' + _xml.rootElement.childElements[j].childElement("item_price").text + '</b></font>';
					
					// ---- Item: Buy Button ----
					if ( tab == 0 | tab == 1 ){
						l_html = l_html + '<a href="/Exec/v4_item.asp?userid=' + userid + '&item_id=' + _xml.rootElement.childElements[j].childElement("item_id").text + '">';
						l_html = l_html + '<img src="http://images.dvdempire.com/gen/pm/de_buy004_20051110.gif" alt="Buy" width="40" height="12" border="0" align="absmiddle" vspace="2" hspace="5"></a>';
					}
					// ---- Item: Pre-order Button ----
					else{
						l_html = l_html + '<a href="/Exec/v4_item.asp?userid=' + userid + '&item_id=' + _xml.rootElement.childElements[j].childElement("item_id").text + '">';
						l_html = l_html + '<img src="http://images.dvdempire.com/gen/pm/de_preoder004_20051110.gif" alt="Pre-Order" width="60" height="12" border="0" align="absmiddle" vspace="2" hspace="5"></a>';
					}
					
					// ---- Close the Column ----
					l_html = l_html + '</td>';		
				
					if ( site == 4 ){
						// ---- Close 1st Row, Add a Blank Row, and Open 2nd Row ----			
						if ( _cnt == 3 ){
							l_html = l_html + '</tr><tr><td colspan="3">&nbsp;</td><tr>';
							l_html = l_html + '<tr>';
						}			
						// ---- Close 2nd Row ----			
						if ( _cnt == 6 ){
							l_html = l_html + '</tr>';
						}	
					}
					else if ( site == 58 | site == 2 ){				
						if ( _cnt == 3 ) {
							//---- Close the 1st row of items ----	
							l_html = l_html + '</tr>';			
							//---- Open and Close blank row ----
							l_html = l_html + '<tr><td colspan="3">&nbsp;</td></tr>';	
							//---- Open the 2nd row of items  ----	
							l_html = l_html + '<tr>';					
						}				
						if ( _cnt == 6 ) {		
							//---- Close the 2nd row of items ----
							l_html = l_html + '</tr>';	
							//---- Open and Close blank row ----
							l_html = l_html + '<tr><td colspan="3">&nbsp;</td></tr>';
							//---- Open the 3rd row of items  ----	
							l_html = l_html + '<tr>';	
						}
						if ( _cnt == 9 ) {
							//---- Close the 3rd row of items ----		
							l_html = l_html + '</tr>';	
						}				
					}					
				}			
			}	
			// ---- Close the item table ----						
			l_html = l_html + '</table>';									
		}	

		// ---- Open the Time & "Complete List" table ----
		l_html = l_html + '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
				
		// ---- Get the Complete List link ----
		if (_xml.rootElement.childElement("tab_path").text != ''){				
			l_html = l_html + '<td width="100%" align="right" class="fontsmall3" style="color:#5A6571;padding-right:10px;padding-top:19px;"><b>' + dateStamp + '</b></td>';
			l_html = l_html + '<td align="right" style="padding-right:5px;padding-top:17px;">';
			l_html = l_html + '<a href="' + _xml.rootElement.childElement("tab_path").text + '?userid=' + userid;
			if (_xml.rootElement.childElement("tab_param").text != ''){
				l_html = l_html + '&' + _xml.rootElement.childElement("tab_param").text.replace('*','&');
			}
			l_html = l_html + '"><b><img src="http://images.dvdempire.com/gen/pm/de_completelist_20051110.gif" alt="Complete List" width="103" height="18" border="0" align="absmiddle" vspace="0" hspace="0"></b></a></td></tr>';
		 }		
		// ---- Close the inner table ----
		l_html = l_html + '</table>';	
				
		// ---- Close the outer table ----
		l_html = l_html + '</td></tr></table><br />';				
	}
		
	// ---- Add to the array of html ----
	if (l_html != ''){		
		_html.length = _html.length + 1;
		_html[_html.length - 1] = l_html;
	}
			
	// ---- Get the first tab load ----
	if (_html.length >= 1){
		drawTabContent();	
	}
}
//-----------------------------------------------------------------------------------------
// DRAW TAB CONTENT
//-----------------------------------------------------------------------------------------

function drawTabContent(){
	
	var tempLayer;
	var l_html = '';
	
	if (_html.length >= 1){
		l_html = _html[_html.length - 1];
	}
	
	// ---- Write out the HTML ----
	if (document.layers) {
		// ---- NN4 ----
		tempLayer = document.layers["tabContent"];
		if (tempLayer != null && l_html != ''){
			tempLayer.document.open();
			tempLayer.document.write(l_html);
			tempLayer.document.close();
		}
	}
	if (document.all) {
		// ---- IE5 ----
		tempLayer = document.all["tabContent"];
		if (tempLayer != null && l_html != ''){
			tempLayer.innerHTML = l_html;
		}
	}
	if(!document.all && document.getElementById){
		// ---- NN6 ----
		tempLayer = document.getElementById("tabContent");
		if (tempLayer != null && l_html != ''){
			tempLayer.innerHTML = l_html;
		}
	}
}
//-----------------------------------------------------------------------------------------
// GET TAB CONTENT
//-----------------------------------------------------------------------------------------

function getTabContent(tabNum){	
	
	req.reset();	
	if ( tab == 0 ){
		req.setURL('/Include/xmlGenFly_RR.asp');
	}
	else if ( tab == 1 ){
		req.setURL('/Include/xmlGenFly_CB.asp');
	}
	else if ( tab == 2 ){
		req.setURL('/Include/xmlGenFly_BP.asp');
	}
	req.addParameter('site_media_id',media);
	req.addParameter('site_id',site);	
	req.setMethod('get');
	req.setAsynch(false);
	req.cacheResponse(false);
	req.setCallback(parseXML);
	sent = req.send();
}
//-----------------------------------------------------------------------------------------

