window.addEvent('domready', function(){		
	
	fade_value = 0.3;
	fade_out_value = 1;
	current_selected = 0;
	current_selected_detect = 0;
	question1 = 0;
	question2 = 0;
	submit_ready = 0;

	var myRequest = new Request.JSON({
				url: '/json/helpmechoose_json.phtml',
				method: 'get',
				onSuccess: function(response) {								
					pop_data = response;
				}
	});
	myRequest.get();
	
	cookie_init();
	
	$('recbutton').addEvent('mouseenter', function(event) {
		$('seemyrec1').set('id', 'seemyrec2');
	});
	$('recbutton').addEvent('mouseleave', function(event) {
		$('seemyrec2').set('id', 'seemyrec1');
	});
	
	
	
	function cookie_init() {

		$('choice1').set('checked', '');
		$('choice2').set('checked', '');
		$('choice3').set('checked', '');
		$('choice4').set('checked', '');
		$('choice5').set('checked', '');
		$('choice6').set('checked', '');
		$('choice7').set('checked', '');
		$('choice8').set('checked', '');
		$('choice9').set('checked', '');
		$('choice10').set('checked', '');
		$('choice11').set('checked', '');
		$('choice12').set('checked', '');
		$('choice13').set('checked', '');
		$('choice14').set('checked', '');
		
		$('seemyrec1').fade('0.2');

		$('AB300').fade('0.2');
		$('D63').fade('0.2');
		$('AB1100').fade('0.2');
		$('D64').fade('0.2');
		$('BLACKPRODUCT').fade('0.2');
		$('D400').fade('0.2');
		$('AB4000').fade('0.2');
		$('D500').fade('0.2');
		$('AB5000PLUS').fade('0.2');
		$('D580').fade('0.2');
		$('AB6000').fade('0.2');
		$('D200').fade('0.2');
	}

}); 

function check_submit() {
	
	submit_ready = 0;
	if ($('ask_question1') != '' && $('ask_question1') != null) {
		if (question1 > 0) {
			submit_ready = 1;
			if ($('ask_question2') != '' && $('ask_question2') != null) {
				if (question2 > 0) {
					submit_ready = 1;
				} else {
					submit_ready = 0;
				}
			}
		}
	}
	
	if ($('ask_question1_multi') != '' && $('ask_question1_multi') != null) {
		if (question1 > 0) {
			submit_ready = 1;
			if ($('ask_question2') != '' && $('ask_question2') != null) {
				if (question2 > 0) {
					submit_ready = 1;
				} else {
					submit_ready = 0;
				}
			}
		}
	}
	
	if (submit_ready == 1) $('seemyrec1').fade('1.0');
	if (submit_ready == 0) $('seemyrec1').fade('0.2');
}

function submit_multi(value) {
	question1 = value;
	$('submit_question1').set('value',question1);
	check_submit();
}

function submit_chage() {
	
	if ($('name') != null) {
		name = $('name').get('value');
		if (name.trim() != '')	$('submit_name').set('value', name.trim());
	}
	if ($('ask_question1') != '' && $('ask_question1') != null) {
		question1 = $('ask_question1').get('value');
		//if (question1 == '') question1 = 0;
		$('submit_question1').set('value',question1.trim());
	}
	
	if ($('ask_question2') != '' && $('ask_question2') != null) {
		//if (question2 == '') question2 = 0;
		question2 = $('ask_question2').get('value');
		$('submit_question2').set('value',question2.trim())
	}

	check_submit();
}

function business_choice(value) {

	biztype = value;

	if (biztype <= 4) {
		$('AB4000').fade('1');
		$('AB5000PLUS').fade('1');
		$('AB6000').fade('1');
		$('D63').fade('1');
		$('D580').fade('1');
		
		// Assign default values
		$('billcounter_rec').set('value', pop_data['BUSINESSTYPE1BILL']);
		$('detector_rec').set('value', pop_data['BUSINESSTYPE1DETECTOR']);
		$('coincounter_rec').set('value', pop_data['BUSINESSTYPE1COIN']);
	}

	if (biztype >= 5 && biztype <= 8) {
		$('AB1100').fade('1');
		$('AB4000').fade('1');
		$('AB6000').fade('1');
		$('D63').fade('1');
		$('D400').fade('1');
		$('D500').fade('1');
		
		// Assign default values
		$('billcounter_rec').set('value', pop_data['BUSINESSTYPE2BILL']);
		$('detector_rec').set('value', pop_data['BUSINESSTYPE2DETECTOR']);
		$('coincounter_rec').set('value', pop_data['BUSINESSTYPE2COIN']);
	}

	if (biztype >= 9 && biztype <= 11) {
		$('AB6000').fade('1');
		$('AB4000').fade('1');
		$('AB1100').fade('1');
		$('D63').fade('1');
		$('D400').fade('1');
		$('D500').fade('1');
		
		// Assign default values
		$('billcounter_rec').set('value', pop_data['BUSINESSTYPE3BILL']);
		$('detector_rec').set('value', pop_data['BUSINESSTYPE3DETECTOR']);
		$('coincounter_rec').set('value', pop_data['BUSINESSTYPE3COIN']);
	}

	if (biztype >= 12 && biztype <= 14) {
		$('AB300').fade('1');
		$('AB1100').fade('1');
		$('D63').fade('1');
		
		// Assign default values
		$('billcounter_rec').set('value', pop_data['BUSINESSTYPE4BILL']);
		$('detector_rec').set('value', pop_data['BUSINESSTYPE4DETECTOR']);
		$('coincounter_rec').set('value', pop_data['BUSINESSTYPE4COIN']);
		document.helpmechoose.submit();
	}
	$('mainbody').fade('0');
	var myRequest = new Request({
		url: 'business-typeajax.phtml',
		method: 'get',
		onSuccess: function(responseText, responseXML) {
			current_selected = 1;
			response = responseText;
			var myTimer = pageSucc.delay(1100);
		}
	});
	myRequest.get({biztype: value, time: $time()});
}

function pageSucc()
{
	$('mainbody').set('html', response);	
	$('mainbody').fade('1');
	$('submit_business').set('value', biztype);
}

function onlyNumbers(evt)
{
    //var charCode = (evt.which) ? evt.which : event.keyCode
    //     if (charCode == 46) return true;
    //     if (charCode > 31 && (charCode < 48 || charCode > 57))
    //        return false;
    //return true;
    var charCode = (evt.which) ? evt.which : event.keyCode;
	
	goodKey = false;
	goodFunc = false;
	goodMov = false;
	
	switch(charCode)
	{
		case 46:
			 goodFunc = true;
			//alert('DEL');
			break;
		case 8:
			 goodMov = true;
			//alert('BSK');
			break;
		case 37:
			 goodMov = true;
			//alert('LEFT');
			break;
		case 39:
			 goodMov = true;
			//alert('RIGHT');
			break;
		case 9:
			 goodFunc = true;
			//alert('TAB');
			break;
	}
	if (charCode >= 48 && charCode <= 57) goodKey = true;
	if (charCode >= 96 && charCode <= 105) goodKey = true;
	
        if (goodKey == true) {
        	inputData = $(id + num).get('value');
        	inputDataLength = inputData.length;
        	idnum = num + 1;
        	if (inputDataLength == 4 && idnum != 5) document.getElementById(id + idnum).focus(); 
        }
        
                
        if (goodKey == true || goodFunc == true || goodMov == true) {
        	return true;
        } else {
        	return false;
        }

}

function submit_data() 
{
	if (submit_ready == 1) javascript:document.helpmechoose.submit();
}
