var myDiv;
var divHtml;

//This function is used when there is no drop down list, ie admin2/Secured/NewsManagerList.aspx or Facts.aspx
function popMap(mypage) {
	var W = 600;
	var H = 495;
	var winl = (screen.width - W) / 2;
	var wint = (screen.height - H) / 2;
	win = window.open(mypage, 'map', 'height='+H+',width='+W+',top='+wint+',left='+winl)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return false;
}

function popMapDDL(language) {
	var W = 600;
	var H = 495;
	//The Maps.ascx adds "Maps_" to the DDLs ID automatically, turning "MapsCity" into "Maps_MapsCity"
	var selLocation=document.forms[0].Maps_MapCity.selectedIndex;
	var selMap=document.forms[0].Maps_MapTheme.selectedIndex;
	var location_value=document.forms[0].Maps_MapCity.options[selLocation].value;
	var map_value=document.forms[0].Maps_MapTheme.options[selMap].value;
	var url = "http://www.undp.org.cd.ws017.alentus.com/maps/map.html?fr="+ language +"&location=" + location_value + "&map=" + map_value;
	var winl = (screen.width - W) / 2;
	var wint = (screen.height - H) / 2;
	win = window.open(url, 'map', 'height='+H+',width='+W+',top='+wint+',left='+winl)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return false;
}

// This is to detect which kind of movie
function popVideo(url) {
	if(url.substring(url.length-3,url.length) == "flv")
		popFlashVideo(url);
	else
		popEmbedVideo(url);
}


// This one is used for the wmv and mov files
function popEmbedVideo(url) {
	url = url.indexOf("index.html") == 0 ? url.substring(1,url.length) : url;
	var myDiv = document.getElementById("divPopup");
	myDiv.className = "popVideo";
	divHtml = 	"<div id='divHandle' style='cursor: move;'><table width=100% bgcolor=Black cellpadding=0 cellspacing=0 border=0>";
	divHtml +=		"<tr><td align=left height=25>" + "" + "</td><td align=right valign=middle><a href='javascript:closePopup(\"divPopup\");;' style='margin:0 5 0 0'><img src='/Images/core/closeLight.gif' border=0 /></a></td></tr>";
	divHtml +=		"</table></div>";
	divHtml +=		"<div id='divHeaderLine'>&nbsp;</div>";
	divHtml +=		"<table width=100% bgcolor=Black cellpadding=0 cellspacing=0 border=0><tr><td align=center><embed src=\"" + url + "\" width=340 height=300 align=middle border=0 bgcolor=#000000 ShowControls=1 ShowStatusBar=0 ShowDisplay=0 autostart=1></embed></td></tr></table>";
	divHtml +=		"<div align=\"right\" style=\"margin:3 5 3 3;\">" + "" + "</div>";
	myDiv.innerHTML = divHtml;
	updateProperties(myDiv, 185);
}

// This is used for the flash movies
function popFlashVideo(url) {
	url = url.indexOf("index.html") == 0 ? url.substring(1,url.length) : url;
	var myDiv = document.getElementById("divPopup");
	myDiv.className = "popVideo";
	divHtml = 	"<div id='divHandle' style='cursor: move;'><table width=100% bgcolor=003399 cellpadding=0 cellspacing=0 border=0>";
	divHtml +=		"<tr><td align=left height=25>" + "" + "</td><td align=right valign=middle><a href='javascript:closePopup(\"divPopup\");;' style='margin:0 5 0 0'><img src='/Images/core/closeLight.gif' border=0 /></a></td></tr>";
	divHtml +=		"</table></div>";
	divHtml +=		"<div id='divHeaderLine'>&nbsp;</div>";
	divHtml +=		"<table width=100% bgcolor=003399 cellpadding=0 cellspacing=0 border=0><tr><td align=center>";
	divHtml +=		"<div id='player'>";
	divHtml +=		"<a href=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW\" target=\"_blank\">";
	divHtml +=		"<img src='/images/core/flash_install_" + language + ".gif' class=photoVideo />";
	divHtml +=		"</a></div>";
	divHtml +=		"</td></tr></table>";
	divHtml +=		"<div id='divHeaderLine'>&nbsp;</div><table width=100% bgcolor=003399 cellpadding=0 cellspacing=0 border=0><tr><td height=25>&nbsp;</td></tr></table>";
	myDiv.innerHTML = divHtml;
	var FO = { 	movie:"/video/player-viral.swf", 
				width:"400", 
				height:"220", 
				majorversion:"7", 
				build:"0", 
				bgcolor:"#FFFFFF",
				flashvars:"file=/"+url+"&autoStart=true" };
	UFO.create(FO, 'player');
	updateProperties(myDiv, 185);
}

