Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / fusion / raptor / js / raptor.js
1 function grayOut(vis, options) {
2   // Pass true to gray out screen, false to ungray
3   // options are optional.  This is a JSON object with the following (optional) properties
4   // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
5   // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
6   // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
7   // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
8   // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
9   // in any order.  Pass only the properties you need to set.
10   var options = options || {}; 
11   var zindex = options.zindex || 50;
12   var opacity = options.opacity || 20;
13   var opaque = (opacity / 100);
14   var bgcolor = options.bgcolor || '#000000';
15   var dark=document.getElementById('darkenScreenObject');
16   //var tbody = document.getElementsByTagName("body")[0];
17   var tbody = document.body;
18   var myAjax = document.getElementById('AjaxLoading');
19   
20   if (!dark) {
21     // The dark layer doesn't exist, it's never been created.  So we'll
22     // create it here and apply some basic styles.
23     // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
24     var tnode = document.createElement('div');           // Create the layer.
25         tnode.style.position='absolute';                 // Position absolutely
26         tnode.style.top='0px';                           // In the top
27         tnode.style.left='0px';                          // Left corner of the page
28         tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
29         tnode.style.display='none';                      // Start out Hidden
30         tnode.id='darkenScreenObject';                   // Name it so we can find it later
31     tbody.appendChild(tnode);                            // Add it to the web page
32     dark=document.getElementById('darkenScreenObject');  // Get the object.
33   }
34   if (vis) {
35     // Calculate the page width and height 
36     if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
37         var pageWidth = document.body.scrollWidth+'px';
38         var pageHeight = document.body.scrollHeight+'px';
39     } else if( document.body.offsetWidth ) {
40       var pageWidth = document.body.offsetWidth+'px';
41       var pageHeight = document.body.offsetHeight+'px';
42     } else {
43        var pageWidth='100%';
44        var pageHeight='100%';
45     }   
46     //set the shader to cover the entire page and make it visible.
47     dark.style.opacity=opaque;                      
48     dark.style.MozOpacity=opaque;                   
49     dark.style.filter='alpha(opacity='+opacity+')'; 
50     dark.style.zIndex=zindex;        
51     dark.style.backgroundColor=bgcolor;  
52     dark.style.width= pageWidth;
53     dark.style.height= pageHeight;
54     dark.style.display='block';
55     //MyAjax
56     
57     /* Display the "Loading" box */
58     var tnode = document.createElement('div'); // Create the layer.
59     tnode.style.position='absolute'; // Position absolutely
60     tnode.style.top='0px'; // In the top
61     tnode.style.left='0px'; // Left corner of the page
62     tnode.style.overflow='hidden'; // Try to avoid making scroll bars
63     tnode.style.display='none'; // Start out Hidden
64     tnode.id='AjaxLoading'; // Name it so we can find it later
65     tbody.appendChild(tnode); // Add it to the web page
66     myAjax=document.getElementById('AjaxLoading'); // Get the object.
67
68     // Content
69     // Reset the opacity options. Want this on top
70     var loadingOptions = loadingOptions || {};
71     var zindex = loadingOptions.zindex || 100;
72     var opacity = loadingOptions.opacity || 100;
73     var opaque = (opacity / 100);
74     var bgcolor = loadingOptions.bgcolor || '#FFFFFF';
75
76     myAjax.style.opacity=opaque;
77     myAjax.style.MozOpacity=opaque;
78     myAjax.style.filter='alpha(opacity='+opacity+')';
79     myAjax.style.zIndex=zindex;
80
81     myAjax.style.height= '40px';
82     myAjax.style.padding = '3px';
83     myAjax.style.fontSize = '14px';
84     myAjax.style.width = '100px';
85     myAjax.style.textAlign = 'center';
86     myAjax.style.left = '45%';
87     myAjax.style.top = '5%';
88     myAjax.style.position = 'absolute';
89     myAjax.style.border = '2px solid #666';
90     myAjax.style.backgroundColor = bgcolor;
91
92     myAjax.innerHTML='Loading <img src="static/fusion/raptor/images/progress.gif" id="wait" />';
93     myAjax.style.display='block';
94     
95   } else {
96      if(dark)   dark.style.display='none';
97      if(myAjax) myAjax.style.display='none';
98   }
99 }
100 function checkDate(dateStr, isOptional) {
101         if(dateStr.charAt(0) == '[' && dateStr.charAt(dateStr.length-1) == ']')
102                 return true;
103         if(dateStr=="")
104                 return isOptional;
105         
106         if((dateStr.length<6)||(dateStr.length>10))
107                 return false;
108         
109         if(dateStr.charAt(1)=='/') {
110                 dmonth  = parseInt(dateStr.substr(0,1));
111                 dateStr = dateStr.substr(2,dateStr.length-2);
112         } else {
113                 //For some strange reason "08" is parsed as 0, so I remove leading 0-s
114                 if(dateStr.charAt(0)=='0')
115                         dmonth = parseInt(dateStr.substr(1,1));
116                 else
117                         dmonth = parseInt(dateStr.substr(0,2));
118                 dateStr = dateStr.substr(3,dateStr.length-3);
119         }
120         
121         if(dateStr.charAt(1)=='/') {
122                 dday = parseInt(dateStr.substr(0,1));
123                 dateStr = dateStr.substr(2,dateStr.length-2);
124         } else {
125                 //For some strange reason "08" is parsed as 0, so I remove leading 0-s
126                 if(dateStr.charAt(0)=='0')
127                         dday = parseInt(dateStr.substr(1,1));
128                 else
129                         dday = parseInt(dateStr.substr(0,2));
130                 dateStr = dateStr.substr(3,dateStr.length-3);
131         }
132         
133         if(dateStr.length==2) {
134                 if (parseInt(dateStr)>50)
135                         dateStr="19"+dateStr;
136                 else
137                         dateStr="20"+dateStr;
138         }
139         dyear = parseInt(dateStr);
140         //alert("day: "+dday+", month: "+dmonth+", year: "+dyear);
141         if((dyear<1990)||(dyear>2090)||(dmonth<1)||(dmonth>12)||(dday<1)||
142                 (dday>((dmonth==2)?(((dyear % 4 == 0) && ((!(dyear % 100 == 0))||(dyear % 400 == 0)))?29:28):(((dmonth==1)||(dmonth==3)||(dmonth==5)||(dmonth==7)||(dmonth==8)||(dmonth==10)||(dmonth==12))?31:30))))
143                 return false;
144                 
145         return true;
146 }   // checkDate
147
148 function validateNumber(numValue, mustBeInteger, mustBePositive) {
149         var decimalPointFound = false;
150         for(var i=0; i<numValue.length; i++) {
151                 var ch = numValue.charAt(i);
152                 
153                 if(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||ch=='6'||ch=='7'||ch=='8'||ch=='9') {
154                         // Valid character - do nothing
155                 } else if(ch=='-') {
156                         if(mustBePositive||i>0)
157                                 return false;
158                 } else if(ch=='.') {
159                         if(mustBeInteger||decimalPointFound)
160                                 return false;
161                         else
162                                 decimalPointFound = true;
163                 } else
164                         // Invalid character
165                         return false;
166         }       // for
167
168         return true;
169 }       // validateNumber
170
171 function checkInteger(numValue) {
172         return validateNumber(numValue, true, false);
173 }       // checkInteger
174
175 function checkNonNegativeInteger(numValue) {
176         return validateNumber(numValue, true, true);
177 }       // checkNonNegativeInteger
178
179 function checkPositiveInteger(numValue) {
180         if(! checkNonNegativeInteger(numValue))
181                 return false;
182                 
183         if(parseInt(numValue)==0)
184                 return false;
185         
186         return true;    
187 }       // checkPositiveInteger
188
189 function checkFloat(numValue) {
190         return validateNumber(numValue, false, false);
191 }       // checkFloat
192
193 function checkNonNegativeFloat(numValue) {
194         return validateNumber(numValue, false, true);
195 }       // checkNonNegativeFloat
196
197 function checkPositiveFloat(numValue) {
198         if(! checkNonNegativeFloat(numValue))
199                 return false;
200
201         if(parseFloat(numValue)<0.001&&parseFloat(numValue)>-0.001)
202                 return false;
203         
204         return true;    
205 }       // checkPositiveFloat
206
207 function getDocHeight(doc) {
208 var docHt = 0, sh, oh;
209 if (doc.height) docHt = doc.height;
210 else if (doc.body) {
211 if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
212 if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
213 if (sh && oh) docHt = Math.max(sh, oh);
214 }
215 return docHt;
216 }
217
218 function getDocWidth(doc) 
219
220         var docWd = 0, sh, oh; 
221         if (doc.width) 
222                 docWd = doc.width; 
223         else if (doc.body) 
224         { 
225                 if (doc.body.scrollWidth) 
226                         docWd = sh = doc.body.scrollWidth; 
227                 if (doc.body.offsetWidth) 
228                         docWd = oh = doc.body.offsetWidth; 
229                 if (sh && oh) 
230                         docWd = Math.max(sh, oh); 
231         } 
232         return docWd; 
233
234  
235
236 function setIframeHeight(iframeName) 
237
238         var oldY = document.body.scrollTop;
239         var iframeWin = window.frames[iframeName]; 
240         var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null; 
241         if ( iframeEl && iframeWin ) { 
242                 iframeEl.style.height = "auto"; 
243                 // helps resize (for some) if new doc shorter than previous 
244                 var docHt = getDocHeight(iframeWin.document); 
245                 var docWd = getDocWidth(iframeWin.document); 
246                 // need to add to height to be sure it will all show 
247                 if (docHt) 
248                         iframeEl.style.height = docHt + 1 + "px"; 
249                 if (docWd) 
250                         iframeEl.style.width = docWd + 1 + "px"; 
251         } 
252         if (oldY != null && oldY != 'undefined')
253                 document.body.scrollTop = oldY;
254 }
255
256 function resizeFrames(){
257         var isFolderAllowed = arguments[0];
258         if (isFolderAllowed == null || isFolderAllowed == 'true'){
259                 if (document.getElementById('scrollableTable') && document.body.offsetHeight > 195)
260                         document.getElementById('scrollableTable').style.height=document.body.offsetHeight - 185;
261                 if (document.getElementById('contentDiv') && document.body.offsetHeight > 145)
262                         document.getElementById('contentDiv').style.height=document.body.offsetHeight - 135;
263                 if (document.getElementById('content_Iframe') && document.body.offsetHeight > 145)
264                         document.getElementById('content_Iframe').height=document.body.offsetHeight - 135;                      
265                 
266         }else{
267                 setIframeHeight('content_Iframe');
268         }
269 }
270
271 function resizeWindow() {
272         var isFolderAllowed = arguments[0];
273         if (isFolderAllowed != null)
274                 resizeFrames(isFolderAllowed);
275         else
276                 resizeFrames(false);    
277 }
278
279 /**
280 * Usage : var myObje = $('theIdOfTheElementYouWantToGet');
281 * Simple gives you the element. Avoids using document.getElementById();
282 */
283         var $;
284         if (!$ && document.getElementById) {
285                 $ = function() {
286                         var elements = new Array();
287                         for (var i = 0; i < arguments.length; i++) {
288                                 var element = arguments[i];
289                                 if (typeof element == 'string') {
290                                         element = document.getElementById(element);
291                                 }
292                                 if (arguments.length == 1) {
293                                         return element;
294                                 }
295                                 elements.push(element);
296                         }
297                         return elements;
298                 }
299         } else if (!$ && document.all) {
300                 $ = function() {
301                         var elements = new Array();
302                         for (var i = 0; i < arguments.length; i++) {
303                                 var element = arguments[i];
304                                 if (typeof element == 'string') {
305                                         element = document.all[element];
306                                 }
307                                 if (arguments.length == 1) {
308                                         return element;
309                                 }
310                                 elements.push(element);
311                         }
312                         return elements;
313                 }
314         }