﻿/*
common.js
*/

$("a.addjob").toggle(function(){
    $(this).text("(-)").attr("title","hide additional jobs").next("div.addjob").show(300);
}, function (){ 
    $(this).text("(+)").attr("title","view additional jobs").next("div.addjob").hide(300);
});

if ($("table.calendar").is(":visible")){ $("dl.calendar").show(); } else { $("dl.calendar").hide(); }
$("span.dok").attr("title","Vehicle will be dropped for service");
        
function showTitleDescription(){
    $("span[title]").each(function(){
        var title = $(this).attr("title");
         $(this).find("em").remove();
         if (title != ""){           
            var toAppend;
            if ($(this).children("label").length>0){
                toAppend = $(this).children("label");
            } else {
                toAppend = $(this);
            }
            $(toAppend).append(" <em>(" + $(this).attr("title") +")</em>");
        }
    });
}

function validateTextarea(name,length){    
    $(name).attr("maxlength",length);
    $(name).keyup(function(){   
        var maxLength  =  $(this).attr('maxlength');  
        var newLength = $(this).val().length;
        var currLength  = maxLength - newLength;
        if (currLength<0){ currLength=0; }
        
        if (newLength>maxLength){
            this.value = this.value.substring(0, maxLength);
        }
    });
}

function mutuallyExclusiveCheckbox(parent){
    var owner = $(parent + " input:checkbox");
    $(owner).click(function(){
        checkedState = $(this).attr("checked");
        $(owner).each(function () {
            $(this).attr("checked", false);
        });
        $(this).attr("checked", checkedState);
    });
}

(function($) {
    $.fn.extend({
        isChildOf: function( filter_string ) {          
        var parents = $(this).parents().get();         
        for ( j = 0; j < parents.length; j++ ) {
            if ( $(parents[j]).is(filter_string) ) {
                return true;
            }
        }
        return false;
        }
    });
})(jQuery);


