1 /**
  2                 @name Util.GeneralUtils
  3                 @class A General utility class.
  4 **/
  5 
  6 
  7 var GeneralUtils = {
  8     zwin : top,
  9 	getURLParameter: function(name) {
 10 		var ret= decodeURI( (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);
 11 		if (ret=="null") return null;
 12 		return ret;
 13 	},
 14     formatNumber: function(no, noOfDecimalPlaces) {
 15         var place = (noOfDecimalPlaces) ? noOfDecimalPlaces : 2;
 16         return parseFloat(no).toFixed(place);
 17     },
 18     isInt: function(n) {
 19         return typeof n === 'number' && parseFloat(n) == parseInt(n, 10) && !isNaN(n);
 20     },
 21     removeSpecialChars: function(stringWithSpecialChars) {
 22         if (typeof stringWithSpecialChars == 'undefined') return "";
 23         var result = stringWithSpecialChars.replace(/[`~!@#$%^&*()|+\=?;,<>\{\}\[\]\\]/gi, '');
 24         return result;
 25     },
 26     toTitleCase: function(str) {
 27         return str.replace(/\w\S*/g, function(txt) {
 28             return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
 29         });
 30     },
 31     windowHeight: function() {
 32         var winH = 460;
 33         if (document.body && document.body.offsetWidth) {
 34             winH = document.body.offsetHeight;
 35         }
 36         if (document.compatMode == 'CSS1Compat' &&
 37             document.documentElement &&
 38             document.documentElement.offsetWidth) {
 39             winH = document.documentElement.offsetHeight;
 40         }
 41         if (window.innerWidth && window.innerHeight) {
 42             winH = window.innerHeight;
 43         }
 44         return winH;
 45     },
 46     windowWidth: function() {
 47         var winW = 630;
 48         if (document.body && document.body.offsetWidth) {
 49             winW = document.body.offsetWidth;
 50         }
 51         if (document.compatMode == 'CSS1Compat' &&
 52             document.documentElement &&
 53             document.documentElement.offsetWidth) {
 54             winW = document.documentElement.offsetWidth;
 55         }
 56         if (window.innerWidth && window.innerHeight) {
 57             winW = window.innerWidth;
 58         }
 59         return winW;
 60     },
 61     isSuperWide: function() {
 62         var winW = this.windowWidth();
 63         if (winW > 1599)
 64             return true;
 65         return false;
 66     },
 67     isMembersWide: function() {
 68         var winW = this.windowWidth();
 69         if (winW > 1299)
 70             return true;
 71         return false;
 72     },
 73     isSkinny: function() {
 74         var cockpit_skinny = false;
 75         var winW = this.windowWidth();
 76         //if (winW < 1270)
 77          //   cockpit_skinny = true;
 78         return cockpit_skinny;
 79     },
 80     hasSpecialChars: function(stringWithSpecialChars) {
 81         if (typeof stringWithSpecialChars == 'undefined') return "";
 82         var result = stringWithSpecialChars.replace(/[`~!@#$%^&*()|+\=?;,<>\{\}\[\]\\]/gi, '');
 83         return (result != stringWithSpecialChars);
 84     },
 85     escapeSpecialChars: function(stringWithSpecialChars) {
 86         if (typeof stringWithSpecialChars == 'undefined') return "";
 87         var result = stringWithSpecialChars.replace(/[`~!@#$%^&*()|]/gi, '\\$&');
 88         //result = result.replace(/[`"']/gi, '"e;');
 89         result = result.replace(/[`"']/gi, '\\\'');
 90         return result;
 91     },
 92     urlEncode: function(str) {
 93         return encodeURIComponent(str).replace("'", "%27");
 94     },
 95     displayImageToCenterbyPageId: function(elem_id, maxWidth, maxHeight, className) {
 96         var elem;
 97         var widthAllowed = maxWidth;
 98         var heightAllowed = maxHeight;
 99         var classN = (className) ? className : "ui-li-thumb";
100         $("#" + elem_id + " img." + classN).each(function(a, b) {
101             var width = b.width;
102             var height = b.height;
103             var margin_left = (widthAllowed - width) / 2;
104             var margin_top = (heightAllowed - height) / 2;
105             if (margin_left < 0 && margin_top < 0) return; //no margin to set
106             $(this).attr("style", "margin-left:" + margin_left + "px; margin-top: " + margin_top + "px;");
107         });;
108     },
109     centerAllImageFromCurrentPage: function(className) {
110         var fromPool = Z.jqm.dynamicPage.isFromPool();
111         var id;
112         var classN = (className) ? className : "ui-li-thumb";
113         if (Z.jqm.dynamicPage.$el && Z.jqm.dynamicPage.$el.length > 0) {
114             id = Z.jqm.dynamicPage.$el[0].id;
115             GeneralUtils.displayImageToCenterbyPageId(id, 80, 60, classN);
116             return;
117         }
118         var zapp = Z.jqm.lastZAppTab.zapp;
119         var tab = Z.jqm.lastZAppTab.tab;
120         var isFloating = isNaN(parseInt(tab));
121         if (!isFloating)
122             tab = tab && !isNaN(tab) ? tab : 1;
123         var action = (isFloating) ? tab : "body" + tab;
124         id = "zapp-+" + action;
125         GeneralUtils.displayImageToCenterbyPageId(id, 80, 60, classN);
126     },
127     get_zjs: function() {
128         return top;
129     },
130     get_zbody: function() {
131         if (document.zbody) {
132             return document.zbody;
133         }
134         return window;
135     },
136 	
137     dummy: function() {}
138 };
139