var windowAlreadyOpened = 0;
function popImageFromList(id) {
	id = ((parseInt(page)-1)*parseInt(nbRowPerPage) + parseInt(id)) - 1;
	item = _listItem[id];
	slideId = id;
	myDiv = document.getElementById("divPopup");
	myDiv.className = "popImage";
	divHtml =	"<div id='divHandle' style='cursor: move;'><table width=100% bgcolor=#003399 cellpadding=0 cellspacing=0 border=0>";
	divHtml +=		"<tr><td align=left height=25><div id=divSlideShowTitle style='margin:0 0 0 10; color:#F9F9F9;'>" + item._title + "</div></td><td align=right valign=middle><a href='javascript:clearTimeout(timer);isSlideShowMode=false;closePopup(\"divPopup\");;' style='margin:0 5 0 0'><img src='/Images/core/closeLight.gif' border=0 ></img></a></td></tr>";
	divHtml +=		"</table></div>";
	divHtml +=		"<div id='divHeaderLine'>&nbsp;</div>";
	divHtml +=		"<div id='divSize' style=\"width:640px; height:480px;\" >&nbsp;</div>";
	divHtml +=		"<div id='divLoading' style='position:absolute; left:300px; top:250px; background-color:White; padding:5px;'>Loading...</div>";
	divHtml +=		"<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td align=center><a href='javascript:window.clearInterval (slideInterval);javascript:clearTimeout(timer);isSlideShowMode=false;closePopup(\"divPopup\");;' style='margin:0 5 0 0'><img id=\"imgSlideShow\" class='hideMe' border=0 title='' ></img></a></td></tr></table>";
	divHtml +=		"<div id='divHeaderLine'>&nbsp;</div>";
	divHtml +=		"<div id=\"divNextPrevious\" style=\"margin:3 0 3 5; float:left;\"><a href='javascript:playStopSlideShow();;'><img id=\"buttonPlay\" src=\"/images/core/button_play_normal.gif\" border=0></a>"
	divHtml +=		"&nbsp;<a href='javascript:previousSlide();;'><img src=\"/images/core/button_back_normal.gif\" border=0></a>"
	divHtml +=		"&nbsp;<a href='javascript:nextSlide();;'><img src=\"/images/core/button_next_normal.gif\" border=0></a></div>"
	divHtml +=		"<div id=\"divSlideShowCredit\" style=\"margin:3 5 3 3; height:20px; float:right; color:#F9F9F9;\">" + item._credit + "</div>"
	divHtml +=		"<img id=\"imgLoader\" src='" + (item._url.indexOf("News_") > -1 ? item._url.replace("News_", "NewsBig_") : item._url) + "' class=\"hideMe\" onLoad=\"imageIsLoaded()\"></img>";
	window.setTimeout("updateProperties(myDiv, 60)", 0);
}

function popNewsFromList(id) {
	id = ((parseInt(page)-1)*parseInt(nbRowPerPage) + parseInt(id)) - 1;
	var item = _listItem[id];
	win = window.open("/News.aspx?newsId=" + item._id);
	return false;
}

function popLinksFromList(id) {
	id = ((parseInt(page)-1)*parseInt(nbRowPerPage) + parseInt(id)) - 1;
	var item = _listItem[id];
	win = window.open(item._url);
	return false;
}

function popDocumentsFromList(id) {
	id = ((parseInt(page)-1)*parseInt(nbRowPerPage) + parseInt(id)) - 1;
	var item = _listItem[id];
	win = window.open('/OpenLink.aspx?docID=' + item._id);
	return false;
}

function popPublicationsFromList(id) {
	id = ((parseInt(page)-1)*parseInt(nbRowPerPage) + parseInt(id)) - 1;
	var item = _listItem[id];
	win = window.open('/OpenLink.aspx?PubID=' + item._id);
	return false; 
}

