//CHARSET=utf-8
//author pm studio/toshio maeoka

//cookie script

function getCookie(name){
	papa=document.cookie+";";
	papa1=papa.indexOf(name,0);
	if (papa1!=-1){
		papa=papa.substring(papa1,papa.length);
		start=papa.indexOf("=",0)+1;
		end=papa.indexOf(";",start);
		return(unescape(papa.substring(start,end)));
	}
	return("");
}

function setCookie(name,val){
	papa=name+"="+escape(val)+";";
	papa+="expires=Tue, 01 Jan 2019 12:00:00 GMT";
	document.cookie=papa;
}

function delCookie() {
	tmp=document.cookie.split(";");
    acDate=new Date();
    acDate.setYear(acDate.getYear()-1);
    for(i=0;i<tmp.length;i++){
       temp1=tmp[i].split("=")[0];
       document.cookie=temp1+"=;acDate="+acDate.toGMTString();
	}
}

function deleteCookie(name) {
	time="expires=Tue, 01 Jan 2001 12:00:00 GMT"
	var cval=getCookie(name);
	num=escape(cval)
	if (cval !=null) 
		document.cookie=name+"="+num +";"+ time;
}

//send_data
function send(){
	document.DocumentRequestForm.submit();
}

function resetData(){
	document.contact.reset();
	document.DocumentRequestForm.reset()
}

var pm_1
var pm_2
var pm_3
var pm_4
var pm_5
var pm_6
var pm_7
var pm_8
var pm_9
var pm_10
var pm_11
var pm_12
var pm_13
var pm_14
var pm_15
var pm_16
var pm_17
var pm_18
var pm_19
var pm_20
var pm_21
var pm_22
var pm_23
var pm_24
var pm_25
var pm_26
var pm_27

for( a=1; a<27; a++ ) {
	pmc='pm_'+a
	pmc=null
}

var errorMessage
var errorNum
var en
var agree_a

errorMessage=""
errorNum=""
var agree_a="true"

