$(document).ready(function(){

setTimeout(function(){$("#success").fadeOut(1000);}, 5000);
//setTimeout(function(){$("#error").fadeOut(1000);}, 4000);





	$("#finish").click(function(){
		$("#next1").hide();
		$("#section1").hide();		
		$("#section6").fadeIn(500);		
	return false; 
	})
	
	$("#various").click(function(){
		$("select[name='group_min'], select[name='group_hour'], #group_time_colon").hide();
		
	})
	
	$("#single").click(function(){
		$("select[name='group_min'], select[name='group_hour'], #group_time_colon").show();
	})
	
	$("#showBank").click(function(){
		$("#showBank").hide();
		$("#otherBankDiv").fadeIn(500);	
	return false; 
	})
	
	$("#showConsole").click(function(){
		$("#showConsole").hide();
		$("#otherConsoleDiv").fadeIn(500);	
	return false; 
	})
	
	$("#showBS").click(function(){
		$("#showBS").hide();
		$("#otherBSdiv").fadeIn(500);	
	return false; 
	})
	
	
	
	
	
	$("#signMeUp").click(function(){
		$("#signMeUp").hide();
		$("#section1").fadeIn(1000);		
	return false; 
	})
	
	$("#next1").click(function(){
		$("#next1").hide();
		$("#section2").slideDown(1000);		
	return false; 
	})
	
	$("#next2").click(function(){
		$("#next2").hide();
		$("#prev3").show();
		
			setTimeout(function(){
				$("#section2").slideUp(400);
			}, 200);
			
			setTimeout(function(){
				$("#section1").slideUp(400);
			}, 600);
			
			setTimeout(function(){
				$("#section3").fadeIn(1000);
			}, 1000);		
	return false; 
	})
	
	$("#yes").click(function(){
		$("#cohabInfo").fadeIn(1000);		 
	})
	
	$("#no").click(function(){
		$("#cohabInfo").fadeOut(1000);		 
	})
	
	$("#netOther").click(function(){
		$("#networkOther, .netOther").fadeIn(1000);		 
	})
	
	$("#iPOther").click(function(){
		$("#internetProviderOther").fadeIn(1000);		 
	})
	
	$("#cyes").click(function(){
		$("#child1").fadeIn(1000);		 
	})
	
	$("#cno").click(function(){
		$("#child1").fadeOut(1000);		 
	})
	
	$("#addChild2").click(function(){
		$(this).addClass('white');
		$("#child2").fadeIn(1000);	
	return false;
	})
	
	$("#addChild3").click(function(){
		$(this).addClass('white');
		$("#child3").fadeIn(1000);	
	return false;
	})
	
	$("#addMoreChildren").click(function(){
		$(this).addClass('white');
		$("#moreChildren").fadeIn(1000);	
	return false;
	})
	
	$("#next3").click(function(){
		$("#next3").hide();
		$("#prev3").hide();
		$("#prev4").show();
			$("#section3").slideUp(600);
			
			setTimeout(function(){
				$("#section4").fadeIn(1000);
			}, 650);		
	return false; 
	})
	
	$("#prev3").click(function(){
		$("#prev3").hide();
		$("#next2").show();
		$("#prev2").show();
		
			$("#section3").fadeOut(500);
		
			setTimeout(function(){
				$("#section1").slideDown(400);
			}, 500);
			
			setTimeout(function(){
				$("#section2").slideDown(400);
			}, 900);	
	return false; 
	})
	
	$("#next4").click(function(){
		$("#next4").hide();
		$("#prev4").hide();
		$("#prev5").show();
		$("#next5").show();
			$("#section4").slideUp(600);
			
			setTimeout(function(){
				$("#section5").fadeIn(1000);
			}, 650);		
	return false; 
	})
	
	$("#prev4").click(function(){
		$("#next3").show();
		$("#prev3").show();
		$("#prev4").hide();
		$("#next").hide();
			$("#section4").slideUp(600);
			
			setTimeout(function(){
				$("#section3").fadeIn(1000);
			}, 650);		
	return false; 
	})
	
	$("#next5").click(function(){
		$("#next5").hide();
		$("#prev5").hide();
		$("#prev6").show();
		$("#submitform").show();
			$("#section5").slideUp(600);
			
			setTimeout(function(){
				$("#section6").fadeIn(1000);
			}, 650);		
	return false; 
	})
	
	$("#prev5").click(function(){
		$("#next4").show();
		$("#prev4").show();
		$("#prev5").hide();
		$("#next5").hide();
			$("#section5").slideUp(600);
			
			setTimeout(function(){
				$("#section4").fadeIn(1000);
			}, 650);		
	return false; 
	})
	
	$("#prev6").click(function(){
		$("#next5").show();
		$("#prev5").show();
		$("#prev6").hide();
		$("#submitform").hide();
			$("#section6").slideUp(600);
			
			setTimeout(function(){
				$("#section5").fadeIn(1000);
			}, 650);		
	return false; 
	})
	
	$("#smokeYes").click(function(){
		$("#smokeInfo").fadeIn(500);		 
	})
	
	$("#smokeNo").click(function(){
		$("#smokeInfo").fadeOut(300);		 
	})
	
	$(".pet").click(function(){
		$("#petInsured").fadeIn(300);
		$("#petLabel").removeClass('white');
	})
	
	
	
   
   
   
  
   
   
});


