function createCookie(name,value,days){var expires="";if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString();}
document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' '){c=c.substring(1,c.length);}
if(c.indexOf(nameEQ)===0){return c.substring(nameEQ.length,c.length);}}
return null;}
function eraseCookie(name){createCookie(name,"",-1);}
jQuery.ajaxSetup({'beforeSend':function(xhr){xhr.setRequestHeader("Accept","text/javascript");},'cache':false});function onRefreshReminderForm(){if($j("select#email_template_before_after").val()=='before'){$j("span#optional_reminder_details").hide();$j("input#email_template_add_optional_reminder").attr("checked",false);$j("span#optional_reminder_details").addClass("inactive");$j("input#email_template_optional_reminder_period_in_days").attr("disabled",true);}else{$j("span#optional_reminder_details").show();if($j("input#email_template_add_optional_reminder").is(':checked')){$j("span#optional_reminder_details").removeClass("inactive");$j("input#email_template_optional_reminder_period_in_days").attr("disabled",false);}else{$j("span#optional_reminder_details").addClass("inactive");$j("input#email_template_optional_reminder_period_in_days").attr("disabled",true);}}}
(function($){$.fn.groupElements=function(elements_per_group,child_selector,wrap_element){return $(this).each(function(i,collection){var collection_elements=$(collection).children(child_selector),group_elements=[];collection_elements.each(function(j,element){var count=j+1;group_elements.push(element);if(count%elements_per_group===0||count===collection_elements.length){$(group_elements).wrapAll($(wrap_element));group_elements=[];};})})}
$.fn.submitWithAjax=function(){this.submit(function(){$.post(this.action,$(this).serialize(),null,"script");return false;});return this;};$.fn.expandText=function(){this.expander({slicePoint:200,expandText:"(all)",userCollapseText:"(collapse)"});return this;};$.fn.loadModal=function(){return this.live('click',function(evnt){var link=$(this),url=link.attr('href'),title=link.attr('title')?link.attr('title'):link.html(),modal_selector='#modal',modal=($(modal_selector).length>0)?$(modal_selector):$j('<div id="modal"/>').appendTo('body')
modal_width=link.attr('data-modal-width')?parseInt(link.attr('data-modal-width')):600
if(link.parents('#modal').length==0){modal.dialog('destroy').dialog({width:modal_width,autoOpen:false,modal:true,resizable:false});};link.addClass('disabled spinner');$.get(url,function(data){var data=$(data)
modal.html(data).dialog('option','title',title).dialog('open');$j('input[type=text], textarea, select',modal).not(':disabled').each(function(idx,elt){if(idx==0){elt.focus()};})
link.removeClass('disabled spinner');});return false;});};$.fn.modalForm=function(options){$j('input[type=submit],button',this).live('click',function(){var button=$(this),form=button.closest('form'),field_data=form.serialize(),buttons=$j('input[type=submit],button',form),action=form.attr('action'),method=form.attr('method'),modal=$j('#modal')
buttons.attr('disabled','disabled').addClass('disabled');button.addClass('spinner');field_data+='&submit_state='+button.attr('name');$.ajax({url:action,type:method,dataType:'json',data:field_data,success:function(response){if($.isFunction(options[response.status])){options[response.status](modal,response)};},complete:function(){if($.isFunction(options['complete'])){options['complete'](modal)};buttons.removeAttr('disabled').removeClass('disabled spinner')
setTimeout(function(){$j('.flash',modal).fadeOut('slow')},3000)}});return false;});return this;};$.fn.inlineDelete=function(options){return this.live('click',function(){var link=$(this),href=$(this).attr('href'),prompt=(link.attr('title'))?link.attr('title')+"\n\n":''
if(link.hasClass('spinner')){return false};link.addClass('spinner');if(options.skip_confirm||confirm(prompt+"Are you sure?")){$.ajax({url:href,type:'delete',dataType:'json',success:function(response){if($.isFunction(options[response.status])){options[response.status](link,response)};},complete:function(){link.removeClass('spinner')}});}
return false;});}
$.fn.powerDropdown=function(){var dropdowns=$(this),powerDropdown_class='powerDropdown',active_class='expanded'
hide_all_dropdowns=function(){$j('.'+powerDropdown_class).removeClass(active_class);},is_powerDropdown=function(candidate){return candidate.hasClass(powerDropdown_class);},is_active=function(candidate){return candidate.hasClass(active_class);}
dropdowns.addClass(powerDropdown_class).click(function(){var dropdown=$(this)
if(!is_active(dropdown)){hide_all_dropdowns()};dropdown.toggleClass(active_class);})
$(document).click(function(e){if(!is_powerDropdown($(e.target).parents())){hide_all_dropdowns()};})
return this;}
$.fn.toggleInvoiceCategoryDisplay=function(){var checkbox=$(this),controls=$j('.line_item_controls','#invoice-amount'),cookie_name='show_'+checkbox.attr('class')+'_categories'
var cookieize_setting=function(){setting=(checkbox.is(':checked'))?'checked':'not_checked';$.cookie(cookie_name,setting);},toggle_controls=function(){controls.toggle(checkbox.is(':checked'));}
checkbox.click(function(){cookieize_setting();toggle_controls();});return this;};$.fn.zebraStripes=function(){return this.find('tbody tr').each(function(index){$(this).removeClass('odd even');$(this).addClass(index%2===0?'odd':'even');});}
$.fn.loadTab=function(target_selector){return this.live('click',function(e){var link=$(e.target).closest('a'),url=link.attr('href'),tab=link.closest('li'),tabs=tab.siblings('li'),tab_target=target_selector?$(target_selector):$j('#tab_content')
tabs.removeClass('active');tab.addClass('active');tab_target.html('<h1 class="loading">Loading</h1>').load(url+'.js');e.preventDefault();return false;});}})(jQuery);$j(function(){$j('a[rel=modal]').loadModal(600);$j('#modal a.cancel').live('click',function(){$j('#modal').dialog('close');return false;});$j('#modal form.income_category').modalForm({success:function(modal,response){var target='income_categories_list'
if($j('#'+target).length>0){$j('#'+target).replaceWith(response.html['list']);}
else{$j('#sub_tabs a.'+target).trigger('click');}
modal.dialog('close');},add_another:function(modal,response){$j('#income_categories_list').replaceWith(response.html['list']);modal.html(response.html['new']);},error:function(modal,response){modal_content=response.html['new']?response.html['new']:response.html['edit']
modal.html(modal_content);}});$j('#modal form.admin_expenses_category').modalForm({success:function(modal,response){var target='admin_expenses_categories_list'
if($j('#'+target).length>0){$j('#'+target).replaceWith(response.html['list']);}
else{$j('#sub_tabs a.'+target).trigger('click');}
modal.dialog('close');},add_another:function(modal,response){$j('#admin_expenses_categories_list').replaceWith(response.html['list']);modal.html(response.html['new']);},error:function(modal,response){modal_content=response.html['new']?response.html['new']:response.html['edit']
modal.html(modal_content);}});$j('#modal form.cost_of_sales_category').modalForm({success:function(modal,response){var target='cost_of_sales_categories_list'
if($j('#'+target).length>0){$j('#'+target).replaceWith(response.html['list']);}
else{$j('#sub_tabs a.'+target).trigger('click');}
modal.dialog('close');},add_another:function(modal,response){$j('#cost_of_sales_categories_list').replaceWith(response.html['list']);modal.html(response.html['new']);},error:function(modal,response){modal_content=response.html['new']?response.html['new']:response.html['edit']
modal.html(modal_content);}});$j('#modal form.invoice_item').modalForm({success:function(modal,response){var mainContent=response.html['invoice_content'],title_actions=response.html['title_actions']
$j('#mainContent').html(mainContent);$j('ul#title_actions').replaceWith(title_actions);modal.dialog('close');},add_another:function(modal,response){var mainContent=response.html['invoice_content'],title_actions=response.html['title_actions']
$j('#mainContent').html(mainContent);$j('ul#title_actions').html(title_actions);modal.html(response.html['new']);},error:function(modal,response){modal_content=response.html['new']?response.html['new']:response.html['edit']
modal.html(modal_content);}});$j('#modal form.estimate_item').modalForm({success:function(modal,response){var mainContent=response.html['estimate_content'],title_actions=response.html['title_actions']
$j('#mainContent').html(mainContent);$j('ul#title_actions').replaceWith(title_actions);modal.dialog('close');},add_another:function(modal,response){var mainContent=response.html['estimate_content'],title_actions=response.html['title_actions']
$j('#mainContent').html(mainContent);$j('ul#title_actions').html(title_actions);modal.html(response.html['new']);},error:function(modal,response){modal_content=response.html['new']?response.html['new']:response.html['edit']
modal.html(modal_content);}});$j('#modal form.price_list_item').modalForm({success:function(modal,response){$j('#MainTitle').replaceWith(response.html['main_title']);$j('#mainContent').html(response.html['list']);modal.dialog('close');},add_another:function(modal,response){$j('#MainTitle').replaceWith(response.html['main_title']);$j('#mainContent').html(response.html['list']);modal.html(response.html['new']);},error:function(modal,response){modal_content=response.html['new']?response.html['new']:response.html['edit']
modal.html(modal_content);}});$j('#income_categories_list a[rel=delete]').inlineDelete({skip_confirm:true,success:function(link,response){link.closest('tr').fadeOut(function(){$j('#income_categories_list').replaceWith(response.html['list']);});},error:function(link,response){alert('Could not delete that income category');}});$j('#admin_expenses_categories_list a[rel=delete]').inlineDelete({skip_confirm:true,success:function(link,response){link.closest('tr').fadeOut(function(){$j('#admin_expenses_categories_list').replaceWith(response.html['list']);});},error:function(link,response){alert('Could not delete that admin expenses category');}});$j('#cost_of_sales_categories_list a[rel=delete]').inlineDelete({skip_confirm:true,success:function(link,response){link.closest('tr').fadeOut(function(){$j('#cost_of_sales_categories_list').replaceWith(response.html['list']);});},error:function(link,response){alert('Could not delete that cost_of_sales category');}});$j('#invoice_items a[rel=delete]').inlineDelete({skip_confirm:true,success:function(link,response){link.closest('tr').fadeOut(function(){$j('#mainContent').html(response.html['invoice_content']);$j('ul#title_actions').replaceWith(response.html['title_actions']);});},error:function(link,response){alert('Could not delete that invoice item');}});$j('#estimate_items a[rel=delete]').inlineDelete({skip_confirm:true,success:function(link,response){link.closest('tr').fadeOut(function(){$j('#mainContent').html(response.html['estimate_content']);$j('ul#title_actions').replaceWith(response.html['title_actions']);});},error:function(link,response){alert('Could not delete that estimate item');}});$j('#price_list_items a[rel=delete]').inlineDelete({skip_confirm:true,success:function(link,response){link.closest('tr').fadeOut(function(){$j('#MainTitle').replaceWith(response.html['main_title']);$j('#mainContent').html(response.html['list']);});},error:function(link,response){alert('Could not delete that Price List item');}});$j('#income_categories_list, #admin_expenses_categories_list, #cost_of_sales_categories_list').livequery(function(){$j(this).zebraStripes();});$j(".power_actions").livequery(function(){$j(this).powerDropdown()});$j('#settings-index #mainContent .row .content').groupElements(3,'div.col','<div class="child_row">');$j('#invoice_item_item_type, #estimate_item_item_type').livequery('change',function(){var select=$j(this),line_item_type=select.attr('id')=='estimate_item_item_type'?'estimate':'invoice',item_type=select.val(),default_amount_helper='Enter discounts and credits as negative.',vat_amount_helper='The total sales tax amount',default_price_label='Unit Price',vat_price_label='Total Amount',comment_quantity_value='n/a',default_quantity_value='0'
if(item_type){$j('#'+line_item_type+'_item_time_help').hide();$j('#'+line_item_type+'_item_unitprice').show();$j('#unit_price_label').html(default_price_label);$j('#'+line_item_type+'_item_category_id').closest('p').show();$j('#'+line_item_type+'_item_sales_tax').show();$j('#'+line_item_type+'_item_second_sales_tax').show();$j('#price_list_item').show();$j('#'+line_item_type+'_item_amount_helper_text').html(default_amount_helper);switch(item_type){case'Comment':$j('#'+line_item_type+'_item_quantity').val(comment_quantity_value);$j('#'+line_item_type+'_item_unitprice').hide();$j('#'+line_item_type+'_item_category_id').closest('p').hide();$j('#'+line_item_type+'_item_sales_tax').hide();$j('#'+line_item_type+'_item_second_sales_tax').hide();$j('#'+line_item_type+'_item_price_list').removeAttr('checked');$j('#price_list_item').hide();$j('#price_list_code').hide();break;case'VAT':$j('#'+line_item_type+'_item_amount_helper_text').html(vat_amount_helper);$j('#unit_price_label').html(vat_price_label);$j('#'+line_item_type+'_item_category_id').closest('p').hide();$j('#'+line_item_type+'_item_sales_tax').hide();$j('#'+line_item_type+'_item_price_list').removeAttr('checked');$j('#price_list_item').hide();$j('#price_list_code').hide();break;case'Hours':$j('#'+line_item_type+'_item_time_help').show();break;case'Discount':$j('#price_list_item').hide();$j('#price_list_code').hide();$j('#'+line_item_type+'_item_price_list').removeAttr('checked');break;case'Credit':$j('#price_list_item').hide();$j('#price_list_code').hide();$j('#'+line_item_type+'_item_price_list').removeAttr('checked');break;default:var a=$j('#'+line_item_type+'_item_quantity').val().split(':');if(a.length>1){$j('#'+line_item_type+'_item_quantity').val(a[0]);}
if($j('#'+line_item_type+'_item_quantity').val()==comment_quantity_value){$j('#'+line_item_type+'_item_quantity').val(default_quantity_value);}
break;}}}).livequery(function(){$j(this).trigger('change');});$j('#invoice_item_price_list, #estimate_item_price_list').live('click',function(){if($j(this).attr('checked')){$j('#price_list_code').show();}
else{$j('#price_list_code').hide();}});$j('#preview_categories').livequery(function(){$j(this).toggleInvoiceCategoryDisplay()});$j('.power_actions li a.category','#invoice-amount').livequery('click',function(){var link=$j(this),url=link.attr('href'),category_id=link.attr('data-id'),line_item_type=link.closest('tr').attr('data-model')
if(category_id&&line_item_type){link.addClass('spinner');data={}
data[line_item_type+'[category_id]']=category_id
jQuery.ajax({'url':url,'type':'put','dataType':'json','data':data,success:function(response){switch(response.status){case'success':var response_partial=(line_item_type=='invoice_item')?'invoice_content':'estimate_content',mainContent=response.html[response_partial]
$j('#mainContent').html(mainContent);break;}},complete:function(){link.removeClass('spinner')}});return false;};})
$j('.innerinfo input#invoice_send_reminder_emails').live('click',function(event){jQuery.ajax({url:'/invoices/'+$j(this).attr('data-invoice-id')+'/toggle_reminder_emails',type:'post',dataType:'script',data:{'_method':'put'}});});$j('.innerinfo input#invoice_send_thank_you_emails').live('click',function(event){jQuery.ajax({url:'/invoices/'+$j(this).attr('data-invoice-id')+'/toggle_thank_you_emails',type:'post',dataType:'script',data:{'_method':'put'}});});$j('#reorder_invoice_items').live('click',function(e){var item_type=$j('body#estimates-show').length?'estimate':'invoice',reorder_button=$j(this),button_text=reorder_button.html(),add_button=$j('#add_invoice_item'),invoice_items=$j('#'+item_type+'_items'),invoice_table=$j('table#invoice-amount'),display_categories=$j('#preview_categories').attr('checked'),things_to_toggle=display_categories?'.item_controls, .line_item_controls':'.item_controls'
if(button_text.match(/I've finished reordering/)){if(item_type=='invoice'){var regex=new RegExp(/\/invoices\/?.*\/(\d+)/);}
else{var regex=new RegExp(/\/estimates\/?.*\/(\d+)/);}
var invoice_id=regex.exec(window.location)[1],new_order=invoice_items.sortable('serialize'),uurl='/'+item_type+'s/'+invoice_id+'/update_item_position'+'?'+new_order;$j.post(uurl,'',null,'xml');reorder_button.html('<span><em>Reorder</em></span>');add_button.show();invoice_items.sortable('destroy');invoice_table.find(things_to_toggle).show().end().find('tr.item').removeClass('moving').removeAttr('title').end();}else{reorder_button.html("<span><em>I've finished reordering</em></span>");add_button.hide();invoice_items.sortable({axis:'y',stop:function(){invoice_table.zebraStripes();}});invoice_table.find(things_to_toggle).hide().end().find('tr.item').addClass('moving').attr('title','Drag to Reorder').end();}
return false;});$j('#price_list_item_item_type').livequery('change',function(){var select=$j(this),item_type=select.val()
if(item_type){$j('#price_list_item_time_help').hide();switch(item_type){case'Hours':$j('#price_list_item_time_help').show();break;default:var a=$j('#price_list_item_quantity').val().split(':');if(a.length>1){$j('#price_list_item_quantity').val(a[0]);}
break;}};}).livequery(function(){$j(this).trigger('change');});toggle_depreciation_schedule=function(select){$j('#depreciation_schedule').toggle((select.find('option:selected').html()=="Purchase of Capital Asset"))}
$j('form select#bill_nominal_code, form select#expense_nominal_code').livequery(function(){toggle_depreciation_schedule($j(this))}).livequery('change',function(){toggle_depreciation_schedule($j(this))})
$j('form[enctype=multipart/form-data], form#invoice_form, form#new_vat_submission, form[name=entryform]').live('submit',function(e){$j(this).find('input[type=submit]').attr('disabled','disabled');})
$j('a[rel=tab]').loadTab();$j('#contacts-show #sub_tabs a').loadTab('#contact_content');$j('#projects-show #sub_tabs a').loadTab('#project_content');init_statement_of_account_form=function(){$j('#statement_of_account_dates').submit(function(e){var date_form=$j(this);$j('#statement_of_account_container').html('<h1 class="loading">loading</h1>');$j('#contact_content').load(date_form.attr('action')+'.js',date_form.serialize());e.preventDefault();return false;});}
init_statement_of_account_form();init_notes=function(){$j(".note_form").submitWithAjax();$j("#note_form").submitWithAjax();$j('ol#notes a.delete').live('click',function(event){if(confirm("Are you sure you want to delete this note?")){jQuery.ajax({url:this.href,type:'post',dataType:'script',data:{'_method':'delete'}});}
return false;});$j("ol#notes a.edit").live('click',function(event){id="#note"+this.href.split("/").last();$j(id+" form").toggle();$j(id+" .note_content").toggle();return false;});$j("ol#notes a.cancel").live('click',function(event){id="#note"+this.href.split("/").last();$j(id+" form")[0].reset();$j(id+" form").toggle();$j(id+" .note_content").toggle();return false;});}
init_notes();if($j("body#bank-account-entries-edit")||$j("body#bank-account-entries-new")){$j("select#paid_invoice_id").change(function(){onInvoiceChange($j("select#paid_invoice_id option:selected"),$j("input#credit_amount"));});$j("select#refund_invoice_id").change(function(){onInvoiceChange($j("select#refund_invoice_id option:selected"),$j("input#debit_amount"));});function onInvoiceChange(selectedOptionElement,nativeAmountElement){var nativeCurrency=selectedOptionElement.attr('data-native-currency');var foreignCurrency=selectedOptionElement.attr('data-foreign-currency');var nativeCurrencyValue=selectedOptionElement.attr('data-native-value');var nativeCurrencyFormattedValue=selectedOptionElement.attr('data-native-formatted-value');var foreignCurrencyValue=selectedOptionElement.attr('data-foreign-value');if(foreignCurrency!=nativeCurrency){$j("input#bank_account_entry_foreign_currency_value").attr('disabled',false);$j("label#foreign_currency_value_label > span#foreign_currency_iso_code").html(foreignCurrency);if($j("input#bank_account_entry_id").length==0){$j("input#bank_account_entry_foreign_currency_value").val(foreignCurrencyValue);}
$j("p#credit_value").find("span#manual_mc_credit_info").css('display','block');$j("p#credit_value").find("span#manual_mc_credit_info strong").html(nativeCurrencyFormattedValue);$j("p#forex").show();}else{$j("input#bank_account_entry_foreign_currency_value").attr('disabled',true);$j("p#forex").hide();$j("p#credit_value").find("span#manual_mc_credit_info").hide();}}
$j("select#bank_account_entry_main_type").change(function(){switch($j(this).val()){case'Invoice Receipt':onInvoiceChange($j("select#paid_invoice_id option:selected"),$j("input#credit_amount"));break;case'Credit Note Refund':onInvoiceChange($j("select#paid_invoice_id option:selected"),$j("input#credit_amount"));break;default:$j("p#forex").hide();}}).trigger('change');}
if($j("form#invoice_form").length){$j(function(){function showHideCustomEditLinks(clicked){if($j("input#invoice_send_new_invoice_emails").is(':checked')){$j("span#email_actions").show();if(clicked&&$j("input#invoice_customise_new_invoice_email").val()==='1'){$j("div#email_form").show();}}else{$j("input#invoice_customise_new_invoice_email").val('0');$j("span#email_actions").hide();$j("div#email_form").hide();}}
$j("input#invoice_send_new_invoice_emails").click(function(){showHideCustomEditLinks(true);});$j("a#customise_email_link").click(function(){$j("input#invoice_customise_new_invoice_email").val('1');$j("div#email_form").show();$j("span#new_invoice_email_text").html('Email this invoice automatically using my custom template');$j("a#customise_email_link").hide();$j("a#reset_email_link").show();return false;});$j("a#reset_email_link").click(function(){$j("span#new_invoice_email_text").html('Email this invoice automatically using my default template');$j("input#invoice_customise_new_invoice_email").val('0');$j("div#email_form").hide();$j("span#edit_email").hide();$j("a#reset_email_link").hide();$j("a#customise_email_link").show();return false;});$j("a#edit_email_link").click(function(){if($j("a#edit_email_link").html()==='cancel editing'){$j("div#email_form").hide();$j("a#edit_email_link").html('edit');}else{$j("a#edit_email_link").html('cancel editing');$j("input#invoice_customise_new_invoice_email").val('1');$j("div#email_form").show();}
return false;});showHideCustomEditLinks(false);function update_project(){var project_select=$j("select#invoice_project_id");var contact_select=$j("select#invoice_contact_id");var invoice_id=project_select.attr('data-invoice-id');$j.ajax({url:"/invoices/update_project",type:'post',dataType:'script',data:{invoice_id:invoice_id,project_id:project_select.val(),contact_id:contact_select.val()}});}
$j("select#invoice_project_id").change(update_project);$j("select#invoice_contact_id").change(update_project);$j("select#invoice_currency").change(function(){var native_ccy=$j("select#invoice_currency").attr('data-native-currency');if($j(this).val()!=native_ccy){$j("#add_unbilled_expenses_and_estimates_heading").hide();$j("#add_unbilled_expenses_and_estimates_content").hide();}else{$j("#add_unbilled_expenses_and_estimates_heading").show();$j("#add_unbilled_expenses_and_estimates_content").show();}});});}
$j("ul.sf-menu").superfish({animation:{opacity:'show'},speed:180,delay:400});$j("a#hide_overview_setup").click(function(){$j("#gs_box").fadeOut();createCookie('hide_overview_setup',1,65);});if($j("form#estimate_form").length){function update_project(){var project_select=$j("select#estimate_project_id");var contact_select=$j("select#estimate_contact_id");var estimate_id=project_select.attr('data-estimate-id');$j.ajax({url:"/estimates/update_project",type:'post',dataType:'script',data:{estimate_id:estimate_id,project_id:project_select.val(),contact_id:contact_select.val()}});}
$j("select#estimate_project_id").change(update_project);$j("select#estimate_contact_id").change(update_project);}
$j("#estimate_list a.view_history").click(function(){var showText='(View History)';var hideText='(Hide History)';$j(this).html($j(this).html()==hideText?showText:hideText);$j(this).next('ol').slideToggle(200);return false;});$j("#subscription_period_monthly").click(function(){$j("#subs_info").show();$j("#monthly-details").fadeIn(500);$j("#yearly-details").hide();});$j("#subscription_period_yearly").click(function(){$j("#subs_info").show();$j("#monthly-details").hide();$j("#yearly-details").fadeIn(500);});$j(".toolbar_dropdown dt a").click(function(e){$j(this).parents('dl').children('dd').children('ul').toggle();e.preventDefault();});$j(".toolbar_dropdown").find("dd").find("ul").find("li").find("a").click(function(){$j(".toolbar_dropdown").find("dd").find("ul").hide();});$j(document).bind('click',function(e){var jQueryclicked=$j(e.target);if(!jQueryclicked.parents().hasClass("toolbar_dropdown")){$j(".toolbar_dropdown dd ul").hide();}});$j("#add_price_list dt a").live('click',function(e){$j("#add_price_list dd ul").toggle();e.preventDefault();});$j("#add_price_list dd ul li a").live('click',function(){$j("#add_price_list dd ul").hide();});$j(document).bind('click',function(e){var jQueryclicked=$j(e.target);if(!jQueryclicked.parents().hasClass("price_dropdown")){$j("#add_price_list dd ul").hide();}});$j("a#toggle-status-dropdown").live('click',function(e){$j(".status_nav ul").toggle();return false;});$j(document).bind('click',function(e){var jQueryclicked=$j(e.target);if(!jQueryclicked.parents().hasClass("showhide")){$j(".status_nav ul").hide();}});$j(".dropdown dt a").livequery('click',function(e){$j(".dropdown dd ul").toggle();e.preventDefault();});$j(".dropdown").find("dd").find("ul").find("li").find("a").click(function(){$j(".dropdown").find("dd").find("ul").hide();});$j(document).bind('click',function(e){var jQueryclicked=$j(e.target);if(!jQueryclicked.parents().hasClass("dropdown")){$j(".dropdown dd ul").hide();}});if($j("body#projects-show").length){$j("a#toggle-project-status").live('click',function(e){$j("#project_status ul").hide();if($j("a#toggle-status-dropdown").html()==='Active'){$j("a#toggle-status-dropdown").addClass('completed').removeClass('active').html('Completed');$j("a#toggle-project-status").html('Mark as Active').removeClass('tick-off').addClass('tick-on');}else{$j("a#toggle-status-dropdown").removeClass('completed').addClass('active').html('Active');$j("a#toggle-project-status").html('Mark as Completed').removeClass('tick-on').addClass('tick-off');}
$j.ajax({url:'/projects/'+$j("input#project_id").val()+'/toggle_status',type:'post',dataType:'script',data:{'_method':'put'}});return false;});$j(document).bind('click',function(e){var jQueryclicked=$j(e.target);if(!jQueryclicked.parents().hasClass("showhide")){$j("#project_status ul").hide();}});$j("input#project_include_unbilled_time_in_profitability").live('click',function(e){var checkbox=$j(this),project_id=checkbox.attr('data-project-id');$j.ajax({url:'/projects/'+project_id+'/toggle_unbilled_time_in_profitability',type:'post',dataType:'script',data:{'_method':'put'},beforeSend:function(){$j("input#project_include_unbilled_time_in_profitability").attr('disabled','disabled').hide().parent().addClass('progressing');},complete:function(){$j("input#project_include_unbilled_time_in_profitability").removeAttr('disabled').show().parent().removeClass('progressing');},error:function(){alert('Could not update the project preferences');checkbox=$j("input#project_include_unbilled_time_in_profitability")
checkbox.attr('checked')?checkbox.removeAttr('checked'):checkbox.attr('checked','checked');}});});}
$j("select#email_template_before_after").change(onRefreshReminderForm);$j("input#email_template_add_optional_reminder").click(onRefreshReminderForm);$j('table#reminders').find('a.delete_template').live('click',function(event){if(confirm("Are you sure you want to delete this reminder?")){jQuery.ajax({url:this.href,type:'post',dataType:'script',data:{'_method':'delete'}});}
return false;});$j('table#reminders').find('input.toggle').live('click',function(event){jQuery.ajax({url:'/email_templates/'+this.id.gsub('toggle_reminder_','')+'/toggle_reminder',type:'post',dataType:'script',data:{'_method':'put'}});});if($j("body#vat-returns-show").length){$j("p#load_vat_transactions a").click(function(){$j(this).parent().hide();$j("p#vat_transactions_loading_graphic").show();$j("div#vat_transactions").show();$j.ajax({url:this.href,type:'post',dataType:'script',data:''});return false;});}
$j("select#vat_return_selector").change(function(){document.location.href='/tax/vat_returns/'+$j(this).val();});$j('img.tooltip, table.flexi-table td .tooltip, table.extra td .tooltip, li span.box_amount .tooltip').livequery(function(){$j(this).cluetip({splitTitle:'|',dropShadow:false,showtitle:false,arrows:true,leftOffset:20})});$j('input[placeholder]').livequery(function(){$j(this).placeHoldize();});$j('textarea.autogrow').livequery(function(){$j(this).elastic();})
match_rebill_label_to_expense_type=function(){var expense_type=$j('input#expense_expense_type').val();if(expense_type=='Mileage'){return true;}
var label=($j('select#expense_main_type').val()=='Refund')?'Refund':'Re-bill';$j('label[for=expense_rebill_type]').html(label+' this Expense?');}
display_rebill_inputs_as_required=function(){var rebill_inputs=$j('p#rebill_inputs');var project_id=$j('select#expense_project_id, select#bill_project_id, select#bank_account_entry_project_id').val();if(project_id==''){rebill_inputs.hide();reset_rebill_type_select();reset_rebill_factor_input();display_rebill_value_inputs_as_required();}
else{rebill_inputs.show();}}
display_rebill_value_inputs_as_required=function(){var rebill_value_inputs=$j('span#rebill_value_input');var rebill_type=$j('select#expense_rebill_type, select#bill_rebill_type, select#bank_account_entry_rebill_type').val();var expense_type=$j('input#expense_expense_type').val();if(rebill_type==''||(rebill_type=='cost'&&expense_type!='Mileage')){rebill_value_inputs.hide();}
else{rebill_value_inputs.show();rebill_value_inputs.find('span.unit').remove();var rebill_factor_input=rebill_value_inputs.find('input#expense_rebill_factor, input#bill_rebill_factor, input#bank_account_entry_rebill_factor');if(rebill_type=='price'){var currency_unit=$j('input#expense_rebill_currency, input#bill_rebill_currency, input#bank_account_entry_rebill_currency').attr('data-rebill-currency-unit')
rebill_factor_input.before('<span class="unit">'+currency_unit+'</span>');}
else if(rebill_type=='markup'){rebill_factor_input.after('<span class="unit">%</span>');}}}
reset_rebill_factor_input=function(){$j('input#expense_rebill_factor, input#bill_rebill_factor, input#bank_account_entry_rebill_factor').val('0.00');}
reset_rebill_type_select=function(){$j('select#expense_rebill_type, select#bill_rebill_type, select#bank_account_entry_rebill_type').val('');}
match_rebill_label_to_expense_type();$j('select#expense_main_type').change(function(){match_rebill_label_to_expense_type();});display_rebill_inputs_as_required();$j('select#expense_project_id, select#bill_project_id, select#bank_account_entry_project_id').change(function(){display_rebill_inputs_as_required();});display_rebill_value_inputs_as_required();$j('select#expense_rebill_type, select#bill_rebill_type, select#bank_account_entry_rebill_type').change(function(){display_rebill_value_inputs_as_required();reset_rebill_factor_input();});$j('.theme_confirm').live('click',function(event){return confirm("Resetting the template will remove all your custom CSS, and there's no way to get this back. Are you sure you want to reset?");});$j().ajaxStop(function(){$j('.spinner').removeClass('spinner');$j('.loading').hide();});$j('#task_dialog').dialog({autoOpen:false,width:600,modal:true,resizable:false});$j('.close_task').live('click',function(e){$j('#task_dialog').dialog('close');return false;});$j('#create_button').live('click',function(e){$j('#another').attr('value','false');});$j('#create_another_button').live('click',function(e){$j('#another').attr('value','true');});$j('#task_dialog input[type=submit]').live('click',function(e){$j('#task_dialog .submitarea').hide();$j('#task_dialog .loading').show();$j('#task_reload').attr('value',!$j('#tasks_tab').hasClass('active'));});$j('#tasks_list a.datadelete').live('click',function(e){if(confirm("Are you sure you want to delete this task?")){$j(this).addClass("spinner");jQuery.ajax({url:this.href,type:'post',dataType:'script',data:{'_method':'delete'}});}
return false;});$j('#task_dialog').live('dialogclose',function(e){if($j('#timeslip_task_id')){$j('#timeslip_task_id').val('');}});$j('#invoices_list a.datadelete').live('click',function(e){if(confirm("Are you sure you want to delete this invoice?")){$j(this).addClass("spinner");jQuery.ajax({url:this.href,type:'post',dataType:'script',data:{'_method':'delete'}});}
return false;});$j('#projects_list a.datadelete').live('click',function(e){if(confirm("Are you sure you want to delete this project?")){$j(this).addClass("spinner");jQuery.ajax({url:this.href,type:'post',dataType:'script',data:{'_method':'delete'}});}
return false;});$j('#timeslips-time-tracking a.datadelete, #timesliplist a.datadelete').live('click',function(e){if(confirm("Are you sure you want to delete this timeslip?")){$j(this).addClass("spinner");jQuery.ajax({url:this.href,type:'post',dataType:'script',data:{'_method':'delete'}});}
return false;});$j('#invoice_gallery li a.dialog').click(function(e){var el=$j(this);var href_parts=el.attr('href').split('#');if(href_parts.length>1){$j('#caption_'+href_parts[1]).dialog('open');e.preventDefault();}});$j('#attachment_image a.expense_preview').click(function(e){if($j('#attachment_preview')){$j('#attachment_preview').dialog('open');e.preventDefault();}});$j('#additional_text_dialog form').submitWithAjax();$j('#additional_text_action a').click(function(e){$j('#additional_text_dialog').dialog('open');e.preventDefault();});$j('#additional_text_close').click(function(e){$j('#additional_text_dialog').dialog('close');e.preventDefault();});$j('.gallery_preview').dialog({autoOpen:false,width:442,modal:true,resizable:false});$j('#attachment_preview').dialog({autoOpen:false,width:'auto',modal:true,resizable:false});$j('#info-popup-content').dialog({autoOpen:false,width:440,minHeight:30,modal:true,resizable:false});$j('#additional_text_dialog').dialog({autoOpen:false,width:500,modal:true,resizable:false});$j('.invoice_items_dialog').dialog({autoOpen:false,width:600,modal:true,resizable:false});$j("#info-popup-open").click(function(){$j("#info-popup-content").dialog('open')});$j('.category a').click(function(event){$j(this).parents('tbody').next('tbody').toggle();$j(this).parents('tr').toggleClass('collapsed');event.preventDefault();});if($j('body#users-index').length){$j('a#toggle_support_access').click(function(){var status=$j("p#support_access strong");var status_button=$j("p#support_access a#toggle_support_access");if(status.html()==='ENABLED'){status.html('DISABLED');status_button.html('Enable access');}else{status.html('ENABLED');status_button.html('Disable access');}
$j.ajax({url:'/settings/toggle_support_access',type:'post',dataType:'script',data:{'_method':'put'}});return false;});}
$j('a.ajaxget-spinner').live('click',function(e){$j(this).addClass("spinner");jQuery.get(this.href,null,null,"script");return false});$j('a.ajaxget').live('click',function(e){jQuery.get(this.href,null,null,"script");return false;});$j('#refund').live('click',function(e){$j('#refund_dialog').dialog('open');return false;});$j('.close_refund').live('click',function(e){$j('#refund_dialog').dialog('close');return false;});$j("a.contact_inactive").live('click',function(e){if($j(this).hasClass('confirm'))
if(!confirm("Marking this contact as inactive will also mark active projects as inactive. Do you want to continue ?")){$j('.status_nav ul').hide();return false;}});$j("a.put_link").live('click',function(e){jQuery.ajax({url:this.href,type:'post',dataType:'script',data:{'_method':'put','status':this.title}});return false;});});function getBrowserWidth(){if(window.innerWidth){return window.innerWidth;}
else if(document.documentElement&&document.documentElement.clientWidth!==0){return document.documentElement.clientWidth;}
else if(document.body){return document.body.clientWidth;}
return 0;}
function dynamicLayout(){var cards=$j('#contact_cards li.c_card');var paddingPerCard=40;var minWidth=325;var viewportWidth=getBrowserWidth()-240;var nRows=parseInt(viewportWidth/minWidth,10);actualWidth=viewportWidth/nRows-paddingPerCard;for(i=0;i<cards.length;i++){cards[i].style.clear='none';cards[i].style.marginRight='20px';cards[i].style.width=actualWidth+"px";if(i>0&&i%nRows===0){cards[i].style.clear='both';}
if((i+1)%nRows===0){cards[i].style.marginRight='0';}}}
function addEvent(obj,type,fn){if(obj.addEventListener){obj.addEventListener(type,fn,false);}
else if(obj.attachEvent){obj["e"+type+fn]=fn;obj[type+fn]=function(){obj["e"+type+fn](window.event);};obj.attachEvent("on"+type,obj[type+fn]);}}
addEvent(window,'load',dynamicLayout);addEvent(window,'resize',dynamicLayout);function showBankAccounts(){var account_type=document.getElementById("account_type");if(account_type){$j('account_type').onchange=function(){var opt_val=account_type.value;switch(opt_val){case'bacc':$j('bank_accounts_form').show();$j('cc_form').hide();$j('pp_form').hide();break;case'ccacc':$j('cc_form').show();$j('bank_accounts_form').hide();$j('pp_form').hide();break;case'ppacc':$j('pp_form').show();$j('bank_accounts_form').hide();$j('cc_form').hide();break;}};}}
function invoiceGallery(){if($j('switch_link')){$j('switch_link').onclick=function(){Effect.toggle(('drop_content'),'blind',{duration:0.2});return false;};}
if($j('switch_link2')){$j('switch_link2').onclick=function(){Effect.toggle(('drop_content'),'blind',{duration:0.2});return false;};}}
function contactCards(){if($j('contact_cards')){var show_proj_links=$j('.show_proj_link');for(i=0;i<show_proj_links.length;i++){show_proj_links[i].onclick=function(){this.toggleClassName('up');var parent_tab=this.up('table');Effect.toggle(parent_tab.down('tbody'),'blind',{duration:0.2});return false;};}}}
function selectSubTab(tab){var subTabs=$j('sub_tabs');if(subTabs){Element.childElements(subTabs).each(function(s,index){if(s.id==tab.id){s.addClassName('active');$(s.id+'_content').show();}else{s.removeClassName('active');$(s.id+'_content').hide();}});}}
function advancedOptions(){var options_tag=document.getElementById("options_toggle");if(options_tag){$j('options_toggle').onclick=function(){Effect.toggle(('advanced_options'),'blind',{duration:0.1});$j('options_toggle').className=($j('options_toggle').className=='up')?'down':'up';};}}
function setExternalLinks(){if(!document.getElementsByTagName){return null;}
var anchors=document.getElementsByTagName("a");for(var i=0;i<anchors.length;i++){var anchor=anchors[i];if(anchor.getAttribute("href")&&anchor.className=="external-link"){anchor.setAttribute("target","_blank");}}}
function addLoadEvent(func)
{var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){oldonload();func();};}}
function hideNonJS(){var elems=document.getElementsByTagName("*");for(var z=0;z<elems.length;z++){if(elems[z].className=="hide_non_js"){elems[z].style.display="none";}}}
function Help(){if(readCookie('fac_help')=='true'){$j('helpcontent').show();}
if($j('helplink')){$j('helplink').onclick=function(){Effect.toggle(('helpcontent'),'blind',{duration:0.3});if(readCookie('fac_help')=='true'){eraseCookie('fac_help');}else{createCookie('fac_help',true,60);}
return false;};}}
function pad(s){s=s||'.';return(s.length>2)?s:pad(s+'0');}
function two_DP(value){value=value.replace(/,/,'');return isNaN(value)?value:(""+(Math.round(value*100)/100)).replace(/(\.\d*)?$/,pad);}
function two_dp(item){if(item!==null){item.value=two_DP(item.value);}}
function display_estimate_item_time_help(){var el=$j('#estimate_item_item_type').val();if(el){if(el=='Comment'){$j('#estimate_item_quantity').val('n/a');$j('#estimate_item_unitprice').hide();$j('#estimate_item_sales_tax').hide();$j('#estimate_item_second_sales_tax').hide();$j('#estimate_item_category_id').closest('p').hide();$j('#price_list_item').hide();$j('#estimate_item_price_list').removeAttr('checked');$j('#price_list_code').hide();}else{if($j('#estimate_item_quantity').val()=='n/a'){$j('#estimate_item_quantity').val('0');}
$j('#estimate_item_category_id').closest('p').show();$j('#estimate_item_unitprice').show();$j('#estimate_item_sales_tax').show();$j('#estimate_item_second_sales_tax').show();$j('#price_list_item').show();}
if(el=='Hours'){$j('#estimate_item_time_help').show();}else{$j('#estimate_item_time_help').hide();var a=$j('#estimate_item_quantity').val().split(':');if(a.length>1){$j('#estimate_item_quantity').val(a[0]);}}}}
function hide_all_fields(){$j('user_payment').hide();$j('user_payment_type').disabled=true;$j('payment').hide();$j('sale').hide();$j('credit_value').hide();$j('debit_value').hide();$j('purchase_sales_tax_field').hide();$j('receipt_sales_tax_field').hide();if($j('purchase_sales_tax_rate')){$j('purchase_sales_tax_rate').disabled=true;}
if($j('receipt_sales_tax_rate')){$j('receipt_sales_tax_rate').disabled=true;}
if($j('ec_status_options')){$j('ec_status_options').hide();}
$j('payment_references').hide();$j('credit_amount').disabled=true;$j('debit_amount').disabled=true;$j('other_payment_type').disabled=true;$j('transfer_out_type').disabled=true;$j('transfer_in').hide();$j('transfer_out').hide();$j('user_receipt').hide();$j('invoice_receipt').hide();$j('credit_note_refund').hide();$j('other_receipt').hide();$j('other_money_out').hide();$j('description').hide();$j('depreciation_schedule').hide();$j('invoice_entry_type').disabled=true;$j('credit_note_entry_type').disabled=true;$j('purchase_of_capital_asset_entry_type').disabled=true;$j('disposal_of_capital_asset_entry_type').disabled=true;$j('subscription_income_entry_type').disabled=true;$j('advertising_income_entry_type').disabled=true;$j('other_sales_income_entry_type').disabled=true;$j('paid_invoice_id').disabled=true;$j('refund_invoice_id').disabled=true;$j('user_receipt_type').disabled=true;$j('other_receipt_type').disabled=true;$j('income_payment_type').disabled=true;$j('other_money_out_type').disabled=true;$j('transfer_in_type').disabled=true;$j('received_user_id').disabled=true;$j('paid_user_id').disabled=true;if($j('transfer_to_bank_account_id')){$j('transfer_to_bank_account_id').disabled=true;}
if($j('transfer_from_bank_account_id')){$j('transfer_from_bank_account_id').disabled=true;}
$j('depreciation_schedule_select').disabled=true;$j('bill_payment').hide();$j('bill_refund').hide();$j('paid_bill_id').disabled=true;$j('refunded_bill_id').disabled=true;$j('bill_payment_entry_type').disabled=true;$j('bill_refund_entry_type').disabled=true;}
function set_entry_fields(){hide_all_fields();two_dp($j('debit_amount'));two_dp($j('credit_amount'));switch($F('bank_account_entry_main_type')){case'Payment':case'Refund':$j('payment').show();$j('debit_value').show();$j('purchase_sales_tax_field').show();$j('payment_references').show();$j('other_payment_type').disabled=false;$j('description').show();if($j('purchase_sales_tax_rate')){$j('purchase_sales_tax_rate').disabled=false;}
if($j('ec_status_options')){$j('ec_status_options').show();}
$j('debit_amount').disabled=false;break;case'Money Paid to User':$j('debit_value').show();$j('user_payment').show();$j('user_payment_type').disabled=false;$j('debit_amount').disabled=false;$j('paid_user_id').disabled=false;break;case'Transfer to Another Account':$j('debit_value').show();$j('transfer_out').show();$j('transfer_out_type').disabled=false;$j('debit_amount').disabled=false;$j('transfer_to_bank_account_id').disabled=false;break;case'Credit Note Refund':$j('debit_value').show();$j('credit_note_refund').show();$j('credit_note_entry_type').disabled=false;$j('debit_amount').disabled=false;$j('refund_invoice_id').disabled=false;break;case'Purchase of Capital Asset':$j('debit_value').show();$j('purchase_sales_tax_field').show();$j('description').show();$j('purchase_of_capital_asset_entry_type').disabled=false;$j('depreciation_schedule').show();$j('depreciation_schedule_select').disabled=false;$j('debit_amount').disabled=false;if($j('purchase_sales_tax_rate')){$j('purchase_sales_tax_rate').disabled=false;}
if($j('ec_status_options')){$j('ec_status_options').show();}
break;case'Other Money Out':$j('debit_value').show();$j('purchase_sales_tax_field').show();$j('other_money_out').show();$j('description').show();$j('debit_amount').disabled=false;$j('other_money_out_type').disabled=false;if($j('purchase_sales_tax_rate')){$j('purchase_sales_tax_rate').disabled=false;}
break;case'Invoice Receipt':$j('credit_value').show();$j('invoice_receipt').show();$j('invoice_entry_type').disabled=false;$j('credit_amount').disabled=false;$j('paid_invoice_id').disabled=false;break;case'Money Received from User':$j('credit_value').show();$j('user_receipt').show();$j('user_receipt_type').disabled=false;$j('received_user_id').disabled=false;$j('credit_amount').disabled=false;break;case'Transfer from Another Account':$j('credit_value').show();$j('transfer_in').show();$j('transfer_in_type').disabled=false;$j('credit_amount').disabled=false;$j('transfer_from_bank_account_id').disabled=false;break;case'Sales':$j('sale').show();$j('credit_value').show();$j('receipt_sales_tax_field').show();$j('description').show();$j('income_payment_type').disabled=false;$j('credit_amount').disabled=false;if($j('receipt_sales_tax_rate')){$j('receipt_sales_tax_rate').disabled=false;}
if($j('ec_status_options')){$j('ec_status_options').show();}
break;case'Disposal of Capital Asset':$j('credit_value').show();$j('description').show();$j('disposal_of_capital_asset_entry_type').disabled=false;$j('credit_amount').disabled=false;if($j('ec_status_options')){$j('ec_status_options').show();}
break;case'Other Money In':$j('credit_value').show();$j('other_receipt').show();$j('other_receipt_type').disabled=false;$j('description').show();$j('credit_amount').disabled=false;break;case'Bill Payment':$j('bill_payment').show();$j('paid_bill_id').disabled=false;$j('bill_payment_entry_type').disabled=false;$j('credit_value').show();$j('credit_amount').disabled=false;break;case'Bill Refund':$j('bill_refund').show();$j('refunded_bill_id').disabled=false;$j('bill_refund_entry_type').disabled=false;$j('credit_value').show();$j('credit_amount').disabled=false;break;}
if($F('is_locked')=="true"){$j('credit_amount').disabled=true;$j('debit_amount').disabled=true;$j('paid_invoice_id').disabled=true;$j('refund_invoice_id').disabled=true;if($j('purchase_sales_tax_rate')){$j('purchase_sales_tax_rate').disabled=true;}
if($j('receipt_sales_tax_rate')){$j('receipt_sales_tax_rate').disabled=true;}
$j('paid_bill_id').disabled=true;$j('refunded_bill_id').disabled=true;$j('paid_invoice_id').disabled=true;$j('refund_invoice_id').disabled=true;$j('bank_account_entry_project_id').disabled=true;$j('bank_account_entry_rebill_type').disabled=true;$j('bank_account_entry_rebill_factor').disabled=true;}
if($j('bank_account_entry_main_type').disabled){if($j('transfer_to_bank_account_id')){$j('transfer_to_bank_account_id').disabled=true;}
if($j('transfer_from_bank_account_id')){$j('transfer_from_bank_account_id').disabled=true;}}}
function showHideVatRegistrationDetails(){if($j('company_sales_tax_registration_status').value=='Not Registered'){$j('registration_number').hide();$j('registration_effective_date').hide();$j('deregistration_effective_date').hide();$j('effective_date_info').hide();$j('registration_initial_details').hide();}else if($j('company_sales_tax_registration_status').value=='Registration Applied For'){$j('registration_number').hide();$j('registration_effective_date').show();$j('deregistration_effective_date').hide();$j('effective_date_info').show();$j('registration_initial_details').hide();}else if($j('company_sales_tax_registration_status').value=='De-registered'){$j('effective_date_info').hide();$j('registration_effective_date').show();$j('deregistration_effective_date').show();$j('registration_number').show();$j('registration_initial_details').show();}else{$j('effective_date_info').hide();$j('registration_effective_date').show();$j('deregistration_effective_date').hide();$j('registration_number').show();$j('registration_initial_details').show();}}
function showHideSalesTaxRegistrationDetails(){if($j('company_sales_tax_registration_status').value=='Not Registered'){$j('sales_tax_settings').hide();}else{$j('sales_tax_settings').show();}}
function disableVatRegistrationDetails(){$j('company_vat_registration_number').disabled=true;$j('company_vat_registration_effective_date').disabled=true;$j('company_vat_first_return_period_ends_on').disabled=true;$j('company_initial_vat_frs_type_index').disabled=true;$j('company_initial_vat_basis').disabled=true;}
function disableVatDeregistrationDetails(){disableVatRegistrationDetails();$j('company_sales_tax_registration_status').disabled=true;$j('company_vat_deregistration_effective_date').disabled=true;$j('company_ec_vat_reporting_enabled').disabled=true;}
function showHideCompanyRegFields(){if($j('company_type').value=='Universal'){$j('company_registration_number').show();$j('company_registration_mandatory').hide();}else if($j('company_type').value=='UK Limited Company'||$j('company_type').value=='UK Limited Liability Partnership'){$j('company_registration_number').show();$j('company_registration_mandatory').show();}else{$j('company_registration_number').hide();$j('company_registration_mandatory').hide();}}
function toggleElementDisplayUsingCheckbox(checkbox_id,element_id){$(element_id).style.display=$(checkbox_id).checked?'block':'none';}
function hideVatReclaimOnMileage(){$j('reclaim_car').hide();$j('reclaim_motorcycle').hide();$j('reclaim_bicycle').hide();if($j('expense_vehicle_type').value=='Bicycle'){$j('vat_reclaim').hide();$j('reclaim_bicycle').show();}else if($j('expense_vehicle_type').value=='Motorcycle'){$j('vat_reclaim').show();$j('reclaim_motorcycle').show();$j('car_engine_details').hide();}else{$j('vat_reclaim').show();$j('car_engine_details').show();$j('reclaim_car').show();}}
function hideRebillMileageRate(){if($j('expense_rebill_to_project_id').value===""){$j('rebill_mileage_rate').hide();}else{$j('rebill_mileage_rate').show();}}
function selectReclaimMileageRateInfoText(){if($j('expense_rebill_to_project_id').value===""){$j('rebill_mileage_rate').hide();}else{$j('rebill_mileage_rate').show();}}
function hideDepreciationSchedule(){if($F('expense_expense_type')=="Purchase of Capital Asset"){$j('depreciation_schedule').show();}else{$j('depreciation_schedule').hide();}}
function hideExpenseSalesTaxAmount(){if($F('expense_sales_tax_rate')=="-3"){$j('manual_sales_tax').show();$j('preset_sales_tax').hide();}else{$j('manual_sales_tax').hide();$j('preset_sales_tax').show();}}
function hideEntrySalesTaxAmount(){if($F('purchase_sales_tax_rate')=="-3"){$j('manual_sales_tax').show();$j('preset_sales_tax').hide();}else{$j('manual_sales_tax').hide();$j('preset_sales_tax').show();}}
function hideBillSalesTaxAmount(){if($F('bill_sales_tax_rate')=="-3"){$j('manual_sales_tax').show();$j('preset_sales_tax').hide();}else{$j('manual_sales_tax').hide();$j('preset_sales_tax').show();}}
function hideUserAndBankAccounts(){if($F('journal_entry_code')=="750"){$j('bank_accounts').show();$j('users').hide();$j('journal_entry_user_id').disabled=true;$j('journal_entry_bank_account_id').disabled=false;}else if($F('journal_entry_code').substring(0,2)=='90'){$j('bank_accounts').hide();$j('users').show();$j('journal_entry_user_id').disabled=false;$j('journal_entry_bank_account_id').disabled=true;}else{$j('bank_accounts').hide();$j('users').hide();$j('journal_entry_user_id').disabled=true;$j('journal_entry_bank_account_id').disabled=true;}}
function hideShowDetailsOnInvoices(){if($j('make_primary').checked===true){$j('show_on_invoices').show();}else{$j('show_on_invoices').hide();}}
function showNewTaskDialog(){if($j('#timeslip_task_id').val()=='new'){$j('#task_dialog').dialog('open');}}
function showHideRecurringEndDate(){if($j("select#recurring").val()){$j('#recurring_end_date').show();}else{$j('#recurring_end_date').hide();if($j('#expense_recurring_end_date')){$j('#expense_recurring_end_date').val('');}
if($j('#bill_recurring_end_date')){$j('#bill_recurring_end_date').val('');}}}
function hideDirectorStartingDate(){if($j('first_payslip_ni_calc_type_employee').checked===true){$j('director_starting_date').hide();}else{$j('director_starting_date').show();}}
function showHideManualPayeNi(){if($j('payslip_manually_enter_paye_ni').checked===true){$j('manual_paye_ni').show();}else{$j('manual_paye_ni').hide();}}
function toggleInlineDisplay(element_id){if($(element_id).style.display=="none"){$(element_id).style.display='inline';}else{$(element_id).style.display='none';}}
function toggleInlinePair(element1_id,element2_id){toggleInlineDisplay(element1_id);toggleInlineDisplay(element2_id);}
function showHideTimeTrackingCustomTimeframe(){if($j('report_timeframe').value=='Custom'){$j('report_custom_timeframe').show();}else{$j('report_custom_timeframe').hide();}}
function timeTrackingReport(){showHideTimeTrackingCustomTimeframe();$j('report_timeframe').onchange=function(){showHideTimeTrackingCustomTimeframe();};}
function rowChange(whichRow){var c=whichRow.className.replace(/hovered/g,'');whichRow.className=c+" hovered";}
function rowChange2(whichRow){whichRow.className=whichRow.className.replace(/hovered/g,'');}
function rowClick(row){var row_links=row.getElementsByTagName("a");if(row_links.length>0){window.location=row_links[0].getAttribute("href");}
var row_radio_buttons=row.getElementsByTagName("input");if(row_radio_buttons.length>0&&row_radio_buttons[0].type=='radio'){row_radio_buttons[0].checked=true;}}
function applyRowHover(row){row.onmouseover=function(){return rowChange(row);};row.onmouseout=function(){return rowChange2(row);};if(row.className!="odd timeslipdetails ajaxrow"){for(var i=0;i<row.cells.length;++i){if(row.cells[i].className.search(/noclick/)==-1){row.cells[i].onclick=function(){return rowClick(row);}}};}}
function tableHover(){var table_rows=document.getElementsByTagName("tr");for(i=0;i<table_rows.length;i++){var titleAttr=table_rows[i].getAttribute("title");var isLocked=/locked/.test(table_rows[i].className);if(titleAttr!==null&&titleAttr.length>0&&!isLocked){applyRowHover(table_rows[i]);}}}
function tableUnhover(){var table_rows=document.getElementsByTagName("tr");for(i=0;i<table_rows.length;i++){table_rows[i].onmouseover=null;table_rows[i].onmouseout=null;for(j=0;j<table_rows[i].cells.length;++j){table_rows[i].cells[j].onclick=null;}}}
function toggleCheckboxes(state){if(state==null)
state=$j('#master_checkbox')[0].checked;$j('input').each(function(e){if(e.type=='checkbox'){e.checked=state;}});}
function resetZebraStripes(table){if(table==null)
table='table#invoice-amount';$j(table).find('tr.item').each(function(index){$j(this).removeClass('odd even');$j(this).addClass(index%2===0?'odd':'even');});}
function closeKeepAlive(){if(/AppleWebKit|MSIE/.test(navigator.userAgent)){request=new Ajax.Request("/ping/close",{asynchronous:false});}}
function getCursorXY(e){mouseX=(window.addEventListener)?e.pageX:e.clientX+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);mouseY=(window.addEventListener)?e.pageY:e.clientY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);}
function captureMouse(){if(window.addEventListener){window.addEventListener("mousemove",getCursorXY,true);}else if(window.attachEvent){document.body.attachEvent('onmousemove',getCursorXY);}}
function sum_times(array_of_times){var total_minutes=0;var total_hours=0;for(i=0;i<array_of_times.length;i++){var time=new Date();time.setHours(array_of_times[i].split(":")[0]);time.setMinutes(array_of_times[i].split(":")[1]);total_hours+=time.getHours();total_minutes+=time.getMinutes();}
extra_hours=Math.floor(total_minutes/60)+total_hours
extra_minutes=total_minutes%60
if(extra_minutes.toString().length==1){extra_minutes='0'+extra_minutes;}
return extra_hours+':'+extra_minutes;}
function calculate_task_totals(){var billed_hours=new Array();var unbilled_hours=new Array();var unbillable_hours=new Array();$j("#tasks_list tr.item:visible td.billed_hours").each(function(index){billed_hours.push($j(this).text());});$j("#tasks_list tr.item:visible td.unbilled_hours").each(function(index){unbilled_hours.push($j(this).text());});$j("#tasks_list tr.item:visible td.unbillable_hours").each(function(index){unbillable_hours.push($j(this).text());});$j("#tasks_list #billed_hours").text(sum_times(billed_hours));$j("#tasks_list #unbilled_hours").text(sum_times(unbilled_hours));$j("#tasks_list #unbillable_hours").text(sum_times(unbillable_hours));}
function determine_visible_tasks(){var status_select=$j("#filter_tasks select"),status_form=status_select.closest('form'),selected_class=status_select.val();$j("#tasks_list").removeClass("status_all status_active status_completed status_hidden").addClass(selected_class);if(selected_class=="status_all"){selected_class="item";}
if($j("#tasks_list tr."+selected_class).size()==0){$j("#filter_no_tasks").show();$j("#tasks_list").hide();status_form.addClass('no_results');}else{$j("#filter_no_tasks").hide();$j("#tasks_list").show();status_form.removeClass('no_results');}}
addLoadEvent(invoiceGallery);addLoadEvent(Help);addLoadEvent(advancedOptions);addLoadEvent(tableHover);addLoadEvent(hideNonJS);addLoadEvent(setExternalLinks);addLoadEvent(contactCards);
