﻿///Javascript Functions

//calnedar
function calendar(obj, path) {
    showx = event.screenX - event.offsetX - 4 - 210; // + deltaX;
    showy = event.screenY - event.offsetY + 18; // + deltaY;
    newWINwidth = 210 + 4 + 18;

    retval = window.showModalDialog(path + "tools/calendar/cal.htm", "", "dialogWidth:206px;dialogHeight:221px;dialogLeft:" + showx + "px; dialogTop:" + showy + "px;status:0;help:0;scroll:0");
    if (retval != null) {
        obj.value = retval;
    }
}

//show current date
function showDate() {

    var today = new Date;
    var week = new Array(7);
 
    week[0] = "天";
    week[1] = "一";
    week[2] = "二";
    week[3] = "三";
    week[4] = "四";
    week[5] = "五";
    week[6] = "六";

    document.write(today.getYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日 星期" + week[today.getDay()]);
}

//show current date
function showSimpleDate() {
    var today = new Date;
    document.write(today.getYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日");
}

//switch button background
function switchbg(obj) {
    if (obj.className == "button_hover")
        obj.className = "button_img";
    else if (obj.className == "button_img") {
        obj.className = "button_hover";
    }
}

function openWindow(url) {
    window.open(url, null, "height=580,width=950,left=200,top=100,status=no,menubar=no,scrollbars=yes,location=no");
}

function initSearchDate() {
    if (document.forms[0].searchDate.value == "") {
        var today = new Date;
        document.forms[0].searchDate.value = today.getYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();
    }
}

function dialog(url,height) { 
    if(height==null ||height<=0)
     height=280; 
    var dialogwidth=500;
    var left=(window.screen.availWidth-dialogwidth)/2;
    var top =(window.screen.availHeight-height)/2;
    window.showModalDialog(url, window.document, "dialogWidth:"+dialogwidth+"px;dialogHeight:"+height+"px;dialogLeft:"+left+"px; dialogTop:"+top+"px;status:0;help:0;scroll:0");
    //window.open(url);
}

function dialogWithHeght(url,height) {
    window.showModalDialog(url, window.document, "dialogWidth:500px;dialogHeight:"+height+"px;dialogLeft:200px; dialogTop:100px;status:0;help:0;scroll:0");
}


function cancelReq(target) {
    var flag

    flag = confirm("确定取消申请吗?", true);
    if (flag == true) {
        document.location.href = target;
    }
}

function deleteConfirm() {
    return confirm('您确定要删除该条数据吗？');
}

function cloneConfirm() {
    return confirm('您确定要复制该条数据吗？');
}

function clearConfirm() {
    return confirm('您确定要彻底删除该条数据吗？（不可恢复）');
}

function listDeleteConfirm(repeater) {

    var checked = false;
    for (var i = 0; i < document.forms[0].elements.length; i++) {
        var e = document.forms[0].elements[i];
        if ((e.type == 'checkbox') && e.id.indexOf(repeater) == 0) {
            //alert(e.id + e.checked);
            if (e.checked) {
                checked = true;
                break;
            }
        }
    }

    if (!checked) {
        alert('请您选择要删除的数据。');
        return false;
    }
    else {
        return confirm('您确定要删除选择的数据吗？');
    }
}
