// ----------------------------------------------------------------------------
// Font Size Botton
// ----------------------------------------------------------------------------
jQuery(function($){
	$("#noScript").hide();
	$("#textresizeBtn").show();
});

// ----------------------------------------------------------------------------
// Font Size Switcher
// ----------------------------------------------------------------------------
jQuery(document).ready( function($) {
	jQuery( "ul.textresizer a" ).textresizer({
		target: "body",
		type: "cssClass",
		sizes: [
			"largeText",
			"mediumText",
			"smallText",
		],
		selectedIndex: 2
	});
});


// ----------------------------------------------------------------------------
// IMG Hover
// ----------------------------------------------------------------------------
jQuery(document).ready(function($) {
	var postfix = '-on';
	var postactive = '-active';
	$('img.rollover').not('[src*="'+ postfix +'."]').not('[src*="'+ postactive +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		 + postfix
		 + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(
			function() {
				img.attr('src', src_on);
			},
			function() {
				img.attr('src', src);
			}
		).click(function() {
				img.attr('src', src);
		});;
	});
	$('input.rollover').not('[src*="'+ postfix +'."]').not('[src*="'+ postactive +'."]').each(function() {
		var inpt = $(this);
		var src = inpt.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		 + postfix
		 + src.substring(src.lastIndexOf('.'));
		$('<input>').attr('src', src_on);
		inpt.hover(
			function() {
				inpt.attr('src', src_on);
			},
			function() {
				inpt.attr('src', src);
			}
		).click(function() {
				inpt.attr('src', src);
		});;
	});
});


// ----------------------------------------------------------------------------
// Search Form
// ----------------------------------------------------------------------------
jQuery(document).ready(function($){
	$('#search')
	.blur(function(){
		var $$=$(this);
		if($$.val()=='' || $$.val()==$$.attr('title')){
		$$.css('color', '#676767')
			.val($$.attr('title'));
		}
	})
	.focus(function(){
		var $$=$(this);
		if($$.val()==$$.attr('title')){
		$(this).css('color', '#000')
				.val('');
		}
	})
	.parents('form:first').submit(function(){
		var $$=$('#search');
		if($$.val()==$$.attr('title')){
		$$.triggerHandler('focus');
		}
	}).end()
	.blur();
	});


// ----------------------------------------------------------------------------
// tab Setting
// ----------------------------------------------------------------------------
jQuery(document).ready(function($){
	var Tabs = $("ul#tab li a");
	var TabActive = "active";
	var TabContents = $("div#tabContents");
	$("div.hide" , TabContents).hide();

	$(Tabs).click(function(e){
		e.preventDefault();
		$("div.hide" , TabContents).hide();
		$($(this).attr("href")).fadeIn(250);
		$(Tabs).removeClass(TabActive);
		$(this).addClass(TabActive);
		$.cookie("contents", $(this).attr("href") , {expires: 365});
	});

	// クッキー読み込み
	var CookieName = $.cookie("contents");
	if (CookieName != null) {
		$(Tabs).removeClass(TabActive);
		$("a[href="+CookieName+"]").addClass(TabActive);
		$(CookieName).fadeIn(300);
	} else {
		$("#tab li a:first").addClass(TabActive);
		$("div:first" , TabContents).fadeIn(300);
	}
});


// ----------------------------------------------------------------------------
// Window Popup New Open
// ----------------------------------------------------------------------------
jQuery.fn.popupwindow = function(p)
{
	var profiles = p || {};
	return this.each(function(index){
		var settings, parameters, mysettings, b, a;
		// for overrideing the default settings
		if( jQuery(this).get(0).tagName.match(/area/i) ) {
			mysettings = (jQuery(this).attr("class") || "").split(",");
		}else{
			mysettings = (jQuery(this).attr("rel") || "").split(",");
		}

		settings = {
			height:600, // sets the height in pixels of the window.
			width:600, // sets the width in pixels of the window.
			toolbar:0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			resizable:1, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			left:0, // left position when the window appears.
			top:0, // top position when the window appears.
			center:0, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
			createnew:1, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0 // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
		};
		// if mysettings length is 1 and not a value pair then assume it is a profile declaration
		// and see if the profile settings exists
		if(mysettings.length == 1 && mysettings[0].split(":").length == 1)
		{
			a = mysettings[0];
			// see if a profile has been defined
			if(typeof profiles[a] != "undefined")
			{
				settings = jQuery.extend(settings, profiles[a]);
			}
		}
		else
		{
			// overrides the settings with parameter passed in using the rel tag.
			for(var i=0; i < mysettings.length; i++)
			{
				b = mysettings[i].split(":");
				if(typeof settings[b[0]] != "undefined" && b.length == 2)
				{
					settings[b[0]] = b[1];
				}
			}
		}
		// center the window
		if (settings.center == 1)
		{
			settings.top = (screen.height-(settings.height + 110))/2;
			settings.left = (screen.width-settings.width)/2;
		}
		
		parameters = "location=" + settings.location + ",menubar=" + settings.menubar + ",height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
		
		jQuery(this).bind("click", function(){
			if( a != "newWindow" ){
				var name = settings.createnew ? "PopUpWindow" + index : "PopUpWindow";
				window.open(this.href, name, parameters).focus();
			}else{
				window.open(this.href).focus();
			}
			return false;
		});
	});
};


