/** * JavaScript loader * @param modules {Array} массив имен js файлов */ var Queue = function () { this.members = []; }; Queue.prototype = { add: function (f) { if (f instanceof Function) { this.members.push(f); } }, iterate: function () { if (this.members.length > 0) { var func = this.members.shift(); func.call(this); } }, clear: function () { this.members = []; } }; var ScriptLoader = function (modules, id) { this.modules = modules.slice(); this.id = id; this.queue = new Queue(); this._init(); }; ScriptLoader.prototype = { run: function () { // test for header ready var head = document.getElementsByTagName("head"); // alert (head.lengt); if (head.length > 0) { this.queue.iterate(); } else { setTimeout(arguments.callee, 500); } }, _init: function () { var i, me = this; for (i = 0; i < me.modules.length; i++) { (function (name) { me.queue.add(function () { var head, script; head = document.getElementsByTagName("head"); if (head.length > 0) { head = head[0]; script = document.createElement("script"); script.src = name; script.type = "text/javascript"; script.onload = script.onreadystatechange = function () { if ((!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) { me.queue.iterate(); script.onload = script.onreadystatechange = null; } }; head.appendChild(script); } }); })(me.modules[i]); } } }; function InitPollStyleType() { var csshead, cssscript; csshead = document.getElementsByTagName("head"); if (csshead.length > 0) { csshead = csshead[0]; cssscript = document.createElement("link"); cssscript.href = "http://ads.corbina.net/incl/poll/display/css/"+VarPollContainerSize+"/"+VarPollContainerFont+"/"+VarPollContainerColor+"/"+VarPollContainerTitleColor+"/"+VarPollContainerTitleSize+"/"+VarPollContainerSid+"/"; cssscript.type="text/css"; cssscript.rel = "stylesheet"; csshead.appendChild(cssscript); } } function PreinitReLoadPollContainer(id) { //initReLoadPollContainer(id); setTimeout("initReLoadPollContainer("+id+")", 1000); } function initReLoadPollContainer(id, block) { //alert (id); var encoding, voted; if(VarPollContainerEncode){encoding = VarPollContainerEncode+'/';}else{encodeing = '';} if(block) { if(PollgetCookie('admvoted'+id) == 1){voted = '?voted=1';} var Reloader = new ScriptLoader(["http://ads.corbina.net/incl/poll/display/polls/"+VarPollContainerSid+"/"+id+"/"+encoding+voted]); } else { var Reloader = new ScriptLoader(["http://ads.corbina.net/incl/poll/display/polls/"+VarPollContainerSid+"/"+id+"/"+encoding+"?voted=1"]); } //alert ("http://ads.corbina.net/incl/poll/display/polls/"+VarPollContainerSid+"/"+id+"/"+encoding+voted); Reloader.queue.add(function() { setTimeout("endLoadPart('pollcorbinastyle_container"+id+"', '"+hjvrsPollVar[id]+"')", 1000); //document.getElementById('pollcorbinastyle_container'+id).innerHTML = hjvrsPollVar[id]+'

'; }); Reloader.run(); if(!block) PollsetCookie('admvoted'+id, '1'); } function InitListPolls(listedPolls) { InitPollsArray = listedPolls.slice(); for (i = 0; i < InitPollsArray.length; i++) { document.write('
'); (function (name) { var div, voted, encoding; if(PollgetCookie('admvoted'+name) == 1){voted = '?voted=1';} var loader = Array(); if(VarPollContainerEncode){encoding = VarPollContainerEncode+'/';} loader[name] = new ScriptLoader(["http://ads.corbina.net/incl/poll/display/polls/"+VarPollContainerSid+"/"+InitPollsArray[i]+"/"+encoding+voted], name); loader[name].run(); loader[name].queue.add(function() { if(!document.getElementById('pollcorbinastyle_container'+name)) { div = document.createElement("div"); div.id = 'pollcorbinastyle_container'+name; document.getElementById('pollcorbinastyle_RootContainer'+name).appendChild(div); } setTimeout("endLoadPart('pollcorbinastyle_container"+name+"', '"+hjvrsPollVar[name]+"')", 1000); }); })(InitPollsArray[i]); } } function endLoadPart(id, str) { if(str != "undefined") { // alert (id.substring(26)); document.getElementById(id).innerHTML = str+'

'; } else { //alert ("initReLoadPollContainer("+id.substring(26)+", '1')"); setTimeout("initReLoadPollContainer(\""+id.substring(26)+"\", '1')", 1000); } } function PollsetCookie(name, value) { var valueEscaped = escape(value); var expiresDate = new Date(); expiresDate.setTime(expiresDate.getTime() + expiresDate.getTime()); var expires = expiresDate.toGMTString(); var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires; if (valueEscaped.length <= 4000) document.cookie = newCookie + ";"; } function PollgetCookie(name) { var prefix = name + "="; var cookieStartIndex = document.cookie.indexOf(prefix); if (cookieStartIndex == -1) return null; var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length); if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length; return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)); }