// JavaScript Document
/**
 * 
 *
 */
 
$(document).ready(function(){
	tabToDisplay = $('#current_tab').val();
	if (typeof(tabToDisplay) == 'undefined') {
		tabToDisplay = 'user_info';
	}
	displayFormSection(tabToDisplay);					
	$('.flyout').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 250 
	});
	

});
 
 
 
function LaunchFoundPet(profile_id, url) {
	$(".popup").popup({
		    width: 400,
		    height: 600,
		    titlebar: false,
		    status: false,
		    resizable: true,
		    toolbar: false,
		    scrollbars: true,
		    menubar: true
		});

	return false;
}

function addContact(profile_id, is_activation) {
	//alert(is_activation);
	
	//$('#contact_grid_edit').load("responders/UpdateContactGrid.php", {add: true, profile_id: profile_id, is_activation:is_activation});

	//$('#contact_grid_next_row').load("responders/UpdateContactGrid.php", {add: true, profile_id: profile_id, is_activation:is_activation});
	prevId = $("#next_contact_id").val();
	oldNum = prevId.substring(3);
	if (oldNum == '') oldNum = 0;
	oldNum = parseInt(oldNum)+1;
	newId = 'new'+oldNum;


	
	html = '<tr><td>N/A</td><td><input type="text" style="width: 130px;" name="emergency_contact['+newId+'][name]"></td><td><input type="text" style="width: 130px;" name="emergency_contact['+newId+'][email]"></td><td><input type="text" style="width: 130px;" name="emergency_contact['+newId+'][phone_number]"></td><td><input type="text" style="width: 130px;" name="emergency_contact['+newId+'][twitter_username]"></td><td><table class="contact_methods"><tr><td><input type="checkbox" value="1" name="emergency_contact['+newId+'][use_phone]">Phone</td></tr><tr><td><input type="checkbox" value="1" name="emergency_contact['+newId+'][use_sms]">Text Msg</td></tr><tr><td><input type="checkbox" name="emergency_contact['+newId+'][use_email]" value="1">Email</td></tr><tr><td><input type="checkbox" value="1" name="emergency_contact['+newId+'][use_twitter]">Twitter</td></tr></table></td></tr>';
	
	html = html + '<input type="hidden"  name="emergency_contact['+newId+'][id]" value="'+newId+'"/>';
	html = html + '<input type="hidden"  name="emergency_contact['+newId+'][profile_id]" value="'+profile_id+'"/>';
	
	
	$('#contact_grid_table').append(html);
	$("#next_contact_id").val(newId);
	//alert('just set to '+$("#next_contact_id").val());
	oldContactIds = $('input[name=contact_ids]').val();
	$('input[name=contact_ids]').val(oldContactIds+","+newId);

	
	
}

function sendMessage(is_user, contact_id, profile_id, method) {
	var div = '#contact['+contact_id+']['+method+'][status]';
	
	div = '#contact_'+contact_id+'_'+method+'_status';
	$(div).load("responders/SendMessage.php", {method: method, contact_id: contact_id, profile_id: profile_id, is_user: is_user});
	
}

function checkForUniqueURL(urlInput, toUpdate) {
	var div = '#'+toUpdate;
	$(div).load("responders/CheckForUniqueURL.php", {testURL: urlInput});
}

function handleUseTwitterToggle() {
	useTwitter = $("#user_use_twitter").attr('checked');
	if (useTwitter == true) {
		$('#twitter_credentials_table').show('slow');
	} else {
		$('#twitter_credentials_table').hide('slow');
	}
	
}

function updateCheckBoxVar(sourceInput, destInput) {
	var val = $('#'+sourceInput).attr('checked');
	if (val == true) {
		$('#'+destInput).attr('checked', true);
	} else {
		$('#'+destInput).attr('checked', false);
	}
}

function displayFormSection(section) {
	switch (section) {
		
		case 'profile_info':
			$('#current_tab').val('profile_info');
			$('#back_button').val('<< Back - Owner Profile');
			$('#next_button').val('Next - Emergency Contacts >>');
			$('#back_button').show();
			$('#next_button').show();
			$('#profile_info').show('slow');
			$('#profile_info_tab').addClass('activeTab');
			$('#user_info').hide('slow');
			$('#user_info_tab').removeClass('activeTab');
			$('#contact_grid_edit').hide('slow');
			$('#contact_grid_edit_tab').removeClass('activeTab');
			break;
			
		case 'contact_grid_edit':
			$('#current_tab').val('profile_info');
			$('#back_button').val('<< Back - Edit Pet Profile');
			$('#back_button').show();
			$('#next_button').hide();
			$('#contact_grid_edit').show('slow');
			$('#contact_grid_edit_tab').addClass('activeTab');
			$('#profile_info').hide('slow');
			$('#profile_info_tab').removeClass('activeTab');
			$('#user_info').hide('slow');
			$('#user_info_tab').removeClass('activeTab');
			$('#current_tab').val('contact_grid_edit');
			break;
			
		case 'user_info':
		default:
			$('#current_tab').val('profile_info');
			$('#back_button').hide();
			$('#next_button').val('Next - Edit Pet Profile >>');
			$('#next_button').show();
			$('#user_info').show('slow');
			$('#user_info_tab').addClass('activeTab');
			$('#profile_info').hide('slow');
			$('#profile_info_tab').removeClass('activeTab');
			$('#contact_grid_edit').hide('slow');
			$('#contact_grid_edit_tab').removeClass('activeTab');
			$('#current_tab').val('user_info');
			break;
			
		
		
		
	}
	
}

/*

function showAddressPopup() {
	toggleAddressPopup(1);	
}

function hideAddressPopup() {
	toggleAddressPopup(0);
}

function toggleAddressPopup(showAddress) {
	if (showAddress == 1) {
		$('#address_popup').show('slow');
	} else {
		$('#address_popup').hide('slow');
	}
	
}
*/

function UpdateURL(url) {
	$("#profile_url").val(url);	
}