function sendData(){
	createOrder_4();
	agree_a=document.getElementById("agr").value
	//alert(agree_a)
	if (agree_a=='true') {
		createOrder_1();
		createOrder_2();
		createOrder_3();

		addA=document.getElementById("addr").value
		addB=document.getElementById("address4").value
		document.getElementById("address2").value=addA+addB

		zip1=document.getElementById("zip1").value
		zip2=document.getElementById("zip2").value
		document.getElementById("zipcode").value=zip1+zip2

		pm_9b=zip1
		pm_9c=zip2
		pm_12b=addA

		pm_1=document.getElementById("family_name").value
		pm_2=document.getElementById("first_name").value

		pm_3=document.getElementById("family_name_kana").value
		pm_4=document.getElementById("first_name_kana").value

		pm_5=document.getElementById("email").value
		pm_6=document.getElementById("tel_area").value
		pm_7=document.getElementById("tel_local").value
		pm_8=document.getElementById("tel_no").value
		pm_9=document.getElementById("zipcode").value

		pm_10=document.getElementById("address1").value
		pm_11=document.getElementById("address2").value
		pm_12=document.getElementById("address4").value

		pm_13=document.getElementById("objectcodes").value
		pm_13b=document.getElementById("objectcodes_b").value

		pm_14=document.getElementById("family_number").value
		pm_15=document.getElementById("birthday").value

		pm_16=document.getElementById("person_job_code").value
		pm_17=document.getElementById("person_income_code").value
		pm_18=document.getElementById("deposit").value
		pm_19=document.getElementById("hope_price_code").value
		pm_20=document.getElementById("dwelling_type").value
		pm_21=document.getElementById("hope_Room_Arrangement_code").value
		pm_22=document.getElementById("hope_area").value

		pm_16b=document.getElementById("person_job_code_b").value
		pm_17b=document.getElementById("person_income_code_b").value
		pm_18b=document.getElementById("deposit_b").value
		pm_19b=document.getElementById("hope_price_code_b").value
		pm_20b=document.getElementById("dwelling_type_b").value
		pm_21b=document.getElementById("hope_Room_Arrangement_code_b").value
		pm_22b=document.getElementById("hope_area_b").value

		pm_23=document.getElementById("acknowledgment_medium_code").value
		pm_23b=document.getElementById("acknowledgment_medium_code_b").value

		pm_24=document.getElementById("acknowledgment_medium_other").value
		pm_25=document.getElementById("free_Message").value
		pm_26=document.getElementById("information_mail_flg").value
		replaceNum()
		errorMes();
		if (errorNum==5) {
			//alert('go')
			if(pm_3=="_") pm_3=""
			if(pm_4=="_") pm_4=""
			if(pm_6=="_") pm_6=""
			if(pm_7=="_") pm_7=""
			if(pm_8=="_") pm_8=""
			if(pm_12=="_") pm_12=""
			if(pm_16=="_") pm_16=""
			if(pm_17=="_") pm_17=""
			if(pm_18=="_") pm_18=""
			if(pm_19=="_") pm_19=""
			if(pm_23=="_") pm_23=""
			if(pm_24=="_") pm_24=""
			if(pm_25=="_") pm_25=""

			document.DocumentRequestForm.familyName.value=pm_1
			document.DocumentRequestForm.firstName.value=pm_2
			document.DocumentRequestForm.familyNameKana.value=pm_3
			document.DocumentRequestForm.firstNameKana.value=pm_4
			document.DocumentRequestForm.email.value=pm_5
			document.DocumentRequestForm.telArea.value=pm_6
			document.DocumentRequestForm.telLocal.value=pm_7
			document.DocumentRequestForm.telNo.value=pm_8
			document.DocumentRequestForm.zipcode.value=pm_9
			document.DocumentRequestForm.address1.value=pm_10
			document.DocumentRequestForm.address2.value=pm_11
			//document.DocumentRequestForm.address4.value=pm_12
			document.DocumentRequestForm.objectcode.value=pm_13
			document.DocumentRequestForm.FamilyNumber.value=""
			document.DocumentRequestForm.birthday.value=""
			document.DocumentRequestForm.PersonJobCode.value=pm_16
			document.DocumentRequestForm.PersonIncomeCode.value=pm_17
			document.DocumentRequestForm.Deposit.value=pm_18
			document.DocumentRequestForm.HopePriceCode.value=pm_19
			document.DocumentRequestForm.DwellingType.value=""
			document.DocumentRequestForm.HopeRoomArrangementCode.value=""
			document.DocumentRequestForm.HopeArea.value=""
			document.DocumentRequestForm.acknowledgmentmediumcode.value=pm_23
			
			document.DocumentRequestForm.acknowledgmentMediumOther.value=pm_24
			document.DocumentRequestForm.freeMessage.value=pm_25
			document.DocumentRequestForm.InformationMailFlG.value=pm_26

			send();
		} else {
			document.getElementById("errorM").value=""
			document.getElementById("errorM").value=errorMessage
			pm_27=document.getElementById("errorM").value
			setCookie('pm_1',pm_1)
			setCookie('pm_2',pm_2)
			setCookie('pm_3',pm_3)
			setCookie('pm_4',pm_4)
			setCookie('pm_5',pm_5)
			setCookie('pm_6',pm_6)
			setCookie('pm_7',pm_7)
			setCookie('pm_8',pm_8)
			setCookie('pm_9',pm_9)
			setCookie('pm_10',pm_10)
			setCookie('pm_11',pm_11)
			setCookie('pm_12',pm_12)
			setCookie('pm_13',pm_13)
			setCookie('pm_14',pm_14)
			setCookie('pm_15',pm_15)

			setCookie('pm_16',pm_16)
			setCookie('pm_17',pm_17)
			setCookie('pm_18',pm_18)
			setCookie('pm_19',pm_19)
			setCookie('pm_20',pm_20)
			setCookie('pm_21',pm_21)
			setCookie('pm_22',pm_22)

			setCookie('pm_9b',pm_9b)
			setCookie('pm_9c',pm_9c)

			setCookie('pm_12b',pm_12b)
			setCookie('pm_13b',pm_13b)

			setCookie('pm_16b',pm_16b)
			setCookie('pm_17b',pm_17b)
			setCookie('pm_18b',pm_18b)
			setCookie('pm_19b',pm_19b)
			setCookie('pm_20b',pm_20b)
			setCookie('pm_21b',pm_21b)
			setCookie('pm_22b',pm_22b)

			setCookie('pm_23',pm_23)
			setCookie('pm_23b',pm_23b)
			setCookie('pm_24',pm_24)
			setCookie('pm_25',pm_25)
			setCookie('pm_26',pm_26)
			setCookie('pm_27',pm_27)

			location.href="apply_2.html"
		}
	} else {
		resetData()
	}
	

}

