/*document.writeln('<script language=javascript src="http://online.xywy.com/html/zh/wow/log.js?MVYNSH"></script>');*/
﻿var isMoveLoadding = false;
function ShowLoadding() {
    var div = document.getElementById('divLoadding');
    if (div) { }
    else {
        var body = document.getElementsByTagName('body').item(0);
        div = document.createElement('div');
        div.id = "divLoadding";
        div.innerHTML = "正在执行，请稍候……";
        body.appendChild(div);
    }
    isMoveLoadding = true;
    moveLoadding();
}

function moveLoadding() {
    var div = document.getElementById('divLoadding');
    if (isMoveLoadding) {
        div.style.right = '0px';
        div.style.top = document.documentElement.scrollTop + 'px';
        div.style.display = '';
        setTimeout('moveLoadding()', 300);
    }
}
function HideLoadding() {
    isMoveLoadding = false;
    var div = document.getElementById('divLoadding');
    div.style.display = 'none';
}
function ClearErrorMsg() {
    $("div.msg").each(function() { $(this).html(''); $(this).hide(); });
}
//给Checkbox提供全选功能
//mybox全选控件
//name被全选的控件匹配字符
function choose(mybox, name) {
    if (mybox.checked) {

        $("input[name*='" + name + "']").attr("checked", true);

    }
    else { $("input[name*='" + name + "']").attr("checked", false); }

}
//获得checked选中的Value
function Strall(name) {
    var all = "";

    $("input[name*='" + name + "']").each(
	function() {
	    if ($(this).attr('checked')) {
	        all = $(this).val() + "-" + all;

	    }

	}

	)
    all = all.substring(0, all.length - 1);
    return all;

}
//检查Checkbox至少要选中一条
function IsCheckedOne(name) {

    var one = false;
    $("input[name*='" + name + "']").each(function() { if ($(this).attr('checked')) one = true; });
    return one;
}
function AjaxPost(url, frm, cnfirm, needchecked) {
    ClearErrorMsg();
    var doit = true;
    if (needchecked == true) {
        if (!IsCheckedOne()) {
            alert('请至少选择一条记录');
            doit = false;
            return;
        }
    }
    if (cnfirm == true) {
        if (!confirm('你确定要执行该操作？')) {
            doit = false;
        }
    }
    if (doit) {
        Ajax(url, frm, 'POST', ShowResult, true);
    }
}
function ShowResult(data) {


    var result = eval('(' + data + ')');

    if (result != undefined) {
        switch (result.method) {
            case "alert":
                alert(result.data);
                break;
            case "goto":
                window.location.href = result.data;
                break;
            case "reload":
                if (result.data != '')
                    alert(result.data);
                location.reload();
                break;
            case "Jsmethod":
                eval(result.data); break;
            case "send_goto":
                var doit = true;
                if (result.cnfirm == 'True') {
                    if (!confirm(result.data)) {
                        doit = false;
                      //  location.reload();
                    }
                }

                if (doit) {


					  //  window.location.href = result.Url;
                    window.open(result.Url, "投票调查", "height=650,width=780,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no");

                }



                break;
        }
    }
}
function AjaxGet(url, func) {
    Ajax(url, '', 'GET', func, true);
}
function AjaxLoad(url, div, func) {
    Ajax(url, div, 'LOAD', function(data) { $('#' + div).html(data); if (func) { func(data); } }, false);
}
function Ajax(url, param, type, func, showloadding) {
    if (showloadding) { ShowLoadding(); }
    if (url.indexOf('?') == -1) {
        url += "?";
    }
    else
        url += "&";
    url += "timeStamp=" + new Date().getTime()

    if (type == 'GET' || type == 'LOAD') {
        $.ajax({ url: url,
            type: 'GET',
            cache: false,
            timeout: 20000,
            error: function() { if (param != '') { $('#param').html('数据加载失败'); } else { alert('数据加载失败，可能是网络连接问题或者服务器错误。'); } },
            success: func,
            complete: function() { if (showloadding) { HideLoadding(); } }
        });
    } else if (type == 'POST') {
        $('.submit').each(function() { $(this).attr('title', $(this).html()); $(this).html('请稍候'); $(this).attr('disabled', 'disabled'); });
        $.ajax({ url: url,
            type: 'POST',
            data: $('#' + param).serialize(),
            cache: false,
            timeout: 20000,
            error: function() { alert('数据加载失败，可能是网络连接问题或者服务器错误。'); },
            success: func,
            complete: function() { if (showloadding) { HideLoadding(); } $('.submit').each(function() { $(this).html($(this).attr('title')); $(this).attr('disabled', false); }); }
        });
    }
}

var oldDiv = new Object();
function TextOnfocus(obj) {
    if (oldDiv.id != null) {
        $(oldDiv.id).className = oldDiv.className;
    }
    var infoid = obj.id + "Info";
    var infoDiv = document.getElementById(infoid);
    oldDiv.id = infoDiv.id;
    oldDiv.className = infoDiv.className;
    infoDiv.className = "regon";
}
//弹出dialog
var dialogTitle;
function openWin(title, param, width, height) {
    if (document.getElementById('dialog')) {
        $("#dialog").dialog("destroy").remove();
    }
    AjaxGet(param, function(t) {
        var body = document.getElementsByTagName('body').item(0);
        var div = document.createElement('div');
        div.id = "dialog";
        div.innerHTML = t;
        body.appendChild(div);
        $("#dialog").dialog({ title: title, width: width == undefined ? 'auto' : width, height: height == undefined ? 'auto' : height, resizable: false, bgiframe: false, modal: true, dialogClass: 'alert' });
    });
}
