// MDB Global JS defined below //Universal Showhide jQuery( function ($) { //Common variables var showHideSwitchClassPrefix = "showHideSwitch", showHideSwitchClassSuffix, showHideSwitchPattern = /\bshowHideSwitch(\d+)\b/, showHideClassPrefix = "showHide", showHideClassSuffix; //Dropdown showHide $("option[class*='" + showHideSwitchClassPrefix + "']").parents("select").change(selectListener).trigger('change'); // every time anything changes in the drop-down, run the following function: function selectListener(){ // hide all of the content divs $("option[class*='" + showHideSwitchClassPrefix + "']").each(function(i){ var selItem = $(this), selClass = selItem.attr("class"), selNum = selClass.match( showHideSwitchPattern )[1]; $("span[class*='showHide" + selNum + "'],div[class*='showHide" + selNum + "']").hide(); }); // loop through the selected ones and show the associated content divs $("option[class*='" + showHideSwitchClassPrefix + "']:selected").each(function(i){ var selItem = $(this), selClass = selItem.attr("class"), selNum = selClass.match( showHideSwitchPattern )[1]; $("span[class*='showHide" + selNum + "'],div[class*='showHide" + selNum + "']").show(); }); return false; } //Radio button showHide // Find all radio buttons... var radioShowHideArray = $("input:radio[class*='showHideSwitch']"); radioShowHideArray.each(function(){ // get the group name var group = $(this).attr("name"); var radioArray = $("input:radio[name='" + group + "']"); radioArray.each( radioListener ).bind( "click", radioListener ); }); function radioListener(){ var group = $(this).attr("name"); // all radio buttons in the same group with a showHide class... $("input:radio[name='" + group + "'][class*='showHideSwitch']").each(function(i){ var hidableItem = $(this), hidableClass = hidableItem.attr("class"), hidableNum = hidableClass.match( showHideSwitchPattern )[1]; if($(this).prop('checked')){ $("span[class*='showHide" + hidableNum + "'],div[class*='showHide" + hidableNum + "']").show(); } else { $("span[class*='showHide" + hidableNum + "'],div[class*='showHide" + hidableNum + "']").hide(); } }); } //Checkbox showHide $("input[class*='" + showHideSwitchClassPrefix + "'][type='checkbox']").each(function(){ tmpCurrentClassName = this.className; tmpCurrentClassName = tmpCurrentClassName.match( showHideSwitchPattern ); if( tmpCurrentClassName !== null ){ showHideClassSuffix = tmpCurrentClassName[1]; } if(this.checked){ $("." + showHideClassPrefix + showHideClassSuffix).show(); }else{ $("." + showHideClassPrefix + showHideClassSuffix).hide(); } $(this).click(function(){ tmpCurrentClassName = this.className; tmpCurrentClassName = tmpCurrentClassName.match( showHideSwitchPattern ); if( tmpCurrentClassName !== null ){ showHideClassSuffix = tmpCurrentClassName[1]; } if(this.checked){ $("." + showHideClassPrefix + showHideClassSuffix).show(); }else{ $("." + showHideClassPrefix + showHideClassSuffix).hide(); } }); }); //Textual showHide inline and block var classArray = $("p[class*='" + showHideSwitchClassPrefix + "'],a[class*='" + showHideSwitchClassPrefix + "'],h3[class*='" + showHideSwitchClassPrefix + "'],span[class*='" + showHideSwitchClassPrefix + "']"); classArray.each(function(){ tmpCurrentClassName = this.className; tmpCurrentClassName = tmpCurrentClassName.match( showHideSwitchPattern ); if( tmpCurrentClassName !== null ){ showHideClassSwitchSuffix = tmpCurrentClassName[1], showHideClassSuffix = tmpCurrentClassName[1]; } $("." + showHideSwitchClassPrefix + showHideClassSuffix).css({"text-decoration":"underline","cursor":"pointer"}); var classes = $("." + showHideSwitchClassPrefix + showHideClassSuffix).attr("class"); if(!classes.match("showHideDefaultShow")){ $("." + showHideClassPrefix + showHideClassSuffix).hide(); } $(this).click(function(){ tmpCurrentClassName = this.className; tmpCurrentClassName = tmpCurrentClassName.match( showHideSwitchPattern ); if( tmpCurrentClassName !== null ){ showHideClassSuffix = tmpCurrentClassName[1]; } if($("." + showHideClassPrefix + showHideClassSuffix).css("display") == "none"){ $(".showHideSwitch" + showHideClassSuffix).removeClass("unselected").addClass("selected"); $("." + showHideClassPrefix + showHideClassSuffix).show(); }else{ $(".showHideSwitch" + showHideClassSuffix).removeClass("selected").addClass("unselected"); $("." + showHideClassPrefix + showHideClassSuffix).hide(); } }); }); }); // select or unselect checkbox jQuery( function ($) { var checkInputSwitchClassPrefix = "checkInputSwitch", checkInputSwitchClassSuffix, checkInputSwitchPattern = /\bcheckInputSwitch(\d+)\b/, checkInputClassPrefix = "checkInput", checkInputClassSuffix, uncheckInputSwitchClassPrefix = "uncheckInputSwitch", uncheckInputSwitchClassSuffix, uncheckInputSwitchPattern = /\buncheckInputSwitch(\d+)\b/, uncheckInputClassPrefix = "checkInput", uncheckInputClassSuffix; $("a[class*='" + checkInputSwitchClassPrefix + "']").click(function(){ checkInputClassSuffix = 0; tmpCurrentClassName = this.className; tmpCurrentClassName = tmpCurrentClassName.match( checkInputSwitchPattern ); if( tmpCurrentClassName !== null ){ checkInputClassSuffix = tmpCurrentClassName[1]; } $("." + checkInputClassPrefix + checkInputClassSuffix).prop("checked",true); return false; }); $("a[class*='" + uncheckInputSwitchClassPrefix + "']").click(function(){ uncheckInputClassSuffix = 0; tmpCurrentClassName = this.className; tmpCurrentClassName = tmpCurrentClassName.match( uncheckInputSwitchPattern ); if( tmpCurrentClassName !== null ){ uncheckInputClassSuffix = tmpCurrentClassName[1]; } $("." + uncheckInputClassPrefix + uncheckInputClassSuffix).prop("checked",""); return false; }); }); // FORM Processing Function collection function disableFormItem(groupElem, controlElem) { if ((document.getElementById(groupElem) != null) && (document.getElementById(controlElem) != null)) { disableNode(document.getElementById(groupElem)); if (document.getElementById(controlElem).type = "radio") { if (!(document.getElementById(controlElem).checked)) { enableNode(document.getElementById(groupElem)); } } else { if (document.getElementById(controlElem).checked) { enableNode(document.getElementById(groupElem)); } } } } function registerOnKeyPress(elem, func) { if (document.getElementById(elem) != null) { document.getElementById(elem).onkeypress = func; } } function registerOnClick(elem, func) { if (document.getElementById(elem) != null) { document.getElementById(elem).onclick = func; } } function registerHref(elem, func) { if (document.getElementById(elem) != null) { document.getElementById(elem).href = func; } } function findFieldSetParent(curElem) { if (curElem.nodeName == "FIELDSET") { return curElem; } else { if (curElem.nodeName != "BODY") { return findFieldSetParent(curElem.parentNode); } else { return null; } } } function doChangeWrapper() { if (doChangeWrapper.arguments.length == 0) { doChange(window.event.srcElement); } else { doChange(doChangeWrapper.arguments[0].currentTarget); } } function doChange(chk) { if (chk.type == "radio") { fieldSetNode = findFieldSetParent(chk); if (chk.value == 1) { enableNode(fieldSetNode); } else { disableNode(fieldSetNode); } } else { fieldSetNode = findFieldSetParent(chk); if (chk.checked) { enableNode(fieldSetNode); } else { disableNode(fieldSetNode); } } } function enableNode(fieldSetNode) { if (fieldSetNode != null) { fieldSetNode.className = 'enableFormItems'; enableElementsByType(fieldSetNode,"input"); enableElementsByType(fieldSetNode,"textarea"); enableElementsByType(fieldSetNode,"select"); } } function disableNode(fieldSetNode) { if (fieldSetNode != null) { fieldSetNode.className = 'disableFormItems'; disableElementsByType(fieldSetNode,"input"); disableElementsByType(fieldSetNode,"textarea"); disableElementsByType(fieldSetNode,"select"); } } function disableElementsByType (node, type) { var sets = node.getElementsByTagName(type); for(var i=0; i< sets.length; i++) { if (isPartOfSpecial(sets[i])) { sets[i].disabled = true; } } } function enableElementsByType (node, type) { var sets = node.getElementsByTagName(type); for(var i=0; i< sets.length; i++) { if (isPartOfSpecial(sets[i])) { sets[i].disabled = false; } } } function isPartOfSpecial (node) { if (node.className.indexOf("disableThisArea") != -1) { return true; } else { if ((node.nodeName != "FIELDSET") && (node.nodeName != "BODY")) { return isPartOfSpecial(node.parentNode); } else { return false; } } } function hideHideable() { var elements = document.getElementsByTagName("div"); for(var i = 0; i < elements.length; i++) { var node = elements.item(i); if (node.className.indexOf("hideable") != -1) { node.className = "hideableHide"; } } if (document.getElementById("showControl") != null) { document.getElementById("showControl").className = "hideableShow"; } } function showHideable() { var elements = document.getElementsByTagName("div"); for(var i = 0; i < elements.length; i++) { var node = elements.item(i); if (node.className.indexOf("hideable") != -1) { node.className = "hideableShow"; } } if (document.getElementById("hideControl") != null) { document.getElementById("hideControl").className = "hideableShow"; } if (document.getElementById("showControl") != null) { document.getElementById("showControl").className = "hideableHide"; } } function initHideableDetails(num) { for(var i = 0; i < num; i++) { hideHideableDetails(i); } } function hideHideableDetails(i) { if (document.getElementById("Details"+i) != null) { document.getElementById("Details"+i).className = "hideableHide"; } if (document.getElementById("showControl"+i) != null) { document.getElementById("showControl"+i).className = "hideableShow"; } if (document.getElementById("hideControl"+i) != null) { document.getElementById("hideControl"+i).className = "hideableHide"; } } function showHideableDetails(i) { if (document.getElementById("Details"+i) != null) { document.getElementById("Details"+i).className = "hideableShow"; } if (document.getElementById("hideControl"+i) != null) { document.getElementById("hideControl"+i).className = "hideableShow"; } if (document.getElementById("showControl"+i) != null) { document.getElementById("showControl"+i).className = "hideableHide"; } } function findParent(curElem, elemType) { if (curElem.nodeName == elemType) { return curElem; } else { if (curElem.nodeName != "BODY") { return findParent(curElem.parentNode, elemType); } else { return null; } } } function setColorWrapper() { if (setColorWrapper.arguments.length == 0) { setColor(window.event.srcElement); } else { setColor(setColorWrapper.arguments[0].currentTarget); } } function setColor( element ) { //This gets our TR row = findParent(element, "TR"); if ( element.checked ) { // set focus to text box (second input element in the row) inputElement = row.getElementsByTagName("input").item(1); if ( inputElement != null ) { inputElement.focus(); } if (row.className == "even") { row.className = "evenSelected"; } else { row.className = "oddSelected"; } } else { if (row.className == "evenSelected") { row.className = "even"; } else { if ( row.className != "even" ) { row.className = "odd"; } } } } function setAll(func) { targets = document.getElementsByTagName( "input" ); for ( i = 0; i < targets.length; i++ ) { t = targets.item( i ); if ( t.type == "checkbox" || t.type == "radio" ) { row = findParent( t, "TR" ) if ( row != null ) { setColor( t ); t.onclick = func; } } } } function openNewWindow( url, windowproperties ) { window.open( url, '', windowproperties ); } util = { getElementByClassName: function(element, classname){ var res = []; var re = new RegExp(" " + classname + " "); var curEl, cn="" var desc = element.getElementsByTagName("*"); for (var x in desc){ curEl = desc[x]; cn = " " + curEl.className + " "; if( re.test(cn)){ res.push(curEl); } } return res; }, cancelClick: function() { return false; }, addEvent: function(elm, evType, fn, useCapture) { // cross-browser event handling for IE5+, NS6 and Mozilla By Scott Andrew if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; } else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; } else { elm['on' + evType] = fn; } }, getEvent: function( e ){ return e || window.event; }, getTarget: function(e, elem){ var target = e.srcElement || e.target || null; if (!target) return; while (target != document.body && target.nodeName.toLowerCase() != elem){ target = target.parentNode; } return target; } }; showHide = { handleLink: function(e){ /*find the parent div*/ /*var el; if (window.event && window.event.srcElement) el = window.event.srcElement; if (e && e.target) el = e.target; if (!el) return;*/ var el = util.getTarget(util.getEvent(e), "a"); if (!el) return; var parentNodeClass = ""; var targetClass = " " + showHide.showHideParentClass + " "; while (el.nodeName.toLowerCase() != 'body'){ el = el.parentNode; parentNodeClass = " " + el.className + " "; if(parentNodeClass.indexOf(targetClass) != -1){ break; } } /*if we went to body we didn't find it*/ if (el.nodeName.toLowerCase() == 'body') return; /*else do we show or hide*/ var showHideHiddenClass = " " + showHide.showHideHiddenClass + " "; var showHideVisibleClass = " " + showHide.showHideVisibleClass + " "; /*it's hidden*/ if(parentNodeClass.indexOf(showHideHiddenClass) != -1){ parentNodeClass = parentNodeClass.replace(showHideHiddenClass, ''); el.className = parentNodeClass + ' ' + showHide.showHideVisibleClass; }else{ parentNodeClass = parentNodeClass.replace(showHideVisibleClass, ''); el.className = parentNodeClass + ' ' + showHide.showHideHiddenClass; } return; }, init: function() { if (!document.getElementById) return; var hidablesControls = util.getElementByClassName(document, showHide.showHideControlClass); if (!hidablesControls) return; var showHideLink = ""; for(var i=0; i 1){ var ele = showHideLink; var dummyEvent = { target: ele } showHide.handleLink(dummyEvent); } } }, showHideControlClass: "showHideControl", showHideParentClass: "showHide", showHideHiddenClass: "hideShowHide", showHideVisibleClass: "showShowHide" } synchFields = { init: function(commonBranch,newMemberships){ if (!commonBranch || !newMemberships) return; commonBranch.toSynch = newMemberships; util.addEvent(commonBranch, 'keyup', synchFields.synch, false); }, synch: function(e){ var el = util.getTarget(util.getEvent(e), "input"); if (!el) return; for(var i=0; i