var hostname;
var cgi_host;
var www_host;

var pathname;
var path_arr;
var path_name;

var file_name;
var up_path;

var link_prefix_cgi;
var link_prefix_www;

var randtime = new Date().getTime() + Math.random();

if(window.location.hostname != ""){
	hostname = window.location.hostname;
	if (hostname.match(/^(www|cgi)[0-9]+\./)) {
		document.open('text/html', '_self');
		document.write(unescape("%3Chtml%3E%3Chead%3E%3C/head%3E%3Cbody%3E%3C/body%3E%3C/html%3E"));
		document.close();
		window.location.href = window.location.href.replace(/^(https?:\/\/)(www|cgi)[0-9]+\./, '$1$2.');
	}

	cgi_host = 'cgi'+hostname.substr(3);
	www_host = 'www'+hostname.substr(3);

	pathname = window.location.pathname;
	path_arr = pathname.split("/");
	path_name = "";
	for(i=0;i<path_arr.length-1;i++){
		path_name += path_arr[i]+"/";
	}
	file_name = path_arr[path_arr.length-1].split(".")[0];
	up_path = path_name.substr(1).replace(/[^\/]+/g, '..');

	document.write(unescape("%3Clink href='"+up_path+"css/thform.css' rel='stylesheet' type='text/css' /%3E"));
	document.write(unescape("%3Cscript src='" + up_path + "js/thform.js' type='text/javascript'%3E%3C/script%3E"));

	link_prefix_cgi = 'http://'+cgi_host+path_name;
	link_prefix_www = 'http://'+www_host+path_name;

}

$(function(){
	var image_cache = new Object();
	$(".hover").not("[src*='_o.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_o' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});

	$("#input")
	.blur(function(){
		var $this = $(this);
		if($this.val()==''){
			$this.css("background-image","url("+up_path+"images/share/head_seach_bg.gif)");
		}
	})
	.focus(function(){
		var $this = $(this);
		if($this.val()==''){
			$this.css("background-image","url("+up_path+"images/share/head_seach_bg_active.gif)");
		}
	}).blur();

	//リンクprefix設定
	jQuery.each($("a[href$='.html']").not("[href^='http://'],[href^='https://'],[href^='/']"), function() {
		$(this).attr("href", link_prefix_www + $(this).attr("href"));
	});
	jQuery.each($("a[href$='.php']").not("[href^='http://'],[href^='https://'],[href^='/']"), function() {
		$(this).attr("href", link_prefix_cgi + $(this).attr("href"));
	});
	jQuery.each($("form[action$='.php']").not("[action^='http://'],[action^='https://'],[action^='/']"), function() {
		$(this).attr("action", link_prefix_cgi + $(this).attr("action"));
	});

});

function MM_openBrWindow(theURL,winName,features) { //v2.0
  w = window.open(theURL,winName,features);
	w.focus();
}

function getElementWidth(objectId) {
	x = document.getElementById(objectId);
	return x.offsetWidth;
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	return oTop
}

