/*
SwfTagWriter.js  version 1.0.7  2006/5/1

Copyright (c) 2005 Katsuyuki Sakai (http://catalase.jp/)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

if(typeof jp == "undefined") jp = new Object();
if(typeof jp.catalase == "undefined") jp.catalase = new Object();
if(typeof jp.catalase.FlashPlayerDetector == "undefined") jp.catalase.FlashPlayerDetector = new Object();
if(typeof jp.catalase.Util == "undefined") jp.catalase.Util = new Object();

jp.catalase.Util.htmlEscape = function(str){
	return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

jp.catalase.SwfTagWriter = function(swf, id, width, height){
	this._swf = swf;
	this._id = id;
	this._width = width;
	this._height = height;
	this._requiredVer = new jp.catalase.FlashPlayerDetector.PlayerVersion(0, 0, 0);
	this._loop = "false";
	this._quality = "high";
	this._altContent = "";
	this._flashvarsAry = new Array();
	this._attrAry = new Array();
	this._paramAry = new Array();
	this._doesShowPlayerInstallMsg = false;
	this._playerInstallMsg = '<p>You have to <a href="http://www.macromedia.com/jp/shockwave/download/?P1_Prod_Version=ShockwaveFlash&amp;Lang=Japanese">install or update Flash Player</a> in order to display the content.</p>';
}
jp.catalase.SwfTagWriter.prototype.setRequiredVersion = function(){
	var major = arguments[0] ? arguments[0] : 0;
	var minor = arguments[1] ? arguments[1] : 0;
	var release = arguments[2] ? arguments[2] : 0;
	this._requiredVer = new jp.catalase.FlashPlayerDetector.PlayerVersion(major, minor, release);
}
jp.catalase.SwfTagWriter.prototype.setLoop = function(loop){
	this._loop = loop;
}
jp.catalase.SwfTagWriter.prototype.setQuality = function(quality){
	this._quality = quality;
}
jp.catalase.SwfTagWriter.prototype.setAltContent = function(altContent){
	this._altContent = altContent;
}
jp.catalase.SwfTagWriter.prototype.addFlashVars = function(key, val){
	this._flashvarsAry[key] = val;
}
jp.catalase.SwfTagWriter.prototype.addAttribute = function(key, val){
	this._attrAry[key] = val;
}
jp.catalase.SwfTagWriter.prototype.addParam = function(key, val){
	this._paramAry[key] = val;
}
jp.catalase.SwfTagWriter.prototype.doesShowPlayerInstallMsg = function(b){
	this._doesShowPlayerInstallMsg = b;
}
jp.catalase.SwfTagWriter.prototype.setPlayerInstallMsg = function(msg){
	this._playerInstallMsg = msg;
}
jp.catalase.SwfTagWriter.prototype.writeHTML = function(){
	document.write(this.getHTML());
}
jp.catalase.SwfTagWriter.prototype.setFlashDetectorSwfUrl = function(url){
	jp.catalase.FlashPlayerDetector.setFlashDetectorSwfUrl(url);
}
jp.catalase.SwfTagWriter.prototype.getFlashvars = function(){
	var tmpAry = new Array();
	var result = '';
	for(var key in this._flashvarsAry){
		var value = this._flashvarsAry[key];
		if(typeof value == 'function') continue;
		
		tmpAry=tmpAry.concat([key + "=" + jp.catalase.Util.htmlEscape(this._flashvarsAry[key])])
	}
	result = tmpAry.join('&');
	
	if(result.length>0){
		return '<param name="flashvars" value="' + result + '" />' + "\n";
	}else{
		return '';
	}
}
jp.catalase.SwfTagWriter.prototype.getParamHtml = function(){
	var result = '';
	for(var key in this._paramAry){
		var value = this._paramAry[key];
		if( (typeof value == 'function')||(key.match(/movie|loop|quality/i)) ) continue;
		
		result += '<param name="' + key + '" value="' + jp.catalase.Util.htmlEscape(value) + '" />' + "\n";
	}
	return result;
}
jp.catalase.SwfTagWriter.prototype.getHTML = function(){
	var agt = navigator.userAgent.toLowerCase();
	var result = '';
	
	//Check if browser is Windows IE
	if( (agt.indexOf("msie") != -1) && (agt.indexOf("win")!=-1) && (agt.indexOf("opera") == -1) ){
		//Windows IE
		
		//Check if FlashPlayer isn't available or it meets requirements.
		if( !jp.catalase.FlashPlayerDetector.isFlashPlayerAvailable() || jp.catalase.FlashPlayerDetector.getFlashPlayerVersion().doesMeetRequirements(this._requiredVer) ){
			//We can write object tag whether Flash Player is available or not. Because Windows IE can automatically install Flash Player.
			
			result += '<object ';
			result += 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
			result += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#' + this._requiredVer.toString() + '" ';
			result += 'width="' + this._width + '" ';
			result += 'height="' + this._height + '" ';
			result += 'id="' + this._id + '" ';
			
			for(var key in this._attrAry){
				var value = this._attrAry[key];
				if(typeof value == 'function') continue;
				
				result += key + '="' + jp.catalase.Util.htmlEscape(this._attrAry[key]) + '" ';
			}
			
			result += '>' + "\n";
			
			result += '<param name="movie" value="' + this._swf + '" />' + "\n";
			result += '<param name="loop" value="' + this._loop + '" />' + "\n";
			result += '<param name="quality" value="' + this._quality + '" />' + "\n";
			
			result += this.getParamHtml();
			
			result += this.getFlashvars();
			
			result += this._altContent;
			
			result += '</object>' + "\n";
		}else{
			//Flash player is available but it doesn't meet requirements.
			
			//Display alternative contents if available
			result += this._altContent;
			
			//Display player install message if needed
			if(this._doesShowPlayerInstallMsg){
				result += this._playerInstallMsg;
			}
		}
	}else{
		//All but Windows IE
		
		//Check if FlashPlayer is available
		if(jp.catalase.FlashPlayerDetector.isFlashPlayerAvailable()){
			
			//We have to check if FlashPlayer's version meets required version.
			if(jp.catalase.FlashPlayerDetector.getFlashPlayerVersion().doesMeetRequirements(this._requiredVer)){
				result += '<object ';
				result += 'type="application/x-shockwave-flash" ';
				result += 'data="' + this._swf + '" ';
				result += 'width="' + this._width + '" ';
				result += 'height="' + this._height + '" ';
				result += 'id="' + this._id + '" ';
				
				for(var key in this._attrAry){
					var value = this._attrAry[key];
					if(typeof value == 'function') continue;
					
					result += key + '="' + jp.catalase.Util.htmlEscape(this._attrAry[key]) + '" ';
				}
				
				result += '>' + "\n";
				
				result += '<param name="movie" value="' + this._swf + '" />' + "\n";
				result += '<param name="loop" value="' + this._loop + '" />' + "\n";
				result += '<param name="quality" value="' + this._quality + '" />' + "\n";
				
				result += this.getParamHtml();
				
				result += this.getFlashvars();
				
				if( !((agt.indexOf('mozilla')!=-1) && (parseInt(navigator.appVersion)==4)) ){
					//Netscape 4 displays both object tag contents and alternative contents. So we have to avoid including alternative contents.
					result += this._altContent;
				}
				
				result += '</object>' + "\n";	
			}else{
				//Installed Flash Player's version doesn't meet requirements.
				
				//Display alternative contents if available
				result += this._altContent;
				
				//Display player install message if needed
				if(this._doesShowPlayerInstallMsg){
					result += this._playerInstallMsg;
				}
			}
		}else{
			//Flash Player is not available.
			
			//Display alternative contents if available
			result += this._altContent;
			
			//Display player install message if needed
			if(this._doesShowPlayerInstallMsg){
				result += this._playerInstallMsg;
			}
		}
	}
	
	return result;
}

jp.catalase.FlashPlayerDetector.isFlashPlayerAvailable = function(){
	var result = false;
	if(navigator.plugins && navigator.mimeTypes.length>0 && navigator.plugins["Shockwave Flash"]){
		result = true;
	}else if(window.ActiveXObject){
		/*@cc_on
		@if(@_jscript_version >= 5.0)
		try{
			var player = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			result = true;
		} catch (e) {}
		@end @*/
	}
	return result;
}
jp.catalase.FlashPlayerDetector.setFlashDetectorSwfUrl = function(url){
	jp.catalase.FlashPlayerDetector._flashDetectorSwfUrl = url;
}
jp.catalase.FlashPlayerDetector.getFlashPlayerVersion = function(){
	var result = new jp.catalase.FlashPlayerDetector.PlayerVersion(0, 0, 0);
	
	if(jp.catalase.FlashPlayerDetector.isFlashPlayerAvailable()){
		if(navigator.plugins && navigator.mimeTypes.length>0 && navigator.plugins["Shockwave Flash"]){
			var player = navigator.plugins["Shockwave Flash"];
			var desc = player.description;
			var versionRex = /([0-9]+)\.([0-9]+)\s+r([0-9]+)/;
			if(desc.match(versionRex)!=null){
				result = new jp.catalase.FlashPlayerDetector.PlayerVersion(RegExp.$1, RegExp.$2, RegExp.$3);
			}
		}else if(window.ActiveXObject){
			/*@cc_on
			@if(@_jscript_version >= 5.0)
			try{
				var player = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				var major = Math.floor(player.FlashVersion()/ 0x10000);
				var minor = player.FlashVersion()% 0x10000;
				result = new jp.catalase.FlashPlayerDetector.PlayerVersion(major, minor, 0);
				
				if( (major<7) && (jp.catalase.FlashPlayerDetector._flashDetectorSwfUrl) && (jp.catalase.FlashPlayerDetector._flashDetectorSwfUrl.length>0) ){
					//We have to insert 1x1px small swf to get the variable named $version if player's major version is below 7. Because the player isn't ready to access the variable when no swf is loaded. If we force to access the variable, browser stops running script.
					if(!document.getElementById("jp_catalase_FlashDetector_util_EmbedSwf")){
						document.write('<div id="jp_catalase_FlashDetector_util_EmbedDiv" style="position:absolute; top:-10px; left:-10px; width:1px; height:1px; z-index:1;">');
						document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1" height="1" id="jp_catalase_FlashDetector_util_EmbedSwf">');
						document.write('<param name="movie" value="', jp.catalase.FlashPlayerDetector._flashDetectorSwfUrl, '">');
						document.write('</object>');
						document.write('</div>');
					}
					player = document.getElementById("jp_catalase_FlashDetector_util_EmbedSwf");
				}
				
				if( (major>=7) || document.getElementById("jp_catalase_FlashDetector_util_EmbedSwf") ){				
					var verStr = player.GetVariable("$version");
					var versionRex = /([0-9]+),([0-9]+),([0-9]+)/;
					if(verStr.match(versionRex)!=null){
						result = new jp.catalase.FlashPlayerDetector.PlayerVersion(RegExp.$1, RegExp.$2, RegExp.$3);
					}
				}
			} catch (e) {}
			@end @*/
		}
	}
	return result;
}

