function changePref(sendpref) {
	
	//県のリストボックス初期化
	document.Form.SelectCity.options.length=0
	document.Form.SelectCity.options[0]= new Option("選択してください","選択してください");
	document.Form.SelectArea.options.length=0
	document.Form.SelectArea.options[0]= new Option("選択してください","選択してください");
	document.Form.SelectAza.options.length=0
	document.Form.SelectAza.options[0]= new Option("選択してください","選択してください");
	document.Form.SelectZip.options.length=0
	document.Form.SelectZip.options[0]= new Option("選択してください","選択してください");
	
	
	function createXMLHttpRequest() {
		try {
			return new XMLHttpRequest();
		} catch(e) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e2) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					return false;
				}
			}
		}
	}
	var httpObj = createXMLHttpRequest();
	httpObj.open("GET",'36TOKUSH-3.CSV',true);
	httpObj.onreadystatechange = function() {
    if(httpObj.readyState == 4) {
        if (httpObj.status == 200) {
			var reqest=httpObj.responseText;
			//alert(reqest);
            //reqestにデータが入っている
			var CR = String.fromCharCode(10);
			lineData = reqest.split(CR);
			
			//文字列検索
			var Objcity = new Array();
			var citySet="";
			
			for (i=0; i<lineData.length; i++) {

				if (lineData[i].indexOf('徳島県',0)>=0) {
					setCity = lineData[i].split(",");
					if (setCity[2]!=citySet){
						citySet=setCity[2];
						Objcity.push(setCity[2]);
					}
				}
			}
			
			//徳島が含まれているデータがcityに入っている
			
			for (i=0; i<Objcity.length; i++) {
				document.Form.SelectCity.options[i+1]= new Option(Objcity[i],Objcity[i]); 
			}
			if(sendpref!='選択してください'){
				document.Form.pref.value='徳島県';
				document.Form.city.value='';
				document.Form.area.value='';
				document.Form.aza.value='';
				document.Form.zipA.value='';
				document.Form.zipB.value='';
			}else{
				document.Form.pref.value='';
				document.Form.city.value='';
				document.Form.area.value='';
				document.Form.aza.value='';
				document.Form.zipA.value='';
				document.Form.zipB.value='';
			}
			
        } else {
            alert("リクエスト失敗");
        }
    }
}
httpObj.send(null);

}

//町を変更したときの処理
function changeCity(sendcity) {
	document.Form.SelectArea.options.length=0
	document.Form.SelectArea.options[0]= new Option("選択してください","選択してください");
	document.Form.SelectAza.options.length=0
	document.Form.SelectAza.options[0]= new Option("選択してください","選択してください");
	document.Form.SelectZip.options.length=0
	document.Form.SelectZip.options[0]= new Option("選択してください","選択してください");
	
	function createXMLHttpRequest() {
		try {
			return new XMLHttpRequest();
		} catch(e) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e2) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					return false;
				}
			}
		}
	}
	var httpObj = createXMLHttpRequest();
	httpObj.open("GET",'36TOKUSH-3.CSV',true);
	httpObj.onreadystatechange = function() {
    if(httpObj.readyState == 4) {
        if (httpObj.status == 200) {
			var reqest=httpObj.responseText;
			
            //reqestにデータが入っている
			var CR = String.fromCharCode(10);
			lineData2 = reqest.split(CR);
			//alert(lineData);
			//文字列検索
			var Objarea = new Array();
			var areaSet="";
			
			for (i=0; i<lineData.length; i++) {

				if (lineData2[i].indexOf("徳島県,"+sendcity,0)>=0) {
					setArea = lineData2[i].split(",");
					//alert(setArea);
					if (setArea[3]!=areaSet){
						areaSet=setArea[3];
						Objarea.push(setArea[3]);
					}
				}
			}
			
			Objarea.sort();
			for (i=0; i<Objarea.length; i++) {
				document.Form.SelectArea.options[i+1]= new Option(Objarea[i],Objarea[i]); 
			}
			
			if(sendcity!='選択してください'){
				document.Form.city.value=sendcity;
				document.Form.area.value='';
				document.Form.aza.value='';
				document.Form.zipA.value='';
				document.Form.zipB.value='';
			}else{
				document.Form.city.value='';
				document.Form.area.value='';
				document.Form.aza.value='';
				document.Form.zipA.value='';
				document.Form.zipB.value='';
			}
			
        } else {
            alert("リクエスト失敗");
        }
    }
}
httpObj.send(null);

}




