// -- License validator -- /* Copyright http://www.perlscriptsjavascripts.com Free and commercial Perl and JavaScripts */ // page to go to if cookie does not exists go_to = "/ttm/Plots/license.cgi"; // number of days cookie lives for num_days = 1200; function ged(noDays){ var today = new Date(); var expr = new Date(today.getTime() + noDays*24*60*60*1000); return expr.toGMTString(); } function readCookie(cookieName){ var start = document.cookie.indexOf(cookieName); var whereami = new String(window.location); if (start == -1 && !whereami.match(go_to)){ window.location = go_to; } } function checkLicense(){ readCookie("ttmlicense"); } // -- Range validator -- function validate_range(obj, lowval, hival, defval, message) { if ((obj.value < lowval) || (obj.value > hival)) { obj.value=defval; alert(message); return false; } return true; } // -- Regular expression validator -- function validate_regex(obj, regex, defval, message) { var re = new RegExp(regex); if (!re.test(obj.value)) { obj.value=defval; alert(message); return false; } return true; } // -- Equality validator (using boolean operator == and != which are assignable ) -- function validate_equality(thelvalue, thevalue, theoperator, defval, message) { var code="'" + String(thelvalue) + "' " + String(theoperator) + " '" + String(thevalue) + "'"; if (!eval(code)) { thelvalue=defval; alert(message); return false; } return true; }