﻿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;

function sGO() 
{
	var ml1 = findObj('l1');
	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";
	}
//l1.style.display = "block";//
	TimeID = setInterval(setPlace, 100);
	
	
}

function setPlace() {
	clearInterval(TimeID);
	var ml1 = findObj('l1');
	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";}
	}
	
	
	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');	

}
