﻿var xmlDoc;
if (window.ActiveXObject) {// code for IE
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument) {// code for Mozilla, Firefox, Opera, etc.
    xmlDoc = document.implementation.createDocument("", "", null);
    ////////////////////////////////////// Start of code section /////////////////////////////////
// added on April 2nd 2009
// From http://www.codingforums.com/showthread.php?t=7028
// This is used to remove whitespace from the XML file
// This is needed otherwise it will cause problem in Firefox, Opera, ...

//const notWhitespace = /\S/;
 notWhitespace = /\S/;

function cleanWhitespace(node) {
  for (var x = 0; x < node.childNodes.length; x++) {
    var childNode = node.childNodes[x]
    if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
// that is, if it's a whitespace text node
      node.removeChild(node.childNodes[x])
      x--
    }
    if (childNode.nodeType == 1) {
// elements can have text child nodes of their own
      cleanWhitespace(childNode)
    }
  }
}

document.addEventListener("load", function() {
  //cleanWhitespace(document)
  cleanWhitespace(xmlDoc)
  
}, true)
////////////////////////////////////// End of code section /////////////////////////////////
    
}
else {
    alert('Your browser cannot handle this script');
}

xmlDoc.async = false;
xmlDoc.load("Other/VideosDB.xml");





var x = xmlDoc.getElementsByTagName("Video");


var SearchInProgress = 'No';
var SearchResultsString = '';

var VideoFolder = 'Videos/';

var ID;
var ID_Previous;

var FlashOk





function startVideoMainCode(ID) {

    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID)
            i2 = i;
    }



    i = i2;
    if (SearchInProgress != 'Yes')
        FillMenu(x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue);
    
    
    if (x[i].getElementsByTagName('HLink')[0].firstChild != null) {

        document.getElementById("VideoDiv").style.backgroundImage = "url(Images/BackgroundLoading.jpg)"; 



        HLink = (x[i].getElementsByTagName("HLink")[0].childNodes[0].nodeValue);


        txt = "<object classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 codebase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0 width=100% height=100% ID=Captivate1 class=VideoContainer>" +
        "<param name=movie value='" + VideoFolder + HLink + "'>" +
        "<param name=quality value=high><param NAME=wmode VALUE=transparent>" +
        "<param name=loop value=0>" +
        "<embed src='" + VideoFolder + HLink + "' width=100% height=100% wmode=transparent loop=0 quality=high pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash menu=false></embed>" +
        "</object>";
        
        document.getElementById("VideoDiv").innerHTML = txt;
        
    }
    else {
    }

    Description = "";
    VideoName = "";
    DatePublished = "";
    Category = "";
    RelatedVideos = "";
    FollowingVideo = "";
    //IsCategory = "";
    Keywords = "";
    DatasetUsed = "";
    PolyworksVersion = "";
    VideoDuration = "";
    

    if (x[i].getElementsByTagName('Description')[0].firstChild != null)
        Description = (x[i].getElementsByTagName("Description")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('VideoName')[0].firstChild != null)
        VideoName = (x[i].getElementsByTagName("VideoName")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('DatePublished')[0].firstChild != null)
        DatePublished = (x[i].getElementsByTagName("DatePublished")[0].childNodes[0].nodeValue);
    //if (x[i].getElementsByTagName('Category')[0].firstChild != null)
    //    Category = (x[i].getElementsByTagName("Category")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('RelatedVideos')[0].firstChild != null)
        RelatedVideos = (x[i].getElementsByTagName("RelatedVideos")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('FollowingVideo')[0].firstChild != null)
        FollowingVideo = (x[i].getElementsByTagName("FollowingVideo")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('VideoID')[0].firstChild != null)
        VideoID = (x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue);
    //if (x[i].getElementsByTagName('IsCategory')[0].firstChild != null)
    //   IsCategory = (x[i].getElementsByTagName("IsCategory")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('Keywords')[0].firstChild != null)
        Keywords = (x[i].getElementsByTagName("Keywords")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('DatasetUsed')[0].firstChild != null)
        DatasetUsed = (x[i].getElementsByTagName("DatasetUsed")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('PolyworksVersion')[0].firstChild != null)
        PolyworksVersion = (x[i].getElementsByTagName("PolyworksVersion")[0].childNodes[0].nodeValue);
    if (x[i].getElementsByTagName('VideoDuration')[0].firstChild != null)
        VideoDuration = (x[i].getElementsByTagName("VideoDuration")[0].childNodes[0].nodeValue);



    //ActiveCategory = "";
    //ActiveSubCategory = "";

    //if (x[i].getElementsByTagName("VideoID")[0].parentNode.parentNode.nodeName == "CategoryL") {
        //Videos without SubCategories
    //    ActiveCategory = x[i].getElementsByTagName("VideoID")[0].parentNode.parentNode.childNodes[0].childNodes[0].nodeValue;
    //    ActiveSubCategory = ""
    //    Category = ActiveCategory
    //}
    // else {
        //Videos in a SubCategories
    //    ActiveCategory = x[i].getElementsByTagName("VideoID")[0].parentNode.parentNode.parentNode.childNodes[0].childNodes[0].nodeValue;
    //    ActiveSubCategory = x[i].getElementsByTagName("VideoID")[0].parentNode.parentNode.childNodes[0].childNodes[0].nodeValue;
    //    Category = ActiveCategory + " / " + ActiveSubCategory
    //}

    //txt = "<table width='98%'><tr><td width='100px'><b>Video Info</b></td><td align=right>";
    //var txtTopMenu = ''

    //if (FollowingVideo.length > 0) {
    //    txt = txt + "Next video: <a href='javascript:startVideo(" + FollowingVideo + ")' Title='" + DescriptionFromID(FollowingVideo) + "'>" + NameFromID(FollowingVideo) + " >></a>"
    //}

    //txt = txt + "</td></tr><tr><td>Video Name:</td><td> " + VideoName + "</td></tr><tr><td>Description: </td><td>" + Description + "</td></tr><tr><td>Category: </td><td>" + Category + "</td></tr><tr><td>Video Duration: </td><td>" + VideoDuration + "";




    //txt = txt + "</td></tr></table>";

    //document.getElementById("ShowInfo").innerHTML = txt;
        //document.getElementById("ShowInfo").style.visibility = "visible";

    
    
        window.location.hash = "ID=" + ID;
        ID_Previous = ID
        document.title = "PolyWorks Learning Guides"
    
    ResizeVideo();

}

