//=========================================================================//
// システム名：共通
// 
// プログラム名：共通Javascript
// 
// Copyright (C) 2008 Boxyz, Inc. All rights reserved.
// http://boxyz.com/
//=========================================================================//

var min=0;

function checkcard(){
var elm = document.getElementById("payment1");
elm.checked=true;
}

function _getParentY(elm,lvl){
	if(isNaN(lvl))lvl=0;
	if(!elm || elm.tagName=='BODY' || elm.tagName=='FRAME')return 0;
	var y = elm.offsetTop;
	var h = elm.offsetHeight;
	
	if(elm.tagName=='FORM'){
		y=0;
	}
	if(elm.tagName=='TBODY'){
		y=0;
	}
	if(elm.tagName=='DIV'){
//		y=0;
	}
	if(elm.tagName=='A' && lvl!=0){
//		y=0;
	}
	if(elm.tagName=='A'){
//		y=10;
	}
	if(elm.tagName=='TR')y=0;

	if(lvl==0){
		py="";
	}else{
//		py=py+elm.tagName+"["+y+"]";
	}

	y+=_getParentY(elm.parentNode,lvl+1);
	
	return y;
}

function size_reset(){
}
function size_reset_old(){
	var mw = document.body.clientWidth;
	var mh = document.body.clientHeight;
	var h = document.getElementById("main_container_center").clientHeight;
	var ch = 0;
	if(document.getElementById("center_pane_top")){
		ch = document.getElementById("center_pane_top").clientHeight;
	}else if(document.getElementById("center_pane")){
		ch = document.getElementById("center_pane").clientHeight;
	}else if(document.getElementById("center_pane2")){
		ch = document.getElementById("center_pane2").clientHeight;
	}
	var ft = document.getElementById("footer_remarks_pane");
	var cc = document.getElementById("main_container_center2").clientHeight;
	var ft2 = document.getElementById("footer_link_pane").clientHeight;
	var ft3 = document.getElementById("footer_copyright_pane").clientHeight;
//	ft.style.position="absolute";

	if(min>h || min==0){
		min=h;
	}
	
	if(mh>h){
	}else if(mh>min){
//		mh=mh+8;
	}else{
		mh=min;
//		mh=mh+8;
	}
//	var aa = document.getElementById("center_pane2").clientHeight;
//	alert(aa);
//	ft.style.height = (mh-(cc+ft2+ft3+15))+"px";
//	document.getElementById("main_container_center").style.height=mh+"px";
	
}


function vanish(tag){
	var elm = document.getElementById(tag);
	elm.style.visibility="hidden";
	elm.style.position="absolute";
	elm.style.left="-1000";
}

function apper(tag){
	var elm = document.getElementById(tag);
	elm.style.visibility="visible";
	elm.style.position="static";
}
function open_keitai(href){
	open(href,'keitai','width=760,height=640,left=25,top=25,resizable=yes,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no');
}

function open_window(href){
	open(href,'_blank','width=890,height=613,left=25,top=25,resizable=yes,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no');
}


function pager(act,pno){
	var frm = document.forms[0];
	frm.method="GET";
	frm.enctype="";
	frm.act.value=act;
	frm.page_no.value=pno;
	frm.submit();
	return false;
}


function _action(act){

	var frm = document.forms[0];
	frm.method="POST";
	frm.enctype="";
	frm.act.value=act;
	frm.submit();
	return false;
}

function _action2(act){

	var frm = document.forms[0];
	frm.method="POST";
	frm.act.value=act;
	frm.submit();
	return false;
}

function action_get(){
	arg="";
	var frm = document.forms[0];
	url=arguments[0];
	a=arguments[1];
  for(var i=2;i<arguments.length;i+=2){
    var k=arguments[i];
		var v=arguments[i+1];
		var d="";
		if(v!=""){
			d=v;
		}else if(v=="%empty%"){
			d="";
		}else{
			eval("d=frm."+k+".value;");
		}
    arg=arg+"&"+k+"="+encodeURI(d);
  }
  location.href=url+"?act="+a+arg;

/*
	var frm = document.forms[0];
	frm.method="GET";
	frm.enctype="";
	frm.act.value=act;
	frm.submit();
	*/
	//return false;
}

function confirm_action(act,conf){
	if(!confirm(conf))return;
	var frm = document.forms[0];
	frm.method="POST";
	frm.enctype="";
	frm.act.value=act;
	frm.submit();
	return false;
}

function confirm_link(href,conf){
	if(!confirm(conf))return;
	location.href=href;
}