jp.catalase.FlashPlayerDetector.PlayerVersion = function(major, minor, release){
	this._major = parseInt(major);
	this._minor = parseInt(minor);
	this._release = parseInt(release);
}
jp.catalase.FlashPlayerDetector.PlayerVersion.prototype.doesMeetRequirements = function(requiredVer){
	if(this._major < requiredVer._major) return false;
	if(this._major > requiredVer._major) return true;
	if(this._minor < requiredVer._minor) return false;
	if(this._minor > requiredVer._minor) return true;
	if(this._release < requiredVer._release) return false;
	if(this._release > requiredVer._release) return true;
	return true;
}
jp.catalase.FlashPlayerDetector.PlayerVersion.prototype.toString = function(){
	return this._major + "," + this._minor + "," + this._release + ",0";
}



//イメージオーバー切り替え//
function chimg(filename,target){
	document.images[target].src = filename;
}

function preloadimg(){
	preloadimg = new Array();
	for(i = 0; i < preimages.length; i++){
		preloadimg[i] = new Image();
		preloadimg[i].src =  preimages[i];
	}
}

function preloadimg2(){
	preloadimg2 = new Array();
	for(i = 0; i < preimages2.length; i++){
		preloadimg2[i] = new Image();
		preloadimg2[i].src =  preimages2[i];
	}
}

