﻿function OpenInformationWindow(_url) {
    WindowNoMSHelp = window.open(_url, "WindowNoMSInfo", "width=600,height=700,menubar=yes,resizable=yes,status=yes,scrollbars=yes");
}

function playMP3InNewWindowEmbed(MP3FileID) {
    MP3Window = window.open('/playMP3.aspx?ID=' + MP3FileID + '&T=0', "PlayMP3", "width=320,height=150,left=30,top=30");
    MP3Window.focus();
}

function playMP3(MP3FileID) {
    MP3Window = window.open('/playMP3.aspx?ID=' + MP3FileID + '&T=1', "PlayMP3", "width=330,height=140,left=30,top=30");
    MP3Window.focus();
}

function playExternal(MP3FileID, Type) {
    var request = false;
    try { request = new XMLHttpRequest(); }
    catch (e) {
        try { request = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { request = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) {
                request = false;
            }
        }
    }

    if (request) {
        request.open('GET', '/tracking.aspx?MP3File=' + MP3FileID + '&Type=' + Type, true);
        request.send(null);
    }
}

function GetHttpRequestObject() {
    var xmlHttp = null;

    if (typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    }
    if (!xmlHttp) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                xmlHttp = null;
            }
        }
    }

    return xmlHttp;
}

function ArtistRegisterIsTraderCB() {
    if (document.Form1.ctl03_dv_Artist_cb_IsTrader.checked) {
        document.Form1.ctl03_dv_Artist_TextBoxUID.disabled = false;
        document.Form1.ctl03_dv_Artist_TextBoxUID.style.backgroundColor = "";
    }
    else {
        document.Form1.ctl03_dv_Artist_TextBoxUID.disabled = true;
        document.Form1.ctl03_dv_Artist_TextBoxUID.value = "";
        document.Form1.ctl03_dv_Artist_TextBoxUID.style.backgroundColor = "#EEEEEE";
    }
}

function sndPasswordCustomer(ev) {
    if (ev.keyCode == 13 || ev.which == 13)
        document.Form1.ctl03$btn_Request.click();
    return true;
}

function sndPasswordArtist(ev) {
    if (ev.keyCode == 13 || ev.which == 13)
        document.Form1.ctl03$btn_Request.click();
    return true;
}

function sndPasswordLabel(ev) {
    if (ev.keyCode == 13 || ev.which == 13)
        document.Form1.ctl03$btn_Request.click();
    return true;
}

function searchArtistOrAlbum(ev) {
    if (ev.keyCode == 13 || ev.which == 13)
        Search();
    return false;
}

function SessionKeepAlive() {
    window.setTimeout("SessionKeepAliveDoIt();", 900000);
}

function SessionKeepAliveDoIt() {
    var request = GetHttpRequestObject();

    if (request) {
        request.open('GET', '/SessionKeepAlive.aspx', true);
        request.send(null);

        window.setTimeout("SessionKeepAliveDoIt();", 900000);
    }
}

function Search() {
    window.location.href = '/search.aspx?key=' + URLEncode(document.getElementById("Search1_txt_Search").value);
}

function URLEncode(url) {
    var SAFECHARS = "0123456789" +
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
    "abcdefghijklmnopqrstuvwxyz" +
    "-_.!~*'()";
    var HEX = "0123456789ABCDEF";

    var plaintext = url;
    var encoded = "";
    for (var i = 0; i < plaintext.length; i++) {
        var ch = plaintext.charAt(i);
        if (ch == " ") {
            encoded += "+";
        }
        else if (SAFECHARS.indexOf(ch) != -1) {
            encoded += ch;
        }
        else {
            var charCode = ch.charCodeAt(0);
            if (charCode > 255) {
                alert("Unicode Character '"
                + ch
                + "' cannot be encoded using standard URL encoding.\n" +
                "(URL encoding only supports 8-bit characters.)\n" +
                "A space (+) will be substituted.");
                encoded += "+";
            }
            else {
                encoded += "%";
                encoded += HEX.charAt((charCode >> 4) & 0xF);
                encoded += HEX.charAt(charCode & 0xF);
            }
        }
    }

    return encoded;
}; 