function NameFromID(ID) {
    //HLink = (x[i].getElementsByTagName("HLink")[0].childNodes[0].nodeValue);
    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID)
            txt1 = x[i].getElementsByTagName("VideoName")[0].childNodes[0].nodeValue;
    }
    return txt1;
}

function VideoDurationFromID(ID) {
    txt2 = ""
    //HLink = (x[i].getElementsByTagName("HLink")[0].childNodes[0].nodeValue);
    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID)
            if (x[i].getElementsByTagName('VideoDuration')[0].firstChild != null)
            txt2 = " (" + x[i].getElementsByTagName("VideoDuration")[0].childNodes[0].nodeValue + ")";
    }
    return txt2;
}
function DescriptionFromID(ID) {
    txt2 = ""
    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID)
            if (x[i].getElementsByTagName('Description')[0].firstChild != null)
            txt2 = x[i].getElementsByTagName("Description")[0].childNodes[0].nodeValue;
        //replace quote with character code (to resolve problem like "how to's")
        txt2 = txt2.replace(/\'/g, "&#39;");
    }
    return txt2;
}
function IsRelatedFilesFromID(ID) {
    txt2 = ""
    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID)
            if (x[i].getElementsByTagName('IsRelatedFiles')[0].firstChild != null)
            txt2 = x[i].getElementsByTagName("IsRelatedFiles")[0].childNodes[0].nodeValue;
    }
    return txt2;
}
function HLinkFromID(ID) {
    txt2 = ""
    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID)
            if (x[i].getElementsByTagName('HLink')[0].firstChild != null)
                txt2 = x[i].getElementsByTagName("HLink")[0].childNodes[0].nodeValue;
    }
    return txt2;
}
function FollowingVideoFromID(ID) {
    txt2 = ""
    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID)
            if (x[i].getElementsByTagName('FollowingVideo')[0].firstChild != null)
            txt2 = x[i].getElementsByTagName("FollowingVideo")[0].childNodes[0].nodeValue;
    }
    return txt2;
}

