/* Go Vote Absentee Widget
 * Kyle Warren - http://govoteabsentee.org
 * kyle@govoteabsentee.org
 *
 */

function styleGVABox() {
	//style
	var style = document.createElement("link");
	style.rel = "stylesheet";
	style.href = "http://govoteabsentee.org/css/gvaWidget.css";
	style.type = "text/css";
	document.getElementsByTagName('head')[0].appendChild(style);
}


//makes the GVAbox and the zip code form
function makeGVABox() {
	//get the box
	var gvabox = document.getElementById("gvabox");

	//create the form
	var form = document.createElement("form");
	form.id = "zipcodeinput";
	form.method = "get";
	form.action = "http://govoteabsentee.org/vastepone.php";
	form.target = "_blank";

	//create and add the form objects
	var hidden = document.createElement("input");
	hidden.type = "hidden";
	hidden.value = "1";
	hidden.name = "w";

	form.appendChild(hidden);

	var search = document.createElement("input");
	search.type = "text";
	search.name = "zipcode";
	search.id = "gray";
	search.value = "your zip";
	search.defaultValue = "your zip";
	search.onclick = function(){GVAclearDefaultText(this)};
	search.onblur = function(){GVAaddDefaultText(this)};

	form.appendChild(search);

	var go = document.createElement("button");
	go.onclick = function(){form.submit()};

	form.appendChild(go);
	
	//the subtitle
	var gvaSubTitle = document.createElement("p");
	gvaSubTitle.id = "gvainfo";
	gvaSubTitle.innerHTML = 'Enter your <strong>home zip code</strong> to start <br /><strong>voting absentee</strong>.<br />';
	
	//a clear
	var clearDiv = document.createElement("div");
	clearDiv.id = "cleardiv";

	gvabox.appendChild(gvaSubTitle);
	gvabox.appendChild(form);
	gvabox.appendChild(clearDiv);
}


//dynamic search bar functions
function GVAclearDefaultText(input) {
	if(input.value == input.defaultValue) {
		input.value = '';
	}
	input.id = 'normal';
}

function GVAaddDefaultText(input) {
	if(input.value == '') {
		input.value = input.defaultValue;
		input.id = 'gray';
	}
}

styleGVABox();
document.write('<div id="gvabox"></div>');
makeGVABox();
