/* debug */

jQuery.fn.ForceNumericOnly = function()
{
	return this.each(function()
	{
		$(this).keydown(function(e)
		{
			var key = e.charCode || e.keyCode || 0;
			return (key == 8 || key == 9 || key == 46 || (key >= 37 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105));
		});
	});
};





$(function()
{
	$(".message").delay(5000).slideUp('slow');
	$("input[type=text]").focus(function()
	{
		if (this.value == this.defaultValue)
		{
			this.select();
		}
	});
	$("input[type=text]").mouseup(function(e)
	{
		e.preventDefault();
	}); // chrome
	$('input[type=text]').blur(function()
	{
		if (!this.value) {
			if (! $(this).hasClass('tiebreakerInput')) {
				this.value = this.defaultValue;
			}
		}
	});
	
	$(".errorInput").live('focus' , function(){ $(this).removeClass('errorInput');});
	
	
	if ($("#mi_postalcode").val().length == 4)
	{
		json = $.ajax(
		{
			type : "GET",
			url : "/cmbpostal?action=get&postal=" + $("#mi_postalcode").val() ,
			async : false
		}).responseText;
		
		
		j = eval('(' + json + ')');
		var options='';
		for (var i = 0; i < j.length; i++) {
			options += '<option value="' + j[i].city + '">' + j[i].city + '</option>';
		}
		
		$("#mi_city").html(options);
	}
	
	
	if ($("#reg_postal").val().length == 4)
	{
		json = $.ajax(
		{
			type : "GET",
			url : "/cmbpostal?action=get&postal=" + $("#reg_postal").val() ,
			async : false
		}).responseText;
		
		
		j = eval('(' + json + ')');
		var options='';
		for (var i = 0; i < j.length; i++) {
			options += '<option value="' + j[i].city + '">' + j[i].city + '</option>';
		}
		
		$("#reg_city").html(options);
	}
	
	
	
	
});



OneDayShotController.refreshAfterFinish = false;

OneDayShotController.tieBreakerCounter = 1;

OneDayShotController.currentStep = 0;

OneDayShotController.parseAjaxResponse = function(json)
{	
	
	var ajaxifyResponse = $.parseJSON( json);
	
	if (ajaxifyResponse.status == "ok"){
		return true;
	}
	
	if (ajaxifyResponse.status == "nok"){
		return false;
	}	
		
	
	if(ajaxifyResponse.ajaxify)
	{
		var actions = eval('(' + ajaxifyResponse.ajaxify + ')');
		if (actions.domAction)
		{
			$(actions.domAction.selector).replaceWith(ajaxifyResponse.html);
			$('.itemSlideUp').slideDown().delay(3000).slideUp();
		} 
		
		else if (actions.forward)
		{
			if (OneDayShotController.netlogIframe == true)
			{
				window.location = actions.forward.url + "&netlogiframe=1";
			}
			else
			{
				window.location = actions.forward.url;
			}
		}
	}
	else if (ajaxifyResponse.multiajaxify)
	{
		actions = ajaxifyResponse.multiajaxify.actions;
		for (var i = 0; i < actions.replacements.length; i++) 
		{
			$(actions.replacements[i].selector).replaceWith(actions.replacements[i].html);
		}
	}
	
	return true;
};

OneDayShotController.checkDefaultValue = function(container)
{	
	var returnval=true;
	$(container).find(".no_defaults").each(function(){
		if (this.value == this.defaultValue)
		{
			returnval=false;
			$(this).addClass('errorInput');
		}
		else
		{
			$(this).removeClass('errorInput');
		}
	});
	return returnval;
};

OneDayShotController.login = function()
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=login&" + $('#login_form').serialize(),
		async : false
	}).responseText;
	
	OneDayShotController.parseAjaxResponse(response);
};

OneDayShotController.feedback = function()
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=feedback&" + $('#feedback_form').serialize(),
		async : false
	}).responseText;
	
	return OneDayShotController.parseAjaxResponse(response);
};