function next() {
    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID) {
            if (x[i].getElementsByTagName('FollowingVideo')[0].firstChild != null)
                FollowingVideo = (x[i].getElementsByTagName("FollowingVideo")[0].childNodes[0].nodeValue);
        }
    }
    val1 = FollowingVideo
    if (val1.length != 0) {
        startVideo(val1);
    }
    else {
        alert("No video was assigned");
    }
}

function previous() {
    if (i > 0) {

    }
}





function EndOfVideo() {

    // MEMO: Remove comments to automaticaly play next videos
    //alert('The next video will play');
    //next();
}



function CheckFlashVersion() {

    FlashOk = false
    // -----------------------------------------------------------------------------
    // Globals
    // Major version of Flash required
    var requiredMajorVersion = 8;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Minor version of Flash required
    var requiredRevision = 0;
    // -----------------------------------------------------------------------------

    // Vérification de la version
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

    //alert(hasReqestedVersion);
    //var message;


    if (hasReqestedVersion) {
        //code HTML à afficher si version installé
        //message = "<div><h2 style=\"color:green;\">Flash est installé</h2></div>";
        //alert("Flash is already installed");
        FlashOk = true
    } else {
        FlashOk = false
        //code HTML à afficher
        //message = "<div><h2 style=\"color:red;\">Vous devez avoir une version de Flash suffisante pour utiliser ce CD. <a target=\"_blank\" href=\"http://www.adobe.com/go/getflashplayer.\">Installer</a></h2></div>";
        //alert("Flash is not installed");
        ////File = "cmd.exe";
        //File = "../Other/install_flash_player_10.exe";
        //WSH = new ActiveXObject("WScript.Shell");
        //WSH.run(File);
        
    }

    //document.write(message);
}



function InitiatePages() {

    var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

 
    
    
    CheckFlashVersion();

    //FillMenu();
    ResizeVideo()
    document.getElementById("VideoDiv").style.backgroundImage = "url(Images/Background.jpg)"; 
    HashStr = window.location.hash

    if (FlashOk == true) {
    
        txt2 = "<form action='javascript:SearchVideo()'><input id='TextToSearch' type='text' name='searchbox' onclick='SearchVideo()' />&nbsp;<input type='button' value='Go' onclick='SearchVideo()' /><br />Search by Keyword</form>"
        document.getElementById("SearchTopInput").innerHTML = txt2;
    
        if (HashStr.length > 0) {
            startVideo(HashStr.substring(4));
        }
        else {
            FillMenu();
        }
    }
    else {
        alert("Flash Player is required to view the videos. Please, click on the link to install Flash Player");
        //txt = "Flash is required to view the videos</br><span class=WithBorders><a href='other/install_flash_player_10.exe'>Click here to install Flash</a><span></br>Once it is installed, click <a href='LearningGuides_Manufacturing.htm'>here</a> or reload the page"

        if (isIE == true) {
        //for IE
            txt = "<span class=WithBorders><a href='other/flash/install_flash_player_10_active_x.msi'>Click here to install Flash</a>. Once it is installed, close the browser and reload the page</span>"
        }
        else {
        // for other browser
            txt = "<span class=WithBorders><a href='other/flash/install_flash_player_10_plugin.msi'>Click here to install Flash</a>. Once it is installed, close the browser and reload the page</span>"
        }
        
        //txt = "<span class=WithBorders><a href='other/flash/install_flash_player_10_active_x.msi'>Click here to install Flash</a>. Once it is installed, click <a href='LearningGuides_Manufacturing.htm'>here</a> or reload the page</span>"
        
        
        document.getElementById("FlashWarnings").innerHTML = txt;
    }
    

}



