function submit() {
    document.online_form.submit();
}

function reset(){
    document.online_form.reset();
}

function over_check(){

	if (document.online_form.maker_name.value == "") {
		alert("メーカー名をご入力ください。");
                document.online_form.maker_name.focus();
		return false;
	}

        if (document.online_form.maker_name.value == "その他" && document.online_form.other_maker_name.value == "") {
                alert("その他メーカー名をご入力ください。");
                document.online_form.other_maker_name.focus();
                return false;
        }

	if (document.online_form.car_name.value == "") {
		alert("車種名・グレードをご入力ください。");
                document.online_form.car_name.focus();
		return false;
	}

	if (document.online_form.nensiki.value == "") {
		alert("年式をご入力ください。");
                document.online_form.nensiki.focus();
		return false;
	}

	if (!checkIsNumber(document.online_form.nensiki.value) || Number(document.online_form.nensiki.value) < 1900) {
		alert("年式をご確認ください。");
                document.online_form.nensiki.focus();
		return false;
	}


        if(document.online_form.root[0] != null ) {
            if (!document.online_form.root[0].checked && !document.online_form.root[1].checked && !document.online_form.root[2].checked) {
                alert("購入種別をご入力ください。");
                document.online_form.root[0].focus();
                return false;
            }
        }

		if(document.online_form.repair[0] != null && document.online_form.repair[1] != null) {
	        if (!document.online_form.repair[0].checked && !document.online_form.repair[1].checked) {
	                alert("修復歴をご入力ください。");
	                document.online_form.repair[0].focus();
	                return false;
	        }
		}

	if (document.online_form.color !=null && document.online_form.color.value == "") {
		alert("ボディ色をご入力ください。");
                document.online_form.color.focus();
		return false;
	}


	if(document.online_form.shift[0] != null && document.online_form.shift[1] != null) {

		if (!document.online_form.shift[0].checked && !document.online_form.shift[1].checked && !document.online_form.shift[2].checked) {
                alert("シフトをご入力ください。");
                document.online_form.shift[0].focus();
                return false;
        }
	}

	if(document.online_form.handle[0] != null && document.online_form.handle[1] != null) {

        if (!document.online_form.handle[0].checked && !document.online_form.handle[1].checked) {
                alert("ハンドルをご入力ください。");
                document.online_form.handle[0].focus();
                return false;
        }

	}

	if (document.online_form.type != null && document.online_form.type.value == "") {
		alert("型式をご入力ください。");
		document.online_form.type.focus();
		return false;
	}


	if (!checkIsNumber(document.online_form.soukou.value)) {
                alert("走行距離をご入力ください。");
                document.online_form.soukou.focus();
                return false;
        }

        if(document.online_form.syaken01.value != "") {
	    if (!checkIsNumber(document.online_form.syaken01.value) || Number(document.online_form.syaken01.value) < 2000) {
		alert("次回車検をご確認ください。");
                document.online_form.syaken01.focus();
		return false;
	    }
        }

        if(document.online_form.syaken02.value != "") {
	    if (!checkIsNumber(document.online_form.syaken02.value) || Number(document.online_form.syaken02.value) > 12) {
		alert("次回車検をご確認ください。");
                document.online_form.syaken02.focus();
		return false;
	    }
        }

        if(document.online_form.syaken03 != null && document.online_form.syaken03.value != "") {
            if (!checkIsNumber(document.online_form.syaken03.value) || Number(document.online_form.syaken03.value) > 31)
 {
                alert("次回車検をご確認ください。");
                document.online_form.syaken03.focus();
                return false;
            }
        }


	if(document.online_form.root[0] != null && document.online_form.root[1] != null && document.online_form.root[2] != null) {

        if (!document.online_form.root[0].checked && !document.online_form.root[1].checked && !document.online_form.root[2].checked) {
                alert("購入種別をご入力ください。");
                document.online_form.root[0].focus();
                return false;
        }
	}

        return true;
}

function form_1_check(){

        if(!over_check()) return;

	if (document.online_form.email1 != null && (document.online_form.email1.value != document.online_form.email2.value || document.online_form.email1.value == "")){
         	alert("メールアドレス をご確認ください。");
                document.online_form.email1.focus();
         	return;
  	}

	if (document.online_form.email1 != null && !valid_mail(document.online_form.email1.value)) {
		alert("メールアドレス を正しく入力してください。");
                document.online_form.email1.focus();
    	        return;
	}

	document.online_form.submit();
}

