﻿/***************************************************
<威博网络后台管理通用JS类>
作者：TerryLv
时间：2008.4.29
***************************************************/
//兼容FF
function getobj(id){
	return document.getElementById(id);	
}

function HiddenOrShow(id){
    var obj = document.getElementById(id);
    obj.style.display = obj.style.display == "none" ? "" : "none";
}

//兼容FF下的childNodes
function childs(nodes)
{
    if(!nodes.length) 
        return [];
    var ret=[];
    for(var i=0;i<nodes.length;i++)
    {
        if(nodes[i].nodeType!=1) 
            continue;
        ret.push(nodes[i]);
    }
    return ret;
}
//多行文本框 MaxLenth设置无效处理
function CheckMaxLenth(obj)
{
    var maxlength = obj.maxsize;
    if(obj.value.length > maxlength)
    {
        alert("输入的内空过长！");
        obj.select();
        return false;
    }
    return true;
}
//-------------------------------------------------------
//打开模式对话框（商品编号规则选择）
//-------------------------------------------------------
//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)
    {
    }
}
//选中全部CHECKBOX
function CheckAll(){
    var InputList = document.getElementsByTagName("input");
    var InputAll = document.getElementById("CheckAllBox");
    for(var j = 0 ; j < InputList.length ; j++){
        if(InputList[j].type == "checkbox" && InputList[j].id.indexOf('CheckBoxID') != -1){
            InputList[j].checked = InputAll.checked == true ? true : false;
            if(InputList[j].checked == true){
                InputList[j].parentNode.parentNode.style.backgroundColor='#F7F7F7';
                InputList[j].parentNode.parentNode.IsSelected = "1";
            }else{
                InputList[j].parentNode.parentNode.style.backgroundColor='#ffffff';
                InputList[j].parentNode.parentNode.IsSelected = "0";
            }
        }
    }
}
//----------------------------------------------------
//选中DataGridView中对应列的全部CHECKBOX
//obj   string      DataGridView的id
//col   int         选取列所在位置
//chk   string      CheckAllBox的id
//
//注意，该列中，第一个INPUT项目必须是要操作的Checkbox
//
//----------------------------------------------------
function CheckAllByGridView(obj, col, chk){
    try
    {
        //剥离<TBODY>标签
        var DataGridView = childs(document.getElementById(obj).childNodes)[0];
        var CheckAllBox = document.getElementById(chk);

        //从1开始，直接排除掉表头
        for(var i=1; i < childs(DataGridView.childNodes).length; i++)
        {
            //剥离<TR>标签
            var objTR = childs(DataGridView.childNodes)[i];
            
            //剥离<TD>标签
            var objCol = childs(objTR.childNodes)[col];
            
            //剥离<INPUT>标签
            var checkbox = childs(objCol.childNodes)[0];

            checkbox.checked = CheckAllBox.checked;
            if(checkbox.checked)
            {
                objTR.style.backgroundColor='#F7F7F7';
                objTR.IsSelected = "1";
            }
            else
            {
                objTR.style.backgroundColor='#F7F7F7';
                objTR.IsSelected = "0";
            }
        }
    }
    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=550,' +
            'top=100,left=200,' +
            'resizable=no,scrollbars=yes';

        //锁定页面
        //document.body.disabled = true;
        winPictureDailog = window.open(uri, '_blank', param);
        tmPictureDailog = setInterval("UnlockPictureDailog()", 1);
    }
    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)
    {
    }
}
//TR移动变色效果
function ShowSelect(obj, type){
    if(obj.IsSelected == "0"){
        if(type == 0){
            obj.style.backgroundColor = '#F7F7F7';
        }else if(type == 1){
            obj.style.backgroundColor = '#FFFFFF';
        }
    }
}
//根据TR上的时间选择CHECKBOX
function CheckByRowID(RowID){
    var InputList = document.getElementsByTagName("input");
    var InputAll = document.getElementById("CheckAllBox");
    var i = 0;

    for(var j = 0 ; j < InputList.length ; j++){
        if(InputList[j].type == "checkbox" && InputList[j].id != "CheckAllBox" && InputList[j].id.indexOf('disable') == -1){
            if(i == RowID){
                if(InputList[j].mouse != 'over'){
                    InputList[j].checked = InputList[j].checked == true ? false : true;
                    if(InputList[j].checked == true){
                        InputList[j].parentNode.parentNode.style.backgroundColor='#F7F7F7';
                    }else{
                        InputList[j].parentNode.parentNode.style.backgroundColor='#ffffff';
                    }
                }
                
                if(InputList[j].checked == true){
                    InputList[j].parentNode.parentNode.IsSelected = "1";
                }else{
                    InputList[j].parentNode.parentNode.IsSelected = "0";
                }
            }
            i++;
        }
    }
}
//编辑事件
var count = 0;
function CheckEdit(){
    count = 0;
    var ids = GetCheckedBox();
    if(ids == "0"){
        alert(document.getElementById("Alert_Str1").innerHTML);
        return false;
    }else if(count > 1){
        alert(document.getElementById("Alert_Str2").innerHTML);
        return false;
    }else{
        document.getElementById("CheckedIDS").value = ids.replace('0,','');
        return true;
    }
}


