var _searchstr = '';
var _currentId = "centerDiv";

function dispImage(path,fn,w,h) {
	var img = document.getElementById('pickup');
	img.src = path + fn;
	img.width = w;
	img.height = h;
}

function clipImage(w,h,img) {
  var iw = img.width;
  var ih = img.height;
  var awh = calcWH3(w,h,iw,ih);
  img.width = awh[0];
  img.height = awh[1];
  var top = Math.floor((h - img.height) / 2);
  var left = Math.floor((w - img.width) / 2);
  var ctop = top;
  var cleft = left;
  var cbottom = "auto";
  var cright = "auto";
  if (top < 0) {
	ctop = (top * -1) + 'px';
	cbottom = (img.height + top) + 'px';
  } else {
	ctop = "auto";
  }
  if (left < 0) {
	cleft = (left * -1) + 'px';
	cright = (img.width + left) + 'px';
  } else {
	cleft = "auto";
  }

  img.style.clip = "rect(" + ctop + " " + cright + " " + cbottom + " " + cleft + ")";
  img.style.top = top + 'px';
  img.style.left = left + 'px';
  img.style.position = 'absolute';
  img.style.visibility = "visible";
}

function calcWH3(w,h,iw,ih){
  var th;
  var tw;
  if (w>=iw || h >=ih) {
    return new Array(iw,ih);
  }
  if (iw < ih) {
    tw = w;
    th = Math.floor((ih * w) / iw);
  } else {
    th = h;
    tw = Math.floor((iw * h) / ih);
  }

  if (th < h) {
    tw = Math.floor(tw * (h / th));
    th = h;
  }
  if (tw < w) {
    th = Math.floor(th * (w /tw));
    tw = w;
  }

  return new Array(tw,th);
}

function srchin() {
	if (_searchstr == '' || !_searchstr) {
		var div = document.getElementById('keywords2');
		div.value = "";
		div.style.color="black";
	}
}

function srchout() {
	var div = document.getElementById('keywords2');
	_searchstr = div.value;
	if (_searchstr == '' || !_searchstr) {
		div.value = "検索窓";
		div.style.color="gray";
	}
}

function getKEYCODE(e) {
	var ua = navigator.userAgent;
//	if (ua.indexOf("Safari" != -1 || ua.serach('opera(\ |\/)6') != -1) {
	if (ua.search('opera(\ |\/)6') != -1) {
		return null;
	} else if (document.layers) {
		return e.which;
	} else if (document.all) {
		return event.keyCode;
	} else if (document.getElementById) {
		return e.keyCode;
	} else {
		return null;
	}
}

function checkCode(e) {
	if (getKEYCODE(e) == 13) {
		_searchstr = document.getElementById('keywords2').value;
		if (_searchstr)
			document.searchform2.submit();
	}
}

function checkKeyword() {
	if (!document.getElementById('keyword').value) {
		return false;
	}
	
	return true;
}

function checkKeyword2() {
	if (_searchstr == '' || !_searchstr) {
		return false;
	}
	
	return true;
}

function check() {
	if (!document.getElementsByName('name')[0].value) {
		alert("お名前を入力してください。");
		return false;
	}
	if (!document.getElementsByName('email')[0].value) {
		alert("メールアドレスを入力してください。");
		return false;
	}
	if (!document.getElementsByName('otoiawase')[0].value) {
		alert("お問い合わせ内容を入力してください。");
		return false;
	}
	
	return true;
}

function changeTab(id,tabId) {
	var div = null;
	var divTab = null;
	var tmpDiv = "centerDiv";
	var tmpTab = "centerTab";
	
	if (id == _currentId) return;
	
	div = document.getElementById(id);
	divTab = document.getElementById(tabId);
	_currentId = id;
	if (id == "centerDiv") {
		tmp = "fieldDiv";
		tmpTab = "fieldTab";
	}

	div.style.visibility = "visible";
	divTab.style.cursor = "default";
	divTab.style.background = "gray";
	document.getElementBuId(tmp).style.visibility = "hidden";
	document.getElementBuId(tmpTab).style.cursor = "pointer";
	document.getElementBuId(tmpTab).style.background = "white";
}