function showdescr(){
	$("#descrblock").animate({height: "show"}, 300);
	$("#descrbut").show();
	return false;
}

function changeRifma(_r){
	if(typeof(descriptions[_r]) != "undefined" && typeof(descriptions_values[_r]) != "undefined"){

		current_ind = descriptions_ind[_r];
		multy1 = descriptions_multy[_r][current_ind];
		hidden1 = descriptions_hidden[_r][current_ind];
		
		k = descriptions_ind[_r] + 1;
		k = (typeof(descriptions[_r][k]) != "undefined") ? k : 0;
		
		if(typeof(descriptions[_r][k]) != "undefined"){
			$("#r_"+_r).html(descriptions[_r][k]);
			$("#i_"+_r).attr("value", descriptions_values[_r][k]);
			descriptions_ind[_r] = k;

			multy = descriptions_multy[_r][k];
			hidden = descriptions_hidden[_r][k];

			if(multy1 == 1 && multy == 0){
				for(i in descriptions_hidden){

					for(j in descriptions_hidden[i]){
						if(descriptions_hidden[i][j] == 1){
							$("#tr_"+i).show();
							
							_v = $("#i_"+i).attr("value");
							if(_v == '' || typeof(_v) == 'undefined'){
								$("#i_"+i).attr("value", descriptions_values[i][j]);
							}
							
							break;
						}
					}
				}
			}

			if(multy1 == 0 && multy == 1){
				for(i in descriptions_hidden){

					for(j in descriptions_hidden[i]){
						if(descriptions_hidden[i][j] == 1){
							$("#tr_"+i).hide();
							$("#i_"+i).attr("value", "");
							break;
						}
					}
				}
			}			
			

		}
	}
}

function DoShowCels(){
	_value = $('#sttype').val();
	elem = $("#celebration");
	elem.empty();
	selindex = 0;
	var ind=0;
	for(i in celebrations){
		if(celebrations[i]['gentype'] == _value){
			$("<option></option>")
				.attr("value", celebrations[i].value)
				.html(celebrations[i].text)
				.appendTo(elem);

				if(celebrations[i].selected){
					selindex = ind;
				}
				
				ind++;
		}
	}
	elem.get(0).selectedIndex = selindex;
	
	if(_value == 1){
		$("#you").hide();
		$("#from").hide();
		$("#count").hide();
		$("#tr_style").hide();
	}else{
		$("#you").show();
		$("#from").show();
		$("#count").show();
		$("#tr_style").show();
	}

	elem = $("#v_to");
	elem.empty();
	selindex = 0;
	ind=0;
	for(i in v_to){
		if(_value == 1){
			if(v_to[i].value == 73 || v_to[i].value == 74){
				$("<option></option>")
					.attr("value", v_to[i].value)
					.html(v_to[i].text)
					.appendTo(elem);
					
				if(v_to[i].selected){
					selindex = ind;
				}
				
				ind++;
			}
		}else{
			$("<option></option>")
				.attr("value", v_to[i].value)
				.html(v_to[i].text)
				.appendTo(elem);

			if(v_to[i].selected){
				selindex = ind;
			}
			
			ind++;			
		}
	}
	elem.get(0).selectedIndex = selindex;
	
	DoShowAge(_value);
}

function DoShowPage(){
	_value = $('#paytype').val();
	if(_value==0 || typeof(_value) == "undefined"){
		if($("#age").attr("style") != 'display: none;'){
			$("#age").show();
			$("#showage").show();
		}
		if(typeof(ShowParams) == "undefined" || ShowParams == false){
			$("#params").show();
			$("input[@name='v_count']:radio").each(function(){
				$("#lv_count" + $(this).val()).show();
				$("#bv_count" + $(this).val()).show();
			});
		}
	}else{
		if($("#age").attr("style") != 'display: none;'){
			$("#age").hide();
			$("#showage").hide();
		}
		if(typeof(ShowParams) == "undefined" || ShowParams == false){
			$("#params").hide();
			$("input[@name='v_count']:radio").each(function(){
				this.checked = false;
				$("#lv_count" + $(this).val()).hide();
				$("#bv_count" + $(this).val()).hide();
				if($(this).val()==1){
					this.checked = true;
					$("#lv_count" + $(this).val()).show();
					$("#bv_count" + $(this).val()).show();
				}
			});	
		}
	}
}