//city
function goMenu_1(menu){
	//alert(menu)
	document.getElementById("address1").value=menu;
}

//birthday
function goMenu_2(menu){
	//alert(menu)
	document.getElementById("birthday").value=menu;
}

//job
function goMenu_3(menu,menu2){
	//alert(menu2)
	document.getElementById("person_job_code").value=menu;
	document.getElementById("person_job_code_b").value=menu2;
}

//income
function goMenu_4(menu,menu2){
	document.getElementById("person_income_code").value=menu;
	document.getElementById("person_income_code_b").value=menu2;
}

//own money
function goMenu_5(menu,menu2){
	document.getElementById("deposit").value=menu;
	document.getElementById("deposit_b").value=menu2;
}

//budget
function goMenu_6(menu,menu2){
	document.getElementById("hope_price_code").value=menu;
	document.getElementById("hope_price_code_b").value=menu2;
}

//current home
function goMenu_7(menu,menu2){
	document.getElementById("dwelling_type").value=menu;
	document.getElementById("dwelling_type_b").value=menu2;
}

//layout
function goMenu_8(menu,menu2){
	document.getElementById("hope_Room_Arrangement_code").value=menu;
	document.getElementById("hope_Room_Arrangement_code_b").value=menu2;
}

//how big
function goMenu_9(menu,menu2){
	document.getElementById("hope_area").value=menu;
	document.getElementById("hope_area_b").value=menu2;
}


function createOrder_1(){                 
	pm_a=document.forms[0].pm_a;
	txt="";
	txt2="";
	for (i=0;i<pm_a.length;++ i) {
  		if (pm_a[i].checked) {
    		//txt=txt + pm_a[i].value + '\n';
			txt=txt + pm_a[i].value + ',';
			txt2=txt2+pm_a[i].id;
    	}
  	}
	document.getElementById("objectcodes").value=txt;
	document.getElementById("objectcodes_b").value=txt2;
}


function createOrder_2(){
	hp=document.forms[0].hp;
	txt="";
	txt2="";
	for (i=0;i<hp.length;++ i) {
  		if (hp[i].checked) {
    		txt=txt + hp[i].value + '|';
			txt2=txt2+hp[i].id;
    	}
  	}
	document.getElementById("acknowledgment_medium_code").value=txt;
	document.getElementById("acknowledgment_medium_code_b").value=txt2;
}

function createOrder_3(){
	club=document.forms[0].club;
	txt="";
	for (i=0;i<club.length;++ i) {
  		if (club[i].checked) {
    		txt=txt + club[i].value;
    	}
  	}
	document.getElementById("information_mail_flg").value=txt;
}


function createOrder_4(){
	ag=document.forms[0].agreementFlg;
	agt=ag.checked
	document.getElementById("agr").value=agt;
}


function errorMes() {
	errorMessage=""
	errorNum=""
	if (pm_1=="_" || pm_2=="_") {
		errorMessage="●お名前をご入力ください"+'\n';
	} else {
		errorNum=1
	}

	if (pm_3=="_") {
		//alert('pm_3 nothing')
	}
	if (pm_4=="_") {
		//alert('pm_4 nothing')
	}

	if (pm_5=="_") {
		errorMessage=errorMessage+"●メールアドレスをご入力ください。"+'\n';
	} else {
		errorNum=errorNum+1
	}

	if (pm_9=="_") {
		errorMessage=errorMessage+"●郵便番号をご入力ください。"+'\n';
	} else {
		errorNum=errorNum+1
	}

	if (pm_10=="_" || pm_11=="_") {
		errorMessage=errorMessage+"●ご住所をご入力ください。"+'\n';
	} else {
		errorNum=errorNum+1
	}

	if (pm_13=="_") {
		errorMessage=errorMessage+"●請求物件をお選びください。"+'\n';
	} else {
		errorNum=errorNum+1
	}

}


function showElement(){
	document.getElementById('formA').style.display="block";
}

