$(document).ready(function(){
	
	// question
	$('#quest a').click(function(){$(this).toggleClass('open'); return false});
	
	//expand textarea
	$('textarea.expand').focus(function(){
		$(this).animate({height:208}, {queue:false, duration: 800, easing: 'easeInExpo'});	
	});
	$('textarea.expand').blur(function(){
		if ($(this).val() == '')
			$(this).animate({height:16}, {queue:false, duration: 800, easing: 'easeInExpo'});	
	});
        //expand textarea
        $('#detail_ifr').focus(function(){
                $(this).animate({height:208}, {queue:false, duration: 800, easing: 'easeInExpo'});
        });
        $('#detail_ifr').blur(function(){
                if ($(this).val() == '')
                        $(this).animate({height:16}, {queue:false, duration: 800, easing: 'easeInExpo'});
        });
	
	// hide
	$('div.option-head a').click(function(){
		if ($(this).is('.open')) {
			$(this).removeClass('open').text('show');
		} else {
			$(this).addClass('open').text('hide');
		}
		$('ul.option').slideToggle({ duration: 500});
		return false;
	});
	
	$('div.ticket input[type="radio"]').change(function(){
		if ($(this).is('#no')) {
			$(this).parent().find('input[type="text"]').attr('disabled','');
		} else {
			$(this).parent().find('input[type="text"]').attr('disabled','disabled');
		}
	});
	
	if (!$('input.will-call').is(':checked')) $('li.will-call').slideUp(300);
	$('input.will-call').change(function(){
		if ($(this).is(':checked')) $('li.will-call').slideDown(300);
		else $('li.will-call').slideUp(300);
	});
	
	if (!$('input.customize-chb').is(':checked')) $('li.customize-area').slideUp(300);
	$('input.customize-chb').change(function(){
		if ($(this).is(':checked')) $('li.customize-area').slideDown(300);
		else $('li.customize-area').slideUp(300);
	});
	
	if (!$('li.password-area input.radio').is('.pass-disable:checked')) $('.pasword-input').attr('disabled','disabled');
	$('li.password-area input.radio').change(function(){
		if (!$(this).is('.pass-disable')) $('.pasword-input').attr('disabled','disabled');
		else if (!$(this).is('.pass-enable')) $('.pasword-input').attr('disabled','')
	});
	
	// popups
	$('div.ticket a.but').click(function(){
		$('#fader').css('display','block');
		if ($.browser.msie && $.browser.version == '6.0') $('#main select').css('visibility','hidden');
			$('#popup2').fadeIn(400);
		poupUp_height('popup2');
		return false;
	});
	$('a.save-bt').click(function(){
		$('#fader').css('display','block');
		if ($.browser.msie && $.browser.version == '6.0') $('#main select').css('visibility','hidden');
			$('#popup1').fadeIn(400);
		poupUp_height('popup1');
		return false;
	});
	$('a.cancel, div.close a').click(function(){
		$(this).parents('div.popup').parent().fadeOut(400, function(){
			$('#fader').css('display','none');
			if ($.browser.msie && $.browser.version == '6.0') $('#main select').css('visibility','visible');
		});
		return false;
	});
	
	
	//Venue & Organizer
	$("input.venue-name").keyup(function() {
		if ($(this).val() != '') {
			var _value = $(this).val();
			$.ajax({
				type: "GET",
				url: "ajax/VenueName.tpl",
				data: "value="+_value,
				success: function(msg){
					$('div.venue-drop').html(msg).fadeIn(200);
					$('div.venue-drop li.new a').click(function(){
						$('#fader').css('display','block');
						if ($.browser.msie && $.browser.version == '6.0') $('select').css('visibility','hidden');
							$('#popup3').fadeIn(400);
						poupUp_height('popup3');
						return false;
					});
				}
			});
		} else {
			$('div.venue-drop').fadeOut(200);
		}
	});
	$('input.venue-name').blur(function(){
		$('div.venue-drop').fadeOut(200);
	});
	
	// radio buttons
	$('div.parts input[type="radio"]').click(function(){
		$(this).parents('div.list-holder').find('li').removeClass('active');
		$(this).parents('ul.slist').find('li').removeClass('active');
		$(this).parent().addClass('active');
	})
	
});
$(window).resize(function(){
	poupUp_height('popup1');
	poupUp_height('popup2');
});

