function Polls() { this.loaded = 0; this.queryitems = []; this.auto = 1; this.count = 0; } function polls_initialize() { with (this) { if (Site.loaded == 1) { loaded = 1; root = "http://petermackay.ca/"; CompileQuery(); OptionsCount(); } else { window.setTimeout('Survey.Initialize()',10); } } } function polls_compilequery() { var fields; with (this) { if (loaded == 1) { fields = document.body.getElementsByTagName("INPUT"); for (i = 0; i < fields.length; i++) { if (fields[i].id != "" && fields[i].name != "") { if (fields[i].id.search(/s-/gi) != -1) { queryitems[fields[i].id] = new Array(fields[i].name,fields[i].value); } } } } } } function polls_addtoquery(item,value,s) { with (this) { if (loaded == 1) { if (item) { if (item.id.search(/s-/gi) != -1) { item.value = value; CompileQuery(); if (s == 1 && auto == "1") { SubmitQuery(); } } } } } } function polls_submitquery() { var query = "http://petermackay.ca/survey/?"; with (this) { if (loaded == 1) { for (i in queryitems) { if (queryitems[i][1] != "") { query += queryitems[i][0]+"="+queryitems[i][1]+"&"; } } query = query.substr(0,query.length-1); location.href = query; } } } function polls_keypress(e) { var evt = e || window.event; var key = evt.which || evt.keyCode; with (this) { if (key == 13) { SubmitQuery(); } } } function polls_optionscount() { var name = "survey.php"; var start = -1; var query = ""; var list = new Array(); var temp; var v = []; with (this) { if (loaded == 1) { // Build query list // --------------------------------- if ($('site_jscript_survey')) { start = $('site_jscript_survey').src.indexOf(name); query = ($('site_jscript_survey').src.length > (start+(name.length+1)) ? $('site_jscript_survey').src.substring((start+(name.length+1)),$('site_jscript_survey').src.length) : ""); if (query != "") { list = query.split(";"); for (i = 0; i < list.length; i++) { temp = list[i].split("="); v[temp[0]] = (temp[1] ? temp[1] : ""); } } } if (count == 0) { count = (v['options'] ? 1*(v['options']) : 0); } if (count != 0) { loaded = 2; } else { window.setTimeout('Survey.OptionsCount()',10); } } } } function polls_insertoption() { var table; var row; var cell; var span; var field; with (this) { if (loaded == 2) { table = $('polls_options_table'); if (table) { count++; row = table.insertRow(-1); cell = row.insertCell(-1); cell.style.paddingRight = "12px"; cell.innerHTML = ""+count+""; cell = row.insertCell(-1); span = document.createElement("SPAN"); span.id = "polls_options_field"+count; cell.insertBefore(span,null); field = document.createElement("TEXTAREA"); field.name = "options[]"; field.style.width = "550px"; field.rows = 1; field.maxlength = 5000; span.insertBefore(field,null); } } } } Polls.prototype.Initialize = polls_initialize; Polls.prototype.CompileQuery = polls_compilequery; Polls.prototype.AddToQuery = polls_addtoquery; Polls.prototype.SubmitQuery = polls_submitquery; Polls.prototype.KeyPress = polls_keypress; Polls.prototype.OptionsCount = polls_optionscount; Polls.prototype.InsertOption = polls_insertoption; var Survey = new Polls(); Survey.Initialize();