﻿function areaNode(name, zipcode, telzip) {
    this.name = name;
    this.zipcode = zipcode;
    this.telzip = telzip;
}


function myVillage(villages) {

    myareaTmp = new Array();
    for (var i = 0; i < villages.length; i += 3) {
        myareaTmp[i / 3] = new areaNode(villages[i], villages[i + 1], villages[i + 2]);
    }
    return myareaTmp;

}


function myCity(city, citycode, villages) {
    this.city = city;
    this.citycode = citycode;
    this.villages = new myVillage(villages);
}

//將縣市下拉選項列出
function printCity(obj, selitm) {
    obj.length = 1;
    for (var j = 0; j < ct.length; j++) {
        k = ct[j];
        obj.length = j + 2;
        obj[j + 1].text = k.city;
        obj[j + 1].value = k.city;

        if (k.city == selitm) {
            obj[j + 1].selected = true;
        }
    }
}

//選擇縣市後,將鄉鎮地區下拉選項列出
function selCity(cityObj, villObj, selno) {

    var idx = cityObj.selectedIndex;
    var cityName = cityObj[idx].text;
    villObj.length = 1;

    for (var j = 0; j < ct.length; j++) {
        k = ct[j];
        if (k.city == cityName) {
            printVillage(villObj, j, selno);
            if (villObj.length == 2) {
                //villObj.selectedIndex = 1;//
            }
            return;
        }
    }
}

function printVillage(villObj, cityIdx, selno) {
    villObj.length = 1;
    k = ct[cityIdx];

    for (var i = 0; i < k.villages.length; i++) {
        villObj.length = i + 2;
        villObj[i + 1].text = k.villages[i].name;
        villObj[i + 1].value = k.villages[i].zipcode;

        if (selno == villObj[i + 1].value) {
            villObj[i + 1].selected = true;
        }
    }
}



/*此function會傳回對應的電話區碼==>telObj
但電話區碼的 text 必須為一陣列*/
//ok
function selVillage(cityObj, villObj, telObj) {
    var cityName = cityObj[cityObj.selectedIndex].value;
    var villageName = villObj[villObj.selectedIndex].value;

    for (var j = 0; j < ct.length; j++) {
        k = ct[j];
        if (k.city == cityName) {

            for (var i = 0; i < k.villages.length; i++) {

                if (k.villages[i].zipcode == villageName) {
                    telObj.value = k.villages[i].telzip;
                    return;
                }
            }
        }
    }
}




function bodyLoad(xx, yy) {
    var ObjFrm = document.form2;
    printCity(ObjFrm.cty, xx);
    selCity(ObjFrm.cty, ObjFrm.ara, yy);
    //selVillage(ObjFrm.cty,ObjFrm.ara,yy);
}


