/* ---------- ---------- ---------- ---------- */

//initUserEnv
function initUserEnv(){
	this.isWin		= navigator.userAgent.indexOf("Win") != -1 ? true : false;
	this.isMac		= navigator.userAgent.indexOf("Mac") != -1 ? true : false;
	this.isNs		= navigator.appName.indexOf("Netscape") != -1 ? true : false;
	this.isNs4		= (document.layers) ? true : false;
	this.isNs4_7	= navigator.userAgent.indexOf("4.7") != -1 ? true : false;
	this.isNs6		= navigator.userAgent.indexOf("Netscape6") != -1 ? true : false;
	this.isNs7		= navigator.userAgent.indexOf("Netscape/7") != -1 ? true : false;
	this.isMoz		= navigator.userAgent.indexOf("Gecko") != -1 ? true : false;
	this.isIe		= navigator.userAgent.indexOf("MSIE") != -1 ? true : false;
	this.isIe4		= navigator.userAgent.indexOf("MSIE 4") != -1 ? true : false;
	this.isIe5		= navigator.userAgent.indexOf("MSIE 5") != -1 ? true : false;
	this.isIe6		= navigator.userAgent.indexOf("MSIE 6") != -1 ? true : false;
	this.isOp		= navigator.userAgent.indexOf("Opera") != -1 ? true : false;
	this.isW3CDom	= (document.getElementById) ? true : false;
	this.isMsDom	= (document.all) ? true : false;
	this.isNsDom	= (document.layers) ? true : false;
	this.isDom		= (this.isW3CDom || this.isMsDom || this.isNsDom) ? true : false;
	return this;
}
var userEnv = new initUserEnv();


//checkBlowser
function checkBlowser(){
	return (userEnv.isW3CDom)? 1:0;
}

//getFlashPlayerVersion
function getSwfVersion(){
	var flashVersion = 0;
	if (userEnv.isIe && userEnv.isWin) {
		try{flashVersion= new ActiveXObject("ShockwaveFlash.ShockwaveFlash").FlashVersion();}catch(e){flashVersion=0};
		flashVersion = Math.floor (flashVersion / 0x10000);
	} else {
		if (userEnv.isNs && !navigator.plugins) {
			flashVersion = 0;
		} else {
			var s = "application/x-shockwave-flash";
			if (navigator.mimeTypes && navigator.mimeTypes[s] && navigator.mimeTypes[s].enabledPlugin) {
				flashVersion=navigator.plugins["Shockwave Flash"].description.match (/\d+/);
			} else {
				flashVersion = 0;
			}
		}
	}
	return flashVersion;
}


//openSubWindow
function openSubWindow(url,name,width,height,misc,centering) {
	var details;
	details = "width="+ width +",height=" + height +",";
	details += "toolbar="+ misc.charAt(0) +",location="+ misc.charAt(1) +",status="+ misc.charAt(2);
	details += ",menubar="+ misc.charAt(4) +",scrollbars="+misc.charAt(5) +",resizable="+misc.charAt(6)+"";
	if (centering =="center") {
		var posX = (screen.width / 2) - (width / 2);
		var posY = (screen.height / 2) - (height / 2);
		details += ",left=" + posX + ",top=" + posY + ",screenX=" + posX + ",screenY=" + posY;
	}
	window.open(url,name,details);
}

//openerWindow
function openerWindow(url){
	if(!window.opener || window.opener.closed){
		window.open(url);
	}else{
		window.opener.location.href = url;
	}
} 

//cookie
function checkEnabledCookie(){
	return (document.cookie) ? 1:0;
}
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

//swapImage
function MM_preloadImages() {
	var d = document;
	if (d.images) {
		if (!d.MM_p) {
			d.MM_p = new Array();
		}
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for (i=0; i<a.length; i++) {
			if (a[i].indexOf("#") != 0) {
				d.MM_p[j] = new Image();
				d.MM_p[j++].src = a[i];
			}
		}
	}
}
function MM_swapImage() {
	var i, j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array();
	for (i=0; i<(a.length-2); i += 3) {
		if ((x=MM_findObj(a[i])) != null) {
			document.MM_sr[j++] = x;
			if (!x.oSrc) {
				x.oSrc = x.src;
			}
			x.src = a[i+2];
		}
	}
}
function MM_swapImgRestore() {
	var i, x, a = document.MM_sr;
	for (i=0; a && i<a.length && (x=a[i]) && x.oSrc; i++) {
		x.src = x.oSrc;
	}
}
function MM_findObj(n, d) {
	var p, i, x;
	if (!d) {
		d = document;
	}
	if ((p=n.indexOf("?"))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p+1)].document;
		n = n.substring(0, p);
	}
	if (!(x=d[n]) && d.all) {
		x = d.all[n];
	}
	for (i=0; !x && i<d.forms.length; i++) {
		x = d.forms[i][n];
	}
	for (i=0; !x && d.layers && i<d.layers.length; i++) {
		x = MM_findObj(n, d.layers[i].document);
	}
	if (!x && d.getElementById) {
		x = d.getElementById(n);
	}
	return x;
}

///////////////////

