//Rollover Images
/*
*	Image rollover js
*	Author : Kazuhito Hokamura
*	http://webtech-walker.com/
*
*	Licensed under the MIT License:
*	http://www.opensource.org/licenses/mit-license.php
*/

(function(){
	function rollover(){
		var targetClassName = "overImg";
		var suffix = "_on";

		var overReg = new RegExp("^(.+)(\\.[a-z]+)$");
		var outReg = new RegExp("^(.+)" + suffix + "(\\.[a-z]+)$");

		var preload = new Array();
		var images = document.getElementsByTagName("img");

		for (var i = 0, il = images.length; i < il; i++) {
			var classStr = images[i].getAttribute("class") || images[i].className;
			var classNames = classStr.split(/\s+/);
			for(var j = 0, cl = classNames.length; j < cl; j++){
				if(classNames[j] == targetClassName){
					//preload
					preload[i] = new Image();
					preload[i].src = images[i].getAttribute("src").replace(overReg, "$1" + suffix + "$2");

					//mouseover
					images[i].onmouseover = function() {
						this.src = this.getAttribute("src").replace(overReg, "$1" + suffix + "$2");
					}
					//mouseout
					images[i].onmouseout = function() {
						this.src = this.getAttribute("src").replace(outReg, "$1$2");
					}
				}
			}
		}
	}

	function addEvent(elem,event,func){
		if(elem.addEventListener) {
			elem.addEventListener(event, func, false);
		}else if(elem.attachEvent) {
			elem.attachEvent("on" + event, func);
		}
	}
	addEvent(window,"load",rollover);
})();



//target="_blank"
window.onload = blankLinks;

function blankLinks() {
	var x = document.getElementsByTagName('a');
	for (var i=0; i<x.length; i++) {
		if (x[i].getAttribute('className') == 'blank' || x[i].getAttribute('class') == 'blank' || 
			x[i].getAttribute('className') == 'blankLink' || x[i].getAttribute('class') == 'blankLink') {
			x[i].target = '_blank';
		}
	}
}



//Input, Textarea 初期値クリア
function setFocus(){
	var input = document.getElementsByTagName("input");
	var textarea = document.getElementsByTagName("textarea");

	// input
	for (i=0;i<input.length;i++){
		if((input[i].getAttribute('type') == 'text') || (input[i].getAttribute('type') == null)){
			if (input[i].value == input[i].defaultValue){
				input[i].className += ' default-value'
			}
			input[i].onfocus = function(){
				if (this.value == this.defaultValue){
					this.value = "";
					this.className = this.className.replace(/ default-value/, "");
				}
			}
			input[i].onblur = function() {
				if (this.value == '') {
					this.value = this.defaultValue;
					this.className += " default-value"
				}
			}
		}
	}

	// textarea
	for (i=0;i<textarea.length;i++){
		if (textarea[i].value == textarea[i].defaultValue){
			textarea[i].className += " default-value"
		}
		textarea[i].onfocus = function(){
			if (this.value == this.defaultValue){
				this.value = "";
				this.className = this.className.replace(/ default-value/, "");
			}
		}
		textarea[i].onblur = function(){
			if (this.value == ""){
				this.value = this.defaultValue;
				this.className += " default-value"
			}
		}
	}
}

function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	}
	else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
	else {
		return false;
	}
}

addEvent(window, 'load', setFocus);



/*function putFocus(this) {
	this.defaultValue = this.value;
	this.value = '';

	//onblur
	this.onblur = function () {
		if (this.value == '') {
			this.value = this.defaultValue;
		}
	}

	//onfocus
	this.onfocus = function() {
		if (this.value == this.defaultValue) {
			this.value = '';
		}
	}

}*/


/*function setFocus( that) {  
        that._defaultValue = that.value;  
        that.value = '';  
        that.onblur = function() {  
            if( that.value === '' ) {  
                that.value = that._defaultValue;  
            }  
        }  
        that.onfocus = function() {  
            if( that.value === that._defaultValue ) {  
                that.value = '';  
            }  
        }  
    }*/