OneDayShotController.trackLink = function(link)
{
	response = $.ajax(
	{ 
		type : "GET",
		url : "/?action=tracklink&link=" + escape(link),
		async : false
	}).responseText;
	
};


OneDayShotController.loginByFbId = function(accesstoken)
{
	response = $.ajax(
	{ 
		type : "GET",
		url : "/?action=loginfacebook&accesstoken=" + accesstoken,
		async : false
	}).responseText;
	
	if (! OneDayShotController.parseAjaxResponse(response))
	{	
		
		FB.api('/me', function(response) {
			$('#mi_firstname').val(response.first_name);
		  	$('#mi_lastname').val(response.last_name);
		  	if (response.gender == "male")
		  	{	
				$('#mi_gender_m').attr('checked', true);
		  	}
		  	else
		  	{	
				$('#mi_gender_f').attr('checked', true);
		  	}
		  	
		  	bday = response.birthday.replace(/0(\d\/)/g,'$1');
			bday = bday.split("/");
		  	if (bday.length == 3)
		  	{	
			  	$('#mi_birthday_day').val(bday[1]);
			  	$('#mi_birthday_month').val(bday[0]);
			  	$('#mi_birthday_year').val(bday[2]);
		  	}		
			
		  	$('#mi_email').val(response.email);
		  	$('#mi_accesstoken').val(accesstoken);
		});
		
		
		$(".login").slideUp('slow', function()
		{
			$(".user-data").slideDown('slow');
		});
		
	}
};

OneDayShotController.loginByFbIdDuring = function(accesstoken)
{
	response = $.ajax(
	{ 
		type : "GET",
		url : "/?action=loginfacebookduring&accesstoken=" + accesstoken,
		async : false
	}).responseText;
	
	if (OneDayShotController.parseAjaxResponse(response) == false)
	{	
		FB.api('/me', function(response) {
			$('#reg_firstname').val(response.first_name);
		  	$('#reg_lastname').val(response.last_name);
		  	if (response.gender == "male")
		  	{	
				$('#reg_gender_m').attr('checked', true);
		  	}
		  	else
		  	{	
				$('#reg_gender_f').attr('checked', true);
		  	}
		  	
		  	bday = response.birthday.replace(/0(\d\/)/g,'$1');
			bday = bday.split("/");
		  	if (bday.length == 3)
		  	{	
			  	$('#reg_birthday_day').val(bday[1]);
			  	$('#reg_birthday_month').val(bday[0]);
			  	$('#reg_birthday_year').val(bday[2]);
		  	}		
			
		  	$('#reg_email').val(response.email);
		});
		
		$(".participation_login").slideUp('slow');
		$(".participation").slideDown('slow');
	};
};

OneDayShotController.bindFbId = function(accesstoken)
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=bindfacebook&accesstoken=" + accesstoken ,
		async : false
	}).responseText;
	
	
	var response = eval('(' + response + ')');
	
	if (response.status == "ok")	
	{
		$("#facebook_button_bind").slideUp();
		$("#facebook_succes_bind").slideDown();
		$("#facebook_fail_bind").hide();
	}
	else
	{
		$("#facebook_fail_bind").hide();
		$("#facebook_fail_bind").slideDown();
	}
};


OneDayShotController.wallPost = function(accesstoken)
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=Postfacebook&accesstoken=" + accesstoken ,
		async : false
	}).responseText;
			
			
	var response = eval('(' + response + ')');
	
	if (response.status == "ok")	
	{
		return true;
	}
	else
	{
		return false;
	}
	
};



OneDayShotController.wallPostShareIO = function(accesstoken)
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=PostfacebookShareIO&accesstoken=" + accesstoken ,
		async : false
	}).responseText;
			
			
	var response = eval('(' + response + ')');
	
	if (response.status == "ok")	
	{
		return true;
	}
	else
	{
		return false;
	}
	
};




OneDayShotController.forgotPassword = function()
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=forgotpassword&Email=" + $('#emailForgotPass').val(),
		async : false
	}).responseText;
	
	OneDayShotController.parseAjaxResponse(response);
};