function delCook() {
	deleteCookie('pm_1')
	deleteCookie('pm_2')
	deleteCookie('pm_3')
	deleteCookie('pm_4')
	deleteCookie('pm_5')
	deleteCookie('pm_6')
	deleteCookie('pm_7')
	deleteCookie('pm_8')
	deleteCookie('pm_9')
	deleteCookie('pm_10')
	deleteCookie('pm_11')
	deleteCookie('pm_12')
	deleteCookie('pm_13')
	deleteCookie('pm_14')
	deleteCookie('pm_15')
	deleteCookie('pm_16')
	deleteCookie('pm_17')
	deleteCookie('pm_18')
	deleteCookie('pm_19')
	deleteCookie('pm_20')
	deleteCookie('pm_21')
	deleteCookie('pm_22')

	deleteCookie('pm_9b')
	deleteCookie('pm_9c')
	deleteCookie('pm_12b')
	deleteCookie('pm_13b')

	deleteCookie('pm_16b')
	deleteCookie('pm_17b')
	deleteCookie('pm_18b')
	deleteCookie('pm_19b')
	deleteCookie('pm_20b')
	deleteCookie('pm_21b')
	deleteCookie('pm_22b')

	deleteCookie('pm_23')
	deleteCookie('pm_24')
	deleteCookie('pm_25')
	deleteCookie('pm_26')
	deleteCookie('pm_27')

	//delCookie()
}

function checkData(){
	sub_1=getCookie('pp_13');
	obj_1=getCookie('pp_13b');
	//alert(obj_1)
	document.getElementById("objectcodes").value=sub_1;
	document.getElementById("objectcodes_b").value=obj_1;

	pm_a=document.forms[0].pm_a;
	for( i=0; i<obj_1.length; i++ ) {
		obj_c= obj_1.charAt(i);
		for( a=0; a<pm_a.length; a++ ) {
			vpm_a = pm_a[a].id;
			if (vpm_a ==obj_c ){
				document.forms[0].pm_a[a].checked=true
			}
		}
	}
	deleteCookie('pp_13')
	deleteCookie('pp_13b')
}


function replaceNum() {
	if (pm_1=="" || pm_1==null) pm_1="_"
	if (pm_2=="" || pm_2==null) pm_2="_"
	if (pm_3=="" || pm_3==null) pm_3="_"
	if (pm_4=="" || pm_4==null) pm_4="_"
	if (pm_5=="" || pm_5==null) pm_5="_"
	if (pm_6=="" || pm_6==null) pm_6="_"
	if (pm_7=="" || pm_7==null) pm_7="_"
	if (pm_8=="" || pm_8==null) pm_8="_"
	if (pm_9=="" || pm_9==null) pm_9="_"
	if (pm_10=="" || pm_10==null) pm_10="_"
	if (pm_11=="" || pm_11==null) pm_11="_"
	if (pm_12=="" || pm_12==null) pm_12="_"
	if (pm_13=="" || pm_13==null) pm_13="_"
	if (pm_14=="" || pm_14==null) pm_14="_"
	if (pm_15=="" || pm_15==null) pm_15="_"
	if (pm_16=="" || pm_16==null) pm_16="_"
	if (pm_17=="" || pm_17==null) pm_17="_"
	if (pm_18=="" || pm_18==null) pm_18="_"
	if (pm_19=="" || pm_19==null) pm_19="_"
	if (pm_20=="" || pm_20==null) pm_20="_"
	if (pm_21=="" || pm_21==null) pm_21="_"
	if (pm_22=="" || pm_22==null) pm_22="_"
	if (pm_23=="" || pm_23==null) pm_23="_"
	if (pm_24=="" || pm_24==null) pm_24="_"
	if (pm_25=="" || pm_25==null) pm_25="_"
	if (pm_26=="" || pm_26==null) pm_26="_"

	if (pm_9b=="" || pm_9b==null) pm_9b="_"
	if (pm_9c=="" || pm_9c==null) pm_9c="_"
	if (pm_12b=="" || pm_12b==null) pm_12b="_"
	if (pm_13b=="" || pm_13b==null) pm_13b="_"

	if (pm_16b=="" || pm_16b==null) pm_16b="_"
	if (pm_17b=="" || pm_17b==null) pm_17b="_"
	if (pm_18b=="" || pm_18b==null) pm_18b="_"
	if (pm_19b=="" || pm_19b==null) pm_19b="_"
	if (pm_20b=="" || pm_20b==null) pm_20b="_"
	if (pm_21b=="" || pm_21b==null) pm_21b="_"
	if (pm_22b=="" || pm_22b==null) pm_22b="_"
	if (pm_23b=="" || pm_23b==null) pm_23b="_"
}

		