//验证码
function ChangeVerifyImgNew(url){
						    if(document.getElementById("verifyimg")!=null)
						    {
							document.getElementById("verifyimg").src = '[$syspath]member/verifyimg.aspx?d=' + Date();
							}
}

//全选事件
function CheckEditAll(obj){
    count=0;
    var ids = GetCheckedBox();

    if(count <= 0)
    {
        alert(document.getElementById("Alert_Str1").innerHTML);
        return false;
    }
    else
    {
        document.getElementById("CheckedIDS").value = ids.replace('0,','');
        return true;
    }
}

//复制事件
function CopyLabel(){
    count = 0;
    var ids = GetCheckedBox();
    if(ids == "0"){
        alert(document.getElementById("Alert_Str1").innerHTML);
        return false;
    }else if(count > 1){
        alert(document.getElementById("Alert_Str2").innerHTML);
        return false;
    }else{
        copyToClipBoard('{web_' + ids.replace('0,','') + "}");
        return false;
    }
}
//复制成功
function copyToClipBoard(str)
    {
	    var clipBoardContent = str;
	    if(window.clipboardData){
	        window.clipboardData.setData("Text",clipBoardContent);
	        alert("复制成功");
	    }else{
	        alert("FireFox浏览器不支持此功能,请手动复制");
	    }
    }
//删除事件
function CheckDel(){
    var ids = GetCheckedBox();
    if(ids == "0"){
        alert(document.getElementById("Alert_Str3").innerHTML);
        return false;
    }else{
        if(confirm(document.getElementById("Alert_Str6").innerHTML)){
            document.getElementById("CheckedIDS").value = ids.replace('0,','');
            return true;
        }else{
            return false;
        }
    }
}
//批量生成事件
function CheckCreateClick(){
    var ids = GetCheckedBox();
    if(ids == "0"){
        alert(document.getElementById("Alert_Str12").innerHTML);
        return false;
    }else{
        if(confirm(document.getElementById("Alert_Str11").innerHTML)){
            document.getElementById("CheckedIDS").value = ids.replace('0,','');
            return true;
        }else{
            return false;
        }
    }
}
//单条删除事件
function CheckDelOne(){
    count = 0;
    var ids = GetCheckedBox();
    if(ids == "0")
    {
        alert(document.getElementById("Alert_Str3").innerHTML);
        return false;
    }else if(count > 1)
    {
        alert(document.getElementById("Alert_Str10").innerHTML);
        return false;
    }
    else
    {
        if(confirm(document.getElementById("Alert_Str6").innerHTML)){
            document.getElementById("CheckedIDS").value = ids.replace('0,','');
            return true;
        }else{
            return false;
        }
    }
}

//批量操作事件
function CheckSelect(){
    var ids = GetCheckedBox();
    if(ids == "0"){
        alert(document.getElementById("Alert_Str9").innerHTML);
        return false;
    }else{
        document.getElementById("CheckedIDS").value = ids.replace('0,','');
        return true;
    }
}
//单条操作事件
function CheckSelectOne(){
    count = 0;
    var ids = GetCheckedBox();
    if(ids == "0"){
        alert(document.getElementById("Alert_Str9").innerHTML);
        return false;
    }else if(count > 1){
        alert(document.getElementById("Alert_Str2").innerHTML);
        return false;
    }else{
        document.getElementById("CheckedIDS").value = ids.replace('0,','');
        return true;
    }
}

