//*******************************************************************************
//　html読み込み完了時の動作
//*******************************************************************************

$(document).ready(function(){


});


//*******************************************************************************
//　イベント用関数
//*******************************************************************************

$(function(){
	//ページ内スクロール
	$(".toPageTop a").click(function(){
		$('html,body').animate({
			scrollTop:$($(this).attr("href")).offset().top
		},'slow','easeOutCirc');
		return false;
	});
});


//*******************************************************************************
//　イベント用関数
//*******************************************************************************
/*
//テキストボックス・テキストエリアにフォーカスが入ったときの処理
function myFocus(){
	$(":text, textarea").focus(function(){
		$(this).addClass("focus");
	});
}

//テキストボックス・テキストエリアにフォーカス無くなったときの処理
function myBlur(){
	//テキストボックス・テキストエリアにフォーカス無くなったときの処理
	$(":text, textarea").blur(function(){
		$(this).removeClass("focus");
	});
}
*/
//*******************************************************************************
//　frmSubmit処理(確認なし)
//*******************************************************************************

function frmSubmit(frm,url){

	document.getElementById(frm).action = url;
	document.getElementById(frm).submit();
	return true;

}


//*******************************************************************************
//　frmSubmit処理(確認あり)
//*******************************************************************************

function frmSubmitConfirm(frm,url){

	if(window.confirm("実行してもよろしいですか？")){
		document.getElementById(frm).action = url;
		document.getElementById(frm).submit();
		return true;
	}
	
	return false;
	
}


//*******************************************************************************
//　アイテム削除時の確認
//*******************************************************************************

function itemDel(actionurl) {
	
	if(actionurl){
		if(window.confirm("画像削除を実行してもよろしいですか？")){
			window.location.href = actionurl;
			return true;
		}
	}
	
	return false;
	
}


//*******************************************************************************
//　エンターキー押下でもsubmitさせない
//*******************************************************************************

function BlockEnter(evt){
	evt = (evt) ? evt : event; 
	var charCode=(evt.charCode) ? evt.charCode : 
		((evt.which) ? evt.which : evt.keyCode);
	if ( Number(charCode) == 13 || Number(charCode) == 3) {
		return false;
	} else {
		return true;
	}
}

function attachBlockEnter(formid) {
	var elements = document.getElementById(formid).elements;
	for (var j=0; j < elements.length; j++) {
		var e = elements[j];	
		if (e.type == "text"){
			e.onkeypress=BlockEnter;
		}
	}
	
	return false;
}


//*******************************************************************************
//　ロールオーパー
//*******************************************************************************

function initRollOverImages() {  
	var image_cache = new Object();  
	$(".rollover").not("[@src*='_on.']").each(function(i) {  
		var imgsrc = this.src;  
		var dot = this.src.lastIndexOf('.');  
		var imgsrc_on = this.src.substr(0, dot) + '_on' + 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; }  
		);  
	});  
}


//*******************************************************************************
//　リンク
//*******************************************************************************

function jump(url,target){
	
	if(url){
		
		if(target){
			window.open(url,target);
		}else{
			location.href = url;
		}
		
		return true;
	}else{
		return false;
	}
}


//*******************************************************************************
//　外部リンク設定
//*******************************************************************************

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
	var anchor = anchors[i];
	if (anchor.getAttribute("href") &&
	((anchor.getAttribute("rel") == "blank nofollow") || (anchor.getAttribute("rel") == "blank external") || (anchor.getAttribute("rel") == "blank")))
	anchor.target = "_blank";
	}
}
window.onload = externalLinks;


//*******************************************************************************
//　フォーム内の値を取得してPOSTでデータを作成
//*******************************************************************************

function makeFormData(box_id){
	var obj = new Object();
	var target;
	var type;
	var key;
	var value;
	var setFlg;
	
	if(box_id && box_id.indexOf("#") == -1){
		box_id = "#" + box_id;
	}
	
	if(box_id){
		target_box_parts = box_id + " .formparts,";
	}else{
		target_box_parts = ".formparts";
	}
	
	$(target_box_parts).each(function(){
		target = $(this);
		type = this.type;
		key = this.name;
		setFlg = true;
		
		if(type.indexOf("checkbox") != -1){
			if(target.attr("checked") == true){
				value = target.val();
			}else{
				value = "";
			}
		}else if(type.indexOf("radio") != -1){
			if(target.attr("checked") == true){
				setFlg = true;
				value = target.val();
			}else{
				setFlg = false;
			}
			
		}else{
			value = target.val();
		}
		
		if(setFlg == true){
			obj[key] = value;
		}
		
		
	});
	
	return obj;
	
}


//*******************************************************************************
//　windowの高さを取得する関数
//*******************************************************************************

function getWindowHeight(){
	
	//Window Area
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	
	return windowHeight;
}


//*******************************************************************************
//　scrollの高さを取得する関数
//*******************************************************************************

function getScrollHeight(){
	
	//Scroll Area
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	//Window Area
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

	// Set pageHeight
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// Set pageWidth
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	// lightboxalertbg Width
	if(pageWidth >= windowWidth){
		largestWidth = pageWidth; smallestWidth = windowWidth;
	}else{
		largestWidth = windowWidth; smallestWidth = pageWidth;
	}

	// lightboxalertbg Height
	if(pageHeight >= windowHeight){
		largestHeight = pageHeight; smallestHeight = windowHeight;
	}else{
		largestHeight = windowHeight; smallestHeight = pageHeight;
	}
	
	return largestHeight;
}



//*******************************************************************************
//　各種共通関数
//*******************************************************************************

//trim関数
function trim(str){
  return String(str).replace(/^[ 　]*/gim, "").replace(/[ 　]*$/gim, "");
}
String.prototype.trim = function (str){
  return String(str).replace(/^[ 　]*/gim, "").replace(/[ 　]*$/gim, "");
}

//POSTデータ送信時、JSONで値を返す
$.postJSON=function(url, data, callback){
    $.post(url, data, callback, "json");
};

// 全置換：全ての文字列 org を dest に置き換える  
String.prototype.replaceAll = function (org, dest){
  return this.split(org).join(dest);
}



