function openSearchZip(zip) {
	var hWnd = window.open('/bin/search_zip?s=' + zip, '_blank', 'height=185,width=400,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
}

function setSearchAddress(s) {
	window.opener.document.getElementById('registForm').address.value = s;
	window.close();
}

function openInquiryForm(sid) {
	var hWnd = window.open('http://www.tekoki-navi.com/bin/inquiry_shop?sid=' + sid, '_blank', 'height=600,width=500,directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no');
}

function openMobileForm(sid) {
	var hWnd = window.open('http://www.tekoki-navi.com/bin/send_mobile?sid=' + sid, '_blank', 'height=185,width=400,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
}

function openCouponForm(sid, height) {
	var h = 280;
	if (height) h += height;
	var hWnd = window.open('http://www.tekoki-navi.com/bin/show_coupon?sid=' + sid, '_blank', 'height=' + h + ',width=400,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
}

function openPicture(sid, idx, width, height) {
	var hWnd = window.open('http://www.tekoki-navi.com/bin/show_picture?sid=' + sid + '&idx=' + idx, '_blank', 'height=' + (height + 50) + ',width=' + (width + 30) + ',directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
}

function setSelectMenu(obj, sel) {
	if (sel) { obj.style.backgroundColor="#AEEB4D"; obj.style.cursor = "pointer"; }
	else { obj.style.backgroundColor="#FFFFFF"; obj.style.cursor = "default"; }
}

function setSelectCategoryListener() {
	var obj = document.getElementById('registForm');
	
	if (obj != null) {
		addListener(obj.cate_parent, 'change', getChildCategory, false);
		addListener(obj.cate_child, 'change', getCarName, false);
	}
}

function setSelectAreaListener() {
	var obj = document.getElementById('registForm');
	
	if (obj != null) {
		addListener(obj.area_parent, 'change', getAreaCategory, false);
		addListener(obj.area_child, 'change', getAreaChildCategory, false);
	}
}

function getChildCategory() {
	var frm = document.getElementById('registForm');
    
	var ResultFunc = function(xml) {
		var frm = document.getElementById('registForm');
		if (xml.documentElement != null) {
			var category = xml.getElementsByTagName('cate');
			var i; var j; var name; var id;
			
			if (category.length) {
				frm.cate_child.options.length = 1;
				for (i = 0; i < category.length; i++) {
					name = ''; no = '';
					for (j = 0; j < category[i].childNodes.length; j++) {
						if (category[i].childNodes[j].tagName == 'name') { name = category[i].childNodes[j].firstChild.nodeValue; }
						else if (category[i].childNodes[j].tagName == 'id') { id = category[i].childNodes[j].firstChild.nodeValue; }
					}
					
					frm.cate_child.options[frm.cate_child.options.length] = new Option(name, id);
				}
			}
			else {
				frm.cate_child.options[frm.cate_child.options.length] = new Option('', '');
				frm.cate_child.options.length = 1;
			}
			
			frm.car_name.options[frm.car_name.options.length] = new Option('', '');
			frm.car_name.options.length = 1;
		}
	}

	httpXmlRequest('/bin/get_category', 'n=' + frm.cate_parent.value, ResultFunc);
}

function getCarName() {
	var frm = document.getElementById('registForm');
    
	var ResultFunc = function(xml) {
		var frm = document.getElementById('registForm');
		if (xml.documentElement != null) {
			var category = xml.getElementsByTagName('cate');
			var i; var j; var name; var id;
			
			if (category.length) {
				frm.car_name.options.length = 1;
				for (i = 0; i < category.length; i++) {
					name = ''; no = '';
					for (j = 0; j < category[i].childNodes.length; j++) {
						if (category[i].childNodes[j].tagName == 'name') { name = category[i].childNodes[j].firstChild.nodeValue; }
						else if (category[i].childNodes[j].tagName == 'id') { id = category[i].childNodes[j].firstChild.nodeValue; }
					}
					
					frm.car_name.options[frm.car_name.options.length] = new Option(name, id);
				}
			}
			else {
				frm.car_name.options[frm.car_name.options.length] = new Option('', '');
				frm.car_name.options.length = 1;
			}	
		}
	}

	httpXmlRequest('/bin/get_category', 'n=' + frm.cate_child.value, ResultFunc);
}

function getAreaCategory() {
	var frm = document.getElementById('registForm');
    
	var ResultFunc = function(xml) {
		var frm = document.getElementById('registForm');
		if (xml.documentElement != null) {
			var category = xml.getElementsByTagName('cate');
			var i; var j; var name; var id;
			
			if (category.length) {
				frm.area_child.options.length = 1;
				for (i = 0; i < category.length; i++) {
					name = ''; no = '';
					for (j = 0; j < category[i].childNodes.length; j++) {
						if (category[i].childNodes[j].tagName == 'name') { name = category[i].childNodes[j].firstChild.nodeValue; }
						else if (category[i].childNodes[j].tagName == 'id') { id = category[i].childNodes[j].firstChild.nodeValue; }
					}
					
					frm.area_child.options[frm.area_child.options.length] = new Option(name, id);
				}
			}
			else {
				frm.area_child.options[frm.area_child.options.length] = new Option('', '');
				frm.area_child.options.length = 1;
			}
			
			frm.area.options[frm.area.options.length] = new Option('', '');
			frm.area.options.length = 1;
		}
	}

	httpXmlRequest('/bin/get_area_category', 'n=' + frm.area_parent.value, ResultFunc);
}

function getAreaChildCategory() {
	var frm = document.getElementById('registForm');
    
	var ResultFunc = function(xml) {
		var frm = document.getElementById('registForm');
		if (xml.documentElement != null) {
			var category = xml.getElementsByTagName('cate');
			var i; var j; var name; var id;
			
			if (category.length) {
				frm.area.options.length = 1;
				for (i = 0; i < category.length; i++) {
					name = ''; no = '';
					for (j = 0; j < category[i].childNodes.length; j++) {
						if (category[i].childNodes[j].tagName == 'name') { name = category[i].childNodes[j].firstChild.nodeValue; }
						else if (category[i].childNodes[j].tagName == 'id') { id = category[i].childNodes[j].firstChild.nodeValue; }
					}
					
					frm.area.options[frm.area.options.length] = new Option(name, id);
				}
			}
			else {
				frm.area.options[frm.area.options.length] = new Option('', '');
				frm.area.options.length = 1;
			}
		}
	}

	httpXmlRequest('/bin/get_area_category', 'l=' + frm.area_child.value, ResultFunc);
}

var image_count = 0;
var image_index = 0;
var image_max = 0;
function attach_image() {
	if (image_count >= image_max) {
		alert('イメージのアップロードは最大' + image_max + 'つまでです。');
		return;
	}
	
	image_count++; image_index++;
	
	var attach = document.getElementById('attach');
	var node_input = document.createElement('input');
	var node_a = document.createElement('a');
	var node_space = document.createTextNode('    ');
	var node_br = document.createElement('br');

	node_input.setAttribute('type', 'file');
	node_input.setAttribute('name', 'image' + image_index);
	node_input.setAttribute('size', '60');

	attach.insertBefore(node_input, null);
	attach.insertBefore(node_space, null);
	attach.insertBefore(node_br, null);
}

function show_image(path) {
	var image = document.getElementById('image');
	
	image.src = '/images/shop/car/m/' + path;
}

function init_image(max, count) {
	image_max = max;
	image_count = count;
}

function checkAlert(loc) {
	if (confirm('本当に実行してもよろしいですか？')) {
		window.location.href = loc;
	}
}

function addFavorite() {
	window.external.AddFavorite('http://www.tekoki-navi.com/', '手コキナビ');
}

