﻿// cookie ----------------------------------------
var v_IE = (document.documentElement.getAttribute("style") == document.documentElement.style);
var v_class;
if(v_IE) v_class = "className";
if(!v_IE) v_class = "class";
function f_setCookie(key, val, param) {
cookieName = key + "=" + escape(val) + ";";
cookieName += "name=gtm;";
effectPath = "path=/;";
switch(param) {
case "temporary":
if(!v_IE) expiresTime = "expires=0";
if(v_IE) expiresTime = "expires=";
break;
default:
nowTime = new Date();
nowTime.setTime(nowTime.getTime() + (3000 * 1000 * 60 * 60 * 24));
expiresTime = "expires=" + nowTime.toGMTString();
break;
}
document.cookie = cookieName + effectPath + expiresTime;
}

//RollOver ----------------------------------------
var RollOver = Class.create();
RollOver.prototype = {
initialize: function(option) {
var props = {
hclass : "imgover",
suffix : "_on"
};
if(option) for(var key in option) props[key] = option[key];
$$('img.'+props.hclass,'input.'+props.hclass).each(
function(el){
var osrc = el.getAttribute('src');
if (!osrc) return;
var hsrc = osrc.replace(/(\.gif|\.jpg)/,props.suffix+'$1');
(new Image()).src = hsrc;
el.observe("mouseover",function(){
el.setAttribute('src', hsrc);
}).observe("mouseout",function(){
el.setAttribute('src', osrc);
});
}
);
}
}
Event.observe(window,'load',function(){new RollOver();});

Event.observe(window, 'load', function() {
$$('a[href^="#"]:not([href="#"])').each(function(element) {
element.observe('click', function(event) {
new Effect.ScrollTo(this.hash.substr(1));
Event.stop(event);
}.bindAsEventListener(element))
})
});

//NewsFlash situation Open Close ----------------------------------------
function newsFlashOpen(){
	document.getElementById('situation').style.display  = 'block';
	document.getElementById('dispOff').style.display      = 'block';
	document.getElementById('dispOn').style.display     = 'none';
}

function newsFlashClose(){
	document.getElementById('situation').style.display  = 'none';
	document.getElementById('dispOn').style.display     = 'block';
	document.getElementById('dispOff').style.display      = 'none';
}

//Tab Change ----------------------------------------
var TabMaker = Class.create()
TabMaker.prototype = {
	initialize: function(name) {
		tabs = $A($(name + 'Index').getElementsByTagName('li'));
		var menu = new TabIndex(name);
		for(var i=0,l=tabs.length; i < l; i++){
			var tab = new Tab(name + '' + i, (i==0));
			menu.appendTab(tab);
		}
		menu.setTab();
	}
}
var Tab = Class.create();
Tab.prototype = {
	initialize: function(name, open) {
		this.name = name;
		this.page = name + 'Box';
		this.open = open;
	},
	styleTab: function() {
		if (this.open)
			this.setStyle('visible', 'block', '', 'open');
		else
			this.setStyle('hidden', 'none', 'absolute', 'close');
		this.open = false;
	},
	setStyle: function(visibility, display, position, className){
		var page = $(this.page).style;
		var name = $(this.name);
		page.visibility = visibility;
		page.display = display;
		page.position = position;
		name.className = className;
	}
}
var TabIndex = Class.create();
TabIndex.prototype = {
	initialize : function(name) {
		this.last = 0;
		this.tabs = new Array();
		this.tabName = name;

		this.tabMenuList = $(name + 'Index').getElementsByTagName('li');

		var temp = $A($(name + 'BoxIndex').getElementsByTagName('div'));
		var list = [];

		temp.each(function(div){
			if(div.className==name+'Box'){
				list.push(div);
			}
		});

		this.tabBoxList = list;
	},
	getTabAt : function(index) {
		return this.tabs[index];
	},
	appendTab : function(tab) {
		this.tabs[this.last] = tab;

		this.tabMenuList[this.last].id = tab.name;
		this.tabBoxList[this.last].id = tab.page;
		this.last++;

		var link = document.createElement('a');
		link.innerHTML = $(tab.name).innerHTML;
		link.href = 'javascript:void(0);'
		$(tab.name).innerHTML = '';
		$(tab.name).appendChild(link);
		$(tab.name).onclick = function(){
			tab.open = true;
			this.setTab();
		}.bind(this);
	},

	setTab: function() {
		this.tabs.each(function(tab) {
			tab.styleTab();
		});
	}
};

//Opne Windows ----------------------------------------
function openWin(url,wnm,w,h) {
	var prop = "width="+w+",height="+h+",scrollbars=yes,status=no,toolbar=no,location=no,resizable=yes";
	var w = window.open(url,wnm, prop);
	w.focus();}