function preloadimg3(){
	preloadimg3 = new Array();
	for(i = 0; i < preimages3.length; i++){
		preloadimg3[i] = new Image();
		preloadimg3[i].src =  preimages3[i];
	}
}



//すべてにチェック//
function ctrlCheckBox(bool) {
	if(document.chkall.chkbox){
		for(i = 0; i < document.chkall.chkbox.length; i++) {
			document.chkall.chkbox[i].checked = bool;
		}
		//IEで1件だけの場合にチェックを入れる
		document.chkall.chkbox.checked = bool;
	}
}



//さらに詳しい条件//
function initDisplay() {
	document.getElementById("detail").style.display = "none";
	document.getElementById("switch").innerHTML = "+さらに詳しい条件";
}
function ctrlDisplay() {
	var switchObj = document.getElementById("switch");
	var blockObj = document.getElementById("detail");
	if (blockObj.style.display == "block") {
		blockObj.style.display = "none";
		switchObj.innerHTML = "+さらに詳しい条件";
	} else {
		blockObj.style.display = "block";
		switchObj.innerHTML = "-さらに詳しい条件";
	}
}


//お役立ち情報//
function initDisplay2() {	// 初期化
	document.getElementById("detail1").style.display = "none";
	document.getElementById("switch1").innerHTML = "+ 初めてリフォームする方へ";
	document.getElementById("detail2").style.display = "none";
	document.getElementById("switch2").innerHTML = "+ リフォーム基礎知識";
	document.getElementById("detail3").style.display = "none";
	document.getElementById("switch3").innerHTML = "+ リフォーム費用について";
	document.getElementById("detail4").style.display = "none";
	document.getElementById("switch4").innerHTML = "+ 実例ヒント集";
	document.getElementById("detail5").style.display = "none";
	document.getElementById("switch5").innerHTML = "+ リフォーム用語集";
	document.getElementById("detail6").style.display = "none";
	document.getElementById("switch6").innerHTML = "+ オススメ！リフォーム密着記事";
}
function ctrlDisplay2(i, index) {	// スイッチ
	var switchObj = document.getElementById("switch" + i);
	var blockObj = document.getElementById("detail" + i);
	if (blockObj.style.display == "block") {
		blockObj.style.display = "none";
		switchObj.innerHTML = "+ " + index;
	} else {
		blockObj.style.display = "block";
		switchObj.innerHTML = "- " + index;
	}
}


