1//============================================================= 2//== Stylesheets manipulations 3//============================================================= 4function setStateStyleSheet(title, state) { 5 "use strict"; 6 var i, a; 7 for (i=0; (a = document.getElementsByTagName("link")[i]); i++) { 8 if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { 9 if (a.getAttribute("title") == title) a.disabled = !state; 10 } 11 } 12} 13 14function getStateStyleSheet(title, state) { 15 "use strict"; 16 var i, a, rez=-1; 17 for (i=0; (a = document.getElementsByTagName("link")[i]); i++) { 18 if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { 19 if (a.getAttribute("title") == title) { 20 rez = a.disabled ? 0 : 1; 21 break; 22 } 23 } 24 } 25 return rez; 26} 27 28function setActiveStyleSheet(title, disableOther) { 29 "use strict"; 30 var i, a, main; 31 for (i=0; (a = document.getElementsByTagName("link")[i]); i++) { 32 if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { 33 if (disableOther) a.disabled = true; 34 if (a.getAttribute("title") == title) a.disabled = false; 35 } 36 } 37} 38 39function getActiveStyleSheet() { 40 "use strict"; 41 var i, a; 42 for (i=0; (a = document.getElementsByTagName("link")[i]); i++) { 43 if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); 44 } 45 return null; 46} 47 48function getPreferredStyleSheet() { 49 "use strict"; 50 var i, a; 51 for (i=0; (a = document.getElementsByTagName("link")[i]); i++) { 52 if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") ) 53 return a.getAttribute("title"); 54 } 55 return null; 56} 57 58 59//============================================================= 60//== ListBox & ComboBox manipulations 61//============================================================= 62function addListBoxItem(box, val, text) { 63 "use strict"; 64 var item = new Option(); 65 item.value = val; 66 item.text = text; 67 box.options.add(item); 68} 69 70function clearListBox(box) { 71 "use strict"; 72 for (var i=box.options.length-1; i>=0; i--) 73 box.options[i] = null; 74} 75 76function delListBoxItemByValue(box, val) { 77 "use strict"; 78 for (var i=0; i<box.options.length; i++) { 79 if (box.options[i].value == val) { 80 box.options[i] = null; 81 break; 82 } 83 } 84} 85 86function delListBoxItemByText(box, txt) { 87 "use strict"; 88 for (var i=0; i<box.options.length; i++) { 89 if (box.options[i].text == txt) { 90 box.options[i] = null; 91 break; 92 } 93 } 94} 95 96function findListBoxItemByValue(box, val) { 97 "use strict"; 98 var idx = -1; 99 for (var i=0; i<box.options.length; i++) { 100 if (box.options[i].value == val) { 101 idx = i; 102 break; 103 } 104 } 105 return idx; 106} 107 108function findListBoxItemByText(box, txt) { 109 "use strict"; 110 var idx = -1; 111 for (var i=0; i<box.options.length; i++) { 112 if (box.options[i].text == txt) { 113 idx = i; 114 break; 115 } 116 } 117 return idx; 118} 119 120function selectListBoxItemByValue(box, val) { 121 "use strict"; 122 for (var i = 0; i < box.options.length; i++) { 123 box.options[i].selected = (val == box.options[i].value); 124 } 125} 126 127function selectListBoxItemByText(box, txt) { 128 "use strict"; 129 for (var i = 0; i < box.options.length; i++) { 130 box.options[i].selected = (txt == box.options[i].text); 131 } 132} 133 134function getListBoxValues(box) { 135 "use strict"; 136 var delim = arguments[1] ? arguments[1] : ','; 137 var str = ''; 138 for (var i=0; i<box.options.length; i++) { 139 str += (str ? delim : '') + box.options[i].value; 140 } 141 return str; 142} 143 144function getListBoxTexts(box) { 145 "use strict"; 146 var delim = arguments[1] ? arguments[1] : ','; 147 var str = ''; 148 for (var i=0; i<box.options.length; i++) { 149 str += (str ? delim : '') + box.options[i].text; 150 } 151 return str; 152} 153 154function sortListBox(box) { 155 "use strict"; 156 var temp_opts = new Array(); 157 var temp = new Option(); 158 for(var i=0; i<box.options.length; i++) { 159 temp_opts[i] = box.options[i].clone(); 160 } 161 for(var x=0; x<temp_opts.length-1; x++) { 162 for(var y=(x+1); y<temp_opts.length; y++) { 163 if(temp_opts[x].text > temp_opts[y].text) { 164 temp = temp_opts[x]; 165 temp_opts[x] = temp_opts[y]; 166 temp_opts[y] = temp; 167 } 168 } 169 } 170 for(var i=0; i<box.options.length; i++) { 171 box.options[i] = temp_opts[i].clone(); 172 } 173} 174 175function getListBoxSelectedIndex(box) { 176 "use strict"; 177 for (var i = 0; i < box.options.length; i++) { 178 if (box.options[i].selected) 179 return i; 180 } 181 return -1; 182} 183 184function getListBoxSelectedValue(box) { 185 "use strict"; 186 for (var i = 0; i < box.options.length; i++) { 187 if (box.options[i].selected) { 188 return box.options[i].value; 189 } 190 } 191 return null; 192} 193 194function getListBoxSelectedText(box) { 195 "use strict"; 196 for (var i = 0; i < box.options.length; i++) { 197 if (box.options[i].selected) { 198 return box.options[i].text; 199 } 200 } 201 return null; 202} 203 204function getListBoxSelectedOption(box) { 205 "use strict"; 206 for (var i = 0; i < box.options.length; i++) { 207 if (box.options[i].selected) { 208 return box.options[i]; 209 } 210 } 211 return null; 212} 213 214 215//============================================================= 216//== Radiobuttons manipulations 217//============================================================= 218function getRadioGroupValue(radioGroupObj) { 219 "use strict"; 220 for (var i=0; i < radioGroupObj.length; i++) 221 if (radioGroupObj[i].checked) return radioGroupObj[i].value; 222 return null; 223} 224 225function setRadioGroupCheckedByNum(radioGroupObj, num) { 226 "use strict"; 227 for (var i=0; i < radioGroupObj.length; i++) 228 if (radioGroupObj[i].checked && i!=num) radioGroupObj[i].checked=false; 229 else if (i==num) radioGroupObj[i].checked=true; 230} 231 232function setRadioGroupCheckedByValue(radioGroupObj, val) { 233 "use strict"; 234 for (var i=0; i < radioGroupObj.length; i++) 235 if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) radioGroupObj[i].checked=false; 236 else if (radioGroupObj[i].value==val) radioGroupObj[i].checked=true; 237} 238 239 240//============================================================= 241//== Array manipulations 242//============================================================= 243function sortArray(thearray) { 244 "use strict"; 245 var caseSensitive = arguments[1] ? arguments[1] : false;
246 for (var x=0; x<thearray.length-1; x++) { 247 for (var y=(x+1); y<thearray.length; y++) { 248 if (caseSensitive) { 249 if (thearray[x] > thearray[y]) { 250 tmp = thearray[x]; 251 thearray[x] = thearray[y]; 252 thearray[y] = tmp; 253 } 254 } else { 255 if (thearray[x].toLowerCase() > thearray[y].toLowerCase()) { 256 tmp = thearray[x]; 257 thearray[x] = thearray[y]; 258 thearray[y] = tmp; 259 } 260 } 261 } 262 } 263} 264 265 266//============================================================= 267//== String functions 268//============================================================= 269function inList(list, str) { 270 "use strict"; 271 var delim = arguments[2] ? arguments[2] : '|'; 272 var icase = arguments[3] ? arguments[3] : true; 273 var retval = false; 274 if (icase) { 275 str = str.toLowerCase(); 276 list = list.toLowerCase(); 277 } 278 parts = list.split(delim); 279 for (var i=0; i<parts.length; i++) { 280 if (parts[i]==str) { 281 retval=true; 282 break; 283 } 284 } 285 return retval; 286} 287 288function alltrim(str) { 289 "use strict"; 290 var dir = arguments[1] ? arguments[1] : 'a'; 291 var rez = ''; 292 var i, start = 0, end = str.length-1; 293 if (dir=='a' || dir=='l') { 294 for (i=0; i<str.length; i++) { 295 if (str.substr(i,1)!=' ') { 296 start = i; 297 break; 298 } 299 } 300 } 301 if (dir=='a' || dir=='r') { 302 for (i=str.length-1; i>=0; i--) { 303 if (str.substr(i,1)!=' ') { 304 end = i; 305 break; 306 } 307 } 308 } 309 return str.substring(start, end+1); 310} 311 312function ltrim(str) { 313 "use strict"; 314 return alltrim(str, 'l'); 315} 316 317function rtrim(str) { 318 "use strict"; 319 return alltrim(str, 'r'); 320} 321 322function padl(str, len) { 323 "use strict"; 324 var char = arguments[2] ? arguments[2] : ' '; 325 var rez = str.substr(0,len); 326 if (rez.length < len) { 327 for (var i=0; i<len-str.length; i++) 328 rez += char; 329 } 330 return rez; 331} 332 333function padr(str, len) { 334 "use strict"; 335 var char = arguments[2] ? arguments[2] : ' '; 336 var rez = str.substr(0,len); 337 if (rez.length < len) { 338 for (var i=0; i<len-str.length; i++) 339 rez = char + rez; 340 } 341 return rez; 342} 343 344function padc(str, len) { 345 "use strict"; 346 var char = arguments[2] ? arguments[2] : ' '; 347 var rez = str.substr(0,len); 348 if (rez.length < len) { 349 for (var i=0; i<Math.floor((len-str.length)/2); i++) 350 rez = char + rez + char; 351 } 352 return rez+(rez.length<len ? char : ''); 353} 354 355function replicate(str, num) { 356 "use strict"; 357 rez = ''; 358 for (var i=0; i<num; i++) { 359 rez += str; 360 } 361 return rez; 362} 363 364 365//============================================================= 366//== Numbers functions 367//============================================================= 368 369// Clear number from any characters and append it with 0 to desired precision 370function clearNumber(num) { 371 "use strict"; 372 var precision = arguments[1] ? arguments[1] : 0; 373 var defa = arguments[2] ? arguments[2] : 0; 374 var res = ''; 375 var float = -1; 376 num = ""+num; 377 if (num=="") num=""+defa; 378 for (var i=0; i<num.length; i++) { 379 if (float==0) break; 380 else if (float>0) float--; 381 var ch = num.substr(i,1); 382 if (ch=='.') { 383 if (precision>0) { 384 res += ch; 385 } 386 float = precision; 387 } else if ((ch>=0 && ch<=9) || (ch=='-' && i==0)) 388 res+=ch; 389 } 390 if (precision>0 && float!=0) { 391 if (float==-1) { 392 res += '.'; 393 float = precision; 394 } 395 for (i=float; i>0; i--) 396 res +='0'; 397 } 398 //if (isNaN(res)) res = clearNumber(defa, precision, defa); 399 return res; 400} 401 402function dec2hex(n) { 403 "use strict"; 404 return Number(n).toString(16); 405} 406 407function hex2dec(hex) { 408 "use strict"; 409 return parseInt(hex,16); 410} 411 412function roundNumber(num) { 413 "use strict"; 414 var precision = arguments[1] ? arguments[1] : 0; 415 var p = Math.pow(10,precision); 416 return Math.round(num*p)/p; 417} 418 419//============================================================= 420//== Color manipulations 421//============================================================= 422function rgb2hex(color) { 423 "use strict"; 424 var aRGB; 425 color = color.replace(/\s/g,"").toLowerCase(); 426 if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)') 427 color = 'transparent'; 428 if (color.indexOf('rgba(')==0) 429 aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 430 else 431 aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 432 433 if(aRGB) { 434 color = ''; 435 for (var i=1; i<=3; i++) 436 color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1'); 437 } else 438 color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3'); 439 return (color.substr(0,1)!='#' ? '#' : '') + color; 440} 441 442function _rgb2hex(r,g,b) { 443 "use strict"; 444 return '#'+ 445 Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 446 Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 447 Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1'); 448} 449 450function split_rgb(color) { 451 "use strict"; 452 color = rgb2hex(color); 453 var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i); 454 if (!matches) return false;
455 for (var i=1, rgb = new Array(3); i<=3; i++) 456 rgb[i-1] = parseInt(matches[i],16); 457 return rgb; 458} 459 460function iColorPicker(){ 461 "use strict"; 462 var id = arguments[0] ? arguments[0] : "iColorPicker"+Math.round(Math.random()*1000); 463 var colors = arguments[1] ? arguments[1] : 464 '#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,' 465 +'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,' 466 +'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,' 467 +'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,' 468 +'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,' 469 +'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,' 470 +'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026'; 471 var colorsList = colors.split(','); 472 var tbl = '<table class="colorPickerTable"><thead>'; 473 for (var i=0; i<colorsList.length; i++) { 474 if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>'; 475 tbl += '<td style="background-color:'+colorsList[i]+'"> </td>'; 476 } 477 tbl += '</tr></thead><tbody>' 478 + '<tr style="height:60px;">' 479 + '<td colspan="8" id="'+id+'_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 480 + '<input style="width:45px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" maxlength="7" />' 481 + '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>' 482 + '</td>' 483 + '<td colspan="8" id="'+id+'_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 484 + '<input style="width:45px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" readonly="readonly" />' 485 + '</td>' 486 + '</tr></tbody></table>'; 487 //tbl += '<style>#iColorPicker input{margin:2px}</style>'; 488 489 jQuery(document.createElement("div")) 490 .attr("id", id) 491 .css('display','none') 492 .html(tbl) 493 .appendTo("body") 494 .addClass("iColorPickerTable") 495 .on('mouseover', 'thead td', function(){ 496 "use strict"; 497 var aaa=rgb2hex(jQuery(this).css('background-color')); 498 jQuery('#'+id+'_colorPreview').css('background',aaa); 499 jQuery('#'+id+'_colorPreview input').val(aaa); 500 }) 501 .on('keypress', '#'+id+'_colorPreview input', function(key){ 502 "use strict"; 503 var aaa=jQuery(this).val() 504 if (aaa.length<7 && ((key.which>=48 && key.which<=57) || (key.which>=97 && key.which<=102) || (key.which===35 || aaa.length===0))) { 505 aaa += String.fromCharCode(key.which); 506 } else if (key.which == 8 && aaa.length>0) { 507 aaa = aaa.substring(0, aaa.length-1); 508 } else if (key.which===13 && (aaa.length===4 || aaa.length===7)) { 509 var fld = jQuery('#'+id).data('field'); 510 var func = jQuery('#'+id).data('func'); 511 if (func!=null && func!='undefined') { 512 func(fld, aaa); 513 } else { 514 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 515 } 516 jQuery('#'+id+'_Bg').fadeOut(500); 517 jQuery('#'+id).fadeOut(500); 518 519 } else { 520 key.preventDefault(); 521 return false; 522 }
523 if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) { 524 jQuery('#'+id+'_colorPreview').css('background',aaa); 525 } 526 }) 527 .on('click', 'thead td', function(){ 528 "use strict"; 529 var fld = jQuery('#'+id).data('field'); 530 var func = jQuery('#'+id).data('func'); 531 var aaa = rgb2hex(jQuery(this).css('background-color')); 532 if (func!=null && func!='undefined') { 533 func(fld, aaa); 534 } else { 535 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 536 } 537 jQuery('#'+id+'_Bg').fadeOut(500); 538 jQuery('#'+id).fadeOut(500); 539 }) 540 .on('click', 'tbody .iColorPicker_moreColors', function(){ 541 "use strict"; 542 var thead = jQuery(this).parents('table').find('thead'); 543 var out = ''; 544 if (thead.hasClass('more_colors')) { 545 for (var i=0; i<colorsList.length; i++) { 546 if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 547 out += '<td style="background-color:'+colorsList[i]+'"> </td>'; 548 } 549 thead.removeClass('more_colors').empty().html(out+'</tr>'); 550 jQuery('#'+id+'_colorPreview').attr('colspan', 8); 551 jQuery('#'+id+'_colorOriginal').attr('colspan', 8); 552 } else { 553 var rgb=[0,0,0], i=0, j=-1; // Set j=-1 or j=0 - show 2 different colors layouts 554 while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) { 555 if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 556 i++; 557 out += '<td style="background-color:'+_rgb2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'"> </td>'; 558 rgb[2]+=3; 559 if (rgb[2]>0xF) { 560 rgb[1]+=3; 561 if (rgb[1]>(j===0 ? 6 : 0xF)) { 562 rgb[0]+=3; 563 if (rgb[0]>0xF) { 564 if (j===0) { 565 j=1; 566 rgb[0]=0; 567 rgb[1]=9; 568 rgb[2]=0; 569 } else { 570 break; 571 } 572 } else { 573 rgb[1]=(j < 1 ? 0 : 9); 574 rgb[2]=0; 575 } 576 } else { 577 rgb[2]=0; 578 } 579 } 580 } 581 thead.addClass('more_colors').empty().html(out+'<td style="background-color:#ffffff" colspan="8"> </td></tr>'); 582 jQuery('#'+id+'_colorPreview').attr('colspan', 9); 583 jQuery('#'+id+'_colorOriginal').attr('colspan', 9); 584 } 585 jQuery('#'+id+' table.colorPickerTable thead td') 586 .css({ 587 'width':'12px', 588 'height':'14px', 589 'border':'1px solid #000', 590 'cursor':'pointer' 591 }); 592 }); 593 jQuery(document.createElement("div")) 594 .attr("id", id+"_Bg") 595 .click(function() { 596 "use strict"; 597 jQuery("#"+id+"_Bg").fadeOut(500); 598 jQuery("#"+id).fadeOut(500); 599 }) 600 .appendTo("body"); 601 jQuery('#'+id+' table.colorPickerTable thead td') 602 .css({ 603 'width':'12px', 604 'height':'14px', 605 'border':'1px solid #000', 606 'cursor':'pointer' 607 }); 608 jQuery('#'+id+' table.colorPickerTable') 609 .css({'border-collapse':'collapse'}); 610 jQuery('#'+id) 611 .css({ 612 'border':'1px solid #ccc', 613 'background':'#333', 614 'padding':'5px', 615 'color':'#fff', 616 'z-index':999999 617 }); 618 jQuery('#'+id+'_colorPreview') 619 .css({'height':'50px'}); 620 return id; 621} 622 623function iColorShow(id, fld, func) { 624 "use strict"; 625 if (id===null || id==='') { 626 id = jQuery('.iColorPickerTable').attr('id'); 627 } 628 var eICP = fld.offset(); 629 var w = jQuery('#'+id).width(); 630 var h = jQuery('#'+id).height(); 631 var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w; 632 var t = eICP.top + fld.outerHeight() + h < jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top + h; 633 jQuery("#"+id) 634 .data({field: fld, func: func}) 635 .css({ 636 'top':t+"px", 637 'left':l+"px", 638 'position':'absolute', 639 'z-index':10001 640 }) 641 .fadeIn(500); 642 jQuery("#"+id+"_Bg") 643 .css({ 644 'position':'fixed', 645 'z-index':10000, 646 'top':0, 647 'left':0, 648 'width':'100%', 649 'height':'100%' 650 }) 651 .fadeIn(500); 652 var def = fld.val().substr(0, 1)=='#' ? fld.val() : rgb2hex(fld.css('backgroundColor')); 653 jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def); 654 jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def); 655} 656 657 658//============================================================= 659//== Cookies manipulations 660//============================================================= 661function getCookie(name) { 662 "use strict"; 663 var defa = arguments[1]!='undefined' ? arguments[1] : null; 664 var start = document.cookie.indexOf(name + '='); 665 var len = start + name.length + 1; 666 if ((!start) && (name != document.cookie.substring(0, name.length))) { 667 return defa; 668 } 669 if (start == -1) 670 return defa; 671 var end = document.cookie.indexOf(';', len); 672 if (end == -1) 673 end = document.cookie.length; 674 return unescape(document.cookie.substring(len, end)); 675} 676 677 678function setCookie(name, value, expires, path, domain, secure) { 679 "use strict"; 680 var today = new Date(); 681 today.setTime(today.getTime()); 682 if (expires) { 683 expires = expires * 1000; // * 60 * 60 * 24; 684 } 685 var expires_date = new Date(today.getTime() + (expires)); 686 document.cookie = name + '=' 687 + escape(value) 688 + ((expires) ? ';expires=' + expires_date.toGMTString() : '') 689 + ((path) ? ';path=' + path : '') 690 + ((domain) ? ';domain=' + domain : '') 691 + ((secure) ? ';secure' : ''); 692} 693 694 695function deleteCookie(name, path, domain) { 696 "use strict"; 697 if (getCookie(name)) 698 document.cookie = name + '=' + ((path) ? ';path=' + path : '') 699 + ((domain) ? ';domain=' + domain : '') 700 + ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 701} 702 703 704//============================================================= 705//== Date manipulations 706//============================================================= 707 708// Return array[Year, Month, Day, Hours, Minutes, Seconds] 709// from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds 710function dateParse(dt) { 711 "use strict"; 712 dt = dt.replace(/\//g, '-').replace(/\./g, '-').replace(/T/g, ' ').split('+')[0]; 713 var dt2 = dt.split(' '); 714 var d = dt2[0].split('-'); 715 var t = dt2[1].split(':'); 716 d.push(t[0], t[1], t[2]); 717 return d; 718} 719 720function dateDifference(dt1, dt2, short, sec) { 721 "use strict"; 722 var dt2 = arguments[1]!==undefined ? arguments[1] : ''; 723 var short = arguments[2]!==undefined ? arguments[2] : true; 724 var sec = arguments[3]!==undefined ? arguments[3] : false;
725 var a1 = dateParse(dt1); 726 dt1 = Date.UTC(a1[0], a1[1], a1[2], a1[3], a1[4], a1[5]); 727 if (dt2 == '') { 728 dt2 = new Date(); 729 var a2 = [dt2.getFullYear(), dt2.getMonth()+1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()]; 730 } else 731 var a2 = dateParse(dt2); 732 dt2 = Date.UTC(a2[0], a2[1], a2[2], a2[3], a2[4], a2[5]); 733 var diff = Math.round((dt2 - dt1)/1000); 734 var days = Math.floor(diff / (24*3600)); 735 diff -= days * 24 * 3600; 736 var hours = Math.floor(diff / 3600); 737 diff -= hours * 3600; 738 var minutes = Math.floor(diff / 60); 739 diff -= minutes * 60; 740 rez = ''; 741 if (days > 0) 742 rez += (rez!='' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : ''); 743 if ((!short || rez=='') && hours > 0) 744 rez += (rez!='' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : ''); 745 if ((!short || rez=='') && minutes > 0) 746 rez += (rez!='' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : ''); 747 if (sec || rez=='') 748 rez += rez!='' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute'; 749 return rez; 750} 751 752 753 754//============================================================= 755//== Form validation 756//============================================================= 757/* 758 // Usage example: 759 var error = formValidate(jQuery(form_selector), { // -------- Options 760 error_message_show: true, // Display or not error message 761 error_message_time: 5000, // Time to display error message 762 error_message_class: 'sc_infobox sc_infobox_style_error', // Class, appended to error message block 763 error_message_text: 'Global error text', // Global error message text (if don't write message in checked field) 764 error_fields_class: 'error_fields_class', // Class, appended to error fields 765 exit_after_first_error: false, // Cancel validation and exit after first error 766 rules: [ 767 { 768 field: 'author', // Checking field name 769 min_length: { value: 1, message: 'The author name can\'t be empty' }, // Min character count (0 - don't check), message - if error occurs 770 max_length: { value: 60, message: 'Too long author name'} // Max character count (0 - don't check), message - if error occurs 771 }, 772 { 773 field: 'email', 774 min_length: { value: 7, message: 'Too short (or empty) email address' }, 775 max_length: { value: 60, message: 'Too long email address'}, 776 mask: { value: '^([a-z0-9_\\-]+\\.)*[a-z0-9_\\-]+@[a-z0-9_\\-]+(\\.[a-z0-9_\\-]+)*\\.[a-z]{2,6}$', message: 'Invalid email address'} 777 }, 778 { 779 field: 'comment', 780 min_length: { value: 1, message: 'The comment text can\'t be empty' }, 781 max_length: { value: 200, message: 'Too long comment'} 782 }, 783 { 784 field: 'pwd1', 785 min_length: { value: 5, message: 'The password can\'t be less then 5 characters' }, 786 max_length: { value: 20, message: 'Too long password'} 787 }, 788 { 789 field: 'pwd2', 790 equal_to: { value: 'pwd1', message: 'The passwords in both fields must be equals' } 791 } 792 ] 793 }); 794*/ 795 796function formValidate(form, opt) { 797 "use strict"; 798 var error_msg = ''; 799 form.find(":input").each(function() { 800 "use strict"; 801 if (error_msg!='' && opt.exit_after_first_error) return; 802 for (var i = 0; i < opt.rules.length; i++) { 803 if (jQuery(this).attr("name") == opt.rules[i].field) { 804 var val = jQuery(this).val(); 805 var error = false; 806 if (typeof(opt.rules[i].min_length) == 'object') { 807 if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) { 808 if (error_msg=='') jQuery(this).get(0).focus(); 809 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].min_length.message)!='undefined' ? opt.rules[i].min_length.message : opt.error_message_text ) + '</p>' 810 error = true; 811 } 812 } 813 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') { 814 if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) { 815 if (error_msg=='') jQuery(this).get(0).focus(); 816 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].max_length.message)!='undefined' ? opt.rules[i].max_length.message : opt.error_message_text ) + '</p>' 817 error = true; 818 } 819 } 820 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') { 821 if (opt.rules[i].mask.value != '') { 822 var regexp = new RegExp(opt.rules[i].mask.value); 823 if (!regexp.test(val)) { 824 if (error_msg=='') jQuery(this).get(0).focus(); 825 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>' 826 error = true; 827 } 828 } 829 } 830 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') { 831 if (opt.rules[i].equal_to.value != '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) { 832 if (error_msg=='') jQuery(this).get(0).focus(); 833 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].equal_to.message)!='undefined' ? opt.rules[i].equal_to.message : opt.error_message_text ) + '</p>' 834 error = true; 835 } 836 } 837 if (opt.error_fields_class != '') jQuery(this).toggleClass(opt.error_fields_class, error); 838 } 839 } 840 }); 841 if (error_msg!='' && opt.error_message_show) { 842 THEMEREX_error_msg_box = form.find(".result"); 843 if (THEMEREX_error_msg_box.length == 0) { 844 form.append('<div class="result"></div>'); 845 THEMEREX_error_msg_box = form.find(".result"); 846 } 847 if (opt.error_message_class) THEMEREX_error_msg_box.toggleClass(opt.error_message_class, true); 848 THEMEREX_error_msg_box.html(error_msg).fadeIn(); 849 setTimeout(function() { THEMEREX_error_msg_box.fadeOut(); }, opt.error_message_time); 850 } 851 return error_msg!=''; 852} 853 854 855 856 857 858//============================================================= 859//== Debug functions 860//============================================================= 861function objDisplay(obj) { 862 "use strict"; 863 var html = arguments[1] ? arguments[1] : false; // Tags decorate 864 var recursive = arguments[2] ? arguments[2] : false; // Show inner objects (arrays) 865 var showMethods = arguments[3] ? arguments[3] : false; // Show object's methods 866 var level = arguments[4] ? arguments[4] : 0; // Nesting level (for inner use only) 867 var dispStr = ""; 868 var addStr = ""; 869 if (level>0) { 870 dispStr += (obj===null ? "null" : "Object") + (html ? "\n<br />" : "\n"); 871 addStr = replicate(html ? ' ' : ' ', level*2); 872 } 873 if (obj!==null) { 874 for (var prop in obj) { 875 if (!showMethods && typeof(obj[prop])=='function') // || prop=='innerHTML' || prop=='outerHTML' || prop=='innerText' || prop=='outerText') 876 continue; 877 if (recursive && (typeof(obj[prop])=='object' || typeof(obj[prop])=='array') && obj[prop]!=obj) 878 dispStr += addStr + (html ? "<b>" : "")+prop+(html ? "</b>" : "")+'='+objDisplay(obj[prop], html, recursive, showMethods, level+1); 879 else 880 dispStr += addStr + (html ? "<b>" : "")+prop+(html ? "</b>" : "")+'='+(typeof(obj[prop])=='string' ? '"' : '')+obj[prop]+(typeof(obj[prop])=='string' ? '"' : '')+(html ? "\n<br />" : "\n"); 881 } 882 }
883 return dispStr; 884}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.