function CheckSelectOneDbclick(obj, ids){
    count = 0;
    if(ids == "0"){
        alert(document.getElementById("Alert_Str9").innerHTML);
        return false;
    }else if(count > 1){
        alert(document.getElementById("Alert_Str2").innerHTML);
        return false;
    }else{
        document.getElementById("CheckedIDS").value = ids.replace('0,','');
        return true;
    }
}

//向上事件
var index = 0;
var indexcount = 0
function CheckUp(){
    var pageindex = document.getElementById("PageIndex").value;
    var maxpageindex = document.getElementById("MaxPageIndex").value;
    indexcount = 0;
    count = 0;
    var ids = GetCheckedBox();
    if(ids == "0"){
        alert(document.getElementById("Alert_Str7").innerHTML);
        return false;
    }else if(count > 1){
        alert(document.getElementById("Alert_Str8").innerHTML);
        return false;
    }else{
        if(index == 0){
            if(pageindex == 0){
                alert(document.getElementById("Alert_Str4").innerHTML);
                return false;
            }else{
                document.getElementById("PageIndex").value = parseInt(pageindex)-1;
                document.getElementById("CheckedIDS").value = ids.replace('0,','');
                return true;
            }
        }else{
            document.getElementById("CheckedIDS").value = ids.replace('0,','');
            return true;
        }
    }
}
//向下事件
function CheckDown(){
    var pageindex = document.getElementById("PageIndex").value;
    var maxpageindex = document.getElementById("MaxPageIndex").value;
    indexcount = 0;
    count = 0;
    var ids = GetCheckedBox();
    if(ids == "0"){
        alert(document.getElementById("Alert_Str7").innerHTML);
        return false;
    }else if(count > 1){
        alert(document.getElementById("Alert_Str8").innerHTML);
        return false;
    }else{
        if(index == indexcount-1){
            if(pageindex == maxpageindex){
                alert(document.getElementById("Alert_Str5").innerHTML);
                return false;
            }else{
                document.getElementById("PageIndex").value = parseInt(pageindex)+1;
                document.getElementById("CheckedIDS").value = ids.replace('0,','');
                return true;
            }
        }else{
            document.getElementById("CheckedIDS").value = ids.replace('0,','');
            return true;
        }
    }
}
//获取全部选中CHECKBOX的值集合
function GetCheckedBox(){
    var ids = "0";
    var InputList = document.getElementsByTagName("input");
    var InputAll = document.getElementById("CheckAllBox");
    for(var j = 0 ; j < InputList.length ; j++){
        if(InputList[j].type == "checkbox" && InputList[j].id.indexOf('CheckBoxID') != -1){
            if(InputList[j].checked == true){
                ids += "," + InputList[j].value;
                count++;
                index = indexcount;
            }
            indexcount++;
        }
    }
    return ids;
}
//将选中的图片放入父窗体的控件中
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;
}
//打开模式对话框（图片选择）
function OpenDialog(ObjID){
    if (navigator.appVersion.indexOf("MSIE") == -1){
        this.returnAction=function(strResult){
            if(strResult!=null && document.getElementById(ObjID)){
                document.getElementById(ObjID).value = strResult;
                if(document.getElementById(ObjID + "View")){
                    document.getElementById(ObjID + "View").src = "../" + strResult;
                    document.getElementById(ObjID + "View").style.display = "block";
                }
            }
        }
        window.open('Picture_Picture_Manage_Dialog.aspx?d=' + Date(),'newWin','modal=yes,width=620,height=620,top=200,left=300,resizable=no,scrollbars=no');
        return;
    }else{
        var GetValue = showModalDialog('Picture_Picture_Manage_Dialog.aspx?d=' + Date(),'','dialogWidth:620px;dialogHeight:620px;')
        if (GetValue != null && document.getElementById(ObjID)) {
            document.getElementById(ObjID).value = GetValue;
            if(document.getElementById(ObjID + "View")){
                document.getElementById(ObjID + "View").src = "../" + GetValue;
                document.getElementById(ObjID + "View").style.display = "block";
            }
        } 
    }
}
//打开模式对话框（广告类别选择）
function OpenDialogAdsCategory(ObjID){
    if (navigator.appVersion.indexOf("MSIE") == -1){
        this.returnAction=function(strResult){
            if(strResult!=null && document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        }
        window.open('Advertisement_AdsCategory_Manage_Dialog.aspx?d=' + Date(),'newWin','modal=yes,width=550,height=550,top=200,left=300,resizable=no,scrollbars=no');
        return;
    }else{
        var GetValue = showModalDialog('Advertisement_AdsCategory_Manage_Dialog.aspx?d=' + Date(),'','dialogWidth:550px;dialogHeight:550px;')
        if (GetValue != null && document.getElementById(ObjID)) {
            if(document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        } 
    }
}
//打开模式对话框（文章类别选择）
function OpenDialogArticleCategory(ObjID){
    if (navigator.appVersion.indexOf("MSIE") == -1){
        this.returnAction=function(strResult){
            if(strResult!=null && document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        }
        window.open('Article_ArticleCategory_Manage_Dialog.aspx?d=' + Date(),'newWin','modal=yes,width=550,height=550,top=200,left=300,resizable=no,scrollbars=no');
        return;
    }else{
        var GetValue = showModalDialog('Article_ArticleCategory_Manage_Dialog.aspx?d=' + Date(),'','dialogWidth:550px;dialogHeight:550px;')
        if (GetValue != null && document.getElementById(ObjID)) {
            if(document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        } 
    }
}

//打开模式对话框（商品类别选择）
function OpenDialogProductCategory(ObjID){
    if (navigator.appVersion.indexOf("MSIE") == -1){
        this.returnAction=function(strResult){
            if(strResult!=null && document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        }
        window.open('Product_ProductCategory_Manage_Dialog.aspx?d=' + Date(),'newWin','modal=yes,width=550,height=550,top=200,left=300,resizable=no,scrollbars=no');
        return;
    }else{
        var GetValue = showModalDialog('Product_ProductCategory_Manage_Dialog.aspx?d=' + Date(),'','dialogWidth:550px;dialogHeight:550px;')
        if (GetValue != null && document.getElementById(ObjID)) {
            if(document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        } 
    }
}

//打开模式对话框（文档选择）
function OpenDialogDocument(ObjID){
   if (navigator.appVersion.indexOf("MSIE") == -1){
        this.returnAction=function(strResult){
            if(strResult!=null && document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        }
        window.open('Document_Document_Manage_Category.aspx?d=' + Date(),'newWin','modal=yes,width=550,height=550,top=200,left=300,resizable=no,scrollbars=no');
        return;
    }else{
        var GetValue = showModalDialog('Document_Document_Manage_Category.aspx?d=' + Date(),'','dialogWidth:550px;dialogHeight:550px;')
        if (GetValue != null && document.getElementById(ObjID)) {
            if(document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        } 
    }
}

//打开模式对话框（文章类别选择）
function OpenDialogStockLog(ObjID){
    if (navigator.appVersion.indexOf("MSIE") == -1){
        this.returnAction=function(strResult){
            if(strResult!=null && document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        }
        window.open('Product_StockLog_Operate.aspx?productid=' + Date(),'newWin','modal=yes,width=550,height=550,top=200,left=300,resizable=no,scrollbars=no');
        return;
    }else{
        var GetValue = showModalDialog('Product_StockLog_Operate.aspx?productid=' + Date(),'','dialogWidth:550px;dialogHeight:550px;')
        if (GetValue != null && document.getElementById(ObjID)) {
            if(document.getElementById(ObjID)){
                document.getElementById(ObjID).value = GetValue;
            }
        } 
    }
}

//打开模式对话框（商品编号）
function OpenDialogProductNumber(ObjID,pid){
        window.open('V5Mall_RuleCategory_Examine.aspx?d=' + Date() + '&id=' + pid,'newWin','width=750,height=280,top=200,left=300,resizable=no,scrollbars=no');
}

//打开模式对话框（查看原图）
function ShowOldImg(imgUrl){
    var img = document.getElementById("review");
    img.src = imgUrl;
    img.style.display = "block";
    document.getElementById("AlphaField").style.display = "";
    document.getElementById("listCategory").style.display = "none";
}
//隐藏图片
function HiddenImg(obj){
    obj.style.display = "none";
    document.getElementById("AlphaField").style.display = "none";
    document.getElementById("listCategory").style.display = "";
}
//初始化广告分类状态
function FormatStatus(id){
    try
    {
        if(!document.getElementById(id)) return;
        var node = childs(childs(document.getElementById(id).childNodes)[0].childNodes);
        var level = 0;
        for(var i=1;i<node.length;i++){
            level = childs(node[i].childNodes)[1].getElementsByTagName("input")[0].value
            if(level != "0"){
                //node[i].style.display = "none";
                childs(node[i].childNodes)[1].style.padding = "0 0 0 "+ level*20 +"px";
            }
        }
    }
    catch(e)
    {
    }
}
//展开或合并子节点
function ShowChilds(obj){
    var id = childs(obj.parentNode.childNodes)[2].value;
    obj.src = obj.src.indexOf("images/plus.gif") != -1 ? "images/minus.gif" : "images/plus.gif";
    
    var node = childs(obj.parentNode.parentNode.parentNode.childNodes);
    var checkobj = childs(obj.parentNode.parentNode.childNodes)[0].getElementsByTagName("input")[0];
    //alert(checkobj.id);
    checkobj.checked = checkobj.checked == false ? true : false;
    
    for(var i=1;i<node.length;i++){
        var childobj = childs(node[i].childNodes)[1].getElementsByTagName("input")[1];
        var familyobj = childs(node[i].childNodes)[1].getElementsByTagName("input")[3];
        var img = childs(node[i].childNodes)[1].getElementsByTagName("img")[0];
        if(familyobj.value.indexOf("," + id + ",") != -1 && node[i].style.display == ""){
        //if(familyobj.value.indexOf("," + id + ",") != -1 && obj.src.indexOf("images/plus.gif") != -1){
            node[i].style.display = "none";
            img.src = "images/plus.gif";
        }else if(familyobj.value.indexOf("," + id + ",") != -1 && node[i].style.display == "none" && img.src.indexOf("images/minus.gif") != -1){
            //node[i].style.display = node[i].style.display == "none" ? "" : "none";
        }else if(childobj.value == id){
            node[i].style.display = node[i].style.display == "none" ? "" : "none";
        }
    }
}
//编辑页面加载后自动给每行加不同样式
function InitTrClass(){
    var flag = 0;
    var node = childs(document.getElementById("OperateTable").childNodes)[0].childNodes;
    for(var i=0;i<node.length;i++){
        if(node[i].tagName == "TR" && node[i].style.display != "none"){
            if(flag == 0)
                node[i].className = "F7tr";
            else
                node[i].className = "FFtr";
            
            flag = 1 - flag;
        }
    }
}

//编辑页面加载后自动给每行加不同样式
function InitTrClassById(id){
    var flag = 0;
    var node = childs(document.getElementById(id).childNodes)[0].childNodes;
    for(var i=0;i<node.length;i++){
        if(node[i].tagName == "TR" && node[i].style.display != "none"){
            if(flag == 0)
                node[i].className = "F7tr";
            else
                node[i].className = "FFtr";
            
            flag = 1 - flag;
        }
    }
}

//根据字符串动态加载相应TR
function InitAdsQuery(obj){
    var str = obj.options[obj.selectedIndex].value;
    if(str != ""){
        var arrayMain = str.split('|');
        var ImgCount = arrayMain[0];
        var QueryArray = arrayMain[1].split(',');
        
        alert(ImgCount);
        for(var i=0;i<QueryArray.length;i++){
            alert(QueryArray[i]);
        }
    }
}

//根据SELECT的值给别的INPUT加值
function InitWidth(obj, w, h){
    var str = obj.options[obj.selectedIndex].value;
    if(str != ""){
        var arrayMain = str.split(',');
        document.getElementById(w).value = arrayMain[0];
        document.getElementById(h).value = arrayMain[1];
    }
}

//选中全部
function SelectAllOption(id){
    var obj = document.getElementById(id);
    for(var i=0;i<obj.options.length;i++){
        //obj.options[i].selected = obj.options[i].selected == true ? false : true;
        obj.options[i].selected = true;
    }
}

//查看广告调用代码
function GetAdsCode(){
    if(CheckEdit()){
        var txt = "<script language=\"javascript\" src=\"Show/"+document.getElementById("CheckedIDS").value+".js\"></script>";
        var url = "Advertisement_Ads_Operate_Dialog.aspx?txt=" + escape(txt) + "&act=view";
        
        if (navigator.appVersion.indexOf("MSIE") == -1){
            window.open(url,'newWin','modal=yes,width=550,height=180,top=200,left=300,resizable=no,scrollbars=no');
            return;
        }else{
            showModalDialog(url,'','dialogWidth:550px;dialogHeight:180px;')
        }
    }
    return false;
}

//查看广告预览调用代码
function GetAdsView(){
    if(CheckEdit()){
        var txt = document.getElementById("CheckedIDS").value;
        var url = "Advertisement_Ads_Operate_DialogView.aspx?txt=" + escape(txt) + "&act=view&d=" + Date();
        
        if (navigator.appVersion.indexOf("MSIE") == -1){
            window.open(url,'newWin','modal=yes,width=650,height=480,top=200,left=300,resizable=no,scrollbars=no');
            return;
        }else{
            showModalDialog(url,'','dialogWidth:650px;dialogHeight:480px;')
        }
    }
    return false;
}

//取得XmlHttp对象
function CreateXMLHttpRequest()//这里是构造XMLHttpRequest对象的方法
{
    var xmlHttpRequest = null;//这里是大家都常用的IE，firefox中取得XMLHttpRequest对象的方法
    try 
    {
        xmlHttpRequest = new XMLHttpRequest(); 
    }
    catch(e)
    {
        try
        {
            xmlHttpRequest=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    return xmlHttpRequest;
}
//----------------------------------------
// 用Ajax提交数据
//
// Url指定跳转页,
// data是要post的数据。
// EventHander 函数指针
//----------------------------------------
function AjaxSubmit(url, data, EventHander)
{
    var xmlHttpResquest = CreateXMLHttpRequest();

    xmlHttpResquest.open("POST", url, true);
    xmlHttpResquest.setRequestHeader("Content-Length", data.length);
    xmlHttpResquest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttpResquest.send(data);
    xmlHttpResquest.onreadystatechange = function ()
    {
        if (xmlHttpResquest.readyState == 4)
        {
            try
            {
                if(xmlHttpResquest.status == 200)
                {
                    //alert(xmlHttpResquest.responseText);      //DEBUG用
                    EventHander(xmlHttpResquest.responseText);  //这里可以调用想要的函数
                }
            }
            catch(e)
            {
                var errMsg = "";
                if(e!=null)
                {
                    errMsg = "Number:" + e.number + "\n" +
                             "Message:" + e.message + "\n";
                }
                alert(errMsg);
            }
        }
    }
}
//------------------------------------------------------------------
// 检查日期型
// 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;
}

function HiddenOrShow(id){
    var obj = document.getElementById(id);
    obj.style.display = obj.style.display == "none" ? "" : "none";
}

function HiddenOrShowSearch(){
    //显示或者隐藏区域
    var obj = document.getElementById("searchmore");
	obj.style.display = obj.style.display == "none" ? "" : "none";
	var img = document.getElementById("searchimg");
	var wd = document.getElementById("searchwd");
	var hidden = document.getElementById("SearchRecord");
	//修改状态
    if(img.src.indexOf('more.gif') != -1){
        img.src = 'images/less.gif';
        wd.innerHTML = '精简';
        hidden.value = "1";
    }else{
        img.src = 'images/more.gif';
        wd.innerHTML = '更多';
        hidden.value = "0";
    }
}

function RowCanSelected(obj){
    obj.style.cursor = 'pointer';
    
    //找到本行TR标签的对象
    var trobj = obj.parentNode.parentNode.childNodes;
    var tdobj = childs(trobj)[0];
    var chkobj = tdobj.getElementsByTagName("input")[0];
    if(chkobj != null){
        chkobj.mouse='out';
    }
}

function RowCanNotSelected(obj){
    obj.style.cursor = 'auto';
    //找到本行TR标签的对象
    var trobj = obj.parentNode.parentNode.childNodes;
    var tdobj = childs(trobj)[0];
    var chkobj = tdobj.getElementsByTagName("input")[0];
    if(chkobj != null){
        chkobj.mouse='over';
    }
}

//判断搜索条状态
function CheckSearchRecord(){
    //获取对象
    var hidden = document.getElementById("SearchRecord");
    var obj = document.getElementById("searchmore");
	var img = document.getElementById("searchimg");
	var wd = document.getElementById("searchwd");
	//修改状态
    if(hidden.value == "1"){
        img.src = 'images/less.gif';
        wd.innerHTML = '精简';
        obj.style.display = "";
    }else{
        img.src = 'images/more.gif';
        wd.innerHTML = '更多';
        obj.style.display = "none";
    }
}

//图片编辑时用到JS
function ChangeImg(imgid, labelid, buttonid)
{
    document.getElementById(buttonid).value = document.getElementById(buttonid).value == "更改图片" ? "返回" : "更改图片";
    ShowOrHidden(labelid);
    ShowOrHidden(imgid);
}

function ShowOrHidden(imgid)
{
    document.getElementById(imgid).style.display = document.getElementById(imgid).style.display == "" ? "none" : "";
}

//查看选中样式
function GetSelectedLabelView(selectid,path){
    var obj = document.getElementById(selectid);
    if(obj.options.length == 0){
        alert('请先创建一个样式！'); 
        return;
    }
    var value = obj.options[obj.options.selectedIndex].value;

    var url = "Template_LabelView_Dialog.aspx?txt=" + escape(value) + "&path=" + path + "&act=view&d=" + Date();
    
    if (navigator.appVersion.indexOf("MSIE") == -1){
        window.open(url,'newWin','modal=yes,width=450,height=158,top=200,left=300,resizable=no,scrollbars=no');
        return;
    }else{
        showModalDialog(url,'','dialogWidth:450px;dialogHeight:158px;')
    }
}

//打开模式对话框（图片选择）
// FCK控件专用
function OpenDialogPageForFckEdit(fckID, basePath)
{
    var uri = '';
    var param = '';
    var oEditor = FCKeditorAPI.GetInstance(fckID);
    
    uri = 'V5Mall_Picture_Dailog.aspx?isfck=1&d=' + Date();
    if (navigator.appVersion.indexOf("MSIE") == -1)
    {
        this.returnAction = function(strResult)
        {
            if(strResult != null)
            {
                oEditor.InsertHtml(GetValue);
            }
        }
        param = 'alwaysRasied=yes,modal=yes,width=620,height=800,top=100,left=200,resizable=no,scrollbars=no';
        var GetValue=window.showModalDialog(uri, '_blank', param);
        oEditor.InsertHtml("<img src='" + GetValue + "'>");        
        return;
    }
    else
    {         
        //param = 'dialogWidth:550px;dialogHeight:550px;';   
        param = 'alwaysRasied=yes,modal=yes,width=620,height=800,top=100,left=200,resizable=no,scrollbars=no';    
        var GetValue = window.showModalDialog(uri, '_blank', param);        
        if (GetValue != null)
        {
            oEditor.InsertHtml("<img src='" + GetValue + "'>");            
        }
    }
}


//查看广告调用代码
function GetAdsCode(obj,ShopID)
{
        var txt = "/Upload/"+ShopID+"/show/"+obj+".js";

        var url = "V5Mall_ShopAds_Operate_Dialog.aspx?txt=" + escape(txt) + "&act=view";

        if (navigator.appVersion.indexOf("MSIE") == -1){
            window.open(url,'newWin','modal=yes,width=550,height=180,top=200,left=300,resizable=no,scrollbars=no');
            return;
        }else{
            showModalDialog(url,'','dialogWidth:550px;dialogHeight:180px;')
        }
}

