1// Push and pop not implemented in IE 2if(!Array.prototype.push) { 3 function array_push() { 4 for(var i=0;i<arguments.length;i++) 5 this[this.length]=arguments[i]; 6 return this.length; 7 } 8 Array.prototype.push = array_push; 9} 10if(!Array.prototype.pop) { 11 function array_pop(){ 12 lastElement = this[this.length-1]; 13 this.length = Math.max(this.length-1,0); 14 return lastElement; 15 } 16 Array.prototype.pop = array_pop; 17} 18 19if(!Array.prototype.contains) { 20 function array_contains(obj){ 21 for (var i = 0; i < this.length; i++) { 22 if (this[i] === obj) { 23 return true; 24 } 25 } 26 return false; 27 } 28 Array.prototype.contains = array_contains; 29} 30 31if(!Array.prototype.removeItem) { 32 function array_removeItem(obj){ 33 for (var i = 0; i < this.length; i++) { 34 if (this[i] === obj) { 35 this.splice(i,1); 36 //alert('remove: ' + obj + ', ' + this.length); 37 return true; 38 } 39 } 40 return false; 41 } 42 Array.prototype.removeItem = array_removeItem; 43} 44 45String.prototype.width = function(font) { 46 var f = font || '12px arial', 47 o = $('<div>' + this + '</div>') 48 .css({'position': 'absolute', 'float': 'left', 'white-space': 'nowrap', 'visibility': 'hidden', 'font': f}) 49 .appendTo($('body')), 50 w = o.width(); 51 52 o.remove(); 53 54 return w; 55} 56 57function getFileExt(filename){ 58 var ext = /^.+\.([^.]+)$/.exec(filename); 59 return ext == null ? "" : ext[1].toLowerCase(); 60} 61 62function isPrivateIP(ip){ 63 var location_host = (ip==""||ip==undefined) ? String(window.location.host) : ip; 64 65 if( location_host.indexOf("192.168") == 0 || 66 location_host.indexOf("127") == 0 || 67 location_host.indexOf("10") == 0 || 68 location_host.indexOf("www.asusnetwork.net") == 0 || 69 location_host.indexOf("router.asus.com") == 0 ){ 70 return 1; 71 } 72 73 return 0; 74} 75 76function getOS(){ 77 var os, ua = navigator.userAgent; 78 if (ua.match(/Win(dows )?NT 6\.0/)) { 79 os = "Windows Vista"; // Windows Vista ??? 80 } 81 else if (ua.match(/Win(dows )?NT 6\.1/)) { 82 os = "Windows 7"; // Windows Vista ??? 83 } 84 else if (ua.match(/Win(dows )?NT 5\.2/)) { 85 os = "Windows Server 2003"; // Windows Server 2003 ??? 86 } 87 else if (ua.match(/Win(dows )?(NT 5\.1|XP)/)) { 88 os = "Windows XP"; // Windows XP ??? 89 } 90 else if (ua.match(/Win(dows)? (9x 4\.90|ME)/)) { 91 os = "Windows ME"; // Windows ME ??? 92 } 93 else if (ua.match(/Win(dows )?(NT 5\.0|2000)/)) { 94 os = "Windows 2000"; // Windows 2000 ??? 95 } 96 else if (ua.match(/Win(dows )?98/)) { 97 os = "Windows 98"; // Windows 98 ??? 98 } 99 else if (ua.match(/Win(dows )?NT( 4\.0)?/)) { 100 os = "Windows NT"; // Windows NT ??? 101 } 102 else if (ua.match(/Win(dows )?95/)) { 103 os = "Windows 95"; // Windows 95 ??? 104 } 105 else if (ua.match(/Mac|PPC/)) { 106 os = "Mac OS"; // Macintosh ??? 107 } 108 else if (ua.match(/Linux/)) { 109 os = "Linux"; // Linux ??? 110 } 111 else if (ua.match(/(Free|Net|Open)BSD/)) { 112 os = RegExp.$1 + "BSD"; // BSD ???? 113 } 114 else if (ua.match(/SunOS/)) { 115 os = "Solaris"; // Solaris ??? 116 } 117 else { 118 os = "N/A"; // ???? OS ??? 119 } 120 121 return os; 122} 123 124function isWinOS(){ 125 var osVer = navigator.appVersion.toLowerCase(); 126 if( osVer.indexOf("win") != -1 ) 127 return 1; 128 129 return 0; 130} 131 132function isMacOS(){ 133 var osVer = navigator.appVersion.toLowerCase(); 134 if( osVer.indexOf("mac") != -1 && osVer.indexOf("iphone") == -1 && osVer.indexOf("ipad") == -1 && osVer.indexOf("ipod") == -1 ) 135 return 1; 136 137 return 0; 138} 139 140function isBrowser(testBrowser){ 141 var browserVer = navigator.userAgent.toLowerCase(); 142 if( browserVer.indexOf(testBrowser) != -1 ) 143 return 1; 144 return 0; 145} 146 147function getUrlVars(){ 148 var vars = [], hash; 149 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 150 for(var i = 0; i < hashes.length; i++){ 151 hash = hashes[i].split('='); 152 vars.push(hash[0]); 153 vars[hash[0]] = hash[1]; 154 } 155 return vars; 156} 157 158function parseXml(xml) { 159 if(isIE()){ 160 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 161 xmlDoc.loadXML(xml); 162 xml = xmlDoc; 163 } 164 return xml; 165} 166 167function addPathSlash(val){ 168 169 if(val.lastIndexOf("/")==val.length-1) 170 return val; 171 172 val += "/" 173 174 return val; 175} 176 177function size_format(size) { 178 var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; 179 var i = 0; 180 while(size >= 1024) { 181 size /= 1024; 182 ++i; 183 } 184 return size.toFixed(1) + ' ' + units[i]; 185} 186 187function mydecodeURI(iurl){ 188 189 //iurl = String(iurl).replace("%7f", "~"); 190 191 try{ 192 var myurl = decodeURIComponent(iurl); 193 /* 194 myurl = String(myurl).replace("%22", "\""); 195 myurl = String(myurl).replace("%23", "#"); 196 myurl = String(myurl).replace("%24", "$"); 197 myurl = String(myurl).replace("%25", "%"); 198 myurl = String(myurl).replace("%26", "&"); 199 myurl = String(myurl).replace("%2b", "+"); 200 myurl = String(myurl).replace("%40", "@"); 201 */ 202 } 203 catch(err){ 204 //Handle errors here 205 //alert('catch error: '+ err); 206 return iurl; 207 } 208 209 return myurl; 210} 211 212function myencodeURI(iurl){ 213 try{ 214 var myurl = iurl; 215 /* 216 myurl = String(myurl).replace("%", "%25"); 217 218 myurl = String(myurl).replace("\"", "%22"); 219 myurl = String(myurl).replace("#", "%23"); 220 myurl = String(myurl).replace("$", "%24"); 221 myurl = String(myurl).replace("&", "%26"); 222 myurl = String(myurl).replace("+", "%2b"); 223 myurl = String(myurl).replace("@", "%40"); 224 225 myurl = encodeURI(myurl); 226 227 myurl = String(myurl).replace("\"", "%22"); 228 myurl = String(myurl).replace("#", "%23"); 229 myurl = String(myurl).replace("$", "%24"); 230 myurl = String(myurl).replace("&", "%26"); 231 myurl = String(myurl).replace("+", "%2b"); 232 myurl = String(myurl).replace("@", "%40"); 233 */ 234 myurl = encodeURIComponent(myurl); 235 } 236 catch(err){ 237 //Handle errors here 238 //alert('catch error: '+ err); 239 return iurl; 240 } 241 242 return myurl; 243} 244 245function isIE(){ 246 var is_ie = false; 247 248 if(navigator.userAgent.indexOf("MSIE")!=-1){ 249 is_ie = true; 250 } 251 else if (!document.all) { 252 253 if (navigator.appName == 'Netscape') 254 { 255 var ua = navigator.userAgent; 256 var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})"); 257 if (re.exec(ua) != null){ 258 rv = parseFloat( RegExp.$1 ); 259 if(rv>=11) 260 is_ie = true; 261 } 262 } 263 } 264 265 return is_ie; 266} 267 268function getInternetExplorerVersion(){ 269 var rv = -1; // Return value assumes failure. 270 if (navigator.appName == 'Microsoft Internet Explorer') 271 { 272 var ua = navigator.userAgent; 273 var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 274 if (re.exec(ua) != null) 275 rv = parseFloat( RegExp.$1 ); 276 } 277 else if (navigator.appName == 'Netscape') 278 { 279 var ua = navigator.userAgent; 280 var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})"); 281 if (re.exec(ua) != null) 282 rv = parseFloat( RegExp.$1 ); 283 } 284 return rv; 285} 286 287function getPageSize() { 288 var body_width = $(window).width(); 289 var body_height = $(window).height(); 290 return [ body_width, body_height ]; 291} 292 293function getLockToken(content){ 294 var parser; 295 var xmlDoc; 296 297 if (window.DOMParser){ 298 parser=new DOMParser(); 299 xmlDoc=parser.parseFromString(content,"text/xml"); 300 } 301 else { // Internet Explorer 302 xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); 303 xmlDoc.async="false"; 304 xmlDoc.loadXML(content); 305 306 if(!xmlDoc.documentElement){ 307 alert("Fail to load xml!"); 308 return; 309 } 310 } 311 312 var j, k, l, n; 313 var x = xmlDoc.documentElement.childNodes; 314 for (var i=0;i<x.length;i++){ 315 316 var y = x[i].childNodes; 317 for (var j=0;j<y.length;j++){ 318 if(y[j].nodeType==1&&y[j].nodeName=="D:activelock"){ 319 var z = y[j].childNodes; 320 321 for(var k=0;k<z.length;k++){ 322 if(z[k].nodeName=="D:locktoken"){ 323 324 var a = z[k].childNodes; 325 326 for(var l=0;l<a.length;l++) 327 { 328 if(a[l].childNodes.length<=0) 329 continue; 330 331 if(a[l].nodeName=="D:href"){ 332 var locktoken = String(a[l].childNodes[0].nodeValue); 333 return locktoken; 334 } 335 } 336 } 337 } 338 } 339 } 340 } 341} 342 343function DrawImage(ImgD,FitWidth,FitHeight,FitWidthOnly){ 344 345 if( isBrowser("msie") && getInternetExplorerVersion()<=8 ) 346 return; 347 348 var image=new Image(); 349 image.src=ImgD.src; 350 if(image.width>0 && image.height>0){ 351 if(FitWidthOnly){ 352 ImgD.width=FitWidth; 353 ImgD.height=(image.height*FitWidth)/image.width; 354 return 355 } 356 357 if(image.width/image.height>= FitWidth/FitHeight){ 358 if(image.width>FitWidth){ 359 ImgD.width=FitWidth; 360 ImgD.height=(image.height*FitWidth)/image.width; 361 }else{ 362 ImgD.width=image.width; 363 ImgD.height=image.height; 364 } 365 } else{ 366 if(image.height>FitHeight){ 367 ImgD.height=FitHeight; 368 ImgD.width=(image.width*FitHeight)/image.height; 369 }else{ 370 ImgD.width=image.width; 371 ImgD.height=image.height; 372 } 373 } 374 } 375} 376 377/* 378function getXmlHttpRequest() { 379 380 var sAgent = navigator.userAgent.toLowerCase(); 381 var isIE = (sAgent.indexOf("msie")!=-1); //IE 382 var getInternetExplorerVersion = function(){ 383 var rv = -1; // Return value assumes failure. 384 if (navigator.appName == 'Microsoft Internet Explorer') 385 { 386 var ua = navigator.userAgent; 387 var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 388 if (re.exec(ua) != null) 389 rv = parseFloat( RegExp.$1 ); 390 } 391 return rv; 392 }; 393 394 try{ 395 if(isIE&&getInternetExplorerVersion()<=8&&window.ActiveXObject) 396 return new window.ActiveXObject("Microsoft.XMLHTTP"); 397 } 398 catch(e) { 399 }; 400 401 try{ 402 return new XMLHttpRequest(); 403 } 404 catch(e) { 405 // not a Mozilla or Konqueror based browser 406 }; 407 408 alert('Your browser does not support XMLHttpRequest, required for ' + 409 'WebDAV access.'); 410 throw('Browser not supported'); 411} 412 413function wrapHandler(handler, request, context) { 414 var self = this; 415 function HandlerWrapper() { 416 this.execute = function() { 417 if (request.readyState == 4) { 418 var status = request.status.toString(); 419 var headers = parseHeaders(request.getAllResponseHeaders()); 420 var content = request.responseText; 421 if (status == '207') { 422 //content = self._parseMultiStatus(content); 423 }; 424 var statusstring = "";//davlib.STATUS_CODES[status]; 425 handler.call(context, status, statusstring, 426 content, headers); 427 }; 428 }; 429 }; 430 return (new HandlerWrapper().execute); 431} 432 433function parseHeaders(headerstring) { 434 var lines = headerstring.split('\n'); 435 var headers = {}; 436 for (var i=0; i < lines.length; i++) { 437 var line = $.trim(lines[i]); 438 if (!line) { 439 continue; 440 }; 441 var chunks = line.split(':'); 442 var key = $.trim(chunks.shift()); 443 var value = $.trim(chunks.join(':')); 444 var lkey = key.toLowerCase(); 445 if (headers[lkey] !== undefined) { 446 if (!headers[lkey].push) { 447 headers[lkey] = [headers[lkey, value]]; 448 } else { 449 headers[lkey].push(value); 450 }; 451 } else { 452 headers[lkey] = value; 453 }; 454 }; 455 return headers; 456} 457*/