// Copyright ©2009 Boardhost.com, Inc.  All Rights Reserved.
function add_answer() {
	var nextanswer = document.poll.next.value;
	var nextname = "answer" + nextanswer;
	document.getElementById("answer_" + nextanswer).style.display = "";
	document.forms.poll[nextname].focus();
	nextanswer++;
	document.poll.next.value = nextanswer;
	if (nextanswer > 30) { document.getElementById("anotherlink").style.display = "none"; }
}

function buttonupdate() {
	if (document.getElementById("viewbuttonbutton").checked) { document.getElementById("viewbutton").style.display = "";  }
	else { document.getElementById("viewbutton").style.display = "none"; }
}
function changeinputs() {
	var span = document.getElementsByTagName("span");
	if (span) {
		for(i=0;i<span.length;i++) {
			if (span[i].id.substring(6,0)=="input_") {
				if (document.poll.multiple.checked) {
					span[i].innerHTML="<input type=checkbox>";
				}
				else {
					span[i].innerHTML="<input type=radio>";
				}
			}
   		}
  	}
}
function clearanswer(num) {
	var updatenum = "answer" + num;
	if (!document.poll[updatenum].value) { 
		document.getElementById("answerrow" + num).style.display = "none"; 
	}
}
function get_code() {
	var answers=0;
	var chars = /^[\w\s\$%\.\?(),'"!:#\-/;@]+$/;
	for (i=1; i<=30; i++) {
		var field = "answer" + i;
		if (document.poll[field].value) { 
			answers++;
			if (!chars.test(document.poll[field].value)) {
				alert("Your \"Poll Answer " + i + "\" contains characters that are not permitted.  Please remove them and try again.");
    				return false;
			}
		}
	}
	if (!document.poll.question.value) {
		alert("You must enter a poll question to ask your voters.  Please enter a poll question and try again.");
		return false;
	}
	if (!chars.test(document.poll.question.value)) {
		alert("Your poll question contains characters that are not permitted.  Please remove them and try again.");
		return false;
	}
	if (answers < 2) { 
		alert("You must answer at least two answers to your poll question.  Please enter at least two answers.");
		return false;
	}

}
function reset() {
	document.poll.question.focus();
	document.poll.next.value = 9;
	document.poll.multiple.checked=false;
	document.getElementById("viewbuttonbutton").checked=true;
	document.poll.font.options[0].selected = true;
	document.poll.bars.options[0].selected = true;
	document.poll.time.options[0].selected = true;
	document.poll.skin.options[0].selected = true;
	document.getElementById("bgimage").value = "";
	document.poll.question.value = "";
	document.poll.font.value = "Verdana";
	document.poll.fontcolor.value = "000000";
	document.poll.bgcolor.value = "EEEEEE";
	document.getElementById("userpoll").style.backgroundImage = "";
	for (i=1; i<=30; i++) {
		var field = "answer" + i;
		document.poll[field].value = "";
	}
}
function resetpost() {
	updateappearance(1);
	document.poll.answer1.focus();
	var usercookie = GetCookie("user");
	if (usercookie) {
		var uc = usercookie.split(":");
		username = uc[0];
		if (username) {
			document.getElementById('firstlink').innerHTML = 'You are logged in as <b>' + username + '</b>';
			document.getElementById('secondlink').innerHTML = '<b><a href=javascript:admin();>Access Account Admin Area</a></b>';
			document.getElementById('thirdlink').innerHTML = '<a href=javascript:logout();>Log Out</a>';
			//document.getElementById("samplepoll").style.visibility = "hidden";
			//document.getElementById("custompoll").style.visibility = "";
			document.getElementById("getpollcodetext").innerHTML = '<font face=verdana size=-2 color=#000000><nobr>This will also add the poll to your account</nobr></font>';
			document.getElementById("freeaccountrequired").style.display = "none";
		}
	}
}
function result_bars() {
	var font = document.poll.font.value;
	var fontcolor = document.poll.fontcolor.value;
	var bgcolor = document.poll.bgcolor.value;
	font=font.replace(/ /g, "");
	var skinvalue = "";
	if (document.getElementById("skin")) {
		if (document.getElementById("skin").value != "0000000") {
			skinvalue = document.getElementById("skin").value.substring(99,7);
		}
	}
	var url = "http://pollcode.com/resultbars.cgi?font=" + font + "&fontcolor=" + fontcolor + "&bgcolor=" + bgcolor + "&bg=" + skinvalue;
	var open = window.open(url,'bars','width=395,height=470,scrollbars=no');
	open.focus();
}

function selectskin(temp) {
	var bars = temp.substring(0,1);
	var hex = temp.substring(7,1);
	var bg = temp.substring(99,7);
	bgimage = "url(http://pollcode.com/images/bg/" + bg + ".gif)";
	document.getElementById("userpoll").style.backgroundImage = bgimage;
	document.getElementById("bgimage").value = bg;
	document.poll.bars.options[bars].selected = true;
	document.poll.fontcolor.value = hex;
	document.getElementById('fontcolor').color.fromString(hex);
	updateappearance(1);
}
function updateanswer(num) {
	var font = document.poll.font.value;
	var color = "#" + document.poll.fontcolor.value;
	document.getElementById("answerrow" + num).style.display = ""; 
	var updatenum = "answer" + num;
	if (!document.poll[updatenum].value) { 
		updateappearance();
	}
	else {
		var chars = /^[\w\s$%\.\?(),'"!:#\-/;@]+$/;
		if (document.poll[updatenum].value && !chars.test(document.poll[updatenum].value)) {
			document.poll[updatenum].value = document.poll[updatenum].value.replace(/[^\w\s$%\.\?(),'"!:#\-/;@]/ig,"");
			alert("You entered a character that is not permitted in the poll answer.  This character has been removed.");
			return false;
		}
		document.getElementById("answerhtml" + num).innerHTML= "<font face='" + font + "' size=2 color=" + color + ">" + document.poll[updatenum].value; + "</font>";
	}
}
function updateappearance(noclear,bgc) {
	var font = document.getElementById("fontchoice").value;
	var color = "#" + document.getElementById("fontcolor").value;
	for (i=1; i<=30; i++) {
		var field = "answer" + i;
		if (document.poll[field].value) { var started=1; }
	}
	for (i=1; i<=30; i++) {
		var field = "answer" + i;
		var answer = document.poll[field].value;
		if (!started && i <= 4 && noclear) { var answer = "Your Answer " + i; }
		if (!answer) {
			clearanswer(i);
		}
		document.getElementById("answerhtml" + i).innerHTML = "<font face='" + font + "' size=2 color=" + color + ">" + answer + "</font>";
	}
	if (bgc) {
		document.poll.skin[0].selected = true;
		document.getElementById("userpoll").style.backgroundImage = "";
		document.getElementById("bgimage").value = "";
	}
	var question = document.poll.question.value;
	if (!question) { question = "Your question"; }
	document.getElementById("questionhtml").innerHTML = "<font face='" + font + "' size=2 color=" + color + ">" + question + "</font>"; 
	document.getElementById("userpoll").style.backgroundColor = "#" + document.poll.bgcolor.value;
}

function updatequestion() {
	var font = document.getElementById("fontchoice").value;
	var color = "#" + document.getElementById("fontcolor").value;
	var chars = /^[\w\s$%\.\?(),'"!:#\-/;@]+$/;
	if (document.poll.question.value && !chars.test(document.poll.question.value)) {
		document.poll.question.value = document.poll.question.value.replace(/[^\w\s$%\.\?(),'"!:#\-/;@]/ig,"");
		alert("You entered a character that is not permitted in the poll question.  This character has been removed.");
		return false;
	}
	var question = document.poll.question.value;
	if (!question) { question = "Your question"; }
	document.getElementById("questionhtml").innerHTML = "<font face='" + font + "' size=2 color=" + color + ">" + question + "</font>"; 

}
function cookiecheck() {
	document.cookie = "test=1"; 
	var foundcookie = GetCookie("test");
	if (!foundcookie) {
		window.location = "http://pollcode.com/cookies.html";
	}
}
/////////////////////////////////////////////////////////////
// Written by: Bill Dortch, hIdaho Design <bdortch@netw.com>
// The following functions are released to the public domain.
function getCookieVal (offset) {
         var endstr = document.cookie.indexOf (";", offset);
            if (endstr == -1)
            endstr = document.cookie.length;
         return unescape(document.cookie.substring(offset, endstr));
         }

function GetCookie (name) {
         var arg = name + "=";
         var alen = arg.length;
         var clen = document.cookie.length;
         var i = 0;
         while (i < clen) {
         var j = i + alen;
             if (document.cookie.substring(i, j) == arg)
             return getCookieVal (j);
         i = document.cookie.indexOf(" ", i) + 1;
             if (i == 0) break;
             }

     return null;
     }
// End cookie code
/////////////////////////////////////////////////////////////