/////////
///////////
////////
/////
//

function lookup(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'phone_make'+"", i:0}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
	
	
} // lookup
function fill(thisValue) {
	$('#phoneMake').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}

///////////////

function lookup2(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions2').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'phone_model'+"", i: 2}, function(data){
			if(data.length >0) {
				$('#suggestions2').show();
				$('#autoSuggestionsList2').html(data);
			}
		});
	}
	
	
} // lookup
function fill2(thisValue) {
	$('#phoneModel').val(thisValue);
	setTimeout("$('#suggestions2').hide();", 200);
}

////////////
	
function lookup3(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions3').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'network'+"", i: 3}, function(data){
			if(data.length >0) {
				$('#suggestions3').show();
				$('#autoSuggestionsList3').html(data);
			}
		});
	}
	
	
} // lookup
function fill3(thisValue) {
	$('#networkOther').val(thisValue);
	setTimeout("$('#suggestions3').hide();", 200);
}

////////////
	
function lookup4(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions4').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'occupation'+"", i: 4}, function(data){
			if(data.length >0) {
				$('#suggestions4').show();
				$('#autoSuggestionsList4').html(data);
			}
		});
	}
	
	
} // lookup
function fill4(thisValue) {
	$('#occupation').val(thisValue);
	setTimeout("$('#suggestions4').hide();", 200);
}

////////////

function lookup5(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions5').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'cohab_occupation'+"", i: 5}, function(data){
			if(data.length >0) {
				$('#suggestions5').show();
				$('#autoSuggestionsList5').html(data);
			}
		});
	}
	
	
} // lookup
function fill5(thisValue) {
	$('#cohabOccupation').val(thisValue);
	setTimeout("$('#suggestions5').hide();", 200);
}

////////////

function lookup6(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions6').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'bank'+"", i: 6}, function(data){
			if(data.length >0) {
				$('#suggestions6').show();
				$('#autoSuggestionsList6').html(data);
			}
		});
	}
	
	
} // lookup
function fill6(thisValue) {
	$('#otherBank').val(thisValue);
	setTimeout("$('#suggestions6').hide();", 200);
}

////////////

function lookup7(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions7').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'building_society'+"", i: 7}, function(data){
			if(data.length >0) {
				$('#suggestions7').show();
				$('#autoSuggestionsList7').html(data);
			}
		});
	}
	
	
} // lookup
function fill7(thisValue) {
	$('#otherBS').val(thisValue);
	setTimeout("$('#suggestions7').hide();", 200);
}

/////////////

function lookup8(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions8').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'car_insurer'+"", i: 8}, function(data){
			if(data.length >0) {
				$('#suggestions8').show();
				$('#autoSuggestionsList8').html(data);
			}
		});
	}
	
	
} // lookup
function fill8(thisValue) {
	$('#carInsurer').val(thisValue);
	setTimeout("$('#suggestions8').hide();", 200);
}