// ----------------------------------------------------------------------------
// Popup Setting jQuery
// ----------------------------------------------------------------------------
var profiles =
{
	newWindow:
	{
		status:1,
		toolbar:1
	},

	rspeaker:
	{
		height:250,
		width:230,
		status:1,
		toolbar:1
	},

	window800:
	{
		height:800,
		width:800,
		status:1
	},

	window200:
	{
		height:200,
		width:200,
		status:1,
		resizable:0
	},

	windowCenter:
	{
		height:300,
		width:400,
		center:1
	},
	
	windowNotNew:
	{
		height:300,
		width:400,
		center:1,
		createnew:0
	}
};
jQuery(function($){
	$("a[rel],area[class*=newWindow]").popupwindow(profiles);
});


// ----------------------------------------------------------------------------
// Link Icon Auto Addition for IE
// ----------------------------------------------------------------------------
jQuery(function($){
	if ($.browser.msie && $.browser.version < 8.0) {
		$('a.external').each(function(){
			$(this).prepend('<span class="icon">&nbsp;</span>');
		});
		$('a.arrow').each(function(){
			$(this).prepend('<span class="icon">&nbsp;</span>');
		});
	}
});


// ----------------------------------------------------------------------------
// External Link Icon Auto Addition
// ----------------------------------------------------------------------------
jQuery(function($){
	var $target = $("body");
	var $p = $(".external", $target);
	$p.removeClass("external");
	$p.addClass("externalJS");
});


// ----------------------------------------------------------------------------
// Firefox Onkeypress
// ----------------------------------------------------------------------------
function keyPressFilter(evt,URL) {
	var keyCode;
	if (evt) {
		keyCode = evt.keyCode;
	} else {
		keyCode = event.keyCode;
	}
	if (keyCode != 10 && keyCode != 13) {
		return true;
	}
}

// ----------------------------------------------------------------------------
// SocialBookmark
// ----------------------------------------------------------------------------
jQuery(function($){
	function dispSbm(){
		var sCONT = new Array();
		var sSbp = '';
		var url;
		var pageTitle;
		var facebook_style;
		facebook_style = ('\v' == 'v') ? 'width: 103px; height: 21px; margin-left: 8px;' : 'width: 98px; height: 21px; margin-left: 8px;';
		var twitter_style = 'width: 85px; height:21px; margin-left: 12px;';
		this.url = encodeURIComponent(location.href); // URL取得&エンコード
		this.pageTitle = encodeURIComponent(document.title); // ページタイトル取得＆エンコード
		sSbp = '<ul class="flat right">\n';
		sSbp += '<li><iframe title="Twitterにツイートするボタン" scrolling="no" frameborder="0" src="https://platform.twitter.com/widgets/tweet_button.html?url=' + this.url + '&amp;text=' + this.pageTitle + '&amp;lang=ja&amp;count=none" allowtransparency="true" style="' + twitter_style + '"></iframe>';
		sSbp += '<!--end Twitter--></li>\n';
		sSbp += '<li><iframe title="facebookでシェアするボタン" src="https://www.facebook.com/plugins/like.php?locale=ja_JP&amp;href=' + this.url + '&amp;send=false&amp;layout=button_count&amp;width=105&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="' + facebook_style + '" allowTransparency="true"></iframe>';
		sSbp += '<!--end Facebook--></li>\n';
		sSbp += '</ul>';
		var s_el = $('.socialBookmark');
		sCONT.push(sSbp);
		var aCONT = sCONT.join("\n");
		$(s_el).html(aCONT);
	}
	dispSbm();
});

// ----------------------------------------------------------------------------
// 株価検索
// ----------------------------------------------------------------------------
function WinOpen(URL){
	var disp = window.open(URL,"TOP");
	disp.focus();
}

