﻿var myWidth = 0, myHeight = 0;
if (typeof (window.innerWidth) == 'number') {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
}
var scrOfX = 0, scrOfY = 0;
if (typeof (window.pageYOffset) == 'number') {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
}

if (myHeight < 681) {
    myHeight = 681;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function divScrollLeftPos() {
    var x, y;
    x = document.getElementById('txtdivScrollLeftPos');
    y = document.getElementById('divScrollLeft');
    x.value = y.scrollTop;
}

function divScrollRightPos() {
    var x, y;
    x = document.getElementById('txtdivScrollRightPos');
    y = document.getElementById('divScrollRight');
    x.value = y.scrollTop;
}

function focus1() {
    var x;
    x = document.getElementById("btReset");
    x.focus();
    window.setTimeout("focus2()", 1);
}

function focus2() {
    var x;
    x = document.getElementById("txtSearchString");
    x.focus();
}

function musicsearch() {
    messages();

    var x, y, a, b, c, z1, z2, x1, x2, x3, so;

    a = (myHeight + scrOfY - 30);
    b = (myWidth - 1000) / 2;

    y = document.getElementById('divScrollLeft');
    a = 0;
    b = 0;
    z2 = y;
    while (z2 != null) {
        a += z2.offsetTop;
        b += z2.offsetLeft;
        z2 = z2.offsetParent;
    }

    x = document.getElementById('txtdivScrollReset');
    if (x != null) {
        if (x.value != '') {
            x.value = '';
            x = document.getElementById('txtdivScrollLeftPos');
            x.value = 0;
            x = document.getElementById('txtdivScrollRightPos');
            x.value = 0;
        }
    }

    x = document.getElementById('txtdivScrollLeftPos');
    y = document.getElementById('divScrollLeft');
    y.style.height = String(myHeight - a - 28) + "px";
    y.scrollTop = x.value;

    x = document.getElementById('txtdivScrollRightPos');
    y = document.getElementById('divScrollRight');
    y.style.height = String(myHeight - a - 28) + "px";
    y.scrollTop = x.value;

    x1 = document.getElementById('lblPlay1');
    x2 = document.getElementById('lblPlay2');
    x3 = document.getElementById('lblPlay3');
    if (x1.innerHTML != x2.innerHTML) {
        so = new SWFObject("mediaplayer.swf", "mediaplayer", "300", "20", "10", "#CCCCCC");
        so.addParam('wmode', 'transparent');
        if (x1.innerHTML != '') {
            so.addParam('flashvars', 'file=' + x1.innerHTML + '&autostart=true');
        }
        so.write("divplayer1");
        x2.innerHTML = x1.innerHTML;
        x3.innerHTML = '1';
    }
    else {
        if (x3.innerHTML == '') {
            so = new SWFObject("mediaplayer.swf", "mediaplayer", "300", "20", "10", "#CCCCCC");
            so.addParam('wmode', 'transparent');
            if (x1.innerHTML != '') {
                so.addParam('flashvars', 'file=' + x1.innerHTML + '&autostart=false');
            }
            so.write("divplayer1");
            x2.innerHTML = x1.innerHTML;
            x3.innerHTML = '1';
        }
    }

    z1 = document.getElementById('divplayer1');
    z2 = document.getElementById('divplayer2');
    a = 0;
    b = 0;
    while (z2 != null) {
        a += z2.offsetTop;
        b += z2.offsetLeft;
        z2 = z2.offsetParent;
    }
    z1.style.position = "absolute";
    z1.style.top = String(a) + "px";
    z1.style.left = String(b) + "px";
    z1.style.zIndex = "10";

    x = document.getElementById('tblDownload');
    x.style.position = "absolute";
    x.style.top = String(a + 17) + "px";
    x.style.left = String(b + 50) + "px";
    x.className = "stylenormal";
    x.style.zIndex = "10";

}

function msgalert() {
    x = document.getElementById('txtMsg');
    if (x != null) {
        if (x.value != "") {
            alert(x.value);
        }
        x.value = "";
    }
}

function msgconfirm() {
    var x, y, z;
    x = document.getElementById('txtConfirmMsg');
    if (x != null) {
        if (x.value != '') {
            z = document.getElementById('txtConfirmBt');
            z = document.getElementById(z.value);
            var y = confirm(x.value);
            x.value = '';
            if (y == true)
                z.click();
        }
    }
}

function ClickButton() {
    var x, y;
    x = document.getElementById('txtClickButton');
    if (x != null) {
        if (x.value != "") {
            y = document.getElementById(x.value);
            x.value = '';
            y.click();
        }
    }
}


function divScrollIni() {
    var x, y, a, b, c, z1, z2, x1, x2, x3;

    y = document.getElementById('divScrollLeft');
    a = 0;
    b = 0;
    z2 = y;
    while (z2 != null) {
        a += z2.offsetTop;
        b += z2.offsetLeft;
        z2 = z2.offsetParent;
    }

    x = document.getElementById('txtdivScrollReset');
    if (x != null) {
        if (x.value != '') {
            x.value = '';
            x = document.getElementById('txtdivScrollLeftPos');
            x.value = 0;
            x = document.getElementById('txtdivScrollRightPos');
            x.value = 0;
        }
    }

    x = document.getElementById('txtdivScrollLeftPos');
    y = document.getElementById('divScrollLeft');
    y.style.height = String(myHeight - a - 28) + "px";
    y.scrollTop = x.value;

    x = document.getElementById('txtdivScrollRightPos');
    y = document.getElementById('divScrollRight');
    y.style.height = String(myHeight - a - 28) + "px";
    y.scrollTop = x.value;

}

function messages() {
    msgalert();
    msgconfirm();
    ClickButton();
}

function fdiv1(div1, div2) {
    grayOut(true);
    var x = document.getElementById(div1);
    var y = document.getElementById(div2);
    var a = 0;
    var b = 0;
    var z = x;
    while (z != null) {
        a += z.offsetTop;
        b += z.offsetLeft;
        z = z.offsetParent;
    }
    y.style.position = "absolute";
    y.style.zIndex = "20";
    y.style.top = String(a + 20) + "px";
    y.style.left = String(b) + "px";
    y.className = "stylenormal";
}

function fdiv2(div2) {
    grayOut(false);
    var y = document.getElementById(div2);
    y.className = "stylehidden";
}


function projects() {

    var x = document.getElementById('txtPanel');
    if (x.value == 'Share') {
        fdiv1('divShare1', 'divShare2');
    }
    else {
        fdiv2('divShare2');
    }
    if (x.value == 'Send') {
        fdiv1('divSend1', 'divSend2');
    }
    else {
        fdiv2('divSend2');
    }

    cb_restore('txtc0');
    cb_restore('txtc1');
    cb_restore('txtc2');
    messages();
    player();
    //    divScrollIni();
}

function player() {
    var so
    x1 = document.getElementById('lblPlay1');
    x2 = document.getElementById('lblPlay2');
    x3 = document.getElementById('lblPlay3');
    if (x1.innerHTML != x2.innerHTML) {
        so = new SWFObject("mediaplayer.swf", "mediaplayer", "220", "20", "10", "#CCCCCC");
        so.addParam('wmode', 'transparent');
        if (x1.innerHTML != '') {
            so.addParam('flashvars', 'file=' + x1.innerHTML + '&autostart=true');
        }
        so.write("divplayer1");
        x2.innerHTML = x1.innerHTML;
        x3.innerHTML = '1';
    }
    else {
        if (x3.innerHTML == '') {
            so = new SWFObject("mediaplayer.swf", "mediaplayer", "220", "20", "10", "#CCCCCC");
            so.addParam('wmode', 'transparent');
            if (x1.innerHTML != '') {
                so.addParam('flashvars', 'file=' + x1.innerHTML + '&autostart=false');
            }
            so.write("divplayer1");
            x2.innerHTML = x1.innerHTML;
            x3.innerHTML = '1';
        }
    }

    z1 = document.getElementById('divplayer1');
    z2 = document.getElementById('divplayer2');
    a = 0;
    b = 0;
    while (z2 != null) {
        a += z2.offsetTop;
        b += z2.offsetLeft;
        z2 = z2.offsetParent;
    }
    z1.style.position = "absolute";
    z1.style.top = String(a) + "px";
    z1.style.left = String(b) + "px";
    z1.style.zIndex = "10";

    x = document.getElementById('tblDownload');
    x.style.position = "absolute";
    x.style.top = String(a + 17) + "px";
    x.style.left = String(b + 10) + "px";
    x.className = "stylenormal";
    x.style.zIndex = "10";
}

function c0_click(x) {
    var y, z, i, l;
    if (x.id == 'c00') {
        y = document.getElementById('txtc0');
        z = y.value.split(';');
        for (i = 1; i < z.length; i++) {
            y = document.getElementById(z[i]);
            if (y != null) {
                y.checked = x.checked;
            }
        }
    }
    else {
        y = document.getElementById('txtc0');
        z = y.value.split(';')
        l = true;
        for (i = 1; i < z.length & l; i++) {
            y = document.getElementById(z[i]);
            if (y != null) {
                l = y.checked;
            }
        }
        y = document.getElementById('c00');
        y.checked = l;
    }
    x = '';
    y = document.getElementById('txtc0');
    z = y.value.split(';');
    for (i = 1; i < z.length; i++) {
        y = document.getElementById(z[i]);
        if (y != null) {
            if (y.checked) {
                x += ';' + y.id;
            }
        }
    }
    y = document.getElementById('txtc0Selected');
    y.value = x.substr(1, 1000);
}

function c1_click(x) {
    var y, z, i, l;

    if (x.checked) {
        x = x.id;
        x = x.substr(2, 1000);
        y = document.getElementById('c2' + x);
        if (y != null) {
            y.checked = false;
        }
    }

    x = '';
    y = document.getElementById('txtc1');
    z = y.value.split(';');
    for (i = 1; i < z.length; i++) {
        y = document.getElementById(z[i]);
        if (y != null) {
            if (y.checked) {
                x += ';' + y.id;
            }
        }
    }
    y = document.getElementById('txtc1Selected');
    y.value = x.substr(1, 1000);

    x = '';
    y = document.getElementById('txtc2');
    z = y.value.split(';');
    for (i = 1; i < z.length; i++) {
        y = document.getElementById(z[i]);
        if (y != null) {
            if (y.checked) {
                x += ';' + y.id;
            }
        }
    }
    y = document.getElementById('txtc2Selected');
    y.value = x.substr(1, 1000);


}

function c2_click(x) {
    var y, z, i, l;

    if (x.checked) {
        x = x.id;
        x = x.substr(2, 1000);
        y = document.getElementById('c1' + x);
        if (y != null) {
            y.checked = false;
        }
    }

    x = '';
    y = document.getElementById('txtc1');
    z = y.value.split(';');
    for (i = 1; i < z.length; i++) {
        y = document.getElementById(z[i]);
        if (y != null) {
            if (y.checked) {
                x += ';' + y.id;
            }
        }
    }
    y = document.getElementById('txtc1Selected');
    y.value = x.substr(1, 1000);

    x = '';
    y = document.getElementById('txtc2');
    z = y.value.split(';');
    for (i = 1; i < z.length; i++) {
        y = document.getElementById(z[i]);
        if (y != null) {
            if (y.checked) {
                x += ';' + y.id;
            }
        }
    }
    y = document.getElementById('txtc2Selected');
    y.value = x.substr(1, 1000);
}

function cb_restore(x) {
    var y, z, i, l;
    y = document.getElementById(x);
    z = y.value.split(';');
    for (i = 0; i < z.length; i++) {
        y = document.getElementById(z[i]);
        if (y != null) {
            y.checked = false;
        }
    }
    y = document.getElementById(x + 'Selected');
    z = y.value.split(';');
    for (i = 0; i < z.length; i++) {
        y = document.getElementById(z[i]);
        if (y != null) {
            y.checked = true;
        }
    }
}

function grayOut(vis, options) {
    // Pass true to gray out screen, false to ungray
    // options are optional.  This is a JSON object with the following (optional) properties
    // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
    // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
    // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
    // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
    // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
    // in any order.  Pass only the properties you need to set.
    var options = options || {};
    var zindex = options.zindex || 19;
    var opacity = options.opacity || 40;
    var opaque = (opacity / 100);
    var bgcolor = options.bgcolor || '#000000';
    var dark = document.getElementById('darkenScreenObject');
    if (!dark) {
        // The dark layer doesn't exist, it's never been created.  So we'll
        // create it here and apply some basic styles.
        // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
        var tbody = document.getElementsByTagName("body")[0];
        var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position = 'absolute';                 // Position absolutely
        tnode.style.top = '0px';                           // In the top
        tnode.style.left = '0px';                          // Left corner of the page
        tnode.style.overflow = 'hidden';                   // Try to avoid making scroll bars            
        tnode.style.display = 'none';                      // Start out Hidden
        tnode.id = 'darkenScreenObject';                   // Name it so we can find it later
        tbody.appendChild(tnode);                            // Add it to the web page
        dark = document.getElementById('darkenScreenObject');  // Get the object.
    }
    if (vis) {
        // Calculate the page width and height 
        if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
            var pageWidth = document.body.scrollWidth + 'px';
            var pageHeight = document.body.scrollHeight + 'px';
        } else if (document.body.offsetWidth) {
            var pageWidth = document.body.offsetWidth + 'px';
            var pageHeight = document.body.offsetHeight + 'px';
        } else {
            var pageWidth = '100%';
            var pageHeight = '100%';
        }
        //set the shader to cover the entire page and make it visible.
        dark.style.opacity = opaque;
        dark.style.MozOpacity = opaque;
        dark.style.filter = 'alpha(opacity=' + opacity + ')';
        dark.style.zIndex = zindex;
        dark.style.backgroundColor = bgcolor;
        dark.style.width = pageWidth;
        dark.style.height = pageHeight;
        dark.style.display = 'block';
    } else {
        dark.style.display = 'none';
    }
}