OneDayShotController.forgotPasswordDuring = function()
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=forgotpasswordDuring&email=" + $('#emailForgotPassDuring').val(),
		async : false
	}).responseText;
	
	OneDayShotController.parseAjaxResponse(response);
};

OneDayShotController.logout = function()
{
	response = $.ajax(
	{
		type : "GET",
		
		url : "/?action=logout",
		async : false
	}).responseText;
	OneDayShotController.parseAjaxResponse(response);
};

OneDayShotController.register = function()
{	
	if (OneDayShotController.checkDefaultValue('#register_form'))
	{
		response = $.ajax(
		{
			type : "GET",
			url : "/?action=register&" + $('#register_form').serialize(),
			async : false
		}).responseText;
		
		OneDayShotController.parseAjaxResponse(response);
	}
	else
	{
		$('#register_form').find('.default_value_error').slideDown();
	}
};

OneDayShotController.resetPass = function()
{	
	if (OneDayShotController.checkDefaultValue('#resetpass_form'))
	{
		response = $.ajax(
		{
			type : "GET",
			url : "/reset?action=reset&" + $('#resetpass_form').serialize(),
			async : false
		}).responseText;
		
		
		
		if (response.search("statusok")  != -1)
		{
			return true;
		}
		else
		{
			OneDayShotController.parseAjaxResponse(response);
			return false;
		}
	}
	else
	{
		$('#resetpass_form').find('.default_value_error').slideDown().delay(2000).slideUp();
		return false;
	}
};


OneDayShotController.preRegister = function()
{	
	if (OneDayShotController.checkDefaultValue('#preregister_form'))
	{
		response = $.ajax(
		{
			type : "GET",
			url : "/preregister?action=register&" + $('#preregister_form').serialize(),
			async : false
		}).responseText;
		
		if (response == "ok")
		{
			return true;
		}
		else
		{
			OneDayShotController.parseAjaxResponse(response);
			return false;
		}
	}
	else
	{
		$('#preregister_form').find('.default_value_error').slideDown().delay(2000).slideUp();
		return false;
	}
};

OneDayShotController.update = function()
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=update&" + $('#register_form').serialize(),
		async : false
	}).responseText;
	
	OneDayShotController.parseAjaxResponse(response);
};



OneDayShotController.resendConfirmationMail = function()
{
	response = $.ajax(
	{
		type : "GET",
		url : "/?action=resendconfirmationmail",
		async : false
	}).responseText;
	
	
	var response = eval('(' + response + ')');
	
	if (response.status == "ok")	
	{
		$("#emailConfirmationBox").slideUp();
		$("#resendEmailSucces").slideDown();
		
	}
	else
	{
		$("#emailConfirmationBox").hide();
		$("#resendEmailFailed").slideDown();
	}
};



OneDayShotController.enableExtraTieBreaker = function(type)
{
	$('.field-disabled_' + type ).removeAttr('disabled').removeClass('field-disabled').addClass('field').val(0);
	if (type=="netlog") {
		first_netlog_share = false;
	}
	
	if (type=="twitter") {
		first_twitter_share = false;
	}
	
};

OneDayShotController.finish = function()
{	
	if (OneDayShotController.checkDefaultValue('.participation') == true)
	{
		urlParticipate = "/?action=participate&" + $('#contest').serialize();
		
		if (OneDayShotController.netlogIframe) {
			urlParticipate += "&netlogid=" + OneDayShotController.netlogId;
		}
		
		response = $.ajax(
		{
			type : "GET",
			url : urlParticipate,
			async : false
		}).responseText;
		
		if (response.search('statusok') != -1){	
			OneDayShotController.trackVirtualPageView('/gavpv/contest/thankyou' , true);
			return true;
		} 
		else {
			OneDayShotController.parseAjaxResponse(response);
			return false;
		}
	}
	else
	{
		$('.participation').find('.default_value_error').slideDown();
		
		return false;
	}
};