function poupUp_height(_id)
{
	var _lightbox = document.getElementById(_id);
	var _popup_table = document.getElementById("fader");
	var _minWidth = document.getElementsByTagName('div')[0].offsetWidth;
	
	
	var _height = 0;
	var _width = 0;
	if (window.innerHeight) {
		_height = window.innerHeight;
		_width = window.innerWidth;
	} else {
		_height = document.documentElement.clientHeight;
		_width = document.documentElement.clientWidth;
	}
	var _page = document.getElementsByTagName("body")[0];
	if (_lightbox && _popup_table && _page) {
		if (_height > _page.offsetHeight) _popup_table.style.height = _height + "px";
		else _popup_table.style.height = _page.offsetHeight + "px";
		if (_width < _minWidth) {_popup_table.style.width = _minWidth + "px";} else {_popup_table.style.width = '100%'}
		
		if (_height > _lightbox.offsetHeight) {
			if (!window.innerHeight) {
				_lightbox.style.position = "absolute";
				_lightbox.style.top = document.documentElement.scrollTop + (_height - _lightbox.offsetHeight) / 2 + "px"
			} else {
				_lightbox.style.position = "fixed";
				_lightbox.style.top = (_height - _lightbox.offsetHeight) / 2 + "px";
			}
		}
		else {
			_lightbox.style.top = "0px";
			_lightbox.style.position = "absolute";
		}
		if (_width > _lightbox.offsetWidth) _lightbox.style.left = (_width - _lightbox.offsetWidth) / 2 + "px";
		else {_lightbox.style.left = "0px";_lightbox.style.position = "absolute";}
	}
}

function onward() {
   city = $("input[@name='radio']:checked").val()
   celebration = $("input[@name='radio3']:checked").val()

   url = celebration + city + "/"

   location = url;
}

function addVenForm() {

	$('#fader').css('display','block');
	if ($.browser.msie && $.browser.version == '6.0') $('select').css('visibility','hidden');
	$('#popup3').fadeIn(400);
	poupUp_height('popup3');
	return false;


}

$(function() {
	$('.error').hide();
        $(".submit_venue").click(function() {	
		$('.error').hide();
		var name = $("input#venue_name").val();
  		if (name == "") {
        		$("label#venue_name_error").show();
        		$("input#venue_name").focus();
        		return false;
      		}
                var addr1 = $("input#venue_addr1").val();
                if (addr1 == "") {
                        $("label#venue_addr1_error").show();
                        $("input#venue_addr1").focus();
                        return false;
                }
                var city_id = $("#venue_city_id").val();
		var zip = $("input#venue_zip").val();
		var url = $("input#venue_url").val();
		var phone = $("input#venue_phone").val();
		var desc = $("#venue_desc").val();
		  var dataString = 'venue_name='+ name + '&venue_addr1=' + addr1 + '&venue_phone=' + phone + '&venue_city_id=' + city_id + '&venue_zip=' + zip + '&venue_url=' + url + '&venue_desc=' + desc;
		  $("#loading").css('visibility','visible');
		  $.ajax({
		    type: "POST",
		    url: "/backend.php/venue/ajaxAdd",
		    data: dataString,
		    success: function(html) {
		     $('#venue_select').replaceWith(html);
		     $('#cantfind').empty(); 
			$('#popup3').fadeOut(400, function(){
			 $('#fader').css('display','none');
			 $('#loading').css('display','none');
			 if ($.browser.msie && $.browser.version == '6.0') $('#main select').css('visibility','visible');
			 });


		    }
		  });
		  return false;
	
	});
});

