﻿//selim saraçoğlu 2009
//selimforever@hotmail.com
//selim@karegen.com
var MemberLoggedIn = false;
var MemberName = "";
var IsArtist = false;
var IsArtistApproved = false;
var NotLoggedInHTML = "";
var notLoaded = null;
var ArtistProfileTime;
var MemberProfileTime;
var PlayListTime;
var theForm = document.forms['aspnetForm'];
var MyMP3PlayList;
jQuery(document).ready(function() {
    var links = jQuery('a');
    for (ix = 0; ix < links.length; ix++) {
        try {
            var l = jQuery(links[ix]);
            var hrf = l[ix].href;
            if (hrf.match('^http')) {

                    if (!hrf.match('^' + siteRoot)) {//Link Site dışıysa
                        l.attr("href", hrf);
                        l.attr("target", '_blank');
                    } else {//link site içiyse

                        if (a = hrf.match('^(http.+)(#.*)')) {//bağlaç ise ana dökümanla ilişkilendir.
                            if (b = document.location.href.match('^(http.+)(#.*)')) { l.attr("href", b[1] + a[2]); } else { l.attr("href", document.location.href + a[2]); }
                        } else {//bağlaç değilse
                            if (!l.hasClass("lightbox") && !l.hasClass("notarget")) {
                                l.attr("href", hrf);
                                l.attr("target", frame);
                                l.click(function() { ClosePage(false); });
                            } else {
                                l.attr("href", hrf);
                            }
                        }
                    }
                
            } else if (a = hrf.match('(javascript:)(.*)')) {//javascript postback methoduysa framee gönder
                //l.attr("target", 'ifContentContentPanelFrame');
                // var w = "";
                //w= "window['ifContentContentPanelFrame'].";
                //if (a[2] != ";") l.attr("href", 'javascript:' + w + a[2]);
            }
        }
        catch (e) { ; }
    }
    function searchGeneral() {
        if (jQuery.trim(txtSearch.val()) == searchText || jQuery.trim(txtSearch.val()).length < 1) {
            jQuery.blockUI({ message: jQuery(msgAlertBox) });
        }
        else {
            frame = jQuery(frame);
            frame[0].src = siteRoot + "/Search.aspx?q=" + txtSearch.val();
            jQuery.blockUI({ message: jQuery(msgWaitBox) });
        }
        return false;
    }

    btnOkey = new jQuery(btnOkey);
    btnOkey.click(function() {
        jQuery.unblockUI();
        return false;
    });

    btnNotLoaded = new jQuery(btnNotLoaded);
    btnNotLoaded.click(function() {
        jQuery.unblockUI();
        return false;
    });

    txtSearch = new jQuery(txtSearch);
    txtSearch.focus(function() {
        if (txtSearch.val() == searchText) {
            txtSearch.val("");
        }
    });
    txtSearch.blur(function() {
        if (jQuery.trim(txtSearch.val()) == "") {
            txtSearch.val(searchText);
        }
    });
    jQuery(PlayListOCLink).click(
    function(evt) {
        OpenBottemLists("#PlayerPanelContent");
    }
    );
    jQuery(MemberPanelOCLink).click(
    function(evt) {
        OpenBottemLists("#MemberPanelContent");
    });
    jQuery(ArtistPanelOCLink).click(
    function(evt) {
        OpenBottemLists("#ArtistPanelContent");
    });
    MyMP3PlayList = new SSPL(PlayListContainer, idPlayer, {}, MP3Defaults, function() { OpenBottemLists("#PlayerPanelContent"); });

    window.MyMP3PlayList = MyMP3PlayList;
    document.MyMP3PlayList = MyMP3PlayList;

});

