﻿var __txtArray = null;
var _btnArray = null;
function initAutoFormStyle()
{        
    var inputArry;
    inputArry = document.getElementsByTagName("input");
    textArry = document.getElementsByTagName("textarea");
    for(var i=0;i<inputArry.length+textArry.length;i++)
    {
        var tmpInput = null;
        if(i< inputArry.length)
        {
            tmpInput = inputArry[i];
            if((tmpInput.type == 'text' || tmpInput.type == 'password' || tmpInput.type == 'file' )&& (tmpInput.disabled == false||tmpInput.readOnly==false))
            {
                setEvent(tmpInput);
            }
        }
        else
        {
            tmpInput = textArry[i-inputArry.length];
            setEvent(tmpInput);
        }
    }
    
    var btnArray;
    btnArray = document.getElementsByTagName("button");
    inputArry = document.getElementsByTagName("input");
    for(var i=0;i<inputArry.length+btnArray.length;i++)
    {
        tmpInput = null;
        if(i< inputArry.length)
        {
            tmpInput = inputArry[i];
            if((tmpInput.type == 'button' || tmpInput.type == 'submit' )&& (tmpInput.disabled == false||tmpInput.readOnly==false))
            {
                setButton(tmpInput);
            }
        }
        else
        {
            tmpInput = btnArray[i-inputArry.length ];
            setButton(tmpInput);
        }
    }
}
function setButton(obj)
{
//    var newClassName = 'ButtonStyle';
//    var focusClassName = 'ButtonStyleHover';
    if(obj!=null && typeof(obj)!='undefined')
    {
        obj.className = 'ButtonStyle';
        obj.onmouseout = function(){
            this.className = 'ButtonStyle';
        }
        obj.onmouseover =function(){
            this.className = 'FocusButtonStyle';
        }
    }
}
function setEvent(obj)
{
//    var newClassName = 'TextBoxStyle';
//    var focusClassName = 'FocusTextBox';
//    if(obj.style.className != undefined)
//    {
//        newClassName = obj.style.className + ' ' + newClassName;
//        focusClassName =  obj.style.className + ' ' + focusClassName;
//    }
    obj.className = 'TextBoxStyle';
    obj.onblur = function(){
        this.className = 'TextBoxStyle';
    }
    obj.onfocus =function(){
        this.className = 'FocusTextBox';
    }
}
function CheckDate(obj)
{
    var sDate = obj.value;
    var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31];
    var iaDate = new Array(3);
    var year, month, day;
    if (arguments.length != 1)
    {
        alert("程序里调用的参数有错，\n只能一个参数！");
        obj.focus();
        obj.select();
        return false;
    }
    iaDate = sDate.toString().split("-");
    if(obj.value != "")
    {
        if(iaDate.length != 3)
        {
            alert("日期格式错误，正确格式：2000-01-01");
            obj.focus();
            obj.select();
            return false;
        }
        if (iaDate[1].length > 2 || iaDate[2].length > 2)
        {
            alert("日期格式错误，正确格式：2000-01-01或2000-1-1");
            obj.focus();
            obj.select();
            return false;
        }
        year = parseFloat(iaDate[0]);
        month = parseFloat(iaDate[1]);
        day=parseFloat(iaDate[2]);
        if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
        if (month < 1 || month > 12)
        {
            alert("月份错误，月份范围应在1-12之间!");
            obj.focus();
            obj.select();
            return false;
        }
        if (day < 1 || day > iaMonthDays[month - 1])
        {
            alert("日期错误，日期范围应在1-" + iaMonthDays[month - 1] + "之间");
            obj.focus();
            obj.select();
            return false;
        }

//        var a=/^\d{4}-((0[1-9]{1})|([1-9]{1})|(1[0-2]{1}))-((0[1-9]{1})|([1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/;

//        if (!a.test(document.all("aa").value)){
//        alert("日期格式错误，正确格式：2000-01-01或2000-1-1")
//        obj.focus();
//        obj.select();
//        return false;
//        }
//        else
//            return true;
    }
    return true;
} 
//Date Compare
function timeRather(beginTime, endTime)
{
    var beginTemp = beginTime.split(" ");
    var endTemp = endTime.split(" ");
    
    if(beginTemp[1] == null){
        return judgement(beginTime, endTime);    
    }else{
        if(beginTemp[0] == endTemp[0]){
            return judgement(beginTemp[1], endTemp[1]);
        }
        return judgement(beginTemp[0], endTemp[0]);
    }
}


function reSolution(r)
{
    var splitTemp = r.split("-");
    if(splitTemp[1] == null){
        splitTemp = r.split(":");
    }
    return splitTemp;
}


function judgement(beginTime, endTime)
{
    var i=0, d1, d2;
    d1 = reSolution(beginTime);
    d2 = reSolution(endTime);
    for(i in d1){
        if(d1[i] <d2[i]){
            return true;
        }
        if(d1[i] >d2[i]){
            return false;
        }
    }
    return false;
}
function parentResize()
{
    parent.moveTo(0,0); 
    parent.resizeTo(screen.availWidth,screen.availHeight);  
    parent.resizeIFrameHeight();
}