OneDayShotController.showError = function(holder, errorBlock, noHolderSlide)
{
	
	if (noHolderSlide)
	{
		$(holder).find(errorBlock).slideDown().delay(2000).slideUp();
	} 
	else
	{
		$('.step_' + OneDayShotController.currentStep).slideUp('slow', function()
		{
			$(holder).slideDown('slow', function()
			{
				$(holder).find(errorBlock).slideDown().delay(2000).slideUp();
			});
		});
	}
	
};


OneDayShotController.duringLogin = function()
{	
	
		urlLogin = "/?action=duringlogin&Email=" + $('#during_login_user').val() + "&Passwd=" + $('#during_login_password').val();
		
		if (OneDayShotController.netlogIframe) {
			urlLogin += "&netlogid=" + OneDayShotController.netlogId;
		}
	
		response = $.ajax(
		{
			type : "GET",
			url :  urlLogin,
			async : false
		}).responseText;
		
		if (response.search('statusok') != -1)
		{	
			return true;
		} 
		else
		{
			OneDayShotController.parseAjaxResponse(response);
			return false;
		}
	
};


OneDayShotController.addOnEnter = function(item, func)
{
	$(item).live('keydown' , function(event) {
		if (event.keyCode == '13') {
	
	     	func();
		}
	});
	return false;
};


//UI========================================================================




$('.btnDeleteShowQuestion').live('click' , function (event){
	$('.deleteQuestion').slideDown();
	$('.deleteMessage').slideUp();
	return false;
});

$('.btnDeleteNo').live('click' , function (event){
	$('.deleteQuestion').slideUp();
	$('.deleteMessage').slideDown();
	return false;
});


$('#btnResendConfirmationMail').live('click' , function (event){
	OneDayShotController.resendConfirmationMail();
	return false
	
});

$('#duringLoginBtn').live('click' , function (event){
	OneDayShotController.duringLogin();
	return false
	
});

$('.registerBtn').live('click', function(event)
{
	OneDayShotController.register();
	return false
});

$('.updateBtn').live('click', function(event)
{
	OneDayShotController.update();
	return false
});

$('#btn_logout').live('click', function(event)
{
	OneDayShotController.logout();
	return false
});

$('.btn_login').live('click', function(event)
{
	OneDayShotController.login();
	return false
});

$("#login").submit(function()
{	
	OneDayShotController.login();
	return true;
});

$('form').find('.birthday_box').live('mouseover' , function()
{	
	$(this).closest('form').find('.underage_message').show();
});

$('form').find('.birthday_box').live('mouseout' , function()
{	
	$(this).closest('form').find('.underage_message').hide();
});




