﻿/*var simpleSelection = Class.create();

simpleSelection.prototype = {

	

	// コンストラクタ

	initialize: function() {

	},

	simpleSelectionForm : "simpleSelection",

	shafttype: function() {

		// 軸選択ラジオボタンオブジェクト

		return $A($(this.simpleSelectionForm).shafttype_id).find(function(v) {return v.checked;});

	},

	shafttype_id: function(){

		shafttype = this.shafttype();

		if(shafttype){

			return this.shafttype().value;

		}else {

			return null;	

		}

	},

	outputshaftDirection : function(){

		return $(this.simpleSelectionForm).outputshaft_direction_id;

	},

	mountStyle : function(){

		return $(this.simpleSelectionForm).mountStyle;

	}

};

var sForm = new simpleSelection();
*/

function initSearchForm()
{
	setDefaultData();	
	setShaftType();	
}


function setShaftType()

{
	var shafttype_id = $('input[name="shafttype_id"]:checked').val();
	
	if(shafttype_id == "P") // 平行軸
	{
		// 取付方法をunset
		unsetMountingStyle("O", true);		

		// 軸出し方向を選択不可に
		unsetOutputshaftDirection(true);

	}else if(shafttype_id== "O") // 直行軸
	{
		// 軸出し方向を選択可に
		for(i=0; i<$('input[name="outputshaft_direction_id"]').length; i++){
			$('input[name="outputshaft_direction_id"]').eq(i).removeAttr('disabled');
		}
/*
		for(i=0; i<$A(sForm.outputshaftDirection()).length; i++){

			//$A(sForm.outputshaftDirection())[i].checked = false;

			$A(sForm.outputshaftDirection())[i].disabled = false;

		}		
*/
		// 取付方法をunset

		unsetMountingStyle("P", true);		

	}else {		// ページ最初ロード時
		resetAllShaftType();
	}
}

function unsetMountingStyle(type, uncheck)		// 取付方法をunset
{
	/* type:P O */
	for(i=0; i<$('input[name="mountStyle"]').length; i++){
		var mountStyle = $('input[name="mountStyle"]').eq(i).val();

		if(mountStyle == 'P_S_V')	// 平行軸取付台付は未公開
			continue;
			
		if(mountStyle.substr(0,1) == type){
			if(uncheck)
				$('input[name="mountStyle"]').eq(i).attr('checked', false);
			$('input[name="mountStyle"]').eq(i).attr('disabled', 'true');
		}else {
			$('input[name="mountStyle"]').eq(i).removeAttr('disabled');
		}
	}
/*
	for(i=0; i<$A(sForm.mountStyle()).length; i++){

		if($A(sForm.mountStyle())[i].value=="P_S_V"){	// 平行軸取付台付は未公開

			continue;

		}

		

		if(	$A(sForm.mountStyle())[i].value.substr(0,1) == type){

			if(uncheck)

				$A(sForm.mountStyle())[i].checked = false;			

			$A(sForm.mountStyle())[i].disabled = true;				

		}else {

			$A(sForm.mountStyle())[i].disabled = false;			

		}

	}	
*/
}

function unsetOutputshaftDirection(uncheck)	// 軸出し方向を選択不可に
{	var checked = true;
	if(uncheck)
		checked = false;
	$('input[name="outputshaft_direction_id"]').attr('checked', checked);	
	$('input[name="outputshaft_direction_id"]').attr('disabled', true);
/*
	for(i=0; i<$A(sForm.outputshaftDirection()).length; i++){

		if(uncheck)

			$A(sForm.outputshaftDirection())[i].checked = false;

		$A(sForm.outputshaftDirection())[i].disabled = true;

	}	
*/
}

function resetAllShaftType()	// 取付方法 出力軸方向のすべてをリセットする
{
	$('input[name="mountStyle"]').attr('disabled', true);
	$('input[name="mountStyle"]').attr('checked', false);

	unsetOutputshaftDirection(true);		
	return true;
/*
	for (i=0; i < sForm.mountStyle().length; i++){

		sForm.mountStyle()[i].checked = false;

		sForm.mountStyle()[i].disabled = true;

	}

	unsetOutputshaftDirection(true)

	

	return true;
*/
}

function setHollwShaft(type)
{
	for(i=0; i<$('input[name="mountStyle"]').length; i++){
		var mountStyle = $('input[name="mountStyle"]').eq(i).val();
		if(mountStyle == "O_H_Y"){
			$('input[name="mountStyle"]').eq(i).attr('checked', type);
		}
	}
	
	for(i=0; i<$('input[name="outputshaft_direction_id"]').length; i++){
		var outputshaft_direction_id = $('input[name="outputshaft_direction_id"]').eq(i).val();
		if(outputshaft_direction_id == "0"){
			$('input[name="outputshaft_direction_id"]').eq(i).attr('checked', type);
		}
	}	
/*
	for(i=0; i<$A(sForm.mountStyle()).length; i++){

		if($A(sForm.mountStyle())[i].value=="O_H_Y"){

			if(type==true){	// ホローシャフトがチェックされた

				$A(sForm.mountStyle())[i].checked = true;

			}else {

				$A(sForm.mountStyle())[i].checked = false;	

			}		

		}

	}

	for(i=0; i<$A(sForm.outputshaftDirection()).length; i++){

		if($A(sForm.outputshaftDirection())[i].value=="0"){

			if(type==true){	// ホローシャフトがチェックされた

				$A(sForm.outputshaftDirection())[i].checked = true;

			}else {

				$A(sForm.outputshaftDirection())[i].checked = false;	

			}			

		}

	}	
*/
}

function checkSolidFrange()
{
	var mountStyle = $('input[name="mountStyle"]:checked').val();
	
	// 中実軸フランジ取付の場合は、軸両出しが選択不可
	if(mountStyle == "O_S_F"){
		if($('input[name="outputshaft_direction_id"]:checked').val() == "T")
			$('input[name="outputshaft_direction_id"]:checked').attr('checked', false);
	}
/*
	// 中実軸フランジ取付の場合は、軸両出しが選択不可

	if($A(sForm.mountStyle()).find(function(v) {return v.checked;}).value == "O_S_F")

	{

		if($A(sForm.outputshaftDirection()).find(function(v) {return v.checked;}).value == "T")

		{

			// 中実軸　軸両出しがチェックされたら

			$A(sForm.outputshaftDirection()).find(function(v) {return v.checked;}).checked = false;

		}			

	}


*/
}

function checkOutputShaftDirection()
{
	// 中実軸　軸両出しの場合は中実軸フランジ取付が選択不可
	if($('input[name="outputshaft_direction_id"]:checked').val() == "T"){
		if($('input[name="mountStyle"]:checked').val() ==  "O_S_F")
			$('input[name="mountStyle"]:checked').attr('checked', false);
	}
/*
	// 中実軸　軸両出しの場合は中実軸フランジ取付が選択不可

	if($A(sForm.outputshaftDirection()).find(function(v) {return v.checked;}).value == "T")

	{

		if($A(sForm.mountStyle()).find(function(v) {return v.checked;}).value == "O_S_F"){

			$A(sForm.mountStyle()).find(function(v) {return v.checked;}).checked = false;

		}

		

	}		
*/
}
