function $(sId) { if (!sId) { return null; } return document.getElementById(sId); } function setCity(name){ // $('c_citi').value = name; $('c_citi').innerHTML = ''+ name+''; $('sr_citi').value = name; } function setProv(name){ // $('c_prov').value = name; $('c_prov').innerHTML = ''+ name +''; $('sr_prov').value = name; } var __now = 1; var __count = 1; var prog = 0; var __vals = []; var div = ''; var count = ''; var __tips = []; var timer = 0; var s_timer = 0; var timerID = 0; var tStart = null; function UpdateTimer() { if(timerID) { clearTimeout(timerID); clockID = 0; } if(!tStart) tStart = new Date(); var tDate = new Date(); var tDiff = tDate.getTime() - tStart.getTime(); tDate.setTime(tDiff); div = $('timer'); var s = tDate.print('%M:%S'); div.innerHTML = s; timerID = setTimeout("UpdateTimer()", 1000); } function start_timer() { tStart = new Date(); div = $('timer'); div.innerHTML = "00:00"; timerID = setTimeout("UpdateTimer()", 1000); update_check(); } function update_check(){ xajax_check_time(); setTimeout("update_check()", 60000); } function show_first(){ div = $('test_1'); div.style.display = 'block'; show_page(); } function show_next(){ calck_progress(); if(__now>__count) return; div = $('test_'+__now); div.style.display = 'none'; __now++; div = $('fin'); div.style.display = 'inline'; if(__now>__count){ div = $('fin'); div.style.display = 'none'; __now = __count+1; if(prog == 100){ div = $('test_finish'); div.style.display = 'block'; } else{ div = $('test_finish_err'); div.style.display = 'block'; } }else{ div = $('test_'+__now); div.style.display = 'block'; } count = $('count'); count.innerHTML = (__now<=__count)?' '+__now+'/'+__count+' ':' '+__count+'/'+__count+' '; show_page(); } function show_prev(){ calck_progress(); div = $('fin'); div.style.display = 'inline'; if(__now<=1) return; div = $('test_finish'); if(div) div.style.display = 'none'; div = $('test_finish_err'); if(div) div.style.display = 'none'; div = $('test_'+__now); if(div) div.style.display = 'none'; __now--; div = $('test_'+__now); div.style.display = 'block'; count = $('count'); count.innerHTML = (__now<=__count)?' '+__now+'/'+__count+' ':' '+__count+'/'+__count+' '; show_page(); } function check_val(obj){ for(var i=0;i<__vals[obj];i++){ if(__tips[obj]==0) if(document.IQ['otv['+obj+']['+i+']'].checked) return true; if(__tips[obj]==1) if(document.IQ['otv['+obj+']'][i].checked) return true; } return false; } function show_finish(){ if(prog!=100)return; calck_progress(); div = $('test_'+__now); div.style.display = 'none'; __now = __count; show_next(); show_page(); } function show_num(num){ calck_progress(); div = $('fin'); div.style.display = 'inline'; div = $('test_finish'); if(div) div.style.display = 'none'; div = $('test_finish_err'); if(div) div.style.display = 'none'; div = $('test_'+__now); if(div) div.style.display = 'none'; __now = num; div = $('test_'+__now); div.style.display = 'block'; count = $('count'); count.innerHTML = (__now<=__count)?' '+__now+'/'+__count+' ':' '+__count+'/'+__count+' '; show_page(); } function calck_progress(){ var pg = 0; for(var i=0;i<=__count;i++){ if(check_val(i)){ pg++; div = $('pg'+(i+1)); if(div) div.className = 'knopar_ok'; } else{ div = $('pg'+(i+1)); if(div) div.className = 'knopar2'; } } prog = (pg!=0)?Math.round(pg/__count*100):0; var progress = $('pr_count'); // progress.innerHTML = prog+'%'; progress.style.width = prog+'%'; var progress = $('pr_c'); progress.innerHTML = prog+'%'; if(prog==100){ div = $('fin'); if(div) div.className = 'knopar'; } } function show_page(){ div = $('pg'+__now); if(div) div.className = 'knopar_now'; } function finish_test(){ document.IQ.submit(); } /** Adds the number of days array to the Date object. */ Date._MD = new Array(31,28,31,30,31,30,31,31,30,31,30,31); /** Constants used for time computations */ Date.SECOND = 1000 /* milliseconds */; Date.MINUTE = 60 * Date.SECOND; Date.HOUR = 60 * Date.MINUTE; Date.DAY = 24 * Date.HOUR; Date.WEEK = 7 * Date.DAY; /** Returns the number of days in the current month */ Date.prototype.getMonthDays = function(month) { var year = this.getFullYear(); if (typeof month == "undefined") { month = this.getMonth(); } if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) { return 29; } else { return Date._MD[month]; } }; /** Returns the number of day in the year. */ Date.prototype.getDayOfYear = function() { var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / Date.DAY); }; /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function() { var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); var DoW = d.getDay(); d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu var ms = d.valueOf(); // GMT d.setMonth(0); d.setDate(4); // Thu in Week 1 return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1; }; /** Checks dates equality (ignores time) */ Date.prototype.equalsTo = function(date) { return ((this.getFullYear() == date.getFullYear()) && (this.getMonth() == date.getMonth()) && (this.getDate() == date.getDate()) && (this.getHours() == date.getHours()) && (this.getMinutes() == date.getMinutes())); }; /** Prints the date in a string according to the given format. */ Date.prototype.print = function (str) { var m = this.getMonth(); var d = this.getDate(); var y = this.getFullYear(); var wn = this.getWeekNumber(); var w = this.getDay(); var s = {}; var hr = this.getHours(); var pm = (hr >= 12); var ir = (pm) ? (hr - 12) : hr; var dy = this.getDayOfYear(); if (ir == 0) ir = 12; var min = this.getMinutes(); var sec = this.getSeconds(); // FIXME: %c : preferred date and time representation for the current locale s["%C"] = 1 + Math.floor(y / 100); // the century number s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31) s["%e"] = d; // the day of the month (range 1 to 31) // FIXME: %D : american date style: %m/%d/%y // FIXME: %E, %F, %G, %g, %h (man strftime) s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format) s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366) s["%k"] = hr; // hour, range 0 to 23 (24h format) s["%l"] = ir; // hour, range 1 to 12 (12h format) s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%n"] = "\n"; // a newline character s["%p"] = pm ? "PM" : "AM"; s["%P"] = pm ? "pm" : "am"; // FIXME: %r : the time in am/pm notation %I:%M:%S %p // FIXME: %R : the time in 24-hour notation %H:%M s["%s"] = Math.floor(this.getTime() / 1000); s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59 s["%t"] = "\t"; // a tab character // FIXME: %T : the time in 24-hour notation (%H:%M:%S) s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn; s["%u"] = w + 1; // the day of the week (range 1 to 7, 1 = MON) s["%w"] = w; // the day of the week (range 0 to 6, 0 = SUN) // FIXME: %x : preferred date representation for the current locale without the time // FIXME: %X : preferred time representation for the current locale without the date s["%y"] = ('' + y).substr(2, 2); // year without the century (range 00 to 99) s["%Y"] = y; // year with the century s["%%"] = "%"; // a literal '%' character var re = /%./g; var a = str.match(re); for (var i = 0; i < a.length; i++) { var tmp = s[a[i]]; if (tmp) { re = new RegExp(a[i], 'g'); str = str.replace(re, tmp); } } return str; }; function showKey(evt) { var key = (typeof evt.which != "undefined") ? evt.which : event.keyCode; if(key==13) show_next(); } Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear; Date.prototype.setFullYear = function(y) { var d = new Date(this); d.__msh_oldSetFullYear(y); if (d.getMonth() != this.getMonth()) this.setDate(28); this.__msh_oldSetFullYear(y); };