﻿// Declare all variables.
var browser=navigator.appName;
var i = 0; var f = 0; var c = 0; var d = 0; var h = 0; var x = 0; var g = 0;
var objectref = ""; var divcommand = ""; var xmlDoc; var lengthCalc = 0;
var tempVideoList = ""; var tempVariable = ""; var tempVariable2 = ""; var tempLinksList = "";
var flashList = new Array(); var linksList = new Array(); var sizeList = new Array(); var descList = new Array(); var nameList = new Array();

function eng() { var trogei = location.href; if (trogei.lastIndexOf("la=2") > 0) return true; else return false; }

// Multiply the blank space.
function multiplyStr(f) { var returnStr;
for (h=0;h<=f;h++) { returnStr = returnStr + "<div style=\"position: relative; height: 103px;\"></div>"; }
return returnStr; }

// Count substring occurances on string.
String.prototype.count=function(s1) { return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length; }

// Function to verify XML files.
function verify() 
{ if (xmlDoc.readyState != 4) { return false; } }

// Function to create a list of video links.
function linksPage(numbah)
{ 
c = 0;
x = 0;
d = numbah;
g = d;
numbah = numbah * 4 - 3;

tempLinksList = "<table width=\"100%\" bgcolor=\"#f9f9f8\" align=\"center\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\">";
for (h=0;h<=3;h++) { tempLinksList = tempLinksList + linksList[numbah]; d++; numbah++; } 
tempVariable = linksList.length - 1;
if (eng()) { tempLinksList = tempLinksList + "<tr><td colspan=\"2\"><br>Page: "; } else
tempLinksList = tempLinksList + "<tr><td colspan=\"2\"><br>Σελίδα: ";
for (h=1;h<=tempVariable+3;h=h+4) { 
if (linksList[h] != 'undefined' && linksList[h] != null) { c++;
if (g == c) { tempLinksList = tempLinksList + "<input type=\"submit\" disabled=\"true\" onclick=\"document.getElementById('whereToList').innerHTML = linksPage('" + c + "')\" value=\"&nbsp;" + c + "&nbsp;\" style=\"background: #e8e8e7;  border: 0px dotted #000000;\"/>&nbsp;"; }
else { tempLinksList = tempLinksList + "<input type=\"submit\" onclick=\"document.getElementById('whereToList').innerHTML = linksPage('" + c + "')\" value=\"&nbsp;" + c + "&nbsp;\" style=\"background: #eeefe7;  border: 0px dotted #000000;\"/>&nbsp;"; } } } tempLinksList = tempLinksList + "</td></tr></table>";
if (eng()) { if (tempLinksList.count('File type : FLV') < 4) { tempLinksList = tempLinksList + multiplyStr(4 - tempLinksList.count('File type : FLV') - 1); } } else
if (tempLinksList.count('Τύπος αρχείου : FLV') < 4) { tempLinksList = tempLinksList + multiplyStr(4 - tempLinksList.count('Τύπος αρχείου : FLV') - 1); }
return tempLinksList.replace("undefined","").replace("undefined","").replace("undefined","").replace("undefined","").replace("undefined",""); }

// Function to insert/update new cookie.
function setCookie(c_name,value,expiredays)
{ var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); }

// Function to return cookie value.
function getCookie(c_name)
{ if (document.cookie.length>0) {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1) {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
} } return ""; }