function subscribePopup() {
	var myDiv = document.getElementById("divPopup");
	myDiv.className = "popup";
	divHtml =	"<div id='divHandle' style='cursor: move;'><table width=100% bgcolor=#003399 cellpadding=0 cellspacing=0 border=0>";
	divHtml +=		"<tr><td align=left height=25><span class='popupTitle'>" + (language == 'fr' ? "Souscription à la newsletter" : "Newsletter subscription") + "</span></td><td align=right valign=middle><a href='javascript:closePopup(\"divPopup\");;' style='margin:0 5 0 0'><img src='/Images/core/closeLight.gif' border=0/></a></td></tr>";
	divHtml +=		"</table></div>";
	divHtml +=		"<div id='divHeaderLine'>&nbsp;</div><div id='divHeaderLine2'></div>";
	divHtml +=		"<div id='divContent'><table width='365' height=185 style='margin:10px;' class='StandardText' cellpadding=5 cellspacing=0 border=0>";
	divHtml +=		"<tr><td colspan=2>" + (language == 'fr' ? "La newsletter MONUC vous tient au courant de toute l'actualité concernant le processus de maintien de la paix des Nations Unies en RD Congo. Pour vous inscrire gratuitement, saisissez votre adresse e-mail puis validez." : "MONUC newsletter brings you the most timely, relevant news on the United Nations peacekeeping process in the DR Congo to your inbox every weekday. To subscribe to MONUC newsletter, insert your email address below.") + "</td></tr>";
	divHtml +=		"<tr><td width=120><strong>Email</strong></td><td valign=top><input type='text' size=40 id='txtEmail' class='TextBoxPopup' /></td></tr>";
	divHtml +=		"<tr height=100%><td width=120 valign=top><strong>Language</strong></td><td valign=top><input type='hidden' id='hLanguage' name='hLanguage' value='" + (language == 'fr' ? "1" : "0") + "'><input type='radio' " + (language == 'en' ? "CHECKED" : "") + " onclick='javascript:if(this.checked){document.getElementById(\"hLanguage\").value=0;}' name='rbLanguage' id='rbLanguage'>" + (language == 'fr' ? "Anglais" : "English") + " <input type='radio' " + (language == 'fr' ? "CHECKED" : "") + " onclick='javascript:if(this.checked){document.getElementById(\"hLanguage\").value=1;}' name='rbLanguage' id='rbLanguage'>" + (language == 'fr' ? "Français" : "French") + " <input type='radio' onclick='javascript:if(this.checked){document.getElementById(\"hLanguage\").value=2;}' name='rbLanguage' id='rbLanguage'>" + (language == 'fr' ? "Les deux" : "Both") + "</td></tr>";
	divHtml +=		"</table>";
	divHtml +=		"<span style='float:right; margin:0 15 10 0;'><h1><a class='title' href='javascript:subscribe();;doNothing();;'><img src='/Images/core/arrow.gif' border=0>&nbsp;&nbsp;" + (language == 'fr' ? "validez" : "subscribe") + "</a></h1></span></div>";
	myDiv.innerHTML = divHtml;
	updateProperties(myDiv, 190);
}

function numberPopup() {
	var myDiv = document.getElementById("divPopup");
	myDiv.className = "popup";
	divHtml =	"<div id='divHandle' style='cursor: move;'><table width=100% bgcolor=#EEEEEE cellpadding=0 cellspacing=0 border=0>";
	divHtml +=		"<tr><td align=left height=25><span class='popupTitle'>" + (language == 'fr' ? "En chiffre" : "Number") + "</span></td><td align=right valign=middle><a href='javascript:closePopup(\"divPopup\");;' style='margin:0 5 0 0'><img src='/Images/core/close.gif' border=0/></a></td></tr>";
	divHtml +=		"</table></div>";
	divHtml +=		"<div id='divHeaderLine'>&nbsp;</div><div id='divHeaderLine2'></div>";
	divHtml +=		"<div id='divContent'><table width='365' style='margin:10px;' class='StandardText' cellpadding=5 cellspacing=0 border=0>";
	divHtml +=		"<tr><td>" + body + "</td></tr>";
	divHtml +=		"</table>";
	myDiv.innerHTML = divHtml;
	updateProperties(myDiv, 190);
}

function updateProperties(obj, xPosition) {
	var group;
	var coordinates = ToolMan.coordinates();
	var drag = ToolMan.drag();
	
	obj.innerHTML = divHtml;
	obj.style.display = "none";
	group = drag.createSimpleGroup(obj, document.getElementById("divHandle"));
	//alert("test updateProperties2");
	var scrollY;
	if (document.all) {    
		if (!document.documentElement.scrollTop)
			scrollY = document.body.scrollTop;
		else
			scrollY = document.documentElement.scrollTop;
	} else {
		scrollY = window.pageYOffset;
	}
	obj.style.top = 0;
	obj.style.left = 0;
	obj.style.margin = scrollY + 132 + " 0 0 " + xPosition;
	obj.style.display = "inline";
	if(_listItem.length < 2) document.getElementById("divNextPrevious").className = "hideMe";
}