function findObj(theObj, theDoc) {
    var p, i, foundObj;

    if (!theDoc) theDoc = document;
    if ((p = theObj.indexOf("?")) > 0 && parent.frames.length) {
        theDoc = parent.frames[theObj.substring(p + 1)].document;
        theObj = theObj.substring(0, p);
    }
    if (!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
    for (i = 0; !foundObj && i < theDoc.forms.length; i++)
        foundObj = theDoc.forms[i][theObj];
    for (i = 0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
        foundObj = findObj(theObj, theDoc.layers[i].document);
    if (!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

    return foundObj;
}


function chk() {
    return false;
}



var TimeID;
var TimeID2;
var to_y = 69;
var to_y2 = 0;
var to_yy = 0;


function sGO() {
    var ml1 = findObj('l1');
    if (ml1 != null) {
        if (!document.all) {
            ml1.style.left = 0 + "px";
            ml1.style.top = to_y + "px";
        } else {
            ml1.style.left = 0 + "px";
            ml1.style.top = (to_y + document.body.scrollTop) + "px";
        }
    }
    var mmymask = findObj('mymask');
    if (mmymask != null) {
        if (!document.all) {
            mmymask.style.left = 0 + "px";
            mmymask.style.top = to_yy + "px";
        } else {
            mmymask.style.left = 0 + "px";
            mmymask.style.top = (document.body.scrollTop) + "px";
        }
    }

    //l1.style.display = "block";//
    TimeID = setInterval(setPlace, 100);


}

function setPlace() {
    clearInterval(TimeID);
    var ml1 = findObj('l1');
    if (ml1 != null) {
        var now_y = parseInt(ml1.style.top.substr(0, ml1.style.top.length - 2));
        if (!document.all) {
            ml1.style.top = (now_y + (to_y + window.pageYOffset - now_y) / 5) + "px"; self.status = 'fx';
        } else {

            if (document.documentElement && document.documentElement.scrollTop)
            { ml1.style.top = (now_y + (to_y + document.documentElement.scrollTop - now_y) / 5) + "px"; }
            else
            { ml1.style.top = (now_y + (to_y + document.body.scrollTop - now_y) / 5) + "px"; }
        }
    }
    var ml2 = findObj('mymask');
    if (ml2 != null) {
        var now_y = parseInt(ml2.style.top.substr(0, ml2.style.top.length - 2));
        if (!document.all) {
            ml2.style.top = (now_y + (to_yy + window.pageYOffset - now_y) / 5) + "px"; self.status = 'fx';
        } else {

            if (document.documentElement && document.documentElement.scrollTop)
            { ml2.style.top = (now_y + (to_yy + document.documentElement.scrollTop - now_y) / 5) + "px"; }
            else
            { ml2.style.top = (now_y + (to_yy + document.body.scrollTop - now_y) / 5) + "px"; }
        }
    }
    TimeID = setInterval(setPlace, 100);

}

function calendar(t) {
    var mll;
    mll = eval('document.' + t + '.value');
    var sPath = 'calendar.aspx?aaa=' + mll + '&obj=' + t;
    window.open(sPath, 'calendar', 'width=180,height=200px');

}

function mtest(m1, m2) {
    var sl = document.getElementById("mng_main");
    var aa = document.getElementById("mymask");
    var bb = document.getElementById("ifm");
    if (aa != null) {
        if (navigator.appName == "Microsoft Internet Explorer") {
            aa.style.width = document.documentElement.clientWidth;
            aa.style.height = document.documentElement.clientHeight;
            //bb.style.width = document.documentElement.clientWidth - 20;
            var mver = navigator.userAgent.toLowerCase();

            if (bb != null && mver.indexOf('msie 6.0') < 0) { bb.style.height = document.documentElement.clientHeight - 20; }



        }
        else {
            aa.style.height = document.body.clientHeight + 'px';
            aa.style.width = document.body.clientWidth + 'px';
            if (bb != null) { bb.style.height = document.body.clientHeight - 20 + 'px'; }
            //bb.style.width = document.body.clientWidth -20 + 'px';
            //sl.style.width = 0 + 'px';
            //sl.style.height = 0 + 'px';
        }

        //alert(navigator.appName);
        aa.style.display = "block";
        //var bb = document.getElementById("ifm");
        bb.src = m1 + m2;
    }

}

function resizeme() {
    var aa = document.getElementById("mymask");
    var bb = document.getElementById("ifm");
    if (aa != null) {
        if (aa.style.display != "none") {
            if (navigator.appName == "Microsoft Internet Explorer") {
                aa.style.width = document.documentElement.clientWidth;
                aa.style.height = document.documentElement.clientHeight;
                //bb.style.width = document.documentElement.clientWidth - 20;
                var mver = navigator.userAgent.toLowerCase();
                if (bb != null && mver.indexOf('msie 6.0') < 0) { bb.style.height = document.documentElement.clientHeight - 20; }


            }
            else {
                aa.style.height = document.body.clientHeight + 'px';
                aa.style.width = document.body.clientWidth + 'px';
                bb.style.height = document.body.clientHeight - 20 + 'px';
                //bb.style.width = document.body.clientWidth -20 + 'px';
            }
        }
    }
    // alert('resize');
}
function closeme() {
    var sl = document.getElementById("mng_main");
    var aa = document.getElementById("mymask");
    var bb = document.getElementById("ifm");
    if (bb != null) { bb.src = ""; }
    if (aa != null) aa.style.display = "none";



}

window.onresize = resizeme;