function OpenBottemLists(idList) {
    var div = jQuery(idList);
    var par=div.parent();
    par.css('width', par.width() + "px");
    div.css('position', 'absolute').height(200).css('padding-bottom','1px');
}
function CloseBottomLists(idList) {
    jQuery(idList).css('position', 'relative').height(20);
}
/////////////////////////////////////////////////////
var OpenPage = function(doc, win) {
    hdnFramePage = doc.location.href;
    var framebody = jQuery("body", doc);
    jQuery(HomeContent).html(framebody.html());
    var thispageform = jQuery("form", HomeContent);
    win.theForm = thispageform[0];
    var scr = jQuery("body script", doc);
    for (ix = 0; ix < scr.length; ix++) {
        var script = document.createElement('script');
        script.setAttribute('type', 'text/javascript');
        if (scr[ix].src) {
            script.setAttribute('src', scr[ix].src);
        } else {

            script.setAttribute('nodeValue', jQuery(scr[ix]).html());
        }
        jQuery(HomeContent).append(script);
    }
    var submt = thispageform.attr("action", doc.location)[0].onsubmit | function() { };
    thispageform.attr("action", doc.location)[0].onsubmit = function() {
        if ((typeof (WebForm_OnSubmit) == "function" && WebForm_OnSubmit() == false) || (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false)) {

            return false;

        }
        else {

            thispageform[0].target = frame;
            ClosePage(true);
            return true;

        }

    };
    var frmlinks = jQuery("form#aspnetForm a", framebody);
    var links = jQuery('a', thispageform);
    for (ix = 0; ix < links.length; ix++) {
        try {
            var l = jQuery(links[ix]);
            var fl = jQuery(frmlinks[ix]);
            var hrf = fl[0].href;
            if (hrf.match('^http')) {
                if (!hrf.match('^' + siteRoot)) {//Link Site dışıysa
                    l.attr("href", hrf);
                    l.attr("target", '_blank');
                } else {//link site içiyse
                  
                        if (a = hrf.match('^(http.+)(#.*)')) {//bağlaç ise ana dökümanla ilişkilendir.
                            if (b = document.location.href.match('^(http.+)(#.*)')) { l.attr("href", b[1] + a[2]); } else { l.attr("href", document.location.href + a[2]); }

                        } else {//bağlaç değilse
                            
                            if (!l.hasClass("lightbox") && !l.hasClass("notarget")) {
                                l.attr("href", hrf);
                                l.attr("target", 'ifContentContentPanelFrame');
                            } else {
                                l.attr("href", hrf);

                            }
                        }
                    
                    
                }
            } else if (a = hrf.match('(javascript:)(.*)')) {
                if (b = hrf.match('(javascript:)(__do.*)')) {//javascript postback methoduysa framee gönder
                    //l.attr("target", 'ifContentContentPanelFrame');
                    var w = "";
                    //w = "window.frames['ifContentContentPanelFrame'].";
                    if (b[2] != ";") l.attr("href", 'javascript:' + w + b[2]);
                } else {
                    l.attr('href', 'javascript:' + a[2]);
                }
            }
        }
        catch (e) { ; }
    }
    var frmimages = jQuery("img", doc.body);
    var images = jQuery('body.home div#pagediv div.content img');
    for (ix = 0; ix < images.length; ix++) {
        try {
            images[ix].src = frmimages[ix].src;

        }
        catch (e) { ; }
    }
    jQuery("a.lightbox").lightbox({
        fileLoadingImage: myImagesPath + 'lightbox/loading.gif',
        fileBottomNavCloseImage: myImagesPath + 'lightbox/closelabel.gif',
        strings: langstrings
    });
    jQuery.unblockUI();
    clearTimeout(notLoaded);

    if (MemberLoggedIn) {
        if (!NotLoggedInHTML) NotLoggedInHTML = jQuery('#LoginStatus').html();
        jQuery('#LoginStatus').html(jQuery('#LoggedInUser').html().replace("{user}", MemberName));

    } else {
        if (NotLoggedInHTML) jQuery('#LoginStatus').html(NotLoggedInHTML);
    }
    if (typeof (pngfix) == "function") {
        pngfix();
    }
}
var ClosePage = function( isPostBack) {
    window.clearTimeout(notLoaded);
    if (!isPostBack) {
        notLoaded = window.setTimeout(function() {
            jQuery.unblockUI();
        }, 40000);
    }
    jQuery.blockUI({ message: jQuery(msgWaitBox) });
};
function getQueryVariable(variable,href) {
    if (!href)
        href = document.location.href;
    var params = href.split("?");

    if (params.length < 2)
        return;
    var query = params[1];
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0].toLowerCase() == variable.toLowerCase()) {
            return pair[1];
        }
    }
}

function ConfirmDelete(n, i) {
    if (confirm(AreYouSureDel + "\n" + n)) {
        document.location.href = "?Delete=" + i;
    }
    return false;
}

function RedirectFrame(addr) {
    frame = window.frames[frame].location.href=addr;
    return false;
}
function changeCulture(elm) {
    document.location.href = siteRoot + "/" + elm.options[elm.selectedIndex].value + "/Index.aspx?RefPage=" + escape(window.frames["ifContentContentPanelFrame"].location);
}
function changeposition(id,height) {
        var el = document.getElementById(id);
        el.style.position = "absolute";
        var g = Number(el.style.width.split(/\D+/)[0]);
        var t = (Number(document.body.clientHeight) - (Number(height))) + "px";
        el.style.top = t;
    }

    function SearchAMA(type) {
        try {
            var queryTB = jQuery('input[type=text][id*=txtSearch][id*=' + type + ']');
            if (!jQuery.trim(queryTB.val()) || jQuery.trim(queryTB.val()).length < 1) {
                jQuery.blockUI({ message: jQuery("#AlertBox") });
            }
            else {
                window.frames[frame].location.href = siteRoot + "/Visitors/Search" + type + "s.aspx?Query=" + queryTB.val();
            }
            return false;
        }
        catch (e) { return true; }
    }
    function CloseMsgBox() {
        jQuery.unblockUI();
        return false;
    }
    function SelectChanged(index, value, text, selectid) {

        var href = window.frames[frame].location.href.split("?");
        
        if (window.frames[frame].location.href.match('ArtistProfile')) {
            window.frames[frame].location.href =href[0]+ '?LangCode=' + value;

        }
        if (window.frames[frame].location.href.match('AlbumDefinition.aspx')) {
            var IDAlbum = getQueryVariable("IDAlbum", window.frames[frame].location.href);
            window.frames[frame].location.href = href[0] + '?LangCode=' + value + "&IDAlbum=" + IDAlbum;
        }
        if (window.frames[frame].location.href.match('ChangeMusic')) {
            var IDMusic = getQueryVariable("IdMusic", window.frames[frame].location.href);
            window.frames[frame].location.href = href[0] + '?LangCode=' + value + '&IdMusic=' + IDMusic;

        }

        return false;
    }