$(document).ready(function(){
	//form submit
	var frmBtns = $('#form_signup_one_a').children('.formBtns').children('.formInput');
	var skipBtn = frmBtns.children('.gray_button');
	
	$(skipBtn).click(function(){
		window.location.href = Server.server_url+'/getting_started/two';
	});
	
	$('.contacts_selection .contact_details').each(function(i){
		$(this).click(function(event){
			var cid = $(this).attr('contact_id');
			var selected_row = $('#selected_'+cid);
			var selection_row = $('#selection_'+cid);
			
			selected_row.show();
			var input = selected_row.children('input');
			input.attr('checked','checked');
			
			//make sure that the selection_row's input is always unchecked
            var hide_selection = $(this).attr('selected_hide');			

            if (hide_selection == '1') {
                selection_row.hide();
                selection_row.children('input').attr('checked','');
            }
			
			selected_empty_row();
		});
	});

	$('.contacts_selected .contact_details').each(function(i){
		$(this).click(function(event){
			var cid = $(this).attr('contact_id');
			var selected_row = $('#selected_'+cid);
			var selection_row = $('#selection_'+cid);
		
			selected_row.hide();
			var input = selected_row.children('input');
			input.attr('checked','');
			
			//make sure that the selection_row's input is always unchecked
			selection_row.show();
			selection_row.children('input').attr('checked','');
			
			selected_empty_row();
		});
	});
	
	$('#form_signup_one_a').find('.submit_form').click(function(){
		$('#form_signup_one_a').submit();
	});
});

function selected_empty_row(){
	var s = $('.contacts_selected :checked');
	if (s.length) {
		$('.contacts_selected').removeClass('empty');
	}
	else {
		$('.contacts_selected').addClass('empty');
	}
}