//字を変更したときの処理
function changeArea(sendcity,sendarea) {
	document.Form.SelectAza.options.length=0
	document.Form.SelectAza.options[0]= new Option("選択してください","選択してください");
	document.Form.SelectZip.options.length=0
	document.Form.SelectZip.options[0]= new Option("選択してください","選択してください");
	
	function createXMLHttpRequest() {
		try {
			return new XMLHttpRequest();
		} catch(e) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e2) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					return false;
				}
			}
		}
	}
	var httpObj = createXMLHttpRequest();
	httpObj.open("GET",'36TOKUSH-3.CSV',true);
	httpObj.onreadystatechange = function() {
    if(httpObj.readyState == 4) {
        if (httpObj.status == 200) {
			var reqest=httpObj.responseText;
			
            //reqestにデータが入っている
			var CR = String.fromCharCode(10);
			lineData3 = reqest.split(CR);
			//alert(lineData3);
			//文字列検索
			var Objaza = new Array();
			var azaSet="";
			var tt="徳島県,"+sendcity+","+sendarea;
			for (i=0; i<lineData3.length; i++) {

				if (lineData3[i].indexOf(tt,0)>=0) {
					setAza = lineData3[i].split(",");
					//alert(setAza);
					if (setAza[4]!=azaSet){
						azaSet=setAza[4];
						Objaza.push(setAza[4]);
					}
				}
			}
			
			for (i=0; i<Objaza.length; i++) {
				document.Form.SelectAza.options[i+1]= new Option(Objaza[i],Objaza[i]); 
			}
			
			if(sendarea!='選択してください' & sendarea!='以下に掲載がない場合'){
				document.Form.area.value=sendarea;
				document.Form.aza.value='';
				document.Form.zipA.value='';
				document.Form.zipB.value='';
			}else{
				document.Form.area.value='';
				document.Form.aza.value='';
				document.Form.zipA.value='';
				document.Form.zipB.value='';
			}
			
        } else {
            alert("リクエスト失敗");
        }
    }
}
httpObj.send(null);

}


function changeAza(sendcity,sendarea,sendaza) {
	document.Form.SelectZip.options.length=0
	document.Form.SelectZip.options[0]= new Option("選択してください","選択してください");
	
	function createXMLHttpRequest() {
		try {
			return new XMLHttpRequest();
		} catch(e) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e2) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					return false;
				}
			}
		}
	}
	var httpObj = createXMLHttpRequest();
	httpObj.open("GET",'36TOKUSH-3.CSV',true);
	httpObj.onreadystatechange = function() {
    if(httpObj.readyState == 4) {
        if (httpObj.status == 200) {
			var reqest=httpObj.responseText;
			
            //reqestにデータが入っている
			var CR = String.fromCharCode(10);
			lineData4 = reqest.split(CR);
			
			//文字列検索
			var Objzip = new Array();
			var Objtiku = new Array();
			var zipSet="";
			var tikuSet="";
			var tt="徳島県,"+sendcity+","+sendarea+","+sendaza;
			for (i=0; i<lineData4.length; i++) {

				if (lineData4[i].indexOf(tt,0)>=0) {
					setZip = lineData4[i].split(",");
					//alert(setAza);
					if (setZip[0]!=zipSet){
						zipSet=setZip[0];
						Objzip.push(setZip[0]);
					}
					if (setZip[5]!=tikuSet){
						tikuSet=setZip[5];
						Objtiku.push(setZip[5]);
					}
				}
			}
			
			
			for (i=0; i<Objzip.length; i++) {
				document.Form.SelectZip.options[i+1]= new Option(Objzip[i],Objzip[i]); 
			}
			//for (i=0; i<Objtiku.length; i++) {
			//	document.Form.banti.options[i+1]= new Option(Objtiku[i],Objtiku[i]); 
			//}
			document.Form.banti.value=Objtiku[0];
			if(sendaza!='選択してください' & sendaza!='以下なし'){
				document.Form.aza.value=sendaza;
				document.Form.zipA.value='';
				document.Form.zipB.value='';
			}else{
				document.Form.aza.value='';
				document.Form.zipA.value='';
				document.Form.zipB.value='';
			}
			
        } else {
            alert("リクエスト失敗");
        }
    }
}
httpObj.send(null);

}