var firstStep = true;
$(".btn-continue, .start").live('click' , function()
{
	
	var content = $(this).closest(".content");
	var items = content.attr('class').split(" ");
	var doNextStep = true;
	var nextstep = false;
	var nextstepname ="";
	$.each(items, function(key, value)
	{
		if (value.substr(0, 5) == 'step_')
		{
			var currentstep = value.substr(5, value.length - 5);
			nextstep = parseInt(currentstep) + 1;
		}
		
		if (value.substr(0, 6) == 'hstep_')
		{
			var currentstep = value.substr(6, value.length - 6);
			nextstep = parseInt(currentstep) + 1;
			
			
		}
		
		if (value =='passreset')
		{
			if (OneDayShotController.resetPass() == false)
			{
				doNextStep = false;
			}
		}
		
		
		
		if (value =='preregister')
		{
			if (OneDayShotController.preRegister() == false)
			{
				doNextStep = false;
			}
		}
		
		if (value == 'question')
		{
			if (content.find("input:checked").length == 0)
			{
				content.children(".questionError").slideDown().delay(2000).slideUp();
				doNextStep = false;
			} 
			else
			{
				doNextStep = true;
			}
		}
		
		if (value == 'participation')
		{
			if (OneDayShotController.finish() == false)
			{
				doNextStep = false;
			}
			;
		}
		
		if (value == 'tiebreaker')
		{
			
			doNextStep = true;
			content.find("input").each(function()
			{
				var jthis = $(this);
				if (jthis.attr('disabled'))
				{
					
				} 
				else
				{
					if (!((jthis.val() - 0) == jthis.val() && jthis.val().length > 0))
					{
						
						doNextStep = false;
					}
				}
				
				
			});
			
			if (doNextStep == false )
			{
				content.children(".disp_errors").hide().slideDown();
			}
		}
		
	});
	
	if (doNextStep)
	{
		
		
		
		if (firstStep == true)
		{
			firstStep = false;
			$('.sidesteps').hide();
			$('.sidestep_middle').show();
			$(".not_logged_in").slideDown('slow' , function(){ $(this).empty().remove();});
		}
		
		if ($('.hstep_' + (nextstep - 1)).is(":visible"))
		{
			$(('.hstep_' + (nextstep - 1))).slideUp('slow', function()
			{
				$('.step_' + nextstep).slideDown('slow');
			});
		}
		
		
		if ($('.step_' + (nextstep - 1)).is(":visible"))
		{
			$(('.step_' + (nextstep - 1))).slideUp('slow', function()
			{
				$('.step_' + nextstep).slideDown('slow');
			});
		}
		
		items = $('.step_' + nextstep).attr('class').split(" ");
		
		$.each(items, function(key, value)
		{
			
			if (value == "movieholder")
			{	
				if (OneDayShotController.timerVideoTicks == 0) {
					OneDayShotController.timerVideoId = setInterval(OneDayShotController.timerVideo , 1000);
					
					$(".hideduringvideo").hide();
					$(".dropdowns").slideUp();
				}	
			}
			
			if (value == "question") {
				$(".hideduringvideo").show();
			}
			
			if (value == "thankyou")
			{
				$('.sidesteps').hide();
				$('.sidestep_last').show();
			}
		});
		
		$('.sidestep_' + nextstep).show();
		
		
		OneDayShotController.currentStep = nextstep;
	}
	//event.preventDefault();
	return false;
});

OneDayShotController.timerVideoId;
OneDayShotController.timerVideoTicks=0;
OneDayShotController.timerVideo = function()
{
	OneDayShotController.timerVideoTicks++;
	
	$("#timerVideo").html((15 - OneDayShotController.timerVideoTicks) + "s");
	if (OneDayShotController.timerVideoTicks == 15)
	{
		$(".movieholder").find(".btn-continue-disabled").removeClass('btn-continue-disabled').addClass("btn-continue");
		$("#timerVideo").hide();
		clearInterval(OneDayShotController.timerVideoId);
		
	}
};


OneDayShotController.nextStep;

var first_netlog_share = true;
var first_facebook_share = true;
var first_twitter_share = true;


$('.tracking_links').live ('click' , function()
{	
	OneDayShotController.trackLink($(this).attr('href'));
});


$('#facebook_post').live ('click' , function()
{
	if (first_facebook_share)
	{
		FB.login(function(response) {
			if (response.session) 
			{	
			  	if (OneDayShotController.wallPost(response.session.access_token))
			  	{
			  		OneDayShotController.enableExtraTieBreaker('facebook');
			  		first_facebook_share = false;
			  	}
			  	else
			  	{	
			  		//Wallpost error
			  	};
		  	} 
		  	else {
			    // user cancelled login
	  		}
		},{perms:'publish_stream'});	
	}
	return false;
});


$('#facebook_post_shareio').live ('click' , function()
{
	if (first_facebook_share)
	{
		FB.login(function(response) {
			if (response.session) 
			{	
			  	if (OneDayShotController.wallPostShareIO(response.session.access_token))
			  	{
			  		//ok
			  	}
			  	else
			  	{	
			  		//Wallpost error
			  	};
		  	} 
		  	else {
			    // user cancelled login
	  		}
		},{perms:'publish_stream'});	
	}
	return false;
});





$(".btn_myinfo, #btn_myinfo_2, #btn_myinfo_fromlogin").live('click' ,function()
{
	$(".not_logged_in, .unconfirmed").slideUp();
	
	if ($('.login').css('display') == 'none')
	{
		$('.user-data').slideDown('slow');
	} else
	{
		$(".login").slideUp('slow', function()
		{
			$(".user-data").slideDown('slow');
		});
	}
});


