// JavaScript Document


//*************************************
//透過PNGを使用
//*************************************
function call_ipngfix()
{
	var imgRepList = document.getElementsByClassName('ipngfix');

	for( var i=0, j=imgRepList.length; i<j; i++){
		
		imgRepList[i].style.behavior = IEPNGFIX.fix(imgRepList[i], imgRepList[i]);
	}
}


//*************************************
//オンマウス時のメニュー画像の切り替え
//*************************************
function swapImage(btnObj,sURL)
{
	btnObj.src = sURL;
}

//******************************************************************************
//	オンマウス時のメニュー画像の切り替え
//******************************************************************************
function swapImagePNG(btnObj,sURL)
{
	btnObj.src = sURL;
	IEPNGFIX.fix(btnObj, btnObj);
}

//*************************************
//FLASH再生
//*************************************
function CreateControl(DivID, CLSID, ObjectID,WIDTH, HEIGHT, URL, AUTOSTART)
{
document.write('<object classid="' + CLSID + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="' + ObjectID + '" width="' + WIDTH + '" height="' + HEIGHT +'"  align="">');
document.write('<param name=movie value="' + URL + '">');
document.write('<param name=autoStart value=' + AUTOSTART + '/>');
document.write('<param name=quality value=height />');
document.write('<embed src="' + URL + '" quality="height" width="' + WIDTH + ' px" height="' + HEIGHT +' px" name=' + ObjectID + ' vspace="0" hspace="0" align="middle" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
document.write('</object>');
}

//*************************************
//葬儀の予約　スケジュール表示
//*************************************
function schedule_matrix()
{
	var cremation 	= document.getElementById("cremation_select").value;
	var size		= document.getElementById("size_select").value;
	
	//if ( cremation == 0 || size == 0 ) return;
	
	var parameter	= $H({cremation:cremation, pet_size:size}).toQueryString();
	
	//AJAXファイルを指定
	ajax_file_path 	= '../ajax/schedule_matrixO.php';
	
	new Ajax.Request(
			ajax_file_path,
			{
				method			:'post',
				asynchronous	:true,
				postBody		:parameter,
				onComplete		:function(httpObject){
					
					$('schedule_matrix_box').innerHTML	= httpObject.responseText;

				},
				onFailure		:function(reg,header){
					
					$('schedule_matrix_box').innerHTML	= "";
				}
			}
	);
}


//*************************************
//葬儀の予約　スケジュール表示
//*************************************
function reserve_schedule()
{
	var date	 	= document.getElementById("date_select").value;
	var size		= document.getElementById("size_select").value;
	
	var date_index	 		= document.getElementById("date_select").selectedIndex;
	var date_array_count	= document.getElementById("date_array_count").value;
	
	//前日ボタンを作成
	if ( date_index - 1 <  1 ){
		$('bt_last').innerHTML	= "<img src=\"../images/bt_last_day_2.gif\" width=\"50\" height=\"20\" alt=\"前日\" />";
	} else {
		$('bt_last').innerHTML	= "<a href=\"javascript:schedule_days_link('last')\"><img src=\"../images/bt_last_day_1.gif\" width=\"50\" height=\"20\" alt=\"前日\" /><a>";
	}
	
	//翌日ボタンを作成
	if ( date_index == date_array_count ){
		$('bt_next').innerHTML	= "<img src=\"../images/bt_next_day_2.gif\" width=\"50\" height=\"20\" alt=\"翌日\" />";
	} else {
		$('bt_next').innerHTML	= "<a href=\"javascript:schedule_days_link('next')\"><img src=\"../images/bt_next_day_1.gif\" width=\"50\" height=\"20\" alt=\"翌日\" /><a>";
	}
	
	var parameter	= $H({date:date, pet_size:size}).toQueryString();
	
	//AJAXファイルを指定
	ajax_file_path 	= '../ajax/schedule_matrix.php';
	
	new Ajax.Request(
			ajax_file_path,
			{
				method			:'post',
				asynchronous	:true,
				postBody		:parameter,
				onComplete		:function(httpObject){
					
					$('schedule_matrix_box').innerHTML	= httpObject.responseText;

				},
				onFailure		:function(reg,header){
					
					$('schedule_matrix_box').innerHTML	= "";
				}
			}
	);
}


//*************************************
//葬儀スケジュール 日にちリンク
//*************************************
function schedule_days_link(kbn)
{
	var date	 	= document.getElementById("date_select").selectedIndex;
	var size		= document.getElementById("size_select").value;
		
	if ( kbn == "last" )
		date = date - 1;
		
	else if ( kbn == "next" )
		date = date + 1;

	document.reserve_date.date_select.value 	= date;
	document.reserve_date.size_select.value 	= size;
	document.reserve_date.submit();
}

//*************************************
//葬儀の予約　フォーム表示
//*************************************
function reserve_form(year,month,day,hour)
{
	pForm = document.reserve_date;
	pForm.year.value 	= year;
	pForm.month.value 	= month;
	pForm.day.value 	= day;
	pForm.hour.value 	= hour;
	pForm.action		= "reserve.html";
	pForm.submit();
}

//*************************************
//料金シュミレーション　トータル表示
//*************************************
function chargrs_simulation(pForm)
{
	var cremation_price		= 0;
	var cremation_fee		= 0;
	var cremation_is_fee	= 0;
	var cemetery_price 		= 0;
	var cemetery_fee	 	= 0;
	var cemetery_is_fee	 	= 0;
	var booth_price 		= 0;
	var booth_fee	 		= 0;
	var booth_is_fee	 	= 0;
	var option_price 		= 0;
	var option_fee		 	= 0;
	var option_is_fee 		= 0;
	var total_price			= 0;
	var total_fee			= 0;
	var hp_price			= 0;
	
	if ( pForm.cremation.value != ""){
		value = pForm.cremation.value;
		value = value.split(",");
		
		cremation_price 	= parseInt(value[0]);
		cremation_fee 		= parseInt(value[1]);
		cremation_is_fee 	= parseInt(value[2]);
	}


	for ( i=0; i < pForm.cemetery.length; i++ ){
	
		if ( pForm.cemetery[i].checked == true ){

			radio_element 	= pForm.cemetery[i].value;

			for(ii = 0; ii < pForm.elements[radio_element].length; ii++) {
 				if(pForm.elements[radio_element][ii].checked) {
					value = pForm.elements[radio_element][ii].value;
					break;
				}
			}
			
			value 	= value.split(",");

			cemetery_price 	= parseInt(cemetery_price) + parseInt(value[0]);
			cemetery_fee 	= parseInt(cemetery_fee) + parseInt(value[1]);
			cemetery_is_fee = parseInt(cemetery_is_fee) + parseInt(value[2]);
		}
	}
	
	
	for ( i=0; i < pForm.booth.length; i++ ){
		
		if ( pForm.booth[i].checked == true ){

			radio_element 	= pForm.booth[i].value;
			
			for(ii = 0; ii < pForm.elements[radio_element].length; ii++) {
 				if(pForm.elements[radio_element][ii].checked) {
					value = pForm.elements[radio_element][ii].value;
					break;
				}
			}
			
			value 	= value.split(",");

			booth_price 	= parseInt(booth_price) + parseInt(value[0]);
			booth_fee 		= parseInt(booth_fee) + parseInt(value[1]);
			booth_is_fee 	= parseInt(booth_is_fee) + parseInt(value[2]);
		}
	}


	for ( i=0; i < pForm.option.length; i++ ){

		if ( pForm.option[i].checked == true ) {
			
			option_value = pForm.option[i].value;
			option_value = option_value.split(",");
			
			option_price 	= parseInt(option_price) + parseInt(option_value[0]);
			option_fee 		= parseInt(option_fee) + parseInt(option_value[1]);
			option_is_fee 	= parseInt(option_is_fee) + parseInt(option_value[2]);
		}
	}

	total_price 	= parseInt(cremation_price) + parseInt(cemetery_price) + parseInt(booth_price) + parseInt(option_price);
	total_fee 		= parseInt(cremation_fee) + parseInt(cemetery_fee) + parseInt(booth_fee) + parseInt(option_fee);
	total_is_fee 	= parseInt(cremation_is_fee) + parseInt(cemetery_is_fee) + parseInt(booth_is_fee) + parseInt(option_is_fee);
	
	if ( total_is_fee != 0 )
		is_fee_price = parseInt(pForm.is_fee.value);
	else
		is_fee_price = 0;
	
	$('simulation_total_price').innerHTML	= total_price + "円";
	$('simulation_total_fee').innerHTML		= total_fee + "円";
	$('simulation_total_is_fee').innerHTML	= is_fee_price + "円";
	
	$('simulation_total').innerHTML	= total_price + total_fee + is_fee_price + "円";
}

//*************************************
//料金シュミレーション　リセット
//*************************************
function chargrs_simulation_reset(pForm)
{
	pForm.reset();
	
	chargrs_simulation(pForm);
}

//*************************************
//ペットサイズ見分け表ウィンドウを開く
//*************************************
function open_pet_size_info(){
	
	url		= "pet_size_info.html";
	
	move 	= 'top=' + 40 + ',left=' + screen.width/2;
	option 	= 'width=' + 420 + ',height=' + 450;
	
	option = option + move + ',scrollbars=0,resizable=0,menubar=0,toolbar=0,location=0,directories=0,status=0,titlebar=0'
	o_colWindow = window.open(url,"schedule",option,"dependent=yes", true);
	
	return;
}

//*************************************
//ペットサイズ見分け表ウィンドウを開く
//*************************************
function open_window(url,width,height){
	
	move 	= 'top=100,left=200';
	option 	= 'width=' + width + ',height=' + height;
	
	option = option + move + ',scrollbars=0,resizable=0,menubar=0,toolbar=0,location=0,directories=0,status=0,titlebar=0'
	o_colWindow = window.open(url,"schedule",option,"dependent=yes", true);
	
	return;
}

//*************************************
//カタカナチェック
//*************************************
function kanaCheck(element) {
	
   var str = element.value;
   
   if( str.match( /[^ァ-ン　\s]+/ ) ) {
      alert("全角カタカナで入力して下さい。");
	  element.value = "";
      return;
   }
   return;
}