function dn_VideoByCode(itemCode, menuType, mainID, subID, archTitleC)
{
	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-video.php?video="+itemCode+"&archType=videos&archive="+archTitleC;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, url ,itemCode, menuType, mainID, subID);};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);

	return false;
}

function dn_MenuItemByCode(itemCode, menuType, mainID, subID, stageLg)
{
	if(!WSD_AJAX) return true;

	//if(menuType == "main" && displayMenuIndex == menuID) return false;
	if(menuType == "sub" && displaysubMenuIndex == subID) return false;

	if(menuType == "main")
		var qAddon = "?page="+itemCode;
	else
		var qAddon = "?pageSub="+itemCode;

	var url = WSD_WEBROOT+"dn-menu.php"+qAddon;
		
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, url ,itemCode, menuType, mainID, subID, stageLg);};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);

	return false;
}

function dn_MenuItemByType(itemCode, menuType, mainID, subID, pageNum, langCode)
{
	if(!WSD_AJAX)
	{
		return true;
	}

	if(menuType == "main")
		var qAddon = "?type="+itemCode;
	else
		var qAddon = "?typeSub="+itemCode;

	var url = WSD_WEBROOT+"dn-menu.php"+qAddon+"&pageNum="+pageNum+"&lang_code="+((langCode) ? langCode : LANG_CODE);

	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, url ,itemCode, menuType, mainID, subID);};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);

	return false;
}

function dn_ImageCategoryByCode(itemCode, menuType, mainID, subID)
{
	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-img-cat.php?imgCat="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, url ,itemCode, menuType, mainID, subID);};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);

	return false;
}

function dn_ArchiveByCode(itemCode, menuType, mainID, subID, archType, archPage)
{
	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-archive.php?archive="+itemCode+"&archType="+archType+"&pageNum="+archPage;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, url ,itemCode, menuType, mainID, subID);};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);

	return false;
}

function dn_NewsByCode(itemCode, menuType, mainID, subID)
{
	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-news.php?news="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, url ,itemCode, menuType, mainID, subID);};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);

	return false;
}

function dn_DJByCode(itemCode, menuType, mainID, subID, stageLg)
{
	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-dj.php?dj="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, url , itemCode, menuType, mainID, subID, stageLg);};
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);

	return false;
}

function dn_NewsletterByTitleC( itemCode, target )
{
	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-newsletter.php?newsletter="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateNewsletter(xmlHttp , target );};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	
	return false;
}

function updateNewsletter(xmlHttp, target )
{
	if(xmlHttp.readyState == 4)
	{
        if(xmlHttp.status == 200)
		{
			var t = document.getElementById( target );
			
			t.innerHTML = xmlHttp.responseText;
		}
	}
}


function updateMenuRequest(xmlHttp, url , itemCode, menuType, menuID, subID, stageLg , otherTop )
{
    if(xmlHttp.readyState == 4)
	{
        if(xmlHttp.status == 200)
		{
			//set_page();

			var responseStatus = xmlHttp.responseText;

			var menuContent = responseStatus;	// Content

			var dnContent = E('dnContent');

			dnContent.innerHTML = menuContent;

			if(menuID)
			{
				if(menuType == "main")
					var global_currentID = displayMenuIndex;
				else
					var global_currentID = displaysubMenuIndex;

				// only switch images if enabled:
				if(WSD_FIMG)
				{
					/* REMOVE */ 

					// remove old sub button
					if(E('subMenu_'+displaysubMenuIndex+'_n') && E('subMenu_'+displaysubMenuIndex+'_h'))
					{
						E('subMenu_'+displaysubMenuIndex+'_h').style.display = 'none';
						E('subMenu_'+displaysubMenuIndex+'_n').style.display = 'block';
					}

					// remove old main button
					if(E('mainMenu_'+displayMenuIndex+'_n') && E('mainMenu_'+displayMenuIndex+'_h'))
					{
						E('mainMenu_'+displayMenuIndex+'_h').style.display = 'none';
						E('mainMenu_'+displayMenuIndex+'_n').style.display = 'block';

						/*E('mainMenu_'+displayMenuIndex+'_td').style.backgroundImage = 'none';*/
						
						// remove submenu holder:
						if(E('submenuHolder_'+displayMenuIndex))
							E('submenuHolder_'+displayMenuIndex).style.displayMenuIndex = 'none';
					}


					/* DISPLAY */

					// display new main button
					if(E('mainMenu_'+menuID+'_h') && E('mainMenu_'+menuID+'_n'))
					{
						E('mainMenu_'+menuID+'_h').style.display = 'block';
						E('mainMenu_'+menuID+'_n').style.display = 'none';

						/*E('mainMenu_'+menuID+'_td').style.backgroundImage = 'url('+WSD_WEBROOT+'images/menu-selected.png)';*/

					}

					// display new sub button
					if(E('subMenu_'+subID+'_h') && E('subMenu_'+subID+'_n'))
					{
						E('subMenu_'+subID+'_h').style.display = 'block';
						E('subMenu_'+subID+'_n').style.display = 'none';
					}

					// reset submenu
					if(menuType == "main")
					{
						// reset submenu
						displaysubMenuIndex = 0;
					}
				}

				// set new display index:
				if(menuType == "main")
					displayMenuIndex = menuID;
				else
				{
					displayMenuIndex = menuID;
					displaysubMenuIndex = subID;
				}
			}

			if( url )
			{
				if( url != document.lastUrl )
				{
					document.lastUrl = url;
				
					E( 'navigator' ).contentWindow.location = 'navigator.php?url=' + escape( url )
										+'&itemCode='+escape(itemCode)+'&menuType='+escape(menuType)+'&mainID='+escape(menuID)+'&subID='+escape(subID)+'&otherTop='+otherTop+'&stageLg='+stageLg;
				}
			}
			
			var istart = menuContent.indexOf('<!--TITLE:');
			var iend = menuContent.indexOf('-->' , istart );
			
			if( istart >= 0 )
			{
				document.title = menuContent.substr( istart + 10  , iend - istart - 12 );
			}
			
			if(stageLg)
			{
				s_currentTab = stageLg;
			}

			if( ! otherTop ) scroll(0,0);
			else 
			{
				var el= document.getElementsByName(otherTop);
				if( el.length ) scroll(0,el[0].offsetTop );
			}
			
		}
	}
}

function navigateBack( url , itemCode, menuType, mainID, subID , stageLg , otherTop )
{
	if( url != document.lastUrl )
	{
		if( url )
		{
			var xmlHttp = createXMLHttpRequest();
			xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, url , itemCode, menuType, mainID, subID , stageLg , otherTop );};
			
			
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		}
	}
}

function playMovie( f )
{
	var p = document.getElementById('player');
	
	try
	{
		p.playVideo( f );
	}
	catch( e )
	{
		p.getElementsByTagName( 'embed' )[0].playVideo( f );
		
	}
	
	return false;
}