//検索　詳細の表示・非表示
function showElementById(_arg) {var targetElement = document.getElementById (_arg);targetElement.style.display = 'block';}
function hideElementById(_arg){var targetElement = document.getElementById (_arg);targetElement.style.display = 'none';}
function openSearchBlock(targetElementID){showElementById(targetElementID);}
function closeSearchBlock(targetElementID){hideElementById(targetElementID);}
var SearchBlockOpenFlg = false;
function toggleSearchBlockArea(){
	if(SearchBlockOpenFlg){
	 	closeSearchBlock('ConditionRowAreaMore')
		SearchBlockOpenFlg =false 
		MM_swapImage('search_btn_open-area','','../common/img/search_btn_open-area.gif',1);
		document.getElementById ('search_btn_open-area').alt = 'エリア選択を開く';
	 } else {
		openSearchBlock('ConditionRowAreaMore')
		SearchBlockOpenFlg =true 
		MM_swapImage('search_btn_open-area','','../common/img/search_btn_close-area.gif',1);
		document.getElementById ('search_btn_open-area').alt = 'エリア選択を閉じる';
	 }
}
function toggleSearchBlockAreaRollOver(){
	if(SearchBlockOpenFlg){
		MM_swapImage('search_btn_open-area','','../common/img/search_btn_close-area_on.gif',1);
	 } else {
		MM_swapImage('search_btn_open-area','','../common/img/search_btn_open-area_on.gif',1);
	 }
}
function toggleSearchBlockAreaRollOut(){
	if(SearchBlockOpenFlg){
		MM_swapImage('search_btn_open-area','','../common/img/search_btn_close-area.gif',1);
	 } else {
		MM_swapImage('search_btn_open-area','','../common/img/search_btn_open-area.gif',1);
	 }
}

//検索　セレクト項目からのテキストの入れ替え
var changeFormTextArray = new Array;
changeFormTextArray[0] = '社名、特長、地域名…';
changeFormTextArray[1] = '展示場・モデルハウス名・家のイメージ…';
changeFormTextArray[2] = '建てたい家のイメージ、社名…';
changeFormTextArray[3] = '商品名、建てたい家のイメージ…';
changeFormTextArray[4] = '社名、企業の特長…';
var changeFormTextId = 0;
var changeFormTextInputFlg = false;

function changeFormText(id) {
	changeFormTextId = id;
	document.search.word.value = changeFormTextArray[id];
	document.search.word.style.color = "#999999";
	changeFormTextInputFlg = false
}
function focusFormText() {
	if(changeFormTextInputFlg ==false){
		document.search.word.value = "";
		document.search.word.style.color = "#333333";
	}
}
function blurFormText() {
	if(document.search.word.value == ''){
		document.search.word.value = changeFormTextArray[changeFormTextId];
		document.search.word.style.color = "#999999";
		changeFormTextInputFlg = false
	} else{
		changeFormTextInputFlg = true
	}
}

var changeFormTextId02 = 0;
var changeFormTextInputFlg02 = false;
function changeFormText02(id) {
	changeFormTextId02 = id;
	document.search02.word.value = changeFormTextArray[id];
	document.search02.word.style.color = "#999999";
	changeFormTextInputFlg02 = false
}
function focusFormText02() {
	if(changeFormTextInputFlg02 ==false){
		document.search02.word.value = "";
		document.search02.word.style.color = "#333333";
	}
}
function blurFormText02() {
	if(document.search02.word.value == ''){
		document.search02.word.value = changeFormTextArray[changeFormTextId02];
		document.search02.word.style.color = "#999999";
		changeFormTextInputFlg02 = false
	} else{
		changeFormTextInputFlg02 = true
	}
}


//printTopSwf
function printTopSwf () {
	if (getSwfVersion () < 6) {
		document.write (
			'<a href="http://www.macromedia.com/shockwave/download/download.cgi?P5_Language=Japanese&Lang=Japanese&Lang=Japanese&P1_Prod_Version=ShockwaveFlash" target="_blank"><img src="img/top_p_noflash.gif" width="375" height="226" alt="" /></a>'
		);
	} else {
		document.write (
			'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ' +
				'width="375" height="226" id="areaSelect" align="middle">' +
				'<param name="base" value="swf">' +
				'<param name="movie" value="swf/map.swf">' +
				'<param name="bgcolor" value="#FAF6EC">' +
				'<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ' +
					'base="swf" name="areaSelect" width="375" height="226" ' +
					'src="swf/map.swf"' + 
				'><\/embed' +
			'><\/object><br />'
		);
	}
}

//printPhotoSwf
function printPhotoSwf () {
	if (getSwfVersion () < 6) {
		document.write (
			'<a href="http://www.macromedia.com/shockwave/download/download.cgi?P5_Language=Japanese&Lang=Japanese&Lang=Japanese&P1_Prod_Version=ShockwaveFlash" target="_blank"><img src="../common/swf/img/photoswf_noflash.gif" width="628" height="358" alt="" /></a>'
		);
	} else {
		document.write (
			'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ' +
				'width="628" height="358" id="photoView" align="middle">' +
				 '<param name="movie" value="../common/swf/photo.swf?photoDir='+pDir+'&amp;xmlDir='+xDir+'&amp;xmlName='+xName+'" />'+
				 '<param name="quality" value="high" />'+
				'<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ' +
					' name="photoView" width="628" height="358" ' +
				' src="../common/swf/photo.swf?photoDir='+pDir+'&amp;xmlDir='+xDir+'&amp;xmlName='+xName+'"' +
				'><\/embed' +
			'><\/object><br />'
		);
	}
}