function GoToHome() {
    window.location = ('LearningGuides_Manufacturing.htm');
}

function LinkForVideo(ID,ActiveID) {
    for (var i = 0; i < x.length; i++) {
        if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID)
            i2 = i;
    }
    VideoName = x[i2].getElementsByTagName("VideoName")[0].childNodes[0].nodeValue
    Description = x[i2].getElementsByTagName("Description")[0].childNodes[0].nodeValue
    Description = Description.replace(/\'/g, "&#39;");
    IsRelatedFiles = "";
    if (x[i2].getElementsByTagName('IsRelatedFiles')[0].firstChild != null)
        IsRelatedFiles = (x[i2].getElementsByTagName("IsRelatedFiles")[0].childNodes[0].nodeValue);

    if (IsRelatedFiles.length > 1) {
        HLink = x[i2].getElementsByTagName("HLink")[0].childNodes[0].nodeValue
        return "<a target=_blank href='" + VideoFolder + HLink + "' Title='" + Description + "'><u>" + VideoName + "</u></a>";
    }
    else {

        if (ID == ActiveID) {
        return "<a href='javascript:startVideo(" + ID + ")' Title='" + Description + VideoDurationFromID(ID) + "'><font color=#ec1c2e>" + VideoName + "</font></a>";
        }
        else {
            return "<a href='javascript:startVideo(" + ID + ")' Title='" + Description + VideoDurationFromID(ID) + "'>" + VideoName +  "</a>";
        }
    }
}