function form_2_check(){

        if(!over_check()) return;

        if (document.online_form.name.value == "") {
                alert("お名前をご入力ください。");
                document.online_form.name.focus();
                return;
        }

	// 2009.03.17 Add
	if (document.online_form.tel.value == "" && document.online_form.mobile.value == "") {
		alert("電話番号と電話番号（携帯)をどちらかご入力してください。");
		document.online_form.tel.focus();
		return;
	}

	// 2009.03.17 Add
	if (document.online_form.tel.value != "" && !checkIsTel(document.online_form.tel.value)) {
		alert("電話番号を正しく入力してください。");
		document.online_form.tel.focus();
		return;
	}

	// 2009.03.17 Add
	if (document.online_form.mobile.value != "" && !checkIsTel(document.online_form.mobile.value)) {
		alert("電話番号（携帯) を正しく入力してください。");
		document.online_form.mobile.focus();
		return;
	}


/********
	if (document.online_form.fax.value != "" && !checkIsTel(document.online_form.fax.value)) {
		alert("FAX番号を正しく入力してください。");
		return;
	}
********/


	if (document.online_form.email1.value != document.online_form.email2.value || 
		document.online_form.email1.value == ""){
         	alert("メールアドレス をご確認ください。");
                document.online_form.email1.focus();
         	return;
  	}

	if (!valid_mail(document.online_form.email1.value)) {
		alert("メールアドレス を正しく入力してください。");
                document.online_form.email1.focus();
    	        return;
	}

	document.online_form.submit();
}


//郵便番号の簡易チェック 
function valid_zip(v_zip3,v_zip4)
{
   if(v_zip3 != ""){
	if(v_zip3.length != 3 || (/^[0-9]{0,3}$/).test(v_zip3) == false){
	   return false;
        }
        if(v_zip4 != ""){
	   if(v_zip4.length != 4 || (/^[0-9]{0,4}$/).test(v_zip4) == false){
	      return false;
	   }
       }
   }
   else if(v_zip4 != ""){
	return false;
   }

   return true;
}


//メールアドレスの簡易チェック 
function valid_mail(mailAddress)
{
  if(!mailAddress.match(/.+@.+\..+/)) return false;
  
  return true;

}

//電話番号の簡易チェック 
function valid_tel(tel)
{
  if(tel==""){
	return false;
  }

  if(tel.length < 10 || tel.length > 13) return false;
  
  if ((tel.match(/^[0-9]+\-[0-9]+\-[0-9]+$/) == null)) {

 	return false;
  }

  return true;

}


//生年月日の簡易チェック 
function valid_birthday(year,month,day)
{
  if(year=="" && month=="" && day==""){
	return true;
  }

  if(year=="" || month=="" || day==""){
	return false;
  }

  return valid_md_combination(eval(year), eval(month) ,eval(day));

}



function valid_md_combination(y, m ,d)
{
	var leap = false;
	if (y%4 == 0){
		if (y%400 == 0 || y%100 != 0){
			leap = true;
		}
	}

	dd = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	if (leap){
		if (m == 2){
			dd[2] = 29;
		}
	}

	if (d<1 || d>dd[m]){
		return false;
	}
	else{
		return true;
	}
}
 

/**
 * 数字チェック
 * 0123456789のみかをチェックします。
 * param  value チェックする値
 * return true : 数字 / false : 数字以外
 */

function checkIsNumber(value){

  return (value.match(/[0-9]+/g) == value);

}

/**
 * 電話番号チェック
 * 電話番号は市外局番で始まり合計10桁の数値で構成されています。
 * JavaScriptでは正規表現文字列内に変数を利用することができないの
 * で桁数のチェックと電話番号のチェックを別々に行い、両方ともマッチ
 * した場合は正しい、そうでない場合は不正というようにします。
 * 正規表現では「^[0-9-]{6,9}$|^[0-9-]{12}$」（桁数）、「^\d{1,4}-\d{4}$|^\d{2,5}-\d{1,4}-\d{4}$」
 * （市外局番を含む電話番号のパターン）のように記述します。なお、-（ハイフン）
 * は含まれるという条件付きであり-なしの場合はサンプルではチェックしていません。 
 * param  value チェックする値
 * return true : 数字 / false : 数字以外
 */

function checkIsTel(value){

   data1 = value.match(/^[0-9-]{6,9}$|^[0-9-]{12}$/);
   data2 = value.match(/^\d{1,4}-\d{4}$|^\d{2,5}-\d{1,4}-\d{4}$/);
   if(!data1 && !data2) {
       return false;
   }
   else {
       return true;
   }
}

/**
 * ＵＲＬチェック
 * param  value チェックする値
 * return true : 数字 / false : 数字以外
 */

function checkIsURL(value){

    data = value.match(/(http|ftp):\/\/.+/);
    if(!data) {
        return false;
    }
    else {
        return true;
    }
}