// Function to add a new flash player object.
function newPrint(file, ilame)
{ 
  var ext = /^.+\.([^.]+)$/.exec(file);
  ext == null ? "" : ext[1];

if (file.length >= 2) { f++;
if (eng()) { flashList[f] = "<table style=\"border-right: white 0px solid; border-top: white 0px solid; border-left: white 0px solid; width: 100%; border-bottom: white 0px solid; border-collapse: separate;\" bordercolor=\"#ffffff\" cellspacing=\"0\" align=\"center\" border=\"0\" padding=\"0px\"><tr><td style=\"height: 28px; background-image: url(/files/Media/table_gradfinale.png);\" valign=\"middle\" bgcolor=\"#76795e\" cellpadding=\"0\"><b><center><font style=\"vertical-align: middle;\" face=\"Verdana\" color=\"#ffffff\" size=\"4\"><strong>" + descList[f - 1] + "</strong></font></center></b></td></tr>"
+ "<tr><td bgcolor=\"#76795e\"><div align=\"center\"><object id=\"HUY\" name=\"HYETA\" type=\"application/x-shockwave-flash\" data=\"/videos/itv/player_4.3_for_plugin.swf\" width=\"440\" height=\"300\">"
+ "<param name=\"movie\" value=\"/videos/itv/player_4.3_for_plugin.swf\">"
+ "<param name=\"allowFullScreen\" value=\"true\">"
+ "<param name=\"autostart\" value=\"true\">"
+ "<param name=\"allowScriptAccess\" value=\"always\">"
+ "<param name=\"flashvars\" value=\"width=440&amp;height=300&amp;file=" + file + "&amp;fullscreen=true&amp;plugins=/videos/itv/jwp4-streamsense-plugin.swf&amp;autostart=false&amp;\"> "
+ "<p class=\"AlternateText\">You will need to download <a target=\"_blank\" href=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" rel=\"external\">the latest flash player from the Adobe Website</a>for this to work.</p>"
+ "</object></div></td></tr><tr><td bgcolor=\"#76795e\"><font color=\"#76795e\"><center>Watch videos about the Greek Army: " + f + "</center></font></tr></td></table>"; } else
flashList[f] = "<table style=\"border-right: white 0px solid; border-top: white 0px solid; border-left: white 0px solid; width: 100%; border-bottom: white 0px solid; border-collapse: separate;\" bordercolor=\"#ffffff\" cellspacing=\"0\" align=\"center\" border=\"0\" padding=\"0px\"><tr><td style=\"height: 28px; background-image: url(/files/Media/table_gradfinale.png);\" valign=\"middle\" bgcolor=\"#76795e\" cellpadding=\"0\"><b><center><font style=\"vertical-align: middle;\" face=\"Verdana\" color=\"#ffffff\" size=\"4\"><strong>" + descList[f - 1] + "</strong></font></center></b></td></tr>"
+ "<tr><td bgcolor=\"#76795e\"><div align=\"center\"><object id=\"HUY\" name=\"HYETA\" type=\"application/x-shockwave-flash\" data=\"/videos/itv/player_4.3_for_plugin.swf\" width=\"440\" height=\"300\">"
+ "<param name=\"movie\" value=\"/videos/itv/player_4.3_for_plugin.swf\">"
+ "<param name=\"allowFullScreen\" value=\"true\">"
+ "<param name=\"autostart\" value=\"true\">"
+ "<param name=\"allowScriptAccess\" value=\"always\">"
+ "<param name=\"flashvars\" value=\"width=440&amp;height=300&amp;file=" + file + "&amp;fullscreen=true&amp;plugins=/videos/itv/jwp4-streamsense-plugin.swf&amp;autostart=true&amp;\"> "
+ "<p class=\"AlternateText\">You will need to download <a target=\"_blank\" href=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" rel=\"external\">the latest flash player from the Adobe Website</a>for this to work.</p>"
+ "</object></div></td></tr><tr><td bgcolor=\"#76795e\"><font color=\"#76795e\"><center>Δείτε το οπτικοακουστικό υλικό απο τις δραστηριότητες του Στρατού Ξηράς: " + f + "</center></font></tr></td></table>";
	if (f == getCookie('lastplayed'))
	{ visiDiv(getCookie('lastplayed')); }
	else if (f == '1') { visiDiv('default'); }
	if (eng()) { linksList[f] = 
"<tr><td valign=\"middle\" id=\"list" + f + "\" style=\"width:100px; border-top: 1px solid #e8fae6; border-right: 1px solid #e8fae6; border-left: 1px solid #b5c3b3; border-bottom: 1px solid #b5c3b3;\" bgcolor=\"#e0e4c4\" onmouseover=\"style.backgroundColor='#efefef';\" onmouseout=\"style.backgroundColor='#e0e4c4';\"><a href=\"javascript:visiDiv('" + f + "')\"><img hspace=\"4\" vspace=\"4\" align=\"middle\" width=\"100px\" height=\"83px\" src=\"" + file.substring(0,file.length - 4) + ".jpg\"></a><td valign=\"middle\" id=\"list" + f + "\" style=\"border-top: 1px solid #e8fae6; border-right: 1px solid #e8fae6; border-left: 1px solid #b5c3b3; border-bottom: 1px solid #b5c3b3;\" bgcolor=\"#e0e4c4\" onmouseover=\"style.backgroundColor='#efefef';\" onmouseout=\"style.backgroundColor='#e0e4c4'\">&nbsp;&nbsp;<a href=\"javascript:visiDiv('" + f + "')\">Description :<strong> " + descList[f - 1] + "</strong></a><br>&nbsp;&nbsp;Filesize : " + sizeList[f - 1] + "mb<br>&nbsp;&nbsp;File type :" + ext[1] + "<br>&nbsp;<img src=\"/files/File/linebreak.gif\"><br>&nbsp;&nbsp;<a href=\"javascript:visiDiv('" + f + "')\">View</a></td></td></tr>"; } else
linksList[f] = 
"<tr><td valign=\"middle\" id=\"list" + f + "\" style=\"width:100px; border-top: 1px solid #e8fae6; border-right: 1px solid #e8fae6; border-left: 1px solid #b5c3b3; border-bottom: 1px solid #b5c3b3;\" bgcolor=\"#e0e4c4\" onmouseover=\"style.backgroundColor='#efefef';\" onmouseout=\"style.backgroundColor='#e0e4c4';\"><a href=\"javascript:visiDiv('" + f + "')\"><img hspace=\"4\" vspace=\"4\" align=\"middle\" width=\"100px\" height=\"83px\" src=\"" + file.substring(0,file.length - 4) + ".jpg\"></a><td valign=\"middle\" id=\"list" + f + "\" style=\"border-top: 1px solid #e8fae6; border-right: 1px solid #e8fae6; border-left: 1px solid #b5c3b3; border-bottom: 1px solid #b5c3b3;\" bgcolor=\"#e0e4c4\" onmouseover=\"style.backgroundColor='#efefef';\" onmouseout=\"style.backgroundColor='#e0e4c4'\">&nbsp;&nbsp;<a href=\"javascript:visiDiv('" + f + "')\">Περιγραφή :<strong> " + descList[f - 1] + "</strong></a><br>&nbsp;&nbsp;Μέγεθος : " + sizeList[f - 1] + "mb<br>&nbsp;&nbsp;Τύπος αρχείου :" + ext[1] + "<br>&nbsp;<img src=\"/files/File/linebreak.gif\"><br>&nbsp;&nbsp;<a href=\"javascript:visiDiv('" + f + "')\">Προβολή</a></td></td></tr>";
document.getElementById('whereToList').innerHTML = linksPage('1');
} }

