$(document).ready(function(){ $('ul#nav li:last-child a').css({ "border" : "0", "padding" : "0", "margin" : "0" }); Date.format = 'mm/dd/yyyy'; $('.cal_picker').datePicker({clickInput:true}); $("a.external").click(function(){ var newWindow = window.open(this.getAttribute('href'), '_blank'); if (newWindow) { if (newWindow.focus) { newWindow.focus(); return false; } } else { return true; } }); //$(".tablesorter").tablesorter({widgets: ['zebra']}).tableScroller(); $(".tablesorter").tablesorter({widgets: ['zebra']}); $(".tablesorter tr:even td").addClass('even'); $('span.depends:not(.open)').hide(); $("input[type=checkbox].trigger").livequery('click', function(event) { var target_class = '.'+$(this).attr('id')+'-fields'; // there should only be one var target_id = '#'+$('span'+target_class+':first').attr('id'); if ($(target_id).is('.open')) { $(target_id).slideUp('fast').removeClass('open'); } else { $(target_id).slideDown('fast').addClass('open'); } }); $("select.trigger").livequery('change', function(event) { var target_option = $('#'+$(this).attr('id')+' option[value='+$(this).attr('value')+']'); var target_id = '#'+$(this).attr('id')+'-is-'+$(this).attr('value')+'-fields'; if ($(target_option).is('.trigger_parent')) { var target_value = $('#'+$(this).attr('id')+' option.trigger').attr('value'); if ($(this).attr('value') == target_value) { $(target_id).slideDown('fast'); } else { $(target_id).slideUp('fast'); } return false; } var open_class = $(this).attr('id')+'_is_open'; $('.'+open_class).slideUp('fast').removeClass(open_class); var open_class = $(this).attr('id')+'_is_open'; var target_id = '#'+$(this).attr('id')+'-is-'+$(this).attr('value')+'-fields'; target_id = target_id.toLowerCase(); target_id = target_id.replace(/ /g, '_'); target_id = target_id.replace(/_g_trigger/g, ''); //var target_value = $('#'+$(this).attr('id')+' option.trigger').attr('value'); //if ($(this).attr('value') == target_value) // if the new option has an trigger class, then open the associated element we identified //if ($(target_option).not('.trigger')) if ($(target_option).not('.'+open_class)) { $(target_id).slideDown('fast').addClass(open_class); } else { $('.'+open_class).slideUp('fast').removeClass(open_class); } }); // Cascade selects $('select.cascade').livequery('change', function(event) { var this_action = $(this).parents('form').attr('action'); var this_value = $(this).attr('value'); var this_id = $(this).attr('id'); var this_name = $(this).attr('name'); // each member of the group of selects has a class group-somegroup var this_group = $(this).attr('class'); var temp = this_group.split(' '); var i; for (i in temp) { if (temp[i].substring(0,5) == 'group') { var this_group = temp[i].substring(6, temp[i].length); break; } } // send the same POST array key that the submit button for this select would var this_trigger = $(this).next('input.cascade').attr("name"); // get the target id to update ... also name of value key var this_target = $(this).next('input.cascade').attr("id"); // the submit button will have an id like update_SELECT where SELECT is the target to be updated var this_target = this_target.substring(7); $('#'+this_target).attr('disabled', 'disabled'); $('#'+this_target).animate({opacity: 0.4}, 500) $.ajax({type: "POST",url: this_action, data: this_name+"="+this_value+"&"+this_trigger+"=1&this_target="+this_target, success: function(data){ $('#'+this_target).after(data).remove(); $('#'+this_target).attr('disabled', ''); $('#'+this_target).animate({opacity: 1.0}, 200) // reset all subsequent group members $('#'+this_target).parent('label').nextAll('label.group-location').each(function() { //$(this).children('select').attr('selectedIndex', 0); $(this).children('select').children('option').each(function() { $(this).remove(); }); }); } }); return false; }); // Clone and increment repeatables //$('fieldset.g_blank').css('border-color', 'yellow'); //$('fieldset.g_blank').css('position', 'absolute'); //$('fieldset.g_blank').css('left', '0px'); // Hide the blanks, unless we need first visible $('fieldset.g_blank:not(.first_set_visible)').css('display', 'none'); // If first_fieldset is visible, we need to copy it to use as a master $('fieldset.g_blank.first_set_visible').each(function() { var master_copy = $(this).html(); var this_id = $(this).attr('id'); var this_class = $(this).attr('class'); master_copy = '
'+master_copy+'
'; // avoid id collision var master_copy = master_copy.replace(new RegExp('id="', "g" ), 'id="glurch_copy_'); $(this).before(master_copy); $('#glurch_copy_'+this_id).css('display', 'none'); }); $("input.add_repeat").livequery('click', function(event) { // find the blank fieldset for this group var this_id = $(this).attr('id'); var tmp = this_id.split('_'); var key = parseInt(tmp[tmp.length-1]); var next_key = (parseInt(key))+1; var prev_key = (parseInt(key))-1; var section_temp = this_id.split('_add_'+key); var section = section_temp[0]; var new_fieldset = $('fieldset.'+section+'.g_blank').html(); var blank_fieldset = $('fieldset.'+section+'.g_blank').html(); // just in case, remove any 'glurch_copy' strings new_fieldset = new_fieldset.replace(new RegExp("glurch_copy_", "g" ), ""); blank_fieldset = blank_fieldset.replace(new RegExp("glurch_copy_", "g" ), ""); // increment the blank set blank_fieldset = blank_fieldset.replace(new RegExp("_"+prev_key, "g" ), "_"+key); $('fieldset.'+section+'.g_blank').html(blank_fieldset); // create and highlight the new fieldset new_fieldset = '
'+new_fieldset+'
'; $(this).before(new_fieldset); $('#'+section+'_'+key+'_repeater').highlightFade({color:'#FDF88B',speed:200}); // Update the ID on the add butotn var new_id = this_id.replace(new RegExp("_"+key, "g" ), "_"+next_key); $(this).attr('id', new_id); return false; }); $("input.remove_repeat").livequery('click', function(event) { /* // we need to know what group this is, so we remove the last two segments from the id var temp = $(this).attr('id').split('_'); var remove_segments = '_'+temp[temp.length-2]+'_'+temp[temp.length-1]; var remove_index = temp[temp.length-1]; var target_class = $(this).attr('id').replace(remove_segments, ""); // match all sibling fieldsets of this group var count = temp[temp.length-2]; $(this).parent('fieldset').next('fieldset.'+target_class).each(function() { // we need to find the index count++; var fieldset = $(this).html(); fieldset = fieldset.replace(new RegExp("_"+count, "g" ), "_"+parseInt(count-1)); new_id = $(this).attr('id').replace(new RegExp("_"+count, "g" ), "_"+parseInt(count-1)); //$(this).attr('id', new_id); //$(this).html(fieldset); });*/ $(this).parent('fieldset').remove(); return false; }); $('.confirm').click(function() { return confirm("Are you sure you want to delete"); }); if(window.opera) { if ($("a.bookmark").attr("rel") != "") { $("a.bookmark").attr("rel","sidebar"); } } $("a.bookmark").click(function(event) { event.preventDefault(); if (window.sidebar) { window.sidebar.addPanel(this.title, this.href, ""); } else if(window.external) { window.external.AddFavorite(this.href, this.title); } else if(window.opera) { return false; } else { alert('Please bookmark this page manually.'); } }); });