// JavaScript Document
var myiframe = "myframe";
var FFextraHeight = 40;
var timerCmbOff;
var idComboOpen;
var isMouseOnCombo = 0;

function resizeIframe() {
    var currentfr = document.getElementById(myiframe)
    if (currentfr && !window.opera) {
        currentfr.style.display = "block"
        if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
            currentfr.height = currentfr.contentDocument.body.offsetHeight + FFextraHeight;
        else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
            currentfr.height = currentfr.Document.body.scrollHeight;
        if (currentfr.addEventListener)
            currentfr.addEventListener("load", readjustIframe, false)
        else if (currentfr.attachEvent) {
            currentfr.detachEvent("onload", readjustIframe)
            currentfr.attachEvent("onload", readjustIframe)
        }
    }
}

function readjustIframe(loadevt) {
    var crossevt = (window.event) ? event : loadevt
    var iframeroot = (crossevt.currentTarget) ? crossevt.currentTarget : crossevt.srcElement
    if (iframeroot)
        resizeIframe(iframeroot.id);
}

function loadIframeURL(url, index, urlNet, urlJava) {
    document.getElementById(myiframe).src = url;
    document.getElementById('SampleMainTitle').innerHTML = document.getElementById('divSampleTitle' + index).innerHTML;
    document.getElementById('selection').innerHTML = document.getElementById('divSampleTitle' + index).innerHTML;

    var netElement = document.getElementById('SamplesDownloadNet');
    netElement.href = urlNet;
    if (urlNet == "") {
        netElement.style.visibility = "hidden";
    }
    else {
        netElement.style.visibility = "visible";
    }

    var javaElement = document.getElementById('SamplesDownloadJava');
    javaElement.href = urlJava;
    if (urlJava == "") {
        javaElement.style.visibility = "hidden";
    }
    else {
        javaElement.style.visibility = "visible";
    }

    var downloadsElement = document.getElementById('SamplesDownload');
    if ((urlJava == "") && (urlNet == "")) {
        downloadsElement.style.visibility = "hidden";
    }
    else {
        downloadsElement.style.visibility = "visible";
    }

    ComboOff('samplesCombo');
}

if (window.addEventListener)
    window.addEventListener("load", resizeIframe, false)
else if (window.attachEvent)
    window.attachEvent("onload", resizeIframe)
else
    window.onload = resizeIframe

function FindChildObjById(childId, parentId) {
    var myParent = document.getElementById(parentId);
    for (var i = 0; i < myParent.childNodes.length; i++) {
        var myId = myParent.childNodes[i].id;
        if (myId == childId) {
            return myParent.childNodes[i];
            i = myParent.childNodes.length;
        }
    }
}

function ToggleCombo(cmbName) {

    clearTimeout(timerCmbOff);
    if (idComboOpen != null && idComboOpen != '') {
        TurnComboOff('samplesCombo');
    }
    else {
        ComboClick('samplesCombo');
    }
}

function ComboOff(cmbName) {
    if (isMouseOnCombo == 0) {
        if (idComboOpen != null)
            timerCmbOff = window.setTimeout("TurnComboOff('" + cmbName + "')", 200);
        else
            TurnComboOff(cmbName);
    }
}

function TurnComboOff(cmbName) {
    var mycmb = document.getElementById(cmbName);
    mycmb.className = 'comboBox';
    var mycmbbtn = FindChildObjById('button', cmbName);
    if (mycmbbtn != null)
        mycmbbtn.className = 'comboButtonOff';
    if (idComboOpen != null && idComboOpen != '') {
        FindChildObjById('dropdown', idComboOpen).className = 'hide';
        idComboOpen = null;
    }

}
function ComboOut(cmbName) {
    isMouseOnCombo = 0;
}
function ComboOver(cmbName) {
    isMouseOnCombo = 1;
    clearTimeout(timerCmbOff);
    var mycmb = document.getElementById(cmbName);
    mycmb.className += ' comboBoxOver';
    var mycmbbtn = FindChildObjById('button', cmbName);
    if (mycmbbtn != null)
        mycmbbtn.className += ' comboButtonOver';

}

function ComboClick(cmbName) {
    clearTimeout(timerCmbOff);
    var mycmb = document.getElementById(cmbName);
    mycmb.className += ' comboBoxOn';
    var mycmbbtn = FindChildObjById('button', cmbName);
    var mydropDown = FindChildObjById('dropdown', cmbName);
    if (mydropDown != null) {
        mydropDown.className = 'comboDropDown';
        idComboOpen = cmbName;
    }
    if (mycmbbtn != null)
        mycmbbtn.className += ' comboButtonOn';

}

function HighlightSample(myobj) {
    myobj.className += ' sampleHighlight';
}

function RemoveHighlight(myobj) {
    myobj.className = 'sampleItem';
}