function changeZip(sendzip) {
	document.Form.zipA.value=sendzip.substring(0, 3);
	document.Form.zipB.value=sendzip.substring(3);
	
}

function nenhenkan(wareki,wanen,watuki) {
	if (wareki == '昭和'){
		wanen=parseInt( wanen );
		watuki=parseInt( watuki );
		if(wanen<=64 & wanen>0){
			seireki = wanen + 1925;
			document.Form.TikuNen.value=seireki;
			document.Form.TikuTuki.value=watuki;
		}else{
			alert("昭和は64年までです！");
		}
	}
	if (wareki == '平成'){
		wanen=parseInt( wanen );
		watuki=parseInt( watuki );
		if(wanen>0){
			seireki = 2000+(wanen - 12);
			document.Form.TikuNen.value=seireki;
			document.Form.TikuTuki.value=watuki;
		}else{
			alert("数値が以上です！");
		}
	}
	
}


//var counter = 0;

function add(counter){
	
	//alert(counter);
	// カウンタを回す
	counter++;

	var table1 = document.getElementById("table1");
	var row1 = table1.insertRow(counter);
	var cell1 = row1.insertCell(0);
	var cell2 = row1.insertCell(1);
	var cell3 = row1.insertCell(2);
	var cell4 = row1.insertCell(3);
	var cell5 = row1.insertCell(4);
	var cell6 = row1.insertCell(5);

	// class の付与は UserAgent によって
	// 挙動が違うっぽいので念のため両方の方法で
	cell1.setAttribute("class","GOUTI");
	cell2.setAttribute("class","TUBO");
	cell3.setAttribute("class","HEIHOU");
	cell4.setAttribute("class","TUBOTANKA");
	cell5.setAttribute("class","PRICE");
	cell6.setAttribute("class","HOUKOU");
	cell1.className = 'GOUTI';
	cell2.className = 'TUBO';
	cell3.className = 'HEIHOU';
	cell4.className = 'TUBOTANKA';
	cell5.className = 'PRICE';
	cell6.className = 'HOUKOU';

	var HTML1 = '<input type="text" name="GOUTI' + counter + '" value="" size="5" maxlength="10" />号地';
	var HTML2 = '<input type="text" name="TUBO' + counter + '" value="" size="10" maxlength="20" onchange="tubochange(this.value,'+counter+')"/>坪';
	var HTML3 = '<input type="text" name="HEIHOU' + counter + '" value="" size="10" maxlength="20" />m&sup2;';
	var HTML4 = '<input type="text" name="TUBOTANKA' + counter + '" value="" size="10" maxlength="20" />万円';
	var HTML5 = '<input type="text" name="PRICE' + counter + '" value="" size="10" maxlength="20" />万円';
	var HTML6 = '<select name="HOUKOU' + counter + '" id="HOUKOU"><option value="北">北</option><option value="東">東</option><option value="南">南</option><option value="西">西</option><option value="北東角地">北東角地</option><option value="南東角地">南東角地</option><option value="南西角地">南西角地</option><option value="北西角地">北西角地</option>';
	
	cell1.innerHTML = HTML1;
	cell2.innerHTML = HTML2;
	cell3.innerHTML = HTML3;
	cell4.innerHTML = HTML4;
	cell5.innerHTML = HTML5;
	cell6.innerHTML = HTML6;
	
	document.Form.Count.value=counter;
	
}

