function changeday(getday){
	var monthday = new Array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22",
		"23","24","25","26","27","28","29","30","31");
	var theyear = document.form1.select1;
	var themonth = document.form1.select2;
	var theday = document.form1.select3;
	var tmp = new Date(theyear.value, themonth.value, 0); 
	var selectday = (getday) ? getday - 1 : theday.value - 1;
	var haveday = tmp.getDate();
	
	for (var m= 0; m < theday.options.length; m++) {
		theday.options[m] = null;
	}
	for (var i = 0; i < haveday; i++) {
		theday.options[i] = new Option(monthday[i],monthday[i]);
		if (i == selectday){
			theday.options[i].selected = true;
		}
	}
}

function getthedate(thedate){
	var theform = document.form1;
	
	theyear = thedate.substr(0,4);
	themonth = thedate.substr(5,2);
	theday = thedate.substr(8,2);
	
	for(var i=0;i<theform.select1.length;i++){
		if(theform.select1.options[i].value == theyear){
			theform.select1.options[i].selected = true;
			break;
		}
	}
	for(var i=0;i<theform.select2.length;i++){
		if(theform.select2.options[i].value == themonth){
			theform.select2.options[i].selected = true;
			break;
		}
	}
	changeday(theday);
}

function ChangeGender(radio,gvalue){
	for(var i=0;i<radio.length;i++){
		if(radio[i].value == gvalue){
			radio[i].checked = true;
			break;
		}
	}
}

function visablebox(ans){
	var theform = document.form1;
	if(ans == 'true'){
		Ext.get('deliverydate').dom.style.visibility = 'visible';
		Ext.get('deliverytime').dom.style.visibility = 'visible';
		Ext.get('deliverydate').dom.style.display = 'block';
		Ext.get('deliverytime').dom.style.display = 'block';
	}else{
		Ext.get('deliverydate').dom.style.visibility = 'hidden';
		Ext.get('deliverytime').dom.style.visibility = 'hidden';
		Ext.get('deliverydate').dom.style.display = 'none';
		Ext.get('deliverytime').dom.style.display = 'none';
	}
	ChangeGender(theform.assign,ans);
}

function visablebox2(ans){
	var theform = document.form1;
	if(ans == 'true'){
		Ext.get('visapparatus1').dom.style.visibility = 'visible';
		Ext.get('visapparatus2').dom.style.visibility = 'visible';
		Ext.get('visapparatus1').dom.style.display = 'block';
		Ext.get('visapparatus2').dom.style.display = 'block';
	}else{
		Ext.get('visapparatus1').dom.style.visibility = 'hidden';
		Ext.get('visapparatus2').dom.style.visibility = 'hidden';
		Ext.get('visapparatus1').dom.style.display = 'none';
		Ext.get('visapparatus2').dom.style.display = 'none';
	}
	ChangeGender(theform.NYapparatus,ans);
}

function visablebox3(ans){
	var theform = document.form1;
	if(ans == 'true'){
		Ext.get('C_Data').autoHeight(true);
		Ext.get('C_Data').show(true);
		Ext.get('CName').dom.mask = "公司名稱";
		Ext.get('MAddress').dom.mask = "公司地址";
		Ext.get('CTel').dom.mask = "公司電話,2";
		Ext.get('CFax').dom.mask = "公司傳真,2";
	}else{
		Ext.get('C_Data').hide(true);
		Ext.get('C_Data').dom.style.display = 'none';
		Ext.get('C_Data').dom.style.visibility = 'hidden';
		Ext.get('C_Data').setHeight(1,true);
		Ext.get('CName').dom.mask = "";
		Ext.get('MAddress').dom.mask = "";
		Ext.get('CTel').dom.mask = "";
		Ext.get('CFax').dom.mask = "";
	}
}

function ChangeAddress(select1,select2,text1,text2,zipvalue){
	var checkAddress = false;
	for(var i=0;i<ZipCode.length;i++){
		for(var j=0;j<ZipCode[i].length;j++){
			if(ZipCode[i][j] == zipvalue){
				select1.options[i].selected = true;
				changeZone(select1, select2, text1);
				select2.options[j].selected = true;
				text1.value = zipvalue;
				text2.value = text2.value.replace(County[i],"");
				text2.value = text2.value.replace(Zone[i][j],"");
				checkAddress = true;
				break;
			}
			if(checkAddress == true){
				break;
			}
		}
	}
}

function getmember(gender,bir,Mgender,Zip,MZip){
	var theform = document.form1;
	
	ChangeAddress(theform.countyText,theform.area,theform.zipcode,theform.Address,Zip);
	ChangeAddress(theform.mcountyText,theform.marea,theform.mzipcode,theform.MAddress,MZip);
	ChangeGender(theform.Gender,gender);
	ChangeGender(theform.MGender,Mgender);
	getthedate(bir);
}

function getorderdata(Mgender,bir,MZip,assign,paytype){
	var theform = document.form1
	
	ChangeAddress(theform.countyText,theform.area,theform.zipcode,theform.MAddress,MZip);
	ChangeGender(theform.MGender,Mgender);
	ChangeGender(theform.paytype,paytype);
	if(assign == '' || assign == 'false'){
		visablebox('false');
	}else{
		visablebox('true');
	}
	if(theform.Apparatus.value == ''){
		visablebox2('false');
	}else{
		visablebox2('true');
	}
	getthedate(bir);
}

function checkDouble(){
	var theuser = Ext.get('Username').dom.value
	var theword = Ext.get('doubleid')
	search_user = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({url: 'getview.php?Type=checkDouble&Thevalue='+theuser}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			id: 'ID'
		},[ 'ID', 'Username']),
		remoteSort: false
	});
	search_user.on('load', function() {
		if(search_user.getCount(search_user) > 0){
			theword.dom.innerHTML = "該帳號已有人使用";
			theword.show(true);
		}else{
			theword.hide(true);
			theword.dom.innerHTML = "";
		}
	});
	search_user.load({params : { 
		"Thevalue":theuser
	}});
}

function fromcheck(){
	
	
}