﻿var Incool = {
    ROOT: incoolROOT,
    IMG: incoolIMG,
    RESROOT: 'http://res.incool.com/',
    UploadService: incoolUploadService,
    UpSongFileUrl: incoolUpSongFileUrl,
    UpCopyrightPicUrl: incoolUpCopyrightPicUrl,
    UpIcoolPicUrl: 'http://res.incool.com/icoolpic/',
    ProxyUrl: '/proxy/',
    PLAYERURL: 'http://www.incool.com/inzone/song.asp?id=',
    AlertHtml: '<div style="padding-top:100px; text-align:center; display:none" id="dvIncoolAlert">' +
	            '<div class="alert_shadow">' +
                    '<div class="alert_content">' +
                        '<div class="alert_title"><span class="alert_tishi pink12_b">提示</span><span class="alert_close"><a href="#" class="pink">[关闭]</a></span></div>' +
                        '<div class="alert_message"></div>' +
                        '<div class="alert_queding"><input type="button" class="button4 gray12_66_b" value="确 定" /></div>' +
                    '</div>' +
	            '</div>' +
             '</div>',
    //普通提示
    Alert: function(message, title) {
        //alert(message);
        if (!$('#dvIncoolAlert').length) {
            $('body').append(Incool.AlertHtml);
        }

        var dvalert = $('#dvIncoolAlert');

        $('.alert_message', dvalert).html(message.replace(new RegExp('\\n', 'g'), '</br>').replace(new RegExp(' ', 'g'), '&nbsp;'));
        $.blockUI({
            message: dvalert,
            css: {
                top: '100px',
                left: ($(window).width() - dvalert.width()) / 2 + 'px'
            }
        });
        dvalert.find('a.pink', 'input').unbind('click').click(function() {
            dvalert.hide();
            $.unblockUI();
        });
        dvalert.find('input').unbind('click').click(function() {
            dvalert.hide();
            $.unblockUI();
        });
        //        $('#incoolalert').text(message);
        //        dvalert.attr('style', 'position:absolute;top: 100px;left:' + ($(window).width() - dvalert.width()) / 2 + 'px');
        //        dvalert.show();
    },
    //确认提示
    Confirm: function(message, title) {
        return confirm(message);
    },
    //错误提示
    Error: function(message, title) {
        alert(Incool.E[0]);
    },
    E: ['服务器繁忙,请重试', '请先登录', '确定要删除？', '您发布的内容需经过审核才能显示。'],
    Reg: {
        tel: /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/,
        mobile: /^((\(\d{2,3}\))|(\d{3}\-))?(13|15|18)\d{9}$/,
        qq: /^[1-9]\d{4,10}$/,
        email: /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/,
        url: /^http[s]?:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/

    },
    EscapeHTML: function(str) {
        return str.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
    },
    ClearHTML: function(str) {
        a = str.indexOf("<");
        b = str.indexOf(">");
        len = str.length;
        c = str.substring(0, a);
        if (b == -1)
            b = a;
        d = str.substring((b + 1), len);
        str = c + d;
        tagCheck = str.indexOf("<");
        if (tagCheck != -1)
            str = Incool.ClearHTML(str);
        return str;
    },
    getMainPicUrl: function(src, size, sortname) {
        if (src == '' || src == "default.gif")
            return Incool.RESROOT + sortname + "/" + size + "/" + "default.gif";
        else
            return Incool.RESROOT + sortname + "/" + size + "/" + src;
    },
    Play: function(key) {
        window.open(Incool.PLAYERURL + key, "SongPlay");
        //Incool._PlayTrace(key, 0);
        self.focus();
    },
    Down: function(id) {
        var url = "" + id;

        window.open(url, 'DOWNLOAD', 'width=450,height=400,resizable=1,scrollbars=1,toolbar=0,location=0,menubar=0');
    },
    TryLogin: function() {
        if (Incool.MyID > 0)
            return true;
        else
            return Incool.Login();
    },
    Login: function(url, isNotConfirm) {
        //if (isNotConfirm == true || confirm("你还没有登录,现在要登录吗?"))
        location.href = "http://c.incool.com/passport/login.aspx?return=" + (url || escape(document.URL.toString()));

        return false;
    },
    Regist: function() {
        window.location.href = "http://c.incool.com/passport/reg.aspx?return=" + escape(document.URL);
    },
    Logout: function() {
        window.location.href = "http://c.incool.com/passport/logout.aspx?return=" + escape(document.URL);
    },
    Close: function(objName) {
        $(objName).hide();
    },
    CloseBlockUI: function(objName, isHide) {
        if (isHide)
            $(objName).hide();
        else
            $(objName).remove();
        $.unblockUI();
    },
    ShowBlockUI: function(objName) {
        $.blockUI({
            message: objName,
            css: {
                top: '50px',
                left: ($(window).width() - objName.width()) / 2 + 'px'
            },
            overlayCSS: {
                backgroundColor: ''
            }
        });
    },
    CheckAgree: function(e, btnObj) {
        if ($(e).attr("checked") == true) {
            $(btnObj).removeAttr('disabled');
        }
        else {
            $(btnObj).attr('disabled', 'disabled');
        }
    }
};