function select_last(id){
	var elm = document.getElementById(id);
	elm.focus();

	if (elm.createTextRange) {
	  var range = elm.createTextRange();
	  range.move('character', elm.value.length);
	  range.select();
	} else if (elm.setSelectionRange) {
	  elm.setSelectionRange(elm.value.length, elm.value.length);
	}
}

function checkBrowser(){
	var a,ua = navigator.userAgent;
	this.bw= { 
	  safari    : ((a=ua.split('AppleWebKit/')[1])?a.split('(')[0]:0)>=124 ,
	  konqueror : ((a=ua.split('Konqueror/')[1])?a.split(';')[0]:0)>=3.3 ,
	  mozes     : ((a=ua.split('Gecko/')[1])?a.split(" ")[0]:0) >= 20011128 ,
	  opera     : (!!window.opera) && ((typeof XMLHttpRequest)=='function') ,
	  msie      : (!!window.ActiveXObject)?(!!createHttpRequest()):false 
	}
	return (this.bw.safari||this.bw.konqueror||this.bw.mozes||this.bw.opera||this.bw.msie)
}

function createHttpRequest(){
	if(window.XMLHttpRequest){
		return new XMLHttpRequest() ;
	} else if(window.ActiveXObject){
		try {
			return new ActiveXObject("Msxml2.XMLHTTP") ;
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP") ;
			} catch (e2) {
				return null ;
 			}
 		}
	} else  {
		return null ;
	}
}

function sendRequest(callback,data,method,url,async,sload,user,password){

	var oj = createHttpRequest();
	if( oj == null ) return null;
		
	var sload = (!!sendRequest.arguments[5])?sload:false;
	if(sload || method.toUpperCase() == 'GET')url += "?";
	if(sload)url=url+"t="+(new Date()).getTime();
		
	var bwoj = new checkBrowser();
	var opera	  = bwoj.bw.opera;
	var safari	  = bwoj.bw.safari;
	var konqueror = bwoj.bw.konqueror;
	var mozes	  = bwoj.bw.mozes ;
				
	if(typeof callback=='object'){
		var callback_onload = callback.onload
		var callback_onbeforsetheader = callback.onbeforsetheader
	} else {
		var callback_onload = callback;
		var callback_onbeforsetheader = null;
	}

	if(opera || safari || mozes){
		oj.onload = function () { callback_onload(oj); }
	} else {
	
		oj.onreadystatechange =function () 
		{
			if ( oj.readyState == 4 ){
				callback_onload(oj);
			}
		}
	}

	data = uriEncode(data,url)
	if(method.toUpperCase() == 'GET') {
		url += data
	}
		
	oj.open(method,url,async,user,password);

		
	if(!!callback_onbeforsetheader)callback_onbeforsetheader(oj)

	setEncHeader(oj)
		
		
	oj.send(data);

	function setEncHeader(oj){

		var contentTypeUrlenc = 'application/x-www-form-urlencoded; charset=UTF-8';
		if(!window.opera){
			oj.setRequestHeader('Content-Type',contentTypeUrlenc);
		} else {
			if((typeof oj.setRequestHeader) == 'function')
				oj.setRequestHeader('Content-Type',contentTypeUrlenc);
		}	
		return oj
	}

	function uriEncode(data,url){
		var encdata =(url.indexOf('?')==-1)?'?dmy':'';
		if(typeof data=='object'){
			for(var i in data)
				encdata+='&'+encodeURIComponent(i)+'='+encodeURIComponent(data[i]);
		} else if(typeof data=='string'){
			if(data=="")return "";
			var encdata = '';
			var datas = data.split('&');
			for(i=1;i<datas.length;i++)
			{
				var dataq = datas[i].split('=');
				encdata += '&'+encodeURIComponent(dataq[0])+'='+encodeURIComponent(dataq[1]);
			}
		} 
		return encdata;
	}

	return oj
}

function _focus(no){
	var elm_s = document.getElementById("scan");
	if(no==1){
		elm_s.style.backgroundPosition="0 -30px";
	}
	if(no==2){
		elm_s.style.backgroundPosition="0 -420px";
	}
	if(no==4){
		elm_s.style.backgroundPosition="0 -620px";
	}
	if(no==5){
		elm_s.style.backgroundPosition="0 -850px";
	}
	if(no==7){
		elm_s.style.backgroundPosition="0 -1000px";
	}
	if(no==8){
		elm_s.style.backgroundPosition="0 -1150px";
	}
	if(no==11){
		elm_s.style.backgroundPosition="0 -1320px";
	}
	if(no==12){
		elm_s.style.backgroundPosition="0 -1450px";
	}
	if(no==14){
		elm_s.style.backgroundPosition="0 -1650px";
	}
}