////////////

function lookup9(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions9').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'home_insurer'+"", i: 9}, function(data){
			if(data.length >0) {
				$('#suggestions9').show();
				$('#autoSuggestionsList9').html(data);
			}
		});
	}
	
	
} // lookup
function fill9(thisValue) {
	$('#homeInsurer').val(thisValue);
	setTimeout("$('#suggestions9').hide();", 200);
}

////////////

function lookup10(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions10').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'car_make'+"", i: 10}, function(data){
			if(data.length >0) {
				$('#suggestions10').show();
				$('#autoSuggestionsList10').html(data);
			}
		});
	}
	
	
} // lookup
function fill10(thisValue) {
	$('#carMake').val(thisValue);
	setTimeout("$('#suggestions10').hide();", 200);
}

////////////

function lookup11(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions11').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'car_model'+"", i: 11}, function(data){
			if(data.length >0) {
				$('#suggestions11').show();
				$('#autoSuggestionsList11').html(data);
			}
		});
	}
	
	
} // lookup
function fill11(thisValue) {
	$('#carModel').val(thisValue);
	setTimeout("$('#suggestions11').hide();", 200);
}

/////////////////

function lookup12(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions12').hide();
	} else {
		
		//if there is more than one line
		if(string.indexOf("\n")){
			var words = string.split("\n");
			var lastword = array_pop(words);
			
			$.post("autoComplete/rpc.php", {queryString: ""+lastword+"", field: ""+'medical'+"", i: 12}, function(data){
				if(data.length >0) {
					$('#suggestions12').show();
					$('#autoSuggestionsList12').html(data);
				}
			});
			
		}else{
			$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'medical'+"", i: 12}, function(data){
				if(data.length >0) {
					$('#suggestions12').show();
					$('#autoSuggestionsList12').html(data);
				}
			});
		}
	}
	
	
} // lookup
function fill12(thisValue) {
	var current = document.getElementById('medical').value;
	
	var wordsearch = current.search("\n");
	
	if(wordsearch!=-1){
		
	
		var words = explode("\n", current);
		array_pop(words);
		var finalArray = implode("\n", words);
		
		
		
		
		$(this).click(function(){
			$('#medical').val(finalArray + "\n" + thisValue);
			$("#suggestions12").hide();
		return false; 
		})
		
		//setTimeout("$('#suggestions12').hide();", 200);
		
	}else{
		$('#medical').val(thisValue);
		setTimeout("$('#suggestions12').hide();", 200);
	}
}


////////////////////////

function lookup13(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions13').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'internet_provider'+"", i: 13}, function(data){
			if(data.length >0) {
				$('#suggestions13').show();
				$('#autoSuggestionsList13').html(data);
			}
		});
	}
	
	
} // lookup
function fill13(thisValue) {
	$('#internetProviderOther').val(thisValue);
	setTimeout("$('#suggestions13').hide();", 200);
}	

////////////////////////

function lookup14(string) {
	if(string.length == 0) {
		// Hide the suggestion box.
		$('#suggestions14').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+string+"", field: ""+'consoles'+"", i: 14}, function(data){
			if(data.length >0) {
				$('#suggestions14').show();
				$('#autoSuggestionsList14').html(data);
			}
		});
	}
	
	
} // lookup
function fill14(thisValue) {
	$('#otherConsole').val(thisValue);
	setTimeout("$('#suggestions14').hide();", 200);
}

////////////

function hideShow(id, divname){
		$("#"+divname+id).toggle();
}


function add_all_users_to_group(){
	
	var ids = '';
	$('.uid').each(function(){
		ids = ids + $(this).val()+',';			
	})
	
	$.post("addUser.php", {ids:ids}, function(data){
		$('#userMessage').empty();
		$('#userMessage').append(data);
		$('#searchResults').empty();
		$('#searchResults').append('<p>All users successfully added to group</p>');
		setTimeout(function(){ $('#searchResults').fadeOut(500) }, 3000);
	});	
		
}