function tubochange(tubo,counter){

	aaa=tubo*=3.30579;
	aaa=aaa*100;
	aaa=Math.floor(aaa);
	aaa=aaa/100;
	//alert(document.all("HEIHOU" + counter).name);
	document.all("HEIHOU" + counter).value=aaa;

}

function del(counter){
	if(counter>0){
		var table1 = document.getElementById("table1");
		table1.deleteRow(counter);
		counter--;
		document.Form.Count.value=counter;
	}
	
}

//業者名のリロード
function reload(){
	
	function createXMLHttpRequest() {
		try {
			return new XMLHttpRequest();
		} catch(e) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e2) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					return false;
				}
			}
		}
	}
	var httpObj = createXMLHttpRequest();
	//業者名をDBから参照
	//バックエンドプログラムbackend.phpを使用
	var url = 'http://kanri.tokushima-tenant.com/template/backend.php';
	httpObj.open("GET",url,true);
	
	httpObj.onreadystatechange = function() {
		//alert(httpObj.readyState);
		
		if(httpObj.readyState == 4) {
			if (httpObj.status == 200) {
				//読み込み成功時
				var reqest=httpObj.responseText;
				//alert(reqest);
				var GC = String.fromCharCode(10);
				gyousya = reqest.split(GC);
				//alert(gyousya.length);
				
				document.Form.Origin.options.length=0
				document.Form.Introduction.options.length=0
				for (i=0; i<gyousya.length; i++) {
					document.Form.Origin.options[i]= new Option(gyousya[i],gyousya[i]); 
					document.Form.Introduction.options[i]= new Option(gyousya[i],gyousya[i]); 
				}
				
			}
		}
	
	}
	
	httpObj.send(null);

}


function k31l2sklist(count){
  myCnt=0;
  for (i=0; i<=count; i++){         // チェックボックスの数分ループ
    if (document.Form.elements[i].checked == true){ // チェックはオンか？
      myCnt++;                                        // チェック数 加算
    }
  }
  
  if(myCnt>64){
	  alert("チェック数エラー\nリスト部でチェックできるのは64件までです！\n現在"+myCnt+"件");
  }
  
  document.Form.Lkensu.value=myCnt;
  
}

function k31l2sksyousai(count){
	
  myCnt=0;
  for (i=0; i<=count; i++){         // チェックボックスの数分ループ
    if (document.Form.elements[i+count+1].checked == true){ // チェックはオンか？
      myCnt++;                                        // チェック数 加算
    }
  }
  if(myCnt>2){
	  alert("チェック数エラー\n詳細部でチェックできるのは2件までです！\n現在"+myCnt+"件");
  }
  document.Form.RUkensu.value=myCnt;
  
}


function k31l8snlist(count){
	
  myCnt=0;
  for (i=0; i<=count; i++){         // チェックボックスの数分ループ
    if (document.Form.elements[i].checked == true){ // チェックはオンか？
      myCnt++;                                        // チェック数 加算
    }
  }
  if(myCnt>45){
	  alert("チェック数エラー\n詳細部でチェックできるのは45件までです！\n現在"+myCnt+"件");
  }
  document.Form.Lkensu.value=myCnt;
  
}

function k31l8snlist2(count,countsinai){
	
  myCnt=0;
  for (i=0; i<=count; i++){         // チェックボックスの数分ループ
    if (document.Form.elements[i+countsinai+1].checked == true){ // チェックはオンか？
      myCnt++;                                        // チェック数 加算
    }
  }
  if(myCnt>20){
	  alert("チェック数エラー\n詳細部でチェックできるのは20件までです！\n現在"+myCnt+"件");
  }
  document.Form.Lkensu2.value=myCnt;
  
}


function k31l8snsksyousai(count,countsinai,countitano){
	
  myCnt=0;
  for (i=0; i<=count; i++){         // チェックボックスの数分ループ
    if (document.Form.elements[i+countsinai+countitano+2].checked == true){ // チェックはオンか？
      myCnt++;                                        // チェック数 加算
    }
  }
  if(myCnt>8){
	  alert("チェック数エラー\n詳細部でチェックできるのは8件までです！\n現在"+myCnt+"件");
  }
  document.Form.RUkensu.value=myCnt;
  
}