$(".btn_open_login , #btn_login_2").live( 'click' , function()
{	
	$(".not_logged_in, .unconfirmed").slideUp();
	
	if ($('.user-data').css('display') == 'none')
	{
		$('.login').slideDown('slow');
	} 
	else
	{
		$(".user-data").slideUp('slow', function()
		{
			$(".login").slideDown('slow');
		});
	}
});

$('.urlBtn').click(function()
{
	$('.movieholder').children('.btn-continue').slideDown();
});

window.NETSPOTVideoplayerCallback = function(tp)
{
	if (tp == 100)
	{
		$('.movieholder').children('.btn-continue').slideDown();
	}
};

$(".btn_awnser").click(function()
{
	$(this).closest('.content').children('.option').removeClass('active');
	$(this).closest('p').addClass('active');
});

$(".btn_dropdown_close").live('click', function()
{
	$(this).closest('.dropdowns').slideUp('normal' , function(){$(".hideAfterClose").hide();});
	$(".not_logged_in, .unconfirmed").slideDown();
});

$(".startFromMoreInfo").click(function()
{
	$(".moreinfo").slideUp('slow', function()
	{
		$('.step_1').slideDown();
		if (OneDayShotController.timerVideoTicks == 0)
		{
			OneDayShotController.timerVideoId = setInterval(OneDayShotController.timerVideo , 1000);
		}
		firstStep = false;
		$('.sidesteps').hide();
		$('.sidestep_middle').show();
		$(".not_logged_in, .unconfirmed").slideDown('slow' , function(){ $(this).empty().remove();});
	});
	return false;
});

$(".btnBackFromSuperKezoo").click(function()
{
	$(".superkezoo").slideUp('slow', function()
	{
		if (OneDayShotController.particpated == false) {
			$('.info').slideDown();
		}
		
	});
	return false;
});


$(".btn_moreinfoback").click(function()
{
	$(".moreinfo").slideUp('slow', function()
	{
		$('.info').slideDown();
	});
	return false;
});


$(".btn_infoprice").click(function()
{
	$(".info").slideUp('slow', function()
	{
		$('.moreinfo').slideDown();
	});
	
	
	
	return false;
});


$(".btnSuperKezoo").click(function()
{
	$(".info").slideUp('slow', function()
	{
		$('.superkezoo').slideDown();
	});
	
	$(".moreinfo").slideUp('slow');
	
	return false;
});

$("#btn_forgotpass").live('click', function(){
	$("#forgot_pass_hidden").slideDown();
});

$(".btn_forgotpass_send").live('click', function()
{
	OneDayShotController.forgotPassword();
	//event.preventDefault();
	return false;
});


$("#btn_forgotpass_during").live('click', function(){
	$("#forgot_pass_hidden_during").slideDown();
});

$(".btn_forgotpass_send_during").live('click', function()
{
	OneDayShotController.forgotPasswordDuring();
	//event.preventDefault();
	return false;
});


OneDayShotController.addOnEnter('#Email' , OneDayShotController.login);
OneDayShotController.addOnEnter('#Passwd' , OneDayShotController.login);
OneDayShotController.addOnEnter('#register_form .update_text' , OneDayShotController.update);
OneDayShotController.addOnEnter('#register_form .register_text' , OneDayShotController.register);


$(".btn_steps").click(function()
{	
	if (this.id.substr(0, 5) == 'step_')
	{
		var step = this.id.substr(5, this.id.length - 5);
	}
	
	if (step != OneDayShotController.currentStep)
	{
		$(('.step_' + (OneDayShotController.currentStep))).slideUp('slow', function()
		{
			$('.step_' + step).slideDown('slow');
		});
		OneDayShotController.currentStep = step;
	}
});

$(".disableChecked").removeAttr('checked');

$(".numeric").ForceNumericOnly();

$("#mi_update_pass").live('click' ,function(){
	$('.passHidden').show();
	$('.passShow').hide();
	return false;
});

$("#logoToolTip").mouseover(function (){ $("#dragToFavorites").show();});
$("#logoToolTip").mouseout(function (){ $("#dragToFavorites").hide();});