function LinkForCategory(Category, Description) {
    ID = "";
    SubCategory = "";
    Description = Description.replace(/\'/g, "&#39;");
    Category = Category.replace(/\'/g, "&#39;");
    return "<a href='javascript:FillMenu(&quot;" + ID + "&quot;,&quot;" + Category + "&quot;,&quot;" + SubCategory + "&quot;)' Title='" + Description + "'>" + Category + "</a>";
}

function LinkForSubCategory(Category, SubCategory, Description) {
    ID = "";
    Description = Description.replace(/\'/g, "&#39;");
    Category = Category.replace(/\'/g, "&#39;");
    SubCategory = SubCategory.replace(/\'/g, "&#39;");
    return "<a href='javascript:FillMenu(&quot;" + ID + "&quot;,&quot;" + Category + "&quot;,&quot;" + SubCategory + "&quot;)' Title='" + Description + "'><b><font color=666666>" + SubCategory + "</font></b></a>";
}

function FillMenu(ID, ActiveCategory, ActiveSubCategory) {
    if (ActiveCategory != null) {
        SearchInProgress = 'No'
    }
    RelatedVideos = ""
        
        txt = ""

        txt = txt + "<h3><a href='LearningGuides_Manufacturing.htm'>Home</a></h3>"

        if (ID != 0 && ID != null) {
            for (var i = 0; i < x.length; i++) {
                if ((x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) == ID){
                    RelatedVideos = ""
                    if(x[i].getElementsByTagName('RelatedVideos')[0].firstChild != null)
                        RelatedVideos = (x[i].getElementsByTagName("RelatedVideos")[0].childNodes[0].nodeValue);
                    i2 = i;
                 }
            }
            i = i2

        
            ActiveCategory = "";
            ActiveSubCategory = "";

            if (x[i].getElementsByTagName("VideoID")[0].parentNode.parentNode.nodeName == "CategoryL") {
                //Videos without SubCategories
                ActiveCategory = x[i].getElementsByTagName("VideoID")[0].parentNode.parentNode.childNodes[0].childNodes[0].nodeValue;
                ActiveSubCategory = ""
                
            }
            else {
                //Videos in a SubCategories
                ActiveCategory = x[i].getElementsByTagName("VideoID")[0].parentNode.parentNode.parentNode.childNodes[0].childNodes[0].nodeValue;
                ActiveSubCategory = x[i].getElementsByTagName("VideoID")[0].parentNode.parentNode.childNodes[0].childNodes[0].nodeValue;
            }
        }
        else {
            //SearchInProgress = 'No';
        }
        
        z = xmlDoc.getElementsByTagName("CategoryL")

        for (i = 0; i < z.length; i++) {

            SubCatFromCat = z[i].getElementsByTagName("SubCategoryL")
            MainCategory = z[i].childNodes[0].childNodes[0].nodeValue
            Description = z[i].getElementsByTagName("CategoryDescription")[0].childNodes[0].nodeValue

            // List MainCategory
            txt = txt + "<h3>" + LinkForCategory(MainCategory, Description) + "</h3>"

            // If there is no Subcategory
            if (SubCatFromCat.length==0){
                txt = txt + "<div class='element'><ul>";
                for (k = 0; k < x.length; k++) {
                    if (x[k].parentNode.childNodes[0].childNodes[0].nodeValue == ActiveCategory) {
                        VideoID = x[k].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue
                        txt = txt + "<li>" + LinkForVideo(VideoID, ID) + "</li>"

                    }
                }
                txt = txt + " </ul></div>"   
            }
            
            for (j = 0; j < SubCatFromCat.length; j++) {
                
                //Subcat
                SubCategory = SubCatFromCat[j].childNodes[0].childNodes[0].nodeValue;
                SubCategoryDescription = SubCatFromCat[j].childNodes[1].childNodes[0].nodeValue;
                if (MainCategory == ActiveCategory) {

                    // List the SubCategory
                    txt = txt + "<div class='elementMore'><ul>";
                    txt = txt + "<li>" + LinkForSubCategory(MainCategory, SubCategory, SubCategoryDescription) + "</li>"
                    txt = txt + "</ul></div>";

                     if (SubCategory == ActiveSubCategory) {
                         txt = txt + "<div class='element'><ul>";
                        // Loops for the video inside this subcategory
                        VideoFromSubCat = SubCatFromCat[j].getElementsByTagName("Video");

                        for (k = 0; k < VideoFromSubCat.length; k++) {

                            VideoID = VideoFromSubCat[k].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue
                            txt = txt + "<li>" + LinkForVideo(VideoID, ID) + "</li>"
                          
                        }         
                    txt = txt + " </ul></div>"
                    }  
                }
            }
        }
        
        txt = txt + "</br>";

        //-----------------------------------------------
        arrRI = RelatedVideos;

        if (arrRI.length != 0 && SearchInProgress == 'No') {
            //To remove all spaces
            arrRI = arrRI.split(" ").join("");
            //To split in array
            arrRI = arrRI.split(",");
            txt = txt + "<h3><a>Related items</a></h3>";
            txt = txt + "<div class='element'><ul>";

            for (var i = 0; i < arrRI.length; i++) {
                if (arrRI[i] != null) {
                    Description = DescriptionFromID(arrRI[i])
                    HLink = HLinkFromID(arrRI[i])

                    if (IsRelatedFilesFromID(arrRI[i]) != "") {
                        txt = txt + "<li><a target=_blank href='" + VideoFolder + HLink + "' Title='" + Description + "'><u>" + NameFromID(arrRI[i]) + "</u></a></li>";
                    }
                    else {
                        txt = txt + "<li><a href='javascript:startVideo(" + arrRI[i] + ")' Title='" + Description + "'>" + NameFromID(arrRI[i]) + VideoDurationFromID(arrRI[i]) + "</a></li>";

                    } 

                }
            }
            txt = txt + "</ul></div>";
        }
        //-----------------------------------------------


        if (SearchInProgress == 'Yes') {
            txt = txt + "<div id='SearchResults'>" + SearchResultsString + "</div>"
        }
        else {
            txt = txt + "<div id='SearchResults'></div>"
        }

        document.getElementById("menu_zone").innerHTML = txt;


}

function startVideoFromSearch(ID) {
    SearchInProgress = 'Yes';

    startVideoMainCode(ID);
}

function startVideo(ID) {
    document.getElementById("SearchTopInput").innerHTML = "<form action='javascript:SearchVideo()'><input id='TextToSearch' type='text' name='searchbox' onclick='SearchVideo()' />&nbsp;<input type='button' value='Go' onclick='SearchVideo()' /></br>Search by Keyword</form>";

    SearchInProgress = 'No';

    startVideoMainCode(ID);
}

function SearchVideo() {
    SearchInProgress = "Yes";
    FillMenu();
    
    txt = ""
    strToSearch = document.getElementById('TextToSearch').value

    if (strToSearch.length > 0) {

        i2 = 0
        var arrResults = new Array(1);
        for (var i = 0; i < x.length; i++) {


                var Keywords = ""
                if (x[i].getElementsByTagName('Keywords')[0].firstChild != null)
                    Keywords = (x[i].getElementsByTagName("Keywords")[0].childNodes[0].nodeValue);

                Keywords = Keywords.toLowerCase();
                strToSearch = strToSearch.toLowerCase();
                result = Keywords.search(strToSearch);
                if (result != -1) {

                    arrResults[i2] = NameFromID(x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue) + "*---*" + x[i].getElementsByTagName("VideoID")[0].childNodes[0].nodeValue

                    i2 = i2 + 1;

                }
            
        }
        arrResults.sort();

        if (arrResults[0] != null) {

            txt = txt + "<h3><a>Search results (" + arrResults.length + ")</a></h3>"
            txt = txt + "<div class='element'><ul>"

            for (var i = 0; i < arrResults.length; i++) {
                ArrForOneSpecific = arrResults[i].split("*---*")

                VidName = ArrForOneSpecific[0]
                VidID = ArrForOneSpecific[1]




                Description = DescriptionFromID(VidID)
                HLink = HLinkFromID(VidID)
                
                if (IsRelatedFilesFromID(VidID) != "") {
                    txt = txt + "<li><a target=_blank href='" + VideoFolder + HLink + "' Title='" + Description + "'><u>" + VidName + "</u></a></li>";
                }
                else {
                    txt = txt + "<li><a href='javascript:startVideoFromSearch(" + VidID + ")' Title='" + Description + "'>" + VidName + VideoDurationFromID(VidID) + "</a></li>";

                } 
            }

            txt = txt + "</ul></div>";

        }
        else {
            txt = "No match"
        }
        SearchResultsString = txt;
        document.getElementById("SearchResults").innerHTML = txt;
    }
}

function ResizeVideo() {

    Ratio = 1024 / 768;
    //BottomBar = 120;
    BottomBar = 20;
    
    if (self.innerWidth) {
        frameWidth = self.innerWidth;
        frameHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        frameWidth = document.documentElement.clientWidth;
        frameHeight = document.documentElement.clientHeight;
    }
    else if (document.body) {
        frameWidth = document.body.clientWidth;
        frameHeight = document.body.clientHeight;
    }

    VideoHeight = frameHeight - BottomBar;
    HashStr = window.location.hash

    if (HashStr.length > 0) {
    
        if (frameHeight < 788) {
            document.getElementById("VideoDiv").style.width = (Ratio * VideoHeight) + 'px';
            document.getElementById("VideoDiv").style.height = VideoHeight + 'px';
            document.getElementById("WindowContainer").style.width = ((Ratio * VideoHeight)+180) + 'px';
            
        }
        else {
            document.getElementById("VideoDiv").style.width = '1024px';
            document.getElementById("VideoDiv").style.height = '768px';
            document.getElementById("WindowContainer").style.width = '1223px';
        }

        if ((frameWidth) < ((Ratio * VideoHeight) + 200)) {
            if ((frameWidth - 200) < 1024) {
            document.getElementById("VideoDiv").style.width = (frameWidth - 200) + 'px';
            document.getElementById("VideoDiv").style.height = (frameWidth - 200)/Ratio + 'px';
            document.getElementById("WindowContainer").style.width = (frameWidth) + 'px';
            }
        }

        
        
    }
    else {
        document.getElementById("VideoDiv").style.width = '1024px';
        document.getElementById("VideoDiv").style.height = '768px';
        document.getElementById("WindowContainer").style.width = '1223px';
    }

}



