//window.onerror = handleError;
//declare/assign global variables
dag = new Date() ;
tid = dag.getTime() ;
var questionText ;
var qnameCookie ;
var code ;
var qname ;
var qunid ;
var qresult ;
var answerValue ;
var questionID ;
var access ;
function setCookie(name, value, expires, path, domain, secure) {
var defaultexpires = new Date();
defaultexpires.setTime(defaultexpires.getTime());
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
/*Class Question*/
function Question( iCode , iQname, iQunid, iResult, iAccess){
if(arguments.length != 5) return
this.code = iCode ;
this.qname = iQname ;
this.qunid = iQunid ;
this.qresult = iResult ;
this.access = iAccess ;
}
// init the array
var questions = new Array();
//
questions[questions.length] = new Question('
','DOMO-87YEQB','1486CC97E8E84F0BC1257774003B844B',' |
| Månadens fråga Kommer de politiska parternas åsikter i hivfrågor att ha nån betydelse på hur du röstar i höst?
| Ja definitivt. 34% | | Nej, definitivt inte. 44% | | Kanske vet inte. 12% | | Kan inte svara på det - vet inte vad de har för åsikter om det. 12% |
|
|
|
','0');
//count amount of question objects
Qamount = questions.length;
// get the question with the right function [[ this function is the remote trigger ]]
function displayQuestion(ID) {
if(Qamount<1) { return;}
if(ID == "random") {
aRandQuestion = randomQuestion();
typeof aRandQuestion=='undefined' ? document.writeln('') : document.writeln(aRandQuestion);
} else {
aIdQuestion = idQuestion(ID);
typeof aIdQuestion=='undefined' ? document.writeln('') : document.writeln(aIdQuestion);
}
}
/* generate random number based on
amount and globals, return any question,
if answeres return the result for current
question */
function randomQuestion() {
var aAnsweredCookie = getCookie('ANSWERED');
if(aAnsweredCookie ==null || aAnsweredCookie == "1") {
randomNumber = parseInt(((tid - (parseInt(tid/1000,10) * 1000))/10)/100*Qamount+ 1,10) - 1;
questionID = questions[randomNumber].qunid ;
questionText = getCookie(questionID)==null ? questions[randomNumber].code : questions[randomNumber].qresult ;
access = questions[randomNumber].access
qnameCookie = questions[randomNumber].qname ;
return questionText;
}else{
document.writeln(idQuestion(aAnsweredCookie));
setCookie('ANSWERED','1',new Date(2015, 12, 31),'/','','');
return "";
}
}
/* get question by key here, and return
that question to function dispayQuestion,
if cookie exists, only return the result */
function idQuestion(thisID) {
for(i=0 ; i < Qamount ; i++ ) {
if(thisID==questions[i].qname) {
questionID = questions[i].qunid ;
qnameCookie = questions[i].qname ;
access = questions[i].access
if(getCookie(questionID)==null) {
questionText = questions[i].code ;
}else{
questionText = questions[i].qresult ;
}
}
}
return questionText;
}
// assign the selected value to answerValue
function setValue(nr) {
answerValue = nr ;
}
// validate the status of answerValue before submitting to dominoAgent
function validate() {
typeof answerValue == 'undefined' ? alert('Vote first, post later!') : runAgent(answerValue);
}
// run the agent with the current values
function runAgent(answerValue) {
setCookie(String(questionID),'1',new Date(2015, 12, 31),'/','','');
setCookie('ANSWERED',String(qnameCookie),new Date(2015, 12, 31),'/','','');
location.href='/rfhpwww/main.nsf/Answer?OpenAgent&UNID='+questionID+'&S='+answerValue+'&Ref='+location.href + (access == '1' ? '&login' : '')
}
// error handle
function handleError(a,b,c) {
window.status = "[Error message] what(" + a +") where("+ b +") line(" + c +")";
return true;
}