//Facebook !
$('#facebook_button_reg').live ('click' , function()
	{
		FB.login(function(response) {
			
			FB.getSession();
			if (response.session) {
				$('#mi_accesstoken').val(response.session.access_token);
			  	FB.api('/me', function(response) {
					$('#mi_firstname').val(response.first_name);
				  	$('#mi_lastname').val(response.last_name);
				  	if (response.gender == "male")
				  	{	
						$('#mi_gender_m').attr('checked', true);
				  	}
				  	else
				  	{	
						$('#mi_gender_f').attr('checked', true);
				  	}
				  	
				  	bday = response.birthday.replace(/0(\d\/)/g,'$1');
					bday = bday.split("/");
				  	if (bday.length == 3)
				  	{	
					  	$('#mi_birthday_day').val(bday[1]);
					  	$('#mi_birthday_month').val(bday[0]);
					  	$('#mi_birthday_year').val(bday[2]);
				  	}		
					
				  	$('#mi_email').val(response.email);
				});
		  	} 
		  	else 
			{
			    // user cancelled login
	  		}
	  	}, {perms:'user_birthday,email'});
	  	//event.preventDefault();
		return false;
	}
);	

$('.facebook_button_login_during').live ('click' , function()
		{
			FB.login(function(response) {
				if (response.session) {
				  	OneDayShotController.loginByFbIdDuring(response.session.access_token);
			  	} 
			  	else 
				{
				    // user cancelled login
		  		}
		  	});
		  	//event.preventDefault();
			return false;
		}
	);

$('#facebook_button_login').live ('click' , function()
		{
			FB.login(function(response) {
				if (response.session) {
				  	OneDayShotController.loginByFbId(response.session.access_token);
			  	} 
			  	else 
				{
				    // user cancelled login
		  		}
		  	},{perms:'user_birthday,email'});
		  	//event.preventDefault();
			return false;
		}
	);	

$('#facebook_button_bind').live ('click' , function()
		{
			FB.login(function(response) {
				if (response.session) 
				{	
				  	OneDayShotController.bindFbId(response.session.access_token);
			  	} 
			  	else {
				    // user cancelled login
		  		}
		  	} );
		  	//event.preventDefault();
			return false;
		}
	);

$("#btnSuperKezoo").click(function(){
	
});

$("#mi_postalcode").live("keyup"  , function(e) {
	
	if ($(this).val().length == 4) {
		json = $.ajax(
		{
			type : "GET",
			url : "/cmbpostal?action=get&postal=" + $(this).val() ,
			async : false
		}).responseText;
		
		
		j = eval('(' + json + ')');
		var options='';
		for (var i = 0; i < j.length; i++) {
			options += '<option value="' + j[i].city + '">' + j[i].city + '</option>';
		}
		
		$("#mi_city").html(options);
	}
	
});

$("#reg_postal").live("keyup"  , function(e) {
	
	if ($(this).val().length == 4) {
		json = $.ajax(
		{
			type : "GET",
			url : "/cmbpostal?action=get&postal=" + $(this).val() ,
			async : false
		}).responseText;
		
		
		j = eval('(' + json + ')');
		var options='';
		for (var i = 0; i < j.length; i++) {
			options += '<option value="' + j[i].city + '">' + j[i].city + '</option>';
		}
		
		$("#reg_city").html(options);
	}
});


//video = 0 is het een video wedstrijd en questions = aantal stappen

// /gavpv/play
// 
// /gavpv/question/id=1-9
// /gavpv/tiebreaker
// /gavpv/contactform
// /gavpv/thankyou


/* GOOGLE ANALYTICS */
OneDayShotController.trackVirtualPageView = function (vpv , showConfigString)
{
	if (typeof(showConfigString) === "undefined")
	{
		showConfigString = false;
	}
	
	if (showConfigString === true)
	{
		_gaq.push(['_trackPageview', vpv + '/video=' + OneDayShotController.isVideo + '&questions=' + OneDayShotController.totalQuestions ]);
	}
	else
	{
		_gaq.push(['_trackPageview', vpv ]);
	}
};

