Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / fusion / raptor / js / other_scripts.js
1 //Reusable Asset Library - CSS Positioning Version (v3.3)
2 //Release Date: 1/26/07
3
4
5 //begin: quick help =======================================
6 var uitmpl_qhId;
7 var uitmpl_cookieVal;
8 var qhRule;
9 var qhCookie;
10
11 //sets cookie value and qhId
12 qhCookie=document.cookie;
13 var pos=qhCookie.indexOf("qhId=");
14
15 if(pos==-1){
16 document.cookie="qhId=0";
17 uitmpl_qhId="0";
18 qhCookie=document.cookie;
19 pos=qhCookie.indexOf("qhId=");
20 }
21 //reads cookie if value is present and sets qhId accordingly
22 var start=pos+5;
23 var end=qhCookie.indexOf(";", start);
24 if (end==-1) end=qhCookie.length;
25 uitmpl_cookieVal=qhCookie.substring(start,end);
26 if(uitmpl_cookieVal!=0){
27         uitmpl_qhId=1;
28 }else{
29 uitmpl_qhId=0;
30 }
31
32
33 //loops through all qh divs and toggles display based on qhId
34 function uitmpl_qhPageInit(){
35 var getTag = document.getElementsByTagName("div");
36         for (i=0;i<getTag.length;i++){
37                 if (getTag[i].className=="mQH"){
38                         getTag[i].style.display=(uitmpl_qhId!="0")?"block":"none";
39                         //getTag[i].onmouseover="alert('foo')";
40                 }
41         }
42         //changes instruction in help menu if menu exists
43         if (uitmpl_qhId==1&&document.getElementById("shHd")){
44         document.getElementById("shHd").innerHTML = "Hide";
45         }
46 }
47
48 function uitmpl_qhPageToggle(){
49 //change instruction in help menu
50 var getCurrent = document.getElementById("shHd").innerHTML;
51 var setCurrent = (getCurrent=="Show")?"Hide":"Show";
52 document.getElementById("shHd").innerHTML = setCurrent;
53 //change cookie value
54 document.cookie = (setCurrent=="Show")?"qhId=0":"qhId=1";
55 //change qhId value
56 uitmpl_qhId = (setCurrent=="Show")?"0":"1";
57 //rerun page init
58 uitmpl_qhPageInit();
59 }
60
61 //individual quick help toggle
62 function uitmpl_qh(obj){
63         var state = document.getElementById(obj).style.display;
64         document.getElementById(obj).style.display=(state!="block")?"block":"none";
65         
66 }
67 //end: quick help =======================================
68
69 //begin: error validation =======================================
70 //string validation
71 function uitmpl_errStrVal(obj, errId){
72         var x=obj.value;
73         var regExp = {
74         number:/(^\d+$)|(^\d+\.\d+$)/,
75         email:/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
76         //phone:/(^\d+$)|(^\d+\.\d+$)/,
77         //time:/(^\d+$)|(^\d+\.\d+$)/
78         };
79
80         var alrtStr = {
81         number:"Please input a valid number!",
82         email:"Please input a valid email address!",
83         date:"That date is invalid.  Please try again."
84         //phone:"Please input a valid phone number!",
85         //time:"Please input a valid time!"
86         };
87
88         var getReg = eval("regExp."+errId);
89         var getAlrt = eval("alrtStr."+errId);
90
91         //Number----------------------------------------------------------
92         if (errId=="number"&&!x.match(getReg)){
93                 alert(getAlrt);
94                 obj.focus();
95                 obj.select();
96         }
97         //Email-----------------------------------------------------------
98         else if (errId=="email"&&!x.match(getReg)){
99                 alert(getAlrt);
100                 obj.focus();
101                 obj.select();
102         }
103         //Date------------------------------------------------------------
104         if (errId=="date"&&!uitmpl_chkdate(obj)){
105                 alert(getAlrt);
106                 obj.focus();
107                 obj.select();
108                 }
109 }
110
111 //supplemental date check function
112 function uitmpl_chkdate(objName) {
113 var strDatestyle = "US"; //United States date style
114 //var strDatestyle = "EU";  //European date style
115 var strDate;
116 var strDateArray;
117 var strDay;
118 var strMonth;
119 var strYear;
120 var intday;
121 var intMonth;
122 var intYear;
123 var booFound = false;
124
125 var datefield = objName;
126 var strSeparatorArray = new Array("-"," ","/",".");
127 var intElementNr;
128 var err = 0;
129 var strMonthArray = new Array(12);
130 strMonthArray[0] = "Jan";
131 strMonthArray[1] = "Feb";
132 strMonthArray[2] = "Mar";
133 strMonthArray[3] = "Apr";
134 strMonthArray[4] = "May";
135 strMonthArray[5] = "Jun";
136 strMonthArray[6] = "Jul";
137 strMonthArray[7] = "Aug";
138 strMonthArray[8] = "Sep";
139 strMonthArray[9] = "Oct";
140 strMonthArray[10] = "Nov";
141 strMonthArray[11] = "Dec";
142 strDate = datefield.value;
143 if (strDate.length < 1) {
144 return true;
145 }
146 for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
147 if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
148 strDateArray = strDate.split(strSeparatorArray[intElementNr]);
149 if (strDateArray.length != 3) {
150 err = 1;
151 return false;
152 }
153 else {
154 strDay = strDateArray[0];
155 strMonth = strDateArray[1];
156 strYear = strDateArray[2];
157 }
158 booFound = true;
159    }
160 }
161 if (booFound == false) {
162 if (strDate.length>5) {
163 strDay = strDate.substr(0, 2);
164 strMonth = strDate.substr(2, 2);
165 strYear = strDate.substr(4);
166    }
167 }
168 if (strYear.length == 2) {
169 strYear = '20' + strYear;
170 }
171 // US style
172 if (strDatestyle == "US") {
173 strTemp = strDay;
174 strDay = strMonth;
175 strMonth = strTemp;
176 }
177 intday = parseInt(strDay, 10);
178 if (isNaN(intday)) {
179 err = 2;
180 return false;
181 }
182 intMonth = parseInt(strMonth, 10);
183 if (isNaN(intMonth)) {
184 for (i = 0;i<12;i++) {
185 if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
186 intMonth = i+1;
187 strMonth = strMonthArray[i];
188 i = 12;
189    }
190 }
191 if (isNaN(intMonth)) {
192 err = 3;
193 return false;
194    }
195 }
196 intYear = parseInt(strYear, 10);
197 if (isNaN(intYear)) {
198 err = 4;
199 return false;
200 }
201 if (intMonth>12 || intMonth<1) {
202 err = 5;
203 return false;
204 }
205 if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
206 err = 6;
207 return false;
208 }
209 if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
210 err = 7;
211 return false;
212 }
213 if (intMonth == 2) {
214 if (intday < 1) {
215 err = 8;
216 return false;
217 }
218 if (LeapYear(intYear) == true) {
219 if (intday > 29) {
220 err = 9;
221 return false;
222 }
223 }
224 else {
225 if (intday > 28) {
226 err = 10;
227 return false;
228 }
229 }
230 }
231 //if (strDatestyle == "US") {
232 //datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
233 //}
234 //else {
235 //datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
236 //}
237 return true;
238 }
239 function LeapYear(intYear) {
240 if (intYear % 100 == 0) {
241 if (intYear % 400 == 0) { return true; }
242 }
243 else {
244 if ((intYear % 4) == 0) { return true; }
245 }
246 return false;
247 }
248
249 //range validation
250 function uitmpl_errRangeVal(obj, minNum, maxNum){
251 if (obj.value>=minNum&&obj.value<=maxNum||obj.value==""){
252 return true;
253 }else{
254 alert("Please input a number within the range of "+minNum+" and "+maxNum+"!");
255 obj.focus();
256 obj.select();
257 }
258 }
259
260 //end: error validation =======================================
261 //begin: popup windows =======================================
262 function uitmpl_popUpReg(url) {
263         window.open(url);
264 }       
265 function uitmpl_popUpConfig(url, name, w, h, sc, rsz) {
266         var features = "width="+w+",height="+h+",scrollbars="+sc+",resizable="+rsz+"menubar=0,status=1";
267         var newWin = window.open(url, name, features);
268         newWin.focus();
269 //popups from nav links:
270 }
271
272
273 function uitmpl_contact(){
274 uitmpl_popUpReg("");
275 }
276 function uitmpl_bizDirect(){
277 uitmpl_popUpReg("");
278 }
279
280 //function uitmpl_closeApp(){
281 //if(window.confirm("You did NOT save your data.  Do you want to close 'application name' without saving your data?")) {
282 //window.close();
283
284 function uitmpl_closeApp(name){
285 if (name != "") {
286 var cAppName=name;
287 }
288 else {
289 var cAppName="the current application";
290 }
291 if(window.confirm("You did NOT save your data.  Do you want to close\n" + cAppName + " without saving your data?")) {
292 window.close();
293 }
294 }
295 //end: popup windows =======================================    
296
297
298
299
300
301 //Select all checkboxes on a form=====================================
302 function uitmpl_chkBoxSelect(formName,btnOn,btnOff) {
303
304         document.getElementById(btnOff).style.display = "block";
305         document.getElementById(btnOn).style.display = "none";
306
307         var f = formName;
308         for (i=0; i < f.elements.length; i++) {
309                 if (f.elements[i].type=="checkbox") {
310                         var e = f.elements[i];
311                         e.checked = true;
312                 }
313         }
314 }
315
316
317 //Clear all checkboxes on a form======================================
318 function uitmpl_chkBoxClear(formName,btnOn, btnOff) {
319
320         document.getElementById(btnOff).style.display = "none";
321         document.getElementById(btnOn).style.display = "block";
322
323         var f = formName;
324         for (i=0; i < f.elements.length; i++) {
325                 if (f.elements[i].type=="checkbox") {
326                         var e = f.elements[i];
327                         e.checked = false;
328                 }
329         }
330 }
331