var sumTime_sumTime_sumTime = 5;
var showObj_showObj_showObj;
var pagePath_pagePath_pagePath;

// 根据id获取对象
function getObjById(id){
    return window.document.getElementById(id);
}

// 判断数字对应的建
function isNumOneKey(num){
    if (event.keyCode == num) {
        return true;
    }
    return false;
}

// 刷新
function reload(){
    window.location.reload()
}

function resetForm(id){
    getObjById(id).reset();
}

// 提交form表单?
function submitForm(formName){
    var myform = getObjById(formName);
    myform.submit();
}

// 获取input元素的值
function getInputValue(id){
    return getObjById(id).value;
}

// 跳转到另一个页面
function toPage(pagePath){
    window.location.href = pagePath;
}



function openWindow(url, winName){
    window.open(url, winName);
}


function openWin(url){
    openWindow(url, "_blank");
}


// input是否为空
function isNull(id){
    if (getObjById(id).value == null) 
        return true;
    return false;
}

// input是否为空字符串
function isVoid(id){
    if (trim(getObjById(id).value) == "") 
        return true;
    return false;
}

// inputԪ获取焦点
function inputFocus(id){
    getObjById(id).focus();
}

// 选中input的文本Ԫ
function inputSelect(id){
    getObjById(id).select();
}

// 判断两个input元素的值是否一致
function isContentSame(id1, id2){
    if (getObjById(id1).value == getObjById(id2).value) 
        return true;
    return false;
}

// 验证input元素是否为空的字符串
function checkAndFocus(id, message){
    if (isNull(id) || isVoid(id)) {
        alert(message);
        inputFocus(id);
        return true;
    }
    return false;
}

var sumTime_sumTime_sumTime = 5;
var showObj_showObj_showObj;

// 自动跳到某页面
function autoToPage(pagePath, showObjId, sumTime){
    sumTime_sumTime_sumTime = sumTime;
    showObj_showObj_showObj = showObjId;
    pagePath_pagePath_pagePath = pagePath;
    setInnerHTML();
}

// 设置指定对象的InnerHTML
function setInnerHTML(){
    if (sumTime_sumTime_sumTime <= 0) {
        window.location = pagePath_pagePath_pagePath;
        return;
    }
    
    getObjById(showObj_showObj_showObj).innerHTML = sumTime_sumTime_sumTime;
    sumTime_sumTime_sumTime--;
    setTimeout(setInnerHTML, 1000);
}

// 设置指定id的InnerHTML
function setInnerHTMLById(id, content){
    getObjById(id).innerHTML = content;
}

// 设置某对象的是否可见
function setVisible(id, isDisplay){

    if (isDisplay) {
        document.getElementById(id).style.display = 'block';
    }
    else {
        document.getElementById(id).style.display = 'none';
    }
}

// ---------------Ajax的技术的代码-------------------------------

// 创建Ajax的请求对象
function createRequest(){
    var ActiveXName = ['MSXML2.XMLHttp.7.0', 'MSXML2.XMLHttp.6.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'Msxml2.XMLHTTP', 'MSXML.XMLHttp', 'Microsoft.XMLHTTP'];
    if (window.ActiveXObject) {
        for (var i = 0; i < ActiveXName.length; i++) {
            try {
                var ajaxObj = new ActiveXObject(ActiveXName[i]);
            } 
            catch (e) {
                continue;
            }
        }
        return ajaxObj;
    }
    else {
        try {
            ajaxObj = new XMLHttpRequest();
        } 
        catch (e) {
            alert('本系统的Ajax暂不支持你的浏览器，请跟换其它版本的浏览器');
        }
        return ajaxObj;
    }
}

function doService(id, url, method, bool){
    var request = createRequest();
    request.onreadystatechange = function(){
    
        if (request.readyState == 4) {
            var html = request.responseText;
            if (id != null && id != "") {
                document.getElementById(id).innerHTML = html;
            }
            
        }
        else {
            if (id != null && id != "") {
                document.getElementById(id).innerHTML = "请 稍 等...";
            }
        }
    }
    request.open(method, url, bool);
    request.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
    request.send(null);
}

function doPost(id, url, bool){
    doService(id, url, "post", bool);
}

function doGet(id, url, bool){
    doService(id, url, "get", bool);
}


// 去左空格
function ltrim(s){
    return s.replace(/^\s*/, "");
}

// 去右空格
function rtrim(s){
    return s.replace(/\s*$/, "");
}

// 去左右空格
function trim(s){
    return ltrim(rtrim(s));
}