/* CONTEST */
$(".gbtn_start").		click(function(){ OneDayShotController.trackVirtualPageView('/gavpv/contest/play' , true);});
$("#gbtn_video").		click(function(){ OneDayShotController.trackVirtualPageView('/gavpv/contest/video');});
$("#gbtn_tiebreaker").	click(function(){ OneDayShotController.trackVirtualPageView('/gavpv/contest/tiebreaker');});
$(".gbtn_finish").		click(function(){ OneDayShotController.trackVirtualPageView('/gavpv/contest/contactform');});


$(".gbtn_questions").	click(function(){
	
	id = this.id.split("_");
	
	if (id.length == 2) {
		id = id[1];
		OneDayShotController.trackVirtualPageView('/gavpv/contest/question/id=' + id);
	}
	
});


/* FOOTER */
$("#gbtn_footer_facebook")	.click( function(){ OneDayShotController.trackVirtualPageView('/gavpv/follow/facebook');});
$("#gbtn_footer_netlog")	.click( function(){ OneDayShotController.trackVirtualPageView('/gavpv/follow/netlog');});
$("#gbtn_footer_twitter")	.click( function(){ OneDayShotController.trackVirtualPageView('/gavpv/follow/twitter');});


/* TIEBREAKER */
$(".gbtn_tiebreaker_facebook")	.click( function(){ OneDayShotController.trackVirtualPageView('/gavpv/share/facebook');});
$(".gbtn_tiebreaker_netlog")	.click( function(){ OneDayShotController.trackVirtualPageView('/gavpv/share/netlog');});
$(".gbtn_tiebreaker_twitter")	.click( function(){ OneDayShotController.trackVirtualPageView('/gavpv/share/twitter');});


/* all */

$(".gbtn").live("click" , function() 
{
	var items = $(this).attr('class').split(" ");
	$.each(items, function(key, value) {
		if (value.substr(0, 5) == 'gbtn_') {
			array  = value.split ("_");
			array.shift();
			var i=array.length;
			for ( i; i ==0; i--)
			{
				array[i].split("-").join("=");
			}
			string = array.join("/");
			
			OneDayShotController.trackVirtualPageView('/gavpv/' + string );
		}
	});
});


$("#feedbackButton").click(function(){ $('#feedbackButton').slideUp('slow' , function(){ $("#hiddenFormFeedback").slideDown('slow');})});


$("#sendFeedFackFormBtn").click(function(){
	OneDayShotController.feedback();
	$("#hiddenFormFeedback").slideUp('slow', function(){
		$("#feedBackThankYou").slideDown('slow').delay(2000).slideUp('slow' , function(){
			$("#feedbackButton").slideDown('slow');
			elem = $("#feed_title").get();
			elem.value = elem.defaultValue;
			elem = $("#feed_description").get();
			elem.value = elem.defaultValue;
			elem = $("#feed_email").get();
			elem.value = elem.defaultValue;
			
		});
	});
	
});



$(".btnShowAllWinners").click(function(){ $(this).hide(); $(this).closest('.sidesteps').find(".btnHideAllWinners").show(); $(this).closest('.sidesteps').find(".moreWinnersIndicator").hide(); $(this).closest('.sidesteps').find('.winneritemhidden').slideDown(); return false;});
$(".btnHideAllWinners").click(function(){ $(this).hide(); $(this).closest('.sidesteps').find(".btnShowAllWinners").show(); $(this).closest('.sidesteps').find(".moreWinnersIndicator").show(); $(this).closest('.sidesteps').find('.winneritemhidden').slideUp(); return false;});


$(".checkParticipationDuringYes").click(function(){ $(this).closest(".content").slideUp('slow'); $(".participation_login").slideDown('slow'); });
$(".checkParticipationDuringNo").click(function(){ $(this).closest(".content").slideUp('slow'); $(".participation").slideDown('slow'); });



function enableNetlog(){
	OneDayShotController.enableExtraTieBreaker('netlog');
}

function enableTwitter(){
	OneDayShotController.enableExtraTieBreaker('twitter');
}

 






