//Document Ready code
$(document).ready(function() {
	
	$('.jquery_datepicker').datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'yy-mm-dd'
	});
	
	//$('select.autocomplete').select_autocomplete();
	
	// Country Picker 
	$('#CountryPicker').change(function(){
		$(location).attr('href', '/country/'+this.options[this.selectedIndex].value);
	});
	
	// Partner Picker
	$('#PartnerPicker').change(function(){
		$(location).attr('href', '/partners/country/'+this.options[this.selectedIndex].value);
	});
	
	// Visa Picker
	$('#VisaPicker').change(function(){
		$(location).attr('href', window.location+'/'+this.options[this.selectedIndex].value);
	});
	
	// Results Summary
	$("div.solutions_summary").accordion({
		collapsible: true,
		active: false,
		autoHeight: false
	});
	
	// DIY Packs
	$("div.diypacks_summary").accordion({
		collapsible: true,
		active: false,
		autoHeight: false
	});
	
	
	//$('#quicksearch-form').delay(500).animate({"height": "show", "opacity": "show"}, "slow");
  });


function updateMoneyLabel(country) {
	$.get('/ajax/localcurrency', {countryId: country}, function(currency) {
		$('.localcurrency').text(currency);
		alert('Please be sure to enter any Wealth and Earnings in '+currency);
	});
}


function getVisas(visaSelect, countrySelect, visaTypeSelect) {
	$.getJSON('/ajax/visas', {countryId: $(countrySelect).val(), visaTypeId: $(visaTypeSelect).val()}, function(j) {
		var options = '';
		for (var i = 0; i < j.length; i++) {
			options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		}
		
		if (j.length == 1) {
			$(visaSelect).attr('disabled', 'disabled');
		} else {
			$(visaSelect).removeAttr('disabled');
		}
		
		$(visaSelect).html(options);
	});
}

function saveSearch() {
	$.loading(true, {text: 'Saving...', mask: true, pulse: 'ellipsis'});
	$('#formdest').val('close');
	$('#frmSearch').submit();
}

function saveClose() {
	$.loading(true, {text: 'Saving...', mask: true, pulse: 'ellipsis'});
	$('#frmSearch').submit();
}

function closeClient() {
	$.loading(true, {text: 'Closing...', mask: true, pulse: 'ellipsis'});
	document.location = '/screener/actions/edit/new';
}

function editContactDetails(link) {
	$('#client-contact-static').toggle();
	$('#client-contact-edit').toggle();
	
	if ($(link).html() == 'edit') {
		$(link).html('cancel');
	} else {
		$(link).html('edit');
	}	
}