function call_dest(){

	//リンク仕様(本番環境)
	var Url="http://qw111.qhit.net/mizuho-sc/kabuka_search/";

	var links = [];
	links["keyNull"] = Url+"qsearch.exe?F=users/mizuho-sc/ichiran";
	links["kabu_list"] = Url+"qsearch.exe?F=users/mizuho-sc/ichiran";
	links["kabu_detail"] = Url+"quote.cgi?F=users/mizuho-sc/kakaku";
	var key1_00 = document.forms["form1"].elements["textfield"].value;
	var Code;

	var key1 = key1_00.toUpperCase();

	if ( key1.length == 4 || key1.length == 5) {
		for (i = 0; i < key1.length; i++) {
			key1 = key1.replace("０","0");
			key1 = key1.replace("１","1");
			key1 = key1.replace("２","2");
			key1 = key1.replace("３","3");
			key1 = key1.replace("４","4");
			key1 = key1.replace("５","5");
			key1 = key1.replace("６","6");
			key1 = key1.replace("７","7");
			key1 = key1.replace("８","8");
			key1 = key1.replace("９","9");
		}
	}

	if(key1==""){	//KEY1がNULLの時
		WinOpen(links["keyNull"]);
	}
	else{
		if(key1.match(/^\d{4,5}(\/[A-Za-z]{1,2})?$/g) != null){	//株コード
			if(key1.indexOf("/",0) !=-1){	//取引所コードが含まれている場合
				keyArray = key1.split("/");
				WinOpen(links["kabu_detail"] + "&QCODE=" + keyArray[0] + "&MKTN=" + keyArray[1]);
			}else{		//取引所コードがない場合
				WinOpen(links["kabu_detail"] + "&QCODE=" + key1);
			}
		}
		else if(key1.match(/\D/g)){  //文字検索の場合
			with(document.form2){
				WinOpen("");
				KEY1.value = key1_00;
				submit();
			}
		}
		else{	//検索リストへ
			WinOpen(links["kabu_list"] + "&KEY2=" + key1);
		}
	}
}// JavaScript Document

// ----------------------------------------------------------------------------
// Tab Focus
// ----------------------------------------------------------------------------
jQuery(function($){
	var navSpeak = "div#navSpeak";
	var navSpeakHash;
	$("a", navSpeak).each(function(){
		$(this).focus(function(){
			$(navSpeak).addClass("navSpeakShow");
		});
		$(this).blur(function(){
			$(navSpeak).removeClass("navSpeakShow");
		});
		$(this).click(function(e){
			e.preventDefault();
			$(navSpeak).removeClass("navSpeakShow");
			navSpeakHash = $(this).attr("href");
			navSpeakHash = navSpeakHash.substr(1, navSpeakHash.length)
			location.hash = navSpeakHash;
		});
	});
});