// Function to edit the Div container of all the videos.
function visiDiv(tempnum) { if (tempnum == 'default') { tempVariable = flashList[1];
document.getElementById('whereToPosition').innerHTML = tempVariable; }
else { tempVariable = flashList[tempnum];
document.getElementById('whereToPosition').innerHTML = tempVariable;
setCookie('lastplayed',tempnum,1); } }

// Function to initiate XML loading.
function loadXML(xmlFile) 
{ document.write("<table align=\"center\" border=\"0\" padding=\"0px\"><tr><td id=\"whereToPosition\">&nbsp;</td></tr></table><table width=\"456\" align=\"center\" border=\"0\" padding=\"0px\"><tr><td id=\"whereToList\">&nbsp;</td></tr></table>");
	if (browser == "Netscape") 
	{
	
		var xmlhttp = new window.XMLHttpRequest();
		xmlhttp.open("GET",xmlFile,false);
		xmlhttp.send(null);
		var xmlDoc = xmlhttp.responseXML.documentElement;
		var x=xmlDoc.getElementsByTagName("Path")
		for (i=0; i < x.length; i++)
		{
			if (xmlDoc.childNodes[i].textContent != ' ')
			{
				descList[i] = xmlDoc.getElementsByTagName("Path")[i].getAttribute("desc")
				sizeList[i] = xmlDoc.getElementsByTagName("Path")[i].getAttribute("size");
				nameList[i] = xmlDoc.getElementsByTagName("Path")[i].firstChild.nodeValue;
			}	
			newPrint(nameList[i], i);
		}
		
	} 
	else if (browser == "Microsoft Internet Explorer") 
	{
	    xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
	    xmlDoc.async=false; 
	    xmlDoc.load(xmlFile); 
	    xmlObj=xmlDoc.documentElement; 
		xmlDoc.onreadystatechange=verify;
	    tempVideoList = "<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"4\" cellpadding=\"4\">";
	    for (i=0; i < xmlObj.childNodes.length ; i++) 
	    {
		   sizeList[i] = xmlDoc.documentElement.childNodes[i].getAttribute("size");
		   descList[i] = xmlDoc.documentElement.childNodes[i].getAttribute("desc");
		   newPrint(xmlObj.childNodes[i].firstChild.text, i);
	    }
	} 
	else
	{
		var xmlhttp = new window.XMLHttpRequest();
		xmlhttp.open("GET",xmlFile,false);
		xmlhttp.send(null);
		var xmlDoc = xmlhttp.responseXML.documentElement;
		var x=xmlDoc.getElementsByTagName("Path")
		for (i=0; i < x.length; i++)
		{
			if (xmlDoc.childNodes[i].textContent != ' ')
			{
				descList[i] = xmlDoc.getElementsByTagName("Path")[i].getAttribute("desc")
				sizeList[i] = xmlDoc.getElementsByTagName("Path")[i].getAttribute("size");
				nameList[i] = xmlDoc.getElementsByTagName("Path")[i].firstChild.nodeValue;
			}	
			newPrint(nameList[i], i);
		}		
	}
}
loadXML(XMLFileName);
