/* for IE6 */
try {
document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

function isIE()
{
	if(navigator.appName.indexOf("Microsoft") != -1)
		return true;
	else
		return false;
}

function isGecko()
{
    if(navigator){
        if(navigator.userAgent){
            if(navigator.userAgent.indexOf("Gecko/") != -1){
                return true;
            }
        }
    }

    return false;
}

function RollOver (obj,val) {
  obj.src = val;
}

function setFocus(dist)
{
	var to = document.getElementById(dist);

	to.focus();
	//window.scrollBy(0, screen.height/3);
}


function setMailAdr(adr, dist, f)
{
	var a = document.getElementById(dist);
	var n = adr.match(/./g).reverse().join('');
	var m = String.fromCharCode(0X40);
	var d = location.hostname;
	a.href = ':otliam'.match(/./g).reverse().join('') + n + m + d;

	if(f)
		a.innerHTML = n + m + d;
}


function getAdr(zip, dist)
{
	if(zip.value.length < 7)
		return;

	zip.value = toHankaku(zip.value, '');

	if(zip.value.match(/^\d{3}\-?\d{4}$/)){
		document.getElementById(dist).value = 'ご住所を検索中です・・・';

		var url = "get_adr.php?zip=" + zip.value.replace(/\D/g, '');
		var http = new JKL.ParseXML(url);

		var func = function(data){
			var adr = data.address.value;

			if(adr.zip)
				document.getElementById(dist).value = adr.ken + adr.shi + adr.cho;
			else
				document.getElementById(dist).value = '';//'検索できませんでした';
		}

		http.async(func);
		http.parse();
   	}
}


function toHankaku(src, exc) {
  var str = new String;
  var len = src.length;
  for (var i = 0; i < len; i++) {
    var c = src.charCodeAt(i);
    if (exc.indexOf(src.charAt(i)) > -1) {
      str += src.charAt(i); /* 除外 */
    } else if (c >= 65281 && c <= 65374 && c != 65340) {
      str += String.fromCharCode(c - 65248);
    } else if (c == 8217) {
      str += String.fromCharCode(39);
    } else if (c == 8221) {
      str += String.fromCharCode(34);
    } else if (c == 12288) {
      str += String.fromCharCode(32);
    } else if (c == 65507) {
      str += String.fromCharCode(126);
    } else if (c == 65509) {
      str += String.fromCharCode(92);
    } else {
      str += src.charAt(i);
    }
  }
  return str;
}


/* yubin2jsonp */
function Yubin2JSONP(root){
	this.root = root;
	this.parse = function(yubin){
		if (! yubin.match(/[0-9]{7}/) ) return;
		var yubin3 = yubin.substr(0,3);
		var script = document.createElement('script');
		script.id = this.root + yubin3 + '/' + yubin + '.js';
		script.charset = 'UTF-8';
		script.src = script.id;
		document.lastChild.appendChild(script);
		// document.lastChild.removeChild(script);
	};
	return this;
}

var yubin2jsonp = new Yubin2JSONP('https://www22.jpsecure.jp/~mcsp/yubin2jsonp/');

function parse_yubin2jsonp(json){
}

function yubin2adr(yubin, dist)
{
	if(yubin.length < 7)
		return;

	yubin = toHankaku(yubin, '');

	if(yubin.match(/^\d{3}\-?\d{4}$/)){
		dist = document.getElementById(dist);

		var bisy = 'ご住所を検索中です・・・';
		dist.value = bisy;

		parse_yubin2jsonp = function(json){
			dist.value = json[0].join('');
		};

		yubin2jsonp.parse(yubin.replace('-', ''));
	}
}


/* camp */
function campSwitchGroup(flag)
{
	var style = flag ? (isIE() ? 'block' : 'table-row') : 'none';
	var objs = document.getElementsByTagName("tr");

	for (i = 0; i < objs.length; i++){
		if( objs[i].id.match(/_\d$/) )
			objs[i].style.display = style;
	}
}