//入力欄の挙動TOP以外
function onFocusBehavior(obj) {
	if (obj.value == obj.defaultValue) {
		obj.style.color = '#000000';
	}
	obj.style.backgroundColor = '#ffebfb';
}
function onBlurBehavior(obj) {
	if (!obj.value) {
		obj.style.color = '#999999';
	}
	obj.style.backgroundColor = '#ffffff';
}
//入力欄の挙動
function onFocusBehaviorTop(obj) {
	if (obj.value == obj.defaultValue) {
		obj.value = '';
		obj.style.color = '#000000';
	}
	obj.style.backgroundColor = '#ffebfb';
}
function onBlurBehaviorTop(obj) {
	if (!obj.value) {
		obj.value = obj.defaultValue;
		obj.style.color = '#999999';
	}
	obj.style.backgroundColor = '#ffffff';
}



//divの開閉の初期値//
function initDispaly() {
	document.getElementById("detail").style.display = "none";
	document.getElementById("switch").innerHTML = "+さらに詳しい条件";
}

//target _blankの代替　※R追加　//
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
function addEvent(func) {
  if (window.addEventListener) {
    window.addEventListener("load", func, false);
  } else if (window.attachEvent) {
    window.attachEvent("onload", func);
  }
}
addEvent(externalLinks);
