/* make rollover on search form button */

function makeRollSearch()  {
	// search
	if (document.getElementById('kensakuBut')) {
		var theBut = document.getElementById('kensakuBut');
		theBut.onmouseover = function () {
			this.className = "kensakuButOvr";
		}
		theBut.onmouseout = function () {
			this.className = "kensakuButOff";
		}
	}

	// search
	if (document.getElementById('inqueryBut2')) {
		var theBut = document.getElementById('inqueryBut2');
		theBut.onmouseover = function () {
			this.className = "inqueryBut2Ovr";
		}
		theBut.onmouseout = function () {
			this.className = "inqueryBut2Off";
		}
	}

	// go to area
	if (document.getElementById('selectAreaBut')) {
		var theBut = document.getElementById('selectAreaBut');
		theBut.onmouseover = function () {
			this.className = "selectAreaButOvr";
		}
		theBut.onmouseout = function () {
			this.className = "selectAreaButOff";
		}
	}
	// go to station
	if (document.getElementById('selectLineBut')) {
		var theBut = document.getElementById('selectLineBut');
		theBut.onmouseover = function () {
			this.className = "selectLineButOvr";
		}
		theBut.onmouseout = function () {
			this.className = "selectLineButOff";
		}
	}
	
}

function bigFave() {
	if (document.getElementsByTagName('img')) {
		var clicked = new Image();
		clicked.src = "http://static.tokyooffice.jp/ofc/img/btn-add-fave-on.gif";
		var theImg = document.getElementsByTagName('img');
		for (i=0; i<theImg.length; i++) {
			theImg[i].onclick = function () {
				if (this.className == "faveBukken off") {
					// ajax call... get parent item id with
					// rel = idxxx where xxx is item id
					// alert(this.parentNode.getAttribute('rel').substr(2));
					this.className = "faveBukken on";
					// to kill reload with firefox
					var futdate = new Date();
					this.src = clicked.src+"?n="+futdate.getTime();
					this.parentNode.setAttribute('title', '候補物件の消除');
					return false;
				} else if (this.className == "faveBukken on") {
					// ajax call...
					this.className = "faveBukken off";
					this.src = "http://static.tokyooffice.jp/ofc/img/btn-add-fave.gif";
					this.parentNode.setAttribute('title', '候補物件に追加');
					return false;
				}
				this.blur();
				
			}
		}
	}
}

function smallFave()  {
	if (document.getElementById('faveThisBuk')) {
		var theLink = document.getElementById('faveThisBuk');
		theLink.onclick = function () {
			if (this.className == "off") {
				// ajax call
				// get id with "rel" element : idxxxx
				// alert(this.getAttribute('rel').substr(2));
				this.className = "on";
				this.innerHTML = "候補物件の消除";
				this.blur();
				return false;
			} else if (this.className == "on") {
				// ajax call
				this.className = "off";
				this.innerHTML = "候補物件に追加";
				this.blur();
				return false;
			}
			
		}
	}
}


var i = false; // La variable i nous dit si la bulle est visible ou non
				

/* old function, not used anymore in inquire-office-01-alt2.html */

function inquiryRollover() {
	if (document.getElementsByTagName('label')) {
		var theLabels = document.getElementsByTagName('label');
		for (i=0; i<theLabels.length; i++) {
			theLabels[i].onmouseover = function () {
				if (this.className == "showHide") {
					document.getElementById('thePopup').innerHTML = this.parentNode.getElementsByTagName('span')[0].innerHTML;
					document.getElementById('thePopup').style.visibility="visible";
					border.render('thePopup');
					i=true;
				} 
			}
			theLabels[i].onmouseout = function () {
				if (this.className == "showHide") {
					document.getElementById('thePopup').style.visibility="hidden";
					document.getElementById('thePopup').innerHTML = "";
					i=false;
				} 
			}
		}
	}
}

function inquiryRollover2() {
	if (document.getElementsByTagName('img')) {
		var theLabels = document.getElementsByTagName('img');
		for (i=0; i<theLabels.length; i++) {
			theLabels[i].onmouseover = function () {
				if (this.className == "kuwasikuIcon") {
					document.getElementById('thePopup').innerHTML = this.parentNode.getElementsByTagName('span')[0].innerHTML;
					document.getElementById('thePopup').style.visibility="visible";
					//border.render('thePopup');
					i=true;
				} 
			}
			theLabels[i].onmouseout = function () {
				if (this.className == "kuwasikuIcon") {
					document.getElementById('thePopup').style.visibility="hidden";
					document.getElementById('thePopup').innerHTML = "";
					i=false;
				} 
			}
		}
	}
}

