|
From: FlorinCB <ory...@us...> - 2008-09-18 00:43:54
|
Update of /cvsroot/mxbb/mx_music/phpbb2/mx_mod/mx_shared/lib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19367/mx_mod/mx_shared/lib Added Files: Array.js Common.js Cookie.js Debug.js DynamicOptionList.js DynamicOptionList_comp.js String.js Toggle.js Validate.js index.htm Log Message: upgrade --- NEW FILE: Array.js --- /* * DO NOT REMOVE THIS NOTICE * * PROJECT: js libs * COPYRIGHT: (c) 2003,2004 Cezary Tomczak * LINK: http://gosu.pl * LICENSE: BSD (revised) */ /* Check whether array contains given string */ Array.prototype.contains = function(s) { for (var i = 0; i < this.length; ++i) { if (this[i] === s) { return true; } } return false; }; /* Indicates whether some other array is "equal to" this one */ Array.prototype.equals = function(a) { if (this.length != a.length) { return false; } for (var i = 0; i < this.length; ++i) { if (this[i] !== a[i]) { return false; } } return true; }; /* Finds the index of the first occurence of item in the array, or -1 if not found */ Array.prototype.indexOf = function(item) { for (var i = 0; i < this.length; ++i) { if (this[i] === item) { return i; } } return -1; }; /* Get the last element from the array */ Array.prototype.getLast = function() { return this[this.length-1]; }; /* Remove elements judged 'false' by the passed function (mutates) */ Array.prototype.filter = function(func) { var i, indexes = []; for (i = 0; i < this.length; ++i) { if (!func(this[i])) { indexes.push(i); } } for (i = indexes.length - 1; i >= 0; --i) { this.splice(indexes[i], 1); } }; /* Apply custom function to every element of an array (mutates) */ Array.prototype.map = function(func) { for (var i = 0; i < this.length; ++i) { this[i] = func(this[i]); } }; /* Push an element at specified index */ Array.prototype.pushAtIndex = function(el, index) { this.splice(index, 0, el); }; /* Remove element with given index (mutates) */ Array.prototype.removeByIndex = function(index) { this.splice(index, 1); }; /* Remove elements with such value (mutates) */ Array.prototype.removeByValue = function(value) { var i, indexes = []; for (i = 0; i < this.length; ++i) { if (this[i] === value) { indexes.push(i); } } for (i = indexes.length - 1; i >= 0; --i) { this.splice(indexes[i], 1); } }; /* Remove duplicate values (mutates) * Dependencies: Array.indexOf() */ Array.prototype.removeDuplicates = function() { var i, unique = [], indexes = []; for (i = 0; i < this.length; ++i) { if (unique.indexOf(this[i]) == -1) { unique.push(this[i]); } else { indexes.push(i); } } for (i = indexes.length - 1; i >= 0; --i) { this.splice(indexes[i], 1); } }; /* Returns copy of an array */ Array.prototype.copy = function() { var copy = []; for (var i = 0; i < this.length; ++i) { copy[i] = (typeof this[i].copy != "undefined") ? this[i].copy() : this[i]; } return copy; }; /* Swaps the values of two indicies (mutates) */ Array.prototype.swap = function(index1, index2) { var temp = this[index1]; this[index1] = this[index2]; this[index2] = temp; }; /* Randomly shuffles array (mutates) * Dependencies: Array.swap() */ Array.prototype.shuffle = function() { for (var i = 0; i < this.length; ++i) { var ind1 = Math.floor(Math.random() * this.length); var ind2 = Math.floor(Math.random() * this.length); this.swap(ind1, ind2); } }; --- NEW FILE: String.js --- /* * DO NOT REMOVE THIS NOTICE * * PROJECT: js libs * COPYRIGHT: (c) 2003,2004 Cezary Tomczak * LINK: http://gosu.pl * LICENSE: BSD (revised) */ /* Strip whitespace from the beginning and end of a string */ String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g, ""); }; /* Strip whitespace from the beginning of a string */ String.prototype.ltrim = function() { return this.replace(/^\s*/g, ""); }; /* Strip whitespace from the end of a string */ String.prototype.rtrim = function() { return this.replace(/\s*$/g, ""); }; /* Count the number of substring occurrences */ String.prototype.substrCount = function(s) { return this.split(s).length - 1; }; /* Check if string is an alphanumeric character */ String.prototype.isAlpha = function() { return (/^[a-z]$/i.test(this)); }; /* Check if string is a digit */ String.prototype.isDigit = function() { return (/^\d$/.test(this)); }; /* Check if string is numeric */ String.prototype.isNumeric = function() { return (/^\d+$/.test(this)); }; /* * Replace ? tokens with variables passed as arguments in a string. * When you are joining many strings with variables, this is a good way to keep the code clean * Examples: * var s = '<div id="'+id+'" class="'+className+'">'+innerText+'</div>'; * var s = '<div id="?" class="?">?</div>'.format(id, className, innerText); */ String.prototype.format = function() { if (!arguments.length) { throw "String.format() failed, no arguments passed, this = "+this; } var tokens = this.split("?"); if (arguments.length != (tokens.length - 1)) { throw "String.format() failed, tokens != arguments, this = "+this; } var s = tokens[0]; for (var i = 0; i < arguments.length; ++i) { s += (arguments[i] + tokens[i + 1]); } return s; }; /* Repeat string n times */ String.prototype.repeat = function(n) { var ret = ""; for (var i = 0; i < n; ++i) { ret += this; } return ret; }; --- NEW FILE: Toggle.js --- function mx_toggle(in_buttonSwitch, in_listID, img_expand, img_contract) { if (document.getElementById) { listID = document.getElementById(in_listID); } else { return; } if (listID.style.display == '') { listID.style.display = 'none'; in_buttonSwitch.innerHTML = '<img src="' + img_expand + '" border="0" />'; rollup_record_state(in_listID, 0); } else { listID.style.display = ''; in_buttonSwitch.innerHTML = '<img src="' + img_contract + '" border="0" />'; rollup_record_state(in_listID, 1); } if (window.event) { window.event.cancelBubble=true; } } function mx_toggle_editCP(in_buttonSwitch, in_listID, img_expand, img_contract) { var in_listID; var inc = 0; var listID = document.all ? document.all : document.getElementsByTagName("*"); if (listID == null){ return; } for (var i=0;i<listID.length;i++){ if (listID[i].className==in_listID){ if (listID[i].style.display == '') { listID[i].style.display = 'none'; in_buttonSwitch.innerHTML = '<img src="' + img_expand + '" border="0" />'; var send_cookie = 0; } else { listID[i].style.display = ''; in_buttonSwitch.innerHTML = '<img src="' + img_contract + '" border="0" />'; var send_cookie = 1; } if (window.event) { window.event.cancelBubble=true; } } } if (send_cookie == 1) { rollup_record_state(in_listID, 1); } else { rollup_record_state(in_listID, 0); } } function rollup_record_state(in_listID, status) { var expDate = new Date(); // expires in 1 year expDate.setTime(expDate.getTime() + 31536000000); document.cookie = in_listID + "=" + escape(status) + "; expires=" + expDate.toGMTString(); } function ref(object) { if (document.getElementById) { return document.getElementById(object); } else if (document.all) { return eval('document.all.' + object); } else { return false; } } function expand(object) { object = ref(object); if( !object.style ) { return false; } else { object.style.display = ''; } if (window.event) { window.event.cancelBubble = true; } } function contract(object) { object = ref(object); if( !object.style ) { return false; } else { object.style.display = 'none'; } if (window.event) { window.event.cancelBubble = true; } } function toggle(object, path) { image = ref(object + '_img'); object = ref(object); if( !object.style ) { return false; } if( object.style.display == 'none' ) { object.style.display = ''; image.src = path + 'contract.gif'; } else { object.style.display = 'none'; image.src = path + 'expand.gif'; } } --- NEW FILE: Debug.js --- /* * DO NOT REMOVE THIS NOTICE * * PROJECT: js libs * COPYRIGHT: (c) 2003,2004 Cezary Tomczak * LINK: http://gosu.pl * LICENSE: BSD (revised) */ var debugWindow = null; function debug(s, name) { if (!debugWindow) { debugWindow = window.open("", "debugWindow", "width=400,height=500,scrollbars=yes,resizable=yes"); debugWindow.document.write("<pre>"); } if (name) { debugWindow.document.write('<div style="font: 12px sans-serif; font-weight: bold;">'+name+'</div>'); } debugWindow.document.write(s + "\n"); } function debugObject(obj, name) { var s = ''; for (var i in obj) { if (obj[i] && (typeof obj[i] == "object" || typeof obj[i] == "function") && obj[i].toString) { s += "Object." + i + "=" + obj[i].toString().replace(/\n/g, "") + "\n"; } else { s += "Object." + i + "=" + obj[i] + "\n"; } } debug(s, name); } function debugArray(arr, name) { var s = ''; for (var i = 0; i < arr.length; ++i) { s += "Array[" + i + "]=" + arr[i] + "\n"; } debug(s, name); } --- NEW FILE: index.htm --- <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> </body> </html> --- NEW FILE: Common.js --- /* * mxBB - common js */ function newImage(arg) { if (document.images) { rslt = new Image(); rslt.src = arg; return rslt; } } function changeImages() { if (document.images ) { for (var i=0; i<changeImages.arguments.length; i+=2) { document[changeImages.arguments[i]].src = changeImages.arguments[i+1]; } } } function full_img(url) { var url = url; window.open(url,'','scrollbars=1,toolbar=0,resizable=1,menubar=0,directories=0,status=0, width=img.width, height=img.height'); return; } function getCookie(name) { var cookies = document.cookie; var start = cookies.indexOf(name + '='); if( start < 0 ) return null; var len = start + name.length + 1; var end = cookies.indexOf(';', len); if( end < 0 ) end = cookies.length; return unescape(cookies.substring(len, end)); } function setCookie(name, value, expires, path, domain, secure) { document.cookie = name + '=' + escape (value) + ((expires) ? '; expires=' + ( (expires == 'never') ? 'Thu, 31-Dec-2099 23:59:59 GMT' : expires.toGMTString() ) : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : ''); } function delCookie(name, path, domain) { if( getCookie(name) ) { document.cookie = name + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT' + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : ''); } } function set_mx_cookie(in_listID, status) { var expDate = new Date(); // expires in 1 year expDate.setTime(expDate.getTime() + 31536000000); document.cookie = in_listID + "=" + escape(status) + "; expires=" + expDate.toGMTString(); } function set_phpbb_cookie(cookieName, cookieValue, lifeTime, path, domain, isSecure) { var expDate = new Date(); // expires in 1 year expDate.setTime(expDate.getTime() + 31536000000); document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) + ";expires=" + expDate.toGMTString() + ( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") + ( isSecure == 1 ? ";secure" : ""); } --- NEW FILE: DynamicOptionList_comp.js --- // =================================================================== // Author: Matt Kruse <ma...@ma...> // WWW: http://www.mattkruse.com/ // // NOTICE: You may use this code for any purpose, commercial or // private, without any further permission from the author. You may // remove this notice from your final code if you wish, however it is // appreciated by the author if at least my web site address is kept. // // You may *NOT* re-distribute this code in any way except through its // use. That means, you can include it in your product, or your web // site, or any other form where the code is actually being used. You // may not put the plain javascript up on your site for download or // include it in your javascript libraries for download. // If you wish to share this code with others, please just point them // to the URL instead. // Please DO NOT link directly to my .js files from your site. Copy // the files to your server and use them there. Thank you. // =================================================================== var dynamicOptionListCount=0;var dynamicOptionListObjects = new Array(); function initDynamicOptionLists(){for(var i=0;i<dynamicOptionListObjects.length;i++){var dol = dynamicOptionListObjects[i];if(dol.formName!=null){dol.form = document.forms[dol.formName];}else if(dol.formIndex!=null){dol.form = document.forms[dol.formIndex];}else{var name = dol.fieldNames[0][0];for(var f=0;f<document.forms.length;f++){if(typeof(document.forms[f][name])!="undefined"){dol.form = document.forms[f];break;}}if(dol.form==null){alert("ERROR: Couldn't find form element "+name+" in any form on the page! Init aborted");return;}}for(var j=0;j<dol.fieldNames.length;j++){for(var k=0;k<dol.fieldNames[j].length-1;k++){var selObj = dol.form[dol.fieldNames[j][k]];if(typeof(selObj)=="undefined"){alert("Select box named "+dol.fieldNames[j][k]+" could not be found in the form. Init aborted");return;}if(k==0){if(selObj.options!=null){for(l=0;l<selObj.options.length;l++){var sopt = selObj.options[l];var m = dol.findMatchingOptionInArray(dol.options,sopt.text,sopt.value,false);if(m!=null){var reselectForNN6 = sopt.selected;var m2 = new Option(sopt.text, sopt.value, sopt.defaultSelected, sopt.selected);m2.selected = sopt.selected;m2.defaultSelected = sopt.defaultSelected;m2.DOLOption = m;selObj.options[l] = m2;selObj.options[l].selected = reselectForNN6;}}}}if(selObj.onchange==null){selObj.onchange = new Function("dynamicOptionListObjects["+dol.index+"].change(this)");}}}}resetDynamicOptionLists();} function resetDynamicOptionLists(theform){for(var i=0;i<dynamicOptionListObjects.length;i++){var dol = dynamicOptionListObjects[i];if(typeof(theform)=="undefined" || theform==null || theform==dol.form){for(var j=0;j<dol.fieldNames.length;j++){dol.change(dol.form[dol.fieldNames[j][0]],true);}}}} function DOLOption(text,value,defaultSelected,selected){this.text = text;this.value = value;this.defaultSelected = defaultSelected;this.selected = selected;this.options = new Array();return this;} function DynamicOptionList(){this.form = null;this.options = new Array();this.longestString = new Array();this.numberOfOptions = new Array();this.currentNode = null;this.currentField = null;this.currentNodeDepth = 0;this.fieldNames = new Array();this.formIndex = null;this.formName = null;this.fieldListIndexes = new Object();this.fieldIndexes = new Object();this.selectFirstOption = true;this.numberOfOptions = new Array();this.longestString = new Array();this.values = new Object();this.forValue = DOL_forValue;this.forText = DOL_forText;this.forField = DOL_forField;this.forX = DOL_forX;this.addOptions = DOL_addOptions;this.addOptionsTextValue = DOL_addOptionsTextValue;this.setDefaultOptions = DOL_setDefaultOptions;this.setValues = DOL_setValues;this.setValue = DOL_setValues;this.setFormIndex = DOL_setFormIndex;this.setFormName = DOL_setFormName;this.printOptions = DOL_printOptions;this.addDependentFields = DOL_addDependentFields;this.change = DOL_change;this.child = DOL_child;this.selectChildOptions = DOL_selectChildOptions;this.populateChild = DOL_populateChild;this.change = DOL_change;this.addNewOptionToList = DOL_addNewOptionToList;this.findMatchingOptionInArray = DOL_findMatchingOptionInArray;if(arguments.length > 0){for(var i=0;i<arguments.length;i++){this.fieldListIndexes[arguments[i].toString()] = this.fieldNames.length;this.fieldIndexes[arguments[i].toString()] = i;}this.fieldNames[this.fieldNames.length] = arguments;}this.index = window.dynamicOptionListCount++;window["dynamicOptionListObjects"][this.index] = this;} function DOL_findMatchingOptionInArray(a,text,value,exactMatchRequired){if(a==null || typeof(a)=="undefined"){return null;}var value_match = null;var text_match = null;for(var i=0;i<a.length;i++){var opt = a[i];if(opt.value==value && opt.text==text){return opt;}if(!exactMatchRequired){if(value_match==null && value!=null && opt.value==value){value_match = opt;}if(text_match==null && text!=null && opt.text==text){text_match = opt;}}}return(value_match!=null)?value_match:text_match;} function DOL_forX(s,type){if(this.currentNode==null){this.currentNodeDepth=0;}var useNode =(this.currentNode==null)?this:this.currentNode;var o = this.findMatchingOptionInArray(useNode["options"],(type=="text")?s:null,(type=="value")?s:null,false);if(o==null){o = new DOLOption(null,null,false,false);o[type] = s;useNode.options[useNode.options.length] = o;}this.currentNode = o;this.currentNodeDepth++;return this;} function DOL_forValue(s){return this.forX(s,"value");} function DOL_forText(s){return this.forX(s,"text");} function DOL_forField(f){this.currentField = f;return this;} function DOL_addNewOptionToList(a, text, value, defaultSelected){var o = new DOLOption(text,value,defaultSelected,false);if(a==null){a = new Array();}for(var i=0;i<a.length;i++){if(a[i].text==o.text && a[i].value==o.value){if(o.selected){a[i].selected=true;}if(o.defaultSelected){a[i].defaultSelected = true;}return a;}}a[a.length] = o;} function DOL_addOptions(){if(this.currentNode==null){this.currentNode = this;}if(this.currentNode["options"] == null){this.currentNode["options"] = new Array();}for(var i=0;i<arguments.length;i++){var text = arguments[i];this.addNewOptionToList(this.currentNode.options,text,text,false);if(typeof(this.numberOfOptions[this.currentNodeDepth])=="undefined"){this.numberOfOptions[this.currentNodeDepth]=0;}if(this.currentNode.options.length > this.numberOfOptions[this.currentNodeDepth]){this.numberOfOptions[this.currentNodeDepth] = this.currentNode.options.length;}if(typeof(this.longestString[this.currentNodeDepth])=="undefined" ||(text.length > this.longestString[this.currentNodeDepth].length)){this.longestString[this.currentNodeDepth] = text;}}this.currentNode = null;this.currentNodeDepth = 0;} function DOL_addOptionsTextValue(){if(this.currentNode==null){this.currentNode = this;}if(this.currentNode["options"] == null){this.currentNode["options"] = new Array();}for(var i=0;i<arguments.length;i++){var text = arguments[i++];var value = arguments[i];this.addNewOptionToList(this.currentNode.options,text,value,false);if(typeof(this.numberOfOptions[this.currentNodeDepth])=="undefined"){this.numberOfOptions[this.currentNodeDepth]=0;}if(this.currentNode.options.length > this.numberOfOptions[this.currentNodeDepth]){this.numberOfOptions[this.currentNodeDepth] = this.currentNode.options.length;}if(typeof(this.longestString[this.currentNodeDepth])=="undefined" ||(text.length > this.longestString[this.currentNodeDepth].length)){this.longestString[this.currentNodeDepth] = text;}}this.currentNode = null;this.currentNodeDepth = 0;} function DOL_child(obj){var listIndex = this.fieldListIndexes[obj.name];var index = this.fieldIndexes[obj.name];if(index <(this.fieldNames[listIndex].length-1)){return this.form[this.fieldNames[listIndex][index+1]];}return null;} function DOL_setDefaultOptions(){if(this.currentNode==null){this.currentNode = this;}for(var i=0;i<arguments.length;i++){var o = this.findMatchingOptionInArray(this.currentNode.options,null,arguments[i],false);if(o!=null){o.defaultSelected = true;}}this.currentNode = null;} function DOL_setValues(){if(this.currentField==null){alert("Can't call setValues() without using forField() first!");return;}if(typeof(this.values[this.currentField])=="undefined"){this.values[this.currentField] = new Object();}for(var i=0;i<arguments.length;i++){this.values[this.currentField][arguments[i]] = true;}this.currentField = null;} function DOL_setFormIndex(i){this.formIndex = i;} function DOL_setFormName(n){this.formName = n;} function DOL_printOptions(name){if((navigator.appName == 'Netscape') &&(parseInt(navigator.appVersion) <= 4)){var index = this.fieldIndexes[name];var ret = "";if(typeof(this.numberOfOptions[index])!="undefined"){for(var i=0;i<this.numberOfOptions[index];i++){ret += "<OPTION>";}}ret += "<OPTION>";if(typeof(this.longestString[index])!="undefined"){for(var i=0;i<this.longestString[index].length;i++){ret += "_";}}document.writeln(ret);}} function DOL_addDependentFields(){for(var i=0;i<arguments.length;i++){this.fieldListIndexes[arguments[i].toString()] = this.fieldNames.length;this.fieldIndexes[arguments[i].toString()] = i;}this.fieldNames[this.fieldNames.length] = arguments;} function DOL_change(obj, usePreselected){if(usePreselected==null || typeof(usePreselected)=="undefined"){usePreselected = false;}var changedListIndex = this.fieldListIndexes[obj.name];var changedIndex = this.fieldIndexes[obj.name];var child = this.child(obj);if(child == null){return;}if(obj.type == "select-one"){if(child.options!=null){child.options.length=0;}if(obj.options!=null && obj.options.length>0 && obj.selectedIndex>=0){var o = obj.options[obj.selectedIndex];this.populateChild(o.DOLOption,child,usePreselected);this.selectChildOptions(child,usePreselected);}}else if(obj.type == "select-multiple"){var currentlySelectedOptions = new Array();if(!usePreselected){for(var i=0;i<child.options.length;i++){var co = child.options[i];if(co.selected){this.addNewOptionToList(currentlySelectedOptions, co.text, co.value, co.defaultSelected);}}}child.options.length=0;if(obj.options!=null){var obj_o = obj.options;for(var i=0;i<obj_o.length;i++){if(obj_o[i].selected){this.populateChild(obj_o[i].DOLOption,child,usePreselected);}}var atLeastOneSelected = false;if(!usePreselected){for(var i=0;i<child.options.length;i++){var m = this.findMatchingOptionInArray(currentlySelectedOptions,child.options[i].text,child.options[i].value,true);if(m!=null){child.options[i].selected = true;atLeastOneSelected = true;}}}if(!atLeastOneSelected){this.selectChildOptions(child,usePreselected);}}}this.change(child,usePreselected);} function DOL_populateChild(dolOption,childSelectObj,usePreselected){if(dolOption!=null && dolOption.options!=null){for(var j=0;j<dolOption.options.length;j++){var srcOpt = dolOption.options[j];if(childSelectObj.options==null){childSelectObj.options = new Array();}var duplicate = false;var preSelectedExists = false;for(var k=0;k<childSelectObj.options.length;k++){var csi = childSelectObj.options[k];if(csi.text==srcOpt.text && csi.value==srcOpt.value){duplicate = true;break;}}if(!duplicate){var newopt = new Option(srcOpt.text, srcOpt.value, false, false);newopt.selected = false;newopt.defaultSelected = false;newopt.DOLOption = srcOpt;childSelectObj.options[childSelectObj.options.length] = newopt;}}}} function DOL_selectChildOptions(obj,usePreselected){var values = this.values[obj.name];var preselectedExists = false;if(usePreselected && values!=null && typeof(values)!="undefined"){for(var i=0;i<obj.options.length;i++){var v = obj.options[i].value;if(v!=null && values[v]!=null && typeof(values[v])!="undefined"){preselectedExists = true;break;}}}var atLeastOneSelected = false;for(var i=0;i<obj.options.length;i++){var o = obj.options[i];if(preselectedExists && o.value!=null && values[o.value]!=null && typeof(values[o.value])!="undefined"){o.selected = true;atLeastOneSelected = true;}else if(!preselectedExists && o.DOLOption!=null && o.DOLOption.defaultSelected){o.selected = true;atLeastOneSelected = true;}else{o.selected = false;}}if(this.selectFirstOption && !atLeastOneSelected && obj.options.length>0){obj.options[0].selected = true;}else if(!atLeastOneSelected && obj.type=="select-one"){obj.selectedIndex = -1;}} --- NEW FILE: Cookie.js --- /* * DO NOT REMOVE THIS NOTICE * * PROJECT: js libs * COPYRIGHT: (c) 2003,2004 Cezary Tomczak * LINK: http://gosu.pl * LICENSE: BSD (revised) */ /* examples: 1) set cookie for an hour var c = new Cookie(); c.set("test", "abc", 3600); 2) delete cookie c.del("test"); 3) get cookie var test = c.get("test"); Dependencies: String.trim() */ function Cookie() { this.get = function(name) { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; ++i) { var a = cookies[i].split("="); if (a.length == 2) { a[0] = a[0].trim(); a[1] = a[1].trim(); if (a[0] == name) { return unescape(a[1]); } } } return ""; }; this.set = function(name, value, seconds, path, domain, secure) { var cookie = (name + "=" + escape(value)); if (seconds) { var date = new Date(new Date().getTime()+seconds*1000); cookie += ("; expires="+date.toGMTString()); } cookie += (path ? "; path="+path : ""); cookie += (domain ? "; domain="+domain : ""); cookie += (secure ? "; secure" : ""); document.cookie = cookie; }; this.del = function(name) { document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT"; }; } --- NEW FILE: Validate.js --- /* * DO NOT REMOVE THIS NOTICE * * PROJECT: js libs * COPYRIGHT: (c) 2003,2004 Cezary Tomczak * LINK: http://gosu.pl * LICENSE: BSD (revised) */ // +----------------------------------------------------------------+ // | Some useful functions for string validation. | // | Author: Cezary Tomczak [www.gosu.pl] | // | Free for any use as long as all copyright messages are intact. | // +----------------------------------------------------------------+ /* yyyy-mm-dd */ function isDate(s) { if (!(/^\d{4,4}-\d{2,2}-\d{2,2}$/.test(s))) { return false; } var a = s.split("-"); var d = new Date(a[0], Number(a[1])-1, a[2]); d = [d.getFullYear().toString(), (d.getMonth()+1).toString(), d.getDate().toString()]; if (!d[0].length || !d[1].length || !d[2].length) { return false; } if (d[1].length == 1) { d[1] = "0"+d[1]; } if (d[2].length == 1) { d[2] = "0"+d[2]; } return a[0] == d[0] && a[1] == d[1] && a[2] == d[2]; } /* hh:mm:ss */ function isHour(s) { if (!(/^\d{2,2}:\d{2,2}:\d{2,2}$/.test(s))) { return false; } var a = s.split(":"); a[0] = Number(a[0]); a[1] = Number(a[1]); a[2] = Number(a[2]); return a[0] >= 0 && a[0] <= 23 && a[1] >= 0 && a[1] <= 59 && a[2] >= 0 && a[2] <= 59; } /* yyyy-mm-dd hh:mm:ss */ function isDateIso(s) { if (!(/^\d{4,4}-\d{2,2}-\d{2,2} \d{2,2}:\d{2,2}:\d{2,2}$/.test(s))) { return false; } var a = s.split(" "); return isDate(a[0]) && isHour(a[1]); } /* ignore whitespace */ function isEmpty(s) { return !Boolean(s.replace(/^\s*|\s*$/g, "").length); } /* ignore whitespace */ function isNonEmpty(s) { return Boolean(s.replace(/^\s*|\s*$/g, "").length); } /* -0.01, 10, 10.45 - ok 01, 00.1, .1, 0.0.0 - bad */ function isNumber(s) { if (s.length && s.charAt(0) == "-") { return isNumber(s.substr(1)); } if (!(/^[\d.]+$/.test(s))) { return false; } if (s.indexOf(".") != -1 && (s.indexOf(".") != s.lastIndexOf("."))) { return false; } if (s.charAt(0) == ".") { return false; } if (s.length >= 2 && s.charAt(0) == "0" && s.charAt(1) != ".") { return false; } return !isNaN(s); } function isEmail(s) { return (/^\w+@\w+\.[\w.]+$/.test(s) && s.charAt(s.length-1) != "."); } /* isHttpAddress("gosu.pl") - true isHttpAddress("www.gosu.pl") - true isHttpAddress("www.gosu.pl", 1) - false isHttpAddress("https://gosu.pl", 1) - true */ function isHttpAddress(s, full) { if (full) { return (/^http(s)?:\/\/(www\.)?\w+\.[\w.]+$/.test(s) && s.charAt(s.length-1) != "."); } else { return (/^(http(s)?:\/\/)?(www\.)?\w+\.[\w.]+$/.test(s) && s.charAt(s.length-1) != "."); } } /* checkSize("12", 4, 16) - true checkSize("12", null, 16) - true checkSize("12", 4, null) - true checkSize("12", 13) - false */ function checkSize(s, min, max) { var n = Number(s); if (typeof min == "number") { if (n < min) { return false; } } if (typeof max == "number") { if (n > max) { return false; } } return true; } /* checkLength("abcdef", 4, 9) - true checkLength("abcdef", null, 9) - true checkLength("abcdef", 4, null) - true checkLength("abcdef", null, 5) - false */ function checkLength(s, min, max) { if (typeof min == "number") { if (s.length < min) { return false; } } if (typeof max == "number") { if (s.length > max) { return false; } } return true; } /* round("12.567", 0) == "13" round("12.567", 1) == "12.6" round("12.567", 2) == "12.57" round("12.565", 2) == "12.56" */ function round(s, n) { return String(Number(s).toFixed(n)); } function isPesel(pesel) { if (pesel.length != 11 || !(/^\d+$/.test(pesel))) { return false; } var steps = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]; var sum_nb = 0, sum_m, sum_c; for (var x = 0; x < 10; ++x) { sum_nb += steps[x] * pesel[x]; } sum_m = 10 - sum_nb % 10; if (sum_m == 10) { sum_c = 0; } else { sum_c = sum_m; } return (sum_c == pesel[10]); } function isRegon(regon) { var steps = [8, 9, 2, 3, 4, 5, 6, 7]; regon = regon.replace(/-/g, ""); regon = regon.replace(/ /g, ""); if (regon.length != 9) { return false; } var sum_nb = 0, sum_m; for (var x = 0; x < 8; ++x) { sum_nb += steps[x] * regon[x]; } sum_m = sum_nb % 11; if (sum_m == 10) { sum_m = 0; } return (sum_m == regon[8]); } function isNip(nip) { var steps = [6, 5, 7, 2, 3, 4, 5, 6, 7]; nip = nip.replace(/-/g, ""); nip = nip.replace(/ /g, ""); if (nip.length != 10) { return false; } var sum_nb = 0, sum_m; for (var x = 0; x < 9; ++x) { sum_nb += steps[x] * nip[x]; } sum_m = sum_nb % 11; if (sum_m == 10) { sum_m = 0; } return (sum_m == nip[9]); } --- NEW FILE: DynamicOptionList.js --- // Global objects to keep track of DynamicOptionList objects created on the page var dynamicOptionListCount=0; var dynamicOptionListObjects = new Array(); // Init call to setup lists after page load. One call to this function sets up all lists. function initDynamicOptionLists() { // init each DynamicOptionList object for (var i=0; i<dynamicOptionListObjects.length; i++) { var dol = dynamicOptionListObjects[i]; // Find the form associated with this list if (dol.formName!=null) { dol.form = document.forms[dol.formName]; } else if (dol.formIndex!=null) { dol.form = document.forms[dol.formIndex]; } else { // Form wasn't set manually, so go find it! // Search for the first form element name in the lists var name = dol.fieldNames[0][0]; for (var f=0; f<document.forms.length; f++) { if (typeof(document.forms[f][name])!="undefined") { dol.form = document.forms[f]; break; } } if (dol.form==null) { alert("ERROR: Couldn't find form element "+name+" in any form on the page! Init aborted"); return; } } // Form is found, now set the onchange attributes of each dependent select box for (var j=0; j<dol.fieldNames.length; j++) { // For each set of field names... for (var k=0; k<dol.fieldNames[j].length-1; k++) { // For each field in the set... var selObj = dol.form[dol.fieldNames[j][k]]; if (typeof(selObj)=="undefined") { alert("Select box named "+dol.fieldNames[j][k]+" could not be found in the form. Init aborted"); return; } // Map the HTML options in the first select into the options we created if (k==0) { if (selObj.options!=null) { for (l=0; l<selObj.options.length; l++) { var sopt = selObj.options[l]; var m = dol.findMatchingOptionInArray(dol.options,sopt.text,sopt.value,false); if (m!=null) { var reselectForNN6 = sopt.selected; var m2 = new Option(sopt.text, sopt.value, sopt.defaultSelected, sopt.selected); m2.selected = sopt.selected; // For some reason I need to do this to make NN4 happy m2.defaultSelected = sopt.defaultSelected; m2.DOLOption = m; selObj.options[l] = m2; selObj.options[l].selected = reselectForNN6; // Reselect this option for NN6 to be happy. Yuck. } } } } if (selObj.onchange==null) { // We only modify the onChange attribute if it's empty! Otherwise do it yourself in your source! selObj.onchange = new Function("dynamicOptionListObjects["+dol.index+"].change(this)"); } } } } // Set the preselectd options on page load resetDynamicOptionLists(); } // This function populates lists with the preselected values. // It's pulled out into a separate function so it can be hooked into a 'reset' button on a form // Optionally passed a form object which should be the only form reset function resetDynamicOptionLists(theform) { // reset each DynamicOptionList object for (var i=0; i<dynamicOptionListObjects.length; i++) { var dol = dynamicOptionListObjects[i]; if (typeof(theform)=="undefined" || theform==null || theform==dol.form) { for (var j=0; j<dol.fieldNames.length; j++) { dol.change(dol.form[dol.fieldNames[j][0]],true); // Second argument says to use preselected values rather than default values } } } } // An object to represent an Option() but just for data-holding function DOLOption(text,value,defaultSelected,selected) { this.text = text; this.value = value; this.defaultSelected = defaultSelected; this.selected = selected; this.options = new Array(); // To hold sub-options return this; } // DynamicOptionList CONSTRUCTOR function DynamicOptionList() { this.form = null;// The form this list belongs to this.options = new Array();// Holds the options of dependent lists this.longestString = new Array();// Longest string that is currently a potential option (for Netscape) this.numberOfOptions = new Array();// The total number of options that might be displayed, to build dummy options (for Netscape) this.currentNode = null;// The current node that has been selected with forValue() or forText() this.currentField = null;// The current field that is selected to be used for setValue() this.currentNodeDepth = 0;// How far down the tree the currentNode is this.fieldNames = new Array();// Lists of dependent fields which use this object this.formIndex = null;// The index of the form to associate with this list this.formName = null;// The name of the form to associate with this list this.fieldListIndexes = new Object();// Hold the field lists index where fields exist this.fieldIndexes = new Object();// Hold the index within the list where fields exist this.selectFirstOption = true;// Whether or not to select the first option by default if no options are default or preselected, otherwise set the selectedIndex = -1 this.numberOfOptions = new Array();// Store the max number of options for a given option list this.longestString = new Array();// Store the longest possible string this.values = new Object(); // Will hold the preselected values for fields, by field name // Method mappings this.forValue = DOL_forValue; this.forText = DOL_forText; this.forField = DOL_forField; this.forX = DOL_forX; this.addOptions = DOL_addOptions; this.addOptionsTextValue = DOL_addOptionsTextValue; this.setDefaultOptions = DOL_setDefaultOptions; this.setValues = DOL_setValues; this.setValue = DOL_setValues; this.setFormIndex = DOL_setFormIndex; this.setFormName = DOL_setFormName; this.printOptions = DOL_printOptions; this.addDependentFields = DOL_addDependentFields; this.change = DOL_change; this.child = DOL_child; this.selectChildOptions = DOL_selectChildOptions; this.populateChild = DOL_populateChild; this.change = DOL_change; this.addNewOptionToList = DOL_addNewOptionToList; this.findMatchingOptionInArray = DOL_findMatchingOptionInArray; // Optionally pass in the dependent field names if (arguments.length > 0) { // Process arguments and add dependency groups for (var i=0; i<arguments.length; i++) { this.fieldListIndexes[arguments[i].toString()] = this.fieldNames.length; this.fieldIndexes[arguments[i].toString()] = i; } this.fieldNames[this.fieldNames.length] = arguments; } // Add this object to the global array of dynamicoptionlist objects this.index = window.dynamicOptionListCount++; window["dynamicOptionListObjects"][this.index] = this; } // Given an array of Option objects, search for an existing option that matches value, text, or both function DOL_findMatchingOptionInArray(a,text,value,exactMatchRequired) { if (a==null || typeof(a)=="undefined") { return null; } var value_match = null; // Whether or not a value has been matched var text_match = null; // Whether or not a text has been matched for (var i=0; i<a.length; i++) { var opt = a[i]; // If both value and text match, return it right away if (opt.value==value && opt.text==text) { return opt; } if (!exactMatchRequired) { // If value matches, store it until we complete scanning the list if (value_match==null && value!=null && opt.value==value) { value_match = opt; } // If text matches, store it for later if (text_match==null && text!=null && opt.text==text) { text_match = opt; } } } return (value_match!=null)?value_match:text_match; } // Util function used by forValue and forText function DOL_forX(s,type) { if (this.currentNode==null) { this.currentNodeDepth=0; } var useNode = (this.currentNode==null)?this:this.currentNode; var o = this.findMatchingOptionInArray(useNode["options"],(type=="text")?s:null,(type=="value")?s:null,false); if (o==null) { o = new DOLOption(null,null,false,false); o[type] = s; useNode.options[useNode.options.length] = o; } this.currentNode = o; this.currentNodeDepth++; return this; } // Set the portion of the list structure that is to be used by a later operation like addOptions function DOL_forValue(s) { return this.forX(s,"value"); } // Set the portion of the list structure that is to be used by a later operation like addOptions function DOL_forText(s) { return this.forX(s,"text"); } // Set the field to be used for setValue() calls function DOL_forField(f) { this.currentField = f; return this; } // Create and add an option to a list, avoiding duplicates function DOL_addNewOptionToList(a, text, value, defaultSelected) { var o = new DOLOption(text,value,defaultSelected,false); // Add the option to the array if (a==null) { a = new Array(); } for (var i=0; i<a.length; i++) { if (a[i].text==o.text && a[i].value==o.value) { if (o.selected) { a[i].selected=true; } if (o.defaultSelected) { a[i].defaultSelected = true; } return a; } } a[a.length] = o; } // Add sub-options to the currently-selected node, with the same text and value for each option function DOL_addOptions() { if (this.currentNode==null) { this.currentNode = this; } if (this.currentNode["options"] == null) { this.currentNode["options"] = new Array(); } for (var i=0; i<arguments.length; i++) { var text = arguments[i]; this.addNewOptionToList(this.currentNode.options,text,text,false); if (typeof(this.numberOfOptions[this.currentNodeDepth])=="undefined") { this.numberOfOptions[this.currentNodeDepth]=0; } if (this.currentNode.options.length > this.numberOfOptions[this.currentNodeDepth]) { this.numberOfOptions[this.currentNodeDepth] = this.currentNode.options.length; } if (typeof(this.longestString[this.currentNodeDepth])=="undefined" || (text.length > this.longestString[this.currentNodeDepth].length)) { this.longestString[this.currentNodeDepth] = text; } } this.currentNode = null; this.currentNodeDepth = 0; } // Add sub-options to the currently-selected node, specifying separate text and values for each option function DOL_addOptionsTextValue() { if (this.currentNode==null) { this.currentNode = this; } if (this.currentNode["options"] == null) { this.currentNode["options"] = new Array(); } for (var i=0; i<arguments.length; i++) { var text = arguments[i++]; var value = arguments[i]; this.addNewOptionToList(this.currentNode.options,text,value,false); if (typeof(this.numberOfOptions[this.currentNodeDepth])=="undefined") { this.numberOfOptions[this.currentNodeDepth]=0; } if (this.currentNode.options.length > this.numberOfOptions[this.currentNodeDepth]) { this.numberOfOptions[this.currentNodeDepth] = this.currentNode.options.length; } if (typeof(this.longestString[this.currentNodeDepth])=="undefined" || (text.length > this.longestString[this.currentNodeDepth].length)) { this.longestString[this.currentNodeDepth] = text; } } this.currentNode = null; this.currentNodeDepth = 0; } // Find the first dependent list of a select box // If it's the last list in a chain, return null because there are no children function DOL_child(obj) { var listIndex = this.fieldListIndexes[obj.name]; var index = this.fieldIndexes[obj.name]; if (index < (this.fieldNames[listIndex].length-1)) { return this.form[this.fieldNames[listIndex][index+1]]; } return null; } // Set the options which should be selected by default for a certain value in the parent function DOL_setDefaultOptions() { if (this.currentNode==null) { this.currentNode = this; } for (var i=0; i<arguments.length; i++) { var o = this.findMatchingOptionInArray(this.currentNode.options,null,arguments[i],false); if (o!=null) { o.defaultSelected = true; } } this.currentNode = null; } // Set the options which should be selected when the page loads. This is different than the default value and ONLY applies when the page LOADS function DOL_setValues() { if (this.currentField==null) { alert("Can't call setValues() without using forField() first!"); return; } if (typeof(this.values[this.currentField])=="undefined") { this.values[this.currentField] = new Object(); } for (var i=0; i<arguments.length; i++) { this.values[this.currentField][arguments[i]] = true; } this.currentField = null; } // Manually set the form for the object using an index function DOL_setFormIndex(i) { this.formIndex = i; } // Manually set the form for the object using a form name function DOL_setFormName(n) { this.formName = n; } // Print blank <option> objects for Netscape4, since it refuses to grow or shrink select boxes for new options function DOL_printOptions(name) { // Only need to write out "dummy" options for Netscape4 if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) <= 4)){ var index = this.fieldIndexes[name]; var ret = ""; if (typeof(this.numberOfOptions[index])!="undefined") { for (var i=0; i<this.numberOfOptions[index]; i++) { ret += "<OPTION>"; } } ret += "<OPTION>"; if (typeof(this.longestString[index])!="undefined") { for (var i=0; i<this.longestString[index].length; i++) { ret += "_"; } } document.writeln(ret); } } // Add a list of field names which use this option-mapping object. // A single mapping object may be used by multiple sets of fields function DOL_addDependentFields() { for (var i=0; i<arguments.length; i++) { this.fieldListIndexes[arguments[i].toString()] = this.fieldNames.length; this.fieldIndexes[arguments[i].toString()] = i; } this.fieldNames[this.fieldNames.length] = arguments; } // Called when a parent select box is changed. It populates its direct child, then calls change on the child object to continue the population. function DOL_change(obj, usePreselected) { if (usePreselected==null || typeof(usePreselected)=="undefined") { usePreselected = false; } var changedListIndex = this.fieldListIndexes[obj.name]; var changedIndex = this.fieldIndexes[obj.name]; var child = this.child(obj); if (child == null) { return; } // No child, no need to continue if (obj.type == "select-one") { // Treat single-select differently so we don't have to scan the entire select list, which could potentially speed things up if (child.options!=null) { child.options.length=0; // Erase all the options from the child so we can re-populate } if (obj.options!=null && obj.options.length>0 && obj.selectedIndex>=0) { var o = obj.options[obj.selectedIndex]; this.populateChild(o.DOLOption,child,usePreselected); this.selectChildOptions(child,usePreselected); } } else if (obj.type == "select-multiple") { // For each selected value in the parent, find the options to fill in for this list // Loop through the child list and keep track of options that are currently selected var currentlySelectedOptions = new Array(); if (!usePreselected) { for (var i=0; i<child.options.length; i++) { var co = child.options[i]; if (co.selected) { this.addNewOptionToList(currentlySelectedOptions, co.text, co.value, co.defaultSelected); } } } child.options.length=0; if (obj.options!=null) { var obj_o = obj.options; // For each selected option in the parent... for (var i=0; i<obj_o.length; i++) { if (obj_o[i].selected) { // if option is selected, add its children to the list this.populateChild(obj_o[i].DOLOption,child,usePreselected); } } // Now go through and re-select any options which were selected before var atLeastOneSelected = false; if (!usePreselected) { for (var i=0; i<child.options.length; i++) { var m = this.findMatchingOptionInArray(currentlySelectedOptions,child.options[i].text,child.options[i].value,true); if (m!=null) { child.options[i].selected = true; atLeastOneSelected = true; } } } if (!atLeastOneSelected) { this.selectChildOptions(child,usePreselected); } } } // Change all the way down the chain this.change(child,usePreselected); } function DOL_populateChild(dolOption,childSelectObj,usePreselected) { // If this opton has sub-options, populate the child list with them if (dolOption!=null && dolOption.options!=null) { for (var j=0; j<dolOption.options.length; j++) { var srcOpt = dolOption.options[j]; if (childSelectObj.options==null) { childSelectObj.options = new Array(); } // Put option into select list var duplicate = false; var preSelectedExists = false; for (var k=0; k<childSelectObj.options.length; k++) { var csi = childSelectObj.options[k]; if (csi.text==srcOpt.text && csi.value==srcOpt.value) { duplicate = true; break; } } if (!duplicate) { var newopt = new Option(srcOpt.text, srcOpt.value, false, false); newopt.selected = false; // Again, we have to do these two statements for NN4 to work newopt.defaultSelected = false; newopt.DOLOption = srcOpt; childSelectObj.options[childSelectObj.options.length] = newopt; } } } } // Once a child select is populated, go back over it to select options which should be selected function DOL_selectChildOptions(obj,usePreselected) { // Look to see if any options are preselected=true. If so, then set then selected if usePreselected=true, otherwise set defaults var values = this.values[obj.name]; var preselectedExists = false; if (usePreselected && values!=null && typeof(values)!="undefined") { for (var i=0; i<obj.options.length; i++) { var v = obj.options[i].value; if (v!=null && values[v]!=null && typeof(values[v])!="undefined") { preselectedExists = true; break; } } } // Go back over all the options to do the selection var atLeastOneSelected = false; for (var i=0; i<obj.options.length; i++) { var o = obj.options[i]; if (preselectedExists && o.value!=null && values[o.value]!=null && typeof(values[o.value])!="undefined") { o.selected = true; atLeastOneSelected = true; } else if (!preselectedExists && o.DOLOption!=null && o.DOLOption.defaultSelected) { o.selected = true; atLeastOneSelected = true; } else { o.selected = false; } } // If nothing else was selected, select the first one by default if (this.selectFirstOption && !atLeastOneSelected && obj.options.length>0) { obj.options[0].selected = true; } else if (!atLeastOneSelected && obj.type=="select-one") { obj.selectedIndex = -1; } } |