/*********************************************************************
 *
 *  </en/common/js/common.js>
 * 
 * ===================================================================
 *
 *  このJavScriptの動作には、以下のjsファイルが必要です。
 *
 *     - jquery.js (1.2.5)
 *     - jquery.preload.js (1.0.7)
 *     - styleswitcher.js
 *
 *********************************************************************/

$(function(){
	// Header
	var defaultText = 'Search within Website';

	$("div#header p.search input.text").val(defaultText)
		.focus(function() {
			if($(this).val() == defaultText) { $(this).val(''); }
		})
		.blur(function() {
		   if(!$(this).val()) { $(this).val(defaultText); }
		});
	
	// Link Hover (div.article)
	$("div#main div.article").not(".one_column").find("div.left p a").hover(
		function(){ $(this).parents(".article").addClass("hover_left"); },
		function(){ $(this).parents(".article").removeClass("hover_left"); }
	);

	$("div#main div.article.one_column div.left p a").hover(
		function(){ $(this).parents(".article").addClass("hover_one_column"); },
		function(){ $(this).parents(".article").removeClass("hover_one_column"); }
	);

	$("div#main div.article div.right p a").hover(
		function(){ $(this).parents(".article").addClass("hover_right"); },
		function(){ $(this).parents(".article").removeClass("hover_right"); }
	);

	$("div#main div.article ul.link a").hover(
		function(){ $(this).parents("li").addClass("hover_list"); },
		function(){ $(this).parents("li").removeClass("hover_list"); }
	);

	// Link Hover (ul.hover)
	$("div#main ul.hover li").not(".no_hover").hover(
		function(){ $(this).addClass("hover_list"); },
		function(){ $(this).removeClass("hover_list"); }
	);

	// Link Hover (p.hover)
	$("div#main p.hover").hover(
		function(){ $(this).addClass("hover_list"); },
		function(){ $(this).removeClass("hover_list"); }
	);

	// Popup Window
	$("div#body .link_popup a").click(function() {popUpWindow(this.href, "popupWin", "660", "660", "scrollbars=yes,location=yes,menubar=yes,resizable=yes"); return false;} );
	var newWin = 0;
	function popUpWindow(URLStr, name, width, height, status) {
	   newWin = open(URLStr, name, status+",width="+width+",height="+height);
	   newWin.focus();
	}

	// Close
	$("div#body p.close img").click( function() { window.close(); });

	// Font Changer (Set)
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);

	$("div#header div.utilities").append('<dl id="font_changer">'+
		'<dt><img src="/en/common/image/txt_font.gif" alt="Text Size" /></dt>'+
		'<dd class="small"><a href="#">Small</a></dd>'+
		'<dd class="medium"><a href="#">Medium</a></dd>'+
		'<dd class="large"><a href="#">Large</a></dd>'+
		'</dl>');

	$("dl#font_changer dd.small a").click(function(e){ setActiveStyleSheet('small'); return false; });
	$("dl#font_changer dd.medium a").click(function(e){ setActiveStyleSheet('medium'); return false; });
	$("dl#font_changer dd.large a").click(function(e){ setActiveStyleSheet('large'); return false; });

	// Preload
	$("img, input").preload({ find: "_off.gif", replace: "_on.gif"});

	// Rollover
	$("img, input").hover(
		function(){ this.src = this.src.replace("_off.gif","_on.gif"); },
		function(){ this.src = this.src.replace("_on.gif","_off.gif"); }
	);
});

function setNewicon(newStartStr,newEndStr){

	nowDate		= new Date();
	nowYear		= new String(nowDate.getFullYear());
	nowMonth	= new String(nowDate.getMonth() + 1);
	nowDates	= new String(nowDate.getDate());

	nowMonth	= setStrLength(nowMonth,2,'0');
	nowDates	= setStrLength(nowDates,2,'0');
	nowDateStr	= nowYear + nowMonth + nowDates;

	nowDateInt	= eval(nowDateStr);
	newStartInt	= eval(newStartStr);
	newEndInt	= eval(newEndStr);

	if(nowDateInt >= newEndInt){
		return;
		}

	if(nowDateInt >= newStartInt){
		document.write('<span class="icon_new"><img src="/en/common/image/icon_new.gif" width="54" height="14" alt="NEW" /></span>');
		return;
	} else {
		return;
	}
	
};

//文字列長整形（処理対象文字列、処理後文字長、不足分埋め文字）----------

function setStrLength(targetStr,targetLength,targetChar){
	var i;
	tgStrLength = targetStr.length;
	if(tgStrLength >= targetLength){return(targetStr)}	//処理不要または長いときはそのまま返す

	targetLength = targetLength - tgStrLength;
	for(i=0;i<targetLength;i++){
		targetStr = targetChar + targetStr;		//指定された文字長さになるまで指定の文字を付ける
	}
	return(targetStr);
}
