// JavaScript Document
// エリアの未チェック
function check(op){
	var flg = 0;
	

	if(op.address.length){
		var i;
		for(i=0;i<op.address.length;i++){
			if(op.address[i].checked){
				flg = 1;
			}
		}
	}else{
		if(op.address.checked){
			flg = 1;
		}
	}
	
	if(flg == 0){
		alert("エリアを選択して下さい。");
		return false;
	}else{
		return true;
	}
}

function sub_area(){
	document.getElementById("hid").innerHTML='<input type="hidden" name="mode" value="area_name">';
}

function sub_ac(){
	document.getElementById("hid").innerHTML='<input type="hidden" name="mode" value="area_map" >';
}

// 学校の未チェック
function check_sc(op){
	var flg = 0;
	
	if(op.maprange.length){
		var i;
		for(i=0;i<op.maprange.length;i++){
			if(op.maprange[i].checked){
				flg = 1;
			}
		}
	}
	
	if(flg == 0){
		alert("学校を選択して下さい。");
		return false;
	}else{
		return true;
	}
}


// エリア or 路線の未チェック
function check_cond(op){
	var flg_area = 0;
	var flg_route = 0;
	
	var num_area;
	var num_route;
	
	var i;
	
	//選択肢がひとつの場合の判定
	if(op.address.length){
		num_area = op.address.length;
	}else{
		num_area = 1;
	}
	if(op.station.length){
		num_route = op.station.length;
	}else{
		num_route = 1;
	}
	
	if(num_area){
		if(num_area == 1){
			if(op.address.checked){
				flg_area = 1;
			}
		}else{
			for(i=0;i<num_area;i++){
				if(op.address[i].checked){
					flg_area = 1;
				}
			}
		}
	}
	if(num_route){
		if(num_route == 1){
			if(op.station.checked){
				flg_route = 1;
			}
		}else{
			for(i=0;i<num_route;i++){
				if(op.station[i].checked){
					flg_route = 1;
				}
			}
		}
	}
	
	
	
	if(flg_area == 0 && flg_route == 0){
		alert("エリアまたは路線を選択して下さい。");
		return false;
	}else if(flg_area == 1 && flg_route == 1){
		alert("エリアまたは路線のどちらかを選択して下さい。");
		if(num_area == 1){
			if(op.address.checked){
				op.address.checked = false;
			}
		}else{
			for(i=0;i<num_area;i++){
				if(op.address[i].checked){
					op.address[i].checked = false;
				}
			}
		}
		if(num_route == 1){
			if(op.station.checked){
				op.station.checked = false;
			}
		}else{
			for(i=0;i<num_route;i++){
				if(op.station[i].checked){
					op.station[i].checked = false;
				}
			}
		}
		return false;
	}else if(flg_area == 1 && flg_route == 0){
		document.getElementById("mode_select").innerHTML='<input type="hidden" name="mode" value="area_name">';
		return true;
	}else if(flg_area == 0 && flg_route == 1){
		document.getElementById("mode_select").innerHTML='<input type="hidden" name="mode" value="station_name">';
		return true;
	}
}


// エリア or 路線の未チェック_大学
function check_cond_ac(op){
	var flg_area = 0;
	var flg_route = 0;
	
	var num_area;
	var num_route;
	
	var i;
	
	//選択肢がひとつの場合の判定
	if(op.maprange.length){
		num_area = op.maprange.length;
	}else{
		num_area = 1;
	}
	if(op.station.length){
		num_route = op.station.length;
	}else{
		num_route = 1;
	}
	
	if(num_area){
		if(num_area == 1){
			if(op.maprange.checked){
				flg_area = 1;
			}
		}else{
			for(i=0;i<num_area;i++){
				if(op.maprange[i].checked){
					flg_area = 1;
				}
			}
		}
	}
	if(num_route){
		if(num_route == 1){
			if(op.station.checked){
				flg_route = 1;
			}
		}else{
			for(i=0;i<num_route;i++){
				if(op.station[i].checked){
					flg_route = 1;
				}
			}
		}
	}
	
	
	
	if(flg_area == 0 && flg_route == 0){
		alert("エリアまたは路線を選択して下さい。");
		return false;
	}else if(flg_area == 1 && flg_route == 1){
		alert("エリアまたは路線のどちらかを選択して下さい。");
		if(num_area == 1){
			if(op.maprange.checked){
				op.maprange.checked = false;
			}
		}else{
			for(i=0;i<num_area;i++){
				if(op.maprange[i].checked){
					op.maprange[i].checked = false;
				}
			}
		}
		if(num_route == 1){
			if(op.station.checked){
				op.station.checked = false;
			}
		}else{
			for(i=0;i<num_route;i++){
				if(op.station[i].checked){
					op.station[i].checked = false;
				}
			}
		}
		return false;
	}else if(flg_area == 1 && flg_route == 0){
		document.getElementById("mode_select").innerHTML='<input type="hidden" name="mode" value="school_map">';
		return true;
	}else if(flg_area == 0 && flg_route == 1){
		document.getElementById("mode_select").innerHTML='<input type="hidden" name="mode" value="station_name">';
		return true;
	}
}