function DoShowAge(_type){
	_type = (typeof(_type) == 'undefined') ? 0 : _type;
	_value = $('#celebration').val();

	if(typeof(celebrations[_value]) == 'undefined'){
		return false;
	}

	if(typeof(celebrations[_value]['age']) != "undefined"){
		if(celebrations[_value]['age']==1){
			$("#age").show();
			$("#showage").show();
		}else{
			$("#age").hide();
			$("#showage").hide();
		}
	}else{
		$("#age").hide();
		$("#showage").hide();
	}
		
	$("#listparams").find("label").each(function(){
		_jid = '#tr_'+$(this).find("input").val();
		if(typeof($(_jid).attr("id")) == 'undefined'){
			_jid = '';
		}
		
		found = false;
		for(i in celebrations[_value]['params']){
			if($(this).find("input").val() == celebrations[_value]['params'][i]){
				found = true;
			}
		}

		if(_jid == ''){
			if(found){
				$(this).animate({height: "show"}, 300);
			}else{
				$(this).find("input").get(0).checked = false;
				$(this).animate({height: "hide"}, 300);
			}
		}else{
			if(found){
				$(_jid).show();
			}else{
				$(this).find("input").get(0).checked = false;
				$(_jid).hide();
			}		
		}
		
	});

	elem = $("#paytype");
	elem.empty();
	if(typeof(elem.attr("name")) != 'undefined' && typeof(celebrations[_value]['paytype']) != 'undefined'){
		_paytype = celebrations[_value]['paytype'];
		for(i in paytypes){
			if(_paytype==i || _paytype==2){
				$("<option></option>")
					.attr("value", i)
					.html(paytypes[i])
					.appendTo(elem);
			}
		}
		elem.get(0).selectedIndex = 0;
	}
	
	if(_type == 1){
		return;
	}
	elem = $("#v_to");
	elem.empty();
	selectindex = 0;
	if(typeof(elem.attr("name")) != 'undefined' && typeof(celebrations[_value]['to']) != 'undefined'){
		for(i in celebrations[_value]['to']){
			for(j in v_to){
				if(j == celebrations[_value]['to'][i]){
					$("<option></option>")
						.attr("value", v_to[j]['value'])
						.html(v_to[j]['text'])
						.appendTo(elem);
					if(v_to[j]['selected']){
						selectindex = i;
					}
				}
			}
		}
		elem.get(0).selectedIndex = selectindex;
	}
	
	elem = $("#v_you");
	elem.empty();
	var checkedid = 0;
	var firstid = '';
	for(i in celebrations[_value]['you']){
		for(j in v_you){
			if(j == celebrations[_value]['you'][i]){
				schecked = (v_you[j]['checked']) ? "checked" : "";
				firstid = (firstid == '') ? v_you[j]['value'] : '';
				checkedid = (v_you[j]['checked']) ? j : checkedid;
				str = '<label for="v_you'+v_you[j]['value']+'" class="smallfont" id="lv_you'+v_you[j]['value']+'"><input name="v_you" id="v_you'+v_you[j]['value']+'" type="radio" class="checkbox" value="'+v_you[j]['value']+'" '+schecked+'>&nbsp;'+v_you[j]['text']+'</label><br>';
				$(str).appendTo(elem);
			}
		}
	}
	if(checkedid == 0){
		$("#v_you"+firstid).get(0).checked = true;
	}
		
	elem = $("#v_from");
	elem.empty();
	checkedid = 0;
	firstid = '';
	for(i in celebrations[_value]['from']){
		for(j in v_from){
			if(j == celebrations[_value]['from'][i]){
				schecked = (v_from[j]['checked']) ? "checked" : "";
				firstid = (firstid == '') ? v_from[j]['value'] : '';
				checkedid = (v_from[j]['checked']) ? j : checkedid;
				str = '<label for="v_from'+v_from[j]['value']+'" class="smallfont" id="lv_from'+v_from[j]['value']+'"><input name="v_from" id="v_from'+v_from[j]['value']+'" type="radio" class="checkbox" value="'+v_from[j]['value']+'" '+schecked+'>&nbsp;'+v_from[j]['text']+'</label><br>';
				$(str).appendTo(elem);
			}
		}
	}
	if(checkedid == 0){
		$("#v_from"+firstid).get(0).checked = true;
	}
	
	DoShowPage();
}

function makeSubmitValue(_name,_form){
	$("#submit_button").append("<input type='hidden' name='"+_name+"' value=1>");
	document.forms[_form].submit();
	return true;
}


hiddenImg1= new Image();
hiddenImg1.src= image_path+'ll1.gif';
hiddenImg2= new Image();
hiddenImg2.src= image_path+'ll2.gif';
hiddenImg3= new Image();
hiddenImg3.src= image_path+'ll3.gif';

$(document).ready(function(){

	$("#showdescr").click(function(){
		return showdescr();
	});	

	$(".knopka").mouseover(function(){
		$("#img1",this).attr("src",hiddenImg1.src);
		$("#img2",this).attr("src",hiddenImg2.src);
		$("#img3",this).attr("background",hiddenImg3.src);
	});	
	$(".knopka").mouseout(function(){
		$("#img1",this).attr("src",image_path+'l1.gif');
		$("#img2",this).attr("src",image_path+'l2.gif');
		$("#img3",this).attr("background",image_path+'l3.gif');
	});		
});
