/**
 * A Siten Eventek
 *
 * @package    mvo
 * @subpackage site
 * @author     Szijártó Tamás ( szicsu ) <szicsu@jquery.hu>
 * @version    SVN: $Id: $
 */
Site.Events.weeklyMenu = function(){
	
	weeklyMenuManager.init();

}


Site.Events.passwordMatch = function(){
	//TODO: ezt általáosabbra kell megcsinálni :)
	
	$('form.jsPasswordMatch input:password').bind('blur, keyup',function( e ){
	
		var masterPsw = false;
		var matched = true;
		
		var matchObj = $('#jsPasswordMatch');
		var notMatchObj = $('#jsPasswordNotMatch');
		
		matchObj.hide();
		notMatchObj.hide();
		
		
		$('form.jsPasswordMatch input:password').each(function(){
			
			if( masterPsw === false ){
				masterPsw = this.value;
			}
			else if( masterPsw != this.value ){
				matched = false;
				return false;
			}
		});
		
		if( matched ){
			matchObj.show();
		}
		else{
			notMatchObj.show();
		}
		
	});
}

/**
 * Regisztrációs hosszú kérdőív
 */
Site.Events.registration_questionnaireIndex = function(){

	questionnaireManager
		.init( $("#jsQuestionnaireContainer") )
		.initDependency();
	
}

/**
 * billboard
 */
 Site.Events.billboard = function(){
	
	billboardManager.init( $('#jsBillboardConatiner') );
	billboardManager.initTimer( 3000 );
 }
 
 /**
 * Webshop
 */
 Site.Events.webshopIndex = function(){
 
	$('.jsWebshopViewLink').bind( 'click', function(event){ 
		$.ajax({ 
			url: $(this).attr('href'),
			dataType: 'html', 
			success: function( ret ){ 
				dialogManager.open({
					title: __('My World') +' - '+ __('Webshop'),
					height: 500,
					text: ret
				}, function( dialogObj ){
					dialogObj.find('.jsWebshopDialogOrderLink').bind('click',function(){
						$('#jsOrderLink_' + this.id ).trigger('click');
						return false;
					});
				});
			} 
		});    
		return false;
	});

	$('.jsWebshopOrderLink').bind( 'click', function(event){ 
		$.ajax({ 
			url: $(this).attr('href'),
			dataType: 'html', 
			success: function( ret ){ 
				info( ret );
			} 
		});    
		return false;
	});
 }
 
/**
  *
  */
Site.Events.usersEditprofilevisibility = function(){

	$("input[name^='mvo_profile_visibility']").eq('2').bind('click', function(){
		$("input[name^='mvo_profile_visibility']")
			.filter("input[value='"+ $(this).val() +"']").not(this).trigger('click');
	});
}
 
 
 /**
 * CategoryFilter
 **/
 Site.Events.categoryFilter = function(){
	
	
	$('.jsCategoryFilter').bind('change.categoryFilter',function(){
		
		if( !$(this).val() ){
			return false;
		}
		
		var catId = $(this).val();
		var selectObj = $('#' + $(this).attr('rel') );
		
		$.ajax({ 
			url: Site.Helper.getSluggedUrl('/ajax/getCategoryChildren'),
			dataType: 'json', 
			data:{ id: catId },
			success: function( ret ){ 
				Site.Helper.Select.replaceOptions( selectObj, ret );
				selectObj.focus();
			} 
		});    
		
		return false;
	})
	.each(function(){
		if( !$(this).hasClass('jsNoAutoFilter') ){
			$(this).trigger('change.categoryFilter');
		}
	});
 }
 
 /**
 * Coupon
 */
 Site.Events.couponIndex = function(){

	$('.jsCouponView').bind( 'click', function(event){ 
		$.ajax({ 
			url: $(this).attr('href') + '?' +(new Date()).getTime(), //IE :(
			dataType: 'html', 
			success: function( ret ){ 
				dialogManager.open({
					title: __('My World') +' - '+ __('Coupon'),
					height: 500,
					text: ret
				}, function( dialogObj ){
					dialogObj.find('form').bind('submit', function(){return false;});
					dialogObj.find('.jsCouponPrint').bind('click',function(){
						
						if( !dialogObj.find('#jsShopSlug').val() ){
							dialogObj.find('#jsCouponShopError').show();
							return false;
						}
						
						var oForm = dialogObj.find('#jsCouponPrintForm'); 
						var sUrl = oForm.attr('action');
						sUrl+= '?slug=' + oForm.find('#jsCouponSlug').val();
						sUrl+= '&shop=' + oForm.find('#jsShopSlug').val();
						
						$('<iframe>')
							.attr('src', sUrl )
							.css({ visibility:'hidden', height: 0, width: 0 })
							.bind('load', dialogManager.close )
							.appendTo('body');
						
						if( $.browser.msie ){
							window.setTimeout( dialogManager.close, 5000 );
						}
						info(__('Please wait, printing in process!'));
						return false;
					});
				});
			} 
		});    
		return false;
	});
 }
 
 Site.Events.recipeSearch = function(){
	recipeSearchManager.init();
 }
 
 