cplxform =  {
	offerObject:null,
	offerType:null,
	visibleForm:'tblas',	
	setOfferType:function(event){
		switch(event.target.id){
			case 'rad4':
				cplxform.offerType = 1;
			break;
			case 'rad5':
				cplxform.offerType = 2;
			break;
		}
		cplxform.synchronize();
		return true;
	},
	setOfferObject:function(event){
		oldoffer = cplxform.offerObject;
		switch(event.target.id){
			case 'rad1':
				cplxform.offerObject = 1;
			break;
			case 'rad2':
				cplxform.offerObject = 2;
			break;
			case 'rad3':
				cplxform.offerObject = 3;
			break;
		}
		
		if(oldoffer != cplxform.offerObject){
			cplxform.offerType=null;
			cplxform.deactivateTypes();
		}
		
		if(cplxform.offerObject == 3){
			$('#rad5').hide();
			$('#rad5label').hide();
		}else{
			$('#rad5').show();
			$('#rad5label').show();
		}
		cplxform.synchronize();
		return true;
	},
	synchronize:function(){
		this.setRadioValue('s1', this.offerObject);
		if(this.offerObject != null){
			this.activateTypes();
			if(this.offerObject == 3){
				this.offerType = 1;
				$('#rad4').attr('checked', 'checked');
			}
		}else{
			this.deactivateTypes();
		}
		this.setRadioValue('s2', this.offerType);
		if(this.offerType != null){
			this.activateMain();
		}else{
			this.deactivateMain();
		}
		this.activateForm();
	},
	getRadioValue:function(surrogateId){
		inputs = $('#'+surrogateId+' input').get();
		for(i=0;i<inputs.length;i++){
			if(inputs[i].attr('checked') == 'checked'){
				return i;
			}
		}
		return null;
	},
	setRadioValue:function(surrogateId, value){
		if (value == null) {
			$('#'+surrogateId+' input').attr('checked', '');
		} else {
			$('#'+surrogateId+' input['+value+']').attr('checked', 'checked');
		}
	},
	activateForm:function(){
		formid = 'tbl';
		switch(this.offerObject){
			case 1:
			formid += 'a';
			break;
			case 2:
			formid += 'h';
			break;
			case 3:
			formid += 'l';
			break
		}
		switch(this.offerType){
			case 1:
			formid += 's';
			break;
			case 2:
			formid += 'l';
			break;
		}
		if(formid.length == 5){
			$('#s4 table').remove().find('input,select').unbind();
			$('#s4 script').after(form[formid]);
			this.visibleForm = formid;
		}
		ajaxBubbleInit($('#s4'));
	},
	activateTypes:function(){
		$("#s1").removeClass("activeGroup");
		$("#s2").addClass("activeGroup");
		$("#s2").removeClass("fadeIt");
		$("#s2 input").removeAttr('disabled');
		
	},
	deactivateTypes:function(){
		$("#s2").removeClass("activeGroup");
		$("#s2").addClass("fadeIt");
		$("#s2 input").attr("disabled",'disabled');
		$("#s2 input").attr('checked','');
		this.offerType=null;
		this.deactivateMain();
	},
	activateMain:function(){
		$("#s2").removeClass("activeGroup");
		$("#s3,#s4").removeClass("fadeIt");
		$("#s3,#s4").addClass("activeGroup");
		$("#s3 input,#s4 input,#s3 select,#s4 select").removeAttr("disabled");
	},
	deactivateMain:function(){
		$("#s3,#s4").addClass("fadeIt");
		$("#s3,#s4").removeClass("activeGroup");
		$("#s3 input,#s4 input,#s3 select,s$ select").attr("disabled","disabled");
	}		
};


var ententyk = 0;

function showbubble() {
	if (ententyk == 0) {
		beginherebubble = "<div id='beginhere'></div>";
		
		$("#s1").prepend( beginherebubble );
		$("#beginhere").fadeIn("slow");
		//setTimeout('blik(3)',2000);
		
		ententyk = 1;
	}
}

function blik(i){
	if(i == 0) return;
	$("#s1").css("background-color","white");
	setTimeout('$("#s1").css("background-color","#FDE4BD")','50');
	setTimeout('blik('+(i-1)+')','200');
	;
}

hpinit = function(){

	cplxform.synchronize();

	$('#s4 script').after(form['tblas']);
	$('#s1 input').bind('click', cplxform.setOfferObject);
	$('#s2 input').bind('click', cplxform.setOfferType);

	$(".fadeOnload").addClass("fadeIt");
	$(".fadeIt input").attr("disabled","disabled");
	
	$(".fadeIt select").attr("disabled","disabled");

	var to = setTimeout("showbubble()",1000);
	$("#s1 input").bind('click',function(){
		ententyk = 1;
		$("#beginhere").remove();
	});
	$("#s1 label").bind('click',function(){
		ententyk = 1;
		$("#beginhere").remove();
	});
}

$(document).ready(hpinit);