1//gets the endtag of the given name in the data object. must also specify parent because we allow same fieldsplit names under different parents 2function getEndtagByName(data,name,parent) { 3 4 for (var key in data) { 5 if (data.hasOwnProperty(key)) { 6 if(data[key].name == name && key.indexOf(parent) == 0) 7 return key; 8 } 9 } 10 return "-1"; 11} 12 13//count the number of children that currently exist for the given parent 14function getNumChildren(data,parent) { 15 16 var childNumUnderscores = getNumUnderscores(parent) + 1; 17 var count = 0; 18 19 for (var key in data) { 20 if (data.hasOwnProperty(key)) { 21 if(getNumUnderscores(key) == childNumUnderscores && key.indexOf(parent) == 0) 22 count ++; 23 } 24 } 25 26 return count; 27} 28 29//returns the number of underscores in the endtag 30function getNumUnderscores(endtag) { 31 32 var count = 0; 33 for(var i=0; i<endtag.length; i++) { 34 if(endtag.charAt(i) == "_") 35 count ++; 36 } 37 return count; 38} 39 40//returns the endtag of the parent (if any) 41function getParent(endtag) { 42 43 if(endtag.indexOf('_') == -1) 44 return "-1"; //has no parent (root case) or invalid endtag 45 46 return endtag.substring(0,endtag.lastIndexOf('_')); 47} 48 49//returns the number of occurrences of a string in another string 50function countNumOccurances(small_string, big_string) { 51 52 var count = 0; 53 54 while(small_string.length <= big_string.length && big_string.indexOf(small_string) != -1) { 55 count ++; 56 var loc = big_string.indexOf(small_string); 57 big_string = big_string.substring(loc + small_string.length, big_string.length); 58 } 59 60 return count; 61} 62 63//scrolls the page 64function scrollTo(id) 65{ 66 $('html,body').animate({scrollTop: $("#"+id).offset().top},'fast'); 67} 68