// ----------------------------------------------------------------------------
// Page Scroll
// ----------------------------------------------------------------------------
var cast = {
  findAllLink: function() {
    var collectLinks = document.getElementsByTagName('a');
    for (var i=0;i<collectLinks.length;i++) {
      var lnk = collectLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) ||
         ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {
        if(lnk.href.indexOf('anchorPageTop') == -1 && lnk.parentNode.parentNode.getAttribute("id") != "tab" && lnk.href.indexOf('anchorContents') == -1 && lnk.href.indexOf('anchorLocalNav') == -1 && lnk.href.indexOf('anchorGlobalNav') == -1 && lnk.href.indexOf('anchorFooter') == -1 && lnk.href.indexOf('loginArea') == -1){
          cast.addEvent(lnk,'click',cast.innerScroll);
		}
      }
    }
  },
  addEvent: function(element, action, work, capture) {
    if (element.addEventListener){
      element.addEventListener(action, work, capture);
      return true;
    } else if (element.attachEvent){
      var rest = element.attachEvent("on"+action, work);
      return rest;
    }
  }, 
  getNowLocate: function() {
    if (document.body && document.body.scrollTop){
      return document.body.scrollTop;
    }
    if (document.documentElement && document.documentElement.scrollTop){
      return document.documentElement.scrollTop;
	 }
    if (window.pageYOffset){
      return window.pageYOffset;
	 }
    return 0;
  },
  actWindow: function(measure,lmPoint,turnPoint,anchorPoint) {
    chkPoint = cast.getNowLocate();
    chkFlag = (chkPoint < lmPoint);
	if(lmPoint>turnPoint){
		if(lmPoint < 200){ slowPoint = 200; }else{ slowPoint = lmPoint*0.7; }
	}else{
		if(turnPoint < 200){ slowPoint = 200; }else{ slowPoint = turnPoint*0.7; }
	}
	if(Math.abs(lmPoint-chkPoint) < slowPoint){
		
		measure = ((lmPoint-chkPoint)/cast.SPEED);
		if(Math.abs(measure) < 1 ){
			if(measure < 0){
				measure = -1;
		   }else if(measure > 0){
				measure = 1;
			}
		}
	}
    window.scrollTo(0,chkPoint + measure);
    nowPoint = cast.getNowLocate();
    chkFlagNow = (nowPoint < lmPoint);
		if ((chkFlag != chkFlagNow) || (chkPoint == nowPoint)) {
      window.scrollTo(0,lmPoint);
      clearInterval(cast.INTERVAL);
		return false;
    }
  },
  innerScroll: function(e) {
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
    if (target.nodeName.toLowerCase() != 'a') return;
    anchorPoint = target.hash.substr(1);
    var collectLinks = document.getElementsByTagName('a');
    var landmarkLink = null;
    for (var i=0;i<collectLinks.length;i++) {
      var lnk = collectLinks[i];
      if (lnk.name && (lnk.name == anchorPoint)) {
        landmarkLink = lnk;
        break;
      }
    }
    if (!landmarkLink) landmarkLink = document.getElementById(anchorPoint);
    if (!landmarkLink) return true;
    var landmark_x = landmarkLink.offsetLeft; 
    var landmark_y = landmarkLink.offsetTop;
    if( navigator.userAgent.indexOf("MSIE") != -1 ){
    	var val = landmarkLink.childNodes.length;
	   for (i =0 ; i< val ; i++){
        if(landmarkLink.childNodes[i].nodeType == 3){
          landmark_y = landmark_y - 5;
        }
      }
    }else{
      if(landmarkLink.text){
        landmark_y = landmark_y -5;
      }
    }
    if(document.all && !window.opera){
      var winH = document.documentElement.offsetHeight;
      var docH = document.body.scrollHeight;
    }else{
      var winH = window.innerHeight;
      var docH = document.height;
    }
    if(winH > (docH-landmark_y))landmark_y -= landmark_y - (docH-winH);
    var thisNode = landmarkLink;
    while (thisNode.offsetParent && (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      landmark_x += thisNode.offsetLeft;
      landmark_y += thisNode.offsetTop;
    }
    clearInterval(cast.INTERVAL);
    turnPoint = cast.getNowLocate();
    movesize = parseInt((landmark_y-turnPoint)/cast.SPEED);
	 if(Math.abs(movesize) < cast.SPEED){
	 	if( movesize < 0 ){
		 	movesize = parseInt(0 - cast.SPEED);
		}else if( movesize > 1 ){
		 	movesize = parseInt(cast.SPEED);
		}
	 }else if(Math.abs(movesize) > cast.LIMIT_SPEED){
	 	if( movesize < 0 ){
		 	movesize = parseInt(0 - cast.LIMIT_SPEED);
		}else if( movesize > 1 ){
		 	movesize = parseInt(cast.LIMIT_SPEED);
		}
	} 
    cast.INTERVAL = setInterval('cast.actWindow('+movesize+','+landmark_y+','+turnPoint+',"'+anchorPoint+'")',15);
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  }
}
cast.SPEED =6;
cast.LIMIT_SPEED =1000;
cast.addEvent(window,"load",cast.findAllLink);


// ----------------------------------------------------------------------------
// Close Link
// ----------------------------------------------------------------------------
function close_win(){
	var nvua = navigator.userAgent;
	if (nvua.indexOf('MSIE') >= 0){
		if (nvua.indexOf('MSIE 5.0') == -1) {
			top.opener = '';
		}
	} else if (nvua.indexOf('Gecko') >= 0) {
		top.name = 'CLOSE_WINDOW';
		wid = window.open('','CLOSE_WINDOW');
	}
	top.close();
}
// ----------------------------------------------------------------------------
// input newWiondow
// ----------------------------------------------------------------------------
function cleanWhite(elm) {
	var node = elm.firstChild;
	while (node) {
		var nextNode = node.nextSibling;
		if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) {
			elm.removeChild(node);
		}
		node = nextNode;
	}
	return elm;
}

function formOpen(fName){
	var elmList = new Array();
	var fn = cleanWhite(document.getElementById(fName));
	var olgNode = cleanWhite(fn.firstChild.cloneNode(true));
	var clnNode = cleanWhite(fn.firstChild.cloneNode(true));
	var oldElm;
	var clnElm = clnNode.childNodes;
	for (var i = 0; i < clnElm.length; i++) {
		if (clnElm[i].getAttribute('type') === 'image') {
			oldElm = clnElm[i];
			var newNode = document.createElement('img');
			newNode.setAttribute('src', clnElm[i].getAttribute('src'));
			elmList[i] = newNode;
		} else {
			elmList[i] = clnElm[i];
		}
	}
	clnNode.removeChild(oldElm);
	for (var i = 0; i < elmList.length; i++) {
		clnNode.appendChild(elmList[i]);
	}
	fn.replaceChild(clnNode, fn.firstChild);
	var formWin = window.open('', 'formWin', '');
	formWin.focus();
	fn.target = 'formWin';
	fn.submit();
	timer = setTimeout(function() {
		clearTimeout(timer);
		fn.replaceChild(olgNode, fn.firstChild);
	}, 1);
	return false;
}

