var frame_style = "";
var get_d = "";
var countdowntimerinstance = null;
function GetCook(key){
if(window.navigator.cookieEnabled){
if (document.cookie) {
var cookies = document.cookie.split("; ");
for (var i = 0; i < cookies.length; i++) {
var str = cookies[i].split("=");
if (str[0] == key) {
return unescape(str[1]);
}
}
}
}else{
return "";
}
}
function SetCook(key, val){
if(window.navigator.cookieEnabled){
var expire = new Date();
expire.setTime( expire.getTime() + 1000 * 3600 * 1 );
document.cookie = key + '=' + escape(val) + '; expires=' + expire.toUTCString() + ';';
}
}
var global_obj = null;
var global_loaded = false;
if(window.addEventListener) {
window.addEventListener("load", eventOnLoad, false);
} else if(window.attachEvent){
window.attachEvent("onload", eventOnLoad);
}
{
var responseText = null;
AccessSite(null);
}
function eventOnLoad(){
global_loaded = true;
if(global_obj){
countdowntimerinstance = new CountdownTimer( "course_limit_cntdwn", new Date(global_obj.ed), global_obj.em, global_obj.tu, global_obj.bf, global_obj.af, global_obj.mi, global_obj.sl, global_obj.st ) ;
countdowntimerinstance.countDown();
}
}
function GetQueryString() {
if (1 < document.location.search.length) {
var query = document.location.search.substring(1);
var parameters = query.split('&');
var result = new Object();
for (var i = 0; i < parameters.length; i++) {
var element = parameters[i].split('=');
var paramName = decodeURIComponent(element[0]);
var paramValue = decodeURIComponent(element[1]);
result[paramName] = decodeURIComponent(paramValue);
}
return result;
}
return null;
}
function AccessSite(d){
var data = { id: 1287, action: 'course_timer', date: d };
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function()
{
var READYSTATE_COMPLETED = 4;
var HTTP_STATUS_OK = 200;
if( this.readyState == READYSTATE_COMPLETED
&& this.status == HTTP_STATUS_OK )
{
if(!this.responseText) {
//setDispStyle("none", document.getElementsByClassName("course_limit_cntdwn"));
return;
}
var txt = this.responseText.replace(/\s+/g, "");
if(!txt) {
//setDispStyle("none", document.getElementsByClassName("course_limit_cntdwn"));
return;
}
global_obj = JSON.parse(this.responseText);
if(global_loaded){
countdowntimerinstance = new CountdownTimer( "course_limit_cntdwn", new Date(global_obj.ed), global_obj.em, global_obj.tu, global_obj.bf, global_obj.af, global_obj.mi, global_obj.sl, global_obj.st );
countdowntimerinstance.countDown();
//SetCook("timer_cache", this.responseText);
}
}
}
xmlHttpRequest.open( 'POST', 'https://on-line-school.jp/wp-admin/admin-ajax.php' );
xmlHttpRequest.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
xmlHttpRequest.send( EncodeHTMLForm( data ) );
var elems = document.getElementsByClassName("course_limit_cntdwn");
}
function EncodeHTMLForm( data )
{
var params = [];
for( var name in data )
{
var value = data[ name ];
var param = encodeURIComponent( name ) + '=' + encodeURIComponent( value );
params.push( param );
}
return params.join( '&' ).replace( /%20/g, '+' );
}
function CountdownTimer( elemID, timeLimit, limitMessage, msgClass ) {
if(countdowntimerinstance){
countdowntimerinstance.tmStop();
countdowntimerinstance = null;
}
this.initialize.apply( this, arguments );
}
function SetCountdownStyle(elemName, style){
elems = document.getElementsByClassName(elemName);
if (!elems) {
return;
}
var carete_style = (function () {
var style = document.createElement('style');
style.setAttribute("type", "text/css");
document.getElementsByTagName('head').item(0).appendChild(style);
return function (item, val) {
style.sheet.insertRule(item + "{" + val + "}", 0);
};
})();
carete_style("." + elemName, style);
}
CountdownTimer.prototype = {
initialize: function (elemName, timeLimit, limitMessage, limitUrl, before, after, is_milis, style, sttext) {
this.elems = document.getElementsByClassName(elemName);
if (!this.elems) {
return;
}
this.dispText = sttext;
this.timeLimit = timeLimit;
this.countdown = false;
this.limitUrl = limitUrl;
this.limitMessage = limitMessage;
this.before = before;
this.after = after;
this.is_milis = is_milis;
this.disp_type = "block";
this.canTimerRun = true;
setDispStyle("none", this.elems);
SetCountdownStyle("course_limit_cntdwn", style);
},
tmStop: function () {
this.canTimerRun = false;
},
countDown: function () {
if (!this.elems) {
return;
}
var timer;
var today = new Date()
var days = Math.floor((this.timeLimit - today) / (24 * 60 * 60 * 1000));
var hours = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
var mins = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) / (60 * 1000)) % 60;
var secs = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) / 1000) % 60 % 60;
var milis = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) / 10) % 100;
var me = this;
if ((this.timeLimit - today) > 0) {
this.countdown = true;
setDispStyle(this.disp_type, this.elems);
if (this.dispText) {
setInnerHtml(this.dispText, this.elems);
}
else {
timer = '' + this.before + '' + '';
if(days > 0) timer = timer + '' + days + '' + '日と';
timer = timer + '' + this.addZero(hours) + '' + '時間';
timer = timer + '' + this.addZero(mins) + '' + '分';
timer = timer + '' + this.addZero(secs) + '' + '秒';
if (this.is_milis) {
timer = timer + '' + this.addZero(milis) + '';
}
timer = timer + '' + this.after + ''
setInnerHtml(timer, this.elems);
}
if(this.canTimerRun){
if (this.is_milis) {
tid = setTimeout(function () { me.countDown(); }, 40);
}else{
tid = setTimeout(function () { me.countDown(); }, 40);
}
}
} else {
if (this.limitUrl) {
location.href = this.limitUrl;
}
else if (this.limitMessage) {
setInnerHtml(this.limitMessage, this.elems);
setDispStyle(this.disp_type, this.elems);
}
else {
setInnerHtml("", this.elems);
setDispStyle("none", this.elems);
}
return;
}
},
addZero: function (num) {
num = '00' + num;
str = num.substring(num.length - 2, num.length);
return str;
}
}
function setDispStyle(style, elems) {
if (!elems) {
return;
}
for (var i = 0; i < elems.length; i++) {
elems[i].style.display = style;
}
}
function setInnerHtml(html, elems) {
if (!elems) {
return;
}
for (var i = 0; i < elems.length; i++) {
elems[i].innerHTML = html;
}
}