function close_popup(){
	var elm = document.getElementById("popup_window2");
	elm.style.left=-1000;
	elm.style.top=-1000;
}


var blog_end=false;
function blog_change(host,serial,no,t){
	var bname = encodeURIComponent(document.getElementById("bname").value);
	var _baby = encodeURIComponent(baby);
	var _called = encodeURIComponent(called);
	var _father = encodeURIComponent(father);
	var _mother = encodeURIComponent(mother);
	var elm = document.getElementById("blog_text");

script="";
script=script+'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="160" height="240" id="blogparts" align="left">';
script=script+'<param name="allowScriptAccess" value="sameDomain" />';
script=script+'<param name="movie" value="'+host+'blogparts.swf?serial='+serial+'&no='+no+'&host='+host+'&bname='+bname+'&baby='+_baby+'&called='+_called+'&father='+_father+'&mother='+_mother+'&t='+t+'" />';
script=script+'<param name="allowFullScreen" value="true" />';
script=script+'<param name="quality" value="high" /><param name="scale" value="noscale" /><param name="bgcolor" value="#ffffff" /><param name="salign" value="lt" />';
script=script+'<embed src="'+host+'blogparts.swf?serial='+serial+'&no='+no+'&host='+host+'&bname='+bname+'&baby='+_baby+'&called='+_called+'&father='+_father+'&mother='+_mother+'&t=18" quality="high" scale="noscale" allowFullScreen="true" scale="#noscale" salign="lt" bgcolor="#ffffff" width="160" height="240" name="blogparts" align="left" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
script=script+'</object>';

	if(elm.value!=script){


		elm.value=script;
	}


	if(blog_end){
		return;
	}
	setTimeout("blog_change('"+host+"','"+serial+"',"+no+","+t+")",100);
}
var baby;
var called;
var father;
var mother;

function blog_window(host,serial,no,title,_baby,_called,_father,_mother){

	baby=_baby;
	called=_called;
	father=_father;
	mother=_mother;
	var elm = document.getElementById("popup_window2");
	var html = "";
	
	var script="";
	
	blog_end=false;
	setTimeout("blog_change('"+host+"','"+serial+"',"+no+","+new Date().getTime()+")",100);


script=script+'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="160" height="240" id="blogparts" align="left">';
script=script+'<param name="allowScriptAccess" value="sameDomain" />';
script=script+'<param name="movie" value="'+host+'blogparts.swf?serial='+serial+'&no='+no+'&host='+host+'&t='+new Date().getTime()+'" />';
script=script+'<param name="allowFullScreen" value="true" />';
script=script+'<param name="quality" value="high" /><param name="scale" value="noscale" /><param name="bgcolor" value="#ffffff" /><param name="salign" value="lt" />';
script=script+'<embed src="'+host+'blogparts.swf?serial='+serial+'&no='+no+'&host='+host+'&t=18" quality="high" scale="noscale" allowFullScreen="true" scale="#noscale" salign="lt" bgcolor="#ffffff" width="160" height="240" name="blogparts" align="left" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
script=script+'</object>';
	
	
	html=html+'<div style="float:left;width:500px;height:300px;">';
	html=html+'<strong>ブログパーツ</strong><br>';
	html=html+'<p style="text-align:left;padding:2px 5px;">ブログパーツタイトル：<input type="text" id="bname" style="font-size:12px;padding:0;margin:0;line-height:13px;width:300px;" value="'+title+'"></p>';
	html=html+'<textarea style="width:480px;height:200px;" readonly onfocus="this.select();" id="blog_text">'+script+'</textarea>';
	html=html+'<p style="text-align:left;padding:2px 5px;">この絵本のブログパーツです。<br>上記のスクリプトをコピーしてあなたのブログに貼り付けるとこの絵本のブログパーツが表示されます。<a href="blog" target="_blank">詳しくはこちら</a></p>';
	html=html+'<p style="text-align:left;padding:2px 5px;"><img src="images/btns_close.gif" style="cursor:pointer;" onclick="blog_end=true;close_popup();"></p>';
	html=html+'<div style="float:left;width:500px;clear:both;"></div>';
	html=html+'</div>';
	
	elm.innerHTML="";
	elm.style.height="1";
	elm.innerHTML=html;

	var mw = document.body.clientWidth;
	var mh = document.body.clientHeight;

	var sw = elm.clientWidth;
	var sh = elm.clientHeight;

	elm.style.left=(mw-sw)/2;
	elm.style.top=(mh-sh)/2+document.body.scrollTop;
	elm.style.height=320;
	

}