function mouseMove(ev){
	if(document.getElementById('thePopup')){
		ev = ev || window.event;
		var mousePos = mouseCoords(ev);
		document.getElementById('thePopup').style.left = mousePos.x+5+"px";
		document.getElementById('thePopup').style.top = mousePos.y+10+"px";
	}
}

function mouseCoords(ev){
	if (i) {
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	}
}

function rollovrregisteredBuk() {
	if (document.getElementById('btnShowRegisteredBuk')) {
		
		// preloading images
		var imgVar1 = new Image();
		imgVar1.src = "http://static.tokyooffice.jp/ofc/e_img/btn-show-registered-ovr.gif";
		var imgVar2 = new Image();
		imgVar2.src = "http://static.tokyooffice.jp/ofc/e_img/btn-show-registered-flag.gif";
		
		var theButton = document.getElementById('btnShowRegisteredBuk');
		theButton.onmouseover = function () {
	 		this.firstChild.src = imgVar1.src;
		}
		theButton.onmouseout = function () {
	 		this.firstChild.src = "http://static.tokyooffice.jp/ofc/e_img/draft-11-btn-seesavedbukken.gif";
		}
	}
}

function flashRegister() {
		if (document.getElementById('btnShowRegisteredBuk')) {	
		var theButton = document.getElementById('btnShowRegisteredBuk');
		theButton.firstChild.src = "./e_img/btn-show-registered-flag.gif";
		
	}
}

function showHideFormPart() {
	if (document.getElementById('kibouType01')) {
		document.getElementById('kibouType01').onclick = function () {
			document.getElementById('selectBlock02').style.display = "none";
			document.getElementById('selectBlock01').style.display = "block";
		}
	}
	if (document.getElementById('kibouType02')) {
		document.getElementById('kibouType02').onclick = function () {
			document.getElementById('selectBlock01').style.display = "none";
			document.getElementById('selectBlock02').style.display = "block";
		}
	}
}

function designShowCase() {
	if (document.getElementsByClassName('designSearch') || document.getElementsByClassName('smlPic')) {
		var linksArray = document.getElementsByClassName('smlPic');
		for (i=0; i<linksArray.length; i++) {
			linksArray[i].onclick = function () {

				var imgPath = new Image();
				imgPath.src =  this.getAttribute('href');
				var imageDescri = this.getAttribute('title');

				this.parentNode.parentNode.getElementsByTagName('img')[0].src = imgPath.src;
				this.parentNode.parentNode.getElementsByTagName('img')[0].setAttribute('alt', imageDescri);
				this.parentNode.parentNode.getElementsByTagName('p')[0].innerHTML = imageDescri;
				
				this.blur();
				return false;
			}
		}
	}
}


function designShowCase2() {
	if (document.getElementsByClassName('designSearch') || document.getElementsByClassName('smlPic')) {
		var linksArray = document.getElementsByClassName('smlPic');
		
		imgLoader = new Image();
		imgLoader.src = "http://static.tokyooffice.jp/ofc/img/loader3.gif";
		
		for (i=0; i<linksArray.length; i++) {
			linksArray[i].onclick = function () {
				
				thePath = this.parentNode.parentNode.parentNode.getElementsByTagName('img')[0];
				thePath.src = imgLoader.src;
				
//				theLegend = this.parentNode.parentNode.parentNode.getElementsByTagName('p')[0];
//				theLegend.innerHTML = "";
				
				imgToShow = new Image();
				imgToShow.src =  this.getAttribute('href');
				imageDescri = this.getAttribute('title');
				
				timedCount();
				
				this.blur();
				return false;
			}
		}
	}
}

function timedCount(){
	if (!IsImageOk(imgToShow)) {
		t=setTimeout("timedCount()",1000);
	}
	else {
		thePath.src = imgToShow.src;
		thePath.setAttribute('alt',imageDescri);
//		theLegend.innerHTML = imageDescri;
	}
}

function IsImageOk(img) {
    // During the onload event, IE correctly identifies any images that
    // weren't downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth and
    // naturalHeight. These give the true size of the image. If it failed
    // to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}


window.onload = function () {
	makeRollSearch();
//	bigFave();
//	smallFave();
	//inquiryRollover();
//	inquiryRollover2();
	rollovrregisteredBuk();
//	showHideFormPart();
//	designShowCase2();
}

document.onmousemove = mouseMove;