//-----------------
function input_step2_click(id) {
	if($("#"+id).attr('checked')) {
		current_options[get_option_array_key(id)]=1;
		if(id=='option_cd_version') {
			$("#cd_version_ship").show();
		}
		$("#view_"+id).html('<LABEL for="'+id+'">$'+current_option_prices[get_option_array_key(id)]+'</LABEL>');
		$("label").mouseover(function() {
			$(this).css('cursor','pointer');
		});
	} else {
		current_options[get_option_array_key(id)]=0;
		if(id=='option_cd_version') {
			$("#cd_version_ship").hide();
		}
		$("#view_"+id).html('');
	}
	calculate_total_order_amount();
	display_total_amount();
}
//-----------------
function display_total_amount() {
	var kol='$'+total_order_amount;
	switch(kol.length) {
		case 3:
		result=kol+'.00';
		break;
		case 5:
		result=kol+'0';
		break;
		default:
		result=kol;
	}
	$("#total td:eq(1)").html(result);
}
//-----------------
function get_option_array_key(id) {
	switch(id) {
		case 'option_cd_version':
		key=0;
		break;
		case 'option_extended_download_period':
		key=1;
		break;
		case 'option_additional_months':
		key=2;
		break;
	}
	return key;
}
//-----------------
function calculate_total_order_amount() {
	total_order_amount=0;
	for(i=0;i<3;i++) {
		if(current_options[i]!=0) {
			total_order_amount=total_order_amount+current_option_prices[i];
		}
	}
	if(current_options[0]!=0) {
		if($("#ship_country").val().substring(0,13)=='United States') {
			ship=3.95;
			//ship=1.00;
		} else {
			//ship=1.00;
			ship=7.95;
		}
		$("#ship_country_span").html('$'+ship);
		total_order_amount=total_order_amount + ship;
	}
	total_order_amount=total_order_amount + base_total_order_amount;
	total_order_amount=Math.round(total_order_amount*Math.pow(10,2))/Math.pow(10,2);
}
//-----------------
function layer_initial_set() {
	$(".info_layer").css('left',((document.body.clientWidth/2)-300));
	for(i=1;i<5;i++) {
		$("#info_layer_"+i).css('top',((obj_top[(i-1)]+document.body.scrollTop)+'px'));
		$('#info_layer_'+i).jqDrag();
	}
}
//-----------------
function show_current_layer(id) {
	if(showing_layers[(id-1)]==0) {
		$("#info_layer_"+id).fadeIn('fast');
		showing_layers[(id-1)]=1;
	} else {
		$("#info_layer_"+id).fadeOut('normal');
		showing_layers[(id-1)]=0;
	}
}
//-----------------
function goto_checkout(id) {
	//---------
	if(js_check()) {
		//---------
		data="&order_type="+id+
		"&what_instrument_do_you_play="+$("#what_instrument_do_you_play").val()+
		"&what_is_your_skill_level="+$("#what_is_your_skill_level").val()+
		"&ship_country="+$("#ship_country").val();
		$(".step1").each(function() {
			if($(this).attr('checked')) {
				data=data+"&"+$(this).attr('id')+"="+$(this).val();
			}
		});
		$(".step2").each(function() {
			if($(this).attr('checked')) {
				data=data+"&"+$(this).attr('id')+"="+$(this).val();
			}
		});
		if(flag_go_out!=0) {
			$(".additional_options").each(function() {
				if($(this).attr('checked')) {
					data=data+"&"+$(this).attr('id')+"="+$(this).val();
				}
			});
		}
		$.ajax({
			type:		"POST",
			url:		"../development/scripts/set_order_params.php",
			data:		"task=set_order_params"+data,
			success:	function(msg) {
				if(msg=='good') {
					window.location.href='./additional_checkout.php';
				} else {
					alert(msg);
				}
			}
		});
		//---------
	}
}
//-----------------
function js_check() {
	var checked_elements=new Array(
	new Array('what_instrument_do_you_play','','what instrument do you play'),
	new Array('what_is_your_skill_level','','what is your skill level')
	);
	$errors='Please, select ';
	for(i=0;i<checked_elements.length;i++) {
		if($("#"+checked_elements[i][0]).val()==checked_elements[i][1]) {
			if($errors.length>15) {
				$errors=$errors+' and ';
			}
			$errors=$errors+checked_elements[i][2];
		}
	}
	$errors=$errors+'.';
	if($("#ship_country").val()=='' && $("#cd_version_ship").css('display')!='none') {
		alert('Please, select any country in "Ship To Country" option');
		return false;
	}
	if($errors.length>16) {
		alert($errors);
		return false;
	} else {
		return true;
	}
}
//-----------------
